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