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