1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.163 2005/01/08 06:34:30 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
36: use Apache::lonratedt;
37: use Apache::lonratsrv;
38: use Apache::lonxml;
39: use Apache::loncreatecourse;
40: use Apache::lonnavmaps;
41: use HTML::Entities;
42: use GDBM_File;
43: use Apache::lonlocal;
44: use Cwd;
45:
46: my $iconpath;
47:
48: my %hash;
49:
50: my $hashtied;
51: my %alreadyseen=();
52:
53: my $hadchanges;
54:
55: # Available help topics
56:
57: my %help=();
58:
59: # Mapread read maps into lonratedt::global arrays
60: # @order and @resources, determines status
61: # sets @order - pointer to resources in right order
62: # sets @resources - array with the resources with correct idx
63: #
64:
65: sub mapread {
66: my ($coursenum,$coursedom,$map)=@_;
67: return
68: &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
69: $map);
70: }
71:
72: sub storemap {
73: my ($coursenum,$coursedom,$map)=@_;
74: my ($outtext,$errtext)=
75: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
76: $map,1);
77: if ($errtext) { return ($errtext,2); }
78:
79: $hadchanges=1;
80: return ($errtext,0);
81: }
82:
83: # ----------------------------------------- Return hash with valid author names
84:
85: sub authorhosts {
86: my %outhash=();
87: my $home=0;
88: my $other=0;
89: foreach (keys %ENV) {
90: if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
91: my $role=$1;
92: my $realm=$2;
93: my ($start,$end)=split(/\./,$ENV{$_});
94: if (($start) && ($start>time)) { next; }
95: if (($end) && (time>$end)) { next; }
96: my $ca; my $cd;
97: if ($1 eq 'au') {
98: $ca=$ENV{'user.name'};
99: $cd=$ENV{'user.domain'};
100: } else {
101: ($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
102: }
103: my $allowed=0;
104: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
105: my @ids=&Apache::lonnet::current_machine_ids();
106: foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
107: if ($allowed) {
108: $home++;
109: $outhash{'home_'.$ca.'@'.$cd}=1;
110: } else {
111: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
112: $other++;
113: }
114: }
115: }
116: return ($home,$other,%outhash);
117: }
118: # ------------------------------------------------------ Generate "dump" button
119:
120: sub dumpbutton {
121: my ($home,$other,%outhash)=&authorhosts();
122: if ($home+$other==0) { return ''; }
123: my $output='</td><td bgcolor="#DDDDCC">';
124: if ($home) {
125: return '</td><td bgcolor="#DDDDCC">'.
126: '<input type="submit" name="dumpcourse" value="'.
127: &mt('Dump Course DOCS to Construction Space').'" />'.
128: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
129: } else {
130: return'</td><td bgcolor="#DDDDCC">'.
131: &mt('Dump Course DOCS to Construction Space: available on other servers');
132: }
133: }
134:
135: # -------------------------------------------------------- Actually dump course
136:
137: sub dumpcourse {
138: my $r=shift;
139: $r->print('<html><head><title>Dump DOCS</title></head>'.
140: &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
141: '<form name="dumpdoc" method="post">');
142: my ($home,$other,%outhash)=&authorhosts();
143: unless ($home) { return ''; }
144: my $origcrsid=$ENV{'request.course.id'};
145: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
146: if (($ENV{'form.authorspace'}) && ($ENV{'form.authorfolder'}=~/\w/)) {
147: # Do the dumping
148: unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
149: my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
150: $r->print('<h3>'.&mt('Copying Files').'</h3>');
151: my $title=$ENV{'form.authorfolder'};
152: $title=~s/[^\w\/]+/\_/g;
153: my %replacehash=();
154: foreach (keys %ENV) {
155: if ($_=~/^form\.namefor\_(.+)/) {
156: $replacehash{$1}=$ENV{$_};
157: }
158: }
159: my $crs='/uploaded/'.$ENV{'request.course.id'}.'/';
160: $crs=~s/\_/\//g;
161: foreach (keys %replacehash) {
162: my $newfilename=$title.'/'.$replacehash{$_};
163: $newfilename=~s/[^\w\/\.\/]+/\_/g;
164: my @dirs=split(/\//,$newfilename);
165: my $path='/home/'.$ca.'/public_html';
166: my $makepath=$path;
167: my $fail=0;
168: for (my $i=0;$i<$#dirs;$i++) {
169: $makepath.='/'.$dirs[$i];
170: unless (-e $makepath) {
171: unless(mkdir($makepath,0777)) { $fail=1; }
172: }
173: }
174: $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
175: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
176: if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
177: print $fh &Apache::loncreatecourse::rewritefile(
178: &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_),
179: (%replacehash,$crs => '')
180: );
181: } else {
182: print $fh
183: &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_);
184: }
185: $fh->close();
186: } else {
187: $fail=1;
188: }
189: if ($fail) {
190: $r->print('<font color="red">fail</font>');
191: } else {
192: $r->print('<font color="green">ok</font>');
193: }
194: }
195: } else {
196: # Input form
197: unless ($home==1) {
198: $r->print(
199: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
200: }
201: foreach (sort keys %outhash) {
202: if ($_=~/^home_(.+)$/) {
203: if ($home==1) {
204: $r->print(
205: '<input type="hidden" name="authorspace" value="'.$1.'" />');
206: } else {
207: $r->print('<option value="'.$1.'">'.$1.' - '.
208: &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
209: }
210: }
211: }
212: unless ($home==1) {
213: $r->print('</select>');
214: }
215: my $title=$origcrsdata{'description'};
216: $title=~s/\s+/\_/gs;
217: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
218: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
219: &tiehash();
220: $r->print('<h3>'.&mt('Filenames in Construction Space').'</h3><table border="2"><tr><th>'.&mt('Internal Filename').'</th><th>'.&mt('Title').'</th><th>'.&mt('Save as ...').'</th></tr>');
221: foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
222: $r->print('<tr><td>'.$_.'</td>');
223: my ($ext)=($_=~/\.(\w+)$/);
224: my $title=$hash{'title_'.$hash{
225: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
226: $title=~s/:/:/g;
227: $r->print('<td>'.($title?$title:' ').'</td>');
228: unless ($title) {
229: $title=$_;
230: }
231: $title=~s/\.(\w+)$//;
232: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
233: $title.='.'.$ext;
234: $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
235: }
236: $r->print("</table>\n");
237: &untiehash();
238: $r->print(
239: '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump Course DOCS').'" /></p></form>');
240: }
241: }
242:
243: # ------------------------------------------------------ Generate "export" button
244:
245: sub exportbutton {
246: return '';
247: return '</td><td bgcolor="#DDDDCC">'.
248: '<input type="submit" name="exportcourse" value="'.
249: &mt('Export Course to IMS').'" />'.
250: &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
251: }
252:
253: sub exportcourse {
254: my $r=shift;
255: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
256: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
257: my $numdisc = keys %discussiontime;
258: my $navmap = Apache::lonnavmaps::navmap->new();
259: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
260: my $curRes;
261: my $outcome;
262:
263: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
264: ['finishexport']);
265: if ($ENV{'form.finishexport'}) {
266: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
267: ['archive','discussion']);
268:
269: my @exportitems = ();
270: if (defined($ENV{'form.archive'})) {
271: if (ref($ENV{'form.archive'}) eq 'ARRAY') {
272: @exportitems = @{$ENV{'form.archive'}};
273: } else {
274: $exportitems[0] = $ENV{'form.archive'};
275: }
276: }
277: my @discussions = ();
278: if (defined($ENV{'form.discussion'})) {
279: if (ref($ENV{'form.discussion'}) eq 'ARRAY') {
280: @discussions = $ENV{'form.discussion'};
281: } else {
282: $discussions[0] = $ENV{'form.discussion'};
283: }
284: }
285: if (@exportitems == 0 && @discussions == 0) {
286: $outcome = '<br />As you did not select any content items or discussions for export, an IMS package has not been created. Please <a href="javascript:history.go(-1)">go back</a> to select either content items or discussions for export';
287: } else {
288: my $now = time;
289: my %symbs;
290: my $manifestok = 0;
291: my $imsresources;
292: my $tempexport;
293: my $copyresult;
294: my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
295: if ($manifestok) {
296: &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
297: close($ims_manifest);
298:
299: #Create zip file in prtspool
300: my $imszipfile = '/prtspool/'.
301: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
302: time.'_'.rand(1000000000).'.zip';
303: # zip can cause an sh launch which can pass along all of %ENV
304: # which can be too large for /bin/sh to handle
305: my %oldENV=%ENV;
306: undef(%ENV);
307: my $cwd = &Cwd::getcwd();
308: my $imszip = '/home/httpd/'.$imszipfile;
309: chdir $tempexport;
310: open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
311: close(OUTPUT);
312: chdir $cwd;
313: %ENV=%oldENV;
314: undef(%oldENV);
315: $outcome .= 'Download the zip file from <a href="'.$imszipfile.'">IMS course archive</a><br />';
316: if ($copyresult) {
317: $outcome .= 'The following errors occurred during export - '.$copyresult;
318: }
319: } else {
320: $outcome = '<br />Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file.<br />';
321: }
322: }
323:
324: $r->print('<html><head><title>Export Course</title></head>'.
325: &Apache::loncommon::bodytag('Export course to IMS content package'));
326: $r->print($outcome);
327: $r->print('</body></html>');
328: } else {
329: my $display;
330: $display = '<form name="exportdoc" method="post">'."\n";
331: $display .= 'Choose which items you wish to export from your course.<br /><br />';
332: $display .= '<table border="0" cellspacing="0" cellpadding="3">'.
333: '<tr><td><fieldset><legend> <b>Content items</b></legend>'.
334: '<input type="button" value="check all" '.
335: 'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
336: ' <input type="button" value="uncheck all"'.
337: ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.
338: '<td> </td><td> </td>'.
339: '<td align="right"><fieldset><legend> <b>Discussion posts'.
340: '</b></legend><input type="button" value="check all"'.
341: ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
342: ' <input type="button" value="uncheck all"'.
343: ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.
344: '</tr></table>';
345: my $curRes;
346: my $depth = 0;
347: my $count = 0;
348: my $boards = 0;
349: my $startcount = 5;
350: my %parent = ();
351: my %children = ();
352: my $lastcontainer = $startcount;
353: my @bgcolors = ('#F6F6F6','#FFFFFF');
354: $display .= '<table cellspacing="0"><tr>'.
355: '<td><b>Export content item?<br /></b></td><td> </td><td align="right">'."\n";
356: if ($numdisc > 0) {
357: $display.='<b>Export discussion posts?</b>'."\n";
358: }
359: $display.=' </td></tr>';
360: while ($curRes = $it->next()) {
361: if (ref($curRes)) {
362: $count ++;
363: }
364: if ($curRes == $it->BEGIN_MAP()) {
365: $depth++;
366: $parent{$depth} = $lastcontainer;
367: }
368: if ($curRes == $it->END_MAP()) {
369: $depth--;
370: $lastcontainer = $parent{$depth};
371: }
372: if (ref($curRes)) {
373: my $symb = $curRes->symb();
374: my $ressymb = $symb;
375: if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {
376: unless ($ressymb =~ m|adm/wrapper/adm|) {
377: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
378: }
379: }
380: my $color = $count%2;
381: $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".
382: '<input type="checkbox" name="archive" value="'.$count.'" ';
383: if (($curRes->is_sequence()) || ($curRes->is_page())) {
384: my $checkitem = $count + $boards + $startcount;
385: $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';
386: }
387: $display .= ' />'."\n";
388: for (my $i=0; $i<$depth; $i++) {
389: $display .= '<img src="/adm/lonIcons/whitespace1.gif" width="25" height="1" alt="" border="0" /><img src="/adm/lonIcons/whitespace1.gif" width="25" height="1" alt="" border="0" />'."\n";
390: }
391: if ($curRes->is_sequence()) {
392: $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif"> '."\n";
393: $lastcontainer = $count + $startcount + $boards;
394: } elsif ($curRes->is_page()) {
395: $display .= '<img src="/adm/lonIcons/navmap.page.open.gif"> '."\n";
396: $lastcontainer = $count + $startcount + $boards;
397: }
398: my $currelem = $count+$boards+$startcount;
399: $children{$parent{$depth}} .= $currelem.':';
400: $display .= ' '.$curRes->title().'</td>';
401: if ($discussiontime{$ressymb} > 0) {
402: $boards ++;
403: $currelem = $count+$boards+$startcount;
404: $display .= '<td> </td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" /> </td>'."\n";
405: } else {
406: $display .= '<td colspan="2"> </td>'."\n";
407: }
408: }
409: }
410: my $scripttag = qq|
411: <script>
412:
413: function checkAll(field) {
414: if (field.length > 0) {
415: for (i = 0; i < field.length; i++) {
416: field[i].checked = true ;
417: }
418: } else {
419: field.checked = true
420: }
421: }
422:
423: function uncheckAll(field) {
424: if (field.length > 0) {
425: for (i = 0; i < field.length; i++) {
426: field[i].checked = false ;
427: }
428: } else {
429: field.checked = false ;
430: }
431: }
432:
433: function propagateCheck(item) {
434: if (document.exportdoc.elements[item].checked == true) {
435: containerCheck(item)
436: }
437: }
438:
439: function containerCheck(item) {
440: document.exportdoc.elements[item].checked = true
441: var numitems = $count + $boards + $startcount
442: var parents = new Array(numitems)
443: for (var i=$startcount; i<numitems; i++) {
444: parents[i] = new Array
445: }
446: |;
447:
448: foreach my $container (sort { $a <=> $b } keys %children) {
449: my @contents = split/:/,$children{$container};
450: for (my $i=0; $i<@contents; $i ++) {
451: $scripttag .= ' parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
452: }
453: }
454:
455: $scripttag .= qq|
456: if (parents[item].length > 0) {
457: for (var j=0; j<parents[item].length; j++) {
458: containerCheck(parents[item][j])
459: }
460: }
461: }
462:
463: </script>
464: |;
465: $r->print('<html><head><title>Export Course</title>'.$scripttag.'</head>'.
466: &Apache::loncommon::bodytag('Export course to IMS content package'
467: ));
468:
469: $r->print($display.'</table>'.
470: '<p><input type="hidden" name="finishexport" value="1">'.
471: '<input type="submit" name="exportcourse" value="'.
472: &mt('Export Course DOCS').'" /></p></form></body></html>');
473: }
474: }
475:
476: sub create_ims_store {
477: my ($now,$manifestok,$outcome,$tempexport) = @_;
478: $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
479: my $ims_manifest;
480: if (!-e $$tempexport) {
481: mkdir($$tempexport,0700);
482: }
483: $$tempexport .= '/'.$now;
484: if (!-e $$tempexport) {
485: mkdir($$tempexport,0700);
486: }
487: $$tempexport .= '/'.$ENV{'user.domain'}.'_'.$ENV{'user.name'};
488: if (!-e $$tempexport) {
489: mkdir($$tempexport,0700);
490: }
491: if (!-e "$$tempexport/resources") {
492: mkdir("$$tempexport/resources",0700);
493: }
494: # open manifest file
495: my $manifest = '/imsmanifest.xml';
496: my $manifestfilename = $$tempexport.$manifest;
497: if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
498: $$manifestok=1;
499: print $ims_manifest
500: '<?xml version="1.0" encoding="UTF-8"?>'."\n".
501: '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
502: ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
503: ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
504: ' identifier="MANIFEST-'.$ENV{'request.course.id'}.'-'.$now.'"'.
505: ' xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
506: ' http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
507: ' <organizations default="ORG-'.$ENV{'request.course.id'}.'-'.$now.'">'."\n".
508: ' <organization identifier="ORG-'.$ENV{'request.course.id'}.'-'.$now.'"'.
509: ' structure="hierarchical">'."\n".
510: ' <title>'.$ENV{'request.'.$ENV{'request.course.id'}.'.description'}.'</title>'
511: } else {
512: $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
513: ;
514: }
515: return $ims_manifest;
516: }
517:
518: sub build_package {
519: my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
520: # first iterator to look for dependencies
521: my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
522: my $curRes;
523: my $count = 0;
524: my $depth = 0;
525: my $lastcontainer = 0;
526: my %parent = ();
527: my @dependencies = ();
528: my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
529: my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
530: while ($curRes = $it->next()) {
531: if (ref($curRes)) {
532: $count ++;
533: }
534: if ($curRes == $it->BEGIN_MAP()) {
535: $depth++;
536: $parent{$depth} = $lastcontainer;
537: }
538: if ($curRes == $it->END_MAP()) {
539: $depth--;
540: $lastcontainer = $parent{$depth};
541: }
542: if (ref($curRes)) {
543: if ($curRes->is_sequence() || $curRes->is_page()) {
544: $lastcontainer = $count;
545: }
546: if (grep/^$count$/,@$exportitems) {
547: &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
548: }
549: }
550: }
551: # second iterator to build manifest and store resources
552: $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
553: $depth = 0;
554: my $prevdepth;
555: $count = 0;
556: my $imsresources;
557: my $pkgdepth;
558: my $included = 0;
559: while ($curRes = $it->next()) {
560: if ($curRes == $it->BEGIN_MAP()) {
561: $prevdepth = $depth;
562: $depth++;
563: }
564: if ($curRes == $it->END_MAP()) {
565: $prevdepth = $depth;
566: $depth--;
567: }
568:
569: if (ref($curRes)) {
570: $count ++;
571: if ((grep/^$count$/,@$exportitems) || (grep/^$count$/,@dependencies)) {
572: my $symb = $curRes->symb();
573: my $isvisible = 'true';
574: my $resourceref;
575: if ($curRes->randomout()) {
576: $isvisible = 'false';
577: }
578: unless ($curRes->is_sequence()) {
579: $resourceref = 'identifierref="RES-'.$ENV{'request.course.id'}.'-'.$count.'"';
580: }
581: if (($depth <= $prevdepth) && ($count > 1) && ($included)) {
582: print $ims_manifest "\n".' </item>'."\n";
583: }
584: $included = 1;
585: $prevdepth = $depth;
586:
587: my $itementry =
588: '<item identifier="ITEM-'.$ENV{'request.course.id'}.'-'.$count.
589: '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
590: '<title>'.$curRes->title().'</title>';
591: print $ims_manifest "\n".$itementry;
592:
593: unless ($curRes->is_sequence()) {
594: my $content_file;
595: my @hrefs = ();
596: &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
597: if ($content_file) {
598: $imsresources .= "\n".
599: ' <resource identifier="RES-'.$ENV{'request.course.id'}.'-'.$count.
600: '" type="webcontent" href="'.$content_file.'">'."\n".
601: ' <file href="'.$content_file.'" />'."\n";
602: foreach (@hrefs) {
603: $imsresources .=
604: ' <file href="'.$_.'" />'."\n";
605: }
606: if (grep/^$count$/,@$discussions) {
607: my $ressymb = $symb;
608: my $mode;
609: if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {
610: unless ($ressymb =~ m|adm/wrapper/adm|) {
611: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
612: }
613: $mode = 'board';
614: }
615: my %extras = (
616: caller => 'imsexport',
617: tempexport => $tempexport.'/resources',
618: count => $count
619: );
620: my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
621: }
622: $imsresources .= ' </resource>'."\n";
623: }
624: }
625: $pkgdepth = $depth;
626: } else {
627: $included = 0;
628: }
629: }
630: }
631: while ($pkgdepth > 0) {
632: print $ims_manifest " </item>\n";
633: $pkgdepth --;
634: }
635: my $resource_text = qq|
636: </organization>
637: </organizations>
638: <resources>
639: $imsresources
640: </resources>
641: </manifest>
642: |;
643: print $ims_manifest $resource_text;
644: }
645:
646: sub get_dependencies {
647: my ($exportitems,$parent,$depth,$dependencies) = @_;
648: if ($depth > 1) {
649: if ((!grep/^$$parent{$depth}$/,@$exportitems) && (!grep/^$$parent{$depth}$/,@$dependencies)) {
650: push @$dependencies, $$parent{$depth};
651: if ($depth > 2) {
652: &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
653: }
654: }
655: }
656: }
657:
658: sub process_content {
659: my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
660: my $content_type;
661: my $message;
662: # find where user is author or co-author
663: my @uploads = ();
664: if ($curRes->is_sequence()) {
665: $content_type = 'sequence';
666: } elsif ($curRes->is_page()) {
667: $content_type = 'page'; # need to handle individual items in pages.
668: } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
669: $content_type = 'syllabus';
670: my $contents = &Apache::imsexport::templatedpage($content_type);
671: if ($contents) {
672: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
673: }
674: } elsif ($symb =~ m-\.sequence___\d+___ext-) {
675: $content_type = 'external';
676: my $title = $curRes->title;
677: my $contents = &Apache::imsexport::external($symb,$title);
678: if ($contents) {
679: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
680: }
681: } elsif ($symb =~ m-adm/navmaps$-) {
682: $content_type = 'navmap';
683: } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
684: $content_type = 'simplepage';
685: my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);
686: if ($contents) {
687: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
688: }
689: } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {
690: $content_type = 'simpleproblem';
691: my $contents = &Apache::imsexport::simpleproblem($symb);
692: if ($contents) {
693: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
694: }
695: } elsif ($symb =~ m-lib/templates/examupload\.problem-m) {
696: $content_type = 'examupload';
697: } elsif ($symb =~ m-adm/(\w+)/(\w+)/(\d+)/bulletinboard$-) {
698: $content_type = 'bulletinboard';
699: my $contents = &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);
700: if ($contents) {
701: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
702: }
703: } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {
704: $content_type = 'aboutme';
705: my $contents = &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);
706: if ($contents) {
707: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
708: }
709: } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
710: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
711: } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
712: my $canedit = 0;
713: if ($2 eq $ENV{'user.domain'} && $3 eq $ENV{'user.name'}) {
714: $canedit= 1;
715: }
716: if ($canedit) {
717: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
718: } else {
719: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
720: }
721: } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
722: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
723: }
724: if (@uploads > 0) {
725: foreach my $item (@uploads) {
726: my $uploadmsg = '';
727: &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
728: if ($uploadmsg) {
729: $$copyresult .= $uploadmsg."\n";
730: }
731: }
732: }
733: if ($message) {
734: $$copyresult .= $message."\n";
735: }
736: }
737:
738: sub replicate_content {
739: my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
740: my ($map,$ind,$url);
741: if ($caller eq 'templateupload') {
742: $url = $symb;
743: $url =~ s#//#/#g;
744: } else {
745: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
746: }
747: my $content;
748: my $filename;
749: my $repstatus;
750: my $content_name;
751: if ($url =~ m-/([^/]+)$-) {
752: $filename = $1;
753: if (!-e $tempexport.'/resources') {
754: mkdir($tempexport.'/resources',0700);
755: }
756: if (!-e $tempexport.'/resources/'.$count) {
757: mkdir($tempexport.'/resources/'.$count,0700);
758: }
759: my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
760: my $copiedfile;
761: if ($copiedfile = Apache::File->new('>'.$destination)) {
762: my $content;
763: if ($caller eq 'resource') {
764: $content = &Apache::lonnet::getfile('/home/httpd/html/res/'.$url);
765: if ($content eq -1) {
766: $$message = 'Could not copy file '.$filename;
767: } else {
768: &extract_media($content,$count,$tempexport,$href,'resource');
769: $repstatus = 'ok';
770: }
771: } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
772: my $rtncode;
773: $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
774: if ($repstatus eq 'ok') {
775: if ($url =~ /\.html?$/i) {
776: &extract_media(\$content,$count,$tempexport,$href,'uploaded');
777: }
778: } else {
779: $$message = 'Could not render '.$url.' server message - '.$rtncode;
780: }
781: } elsif ($caller eq 'noedit') {
782: # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
783: $repstatus = 'ok';
784: $content = 'Not the owner of this resource';
785: }
786: if ($repstatus eq 'ok') {
787: print $copiedfile $content;
788: }
789: close($copiedfile);
790: } else {
791: $$message = 'Could not open destination file for '.$filename."\n";
792: }
793: } else {
794: $$message = 'Could not determine name of file for '.$symb."\n";
795: }
796: if ($repstatus eq 'ok') {
797: $content_name = $count.'/'.$filename;
798: }
799: return $content_name;
800: }
801:
802: sub extract_media {
803: my ($content,$count,$tempexport,$href,$caller) = @_;
804: # @$href will contain path to any embedded resources in the content.
805: # For LON-CAPA problems this would be images. applets etc.
806: # For uploaded HTML files this would be images etc.
807: # paths will be in the form $count/res/$file, and urls in the $content will be rewritten with the new paths.
808: return;
809: }
810:
811: sub store_template {
812: my ($contents,$tempexport,$count,$content_type) = @_;
813: if ($contents) {
814: if ($tempexport) {
815: if (!-e $tempexport.'/resources') {
816: mkdir($tempexport.'/resources',0700);
817: }
818: if (!-e $tempexport.'/resources/'.$count) {
819: mkdir($tempexport.'/resources/'.$count,0700);
820: }
821: my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
822: my $storetemplate;
823: if ($storetemplate = Apache::File->new('>'.$destination)) {
824: print $storetemplate $contents;
825: close($storetemplate);
826: }
827: if ($content_type eq 'external') {
828: return $count.'/'.$content_type.'.html';
829: } else {
830: return $count.'/'.$content_type.'.xml';
831: }
832: }
833: }
834: }
835:
836: # Imports the given (name, url) resources into the course
837: # coursenum, coursedom, and folder must precede the list
838: sub group_import {
839: my $coursenum = shift;
840: my $coursedom = shift;
841: my $folder = shift;
842: my $container = shift;
843: my $caller = shift;
844: while (@_) {
845: my $name = shift;
846: my $url = shift;
847: if (($url =~ m#^/uploaded/$coursedom/$coursenum/(default_\d+\.)(page|sequence)$#) && ($caller eq 'londocs')) {
848: my $errtext = '';
849: my $fatal = 0;
850: my $newmapstr = '<map>'."\n".
851: '<resource id="1" src="" type="start"></resource>'."\n".
852: '<link from="1" to="2" index="1"></link>'."\n".
853: '<resource id="2" src="" type="finish"></resource>'."\n".
854: '</map>';
855: $ENV{'form.output'}=$newmapstr;
856: my $home=&Apache::lonnet::homeserver($coursenum,$coursedom);
857: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$home,
858: 'output',$1.$2);
859: if ($result != m|^/uploaded/|) {
860: $errtext.='Map not saved: A network error occured when trying to save the new map. ';
861: $fatal = 2;
862: }
863: if ($fatal) {
864: return ($errtext,$fatal);
865: }
866: }
867: if ($url) {
868: my $idx = $#Apache::lonratedt::resources + 1;
869: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
870: my $ext = 'false';
871: if ($url=~/^http:\/\//) { $ext = 'true'; }
872: $url =~ s/:/\:/g;
873: $name =~ s/:/\:/g;
874: $Apache::lonratedt::resources[$idx] =
875: join ':', ($name, $url, $ext, 'normal', 'res');
876: }
877: }
878: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
879: }
880:
881: sub breadcrumbs {
882: my ($where)=@_;
883: &Apache::lonhtmlcommon::clear_breadcrumbs();
884: my (@folders);
885: if ($ENV{'form.pagepath'}) {
886: @folders = split('&',$ENV{'form.pagepath'});
887: } else {
888: @folders=split('&',$ENV{'form.folderpath'});
889: }
890: my $folderpath;
891: while (@folders) {
892: my $folder=shift(@folders);
893: my $foldername=shift(@folders);
894: if ($folderpath) {$folderpath.='&';}
895: $folderpath.=$folder.'&'.$foldername;
896: my $url='/adm/coursedocs?folderpath='.
897: &Apache::lonnet::escape($folderpath);
898: &Apache::lonhtmlcommon::add_breadcrumb(
899: {'href'=>$url,
900: 'title'=>&Apache::lonnet::unescape($foldername),
901: 'text'=>'<font size="+1">'.
902: &Apache::lonnet::unescape($foldername).'</font>'
903: });
904:
905:
906: }
907: return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,
908: 0,'nohelp');
909: }
910:
911: sub editor {
912: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
913:
914: $r->print(&breadcrumbs($folder));
915: my $errtext='';
916: my $fatal=0;
917: my $container='sequence';
918: if ($ENV{'form.pagepath'}) {
919: $container='page';
920: }
921: ($errtext,$fatal)=
922: &mapread($coursenum,$coursedom,$folder.'.'.$container);
923: if ($#Apache::lonratedt::order<1) {
924: $Apache::lonratedt::order[0]=1;
925: $Apache::lonratedt::resources[1]='';
926: }
927: if ($fatal) {
928: $r->print('<p><font color="red">'.$errtext.'</font></p>');
929: } else {
930: # ------------------------------------------------------------ Process commands
931:
932: # ---------------- if they are for this folder and user allowed to make changes
933: if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
934: # set parameters and change order
935: if (defined($ENV{'form.setparms'})) {
936: my $idx=$ENV{'form.setparms'};
937: # set parameters
938: if ($ENV{'form.randpick_'.$idx}) {
939: &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
940: } else {
941: &Apache::lonratedt::delparameter($idx,'parameter_randompick');
942: }
943: if ($ENV{'form.hidprs_'.$idx}) {
944: &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
945: } else {
946: &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
947: }
948: if ($ENV{'form.encprs_'.$idx}) {
949: &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
950: } else {
951: &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
952: }
953:
954: if ($ENV{'form.newpos'}) {
955: # change order
956:
957: my $newpos=$ENV{'form.newpos'}-1;
958: my $currentpos=$ENV{'form.currentpos'}-1;
959: my $i;
960: my @neworder=();
961: if ($newpos>$currentpos) {
962: # moving stuff up
963: for ($i=0;$i<$currentpos;$i++) {
964: $neworder[$i]=$Apache::lonratedt::order[$i];
965: }
966: for ($i=$currentpos;$i<$newpos;$i++) {
967: $neworder[$i]=$Apache::lonratedt::order[$i+1];
968: }
969: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
970: for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
971: $neworder[$i]=$Apache::lonratedt::order[$i];
972: }
973: } else {
974: # moving stuff down
975: for ($i=0;$i<$newpos;$i++) {
976: $neworder[$i]=$Apache::lonratedt::order[$i];
977: }
978: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
979: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
980: $neworder[$i]=$Apache::lonratedt::order[$i-1];
981: }
982: for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
983: $neworder[$i]=$Apache::lonratedt::order[$i];
984: }
985: }
986: @Apache::lonratedt::order=@neworder;
987: }
988: # store the changed version
989:
990: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
991: if ($fatal) {
992: $r->print('<p><font color="red">'.$errtext.'</font></p>');
993: return;
994: }
995:
996: }
997:
998: # upload a file, if present
999: if (($ENV{'form.uploaddoc.filename'}) &&
1000: ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
1001: if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
1002: # this is for a course, not a user, so set coursedoc flag
1003: # probably the only place in the system where this should be "1"
1004: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
1005: my $ext='false';
1006: if ($url=~/^http\:\/\//) { $ext='true'; }
1007: $url=~s/\:/\:/g;
1008: my $comment=$ENV{'form.comment'};
1009: $comment=~s/\</\<\;/g;
1010: $comment=~s/\>/\>\;/g;
1011: $comment=~s/\:/\:/g;
1012: if ($folder=~/^supplemental/) {
1013: $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
1014: $ENV{'user.domain'}.'___&&&___'.$comment;
1015: }
1016: my $newidx=$#Apache::lonratedt::resources+1;
1017: $Apache::lonratedt::resources[$newidx]=
1018: $comment.':'.$url.':'.$ext.':normal:res';
1019: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
1020: $newidx;
1021:
1022: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1023: if ($fatal) {
1024: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1025: return;
1026: }
1027: }
1028: }
1029: if ($ENV{'form.cmd'}) {
1030: my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
1031: if ($cmd eq 'del') {
1032: my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
1033: if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) {
1034: &Apache::lonnet::removeuploadedurl($url);
1035: }
1036: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
1037: $Apache::lonratedt::order[$i]=
1038: $Apache::lonratedt::order[$i+1];
1039: }
1040: $#Apache::lonratedt::order--;
1041: } elsif ($cmd eq 'up') {
1042: if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
1043: my $i=$Apache::lonratedt::order[$idx-1];
1044: $Apache::lonratedt::order[$idx-1]=
1045: $Apache::lonratedt::order[$idx];
1046: $Apache::lonratedt::order[$idx]=$i;
1047: }
1048: } elsif ($cmd eq 'down') {
1049: if (defined($Apache::lonratedt::order[$idx+1])) {
1050: my $i=$Apache::lonratedt::order[$idx+1];
1051: $Apache::lonratedt::order[$idx+1]=
1052: $Apache::lonratedt::order[$idx];
1053: $Apache::lonratedt::order[$idx]=$i;
1054: }
1055: } elsif ($cmd eq 'rename') {
1056: my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]];
1057: my ($rtitle,@rrest)=split(/\:/,
1058: $Apache::lonratedt::resources[
1059: $Apache::lonratedt::order[$idx]]);
1060: my $comment=
1061: &HTML::Entities::decode($ENV{'form.title'});
1062: $comment=~s/\</\<\;/g;
1063: $comment=~s/\>/\>\;/g;
1064: $comment=~s/\:/\:/g;
1065: if ($comment=~/\S/) {
1066: $Apache::lonratedt::resources[
1067: $Apache::lonratedt::order[$idx]]=
1068: $comment.':'.join(':',@rrest);
1069: }
1070: }
1071: # Store the changed version
1072: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1073: $folder.'.'.$container);
1074: if ($fatal) {
1075: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1076: return;
1077: }
1078: }
1079: # Group import/search
1080: if ($ENV{'form.importdetail'}) {
1081: my @imports;
1082: foreach (split(/\&/,$ENV{'form.importdetail'})) {
1083: if (defined($_)) {
1084: my ($name,$url)=split(/\=/,$_);
1085: $name=&Apache::lonnet::unescape($name);
1086: $url=&Apache::lonnet::unescape($url);
1087: push @imports, $name, $url;
1088: }
1089: }
1090: # Store the changed version
1091: ($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
1092: $container,'londocs',@imports);
1093: if ($fatal) {
1094: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1095: return;
1096: }
1097: }
1098: # Loading a complete map
1099: if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
1100: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
1101: my $idx=$#Apache::lonratedt::resources;
1102: $idx++;
1103: $Apache::lonratedt::resources[$idx]=$_;
1104: $Apache::lonratedt::order
1105: [$#Apache::lonratedt::order+1]=$idx;
1106: }
1107:
1108: # Store the changed version
1109: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1110: $folder.'.'.$container);
1111: if ($fatal) {
1112: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1113: return;
1114: }
1115: }
1116: }
1117: # ---------------------------------------------------------------- End commands
1118: # ---------------------------------------------------------------- Print screen
1119: my $idx=0;
1120: my $shown=0;
1121: $r->print('<table>');
1122: foreach (@Apache::lonratedt::order) {
1123: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
1124: unless ($name) { $name=(split(/\//,$url))[-1]; }
1125: unless ($name) { $idx++; next; }
1126: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
1127: $idx++;
1128: $shown++;
1129: }
1130: unless ($shown) {
1131: $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
1132: }
1133: $r->print('</table>');
1134: }
1135: }
1136:
1137: # --------------------------------------------------------------- An entry line
1138:
1139: sub entryline {
1140: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1141: $title=~s/\&colon\;/\:/g;
1142: $title=&HTML::Entities::encode(&HTML::Entities::decode(
1143: &Apache::lonnet::unescape($title)),'"<>&\'');
1144: my $renametitle=$title;
1145: my $foldertitle=$title;
1146: my $pagetitle=$title;
1147: my $orderidx=$Apache::lonratedt::order[$index];
1148: if ($title=~ /^(\d+)___&&&___(\w+)___&&&___(\w+)___&&&___(.*)$/ ) {
1149: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1150: $renametitle=$4;
1151: $title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
1152: &Apache::loncommon::plainname($2,$3).': <br />'.
1153: $foldertitle;
1154: }
1155: $renametitle=~s/\"\;/\\\"/g;
1156: my $line='<tr>';
1157: # Edit commands
1158: my $container;
1159: my $folderpath;
1160: if ($ENV{'form.folderpath'}) {
1161: $container = 'sequence';
1162: $folderpath=&Apache::lonnet::escape($ENV{'form.folderpath'});
1163: # $htmlfoldername=&HTML::Entities::encode($ENV{'form.foldername'},'<>&"');
1164: }
1165: my ($pagepath,$pagesymb);
1166: if ($ENV{'form.pagepath'}) {
1167: $container = 'page';
1168: $pagepath=&Apache::lonnet::escape($ENV{'form.pagepath'});
1169: $pagesymb=&Apache::lonnet::escape($ENV{'form.pagesymb'});
1170: }
1171: if ($allowed) {
1172: my $incindex=$index+1;
1173: my $selectbox='';
1174: if ($folder!~/^supplemental/) {
1175: $selectbox=
1176: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1177: '<select name="newpos" onChange="this.form.submit()">';
1178: for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
1179: if ($i==$incindex) {
1180: $selectbox.='<option value="" selected="1">('.$i.')</option>';
1181: } else {
1182: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1183: }
1184: }
1185: $selectbox.='</select>';
1186: }
1187: my %lt=&Apache::lonlocal::texthash(
1188: 'up' => 'Move Up',
1189: 'dw' => 'Move Down',
1190: 'rm' => 'Remove',
1191: 'rn' => 'Rename');
1192: if ($ENV{'form.pagepath'}) {
1193: $line.=(<<END);
1194: <form name="entry_$index" action="/adm/coursedocs" method="post">
1195: <input type="hidden" name="pagepath" value="$ENV{'form.pagepath'}" />
1196: <input type="hidden" name="pagesymb" value="$ENV{'form.pagesymb'}" />
1197: <input type="hidden" name="setparms" value="$orderidx" />
1198: <td><table border='0' cellspacing='2' cellpadding='0'>
1199: <tr><td bgcolor="#DDDDDD">
1200: <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb'>
1201: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1202: <tr><td bgcolor="#DDDDDD">
1203: <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb'>
1204: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1205: </table></td>
1206: <td>$selectbox
1207: </td><td bgcolor="#DDDDDD">
1208: <a href='javascript:removeres("$pagepath","$index","$renametitle","page","$pagesymb");'>
1209: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1210: <a href='javascript:changename("$pagepath","$index","$renametitle","page","$pagesymb");'>
1211: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
1212: END
1213: } else {
1214: $line.=(<<END);
1215: <form name="entry_$index" action="/adm/coursedocs" method="post">
1216: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1217: <input type="hidden" name="setparms" value="$orderidx" />
1218: <td><table border='0' cellspacing='2' cellpadding='0'>
1219: <tr><td bgcolor="#DDDDDD">
1220: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath'>
1221: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1222: <tr><td bgcolor="#DDDDDD">
1223: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath'>
1224: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1225: </table></td>
1226: <td>$selectbox
1227: </td><td bgcolor="#DDDDDD">
1228: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
1229: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1230: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
1231: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
1232: END
1233: }
1234: }
1235: # Figure out what kind of a resource this is
1236: my ($extension)=($url=~/\.(\w+)$/);
1237: my $uploaded=($url=~/^\/*uploaded\//);
1238: my $icon=&Apache::loncommon::icon($url);
1239: my $isfolder=0;
1240: my $ispage=0;
1241: my $folderarg;
1242: my $pagearg;
1243: my $pagefile;
1244: if ($uploaded) {
1245: if ($extension eq 'sequence') {
1246: $icon=$iconpath.'/folder_closed.gif';
1247: $url=~/$coursenum\/([\/\w]+)\.sequence$/;
1248: $url='/adm/coursedocs?';
1249: $folderarg=$1;
1250: $isfolder=1;
1251: } elsif ($extension eq 'page') {
1252: $icon=$iconpath.'/page.gif';
1253: $url=~/$coursenum\/([\/\w]+)\.page$/;
1254: $pagearg=$1;
1255: $url='/adm/coursedocs?';
1256: $ispage=1;
1257: } else {
1258: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1259: }
1260: }
1261: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
1262: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1263: my $symb=&Apache::lonnet::symbclean(
1264: &Apache::lonnet::declutter('uploaded/'.
1265: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
1266: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
1267: '.sequence').
1268: '___'.$residx.'___'.
1269: &Apache::lonnet::declutter($url));
1270: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1271: $url=&Apache::lonnet::clutter($url);
1272: if ($url=~/^\/*uploaded\//) {
1273: $url=~/\.(\w+)$/;
1274: my $embstyle=&Apache::loncommon::fileembstyle($1);
1275: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
1276: $url='/adm/wrapper'.$url;
1277: } elsif ($embstyle eq 'ssi') {
1278: #do nothing with these
1279: } elsif ($url!~/\.(sequence|page)$/) {
1280: $url='/adm/coursedocs/showdoc'.$url;
1281: }
1282: } elsif ($url=~m|^/ext/|) {
1283: $url='/adm/wrapper'.$url;
1284: }
1285: $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
1286: if ($container eq 'page') {
1287: my $symb=$ENV{'form.pagesymb'};
1288:
1289: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1290: $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
1291: }
1292: }
1293: my $parameterset=' ';
1294: if ($isfolder) {
1295: my $foldername=&Apache::lonnet::escape($foldertitle);
1296: my $folderpath=$ENV{'form.folderpath'};
1297: if ($folderpath) { $folderpath.='&' };
1298: $folderpath.=$folderarg.'&'.$foldername;
1299: $url.='folderpath='.&Apache::lonnet::escape($folderpath);
1300: $parameterset='<label>'.&mt('Randomly Pick: ').
1301: '<input type="text" size="4" name="randpick_'.$orderidx.'" value="'.
1302: (&Apache::lonratedt::getparameter($orderidx,
1303: 'parameter_randompick'))[0].
1304: '" />'.'</label>';
1305:
1306: }
1307: if ($ispage) {
1308: my $pagename=&Apache::lonnet::escape($pagetitle);
1309: my $pagepath;
1310: my $folderpath=$ENV{'form.folderpath'};
1311: if ($folderpath) { $pagepath = $folderpath.'&' };
1312: $pagepath.=$pagearg.'&'.$pagename;
1313: my $symb=$ENV{'form.pagesymb'};
1314: if (!$symb) {
1315: my $path='uploaded/'.
1316: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
1317: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/';
1318: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
1319: $residx,
1320: $path.$pagearg.'.page');
1321: }
1322: $url.='pagepath='.&Apache::lonnet::escape($pagepath).
1323: '&pagesymb='.&Apache::lonnet::escape($symb);
1324: }
1325: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
1326: '" border="0"></a></td>'.
1327: "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
1328: if (($allowed) && ($folder!~/^supplemental/)) {
1329: my %lt=&Apache::lonlocal::texthash(
1330: 'hd' => 'Hidden',
1331: 'ec' => 'URL hidden',
1332: 'sp' => 'Store Parameters');
1333: my $enctext=
1334: ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
1335: my $hidtext=
1336: ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1337: $line.=(<<ENDPARMS);
1338: <td bgcolor="#BBBBFF"><font size='-2'>
1339: <nobr><label><input type="checkbox" name="hidprs_$orderidx" $hidtext/> $lt{'hd'}</label></nobr></td>
1340: <td bgcolor="#BBBBFF"><font size='-2'>
1341: <nobr><label><input type="checkbox" name="encprs_$orderidx" $enctext/> $lt{'ec'}</label></nobr></td>
1342: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
1343: <td bgcolor="#BBBBFF"><font size='-2'>
1344: <input type="submit" value="$lt{'sp'}" />
1345: </font></td>
1346: ENDPARMS
1347: }
1348: $line.="</form></tr>";
1349: return $line;
1350: }
1351:
1352: # ---------------------------------------------------------------- tie the hash
1353:
1354: sub tiehash {
1355: my ($mode)=@_;
1356: $hashtied=0;
1357: if ($ENV{'request.course.fn'}) {
1358: if ($mode eq 'write') {
1359: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
1360: &GDBM_WRCREAT(),0640)) {
1361: $hashtied=2;
1362: }
1363: } else {
1364: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
1365: &GDBM_READER(),0640)) {
1366: $hashtied=1;
1367: }
1368: }
1369: }
1370: }
1371:
1372: sub untiehash {
1373: if ($hashtied) { untie %hash; }
1374: $hashtied=0;
1375: }
1376:
1377: # --------------------------------------------------------------- check on this
1378:
1379: sub checkonthis {
1380: my ($r,$url,$level,$title)=@_;
1381: $url=&Apache::lonnet::unescape($url);
1382: $alreadyseen{$url}=1;
1383: $r->rflush();
1384: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1385: $r->print("\n<br />");
1386: for (my $i=0;$i<=$level*5;$i++) {
1387: $r->print(' ');
1388: }
1389: $r->print('<a href="'.$url.'" target="cat">'.
1390: ($title?$title:$url).'</a> ');
1391: if ($url=~/^\/res\//) {
1392: my $result=&Apache::lonnet::repcopy(
1393: &Apache::lonnet::filelocation('',$url));
1394: if ($result==OK) {
1395: $r->print('<font color="green">'.&mt('ok').'</font>');
1396: $r->rflush();
1397: &Apache::lonnet::countacc($url);
1398: $url=~/\.(\w+)$/;
1399: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
1400: $r->print('<br />');
1401: $r->rflush();
1402: for (my $i=0;$i<=$level*5;$i++) {
1403: $r->print(' ');
1404: }
1405: $r->print('- '.&mt('Rendering').': ');
1406: my $oldpath=$ENV{'request.filename'};
1407: $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
1408: &Apache::lonxml::xmlparse($r,'web',
1409: &Apache::lonnet::getfile(
1410: &Apache::lonnet::filelocation('',$url)));
1411: undef($Apache::lonhomework::parsing_a_problem);
1412: $ENV{'request.filename'}=$oldpath;
1413: if (($Apache::lonxml::errorcount) ||
1414: ($Apache::lonxml::warningcount)) {
1415: if ($Apache::lonxml::errorcount) {
1416: $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
1417: $Apache::lonxml::errorcount.' '.
1418: &mt('error(s)').'</b></font> ');
1419: }
1420: if ($Apache::lonxml::warningcount) {
1421: $r->print('<font color="blue">'.
1422: $Apache::lonxml::warningcount.' '.
1423: &mt('warning(s)').'</font>');
1424: }
1425: } else {
1426: $r->print('<font color="green">'.&mt('ok').'</font>');
1427: }
1428: $r->rflush();
1429: }
1430: my $dependencies=
1431: &Apache::lonnet::metadata($url,'dependencies');
1432: foreach (split(/\,/,$dependencies)) {
1433: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
1434: &checkonthis($r,$_,$level+1);
1435: }
1436: }
1437: } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
1438: $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
1439: } elsif ($result==HTTP_NOT_FOUND) {
1440: unless ($url=~/\$/) {
1441: $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
1442: } else {
1443: $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
1444: }
1445: } else {
1446: $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
1447: }
1448: }
1449: }
1450: }
1451:
1452:
1453: #
1454: # -------------------------------------------------------------- Verify Content
1455: #
1456: sub verifycontent {
1457: my $r=shift;
1458: my $loaderror=&Apache::lonnet::overloaderror($r);
1459: if ($loaderror) { return $loaderror; }
1460:
1461: $r->print('<html><head><title>Verify Content</title></head>'.
1462: &Apache::loncommon::bodytag('Verify Course Documents'));
1463: $hashtied=0;
1464: undef %alreadyseen;
1465: %alreadyseen=();
1466: &tiehash();
1467: foreach (keys %hash) {
1468: if ($hash{$_}=~/\.(page|sequence)$/) {
1469: if (($_=~/^src_/) && ($alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
1470: $r->print('<hr /><font color="red">'.
1471: &mt('The following sequence or page is included more than once in your course: ').
1472: &Apache::lonnet::unescape($hash{$_}).'</font><br />'.
1473: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
1474: }
1475: }
1476: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
1477: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1478: }
1479: }
1480: &untiehash();
1481: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
1482: &mt('Return to DOCS').'</a>');
1483: }
1484:
1485: # -------------------------------------------------------------- Check Versions
1486:
1487: sub checkversions {
1488: my $r=shift;
1489: $r->print('<html><head><title>Check Versions</title></head>'.
1490: &Apache::loncommon::bodytag('Check Course Document Versions'));
1491: my $header='';
1492: my $startsel='';
1493: my $monthsel='';
1494: my $weeksel='';
1495: my $daysel='';
1496: my $allsel='';
1497: my %changes=();
1498: my $starttime=0;
1499: my $haschanged=0;
1500: my %setversions=&Apache::lonnet::dump('resourceversions',
1501: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1502: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1503:
1504: $hashtied=0;
1505: &tiehash();
1506: my %newsetversions=();
1507: if ($ENV{'form.setmostrecent'}) {
1508: $haschanged=1;
1509: foreach (keys %hash) {
1510: if ($_=~/^ids\_(\/res\/.+)$/) {
1511: $newsetversions{$1}='mostrecent';
1512: }
1513: }
1514: } elsif ($ENV{'form.setcurrent'}) {
1515: $haschanged=1;
1516: foreach (keys %hash) {
1517: if ($_=~/^ids\_(\/res\/.+)$/) {
1518: my $getvers=&Apache::lonnet::getversion($1);
1519: if ($getvers>0) {
1520: $newsetversions{$1}=$getvers;
1521: }
1522: }
1523: }
1524: } elsif ($ENV{'form.setversions'}) {
1525: $haschanged=1;
1526: foreach (keys %ENV) {
1527: if ($_=~/^form\.set_version_(.+)$/) {
1528: my $src=$1;
1529: if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
1530: $newsetversions{$src}=$ENV{$_};
1531: }
1532: }
1533: }
1534: }
1535: if ($haschanged) {
1536: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
1537: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1538: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {
1539: $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
1540: } else {
1541: $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
1542: }
1543: &mark_hash_old();
1544: }
1545: &changewarning($r,'');
1546: if ($ENV{'form.timerange'} eq 'all') {
1547: # show all documents
1548: $header=&mt('All Documents in Course');
1549: $allsel=1;
1550: foreach (keys %hash) {
1551: if ($_=~/^ids\_(\/res\/.+)$/) {
1552: my $src=$1;
1553: $changes{$src}=1;
1554: }
1555: }
1556: } else {
1557: # show documents which changed
1558: %changes=&Apache::lonnet::dump
1559: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1560: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1561: my $firstkey=(keys %changes)[0];
1562: unless ($firstkey=~/^error\:/) {
1563: unless ($ENV{'form.timerange'}) {
1564: $ENV{'form.timerange'}=604800;
1565: }
1566: my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
1567: .&mt('seconds');
1568: if ($ENV{'form.timerange'}==-1) {
1569: $seltext='since start of course';
1570: $startsel='selected';
1571: $ENV{'form.timerange'}=time;
1572: }
1573: $starttime=time-$ENV{'form.timerange'};
1574: if ($ENV{'form.timerange'}==2592000) {
1575: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1576: $monthsel='selected';
1577: } elsif ($ENV{'form.timerange'}==604800) {
1578: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1579: $weeksel='selected';
1580: } elsif ($ENV{'form.timerange'}==86400) {
1581: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1582: $daysel='selected';
1583: }
1584: $header=&mt('Content changed').' '.$seltext;
1585: } else {
1586: $header=&mt('No content modifications yet.');
1587: }
1588: }
1589: %setversions=&Apache::lonnet::dump('resourceversions',
1590: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1591: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1592: my %lt=&Apache::lonlocal::texthash
1593: ('st' => 'Version changes since start of Course',
1594: 'lm' => 'Version changes since last Month',
1595: 'lw' => 'Version changes since last Week',
1596: 'sy' => 'Version changes since Yesterday',
1597: 'al' => 'All Resources (possibly large output)',
1598: 'sd' => 'Display',
1599: 'fi' => 'File',
1600: 'md' => 'Modification Date',
1601: 'mr' => 'Most recently published Version',
1602: 've' => 'Version used in Course',
1603: 'vu' => 'Set Version to be used in Course',
1604: 'sv' => 'Set Versions to be used in Course according to Selections below',
1605: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
1606: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1607: 'di' => 'Differences');
1608: $r->print(<<ENDHEADERS);
1609: <form action="/adm/coursedocs" method="post">
1610: <input type="hidden" name="versions" value="1" />
1611: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
1612: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1613: <select name="timerange">
1614: <option value='all' $allsel>$lt{'al'}</option>
1615: <option value="-1" $startsel>$lt{'st'}</option>
1616: <option value="2592000" $monthsel>$lt{'lm'}</option>
1617: <option value="604800" $weeksel>$lt{'lw'}</option>
1618: <option value="86400" $daysel>$lt{'sy'}</option>
1619: </select>
1620: <input type="submit" name="display" value="$lt{'sd'}" />
1621: <h3>$header</h3>
1622: <input type="submit" name="setversions" value="$lt{'sv'}" />
1623: <table border="0">
1624: ENDHEADERS
1625: foreach (sort keys %changes) {
1626: if ($changes{$_}>$starttime) {
1627: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
1628: my $currentversion=&Apache::lonnet::getversion($_);
1629: if ($currentversion<0) {
1630: $currentversion=&mt('Could not be determined.');
1631: }
1632: my $linkurl=&Apache::lonnet::clutter($_);
1633: $r->print(
1634: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1635: &Apache::lonnet::gettitle($linkurl).
1636: '</b></font></td></tr>'.
1637: '<tr><td> </td>'.
1638: '<td colspan="4">'.
1639: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
1640: '</a></td></tr>'.
1641: '<tr><td></td>'.
1642: '<td title="'.$lt{'md'}.'">'.
1643: &Apache::lonlocal::locallocaltime(
1644: &Apache::lonnet::metadata($root.'.'.$extension,
1645: 'lastrevisiondate')
1646: ).
1647: '</td>'.
1648: '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
1649: '<font size="+1">'.$currentversion.'</font>'.
1650: '</nobr></td>'.
1651: '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
1652: '<font size="+1">');
1653: # Used in course
1654: my $usedversion=$hash{'version_'.$linkurl};
1655: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1656: $r->print($usedversion);
1657: } else {
1658: $r->print($currentversion);
1659: }
1660: $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
1661: '<nobr>Use: ');
1662: # Set version
1663: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1664: 'set_version_'.$linkurl,
1665: ('select_form_order' =>
1666: ['',1..$currentversion,'mostrecent'],
1667: '' => '',
1668: 'mostrecent' => 'most recent',
1669: map {$_,$_} (1..$currentversion))));
1670: $r->print('</nobr></td></tr><tr><td></td>');
1671: my $lastold=1;
1672: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
1673: my $url=$root.'.'.$prevvers.'.'.$extension;
1674: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
1675: $starttime) {
1676: $lastold=$prevvers;
1677: }
1678: }
1679: #
1680: # Code to figure out how many version entries should go in
1681: # each of the four columns
1682: my $entries_per_col = 0;
1683: my $num_entries = ($currentversion-$lastold);
1684: if ($num_entries % 4 == 0) {
1685: $entries_per_col = $num_entries/4;
1686: } else {
1687: $entries_per_col = $num_entries/4 + 1;
1688: }
1689: my $entries_count = 0;
1690: $r->print('<td valign="top"><font size="-2">');
1691: my $cols_output = 1;
1692: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1693: my $url=$root.'.'.$prevvers.'.'.$extension;
1694: $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
1695: '">'.&mt('Version').' '.$prevvers.'</a> ('.
1696: &Apache::lonlocal::locallocaltime(
1697: &Apache::lonnet::metadata($url,
1698: 'lastrevisiondate')
1699: ).
1700: ')');
1701: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1702: $r->print(' <a href="/adm/diff?filename='.
1703: &Apache::lonnet::clutter($root.'.'.$extension).
1704: '&versionone='.$prevvers.
1705: '">'.&mt('Diffs').'</a>');
1706: }
1707: $r->print('</nobr><br />');
1708: if (++$entries_count % $entries_per_col == 0) {
1709: $r->print('</font></td>');
1710: if ($cols_output != 4) {
1711: $r->print('<td valign="top"><font size="-2">');
1712: $cols_output++;
1713: }
1714: }
1715: }
1716: while($cols_output++ < 4) {
1717: $r->print('</font></td><td><font>')
1718: }
1719: $r->print('</font></td></tr>'."\n");
1720: }
1721: }
1722: $r->print('</table></form>');
1723: $r->print('<h1>'.&mt('Done').'.</h1>');
1724:
1725: &untiehash();
1726: }
1727:
1728: sub mark_hash_old {
1729: my $retie_hash=0;
1730: if ($hashtied) {
1731: $retie_hash=1;
1732: &untiehash();
1733: }
1734: &tiehash('write');
1735: $hash{'old'}=1;
1736: &untiehash();
1737: if ($retie_hash) { &tiehash(); }
1738: }
1739:
1740: sub is_hash_old {
1741: my $untie_hash=0;
1742: if (!$hashtied) {
1743: $untie_hash=1;
1744: &tiehash();
1745: }
1746: my $return=$hash{'old'};
1747: if ($untie_hash) { &untiehash(); }
1748: return $return;
1749: }
1750:
1751: sub changewarning {
1752: my ($r,$postexec)=@_;
1753: if (!&is_hash_old()) { return; }
1754: my $pathvar='folderpath';
1755: my $path=&Apache::lonnet::escape($ENV{'form.folderpath'});
1756: if (defined($ENV{'form.pagepath'})) {
1757: $pathvar='pagepath';
1758: $path=&Apache::lonnet::escape($ENV{'form.pagepath'});
1759: $path.='&symb='.&Apache::lonnet::escape($ENV{'form.pagesymb'});
1760: }
1761: $r->print(
1762: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
1763: '<form method="post" action="/adm/roles" target="loncapaclient">'.
1764: '<input type="hidden" name="orgurl" value="/adm/coursedocs?'.
1765: $pathvar.'='.$path.
1766: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1767: &mt('Changes will become active for your current session after').
1768: ' <input type="hidden" name="'.
1769: $ENV{'request.role'}.'" value="1" /><input type="button" value="'.
1770: &mt('re-initializing course').'" onClick="reinit(this.form)"/>'.&mt(', or the next time you log in.').
1771: $help{'Caching'}.'</font></h3></form>');
1772: }
1773:
1774: # ================================================================ Main Handler
1775: sub handler {
1776: my $r = shift;
1777: &Apache::loncommon::content_type($r,'text/html');
1778: $r->send_http_header;
1779: return OK if $r->header_only;
1780:
1781: # --------------------------------------------- Initialize help topics for this
1782: foreach ('Adding_Course_Doc','Main_Course_Documents',
1783: 'Adding_External_Resource','Navigate_Content',
1784: 'Adding_Folders','Docs_Overview', 'Load_Map',
1785: 'Supplemental','Score_Upload_Form','Adding_Pages',
1786: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
1787: 'Check_Resource_Versions','Verify_Content') {
1788: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
1789: }
1790: # Composite help files
1791: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
1792: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
1793: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
1794: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1795: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
1796: 'Option_Response_Simple');
1797: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
1798: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1799: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
1800: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1801: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1802:
1803: if ($ENV{'form.verify'}) {
1804: &verifycontent($r);
1805: } elsif ($ENV{'form.versions'}) {
1806: &checkversions($r);
1807: } elsif ($ENV{'form.dumpcourse'}) {
1808: &dumpcourse($r);
1809: } elsif ($ENV{'form.exportcourse'}) {
1810: &exportcourse($r);
1811: } else {
1812: # is this a standard course?
1813:
1814: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1815: my $forcestandard = 0;
1816: my $forcesupplement;
1817: my $script='';
1818: my $allowed;
1819: my $events='';
1820: my $showdoc=0;
1821: my $containertag;
1822: my $uploadtag;
1823: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1824: ['folderpath','pagepath','pagesymb']);
1825: if ($ENV{'form.folderpath'}) {
1826: my (@folderpath)=split('&',$ENV{'form.folderpath'});
1827: $ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
1828: $ENV{'form.folder'}=pop(@folderpath);
1829: }
1830: if ($ENV{'form.pagepath'}) {
1831: my (@pagepath)=split('&',$ENV{'form.pagepath'});
1832: $ENV{'form.pagename'}=&Apache::lonnet::unescape(pop(@pagepath));
1833: $ENV{'form.folder'}=pop(@pagepath);
1834: $containertag = '<input type="hidden" name="pagepath" value="" />'.
1835: '<input type="hidden" name="pagesymb" value="" />';
1836: $uploadtag = '<input type="hidden" name="pagepath" value="'.$ENV{'form.pagepath'}.'" />'.
1837: '<input type="hidden" name="pagesymb" value="'.$ENV{'form.pagesymb'}.'" />';
1838: }
1839: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1840: $showdoc='/'.$1;
1841: }
1842: unless ($showdoc) { # got called from remote
1843: if (($ENV{'form.folder'}=~/^default_/) ||
1844: ($ENV{'form.folder'} =~ m#^\d+/(pages|sequences)/#)) {
1845: $forcestandard = 1;
1846: }
1847: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1848:
1849: # does this user have privileges to post, etc?
1850: $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1851: if ($allowed) {
1852: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1853: $script=&Apache::lonratedt::editscript('simple');
1854: }
1855: } else { # got called in sequence from course
1856: $allowed=0;
1857: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
1858: $events='onLoad="'.&Apache::lonmenu::loadevents.
1859: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1860: }
1861:
1862: # get course data
1863: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
1864: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1865:
1866: # get personal data
1867:
1868: my $uname=$ENV{'user.name'};
1869: my $udom=$ENV{'user.domain'};
1870: my $plainname=&Apache::lonnet::escape(
1871: &Apache::loncommon::plainname($uname,$udom));
1872:
1873: # graphics settings
1874:
1875: $iconpath = $r->dir_config('lonIconsURL') . "/";
1876:
1877: my $now=time;
1878:
1879: # print screen
1880: $r->print(<<ENDDOCUMENT);
1881: <html>
1882: <head>
1883: <title>The LearningOnline Network with CAPA</title>
1884: <script>
1885: $script
1886: </script>
1887: ENDDOCUMENT
1888: if ($allowed) {
1889: $r->print(<<ENDNEWSCRIPT);
1890: <script>
1891: function makenewfolder(targetform,folderseq) {
1892: var foldername=prompt('Name of New Folder','New Folder');
1893: if (foldername) {
1894: targetform.importdetail.value=foldername+"="+folderseq;
1895: targetform.submit();
1896: }
1897: }
1898:
1899: function makenewpage(targetform,folderseq) {
1900: var pagename=prompt('Name of New Page','New Page');
1901: if (pagename) {
1902: targetform.importdetail.value=pagename+"="+folderseq;
1903: targetform.submit();
1904: }
1905: }
1906:
1907: function makenewext(targetname) {
1908: this.document.forms.extimport.useform.value=targetname;
1909: window.open('/adm/rat/extpickframe.html');
1910: }
1911:
1912: function makeexamupload() {
1913: var title=prompt('Listed Title for the Uploaded Score');
1914: if (title) {
1915: this.document.forms.newexamupload.importdetail.value=
1916: title+'=/res/lib/templates/examupload.problem';
1917: this.document.forms.newexamupload.submit();
1918: }
1919: }
1920:
1921: function makesmppage() {
1922: var title=prompt('Listed Title for the Page');
1923: if (title) {
1924: this.document.forms.newsmppg.importdetail.value=
1925: title+'=/adm/$udom/$uname/$now/smppg';
1926: this.document.forms.newsmppg.submit();
1927: }
1928: }
1929:
1930: function makesmpproblem() {
1931: var title=prompt('Listed Title for the Problem');
1932: if (title) {
1933: this.document.forms.newsmpproblem.importdetail.value=
1934: title+'=/res/lib/templates/simpleproblem.problem';
1935: this.document.forms.newsmpproblem.submit();
1936: }
1937: }
1938:
1939: function makebulboard() {
1940: var title=prompt('Listed Title for the Bulletin Board');
1941: if (title) {
1942: this.document.forms.newbul.importdetail.value=
1943: title+'=/adm/$udom/$uname/$now/bulletinboard';
1944: this.document.forms.newbul.submit();
1945: }
1946: }
1947:
1948: function makeabout() {
1949: var user=prompt("Enter user\@domain for User's 'About Me' Page");
1950: if (user) {
1951: var comp=new Array();
1952: comp=user.split('\@');
1953: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
1954: if ((comp[0]) && (comp[1])) {
1955: this.document.forms.newaboutsomeone.importdetail.value=
1956: 'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1957: this.document.forms.newaboutsomeone.submit();
1958: }
1959: }
1960: }
1961: }
1962:
1963: function makeims() {
1964: var caller = document.forms.ims.folder.value
1965: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
1966: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
1967: newWindow.location.href = newlocation
1968: }
1969:
1970:
1971: function finishpick() {
1972: var title=this.document.forms.extimport.title.value;
1973: var url=this.document.forms.extimport.url.value;
1974: var form=this.document.forms.extimport.useform.value;
1975: eval
1976: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
1977: '";this.document.forms.'+form+'.submit();');
1978: }
1979:
1980: function changename(folderpath,index,oldtitle,container,pagesymb) {
1981: var title=prompt('New Title',oldtitle);
1982: if (title) {
1983: this.document.forms.renameform.title.value=title;
1984: this.document.forms.renameform.cmd.value='rename_'+index;
1985: if (container == 'sequence') {
1986: this.document.forms.renameform.folderpath.value=folderpath;
1987: }
1988: if (container == 'page') {
1989: this.document.forms.renameform.pagepath.value=folderpath;
1990: this.document.forms.renameform.pagesymb.value=pagesymb;
1991: }
1992: this.document.forms.renameform.submit();
1993: }
1994: }
1995:
1996: function removeres(folderpath,index,oldtitle,container,pagesymb) {
1997: if (confirm('Remove "'+oldtitle+'"?')) {
1998: this.document.forms.renameform.cmd.value='del_'+index;
1999: if (container == 'sequence') {
2000: this.document.forms.renameform.folderpath.value=folderpath;
2001: }
2002: if (container == 'page') {
2003: this.document.forms.renameform.pagepath.value=folderpath;
2004: this.document.forms.renameform.pagesymb.value=pagesymb;
2005: }
2006: this.document.forms.renameform.submit();
2007: }
2008: }
2009:
2010: </script>
2011:
2012: ENDNEWSCRIPT
2013: }
2014: # -------------------------------------------------------------------- Body tag
2015: $r->print('</head>'.
2016: &Apache::loncommon::bodytag('Course Documents','',$events,
2017: '','',$showdoc).
2018: &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
2019: unless ($showdoc) {
2020: # -----------------------------------------------------------------------------
2021: my %lt=&Apache::lonlocal::texthash(
2022: 'uplm' => 'Upload a new main course document',
2023: 'upls' => 'Upload a new supplemental course document',
2024: 'impp' => 'Import a published document',
2025: 'spec' => 'Special documents',
2026: 'upld' => 'Upload Document',
2027: 'srch' => 'Search',
2028: 'impo' => 'Import',
2029: 'selm' => 'Select Map',
2030: 'load' => 'Load Map',
2031: 'newf' => 'New Folder',
2032: 'newp' => 'New Composite Page',
2033: 'extr' => 'External Resource',
2034: 'syll' => 'Syllabus',
2035: 'navc' => 'Navigate Contents',
2036: 'sipa' => 'Simple Page',
2037: 'sipr' => 'Simple Problem',
2038: 'scuf' => 'Score Upload Form',
2039: 'bull' => 'Bulletin Board',
2040: 'mypi' => 'My Personal Info',
2041: 'abou' => 'About User',
2042: 'imsf' => 'Import IMS package',
2043: 'file' => 'File',
2044: 'title' => 'Title',
2045: 'comment' => 'Comment'
2046: );
2047: # -----------------------------------------------------------------------------
2048: if ($allowed) {
2049: my $dumpbut=&dumpbutton();
2050: my $exportbut=&exportbutton();
2051: my %lt=&Apache::lonlocal::texthash(
2052: 'vc' => 'Verify Content',
2053: 'cv' => 'Check/Set Resource Versions',
2054: );
2055:
2056: my $folderpath=$ENV{'form.folderpath'};
2057: if (!$folderpath) {
2058: if ($ENV{'form.folder'} eq '' ||
2059: $ENV{'form.folder'} eq 'supplemental') {
2060: $folderpath='default&'.
2061: &Apache::lonnet::escape(&mt('Main Course Documents'));
2062: }
2063: }
2064: unless ($ENV{'form.pagepath'}) {
2065: $containertag = '<input type="hidden" name="folderpath" value="" />';
2066: $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
2067: }
2068:
2069: $r->print(<<ENDCOURSEVERIFY);
2070: <form name="renameform" method="post" action="/adm/coursedocs">
2071: <input type="hidden" name="title" />
2072: <input type="hidden" name="cmd" />
2073: $containertag
2074: </form>
2075: <form name="simpleedit" method="post" action="/adm/coursedocs">
2076: <input type=hidden name="importdetail" value="">
2077: $uploadtag
2078: </form>
2079: <form action="/adm/coursedocs" method="post" name="courseverify">
2080: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
2081: <tr><td bgcolor="#DDDDCC">
2082: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
2083: </td><td bgcolor="#DDDDCC">
2084: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
2085: $dumpbut
2086: $exportbut
2087: </td></tr></table>
2088: </form>
2089: ENDCOURSEVERIFY
2090: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
2091: &mt('Editing the Table of Contents for your Course')));
2092: }
2093: # --------------------------------------------------------- Standard documents
2094: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
2095: if (($standard) && ($allowed) && (!$forcesupplement)) {
2096: $r->print('<tr><td bgcolor="#BBBBBB">');
2097: # '<h2>'.&mt('Main Course Documents').
2098: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
2099: my $folder=$ENV{'form.folder'};
2100: if ($folder eq '' || $folder eq 'supplemental') {
2101: $folder='default';
2102: $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
2103: }
2104: my $postexec='';
2105: if ($folder eq 'default') {
2106: $r->print('<script>this.window.name="loncapaclient";</script>');
2107: } else {
2108: #$postexec='self.close();';
2109: }
2110: $hadchanges=0;
2111: &editor($r,$coursenum,$coursedom,$folder,$allowed);
2112: if ($hadchanges) {
2113: &mark_hash_old()
2114: }
2115: &changewarning($r,$postexec);
2116: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2117: '.sequence';
2118: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2119: '.page';
2120:
2121: $r->print(<<ENDFORM);
2122: <table cellspacing=4 cellpadding=4><tr>
2123: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
2124: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
2125: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
2126: </tr>
2127: <tr><td bgcolor="#DDDDDD">
2128: $lt{'file'}:<br />
2129: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
2130: <input type="file" name="uploaddoc" size="40">
2131: <br />
2132: $lt{'title'}:<br />
2133: <input type="text" size="50" name="comment">
2134: $uploadtag
2135: <input type="hidden" name="cmd" value="upload_default">
2136: <nobr>
2137: <input type="submit" value="$lt{'upld'}">
2138: $help{'Uploading_From_Harddrive'}
2139: </nobr>
2140: </form>
2141: </td>
2142: <td bgcolor="#DDDDDD">
2143: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
2144: $uploadtag
2145: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
2146: <nobr>
2147: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
2148: $help{'Importing_LON-CAPA_Resource'}
2149: </nobr>
2150: <p>
2151: <hr />
2152: <input type="text" size="20" name="importmap"><br />
2153: <nobr><input type=button
2154: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
2155: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
2156: $help{'Load_Map'}</nobr>
2157: </p>
2158: </form>
2159: </td>
2160: <td bgcolor="#DDDDDD">
2161: ENDFORM
2162: unless ($ENV{'form.pagepath'}) {
2163: $r->print(<<ENDFORM);
2164: <form action="/adm/coursedocs" method="post" name="newfolder">
2165: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2166: <input type=hidden name="importdetail" value="">
2167: <nobr>
2168: <input name="newfolder" type="button"
2169: onClick="javascript:makenewfolder(this.form,'$folderseq');"
2170: value="$lt{'newf'}" />$help{'Adding_Folders'}
2171: </nobr>
2172: </form>
2173: <form action="/adm/coursedocs" method="post" name="newpage">
2174: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2175: <input type=hidden name="importdetail" value="">
2176: <nobr>
2177: <input name="newpage" type="button"
2178: onClick="javascript:makenewpage(this.form,'$pageseq');"
2179: value="$lt{'newp'}" />$help{'Adding_Pages'}
2180: </nobr>
2181: </form>
2182: <form action="/adm/coursedocs" method="post" name="newext">
2183: $uploadtag
2184: <input type=hidden name="importdetail" value="">
2185: <nobr>
2186: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
2187: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
2188: </nobr>
2189: </form>
2190: <form action="/adm/coursedocs" method="post" name="newsyl">
2191: $uploadtag
2192: <input type=hidden name="importdetail"
2193: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
2194: <nobr>
2195: <input name="newsyl" type="submit" value="$lt{'syll'}" />
2196: $help{'Syllabus'}
2197: </nobr>
2198: </form>
2199: <form action="/adm/coursedocs" method="post" name="newnav">
2200: $uploadtag
2201: <input type=hidden name="importdetail"
2202: value="Navigate Content=/adm/navmaps">
2203: <nobr>
2204: <input name="newnav" type="submit" value="$lt{'navc'}" />
2205: $help{'Navigate_Content'}
2206: </nobr>
2207: </form>
2208: <form action="/adm/coursedocs" method="post" name="newsmppg">
2209: $uploadtag
2210: <input type=hidden name="importdetail" value="">
2211: <nobr>
2212: <input name="newsmppg" type="button" value="$lt{'sipa'}"
2213: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
2214: </nobr>
2215: </form>
2216: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
2217: $uploadtag
2218: <input type=hidden name="importdetail" value="">
2219: <nobr>
2220: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2221: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2222: </nobr>
2223: </form>
2224: <form action="/adm/coursedocs" method="post" name="newexamupload">
2225: $uploadtag
2226: <input type=hidden name="importdetail" value="">
2227: <nobr>
2228: <input name="newexamupload" type="button" value="$lt{'scuf'}"
2229: onClick="javascript:makeexamupload();" />
2230: $help{'Score_Upload_Form'}
2231: </nobr>
2232: </form>
2233: <form action="/adm/coursedocs" method="post" name="newbul">
2234: $uploadtag
2235: <input type=hidden name="importdetail" value="">
2236: <nobr>
2237: <input name="newbulletin" type="button" value="$lt{'bull'}"
2238: onClick="javascript:makebulboard();" />
2239: $help{'Bulletin Board'}
2240: </nobr>
2241: </form>
2242: <form action="/adm/coursedocs" method="post" name="newaboutme">
2243: $uploadtag
2244: <input type=hidden name="importdetail"
2245: value="$plainname=/adm/$udom/$uname/aboutme">
2246: <nobr>
2247: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
2248: $help{'My Personal Info'}
2249: </nobr>
2250: </form>
2251: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
2252: $uploadtag
2253: <input type=hidden name="importdetail" value="">
2254: <nobr>
2255: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
2256: onClick="javascript:makeabout();" />
2257: </nobr>
2258: ENDFORM
2259: }
2260: if ($ENV{'form.pagepath'}) {
2261: $r->print(<<ENDBLOCK);
2262: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
2263: $uploadtag
2264: <input type=hidden name="importdetail" value="">
2265: <nobr>
2266: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2267: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2268: </nobr>
2269: </form>
2270: <form action="/adm/coursedocs" method="post" name="newexamupload">
2271: $uploadtag
2272: <input type=hidden name="importdetail" value="">
2273: <nobr>
2274: <input name="newexamupload" type="button" value="$lt{'scuf'}"
2275: onClick="javascript:makeexamupload();" />
2276: $help{'Score_Upload_Form'}
2277: </nobr>
2278: </form>
2279: ENDBLOCK
2280: } else {
2281: $r->print(<<ENDFORM);
2282: </form>
2283: <form action="/adm/imsimportdocs" method="post" name="ims">
2284: <input type="hidden" name="folder" value="$folder" />
2285: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
2286: </nobr>
2287: </form>
2288: ENDFORM
2289: }
2290: $r->print('</td></tr>'."\n".
2291: '</table>');
2292: $r->print('</td></tr>');
2293: }
2294: # ----------------------------------------------------- Supplemental documents
2295: if (!$forcestandard) {
2296: $r->print('<tr><td bgcolor="#BBBBBB">');
2297: # '<h2>'.&mt('Supplemental Course Documents').
2298: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
2299: my $folder=$ENV{'form.folder'};
2300: unless ($folder=~/^supplemental/) {
2301: $folder='supplemental';
2302: }
2303: if ($folder =~ /^supplemental$/ &&
2304: $ENV{'form.folderpath'} =~ /^default\&/) {
2305: $ENV{'form.folderpath'}='supplemental&'.
2306: &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
2307: }
2308: &editor($r,$coursenum,$coursedom,$folder,$allowed);
2309: if ($allowed) {
2310: my $folderseq=
2311: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
2312: '.sequence';
2313:
2314: $r->print(<<ENDSUPFORM);
2315: <table cellspacing=4 cellpadding=4><tr>
2316: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
2317: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
2318: </tr>
2319: <tr><td bgcolor="#DDDDDD">
2320: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
2321: <input type="file" name="uploaddoc" size="40">
2322: <br />$lt{'comment'}:<br />
2323: <textarea cols=50 rows=4 name='comment'>
2324: </textarea>
2325: <br />
2326: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2327: <input type="hidden" name="cmd" value="upload_supplemental">
2328: <nobr>
2329: <input type="submit" value="$lt{'upld'}">
2330: $help{'Uploading_From_Harddrive'}
2331: </nobr>
2332: </form>
2333: </td>
2334: <td bgcolor="#DDDDDD">
2335: <form action="/adm/coursedocs" method="post" name="supnewfolder">
2336: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2337: <input type=hidden name="importdetail" value="">
2338: <nobr>
2339: <input name="newfolder" type="button"
2340: onClick="javascript:makenewfolder(this.form,'$folderseq');"
2341: value="$lt{'newf'}" /> $help{'Adding_Folders'}
2342: </nobr>
2343: </form>
2344: <form action="/adm/coursedocs" method="post" name="supnewext">
2345: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2346: <input type=hidden name="importdetail" value="">
2347: <nobr>
2348: <input name="newext" type="button"
2349: onClick="javascript:makenewext('supnewext');"
2350: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
2351: </nobr>
2352: </form>
2353: <form action="/adm/coursedocs" method="post" name="supnewsyl">
2354: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2355: <input type=hidden name="importdetail"
2356: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
2357: <nobr>
2358: <input name="newsyl" type="submit" value="$lt{'syll'}" />
2359: $help{'Syllabus'}
2360: </nobr>
2361: </form>
2362: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
2363: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2364: <input type=hidden name="importdetail"
2365: value="$plainname=/adm/$udom/$uname/aboutme">
2366: <nobr>
2367: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
2368: $help{'My Personal Info'}
2369: </nobr>
2370: </form>
2371: </td></tr>
2372: </table></td></tr>
2373: ENDSUPFORM
2374: }
2375: }
2376: if ($allowed) {
2377: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
2378: }
2379: $r->print('</table>');
2380: } else {
2381: # -------------------------------------------------------- This is showdoc mode
2382: $r->print("<h1>".&mt('Uploaded Document').' - '.
2383: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
2384: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
2385: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
2386: }
2387: }
2388: $r->print('</body></html>');
2389: return OK;
2390: }
2391:
2392: 1;
2393: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>