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