1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.283 2007/07/03 00:17:42 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 LONCAPA::map();
37: use Apache::lonratedt();
38: use Apache::lonxml;
39: use Apache::lonclonecourse;
40: use Apache::lonnavmaps;
41: use HTML::Entities;
42: use GDBM_File;
43: use Apache::lonlocal;
44: use Cwd;
45: use LONCAPA qw(:DEFAULT :match);
46:
47: my $iconpath;
48:
49: my %hash;
50:
51: my $hashtied;
52: my %alreadyseen=();
53:
54: my $hadchanges;
55:
56: # Available help topics
57:
58: my %help=();
59:
60: # Mapread read maps into LONCAPA::map:: global arrays
61: # @order and @resources, determines status
62: # sets @order - pointer to resources in right order
63: # sets @resources - array with the resources with correct idx
64: #
65:
66: sub mapread {
67: my ($coursenum,$coursedom,$map)=@_;
68: return
69: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
70: $map);
71: }
72:
73: sub storemap {
74: my ($coursenum,$coursedom,$map)=@_;
75: my ($outtext,$errtext)=
76: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
77: $map,1);
78: if ($errtext) { return ($errtext,2); }
79:
80: $hadchanges=1;
81: return ($errtext,0);
82: }
83:
84: # ----------------------------------------- Return hash with valid author names
85:
86: sub authorhosts {
87: my %outhash=();
88: my $home=0;
89: my $other=0;
90: foreach (keys %env) {
91: if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
92: my $role=$1;
93: my $realm=$2;
94: my ($start,$end)=split(/\./,$env{$_});
95: if (($start) && ($start>time)) { next; }
96: if (($end) && (time>$end)) { next; }
97: my $ca; my $cd;
98: if ($1 eq 'au') {
99: $ca=$env{'user.name'};
100: $cd=$env{'user.domain'};
101: } else {
102: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
103: }
104: my $allowed=0;
105: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
106: my @ids=&Apache::lonnet::current_machine_ids();
107: foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
108: if ($allowed) {
109: $home++;
110: $outhash{'home_'.$ca.'@'.$cd}=1;
111: } else {
112: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
113: $other++;
114: }
115: }
116: }
117: return ($home,$other,%outhash);
118: }
119: # ------------------------------------------------------ Generate "dump" button
120:
121: sub dumpbutton {
122: my ($home,$other,%outhash)=&authorhosts();
123: my $type = &Apache::loncommon::course_type();
124: if ($home+$other==0) { return ''; }
125: if ($home) {
126: return '<div>'.
127: '<input type="submit" name="dumpcourse" value="'.
128: &mt('Dump '.$type.' DOCS to Construction Space').'" />'.
129: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').
130: '</div>';
131: } else {
132: return '<div>'.
133: &mt('Dump '.$type.
134: ' DOCS to Construction Space: available on other servers').
135: '</div>';
136: }
137: }
138:
139: sub clean {
140: my ($title)=@_;
141: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
142: return $title;
143: }
144: # -------------------------------------------------------- Actually dump course
145:
146: sub dumpcourse {
147: my ($r) = @_;
148: my $type = &Apache::loncommon::course_type();
149: $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space').
150: '<form name="dumpdoc" method="post">');
151: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$type.' DOCS to Construction Space'));
152: my ($home,$other,%outhash)=&authorhosts();
153: unless ($home) { return ''; }
154: my $origcrsid=$env{'request.course.id'};
155: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
156: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
157: # Do the dumping
158: unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }
159: my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
160: $r->print('<h3>'.&mt('Copying Files').'</h3>');
161: my $title=$env{'form.authorfolder'};
162: $title=&clean($title);
163: my %replacehash=();
164: foreach (keys %env) {
165: if ($_=~/^form\.namefor\_(.+)/) {
166: $replacehash{$1}=$env{$_};
167: }
168: }
169: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
170: $crs=~s/\_/\//g;
171: foreach (keys %replacehash) {
172: my $newfilename=$title.'/'.$replacehash{$_};
173: $newfilename=~s/\.(\w+)$//;
174: my $ext=$1;
175: $newfilename=&clean($newfilename);
176: $newfilename.='.'.$ext;
177: my @dirs=split(/\//,$newfilename);
178: my $path='/home/'.$ca.'/public_html';
179: my $makepath=$path;
180: my $fail=0;
181: for (my $i=0;$i<$#dirs;$i++) {
182: $makepath.='/'.$dirs[$i];
183: unless (-e $makepath) {
184: unless(mkdir($makepath,0777)) { $fail=1; }
185: }
186: }
187: $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
188: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
189: if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
190: print $fh &Apache::lonclonecourse::rewritefile(
191: &Apache::lonclonecourse::readfile($env{'request.course.id'},$_),
192: (%replacehash,$crs => '')
193: );
194: } else {
195: print $fh
196: &Apache::lonclonecourse::readfile($env{'request.course.id'},$_);
197: }
198: $fh->close();
199: } else {
200: $fail=1;
201: }
202: if ($fail) {
203: $r->print('<span class="LC_error">'.&mt('fail').'</span>');
204: } else {
205: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
206: }
207: }
208: } else {
209: # Input form
210: unless ($home==1) {
211: $r->print(
212: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
213: }
214: foreach (sort keys %outhash) {
215: if ($_=~/^home_(.+)$/) {
216: if ($home==1) {
217: $r->print(
218: '<input type="hidden" name="authorspace" value="'.$1.'" />');
219: } else {
220: $r->print('<option value="'.$1.'">'.$1.' - '.
221: &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
222: }
223: }
224: }
225: unless ($home==1) {
226: $r->print('</select>');
227: }
228: my $title=$origcrsdata{'description'};
229: $title=~s/[\/\s]+/\_/gs;
230: $title=&clean($title);
231: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
232: &tiehash();
233: $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>');
234: foreach (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
235: $r->print('<tr><td>'.$_.'</td>');
236: my ($ext)=($_=~/\.(\w+)$/);
237: my $title=$hash{'title_'.$hash{
238: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
239: $r->print('<td>'.($title?$title:' ').'</td>');
240: if (!$title) {
241: $title=$_;
242: } else {
243: $title=~s|/|_|g;
244: }
245: $title=~s/\.(\w+)$//;
246: $title=&clean($title);
247: $title.='.'.$ext;
248: $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
249: }
250: $r->print("</table>\n");
251: &untiehash();
252: $r->print(
253: '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump [_1] DOCS',$type).'" /></p></form>');
254: }
255: }
256:
257: # ------------------------------------------------------ Generate "export" button
258:
259: sub exportbutton {
260: my $type = &Apache::loncommon::course_type();
261: return '<div>'.
262: '<input type="submit" name="exportcourse" value="'.
263: &mt('Export '.$type.' to IMS').'" />'.
264: &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'</div>';
265: }
266:
267: sub exportcourse {
268: my $r=shift;
269: my $type = &Apache::loncommon::course_type();
270: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
271: $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
272: my $numdisc = keys %discussiontime;
273: my $navmap = Apache::lonnavmaps::navmap->new();
274: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
275: my $curRes;
276: my $outcome;
277:
278: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
279: ['finishexport']);
280: if ($env{'form.finishexport'}) {
281: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
282: ['archive','discussion']);
283:
284: my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
285: my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
286: if (@exportitems == 0 && @discussions == 0) {
287: $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';
288: } else {
289: my $now = time;
290: my %symbs;
291: my $manifestok = 0;
292: my $imsresources;
293: my $tempexport;
294: my $copyresult;
295: my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
296: if ($manifestok) {
297: &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
298: close($ims_manifest);
299:
300: #Create zip file in prtspool
301: my $imszipfile = '/prtspool/'.
302: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
303: time.'_'.rand(1000000000).'.zip';
304: my $cwd = &Cwd::getcwd();
305: my $imszip = '/home/httpd/'.$imszipfile;
306: chdir $tempexport;
307: open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
308: close(OUTPUT);
309: chdir $cwd;
310: $outcome .= &mt('Download the zip file from <a href="[_1]">IMS '.lc($type).' archive</a><br />',$imszipfile,);
311: if ($copyresult) {
312: $outcome .= 'The following errors occurred during export - '.$copyresult;
313: }
314: } else {
315: $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 />';
316: }
317: }
318: $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package'));
319: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));
320: $r->print($outcome);
321: $r->print(&Apache::loncommon::end_page());
322: } else {
323: my $display;
324: $display = '<form name="exportdoc" method="post">'."\n";
325: $display .= &mt('Choose which items you wish to export from your '.$type.'.<br /><br />');
326: $display .= '<table border="0" cellspacing="0" cellpadding="3">'.
327: '<tr><td><fieldset><legend> <b>Content items</b></legend>'.
328: '<input type="button" value="check all" '.
329: 'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
330: ' <input type="button" value="uncheck all"'.
331: ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.
332: '<td> </td><td> </td>'.
333: '<td align="right"><fieldset><legend> <b>Discussion posts'.
334: '</b></legend><input type="button" value="check all"'.
335: ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
336: ' <input type="button" value="uncheck all"'.
337: ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.
338: '</tr></table>';
339: my $curRes;
340: my $depth = 0;
341: my $count = 0;
342: my $boards = 0;
343: my $startcount = 5;
344: my %parent = ();
345: my %children = ();
346: my $lastcontainer = $startcount;
347: my @bgcolors = ('#F6F6F6','#FFFFFF');
348: $display .= '<table cellspacing="0"><tr>'.
349: '<td><b>Export content item?<br /></b></td><td> </td><td align="right">'."\n";
350: if ($numdisc > 0) {
351: $display.='<b>Export discussion posts?</b>'."\n";
352: }
353: $display.=' </td></tr>';
354: while ($curRes = $it->next()) {
355: if (ref($curRes)) {
356: $count ++;
357: }
358: if ($curRes == $it->BEGIN_MAP()) {
359: $depth++;
360: $parent{$depth} = $lastcontainer;
361: }
362: if ($curRes == $it->END_MAP()) {
363: $depth--;
364: $lastcontainer = $parent{$depth};
365: }
366: if (ref($curRes)) {
367: my $symb = $curRes->symb();
368: my $ressymb = $symb;
369: if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
370: unless ($ressymb =~ m|adm/wrapper/adm|) {
371: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
372: }
373: }
374: my $color = $count%2;
375: $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".
376: '<input type="checkbox" name="archive" value="'.$count.'" ';
377: if (($curRes->is_sequence()) || ($curRes->is_page())) {
378: my $checkitem = $count + $boards + $startcount;
379: $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';
380: }
381: $display .= ' />'."\n";
382: for (my $i=0; $i<$depth; $i++) {
383: $display .= '<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" /><img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" />'."\n";
384: }
385: if ($curRes->is_sequence()) {
386: $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif"> '."\n";
387: $lastcontainer = $count + $startcount + $boards;
388: } elsif ($curRes->is_page()) {
389: $display .= '<img src="/adm/lonIcons/navmap.page.open.gif"> '."\n";
390: $lastcontainer = $count + $startcount + $boards;
391: }
392: my $currelem = $count+$boards+$startcount;
393: $children{$parent{$depth}} .= $currelem.':';
394: $display .= ' '.$curRes->title().'</td>';
395: if ($discussiontime{$ressymb} > 0) {
396: $boards ++;
397: $currelem = $count+$boards+$startcount;
398: $display .= '<td> </td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" /> </td>'."\n";
399: } else {
400: $display .= '<td colspan="2"> </td>'."\n";
401: }
402: }
403: }
404: my $scripttag = qq|
405: <script>
406:
407: function checkAll(field) {
408: if (field.length > 0) {
409: for (i = 0; i < field.length; i++) {
410: field[i].checked = true ;
411: }
412: } else {
413: field.checked = true
414: }
415: }
416:
417: function uncheckAll(field) {
418: if (field.length > 0) {
419: for (i = 0; i < field.length; i++) {
420: field[i].checked = false ;
421: }
422: } else {
423: field.checked = false ;
424: }
425: }
426:
427: function propagateCheck(item) {
428: if (document.exportdoc.elements[item].checked == true) {
429: containerCheck(item)
430: }
431: }
432:
433: function containerCheck(item) {
434: document.exportdoc.elements[item].checked = true
435: var numitems = $count + $boards + $startcount
436: var parents = new Array(numitems)
437: for (var i=$startcount; i<numitems; i++) {
438: parents[i] = new Array
439: }
440: |;
441:
442: foreach my $container (sort { $a <=> $b } keys %children) {
443: my @contents = split/:/,$children{$container};
444: for (my $i=0; $i<@contents; $i ++) {
445: $scripttag .= ' parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
446: }
447: }
448:
449: $scripttag .= qq|
450: if (parents[item].length > 0) {
451: for (var j=0; j<parents[item].length; j++) {
452: containerCheck(parents[item][j])
453: }
454: }
455: }
456:
457: </script>
458: |;
459: $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package',
460: $scripttag));
461: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));
462: $r->print($display.'</table>'.
463: '<p><input type="hidden" name="finishexport" value="1">'.
464: '<input type="submit" name="exportcourse" value="'.
465: &mt('Export '.$type.' DOCS').'" /></p></form>'.
466: &Apache::loncommon::end_page());
467: }
468: }
469:
470: sub create_ims_store {
471: my ($now,$manifestok,$outcome,$tempexport) = @_;
472: $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
473: my $ims_manifest;
474: if (!-e $$tempexport) {
475: mkdir($$tempexport,0700);
476: }
477: $$tempexport .= '/'.$now;
478: if (!-e $$tempexport) {
479: mkdir($$tempexport,0700);
480: }
481: $$tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
482: if (!-e $$tempexport) {
483: mkdir($$tempexport,0700);
484: }
485: if (!-e "$$tempexport/resources") {
486: mkdir("$$tempexport/resources",0700);
487: }
488: # open manifest file
489: my $manifest = '/imsmanifest.xml';
490: my $manifestfilename = $$tempexport.$manifest;
491: if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
492: $$manifestok=1;
493: print $ims_manifest
494: '<?xml version="1.0" encoding="UTF-8"?>'."\n".
495: '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
496: ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
497: ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
498: ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'.
499: ' xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
500: ' http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
501: ' <metadata>
502: <schema></schema>
503: <imsmd:lom>
504: <imsmd:general>
505: <imsmd:identifier>'.$env{'request.course.id'}.'</imsmd:identifier>
506: <imsmd:title>
507: <imsmd:langstring xml:lang="en">'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</imsmd:langstring>
508: </imsmd:title>
509: </imsmd:general>
510: </imsmd:lom>
511: </metadata>'."\n".
512: ' <organizations default="ORG-'.$env{'request.course.id'}.'-'.$now.'">'."\n".
513: ' <organization identifier="ORG-'.$env{'request.course.id'}.'-'.$now.'"'.
514: ' structure="hierarchical">'."\n".
515: ' <title>'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</title>'
516: } else {
517: $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
518: ;
519: }
520: return $ims_manifest;
521: }
522:
523: sub build_package {
524: my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
525: # first iterator to look for dependencies
526: my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
527: my $curRes;
528: my $count = 0;
529: my $depth = 0;
530: my $lastcontainer = 0;
531: my %parent = ();
532: my @dependencies = ();
533: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
534: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
535: while ($curRes = $it->next()) {
536: if (ref($curRes)) {
537: $count ++;
538: }
539: if ($curRes == $it->BEGIN_MAP()) {
540: $depth++;
541: $parent{$depth} = $lastcontainer;
542: }
543: if ($curRes == $it->END_MAP()) {
544: $depth--;
545: $lastcontainer = $parent{$depth};
546: }
547: if (ref($curRes)) {
548: if ($curRes->is_sequence() || $curRes->is_page()) {
549: $lastcontainer = $count;
550: }
551: if (grep/^$count$/,@$exportitems) {
552: &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
553: }
554: }
555: }
556: # second iterator to build manifest and store resources
557: $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
558: $depth = 0;
559: my $prevdepth;
560: $count = 0;
561: my $imsresources;
562: my $pkgdepth;
563: while ($curRes = $it->next()) {
564: if ($curRes == $it->BEGIN_MAP()) {
565: $prevdepth = $depth;
566: $depth++;
567: }
568: if ($curRes == $it->END_MAP()) {
569: $prevdepth = $depth;
570: $depth--;
571: }
572:
573: if (ref($curRes)) {
574: $count ++;
575: if ((grep/^$count$/,@$exportitems) || (grep/^$count$/,@dependencies)) {
576: my $symb = $curRes->symb();
577: my $isvisible = 'true';
578: my $resourceref;
579: if ($curRes->randomout()) {
580: $isvisible = 'false';
581: }
582: unless ($curRes->is_sequence()) {
583: $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"';
584: }
585: my $step = $prevdepth - $depth;
586: if (($step >= 0) && ($count > 1)) {
587: while ($step >= 0) {
588: print $ims_manifest "\n".' </item>'."\n";
589: $step --;
590: }
591: }
592: $prevdepth = $depth;
593:
594: my $itementry =
595: '<item identifier="ITEM-'.$env{'request.course.id'}.'-'.$count.
596: '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
597: '<title>'.$curRes->title().'</title>';
598: print $ims_manifest "\n".$itementry;
599:
600: unless ($curRes->is_sequence()) {
601: my $content_file;
602: my @hrefs = ();
603: &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
604: if ($content_file) {
605: $imsresources .= "\n".
606: ' <resource identifier="RES-'.$env{'request.course.id'}.'-'.$count.
607: '" type="webcontent" href="'.$content_file.'">'."\n".
608: ' <file href="'.$content_file.'" />'."\n";
609: foreach (@hrefs) {
610: $imsresources .=
611: ' <file href="'.$_.'" />'."\n";
612: }
613: if (grep/^$count$/,@$discussions) {
614: my $ressymb = $symb;
615: my $mode;
616: if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
617: unless ($ressymb =~ m|adm/wrapper/adm|) {
618: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
619: }
620: $mode = 'board';
621: }
622: my %extras = (
623: caller => 'imsexport',
624: tempexport => $tempexport.'/resources',
625: count => $count
626: );
627: my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
628: }
629: $imsresources .= ' </resource>'."\n";
630: }
631: }
632: $pkgdepth = $depth;
633: }
634: }
635: }
636: while ($pkgdepth > 0) {
637: print $ims_manifest " </item>\n";
638: $pkgdepth --;
639: }
640: my $resource_text = qq|
641: </organization>
642: </organizations>
643: <resources>
644: $imsresources
645: </resources>
646: </manifest>
647: |;
648: print $ims_manifest $resource_text;
649: }
650:
651: sub get_dependencies {
652: my ($exportitems,$parent,$depth,$dependencies) = @_;
653: if ($depth > 1) {
654: if ((!grep/^$$parent{$depth}$/,@$exportitems) && (!grep/^$$parent{$depth}$/,@$dependencies)) {
655: push @$dependencies, $$parent{$depth};
656: if ($depth > 2) {
657: &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
658: }
659: }
660: }
661: }
662:
663: sub process_content {
664: my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
665: my $content_type;
666: my $message;
667: my @uploads = ();
668: if ($curRes->is_sequence()) {
669: $content_type = 'sequence';
670: } elsif ($curRes->is_page()) {
671: $content_type = 'page'; # need to handle individual items in pages.
672: } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
673: $content_type = 'syllabus';
674: my $contents = &Apache::imsexport::templatedpage($content_type);
675: if ($contents) {
676: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
677: }
678: } elsif ($symb =~ m-\.sequence___\d+___ext-) {
679: $content_type = 'external';
680: my $title = $curRes->title;
681: my $contents = &Apache::imsexport::external($symb,$title);
682: if ($contents) {
683: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
684: }
685: } elsif ($symb =~ m-adm/navmaps$-) {
686: $content_type = 'navmap';
687: } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
688: $content_type = 'simplepage';
689: my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);
690: if ($contents) {
691: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
692: }
693: } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {
694: $content_type = 'simpleproblem';
695: my $contents = &Apache::imsexport::simpleproblem($symb);
696: if ($contents) {
697: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
698: }
699: } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {
700: $content_type = 'examupload';
701: } elsif ($symb =~ m-adm/($match_domain)/($match_username)/(\d+)/bulletinboard$-) {
702: $content_type = 'bulletinboard';
703: my $contents = &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);
704: if ($contents) {
705: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
706: }
707: } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {
708: $content_type = 'aboutme';
709: my $contents = &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);
710: if ($contents) {
711: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
712: }
713: } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
714: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
715: } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
716: my $canedit = 0;
717: if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'}) {
718: $canedit= 1;
719: }
720: # only include problem code where current user is author
721: if ($canedit) {
722: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
723: } else {
724: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
725: }
726: } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
727: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
728: }
729: if (@uploads > 0) {
730: foreach my $item (@uploads) {
731: my $uploadmsg = '';
732: &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
733: if ($uploadmsg) {
734: $$copyresult .= $uploadmsg."\n";
735: }
736: }
737: }
738: if ($message) {
739: $$copyresult .= $message."\n";
740: }
741: }
742:
743: sub replicate_content {
744: my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
745: my ($map,$ind,$url);
746: if ($caller eq 'templateupload') {
747: $url = $symb;
748: $url =~ s#//#/#g;
749: } else {
750: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
751: }
752: my $content;
753: my $filename;
754: my $repstatus;
755: my $content_name;
756: if ($url =~ m-/([^/]+)$-) {
757: $filename = $1;
758: if (!-e $tempexport.'/resources') {
759: mkdir($tempexport.'/resources',0700);
760: }
761: if (!-e $tempexport.'/resources/'.$count) {
762: mkdir($tempexport.'/resources/'.$count,0700);
763: }
764: my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
765: my $copiedfile;
766: if ($copiedfile = Apache::File->new('>'.$destination)) {
767: my $content;
768: if ($caller eq 'resource') {
769: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
770: my $filepath = &Apache::lonnet::filelocation($respath,$url);
771: $content = &Apache::lonnet::getfile($filepath);
772: if ($content eq -1) {
773: $$message = 'Could not copy file '.$filename;
774: } else {
775: &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');
776: $repstatus = 'ok';
777: }
778: } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
779: my $rtncode;
780: $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
781: if ($repstatus eq 'ok') {
782: if ($url =~ /\.html?$/i) {
783: &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');
784: }
785: } else {
786: $$message = 'Could not render '.$url.' server message - '.$rtncode."<br />\n";
787: }
788: } elsif ($caller eq 'noedit') {
789: # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
790: $repstatus = 'ok';
791: $content = 'Not the owner of this resource';
792: }
793: if ($repstatus eq 'ok') {
794: print $copiedfile $content;
795: }
796: close($copiedfile);
797: } else {
798: $$message = 'Could not open destination file for '.$filename."<br />\n";
799: }
800: } else {
801: $$message = 'Could not determine name of file for '.$symb."<br />\n";
802: }
803: if ($repstatus eq 'ok') {
804: $content_name = 'resources/'.$count.'/'.$filename;
805: }
806: return $content_name;
807: }
808:
809: sub extract_media {
810: my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
811: my ($dirpath,$container);
812: my %allfiles = ();
813: my %codebase = ();
814: if ($url =~ m-(.*/)([^/]+)$-) {
815: $dirpath = $1;
816: $container = $2;
817: } else {
818: $dirpath = $url;
819: $container = '';
820: }
821: &Apache::lonnet::extract_embedded_items(undef,undef,\%allfiles,\%codebase,$content);
822: foreach my $embed_file (keys(%allfiles)) {
823: my $filename;
824: if ($embed_file =~ m#([^/]+)$#) {
825: $filename = $1;
826: } else {
827: $filename = $embed_file;
828: }
829: my $newname = 'res/'.$filename;
830: my ($rtncode,$embed_content,$repstatus);
831: my $embed_url;
832: if ($embed_file =~ m-^/-) {
833: $embed_url = $embed_file; # points to absolute path
834: } else {
835: if ($embed_file =~ m-https?://-) {
836: next; # points to url
837: } else {
838: $embed_url = $dirpath.$embed_file; # points to relative path
839: }
840: }
841: if ($caller eq 'resource') {
842: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
843: my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
844: $embed_content = &Apache::lonnet::getfile($embed_path);
845: unless ($embed_content eq -1) {
846: $repstatus = 'ok';
847: }
848: } elsif ($caller eq 'uploaded') {
849:
850: $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
851: }
852: if ($repstatus eq 'ok') {
853: my $destination = $tempexport.'/resources/'.$count.'/res';
854: if (!-e "$destination") {
855: mkdir($destination,0755);
856: }
857: $destination .= '/'.$filename;
858: my $copiedfile;
859: if ($copiedfile = Apache::File->new('>'.$destination)) {
860: print $copiedfile $embed_content;
861: push @{$href}, 'resources/'.$count.'/res/'.$filename;
862: my $attrib_regexp = '';
863: if (@{$allfiles{$embed_file}} > 1) {
864: $attrib_regexp = join('|',@{$allfiles{$embed_file}});
865: } else {
866: $attrib_regexp = $allfiles{$embed_file}[0];
867: }
868: $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
869: if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {
870: $$content =~ s#\Q$embed_file\E#$newname#gi;
871: }
872: }
873: } else {
874: $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";
875: }
876: }
877: return;
878: }
879:
880: sub store_template {
881: my ($contents,$tempexport,$count,$content_type) = @_;
882: if ($contents) {
883: if ($tempexport) {
884: if (!-e $tempexport.'/resources') {
885: mkdir($tempexport.'/resources',0700);
886: }
887: if (!-e $tempexport.'/resources/'.$count) {
888: mkdir($tempexport.'/resources/'.$count,0700);
889: }
890: my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
891: my $storetemplate;
892: if ($storetemplate = Apache::File->new('>'.$destination)) {
893: print $storetemplate $contents;
894: close($storetemplate);
895: }
896: if ($content_type eq 'external') {
897: return 'resources/'.$count.'/'.$content_type.'.html';
898: } else {
899: return 'resources/'.$count.'/'.$content_type.'.xml';
900: }
901: }
902: }
903: }
904:
905: # Imports the given (name, url) resources into the course
906: # coursenum, coursedom, and folder must precede the list
907: sub group_import {
908: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
909:
910: while (@files) {
911: my $name = shift(@files);
912: my $url = shift(@files);
913: #FIXME check if file exists before overwriting, might be restoring it
914: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
915: && ($caller eq 'londocs')
916: && (!&Apache::lonnet::stat_file($url))) {
917:
918: my $errtext = '';
919: my $fatal = 0;
920: my $newmapstr = '<map>'."\n".
921: '<resource id="1" src="" type="start"></resource>'."\n".
922: '<link from="1" to="2" index="1"></link>'."\n".
923: '<resource id="2" src="" type="finish"></resource>'."\n".
924: '</map>';
925: $env{'form.output'}=$newmapstr;
926: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
927: 'output',$1.$2);
928: if ($result != m|^/uploaded/|) {
929: $errtext.='Map not saved: A network error occured when trying to save the new map. ';
930: $fatal = 2;
931: }
932: if ($fatal) {
933: return ($errtext,$fatal);
934: }
935: }
936: if ($url) {
937: my $idx = &LONCAPA::map::getresidx($url);
938: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
939: my $ext = 'false';
940: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
941: $url = &LONCAPA::map::qtunescape($url);
942: $name = &LONCAPA::map::qtunescape($name);
943: $LONCAPA::map::resources[$idx] =
944: join ':', ($name, $url, $ext, 'normal', 'res');
945: }
946: }
947: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
948: }
949:
950: sub breadcrumbs {
951: my ($where)=@_;
952: &Apache::lonhtmlcommon::clear_breadcrumbs();
953: my (@folders);
954: if ($env{'form.pagepath'}) {
955: @folders = split('&',$env{'form.pagepath'});
956: } else {
957: @folders=split('&',$env{'form.folderpath'});
958: }
959: my $folderpath;
960: my $cpinfo='';
961: my $plain='';
962: my $randompick=-1;
963: my $isencrypted=0;
964: my $ishidden=0;
965: while (@folders) {
966: my $folder=shift(@folders);
967: my $foldername=shift(@folders);
968: if ($folderpath) {$folderpath.='&';}
969: $folderpath.=$folder.'&'.$foldername;
970: my $url='/adm/coursedocs?folderpath='.
971: &escape($folderpath);
972: my $name=&unescape($foldername);
973: # randompick number, hidden, encrypted is appended with ":"s to the foldername
974: $name=~s/\:(\d*)\:(\w*)\:(\w*)$//;
975: if ($1 ne '') {
976: $randompick=$1;
977: } else {
978: $randompick=-1;
979: }
980: if ($2) { $ishidden=1; }
981: if ($3) { $isencrypted=1; }
982: &Apache::lonhtmlcommon::add_breadcrumb(
983: {'href'=>$url.$cpinfo,
984: 'title'=>$name,
985: 'text'=>'<font size="+1">'.
986: $name.'</font>',
987: 'no_mt'=>1,
988: });
989: $plain.=$name.' > ';
990: }
991: $plain=~s/\>\;\s*$//;
992: return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
993: 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain);
994: }
995:
996: sub log_docs {
997: return &Apache::lonnet::instructor_log('docslog',@_);
998: }
999:
1000: {
1001: my @oldresources=();
1002: my @oldorder=();
1003: my $parmidx;
1004: my %parmaction=();
1005: my %parmvalue=();
1006: my $changedflag;
1007:
1008: sub snapshotbefore {
1009: @oldresources=@LONCAPA::map::resources;
1010: @oldorder=@LONCAPA::map::order;
1011: $parmidx=undef;
1012: %parmaction=();
1013: %parmvalue=();
1014: $changedflag=0;
1015: }
1016:
1017: sub remember_parms {
1018: my ($idx,$parameter,$action,$value)=@_;
1019: $parmidx=$idx;
1020: $parmaction{$parameter}=$action;
1021: $parmvalue{$parameter}=$value;
1022: $changedflag=1;
1023: }
1024:
1025: sub log_differences {
1026: my ($plain)=@_;
1027: my %storehash=('folder' => $plain,
1028: 'currentfolder' => $env{'form.folder'});
1029: if ($parmidx) {
1030: $storehash{'parameter_res'}=$oldresources[$parmidx];
1031: foreach my $parm (keys %parmaction) {
1032: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1033: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1034: }
1035: }
1036: my $maxidx=$#oldresources;
1037: if ($#LONCAPA::map::resources>$#oldresources) {
1038: $maxidx=$#LONCAPA::map::resources;
1039: }
1040: for (my $idx=0; $idx<=$maxidx; $idx++) {
1041: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1042: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1043: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1044: $changedflag=1;
1045: }
1046: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1047: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1048: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1049: $changedflag=1;
1050: }
1051: }
1052: $storehash{'maxidx'}=$maxidx;
1053: if ($changedflag) { &log_docs(\%storehash); }
1054: }
1055: }
1056:
1057:
1058: #
1059: # Docs Change Log
1060: #
1061: sub docs_change_log {
1062: my ($r)=@_;
1063: my $folder=$env{'form.folder'};
1064: $r->print(&Apache::loncommon::start_page('Course Document Change Log'));
1065: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));
1066: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1067: $env{'course.'.$env{'request.course.id'}.'.domain'},
1068: $env{'course.'.$env{'request.course.id'}.'.num'});
1069:
1070: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1071:
1072: $r->print('<form action="/adm/coursedocs" method="post" name="docslog">'.
1073: '<input type="hidden" name="docslog" value="1" />');
1074:
1075: my %saveable_parameters = ('show' => 'scalar',);
1076: &Apache::loncommon::store_course_settings('docs_log',
1077: \%saveable_parameters);
1078: &Apache::loncommon::restore_course_settings('docs_log',
1079: \%saveable_parameters);
1080: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1081: my %lt=('hiddenresource' => 'Resources hidden',
1082: 'encrypturl' => 'URL hidden',
1083: 'randompick' => 'Randomly pick',
1084: 'set' => 'set to',
1085: 'del' => 'deleted');
1086: $r->print(&Apache::loncommon::display_filter().
1087: '<input type="hidden" name="folder" value="'.$folder.'" />'.
1088: '<input type="submit" value="'.&mt('Display').'" /></form>');
1089: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1090: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1091: &mt('After').'</th>'.
1092: &Apache::loncommon::end_data_table_header_row());
1093: my $shown=0;
1094: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1095: if ($env{'form.displayfilter'} eq 'currentfolder') {
1096: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1097: }
1098: my @changes=keys(%{$docslog{$id}{'logentry'}});
1099: if ($env{'form.displayfilter'} eq 'containing') {
1100: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1101: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1102: foreach my $key (@changes) {
1103: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1104: }
1105: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1106: }
1107: my $count = 0;
1108: my $time =
1109: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1110: my $plainname =
1111: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1112: $docslog{$id}{'exe_udom'});
1113: my $about_me_link =
1114: &Apache::loncommon::aboutmewrapper($plainname,
1115: $docslog{$id}{'exe_uname'},
1116: $docslog{$id}{'exe_udom'});
1117: my $send_msg_link='';
1118: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1119: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1120: $send_msg_link ='<br />'.
1121: &Apache::loncommon::messagewrapper(&mt('Send message'),
1122: $docslog{$id}{'exe_uname'},
1123: $docslog{$id}{'exe_udom'});
1124: }
1125: $r->print(&Apache::loncommon::start_data_table_row());
1126: $r->print('<td>'.$time.'</td>
1127: <td>'.$about_me_link.
1128: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1129: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1130: $send_msg_link.'</td><td>'.
1131: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1132: # Before
1133: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1134: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1135: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1136: if ($oldname ne $newname) {
1137: $r->print(&LONCAPA::map::qtescape($oldname));
1138: }
1139: }
1140: $r->print('<ul>');
1141: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1142: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1143: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');
1144: }
1145: }
1146: $r->print('</ul>');
1147: # After
1148: $r->print('</td><td>');
1149:
1150: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1151: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1152: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1153: if ($oldname ne '' && $oldname ne $newname) {
1154: $r->print(&LONCAPA::map::qtescape($newname));
1155: }
1156: }
1157: $r->print('<ul>');
1158: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1159: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1160: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');
1161: }
1162: }
1163: $r->print('</ul>');
1164: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1165: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1166: foreach my $parameter ('randompick','hiddenresource','encrypturl') {
1167: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1168: $r->print('<li>'.
1169: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1170: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1171: .'</li>');
1172: }
1173: }
1174: $r->print('</ul>');
1175: }
1176: # End
1177: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1178: $shown++;
1179: if (!($env{'form.show'} eq &mt('all')
1180: || $shown<=$env{'form.show'})) { last; }
1181: }
1182: $r->print(&Apache::loncommon::end_data_table());
1183: }
1184:
1185: sub update_paste_buffer {
1186: my ($coursenum,$coursedom) = @_;
1187:
1188: return if (!defined($env{'form.markcopy'}));
1189: return if (!defined($env{'form.copyfolder'}));
1190: return if ($env{'form.markcopy'} < 0);
1191:
1192: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1193: $env{'form.copyfolder'});
1194:
1195: return if ($fatal);
1196:
1197: # Mark for copying
1198: my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
1199: if (&is_supplemental_title($title)) {
1200: ($title) = &parse_supplemental_title($title);
1201: }
1202: &Apache::lonnet::appenv('docs.markedcopy_title' => $title,
1203: 'docs.markedcopy_url' => $url);
1204: delete($env{'form.markcopy'});
1205: }
1206:
1207: sub print_paste_buffer {
1208: my ($r,$container) = @_;
1209: return if (!defined($env{'docs.markedcopy_url'}));
1210:
1211: $r->print(<<ENDPASTE);
1212: <p><form name="pasteform" action="/adm/coursedocs" method="post">
1213: ENDPASTE
1214: $r->print('<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> ');
1215:
1216: my $type;
1217: if ($env{'docs.markedcopy_url'} =~ m{^/adm/wrapper/ext}) {
1218: $type = &mt('External Resource');
1219: $r->print($type.': '.&Apache::map::qtescape($env{'docs.markedcopy_title'}));
1220: } else {
1221: my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
1222: my $type = &Apache::loncommon::filedescription($extension);
1223: my $icon = '<img src="'.&Apache::loncommon::icon($extension).
1224: '" class="LC_icon" />';
1225: $r->print($icon.$type.': '. &parse_supplemental_title($env{'docs.markedcopy_title'}));
1226: }
1227: if ($container eq 'page') {
1228: $r->print(<<PAGEINFO);
1229: <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />
1230: <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />
1231: PAGEINFO
1232: } else {
1233: $r->print(<<FOLDERINFO);
1234: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1235: FOLDERINFO
1236: }
1237: $r->print('</form></p>');
1238: }
1239:
1240: sub editor {
1241: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$which)=@_;
1242: my $errtext='';
1243: my $fatal=0;
1244: my $container='sequence';
1245: if ($env{'form.pagepath'}) {
1246: $container='page';
1247: }
1248: ($errtext,$fatal) = &mapread($coursenum,$coursedom,$folder.'.'.$container);
1249: if ($#LONCAPA::map::order<1) {
1250: my $idx=&LONCAPA::map::getresidx();
1251: if ($idx<=0) { $idx=1; }
1252: $LONCAPA::map::order[0]=$idx;
1253: $LONCAPA::map::resources[$idx]='';
1254: }
1255:
1256: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain)=&breadcrumbs($folder);
1257: $r->print($breadcrumbtrail);
1258: if ($fatal) {
1259: $r->print('<p><span class="LC_error">'.$errtext.'</span></p>');
1260: } else {
1261: # ------------------------------------------------------------ Process commands
1262:
1263: # ---------------- if they are for this folder and user allowed to make changes
1264: if (($allowed) && ($env{'form.folder'} eq $folder)) {
1265: # set parameters and change order
1266: &snapshotbefore();
1267: if ($env{'form.changeparms'}) {
1268: my $idx=$env{'form.setparms'};
1269: # set parameters
1270: if ($env{'form.changeparms'} eq 'randompick') {
1271: if ($env{'form.randpick_'.$idx}) {
1272: &LONCAPA::map::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos');
1273: &remember_parms($idx,'randompick','set',$env{'form.randpick_'.$idx});
1274: } else {
1275: &LONCAPA::map::delparameter($idx,'parameter_randompick');
1276: &remember_parms($idx,'randompick','del');
1277: }
1278: }
1279: if ($env{'form.changeparms'} eq 'hiddenresource') {
1280: if ($env{'form.hidprs_'.$idx}) {
1281: &LONCAPA::map::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
1282: &remember_parms($idx,'hiddenresource','set',$env{'form.hidprs_'.$idx});
1283: } else {
1284: &LONCAPA::map::delparameter($idx,'parameter_hiddenresource');
1285: &remember_parms($idx,'hiddenresource','del');
1286: }
1287: }
1288: if ($env{'form.changeparms'} eq 'encrypturl') {
1289: if ($env{'form.encprs_'.$idx}) {
1290: &LONCAPA::map::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
1291: &remember_parms($idx,'encrypturl','set',$env{'form.encprs_'.$idx});
1292: } else {
1293: &LONCAPA::map::delparameter($idx,'parameter_encrypturl');
1294: &remember_parms($idx,'encrypturl','del');
1295: }
1296: }
1297: # store the changed version
1298: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1299: if ($fatal) {
1300: $r->print('<p><span class="LC_error">'.$errtext.'</span></p>');
1301: return;
1302: }
1303: }
1304:
1305: if ($env{'form.newpos'}) {
1306: # change order
1307: my $newpos=$env{'form.newpos'}-1;
1308: my $currentpos=$env{'form.currentpos'}-1;
1309: my $i;
1310: my @neworder=();
1311: if ($newpos>$currentpos) {
1312: # moving stuff up
1313: for ($i=0;$i<$currentpos;$i++) {
1314: $neworder[$i]=$LONCAPA::map::order[$i];
1315: }
1316: for ($i=$currentpos;$i<$newpos;$i++) {
1317: $neworder[$i]=$LONCAPA::map::order[$i+1];
1318: }
1319: $neworder[$newpos]=$LONCAPA::map::order[$currentpos];
1320: for ($i=$newpos+1;$i<=$#LONCAPA::map::order;$i++) {
1321: $neworder[$i]=$LONCAPA::map::order[$i];
1322: }
1323: } else {
1324: # moving stuff down
1325: for ($i=0;$i<$newpos;$i++) {
1326: $neworder[$i]=$LONCAPA::map::order[$i];
1327: }
1328: $neworder[$newpos]=$LONCAPA::map::order[$currentpos];
1329: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
1330: $neworder[$i]=$LONCAPA::map::order[$i-1];
1331: }
1332: for ($i=$currentpos+1;$i<=$#LONCAPA::map::order;$i++) {
1333: $neworder[$i]=$LONCAPA::map::order[$i];
1334: }
1335: }
1336: @LONCAPA::map::order=@neworder;
1337: # store the changed version
1338: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1339: if ($fatal) {
1340: $r->print('<p><span class="LC_error">'.$errtext.'</span></p>');
1341: return;
1342: }
1343: }
1344:
1345: if ($env{'form.pastemarked'}) {
1346: # paste resource to end of list
1347: my $url=$env{'docs.markedcopy_url'};
1348: my $title=$env{'docs.markedcopy_title'};
1349: # Maps need to be copied first
1350: if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) {
1351: $title=&mt('Copy of').' '.$title;
1352: my $newid=$$.time;
1353: $url=~/^(.+)\.(\w+)$/;
1354: my $newurl=$1.$newid.'.'.$2;
1355: my $storefn=$newurl;
1356: $storefn=~s{^/\w+/$match_domain/$match_username/}{};
1357: &Apache::lonclonecourse::writefile
1358: ($env{'request.course.id'},$storefn,
1359: &Apache::lonnet::getfile($url));
1360: $url=$newurl;
1361: }
1362: $title = &LONCAPA::map::qtunescape($title);
1363: my $ext='false';
1364: if ($url=~/^http\:\/\//) { $ext='true'; }
1365: $url = &LONCAPA::map::qtunescape($url);
1366: # Now insert the URL at the bottom
1367: my $newidx=&LONCAPA::map::getresidx($url);
1368: $LONCAPA::map::resources[$newidx]=
1369: $title.':'.$url.':'.$ext.':normal:res';
1370: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
1371: # Store the result
1372: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1373: if ($fatal) {
1374: $r->print('<p><span class="LC_error">'.$errtext.'</span></p>');
1375: return;
1376: }
1377:
1378: }
1379: $r->print($upload_output);
1380: if ($env{'form.cmd'}) {
1381: my ($cmd,$idx)=split(/\_/,$env{'form.cmd'});
1382: if ($cmd eq 'del') {
1383: my (undef,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
1384: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1385: ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
1386: &Apache::lonnet::removeuploadedurl($url);
1387: } else {
1388: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1389: }
1390: for (my $i=$idx;$i<$#LONCAPA::map::order;$i++) {
1391: $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
1392: }
1393: $#LONCAPA::map::order--;
1394: } elsif ($cmd eq 'cut') {
1395: my (undef,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
1396: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1397: for (my $i=$idx;$i<$#LONCAPA::map::order;$i++) {
1398: $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
1399: }
1400: $#LONCAPA::map::order--;
1401: } elsif ($cmd eq 'up') {
1402: if (($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
1403: my $i=$LONCAPA::map::order[$idx-1];
1404: $LONCAPA::map::order[$idx-1] = $LONCAPA::map::order[$idx];
1405: $LONCAPA::map::order[$idx] = $i;
1406: }
1407: } elsif ($cmd eq 'down') {
1408: if (defined($LONCAPA::map::order[$idx+1])) {
1409: my $i=$LONCAPA::map::order[$idx+1];
1410: $LONCAPA::map::order[$idx+1] = $LONCAPA::map::order[$idx];
1411: $LONCAPA::map::order[$idx] = $i;
1412: }
1413: } elsif ($cmd eq 'rename') {
1414: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1415: my ($rtitle,@rrest)=split(/\:/,
1416: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
1417: my $comment=$env{'form.title'};
1418: $comment = &LONCAPA::map::qtunescape($comment);
1419: if ($comment=~/\S/) {
1420: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
1421: $comment.':'.join(':',@rrest);
1422: }
1423: # Devalidate title cache
1424: my $renamed_url=&LONCAPA::map::qtescape($rrest[0]);
1425: &Apache::lonnet::devalidate_title_cache($renamed_url);
1426: }
1427: # Store the changed version
1428: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1429: $folder.'.'.$container);
1430: if ($fatal) {
1431: $r->print('<p><span class="LC_error">'.$errtext.'</span></p>');
1432: return;
1433: }
1434: }
1435: # Group import/search
1436: if ($env{'form.importdetail'}) {
1437: my @imports;
1438: # &Apache::lonnet::logthis("imp detail ".$env{'form.importdetail'});
1439: foreach (split(/\&/,$env{'form.importdetail'})) {
1440: if (defined($_)) {
1441: my ($name,$url)=split(/\=/,$_);
1442: $name=&unescape($name);
1443: $url=&unescape($url);
1444: push @imports, $name, $url;
1445: }
1446: }
1447: # Store the changed version
1448: ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
1449: $container,'londocs',@imports);
1450: if ($fatal) {
1451: $r->print('<p><span class="LC_error">'.$errtext.'</span></p>');
1452: return;
1453: }
1454: }
1455: # Loading a complete map
1456: if ($env{'form.loadmap'}) {
1457: if ($env{'form.importmap'}=~/\w/) {
1458: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1459: my ($title,$url,$ext,$type)=split(/\:/,$_);
1460: my $idx=&LONCAPA::map::getresidx($url);
1461: $LONCAPA::map::resources[$idx]=$_;
1462: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
1463: }
1464: # Store the changed version
1465: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1466: $folder.'.'.$container);
1467: if ($fatal) {
1468: $r->print('<p><span class="LC_error">'.$errtext.'</span></p>');
1469: return;
1470: }
1471: } else {
1472: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1473:
1474: }
1475: }
1476: &log_differences($plain);
1477: }
1478: # ---------------------------------------------------------------- End commands
1479: # ---------------------------------------------------------------- Print screen
1480: my $idx=0;
1481: my $shown=0;
1482: if (($ishidden) || ($isencrypted) || ($randompick>=0)) {
1483: $r->print('<p>'.&mt('Parameters').':<ul>'.
1484: ($randompick>=0?'<li>'.&mt('randomly pick [_1] resources',$randompick).'</li>':'').
1485: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
1486: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
1487: '</ul></p>');
1488: }
1489: if ($randompick>=0) {
1490: $r->print('<p>'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'</p>');
1491: }
1492: $r->print('<table>');
1493: foreach my $res (@LONCAPA::map::order) {
1494: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1495: $name=&LONCAPA::map::qtescape($name);
1496: $url=&LONCAPA::map::qtescape($url);
1497: unless ($name) { $name=(split(/\//,$url))[-1]; }
1498: unless ($name) { $idx++; next; }
1499: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$res,
1500: $coursenum));
1501: $idx++;
1502: $shown++;
1503: }
1504: unless ($shown) {
1505: $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
1506: }
1507: $r->print("\n</table>\n");
1508:
1509: &print_paste_buffer($r,$container);
1510:
1511: }
1512: }
1513:
1514: sub process_file_upload {
1515: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1516: # upload a file, if present
1517: my $parseaction;
1518: if ($env{'form.parserflag'}) {
1519: $parseaction = 'parse';
1520: }
1521: my $phase_status;
1522: my $folder=$env{'form.folder'};
1523: if ($folder eq '') {
1524: $folder='default';
1525: }
1526: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1527: my $errtext='';
1528: my $fatal=0;
1529: my $container='sequence';
1530: if ($env{'form.pagepath'}) {
1531: $container='page';
1532: }
1533: ($errtext,$fatal)=
1534: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1535: if ($#LONCAPA::map::order<1) {
1536: $LONCAPA::map::order[0]=1;
1537: $LONCAPA::map::resources[1]='';
1538: }
1539: if ($fatal) {
1540: return 'failed';
1541: }
1542: my $destination = 'docs/';
1543: if ($folder =~ /^supplemental/) {
1544: $destination = 'supplemental/';
1545: }
1546: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1547: $destination .= 'default/';
1548: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1549: $destination .= $2.'/';
1550: }
1551: # this is for a course, not a user, so set coursedoc flag
1552: # probably the only place in the system where this should be "1"
1553: my $newidx=&LONCAPA::map::getresidx();
1554: $destination .= $newidx;
1555: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
1556: $parseaction,$allfiles,
1557: $codebase);
1558: my $ext='false';
1559: if ($url=~/^http\:\/\//) { $ext='true'; }
1560: $url = &LONCAPA::map::qtunescape($url);
1561: my $comment=$env{'form.comment'};
1562: $comment = &LONCAPA::map::qtunescape($comment);
1563: if ($folder=~/^supplemental/) {
1564: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1565: $env{'user.domain'}.'___&&&___'.$comment;
1566: }
1567:
1568: $LONCAPA::map::resources[$newidx]=
1569: $comment.':'.$url.':'.$ext.':normal:res';
1570: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
1571: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1572: $folder.'.'.$container);
1573: if ($fatal) {
1574: $$upload_output .= '<p><span class="LC_error">'.$errtext.'</span></p>';
1575: return 'failed';
1576: } else {
1577: if ($parseaction eq 'parse') {
1578: my $total_embedded = keys(%{$allfiles});
1579: if ($total_embedded > 0) {
1580: my $num = 0;
1581: my $state = '
1582: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
1583: <input type="hidden" name="cmd" value="upload_embedded" />
1584: <input type="hidden" name="newidx" value="'.$newidx.'" />
1585: <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
1586: <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
1587: $phase_status = 'phasetwo';
1588:
1589: $$upload_output .=
1590: 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />'.
1591: &ask_for_embedded_content('/adm/coursedocs',
1592: $state,$allfiles,$codebase);
1593: } else {
1594: $$upload_output .= 'No embedded items identified<br />';
1595: }
1596: }
1597: }
1598: }
1599: return $phase_status;
1600: }
1601:
1602: sub ask_for_embedded_content {
1603: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1604: my $upload_output = '
1605: <form name="upload_embedded" action="'.$actionurl.'"
1606: method="post" enctype="multipart/form-data">';
1607: $upload_output .= $state;
1608: $upload_output .= '<b>Upload embedded files</b>:<br />'.
1609: &Apache::loncommon::start_data_table();
1610:
1611: my $num = 0;
1612: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
1613: $upload_output .= &Apache::loncommon::start_data_table_row().
1614: '<td>'.$embed_file.'</td><td>';
1615: if ($args->{'ignore_remote_references'}
1616: && $embed_file =~ m{^\w+://}) {
1617: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1618: } elsif ($args->{'error_on_invalid_names'}
1619: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1620:
1621: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
1622:
1623: } else {
1624:
1625: $upload_output .='
1626: <input name="embedded_item_'.$num.'" type="file" value="bob" />
1627: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
1628: my $attrib = join(':',@{$$allfiles{$embed_file}});
1629: $upload_output .=
1630: "\n\t\t".
1631: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
1632: $attrib.'" />';
1633: if (exists($$codebase{$embed_file})) {
1634: $upload_output .=
1635: "\n\t\t".
1636: '<input name="codebase_'.$num.'" type="hidden" value="'.
1637: &escape($$codebase{$embed_file}).'" />';
1638: }
1639: }
1640: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
1641: $num++;
1642: }
1643: $upload_output .= &Apache::loncommon::end_data_table().'<br />
1644: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
1645: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
1646: '.&mt('(only files for which a location has been provided will be uploaded)').'
1647: </form>';
1648: return $upload_output;
1649: }
1650:
1651: sub process_secondary_uploads {
1652: my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
1653: my $folder=$env{'form.folder'};
1654: my $destination = 'docs/';
1655: if ($folder =~ /^supplemental/) {
1656: $destination = 'supplemental/';
1657: }
1658: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1659: $destination .= 'default/';
1660: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1661: $destination .= $2.'/';
1662: }
1663: $destination .= $newidx;
1664: my ($url,$filename);
1665: $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
1666: ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
1667: return $filename;
1668: }
1669:
1670: sub is_supplemental_title {
1671: my ($title) = @_;
1672: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
1673: }
1674:
1675: sub parse_supplemental_title {
1676: my ($title) = @_;
1677:
1678: my ($foldertitle,$renametitle);
1679: if ($title =~ /&&&/) {
1680: $title = &HTML::Entites::decode($title);
1681: }
1682: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
1683: $renametitle=$4;
1684: my ($time,$uname,$udom) = ($1,$2,$3);
1685: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1686: my $name = &Apache::loncommon::plainname($uname,$udom);
1687: $name = &HTML::Entities::encode($name,'"<>&\'');
1688: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
1689: $name.': <br />'.$foldertitle;
1690: }
1691: if (wantarray) {
1692: return ($title,$foldertitle,$renametitle);
1693: }
1694: return $title;
1695: }
1696:
1697: # --------------------------------------------------------------- An entry line
1698:
1699: sub entryline {
1700: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1701:
1702: my ($foldertitle,$pagetitle,$renametitle);
1703: if (&is_supplemental_title($title)) {
1704: ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
1705: $pagetitle = $foldertitle;
1706: } else {
1707: $title=&HTML::Entities::encode($title,'"<>&\'');
1708: $renametitle=$title;
1709: $foldertitle=$title;
1710: $pagetitle=$title;
1711: }
1712:
1713: my $orderidx=$LONCAPA::map::order[$index];
1714:
1715:
1716: $renametitle=~s/\\/\\\\/g;
1717: $renametitle=~s/\"\;/\\\"/g;
1718: my $line='<tr>';
1719: # Edit commands
1720: my $container;
1721: my ($container, $type, $esc_path, $path, $symb);
1722: if ($env{'form.folderpath'}) {
1723: $type = 'folder';
1724: $container = 'sequence';
1725: $esc_path=&escape($env{'form.folderpath'});
1726: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1727: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
1728: }
1729: if ($env{'form.pagepath'}) {
1730: $type = $container = 'page';
1731: $esc_path=&escape($path = $env{'form.pagepath'});
1732: $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
1733: $symb=&escape($env{'form.pagesymb'});
1734: }
1735: my $cpinfo='';
1736: if ($allowed) {
1737: my $incindex=$index+1;
1738: my $selectbox='';
1739: if (($folder!~/^supplemental/) &&
1740: ($#LONCAPA::map::order>0) &&
1741: ((split(/\:/,
1742: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
1743: ne '') &&
1744: ((split(/\:/,
1745: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1746: ne '')) {
1747: $selectbox=
1748: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1749: '<select name="newpos" onChange="this.form.submit()">';
1750: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
1751: if ($i==$incindex) {
1752: $selectbox.='<option value="" selected="1">('.$i.')</option>';
1753: } else {
1754: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1755: }
1756: }
1757: $selectbox.='</select>';
1758: }
1759: my %lt=&Apache::lonlocal::texthash(
1760: 'up' => 'Move Up',
1761: 'dw' => 'Move Down',
1762: 'rm' => 'Remove',
1763: 'ct' => 'Cut',
1764: 'rn' => 'Rename',
1765: 'cp' => 'Copy');
1766: my $nocopy=0;
1767: my $nocut=0;
1768: if ($url=~/\.(page|sequence)$/) {
1769: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url))) {
1770: my ($title,$url,$ext,$type)=split(/\:/,$_);
1771: if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
1772: $nocopy=1;
1773: last;
1774: }
1775: }
1776: }
1777: if ($url=~/^\/res\/lib\/templates\//) {
1778: $nocopy=1;
1779: $nocut=1;
1780: }
1781: my $copylink=' ';
1782: my $cutlink=' ';
1783:
1784: if (!$nocopy) {
1785: $copylink=(<<ENDCOPY);
1786: <a href='javascript:markcopy("$esc_path","$index","$renametitle","$container","$symb","$folder");'>
1787: <font size="-2" color="#000099">$lt{'cp'}</font></a>
1788: ENDCOPY
1789: }
1790: if (!$nocut) {
1791: $cutlink=(<<ENDCUT);
1792: <a href='javascript:cutres("$esc_path","$index","$renametitle","$container","$symb","$folder");'>
1793: <font size="-2" color="#550044">$lt{'ct'}</font></a>
1794: ENDCUT
1795: }
1796: $line.=(<<END);
1797: <form name="entry_$index" action="/adm/coursedocs" method="post">
1798: <input type="hidden" name="${type}path" value="$path" />
1799: <input type="hidden" name="${type}symb" value="$symb" />
1800: <input type="hidden" name="setparms" value="$orderidx" />
1801: <input type="hidden" name="changeparms" value="0" />
1802: <td>
1803: <table border='0' cellspacing='2' cellpadding='0'>
1804: <tr>
1805: <td bgcolor="#DDDDDD">
1806: <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'><img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" /></a>
1807: </td>
1808: </tr>
1809: <tr>
1810: <td bgcolor="#DDDDDD">
1811: <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'><img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" /></a>
1812: </td>
1813: </tr>
1814: </table>
1815: </td>
1816: <td>
1817: $selectbox
1818: </td>
1819: <td bgcolor="#DDDDDD">
1820: <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb");'><font size="-2" color="#990000">$lt{'rm'}</font></a>
1821: $cutlink
1822: <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");'><font size="-2" color="#009900">$lt{'rn'}</font></a>
1823: $copylink
1824: </td>
1825: END
1826:
1827: }
1828: # Figure out what kind of a resource this is
1829: my ($extension)=($url=~/\.(\w+)$/);
1830: my $uploaded=($url=~/^\/*uploaded\//);
1831: my $icon=&Apache::loncommon::icon($url);
1832: my $isfolder=0;
1833: my $ispage=0;
1834: my $folderarg;
1835: my $pagearg;
1836: my $pagefile;
1837: if ($uploaded) {
1838: if ($extension eq 'sequence') {
1839: $icon=$iconpath.'/folder_closed.gif';
1840: $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;
1841: $url='/adm/coursedocs?';
1842: $folderarg=$1;
1843: $isfolder=1;
1844: } elsif ($extension eq 'page') {
1845: $icon=$iconpath.'/page.gif';
1846: $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;
1847: $pagearg=$1;
1848: $url='/adm/coursedocs?';
1849: $ispage=1;
1850: } else {
1851: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1852: }
1853: }
1854: $url=~s-^http(\&colon\;|:)//-/adm/wrapper/ext/-;
1855: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1856: my $symb=&Apache::lonnet::symbclean(
1857: &Apache::lonnet::declutter('uploaded/'.
1858: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1859: $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
1860: '.sequence').
1861: '___'.$residx.'___'.
1862: &Apache::lonnet::declutter($url));
1863: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1864: $url=&Apache::lonnet::clutter($url);
1865: if ($url=~/^\/*uploaded\//) {
1866: $url=~/\.(\w+)$/;
1867: my $embstyle=&Apache::loncommon::fileembstyle($1);
1868: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
1869: $url='/adm/wrapper'.$url;
1870: } elsif ($embstyle eq 'ssi') {
1871: #do nothing with these
1872: } elsif ($url!~/\.(sequence|page)$/) {
1873: $url='/adm/coursedocs/showdoc'.$url;
1874: }
1875: } elsif ($url=~m|^/ext/|) {
1876: $url='/adm/wrapper'.$url;
1877: }
1878: if (&Apache::lonnet::symbverify($symb,$url)) {
1879: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1880: } else {
1881: $url='';
1882: }
1883: if ($container eq 'page') {
1884: my $symb=$env{'form.pagesymb'};
1885:
1886: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1887: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1888: }
1889: }
1890: my $parameterset=' ';
1891: if ($isfolder || $extension eq 'sequence') {
1892: my $foldername=&escape($foldertitle);
1893: my $folderpath=$env{'form.folderpath'};
1894: if ($folderpath) { $folderpath.='&' };
1895: # Append randompick number, hidden, and encrypted with ":" to foldername,
1896: # so it gets transferred between levels
1897: $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
1898: 'parameter_randompick'))[0]
1899: .':'.((&LONCAPA::map::getparameter($orderidx,
1900: 'parameter_hiddenresource'))[0]=~/^yes$/i)
1901: .':'.((&LONCAPA::map::getparameter($orderidx,
1902: 'parameter_encrypturl'))[0]=~/^yes$/i);
1903: $url.='folderpath='.&escape($folderpath).$cpinfo;
1904: $parameterset='<label>'.&mt('Randomly Pick: ').
1905: '<input type="text" size="4" onChange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randpick_'.$orderidx.'" value="'.
1906: (&LONCAPA::map::getparameter($orderidx,
1907: 'parameter_randompick'))[0].
1908: '" />'.
1909: '<font size="-2"><a href="javascript:void(0)">'.&mt('Save').'</a></font></label>';
1910:
1911: }
1912: if ($ispage) {
1913: my $pagename=&escape($pagetitle);
1914: my $pagepath;
1915: my $folderpath=$env{'form.folderpath'};
1916: if ($folderpath) { $pagepath = $folderpath.'&' };
1917: $pagepath.=$pagearg.'&'.$pagename;
1918: my $symb=$env{'form.pagesymb'};
1919: if (!$symb) {
1920: my $path='uploaded/'.
1921: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1922: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
1923: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
1924: $residx,
1925: $path.$pagearg.'.page');
1926: }
1927: $url.='pagepath='.&escape($pagepath).
1928: '&pagesymb='.&escape($symb).$cpinfo;
1929: }
1930: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
1931: '" class="LC_icon" /></a></td>'.
1932: "<td bgcolor='#FFFFBB'>".($url?"<a href=\"$url\">":'').$title.
1933: ($url?'</a>':' <font size="-2">'.&mt('(re-initialize course to access)').'</font>')."</td>";
1934: if (($allowed) && ($folder!~/^supplemental/)) {
1935: my %lt=&Apache::lonlocal::texthash(
1936: 'hd' => 'Hidden',
1937: 'ec' => 'URL hidden');
1938: my $enctext=
1939: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
1940: my $hidtext=
1941: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1942: $line.=(<<ENDPARMS);
1943: <td bgcolor="#BBBBFF"><font size='-2'>
1944: <nobr><label><input type="checkbox" name="hidprs_$orderidx" onClick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label></nobr></td>
1945: <td bgcolor="#BBBBFF"><font size='-2'>
1946: <nobr><label><input type="checkbox" name="encprs_$orderidx" onClick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label></nobr></td>
1947: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
1948: ENDPARMS
1949: }
1950: $line.="</form></tr>";
1951: return $line;
1952: }
1953:
1954: # ---------------------------------------------------------------- tie the hash
1955:
1956: sub tiehash {
1957: my ($mode)=@_;
1958: $hashtied=0;
1959: if ($env{'request.course.fn'}) {
1960: if ($mode eq 'write') {
1961: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1962: &GDBM_WRCREAT(),0640)) {
1963: $hashtied=2;
1964: }
1965: } else {
1966: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1967: &GDBM_READER(),0640)) {
1968: $hashtied=1;
1969: }
1970: }
1971: }
1972: }
1973:
1974: sub untiehash {
1975: if ($hashtied) { untie %hash; }
1976: $hashtied=0;
1977: return OK;
1978: }
1979:
1980: # --------------------------------------------------------------- check on this
1981:
1982: sub checkonthis {
1983: my ($r,$url,$level,$title)=@_;
1984: $url=&unescape($url);
1985: $alreadyseen{$url}=1;
1986: $r->rflush();
1987: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1988: $r->print("\n<br />");
1989: for (my $i=0;$i<=$level*5;$i++) {
1990: $r->print(' ');
1991: }
1992: $r->print('<a href="'.$url.'" target="cat">'.
1993: ($title?$title:$url).'</a> ');
1994: if ($url=~/^\/res\//) {
1995: my $result=&Apache::lonnet::repcopy(
1996: &Apache::lonnet::filelocation('',$url));
1997: if ($result eq 'ok') {
1998: $r->print('<font color="green">'.&mt('ok').'</font>');
1999: $r->rflush();
2000: &Apache::lonnet::countacc($url);
2001: $url=~/\.(\w+)$/;
2002: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
2003: $r->print('<br />');
2004: $r->rflush();
2005: for (my $i=0;$i<=$level*5;$i++) {
2006: $r->print(' ');
2007: }
2008: $r->print('- '.&mt('Rendering').': ');
2009: my ($errorcount,$warningcount)=split(/:/,
2010: &Apache::lonnet::ssi_body($url,
2011: ('grade_target'=>'web',
2012: 'return_only_error_and_warning_counts' => 1)));
2013: if (($errorcount) ||
2014: ($warningcount)) {
2015: if ($errorcount) {
2016: $r->print('<img src="/adm/lonMisc/bomb.gif" /><span class="LC_error">'.
2017: $errorcount.' '.
2018: &mt('error(s)').'</span> ');
2019: }
2020: if ($warningcount) {
2021: $r->print('<span class="LC_warning">'.
2022: $warningcount.' '.
2023: &mt('warning(s)').'</span>');
2024: }
2025: } else {
2026: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2027: }
2028: $r->rflush();
2029: }
2030: my $dependencies=
2031: &Apache::lonnet::metadata($url,'dependencies');
2032: foreach (split(/\,/,$dependencies)) {
2033: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
2034: &checkonthis($r,$_,$level+1);
2035: }
2036: }
2037: } elsif ($result eq 'unavailable') {
2038: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
2039: } elsif ($result eq 'not_found') {
2040: unless ($url=~/\$/) {
2041: $r->print('<span class="LC_error">'.&mt('not found').'</b></font>');
2042: } else {
2043: $r->print('<span class="LC_unknown">'.&mt('unable to verify variable URL').'</span>');
2044: }
2045: } else {
2046: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
2047: }
2048: }
2049: }
2050: }
2051:
2052:
2053: #
2054: # ----------------------------------------------------------------- List Symbs
2055: #
2056: sub list_symbs {
2057: my ($r) = @_;
2058:
2059: $r->print(&Apache::loncommon::start_page('Symb List'));
2060: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
2061: my $navmap = Apache::lonnavmaps::navmap->new();
2062: $r->print("<pre>\n");
2063: foreach my $res ($navmap->retrieveResources()) {
2064: $r->print($res->compTitle()."\t".$res->symb()."\n");
2065: }
2066: $r->print("\n</pre>\n");
2067: $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
2068: }
2069:
2070:
2071: #
2072: # -------------------------------------------------------------- Verify Content
2073: #
2074: sub verifycontent {
2075: my ($r) = @_;
2076: my $type = &Apache::loncommon::course_type();
2077: my $loaderror=&Apache::lonnet::overloaderror($r);
2078: if ($loaderror) { return $loaderror; }
2079: $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
2080: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));
2081: $hashtied=0;
2082: undef %alreadyseen;
2083: %alreadyseen=();
2084: &tiehash();
2085: foreach (keys %hash) {
2086: if ($hash{$_}=~/\.(page|sequence)$/) {
2087: if (($_=~/^src_/) && ($alreadyseen{&unescape($hash{$_})})) {
2088: $r->print('<hr /><span class="LC_error">'.
2089: &mt('The following sequence or page is included more than once in your '.$type.': ').
2090: &unescape($hash{$_}).'</span><br />'.
2091: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
2092: }
2093: }
2094: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$_})})) {
2095: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
2096: }
2097: }
2098: &untiehash();
2099: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
2100: &mt('Return to DOCS').'</a>');
2101: }
2102:
2103:
2104: # -------------------------------------------------------------- Check Versions
2105:
2106: sub devalidateversioncache {
2107: my $src=shift;
2108: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
2109: &Apache::lonnet::clutter($src));
2110: }
2111:
2112: sub checkversions {
2113: my ($r) = @_;
2114: my $type = &Apache::loncommon::course_type();
2115: $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
2116: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));
2117: my $header='';
2118: my $startsel='';
2119: my $monthsel='';
2120: my $weeksel='';
2121: my $daysel='';
2122: my $allsel='';
2123: my %changes=();
2124: my $starttime=0;
2125: my $haschanged=0;
2126: my %setversions=&Apache::lonnet::dump('resourceversions',
2127: $env{'course.'.$env{'request.course.id'}.'.domain'},
2128: $env{'course.'.$env{'request.course.id'}.'.num'});
2129:
2130: $hashtied=0;
2131: &tiehash();
2132: my %newsetversions=();
2133: if ($env{'form.setmostrecent'}) {
2134: $haschanged=1;
2135: foreach (keys %hash) {
2136: if ($_=~/^ids\_(\/res\/.+)$/) {
2137: $newsetversions{$1}='mostrecent';
2138: &devalidateversioncache($1);
2139: }
2140: }
2141: } elsif ($env{'form.setcurrent'}) {
2142: $haschanged=1;
2143: foreach (keys %hash) {
2144: if ($_=~/^ids\_(\/res\/.+)$/) {
2145: my $getvers=&Apache::lonnet::getversion($1);
2146: if ($getvers>0) {
2147: $newsetversions{$1}=$getvers;
2148: &devalidateversioncache($1);
2149: }
2150: }
2151: }
2152: } elsif ($env{'form.setversions'}) {
2153: $haschanged=1;
2154: foreach (keys %env) {
2155: if ($_=~/^form\.set_version_(.+)$/) {
2156: my $src=$1;
2157: if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
2158: $newsetversions{$src}=$env{$_};
2159: &devalidateversioncache($src);
2160: }
2161: }
2162: }
2163: }
2164: if ($haschanged) {
2165: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
2166: $env{'course.'.$env{'request.course.id'}.'.domain'},
2167: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
2168: $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');
2169: } else {
2170: $r->print('<h1><span class="LC_error">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</span></h1>');
2171: }
2172: &mark_hash_old();
2173: }
2174: &changewarning($r,'');
2175: if ($env{'form.timerange'} eq 'all') {
2176: # show all documents
2177: $header=&mt('All Documents in '.$type);
2178: $allsel=1;
2179: foreach (keys %hash) {
2180: if ($_=~/^ids\_(\/res\/.+)$/) {
2181: my $src=$1;
2182: $changes{$src}=1;
2183: }
2184: }
2185: } else {
2186: # show documents which changed
2187: %changes=&Apache::lonnet::dump
2188: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
2189: $env{'course.'.$env{'request.course.id'}.'.num'});
2190: my $firstkey=(keys %changes)[0];
2191: unless ($firstkey=~/^error\:/) {
2192: unless ($env{'form.timerange'}) {
2193: $env{'form.timerange'}=604800;
2194: }
2195: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
2196: .&mt('seconds');
2197: if ($env{'form.timerange'}==-1) {
2198: $seltext='since start of course';
2199: $startsel='selected';
2200: $env{'form.timerange'}=time;
2201: }
2202: $starttime=time-$env{'form.timerange'};
2203: if ($env{'form.timerange'}==2592000) {
2204: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2205: $monthsel='selected';
2206: } elsif ($env{'form.timerange'}==604800) {
2207: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2208: $weeksel='selected';
2209: } elsif ($env{'form.timerange'}==86400) {
2210: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2211: $daysel='selected';
2212: }
2213: $header=&mt('Content changed').' '.$seltext;
2214: } else {
2215: $header=&mt('No content modifications yet.');
2216: }
2217: }
2218: %setversions=&Apache::lonnet::dump('resourceversions',
2219: $env{'course.'.$env{'request.course.id'}.'.domain'},
2220: $env{'course.'.$env{'request.course.id'}.'.num'});
2221: my %lt=&Apache::lonlocal::texthash
2222: ('st' => 'Version changes since start of '.$type,
2223: 'lm' => 'Version changes since last Month',
2224: 'lw' => 'Version changes since last Week',
2225: 'sy' => 'Version changes since Yesterday',
2226: 'al' => 'All Resources (possibly large output)',
2227: 'sd' => 'Display',
2228: 'fi' => 'File',
2229: 'md' => 'Modification Date',
2230: 'mr' => 'Most recently published Version',
2231: 've' => 'Version used in '.$type,
2232: 'vu' => 'Set Version to be used in '.$type,
2233: 'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
2234: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
2235: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
2236: 'di' => 'Differences');
2237: $r->print(<<ENDHEADERS);
2238: <form action="/adm/coursedocs" method="post">
2239: <input type="hidden" name="versions" value="1" />
2240: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
2241: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
2242: <select name="timerange">
2243: <option value='all' $allsel>$lt{'al'}</option>
2244: <option value="-1" $startsel>$lt{'st'}</option>
2245: <option value="2592000" $monthsel>$lt{'lm'}</option>
2246: <option value="604800" $weeksel>$lt{'lw'}</option>
2247: <option value="86400" $daysel>$lt{'sy'}</option>
2248: </select>
2249: <input type="submit" name="display" value="$lt{'sd'}" />
2250: <h3>$header</h3>
2251: <input type="submit" name="setversions" value="$lt{'sv'}" />
2252: <table border="0">
2253: ENDHEADERS
2254: foreach (sort keys %changes) {
2255: if ($changes{$_}>$starttime) {
2256: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
2257: my $currentversion=&Apache::lonnet::getversion($_);
2258: if ($currentversion<0) {
2259: $currentversion=&mt('Could not be determined.');
2260: }
2261: my $linkurl=&Apache::lonnet::clutter($_);
2262: $r->print(
2263: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
2264: &Apache::lonnet::gettitle($linkurl).
2265: '</b></font></td></tr>'.
2266: '<tr><td> </td>'.
2267: '<td colspan="4">'.
2268: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
2269: '</a></td></tr>'.
2270: '<tr><td></td>'.
2271: '<td title="'.$lt{'md'}.'">'.
2272: &Apache::lonlocal::locallocaltime(
2273: &Apache::lonnet::metadata($root.'.'.$extension,
2274: 'lastrevisiondate')
2275: ).
2276: '</td>'.
2277: '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
2278: '<font size="+1">'.$currentversion.'</font>'.
2279: '</nobr></td>'.
2280: '<td title="'.$lt{'ve'}.'"><nobr>In '.$type.': '.
2281: '<font size="+1">');
2282: # Used in course
2283: my $usedversion=$hash{'version_'.$linkurl};
2284: if (($usedversion) && ($usedversion ne 'mostrecent')) {
2285: $r->print($usedversion);
2286: } else {
2287: $r->print($currentversion);
2288: }
2289: $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
2290: '<nobr>Use: ');
2291: # Set version
2292: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
2293: 'set_version_'.$linkurl,
2294: ('select_form_order' =>
2295: ['',1..$currentversion,'mostrecent'],
2296: '' => '',
2297: 'mostrecent' => 'most recent',
2298: map {$_,$_} (1..$currentversion))));
2299: $r->print('</nobr></td></tr><tr><td></td>');
2300: my $lastold=1;
2301: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
2302: my $url=$root.'.'.$prevvers.'.'.$extension;
2303: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
2304: $starttime) {
2305: $lastold=$prevvers;
2306: }
2307: }
2308: #
2309: # Code to figure out how many version entries should go in
2310: # each of the four columns
2311: my $entries_per_col = 0;
2312: my $num_entries = ($currentversion-$lastold);
2313: if ($num_entries % 4 == 0) {
2314: $entries_per_col = $num_entries/4;
2315: } else {
2316: $entries_per_col = $num_entries/4 + 1;
2317: }
2318: my $entries_count = 0;
2319: $r->print('<td valign="top"><font size="-2">');
2320: my $cols_output = 1;
2321: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
2322: my $url=$root.'.'.$prevvers.'.'.$extension;
2323: $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
2324: '">'.&mt('Version').' '.$prevvers.'</a> ('.
2325: &Apache::lonlocal::locallocaltime(
2326: &Apache::lonnet::metadata($url,
2327: 'lastrevisiondate')
2328: ).
2329: ')');
2330: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
2331: $r->print(' <a href="/adm/diff?filename='.
2332: &Apache::lonnet::clutter($root.'.'.$extension).
2333: '&versionone='.$prevvers.
2334: '">'.&mt('Diffs').'</a>');
2335: }
2336: $r->print('</nobr><br />');
2337: if (++$entries_count % $entries_per_col == 0) {
2338: $r->print('</font></td>');
2339: if ($cols_output != 4) {
2340: $r->print('<td valign="top"><font size="-2">');
2341: $cols_output++;
2342: }
2343: }
2344: }
2345: while($cols_output++ < 4) {
2346: $r->print('</font></td><td><font>')
2347: }
2348: $r->print('</font></td></tr>'."\n");
2349: }
2350: }
2351: $r->print('</table></form>');
2352: $r->print('<h1>'.&mt('Done').'.</h1>');
2353:
2354: &untiehash();
2355: }
2356:
2357: sub mark_hash_old {
2358: my $retie_hash=0;
2359: if ($hashtied) {
2360: $retie_hash=1;
2361: &untiehash();
2362: }
2363: &tiehash('write');
2364: $hash{'old'}=1;
2365: &untiehash();
2366: if ($retie_hash) { &tiehash(); }
2367: }
2368:
2369: sub is_hash_old {
2370: my $untie_hash=0;
2371: if (!$hashtied) {
2372: $untie_hash=1;
2373: &tiehash();
2374: }
2375: my $return=$hash{'old'};
2376: if ($untie_hash) { &untiehash(); }
2377: return $return;
2378: }
2379:
2380: sub changewarning {
2381: my ($r,$postexec,$message,$url)=@_;
2382: if (!&is_hash_old()) { return; }
2383: my $pathvar='folderpath';
2384: my $path=&escape($env{'form.folderpath'});
2385: if (!defined($url)) {
2386: if (defined($env{'form.pagepath'})) {
2387: $pathvar='pagepath';
2388: $path=&escape($env{'form.pagepath'});
2389: $path.='&pagesymb='.&escape($env{'form.pagesymb'});
2390: }
2391: $url='/adm/coursedocs?'.$pathvar.'='.$path;
2392: }
2393: my $course_type = &Apache::loncommon::course_type();
2394: if (!defined($message)) {
2395: $message='Changes will become active for your current session after [_1], or the next time you log in.';
2396: }
2397: $r->print("\n\n".
2398: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n".
2399: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
2400: '<input type="hidden" name="orgurl" value="'.$url.
2401: '" /><input type="hidden" name="selectrole" value="1" /><h3><span class="LC_warning">'.
2402: &mt($message,' <input type="hidden" name="'.
2403: $env{'request.role'}.'" value="1" /><input type="button" value="'.
2404: &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />').
2405: $help{'Caching'}.'</span></h3></form>'."\n\n");
2406: }
2407:
2408: # =========================================== Breadcrumbs for special functions
2409:
2410: sub init_breadcrumbs {
2411: my ($form,$text)=@_;
2412: &Apache::lonhtmlcommon::clear_breadcrumbs();
2413: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
2414: text=>&Apache::loncommon::course_type()." Documents",
2415: faq=>273,
2416: bug=>'Instructor Interface',
2417: help => 'Docs_Adding_Course_Doc'});
2418: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
2419: text=>$text,
2420: faq=>273,
2421: bug=>'Instructor Interface'});
2422: }
2423:
2424: # ================================================================ Main Handler
2425: sub handler {
2426: my $r = shift;
2427: &Apache::loncommon::content_type($r,'text/html');
2428: $r->send_http_header;
2429: return OK if $r->header_only;
2430: my $type = &Apache::loncommon::course_type();
2431:
2432: # --------------------------------------------- Initialize help topics for this
2433: foreach ('Adding_Course_Doc','Main_Course_Documents',
2434: 'Adding_External_Resource','Navigate_Content',
2435: 'Adding_Folders','Docs_Overview', 'Load_Map',
2436: 'Supplemental','Score_Upload_Form','Adding_Pages',
2437: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2438: 'Check_Resource_Versions','Verify_Content') {
2439: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
2440: }
2441: # Composite help files
2442: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2443: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2444: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2445: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
2446: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2447: 'Option_Response_Simple');
2448: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2449: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
2450: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
2451: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
2452: $help{'Group Files'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
2453: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
2454:
2455: # does this user have privileges to modify docs
2456: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2457: if ($allowed && $env{'form.verify'}) {
2458: &init_breadcrumbs('verify','Verify Content');
2459: &verifycontent($r);
2460: } elsif ($allowed && $env{'form.listsymbs'}) {
2461: &init_breadcrumbs('listsymbs','List Symbs');
2462: &list_symbs($r);
2463: } elsif ($allowed && $env{'form.docslog'}) {
2464: &init_breadcrumbs('docslog','Show Log');
2465: &docs_change_log($r);
2466: } elsif ($allowed && $env{'form.versions'}) {
2467: &init_breadcrumbs('versions','Check/Set Resource Versions');
2468: &checkversions($r);
2469: } elsif ($allowed && $env{'form.dumpcourse'}) {
2470: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
2471: &dumpcourse($r);
2472: } elsif ($allowed && $env{'form.exportcourse'}) {
2473: &init_breadcrumbs('exportcourse','Export '.&Apache::loncommon::course_type().' to IMS');
2474: &exportcourse($r);
2475: } else {
2476: # is this a standard course?
2477:
2478: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
2479: my $forcestandard = 0;
2480: my $forcesupplement;
2481: my $script='';
2482: my $showdoc=0;
2483: my $containertag;
2484: my $uploadtag;
2485: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2486: ['folderpath','pagepath',
2487: 'pagesymb']);
2488: if ($env{'form.folderpath'}) {
2489: my (@folderpath)=split('&',$env{'form.folderpath'});
2490: $env{'form.foldername'}=&unescape(pop(@folderpath));
2491: $env{'form.folder'}=pop(@folderpath);
2492: }
2493: if ($env{'form.pagepath'}) {
2494: my (@pagepath)=split('&',$env{'form.pagepath'});
2495: $env{'form.pagename'}=&unescape(pop(@pagepath));
2496: $env{'form.folder'}=pop(@pagepath);
2497: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2498: '<input type="hidden" name="pagesymb" value="" />';
2499: $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
2500: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';
2501: }
2502: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
2503: $showdoc='/'.$1;
2504: }
2505: unless ($showdoc) { # got called from remote
2506: if (($env{'form.folder'}=~/^(?:group|default)_/) ||
2507: ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
2508: $forcestandard = 1;
2509: }
2510: $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
2511:
2512: if ($allowed) {
2513: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
2514: $script=&Apache::lonratedt::editscript('simple');
2515: }
2516: } else { # got called in sequence from course
2517: $allowed=0;
2518: }
2519:
2520: # get course data
2521: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2522: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2523:
2524: # get personal data
2525: my $uname=$env{'user.name'};
2526: my $udom=$env{'user.domain'};
2527: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
2528:
2529: # graphics settings
2530:
2531: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
2532:
2533: if ($allowed) {
2534: $script .= &editing_js($udom,$uname);
2535: }
2536: # -------------------------------------------------------------------- Body tag
2537: $script = '<script type="text/javascript">'."\n".$script."\n".'</script>';
2538: $r->print(&Apache::loncommon::start_page("$type Documents", $script,
2539: {'force_register' => $showdoc,}).
2540: &Apache::loncommon::help_open_menu('','',273,'RAT'));
2541:
2542: my %allfiles = ();
2543: my %codebase = ();
2544: my ($upload_result,$upload_output);
2545: if ($allowed) {
2546: if (($env{'form.uploaddoc.filename'}) &&
2547: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
2548: # Process file upload - phase one - upload and parse primary file.
2549: $upload_result = &process_file_upload(\$upload_output,$coursenum,
2550: $coursedom,\%allfiles,
2551: \%codebase,$1);
2552: if ($upload_result eq 'phasetwo') {
2553: $r->print($upload_output);
2554: }
2555: } elsif ($env{'form.phasetwo'}) {
2556: my %newname = ();
2557: my %origname = ();
2558: my %attribs = ();
2559: my $updateflag = 0;
2560: my $residx = $env{'form.newidx'};
2561: my $primary_url = &unescape($env{'form.primaryurl'});
2562: # Process file upload - phase two - gather secondary files.
2563: for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
2564: if ($env{'form.embedded_item_'.$i.'.filename'}) {
2565: my $javacodebase;
2566: $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
2567: $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
2568: if (exists($env{'form.embedded_codebase_'.$i})) {
2569: $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
2570: $origname{$i} =~ s#^\Q$javacodebase\E/##;
2571: }
2572: my @attributes = ();
2573: if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
2574: @attributes = split/:/,$env{'form.embedded_attrib_'.$i};
2575: } else {
2576: @attributes = ($env{'form.embedded_attrib_'.$i});
2577: }
2578: foreach (@attributes) {
2579: push(@{$attribs{$i}},&unescape($_));
2580: }
2581: if ($javacodebase) {
2582: $codebase{$i} = $javacodebase;
2583: $codebase{$i} =~ s#/$##;
2584: $updateflag = 1;
2585: }
2586: }
2587: unless ($newname{$i} eq $origname{$i}) {
2588: $updateflag = 1;
2589: }
2590: }
2591: # Process file upload - phase three - modify primary file
2592: if ($updateflag) {
2593: my ($content,$rtncode);
2594: my $updateflag = 0;
2595: my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
2596: if ($getstatus eq 'ok') {
2597: foreach my $item (keys %newname) {
2598: if ($newname{$item} ne $origname{$item}) {
2599: my $attrib_regexp = '';
2600: if (@{$attribs{$item}} > 1) {
2601: $attrib_regexp = join('|',@{$attribs{$item}});
2602: } else {
2603: $attrib_regexp = $attribs{$item}[0];
2604: }
2605: if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
2606: }
2607: $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
2608: }
2609: if (exists($codebase{$item})) {
2610: $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
2611: }
2612: }
2613: # Save edited file.
2614: my $saveresult;
2615: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2616: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2617: my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
2618: } else {
2619: &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
2620: }
2621: }
2622: }
2623: }
2624:
2625: unless ($showdoc || $upload_result eq 'phasetwo') {
2626: # -----------------------------------------------------------------------------
2627: my %lt=&Apache::lonlocal::texthash(
2628: 'uplm' => 'Upload a new main '.lc($type).' document',
2629: 'upls' => 'Upload a new supplemental '.lc($type).' document',
2630: 'impp' => 'Import a document',
2631: 'pubd' => 'Published documents',
2632: 'copm' => 'All documents out of a published map into this folder',
2633: 'spec' => 'Special documents',
2634: 'upld' => 'Upload Document',
2635: 'srch' => 'Search',
2636: 'impo' => 'Import',
2637: 'book' => 'Import Bookmarks',
2638: 'selm' => 'Select Map',
2639: 'load' => 'Load Map',
2640: 'reco' => 'Recover Deleted Resources',
2641: 'newf' => 'New Folder',
2642: 'newp' => 'New Composite Page',
2643: 'extr' => 'External Resource',
2644: 'syll' => 'Syllabus',
2645: 'navc' => 'Navigate Contents',
2646: 'sipa' => 'Simple Page',
2647: 'sipr' => 'Simple Problem',
2648: 'drbx' => 'Drop Box',
2649: 'scuf' => 'Score Upload Form',
2650: 'bull' => 'Bulletin Board',
2651: 'mypi' => 'My Personal Info',
2652: 'grpo' => 'Group Files',
2653: 'abou' => 'About User',
2654: 'imsf' => 'Import IMS package',
2655: 'file' => 'File',
2656: 'title' => 'Title',
2657: 'comment' => 'Comment',
2658: 'parse' => 'If HTML file, upload embedded images/multimedia files'
2659: );
2660: # -----------------------------------------------------------------------------
2661: if ($allowed) {
2662: &update_paste_buffer($coursenum,$coursedom);
2663: my $dumpbut=&dumpbutton();
2664: my $exportbut=&exportbutton();
2665: my %lt=&Apache::lonlocal::texthash(
2666: 'vc' => 'Verify Content',
2667: 'cv' => 'Check/Set Resource Versions',
2668: 'ls' => 'List Symbs',
2669: 'sl' => 'Show Log'
2670: );
2671:
2672: my $folderpath=$env{'form.folderpath'};
2673: if (!$folderpath) {
2674: if ($env{'form.folder'} eq '' ||
2675: $env{'form.folder'} eq 'supplemental') {
2676: $folderpath='default&'.
2677: &escape(&mt('Main '.$type.' Documents'));
2678: }
2679: }
2680: unless ($env{'form.pagepath'}) {
2681: $containertag = '<input type="hidden" name="folderpath" value="" />';
2682: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
2683: }
2684:
2685: $r->print(<<ENDCOURSEVERIFY);
2686: <form name="renameform" method="post" action="/adm/coursedocs">
2687: <input type="hidden" name="title" />
2688: <input type="hidden" name="cmd" />
2689: <input type="hidden" name="markcopy" />
2690: <input type="hidden" name="copyfolder" />
2691: $containertag
2692: </form>
2693: <form name="simpleedit" method="post" action="/adm/coursedocs">
2694: <input type="hidden" name="importdetail" value="" />
2695: $uploadtag
2696: </form>
2697: <form action="/adm/coursedocs" method="post" name="courseverify">
2698: <div class="LC_docs_course_commands">
2699:
2700: <div>
2701: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
2702: </div>
2703: <div>
2704: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
2705: </div>
2706: $dumpbut
2707: $exportbut
2708: <div>
2709: <input type="submit" name="listsymbs" value="$lt{'ls'}" />
2710: </div>
2711: <div>
2712: <input type="hidden" name="folder" value="$env{'form.folder'}" />
2713: <input type="submit" name="docslog" value="$lt{'sl'}" />
2714: </div>
2715: </div>
2716: </form>
2717: <div style="clear: both; height: 0px;"> </div>
2718: ENDCOURSEVERIFY
2719: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
2720: &mt('Editing the Table of Contents for your '.$type)));
2721: }
2722: # --------------------------------------------------------- Standard documents
2723: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
2724: if (($standard) && ($allowed) && (!$forcesupplement)) {
2725: $r->print('<tr><td bgcolor="#BBBBBB">');
2726: # '<h2>'.&mt('Main Course Documents').
2727: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
2728: my $folder=$env{'form.folder'};
2729: if ($folder eq '' || $folder eq 'supplemental') {
2730: $folder='default';
2731: $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
2732: }
2733: my $postexec='';
2734: if ($folder eq 'default') {
2735: $r->print('<script>this.window.name="loncapaclient";</script>');
2736: } else {
2737: #$postexec='self.close();';
2738: }
2739: $hadchanges=0;
2740: &editor($r,$coursenum,$coursedom,$folder,$allowed,$upload_output);
2741: if ($hadchanges) {
2742: &mark_hash_old()
2743: }
2744: &changewarning($r,$postexec);
2745: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2746: '.sequence';
2747: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2748: '.page';
2749: my $container='sequence';
2750: if ($env{'form.pagepath'}) {
2751: $container='page';
2752: }
2753: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
2754: $r->print(<<ENDFORM);
2755: <table cellspacing=4 cellpadding=4><tr>
2756: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
2757: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
2758: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
2759: </tr>
2760: <tr><td bgcolor="#DDDDDD">
2761: $lt{'file'}:<br />
2762: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
2763: <input type="file" name="uploaddoc" size="40">
2764: <br />
2765: $lt{'title'}:<br />
2766: <input type="text" size="50" name="comment">
2767: $uploadtag
2768: <input type="hidden" name="cmd" value="upload_default">
2769: <br />
2770: <nobr>
2771: <label>$lt{'parse'}?
2772: <input type="checkbox" name="parserflag" />
2773: </label>
2774: </nobr>
2775: <br />
2776: <br />
2777: <nobr>
2778: <input type="submit" value="$lt{'upld'}">
2779: $help{'Uploading_From_Harddrive'}
2780: </nobr>
2781: </form>
2782: </td>
2783: <td bgcolor="#DDDDDD">
2784: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
2785: $lt{'pubd'}<br />
2786: $uploadtag
2787: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}" />
2788: <br />
2789: <nobr>
2790: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}" />
2791: $help{'Importing_LON-CAPA_Resource'}
2792: </nobr>
2793: <br />
2794: <input type=button onClick="javascript:groupopen(0,1,1);" value="$lt{'book'}" />
2795: <p>
2796: <hr />
2797: $lt{'copm'}<br />
2798: <input type="text" size="40" name="importmap" /><br />
2799: <nobr><input type=button
2800: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
2801: value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
2802: $help{'Load_Map'}</nobr>
2803: </p>
2804: </form>
2805: <hr />
2806: <form action="/adm/groupsort" method="post" name="recover">
2807: <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />
2808: </form>
2809: ENDFORM
2810: unless ($env{'form.pagepath'}) {
2811: $r->print(<<ENDFORM);
2812: <hr />
2813: <form action="/adm/coursedocs" method="post" name="newext">
2814: $uploadtag
2815: <input type="hidden" name="importdetail" value="" />
2816: <nobr>
2817: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
2818: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
2819: </nobr>
2820: </form>
2821: <br /><form action="/adm/imsimportdocs" method="post" name="ims">
2822: <input type="hidden" name="folder" value="$folder" />
2823: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
2824: </form>
2825: ENDFORM
2826: }
2827: $r->print('</td><td bgcolor="#DDDDDD">');
2828: unless ($env{'form.pagepath'}) {
2829: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
2830: $r->print(<<ENDFORM);
2831: <br /><form action="/adm/coursedocs" method="post" name="newfolder">
2832: <input type="hidden" name="folderpath" value="$path" />
2833: <input type="hidden" name="importdetail" value="" />
2834: <nobr>
2835: <input name="newfolder" type="button"
2836: onClick="javascript:makenewfolder(this.form,'$folderseq');"
2837: value="$lt{'newf'}" />$help{'Adding_Folders'}
2838: </nobr>
2839: </form>
2840: <br /><form action="/adm/coursedocs" method="post" name="newpage">
2841: <input type="hidden" name="folderpath" value="$path" />
2842: <input type="hidden" name="importdetail" value="" />
2843: <nobr>
2844: <input name="newpage" type="button"
2845: onClick="javascript:makenewpage(this.form,'$pageseq');"
2846: value="$lt{'newp'}" />$help{'Adding_Pages'}
2847: </nobr>
2848: </form>
2849: <br /><form action="/adm/coursedocs" method="post" name="newsyl">
2850: $uploadtag
2851: <input type="hidden" name="importdetail"
2852: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
2853: <nobr>
2854: <input name="newsyl" type="submit" value="$lt{'syll'}" />
2855: $help{'Syllabus'}
2856: </nobr>
2857: </form>
2858: <br /><form action="/adm/coursedocs" method="post" name="newnav">
2859: $uploadtag
2860: <input type="hidden" name="importdetail"
2861: value="Navigate Content=/adm/navmaps" />
2862: <nobr>
2863: <input name="newnav" type="submit" value="$lt{'navc'}" />
2864: $help{'Navigate_Content'}
2865: </nobr>
2866: </form>
2867: <br /><form action="/adm/coursedocs" method="post" name="newsmppg">
2868: $uploadtag
2869: <input type="hidden" name="importdetail" value="" />
2870: <nobr>
2871: <input name="newsmppg" type="button" value="$lt{'sipa'}"
2872: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
2873: </nobr>
2874: </form>
2875: <br /><form action="/adm/coursedocs" method="post" name="newsmpproblem">
2876: $uploadtag
2877: <input type="hidden" name="importdetail" value="" />
2878: <nobr>
2879: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2880: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2881: </nobr>
2882: </form>
2883: <br /><form action="/adm/coursedocs" method="post" name="newdropbox">
2884: $uploadtag
2885: <input type="hidden" name="importdetail" value="" />
2886: <nobr>
2887: <input name="newdropbox" type="button" value="$lt{'drbx'}"
2888: onClick="javascript:makedropbox();" />
2889: </nobr>
2890: </form>
2891: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
2892: $uploadtag
2893: <input type="hidden" name="importdetail" value="" />
2894: <nobr>
2895: <input name="newexamupload" type="button" value="$lt{'scuf'}"
2896: onClick="javascript:makeexamupload();" />
2897: $help{'Score_Upload_Form'}
2898: </nobr>
2899: </form>
2900: <br /><form action="/adm/coursedocs" method="post" name="newbul">
2901: $uploadtag
2902: <input type="hidden" name="importdetail" value="" />
2903: <nobr>
2904: <input name="newbulletin" type="button" value="$lt{'bull'}"
2905: onClick="javascript:makebulboard();" />
2906: $help{'Bulletin Board'}
2907: </nobr>
2908: </form>
2909: <br /><form action="/adm/coursedocs" method="post" name="newaboutme">
2910: $uploadtag
2911: <input type="hidden" name="importdetail"
2912: value="$plainname=/adm/$udom/$uname/aboutme" />
2913: <nobr>
2914: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
2915: $help{'My Personal Info'}
2916: </nobr>
2917: </form>
2918: <br /><form action="/adm/coursedocs" method="post" name="newaboutsomeone">
2919: $uploadtag
2920: <input type="hidden" name="importdetail" value="" />
2921: <nobr>
2922: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
2923: onClick="javascript:makeabout();" />
2924: </nobr>
2925: </form>
2926: <br /><form action="/adm/coursedocs" method="post" name="newgroupfiles">
2927: $uploadtag
2928: <input type="hidden" name="importdetail"
2929: value="Group Files=/adm/$coursedom/$coursenum/aboutme" />
2930: <nobr>
2931: <input name="newgroupfiles" type="submit" value="$lt{'grpo'}" />
2932: $help{'Group Files'}
2933: </nobr>
2934: </form>
2935: ENDFORM
2936: }
2937: if ($env{'form.pagepath'}) {
2938: $r->print(<<ENDBLOCK);
2939: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
2940: $uploadtag
2941: <input type="hidden" name="importdetail" value="" />
2942: <nobr>
2943: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2944: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2945: </nobr>
2946: </form>
2947: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
2948: $uploadtag
2949: <input type="hidden" name="importdetail" value="" />
2950: <nobr>
2951: <input name="newexamupload" type="button" value="$lt{'scuf'}"
2952: onClick="javascript:makeexamupload();" />
2953: $help{'Score_Upload_Form'}
2954: </nobr>
2955: </form>
2956: ENDBLOCK
2957: }
2958: $r->print('</td></tr>'."\n".
2959: '</table>');
2960: $r->print('</td></tr>');
2961: }
2962: # ----------------------------------------------------- Supplemental documents
2963: if (!$forcestandard) {
2964: $r->print('<tr><td bgcolor="#BBBBBB">');
2965: # '<h2>'.&mt('Supplemental Course Documents').
2966: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
2967: my $folder=$env{'form.folder'};
2968: unless ($folder=~/^supplemental/) {
2969: $folder='supplemental';
2970: }
2971: if ($folder =~ /^supplemental$/ &&
2972: $env{'form.folderpath'} =~ /^default\&/) {
2973: $env{'form.folderpath'}='supplemental&'.
2974: &escape(&mt('Supplemental '.$type.' Documents'));
2975: }
2976: &editor($r,$coursenum,$coursedom,$folder,$allowed);
2977: if ($allowed) {
2978: my $folderseq=
2979: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
2980: '.sequence';
2981:
2982: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
2983: $r->print(<<ENDSUPFORM);
2984: <table cellspacing=4 cellpadding=4><tr>
2985: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
2986: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
2987: </tr>
2988: <tr><td bgcolor="#DDDDDD">
2989: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
2990: <input type="file" name="uploaddoc" size="40">
2991: <br />
2992: <br />
2993: <nobr>
2994: <label>$lt{'parse'}?
2995: <input type="checkbox" name="parserflag" />
2996: </label>
2997: </nobr>
2998: <br /><br />
2999: $lt{'comment'}:<br />
3000: <textarea cols=50 rows=4 name='comment'>
3001: </textarea>
3002: <br />
3003: <input type="hidden" name="folderpath" value="$path" />
3004: <input type="hidden" name="cmd" value="upload_supplemental">
3005: <nobr>
3006: <input type="submit" value="$lt{'upld'}">
3007: $help{'Uploading_From_Harddrive'}
3008: </nobr>
3009: </form>
3010: </td>
3011: <td bgcolor="#DDDDDD">
3012: <form action="/adm/coursedocs" method="post" name="supnewfolder">
3013: <input type="hidden" name="folderpath" value="$path" />
3014: <input type="hidden" name="importdetail" value="" />
3015: <nobr>
3016: <input name="newfolder" type="button"
3017: onClick="javascript:makenewfolder(this.form,'$folderseq');"
3018: value="$lt{'newf'}" /> $help{'Adding_Folders'}
3019: </nobr>
3020: </form>
3021: <br /><form action="/adm/coursedocs" method="post" name="supnewext">
3022: <input type="hidden" name="folderpath" value="$path" />
3023: <input type="hidden" name="importdetail" value="" />
3024: <nobr>
3025: <input name="newext" type="button"
3026: onClick="javascript:makenewext('supnewext');"
3027: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
3028: </nobr>
3029: </form>
3030: <br /><form action="/adm/coursedocs" method="post" name="supnewsyl">
3031: <input type="hidden" name="folderpath" value="$path" />
3032: <input type="hidden" name="importdetail"
3033: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
3034: <nobr>
3035: <input name="newsyl" type="submit" value="$lt{'syll'}" />
3036: $help{'Syllabus'}
3037: </nobr>
3038: </form>
3039: <br /><form action="/adm/coursedocs" method="post" name="subnewaboutme">
3040: <input type="hidden" name="folderpath" value="$path" />
3041: <input type="hidden" name="importdetail"
3042: value="$plainname=/adm/$udom/$uname/aboutme" />
3043: <nobr>
3044: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
3045: $help{'My Personal Info'}
3046: </nobr>
3047: </form>
3048: </td></tr>
3049: </table></td></tr>
3050: ENDSUPFORM
3051: }
3052: }
3053: if ($allowed) {
3054: $r->print('<form method="POST" name="extimport" action="/adm/coursedocs"><input type="hidden" name="title" /><input type="hidden" name="url" /><input type="hidden" name="useform" /></form>');
3055: }
3056: $r->print('</table>');
3057: } else {
3058: unless ($upload_result eq 'phasetwo') {
3059: # -------------------------------------------------------- This is showdoc mode
3060: $r->print("<h1>".&mt('Uploaded Document').' - '.
3061: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3062: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
3063: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
3064: }
3065: }
3066: }
3067: $r->print(&Apache::loncommon::end_page());
3068: return OK;
3069: }
3070:
3071:
3072: sub editing_js {
3073: my ($udom,$uname) = @_;
3074: my $now = time();
3075:
3076: return <<ENDNEWSCRIPT;
3077: function makenewfolder(targetform,folderseq) {
3078: var foldername=prompt('Name of New Folder','New Folder');
3079: if (foldername) {
3080: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3081: targetform.submit();
3082: }
3083: }
3084:
3085: function makenewpage(targetform,folderseq) {
3086: var pagename=prompt('Name of New Page','New Page');
3087: if (pagename) {
3088: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3089: targetform.submit();
3090: }
3091: }
3092:
3093: function makenewext(targetname) {
3094: this.document.forms.extimport.useform.value=targetname;
3095: window.open('/adm/rat/extpickframe.html');
3096: }
3097:
3098: function makeexamupload() {
3099: var title=prompt('Listed Title for the Uploaded Score');
3100: if (title) {
3101: this.document.forms.newexamupload.importdetail.value=
3102: escape(title)+'=/res/lib/templates/examupload.problem';
3103: this.document.forms.newexamupload.submit();
3104: }
3105: }
3106:
3107: function makesmppage() {
3108: var title=prompt('Listed Title for the Page');
3109: if (title) {
3110: this.document.forms.newsmppg.importdetail.value=
3111: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3112: this.document.forms.newsmppg.submit();
3113: }
3114: }
3115:
3116: function makesmpproblem() {
3117: var title=prompt('Listed Title for the Problem');
3118: if (title) {
3119: this.document.forms.newsmpproblem.importdetail.value=
3120: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3121: this.document.forms.newsmpproblem.submit();
3122: }
3123: }
3124:
3125: function makedropbox() {
3126: var title=prompt('Listed Title for the Drop Box');
3127: if (title) {
3128: this.document.forms.newdropbox.importdetail.value=
3129: escape(title)+'=/res/lib/templates/DropBox.problem';
3130: this.document.forms.newdropbox.submit();
3131: }
3132: }
3133:
3134: function makebulboard() {
3135: var title=prompt('Listed Title for the Bulletin Board');
3136: if (title) {
3137: this.document.forms.newbul.importdetail.value=
3138: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3139: this.document.forms.newbul.submit();
3140: }
3141: }
3142:
3143: function makeabout() {
3144: var user=prompt("Enter user:domain for User's 'About Me' Page");
3145: if (user) {
3146: var comp=new Array();
3147: comp=user.split(':');
3148: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3149: if ((comp[0]) && (comp[1])) {
3150: this.document.forms.newaboutsomeone.importdetail.value=
3151: 'About '+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
3152: this.document.forms.newaboutsomeone.submit();
3153: } else {
3154: alert("Not a valid user:domain");
3155: }
3156: } else {
3157: alert("Please enter both user and domain in the format user:domain");
3158: }
3159: }
3160: }
3161:
3162: function makeims() {
3163: var caller = document.forms.ims.folder.value;
3164: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3165: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3166: newWindow.location.href = newlocation;
3167: }
3168:
3169:
3170: function finishpick() {
3171: var title=this.document.forms.extimport.title.value;
3172: var url=this.document.forms.extimport.url.value;
3173: var form=this.document.forms.extimport.useform.value;
3174: eval
3175: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
3176: '";this.document.forms.'+form+'.submit();');
3177: }
3178:
3179: function changename(folderpath,index,oldtitle,container,pagesymb) {
3180: var title=prompt('New Title',oldtitle);
3181: if (title) {
3182: this.document.forms.renameform.markcopy.value=-1;
3183: this.document.forms.renameform.title.value=title;
3184: this.document.forms.renameform.cmd.value='rename_'+index;
3185: if (container == 'sequence') {
3186: this.document.forms.renameform.folderpath.value=folderpath;
3187: }
3188: if (container == 'page') {
3189: this.document.forms.renameform.pagepath.value=folderpath;
3190: this.document.forms.renameform.pagesymb.value=pagesymb;
3191: }
3192: this.document.forms.renameform.submit();
3193: }
3194: }
3195:
3196: function removeres(folderpath,index,oldtitle,container,pagesymb) {
3197: if (confirm('WARNING: Removing a resource makes associated grades and scores inaccessible!\\nRemove "'+oldtitle+'"?')) {
3198: this.document.forms.renameform.markcopy.value=-1;
3199: this.document.forms.renameform.cmd.value='del_'+index;
3200: if (container == 'sequence') {
3201: this.document.forms.renameform.folderpath.value=folderpath;
3202: }
3203: if (container == 'page') {
3204: this.document.forms.renameform.pagepath.value=folderpath;
3205: this.document.forms.renameform.pagesymb.value=pagesymb;
3206: }
3207: this.document.forms.renameform.submit();
3208: }
3209: }
3210:
3211: function cutres(folderpath,index,oldtitle,container,pagesymb,folder) {
3212: if (confirm('WARNING: Cutting a resource makes associated grades and scores inaccessible!\\nGrades remain inaccessible if resource is pasted into another folder.\\nCut "'+oldtitle+'"?')) {
3213: this.document.forms.renameform.cmd.value='cut_'+index;
3214: this.document.forms.renameform.markcopy.value=index;
3215: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3216: if (container == 'sequence') {
3217: this.document.forms.renameform.folderpath.value=folderpath;
3218: }
3219: if (container == 'page') {
3220: this.document.forms.renameform.pagepath.value=folderpath;
3221: this.document.forms.renameform.pagesymb.value=pagesymb;
3222: }
3223: this.document.forms.renameform.submit();
3224: }
3225: }
3226:
3227: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
3228: this.document.forms.renameform.markcopy.value=index;
3229: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3230: if (container == 'sequence') {
3231: this.document.forms.renameform.folderpath.value=folderpath;
3232: }
3233: if (container == 'page') {
3234: this.document.forms.renameform.pagepath.value=folderpath;
3235: this.document.forms.renameform.pagesymb.value=pagesymb;
3236: }
3237: this.document.forms.renameform.submit();
3238: }
3239:
3240: ENDNEWSCRIPT
3241: }
3242: 1;
3243: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>