1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.138 2004/08/22 18:15:54 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::lonnet;
34: use Apache::loncommon;
35: use Apache::lonratedt;
36: use Apache::lonratsrv;
37: use Apache::lonxml;
38: use Apache::loncreatecourse;
39: use Apache::lonnavmaps;
40: use HTML::Entities;
41: use GDBM_File;
42: use Apache::lonlocal;
43:
44: my $iconpath;
45:
46: my %hash;
47:
48: my $hashtied;
49: my %alreadyseen=();
50:
51: my $hadchanges;
52:
53: # Available help topics
54:
55: my %help=();
56:
57: # Mapread read maps into lonratedt::global arrays
58: # @order and @resources, determines status
59: # sets @order - pointer to resources in right order
60: # sets @resources - array with the resources with correct idx
61: #
62:
63: sub mapread {
64: my ($coursenum,$coursedom,$map)=@_;
65: return
66: &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
67: $map);
68: }
69:
70: sub storemap {
71: my ($coursenum,$coursedom,$map)=@_;
72: my ($outtext,$errtext)=
73: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
74: $map,1);
75: if ($errtext) { return ($errtext,2); }
76:
77: $hadchanges=1;
78: return ($errtext,0);
79: }
80:
81: # ----------------------------------------- Return hash with valid author names
82:
83: sub authorhosts {
84: my %outhash=();
85: my $home=0;
86: my $other=0;
87: foreach (keys %ENV) {
88: if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
89: my $role=$1;
90: my $realm=$2;
91: my ($start,$end)=split(/\./,$ENV{$_});
92: if (($start) && ($start>time)) { next; }
93: if (($end) && (time>$end)) { next; }
94: my $ca; my $cd;
95: if ($1 eq 'au') {
96: $ca=$ENV{'user.name'};
97: $cd=$ENV{'user.domain'};
98: } else {
99: ($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
100: }
101: my $allowed=0;
102: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
103: my @ids=&Apache::lonnet::current_machine_ids();
104: foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
105: if ($allowed) {
106: $home++;
107: $outhash{'home_'.$ca.'@'.$cd}=1;
108: } else {
109: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
110: $other++;
111: }
112: }
113: }
114: return ($home,$other,%outhash);
115: }
116: # ------------------------------------------------------ Generate "dump" button
117:
118: sub dumpbutton {
119: my ($home,$other,%outhash)=&authorhosts();
120: if ($home+$other==0) { return ''; }
121: my $output='</td><td bgcolor="#DDDDCC">';
122: if ($home) {
123: return '</td><td bgcolor="#DDDDCC">'.
124: '<input type="submit" name="dumpcourse" value="'.
125: &mt('Dump Course DOCS to Construction Space').'" />'.
126: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
127: } else {
128: return'</td><td bgcolor="#DDDDCC">'.
129: &mt('Dump Course DOCS to Construction Space: available on other servers');
130: }
131: }
132:
133: # -------------------------------------------------------- Actually dump course
134:
135: sub dumpcourse {
136: my $r=shift;
137: $r->print('<html><head><title>Dump DOCS</title></head>'.
138: &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
139: '<form name="dumpdoc" method="post">');
140: my ($home,$other,%outhash)=&authorhosts();
141: unless ($home) { return ''; }
142: my $origcrsid=$ENV{'request.course.id'};
143: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
144: if (($ENV{'form.authorspace'}) && ($ENV{'form.authorfolder'}=~/\w/)) {
145: # Do the dumping
146: unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
147: my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
148: $r->print('<h3>'.&mt('Copying Files').'</h3>');
149: my $title=$ENV{'form.authorfolder'};
150: $title=~s/[^\w\/]+/\_/g;
151: my %replacehash=();
152: foreach (keys %ENV) {
153: if ($_=~/^form\.namefor\_(.+)/) {
154: $replacehash{$1}=$ENV{$_};
155: }
156: }
157: my $crs='/uploaded/'.$ENV{'request.course.id'}.'/';
158: $crs=~s/\_/\//g;
159: foreach (keys %replacehash) {
160: my $newfilename=$title.'/'.$replacehash{$_};
161: $newfilename=~s/[^\w\/\.\/]+/\_/g;
162: my @dirs=split(/\//,$newfilename);
163: my $path='/home/'.$ca.'/public_html';
164: my $makepath=$path;
165: my $fail=0;
166: for (my $i=0;$i<$#dirs;$i++) {
167: $makepath.='/'.$dirs[$i];
168: unless (-e $makepath) {
169: unless(mkdir($makepath,0777)) { $fail=1; }
170: }
171: }
172: $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
173: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
174: if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
175: print $fh &Apache::loncreatecourse::rewritefile(
176: &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_),
177: (%replacehash,$crs => '')
178: );
179: } else {
180: print $fh
181: &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_);
182: }
183: $fh->close();
184: } else {
185: $fail=1;
186: }
187: if ($fail) {
188: $r->print('<font color="red">fail</font>');
189: } else {
190: $r->print('<font color="green">ok</font>');
191: }
192: }
193: } else {
194: # Input form
195: unless ($home==1) {
196: $r->print(
197: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
198: }
199: foreach (sort keys %outhash) {
200: if ($_=~/^home_(.+)$/) {
201: if ($home==1) {
202: $r->print(
203: '<input type="hidden" name="authorspace" value="'.$1.'" />');
204: } else {
205: $r->print('<option value="'.$1.'">'.$1.' - '.
206: &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
207: }
208: }
209: }
210: unless ($home==1) {
211: $r->print('</select>');
212: }
213: my $title=$origcrsdata{'description'};
214: $title=~s/\s+/\_/gs;
215: $title=~s/\W//gs;
216: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
217: &tiehash();
218: $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>');
219: foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
220: $r->print('<tr><td>'.$_.'</td>');
221: my ($ext)=($_=~/\.(\w+)$/);
222: my $title=$hash{'title_'.$hash{
223: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
224: $r->print('<td>'.($title?$title:' ').'</td>');
225: unless ($title) {
226: $title=$_;
227: }
228: $title=~s/\.(\w+)$//;
229: $title=~s/[^\w\/]+/\_/gs;
230: $title.='.'.$ext;
231: $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
232: }
233: $r->print("</table>\n");
234: &untiehash();
235: $r->print(
236: '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump Course DOCS').'" /></p></form>');
237: }
238: }
239:
240: # ------------------------------------------------------ Generate "export" button
241:
242: sub exportbutton {
243: return '</td><td bgcolor="#DDDDCC">'.
244: '<input type="submit" name="exportcourse" value="'.
245: &mt('Export Course to IMS').'" />'.
246: &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
247: }
248:
249: sub exportcourse {
250: my $r=shift;
251: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
252: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
253: my $numdisc = keys %discussiontime;
254: my $navmap = Apache::lonnavmaps::navmap->new();
255: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
256: my $curRes;
257:
258: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
259: ['finishexport']);
260: if ($ENV{'form.finishexport'}) {
261: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
262: ['archive','discussion']);
263:
264: my @exportitems = ();
265: if (defined($ENV{'form.archive'})) {
266: if (ref($ENV{'form.archive'}) eq 'ARRAY') {
267: @exportitems = @{$ENV{'form.archive'}};
268: } else {
269: $exportitems[0] = $ENV{'form.archive'};
270: }
271: }
272: my @discussions = ();
273: if (defined($ENV{'form.discussion'})) {
274: if (ref($ENV{'form.discussion'}) eq 'ARRAY') {
275: @discussions = $ENV{'form.discussion'};
276: } else {
277: $discussions[0] = $ENV{'form.discussion'};
278: }
279: }
280: my $curRes;
281: my $count;
282: my %symbs;
283: my $display;
284: while ($curRes = $it->next()) {
285: if (ref($curRes)) {
286: $count ++;
287: $symbs{$count} = $curRes->symb();
288: if (grep/^$count$/,@exportitems) {
289: $display.= 'Export content item '.$curRes->title()."<br />\n";
290: }
291: if (grep/^$count$/,@discussions) {
292: $display.= 'Export discussion posts '.$curRes->title()."<br />\n";
293: }
294: }
295: }
296:
297: $r->print('<html><head><title>Export Course</title></head>'.
298: &Apache::loncommon::bodytag('Export course to IMS or SCORM content package'
299: ));
300:
301: my $exportfile;
302: $r->print($display);
303: $r->print('</body></html>');
304: } else {
305: my $display;
306: $display = '<form name="exportdoc" method="post">'."\n";
307: $display .= 'Choose which items you wish to export from your course.<br /><br />';
308: $display .= '<table border="0" cellspacing="0" cellpadding="3">'.
309: '<tr><td><fieldset><legend> <b>Content items</b></legend>'.
310: '<input type="button" value="check all" '.
311: 'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
312: ' <input type="button" value="uncheck all"'.
313: ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.
314: '<td> </td><td> </td>'.
315: '<td align="right"><fieldset><legend> <b>Discussion posts'.
316: '</b></legend><input type="button" value="check all"'.
317: ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
318: ' <input type="button" value="uncheck all"'.
319: ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.
320: '</tr></table>';
321: my $curRes;
322: my $depth = 0;
323: my $count = 0;
324: my $boards = 0;
325: my $startcount = 5;
326: my %parent = ();
327: my %children = ();
328: my $lastcontainer = $startcount;
329: my @bgcolors = ('#F6F6F6','#FFFFFF');
330: $display .= '<table cellspacing="0"><tr>'.
331: '<td><b>Export content item?<br /></b></td><td> </td><td align="right">'."\n";
332: if ($numdisc > 0) {
333: $display.='<b>Export discussion posts?</b>'."\n";
334: }
335: $display.=' </td></tr>';
336: while ($curRes = $it->next()) {
337: if (ref($curRes)) {
338: $count ++;
339: }
340: if ($curRes == $it->BEGIN_MAP()) {
341: $depth++;
342: $parent{$depth} = $lastcontainer;
343: }
344: if ($curRes == $it->END_MAP()) {
345: $depth--;
346: $lastcontainer = $parent{$depth};
347: }
348: if (ref($curRes)) {
349: my $symb = $curRes->symb();
350: my $color = $count%2;
351: $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".
352: '<input type="checkbox" name="archive" value="'.$count.'" ';
353: if (($curRes->is_sequence()) || ($curRes->is_page())) {
354: my $checkitem = $count + $boards + $startcount;
355: $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';
356: }
357: $display .= ' />'."\n";
358: for (my $i=0; $i<$depth; $i++) {
359: $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";
360: }
361: if ($curRes->is_sequence()) {
362: $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif"> '."\n";
363: $lastcontainer = $count + $startcount + $boards;
364: } elsif ($curRes->is_page()) {
365: $display .= '<img src="/adm/lonIcons/navmap.page.open.gif"> '."\n";
366: $lastcontainer = $count + $startcount + $boards;
367: }
368: my $currelem = $count+$boards+$startcount;
369: $children{$parent{$depth}} .= $currelem.':';
370: $display .= ' '.$curRes->title().'</td>';
371: if ($discussiontime{$symb} > 0) {
372: $boards ++;
373: $currelem = $count+$boards+$startcount;
374: $display .= '<td> </td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" /> </td>'."\n";
375: } else {
376: $display .= '<td colspan="2"> </td>'."\n";
377: }
378: }
379: }
380: my $scripttag = qq|
381: <script>
382:
383: function checkAll(field) {
384: for (i = 0; i < field.length; i++)
385: field[i].checked = true ;
386: }
387:
388: function uncheckAll(field) {
389: for (i = 0; i < field.length; i++)
390: field[i].checked = false ;
391: }
392:
393: function propagateCheck(item) {
394: if (document.exportdoc.elements[item].checked == true) {
395: containerCheck(item)
396: }
397: }
398:
399: function containerCheck(item) {
400: document.exportdoc.elements[item].checked = true
401: var numitems = $count + $boards + $startcount
402: var parents = new Array(numitems)
403: for (var i=$startcount; i<numitems; i++) {
404: parents[i] = new Array
405: }
406: |;
407:
408: foreach my $container (sort { $a <=> $b } keys %children) {
409: my @contents = split/:/,$children{$container};
410: for (my $i=0; $i<@contents; $i ++) {
411: $scripttag .= ' parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
412: }
413: }
414:
415: $scripttag .= qq|
416: if (parents[item].length > 0) {
417: for (var j=0; j<parents[item].length; j++) {
418: containerCheck(parents[item][j])
419: }
420: }
421: }
422:
423: </script>
424: |;
425: $r->print('<html><head><title>Export Course</title>'.$scripttag.'</head>'.
426: &Apache::loncommon::bodytag('Export course to IMS or SCORM content package'
427: ));
428:
429: $r->print($display.'</table>'.
430: '<p><input type="hidden" name="finishexport" value="1">'.
431: '<input type="submit" name="exportcourse" value="'.
432: &mt('Export Course DOCS').'" /></p></form></body></html>');
433: }
434: }
435:
436:
437: # Imports the given (name, url) resources into the course
438: # coursenum, coursedom, and folder must precede the list
439: sub group_import {
440: my $coursenum = shift;
441: my $coursedom = shift;
442: my $folder = shift;
443: while (@_) {
444: my $name = shift;
445: my $url = shift;
446: if ($url) {
447: my $idx = $#Apache::lonratedt::resources + 1;
448: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
449: my $ext = 'false';
450: if ($url=~/^http:\/\//) { $ext = 'true'; }
451: $url =~ s/:/\:/g;
452: $name =~ s/:/\:/g;
453: $Apache::lonratedt::resources[$idx] =
454: join ':', ($name, $url, $ext, 'normal', 'res');
455: }
456: }
457: return &storemap($coursenum, $coursedom, $folder.'.sequence');
458: }
459:
460: sub breadcrumbs {
461: my ($where)=@_;
462: &Apache::lonhtmlcommon::clear_breadcrumbs();
463: my (@folders)=split('&',$ENV{'form.folderpath'});
464: my $folderpath;
465: while (@folders) {
466: my $folder=shift(@folders);
467: my $foldername=shift(@folders);
468: if ($folderpath) {$folderpath.='&';}
469: $folderpath.=$folder.'&'.$foldername;
470: my $url='/adm/coursedocs?folderpath='.
471: &Apache::lonnet::escape($folderpath);
472: &Apache::lonhtmlcommon::add_breadcrumb(
473: {'href'=>$url,
474: 'title'=>&Apache::lonnet::unescape($foldername),
475: 'text'=>'<font size="+1">'.
476: &Apache::lonnet::unescape($foldername).'</font>'
477: });
478:
479:
480: }
481: return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,
482: 0,'nohelp');
483: }
484:
485: sub editor {
486: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
487:
488: $r->print(&breadcrumbs($folder));
489: my $errtext='';
490: my $fatal=0;
491: ($errtext,$fatal)=
492: &mapread($coursenum,$coursedom,$folder.'.sequence');
493: if ($#Apache::lonratedt::order<1) {
494: $Apache::lonratedt::order[0]=1;
495: $Apache::lonratedt::resources[1]='';
496: }
497: if ($fatal) {
498: $r->print('<p><font color="red">'.$errtext.'</font></p>');
499: } else {
500: # ------------------------------------------------------------ Process commands
501:
502: # ---------------- if they are for this folder and user allowed to make changes
503: if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
504: # set parameters and change order
505: if (defined($ENV{'form.setparms'})) {
506: my $idx=$ENV{'form.setparms'};
507: # set parameters
508: if ($ENV{'form.randpick_'.$idx}) {
509: &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
510: } else {
511: &Apache::lonratedt::delparameter($idx,'parameter_randompick');
512: }
513: if ($ENV{'form.hidprs_'.$idx}) {
514: &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
515: } else {
516: &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
517: }
518: if ($ENV{'form.encprs_'.$idx}) {
519: &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
520: } else {
521: &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
522: }
523:
524: if ($ENV{'form.newpos'}) {
525: # change order
526:
527: my $newpos=$ENV{'form.newpos'}-1;
528: my $currentpos=$ENV{'form.currentpos'}-1;
529: my $i;
530: my @neworder=();
531: if ($newpos>$currentpos) {
532: # moving stuff up
533: for ($i=0;$i<$currentpos;$i++) {
534: $neworder[$i]=$Apache::lonratedt::order[$i];
535: }
536: for ($i=$currentpos;$i<$newpos;$i++) {
537: $neworder[$i]=$Apache::lonratedt::order[$i+1];
538: }
539: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
540: for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
541: $neworder[$i]=$Apache::lonratedt::order[$i];
542: }
543: } else {
544: # moving stuff down
545: for ($i=0;$i<$newpos;$i++) {
546: $neworder[$i]=$Apache::lonratedt::order[$i];
547: }
548: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
549: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
550: $neworder[$i]=$Apache::lonratedt::order[$i-1];
551: }
552: for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
553: $neworder[$i]=$Apache::lonratedt::order[$i];
554: }
555: }
556: @Apache::lonratedt::order=@neworder;
557: }
558: # store the changed version
559:
560: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
561: if ($fatal) {
562: $r->print('<p><font color="red">'.$errtext.'</font></p>');
563: return;
564: }
565:
566: }
567:
568: # upload a file, if present
569: if (($ENV{'form.uploaddoc.filename'}) &&
570: ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
571: if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
572: # this is for a course, not a user, so set coursedoc flag
573: # probably the only place in the system where this should be "1"
574: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
575: my $ext='false';
576: if ($url=~/^http\:\/\//) { $ext='true'; }
577: $url=~s/\:/\:/g;
578: my $comment=$ENV{'form.comment'};
579: $comment=~s/\</\<\;/g;
580: $comment=~s/\>/\>\;/g;
581: $comment=~s/\:/\:/g;
582: if ($folder=~/^supplemental/) {
583: $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
584: $ENV{'user.domain'}.'___&&&___'.$comment;
585: }
586: my $newidx=$#Apache::lonratedt::resources+1;
587: $Apache::lonratedt::resources[$newidx]=
588: $comment.':'.$url.':'.$ext.':normal:res';
589: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
590: $newidx;
591:
592: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
593: if ($fatal) {
594: $r->print('<p><font color="red">'.$errtext.'</font></p>');
595: return;
596: }
597: }
598: }
599: if ($ENV{'form.cmd'}) {
600: my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
601: if ($cmd eq 'del') {
602: my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
603: if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) {
604: &Apache::lonnet::removeuploadedurl($url);
605: }
606: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
607: $Apache::lonratedt::order[$i]=
608: $Apache::lonratedt::order[$i+1];
609: }
610: $#Apache::lonratedt::order--;
611: } elsif ($cmd eq 'up') {
612: if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
613: my $i=$Apache::lonratedt::order[$idx-1];
614: $Apache::lonratedt::order[$idx-1]=
615: $Apache::lonratedt::order[$idx];
616: $Apache::lonratedt::order[$idx]=$i;
617: }
618: } elsif ($cmd eq 'down') {
619: if (defined($Apache::lonratedt::order[$idx+1])) {
620: my $i=$Apache::lonratedt::order[$idx+1];
621: $Apache::lonratedt::order[$idx+1]=
622: $Apache::lonratedt::order[$idx];
623: $Apache::lonratedt::order[$idx]=$i;
624: }
625: } elsif ($cmd eq 'rename') {
626: my ($rtitle,@rrest)=split(/\:/,
627: $Apache::lonratedt::resources[
628: $Apache::lonratedt::order[$idx]]);
629: my $comment=
630: &HTML::Entities::decode($ENV{'form.title'});
631: $comment=~s/\</\<\;/g;
632: $comment=~s/\>/\>\;/g;
633: $comment=~s/\:/\:/g;
634: $Apache::lonratedt::resources[
635: $Apache::lonratedt::order[$idx]]=
636: $comment.':'.join(':',@rrest);
637:
638: }
639: # Store the changed version
640: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
641: $folder.'.sequence');
642: if ($fatal) {
643: $r->print('<p><font color="red">'.$errtext.'</font></p>');
644: return;
645: }
646: }
647: # Group import/search
648: if ($ENV{'form.importdetail'}) {
649: my @imports;
650: foreach (split(/\&/,$ENV{'form.importdetail'})) {
651: if (defined($_)) {
652: my ($name,$url)=split(/\=/,$_);
653: $name=&Apache::lonnet::unescape($name);
654: $url=&Apache::lonnet::unescape($url);
655: push @imports, $name, $url;
656: }
657: }
658: # Store the changed version
659: ($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
660: @imports);
661: if ($fatal) {
662: $r->print('<p><font color="red">'.$errtext.'</font></p>');
663: return;
664: }
665: }
666: # Loading a complete map
667: if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
668: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
669: my $idx=$#Apache::lonratedt::resources;
670: $idx++;
671: $Apache::lonratedt::resources[$idx]=$_;
672: $Apache::lonratedt::order
673: [$#Apache::lonratedt::order+1]=$idx;
674: }
675:
676: # Store the changed version
677: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
678: $folder.'.sequence');
679: if ($fatal) {
680: $r->print('<p><font color="red">'.$errtext.'</font></p>');
681: return;
682: }
683: }
684: }
685: # ---------------------------------------------------------------- End commands
686: # ---------------------------------------------------------------- Print screen
687: my $idx=0;
688: $r->print('<table>');
689: foreach (@Apache::lonratedt::order) {
690: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
691: unless ($name) { $name=(split(/\//,$url))[-1]; }
692: unless ($name) { next; }
693: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
694: $idx++;
695: }
696: unless ($idx) {
697: $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
698: }
699: $r->print('</table>');
700: }
701: }
702:
703: # --------------------------------------------------------------- An entry line
704:
705: sub entryline {
706: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
707: $title=~s/\&colon\;/\:/g;
708: $title=&HTML::Entities::encode(&HTML::Entities::decode(
709: &Apache::lonnet::unescape($title)),'"<>&\'');
710: my $renametitle=$title;
711: my $foldertitle=$title;
712: my $orderidx=$Apache::lonratedt::order[$index];
713: if ($title=~ /^(\d+)___&&&___(\w+)___&&&___(\w+)___&&&___(.*)$/ ) {
714: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
715: $renametitle=$4;
716: $title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
717: &Apache::loncommon::plainname($2,$3).': <br />'.
718: $foldertitle;
719: }
720: $renametitle=~s/\"\;/\\\"/g;
721: my $line='<tr>';
722: # Edit commands
723: my $folderpath;
724: if ($ENV{'form.folderpath'}) {
725: $folderpath=&Apache::lonnet::escape($ENV{'form.folderpath'});
726: # $htmlfoldername=&HTML::Entities::encode($ENV{'form.foldername'},'<>&"');
727: }
728: if ($allowed) {
729: my $incindex=$index+1;
730: my $selectbox='';
731: if ($folder!~/^supplemental/) {
732: $selectbox=
733: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
734: '<select name="newpos" onChange="this.form.submit()">';
735: for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
736: if ($i==$incindex) {
737: $selectbox.='<option value="" selected="1">('.$i.')</option>';
738: } else {
739: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
740: }
741: }
742: $selectbox.='</select>';
743: }
744: my %lt=&Apache::lonlocal::texthash(
745: 'up' => 'Move Up',
746: 'dw' => 'Move Down',
747: 'rm' => 'Remove',
748: 'rn' => 'Rename');
749: $line.=(<<END);
750: <form name="entry_$index" action="/adm/coursedocs" method="post">
751: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
752: <input type="hidden" name="setparms" value="$orderidx" />
753: <td><table border='0' cellspacing='2' cellpadding='0'>
754: <tr><td bgcolor="#DDDDDD">
755: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath'>
756: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
757: <tr><td bgcolor="#DDDDDD">
758: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath'>
759: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
760: </table></td>
761: <td>$selectbox
762: </td><td bgcolor="#DDDDDD">
763: <a href='javascript:removeres("$folderpath","$index","$renametitle");'>
764: <font size="-2" color="#990000">$lt{'rm'}</font></a>
765: <a href='javascript:changename("$folderpath","$index","$renametitle");'>
766: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
767: END
768: }
769: # Figure out what kind of a resource this is
770: my ($extension)=($url=~/\.(\w+)$/);
771: my $uploaded=($url=~/^\/*uploaded\//);
772: my $icon=&Apache::loncommon::icon($url);
773: my $isfolder=0;
774: my $folderarg;
775: if ($uploaded) {
776: if ($extension eq 'sequence') {
777: $icon=$iconpath.'/folder_closed.gif';
778: $url=~/$coursenum\/([\/\w]+)\.sequence$/;
779: $url='/adm/coursedocs?';
780: $folderarg=$1;
781: $isfolder=1;
782: } else {
783: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
784: }
785: }
786: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
787: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/)) {
788: my $symb=&Apache::lonnet::symbclean(
789: &Apache::lonnet::declutter('uploaded/'.
790: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
791: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
792: '.sequence').
793: '___'.$residx.'___'.
794: &Apache::lonnet::declutter($url));
795: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
796: $url=&Apache::lonnet::clutter($url);
797: if ($url=~/^\/*uploaded\//) {
798: $url=~/\.(\w+)$/;
799: my $embstyle=&Apache::loncommon::fileembstyle($1);
800: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
801: $url='/adm/wrapper'.$url;
802: } elsif ($embstyle eq 'ssi') {
803: #do nothing with these
804: } elsif ($url!~/\.(sequence|page)$/) {
805: $url='/adm/coursedocs/showdoc'.$url;
806: }
807: }
808: $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
809: }
810: my $parameterset=' ';
811: if ($isfolder) {
812: my $foldername=&Apache::lonnet::escape($foldertitle);
813: my $folderpath=$ENV{'form.folderpath'};
814: if ($folderpath) { $folderpath.='&' };
815: $folderpath.=$folderarg.'&'.$foldername;
816: $url.='folderpath='.&Apache::lonnet::escape($folderpath);
817: $parameterset=&mt('Randomly Pick: ').
818: '<input type="text" size="4" name="randpick_'.$orderidx.'" value="'.
819: (&Apache::lonratedt::getparameter($orderidx,'parameter_randompick'))[0].'" />';
820: }
821: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
822: '" border="0"></a></td>'.
823: "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
824: if (($allowed) && ($folder!~/^supplemental/)) {
825: my %lt=&Apache::lonlocal::texthash(
826: 'hd' => 'Hidden',
827: 'ec' => 'URL hidden',
828: 'sp' => 'Store Parameters');
829: my $enctext=
830: ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
831: my $hidtext=
832: ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
833: $line.=(<<ENDPARMS);
834: <td bgcolor="#BBBBFF"><font size='-2'>
835: <input type="checkbox" name="hidprs_$orderidx" $hidtext/> $lt{'hd'}</td>
836: <td bgcolor="#BBBBFF"><font size='-2'>
837: <input type="checkbox" name="encprs_$orderidx" $enctext/> $lt{'ec'}</td>
838: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
839: <td bgcolor="#BBBBFF"><font size='-2'>
840: <input type="submit" value="$lt{'sp'}" />
841: </font></td>
842: ENDPARMS
843: }
844: $line.="</form></tr>";
845: return $line;
846: }
847:
848: # ---------------------------------------------------------------- tie the hash
849:
850: sub tiehash {
851: my ($mode)=@_;
852: $hashtied=0;
853: if ($ENV{'request.course.fn'}) {
854: if ($mode eq 'write') {
855: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
856: &GDBM_WRCREAT(),0640)) {
857: $hashtied=2;
858: }
859: } else {
860: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
861: &GDBM_READER(),0640)) {
862: $hashtied=1;
863: }
864: }
865: }
866: }
867:
868: sub untiehash {
869: if ($hashtied) { untie %hash; }
870: $hashtied=0;
871: }
872:
873: # --------------------------------------------------------------- check on this
874:
875: sub checkonthis {
876: my ($r,$url,$level,$title)=@_;
877: $alreadyseen{$url}=1;
878: $r->rflush();
879: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
880: $r->print("\n<br />");
881: for (my $i=0;$i<=$level*5;$i++) {
882: $r->print(' ');
883: }
884: $r->print('<a href="'.$url.'" target="cat">'.
885: ($title?$title:$url).'</a> ');
886: if ($url=~/^\/res\//) {
887: my $result=&Apache::lonnet::repcopy(
888: &Apache::lonnet::filelocation('',$url));
889: if ($result==OK) {
890: $r->print('<font color="green">'.&mt('ok').'</font>');
891: $r->rflush();
892: &Apache::lonnet::countacc($url);
893: $url=~/\.(\w+)$/;
894: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
895: $r->print('<br />');
896: $r->rflush();
897: for (my $i=0;$i<=$level*5;$i++) {
898: $r->print(' ');
899: }
900: $r->print('- '.&mt('Rendering').': ');
901: my $oldpath=$ENV{'request.filename'};
902: $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
903: &Apache::lonxml::xmlparse($r,'web',
904: &Apache::lonnet::getfile(
905: &Apache::lonnet::filelocation('',$url)));
906: undef($Apache::lonhomework::parsing_a_problem);
907: $ENV{'request.filename'}=$oldpath;
908: if (($Apache::lonxml::errorcount) ||
909: ($Apache::lonxml::warningcount)) {
910: if ($Apache::lonxml::errorcount) {
911: $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
912: $Apache::lonxml::errorcount.' '.
913: &mt('error(s)').'</b></font> ');
914: }
915: if ($Apache::lonxml::warningcount) {
916: $r->print('<font color="blue">'.
917: $Apache::lonxml::warningcount.' '.
918: &mt('warning(s)').'</font>');
919: }
920: } else {
921: $r->print('<font color="green">'.&mt('ok').'</font>');
922: }
923: $r->rflush();
924: }
925: my $dependencies=
926: &Apache::lonnet::metadata($url,'dependencies');
927: foreach (split(/\,/,$dependencies)) {
928: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
929: &checkonthis($r,$_,$level+1);
930: }
931: }
932: } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
933: $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
934: } elsif ($result==HTTP_NOT_FOUND) {
935: unless ($url=~/\$/) {
936: $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
937: } else {
938: $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
939: }
940: } else {
941: $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
942: }
943: }
944: }
945: }
946:
947:
948: #
949: # -------------------------------------------------------------- Verify Content
950: #
951: sub verifycontent {
952: my $r=shift;
953: my $loaderror=&Apache::lonnet::overloaderror($r);
954: if ($loaderror) { return $loaderror; }
955:
956: $r->print('<html><head><title>Verify Content</title></head>'.
957: &Apache::loncommon::bodytag('Verify Course Documents'));
958: $hashtied=0;
959: undef %alreadyseen;
960: %alreadyseen=();
961: &tiehash();
962: foreach (keys %hash) {
963: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
964: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
965: }
966: }
967: &untiehash();
968: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
969: &mt('Return to DOCS').'</a>');
970: }
971:
972: # -------------------------------------------------------------- Check Versions
973:
974: sub checkversions {
975: my $r=shift;
976: $r->print('<html><head><title>Check Versions</title></head>'.
977: &Apache::loncommon::bodytag('Check Course Document Versions'));
978: my $header='';
979: my $startsel='';
980: my $monthsel='';
981: my $weeksel='';
982: my $daysel='';
983: my $allsel='';
984: my %changes=();
985: my $starttime=0;
986: my $haschanged=0;
987: my %setversions=&Apache::lonnet::dump('resourceversions',
988: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
989: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
990:
991: $hashtied=0;
992: &tiehash();
993: my %newsetversions=();
994: if ($ENV{'form.setmostrecent'}) {
995: $haschanged=1;
996: foreach (keys %hash) {
997: if ($_=~/^ids\_(\/res\/.+)$/) {
998: $newsetversions{$1}='mostrecent';
999: }
1000: }
1001: } elsif ($ENV{'form.setcurrent'}) {
1002: $haschanged=1;
1003: foreach (keys %hash) {
1004: if ($_=~/^ids\_(\/res\/.+)$/) {
1005: my $getvers=&Apache::lonnet::getversion($1);
1006: if ($getvers>0) {
1007: $newsetversions{$1}=$getvers;
1008: }
1009: }
1010: }
1011: } elsif ($ENV{'form.setversions'}) {
1012: $haschanged=1;
1013: foreach (keys %ENV) {
1014: if ($_=~/^form\.set_version_(.+)$/) {
1015: my $src=$1;
1016: if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
1017: $newsetversions{$src}=$ENV{$_};
1018: }
1019: }
1020: }
1021: }
1022: if ($haschanged) {
1023: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
1024: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1025: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {
1026: $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
1027: } else {
1028: $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
1029: }
1030: &mark_hash_old();
1031: }
1032: &changewarning($r,'');
1033: if ($ENV{'form.timerange'} eq 'all') {
1034: # show all documents
1035: $header=&mt('All Documents in Course');
1036: $allsel=1;
1037: foreach (keys %hash) {
1038: if ($_=~/^ids\_(\/res\/.+)$/) {
1039: my $src=$1;
1040: $changes{$src}=1;
1041: }
1042: }
1043: } else {
1044: # show documents which changed
1045: %changes=&Apache::lonnet::dump
1046: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1047: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1048: my $firstkey=(keys %changes)[0];
1049: unless ($firstkey=~/^error\:/) {
1050: unless ($ENV{'form.timerange'}) {
1051: $ENV{'form.timerange'}=604800;
1052: }
1053: my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
1054: .&mt('seconds');
1055: if ($ENV{'form.timerange'}==-1) {
1056: $seltext='since start of course';
1057: $startsel='selected';
1058: $ENV{'form.timerange'}=time;
1059: }
1060: $starttime=time-$ENV{'form.timerange'};
1061: if ($ENV{'form.timerange'}==2592000) {
1062: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1063: $monthsel='selected';
1064: } elsif ($ENV{'form.timerange'}==604800) {
1065: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1066: $weeksel='selected';
1067: } elsif ($ENV{'form.timerange'}==86400) {
1068: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1069: $daysel='selected';
1070: }
1071: $header=&mt('Content changed').' '.$seltext;
1072: } else {
1073: $header=&mt('No content modifications yet.');
1074: }
1075: }
1076: %setversions=&Apache::lonnet::dump('resourceversions',
1077: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1078: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1079: my %lt=&Apache::lonlocal::texthash
1080: ('st' => 'Version changes since start of Course',
1081: 'lm' => 'Version changes since last Month',
1082: 'lw' => 'Version changes since last Week',
1083: 'sy' => 'Version changes since Yesterday',
1084: 'al' => 'All Resources (possibly large output)',
1085: 'sd' => 'Display',
1086: 'fi' => 'File',
1087: 'md' => 'Modification Date',
1088: 'mr' => 'Most recently published Version',
1089: 've' => 'Version used in Course',
1090: 'vu' => 'Set Version to be used in Course',
1091: 'sv' => 'Set Versions to be used in Course according to Selections below',
1092: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
1093: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1094: 'di' => 'Differences');
1095: $r->print(<<ENDHEADERS);
1096: <form action="/adm/coursedocs" method="post">
1097: <input type="hidden" name="versions" value="1" />
1098: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
1099: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1100: <select name="timerange">
1101: <option value='all' $allsel>$lt{'al'}</option>
1102: <option value="-1" $startsel>$lt{'st'}</option>
1103: <option value="2592000" $monthsel>$lt{'lm'}</option>
1104: <option value="604800" $weeksel>$lt{'lw'}</option>
1105: <option value="86400" $daysel>$lt{'sy'}</option>
1106: </select>
1107: <input type="submit" name="display" value="$lt{'sd'}" />
1108: <h3>$header</h3>
1109: <input type="submit" name="setversions" value="$lt{'sv'}" />
1110: <table border="0">
1111: ENDHEADERS
1112: foreach (sort keys %changes) {
1113: if ($changes{$_}>$starttime) {
1114: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
1115: my $currentversion=&Apache::lonnet::getversion($_);
1116: if ($currentversion<0) {
1117: $currentversion=&mt('Could not be determined.');
1118: }
1119: my $linkurl=&Apache::lonnet::clutter($_);
1120: $r->print(
1121: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1122: &Apache::lonnet::gettitle($linkurl).
1123: '</b></font></td></tr>'.
1124: '<tr><td> </td>'.
1125: '<td colspan="4">'.
1126: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
1127: '</a></td></tr>'.
1128: '<tr><td></td>'.
1129: '<td title="'.$lt{'md'}.'">'.
1130: &Apache::lonlocal::locallocaltime(
1131: &Apache::lonnet::metadata($root.'.'.$extension,
1132: 'lastrevisiondate')
1133: ).
1134: '</td>'.
1135: '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
1136: '<font size="+1">'.$currentversion.'</font>'.
1137: '</nobr></td>'.
1138: '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
1139: '<font size="+1">');
1140: # Used in course
1141: my $usedversion=$hash{'version_'.$linkurl};
1142: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1143: $r->print($usedversion);
1144: } else {
1145: $r->print($currentversion);
1146: }
1147: $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
1148: '<nobr>Use: ');
1149: # Set version
1150: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1151: 'set_version_'.$linkurl,
1152: ('select_form_order' =>
1153: ['',1..$currentversion,'mostrecent'],
1154: '' => '',
1155: 'mostrecent' => 'most recent',
1156: map {$_,$_} (1..$currentversion))));
1157: $r->print('</nobr></td></tr><tr><td></td>');
1158: my $lastold=1;
1159: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
1160: my $url=$root.'.'.$prevvers.'.'.$extension;
1161: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
1162: $starttime) {
1163: $lastold=$prevvers;
1164: }
1165: }
1166: #
1167: # Code to figure out how many version entries should go in
1168: # each of the four columns
1169: my $entries_per_col = 0;
1170: my $num_entries = ($currentversion-$lastold);
1171: if ($num_entries % 4 == 0) {
1172: $entries_per_col = $num_entries/4;
1173: } else {
1174: $entries_per_col = $num_entries/4 + 1;
1175: }
1176: my $entries_count = 0;
1177: $r->print('<td valign="top"><font size="-2">');
1178: my $cols_output = 1;
1179: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1180: my $url=$root.'.'.$prevvers.'.'.$extension;
1181: $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
1182: '">'.&mt('Version').' '.$prevvers.'</a> ('.
1183: &Apache::lonlocal::locallocaltime(
1184: &Apache::lonnet::metadata($url,
1185: 'lastrevisiondate')
1186: ).
1187: ')');
1188: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1189: $r->print(' <a href="/adm/diff?filename='.
1190: &Apache::lonnet::clutter($root.'.'.$extension).
1191: '&versionone='.$prevvers.
1192: '">'.&mt('Diffs').'</a>');
1193: }
1194: $r->print('</nobr><br />');
1195: if (++$entries_count % $entries_per_col == 0) {
1196: $r->print('</font></td>');
1197: if ($cols_output != 4) {
1198: $r->print('<td valign="top"><font size="-2">');
1199: $cols_output++;
1200: }
1201: }
1202: }
1203: while($cols_output++ < 4) {
1204: $r->print('</font></td><td><font>')
1205: }
1206: $r->print('</font></td></tr>'."\n");
1207: }
1208: }
1209: $r->print('</table></form>');
1210: $r->print('<h1>'.&mt('Done').'.</h1>');
1211:
1212: &untiehash();
1213: }
1214:
1215: sub mark_hash_old {
1216: my $retie_hash=0;
1217: if ($hashtied) {
1218: $retie_hash=1;
1219: &untiehash();
1220: }
1221: &tiehash('write');
1222: $hash{'old'}=1;
1223: &untiehash();
1224: if ($retie_hash) { &tiehash(); }
1225: }
1226:
1227: sub is_hash_old {
1228: my $untie_hash=0;
1229: if (!$hashtied) {
1230: $untie_hash=1;
1231: &tiehash();
1232: }
1233: my $return=$hash{'old'};
1234: if ($untie_hash) { &untiehash(); }
1235: return $return;
1236: }
1237:
1238: sub changewarning {
1239: my ($r,$postexec)=@_;
1240: if (!&is_hash_old()) { return; }
1241: $r->print(
1242: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
1243: '<form method="post" action="/adm/roles" target="loncapaclient">'.
1244: '<input type="hidden" name="orgurl" value="/adm/coursedocs?folderpath='.
1245: &Apache::lonnet::escape($ENV{'form.folderpath'}).
1246: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1247: &mt('Changes will become active for your current session after').
1248: ' <input type="hidden" name="'.
1249: $ENV{'request.role'}.'" value="1" /><input type="button" value="'.
1250: &mt('re-initializing course').'" onClick="reinit(this.form)"/>'.&mt(', or the next time you log in.').
1251: $help{'Caching'}.'</font></h3></form>');
1252: }
1253:
1254: # ================================================================ Main Handler
1255: sub handler {
1256: my $r = shift;
1257: &Apache::loncommon::content_type($r,'text/html');
1258: $r->send_http_header;
1259: return OK if $r->header_only;
1260:
1261: # --------------------------------------------- Initialize help topics for this
1262: foreach ('Adding_Course_Doc','Main_Course_Documents',
1263: 'Adding_External_Resource','Navigate_Content',
1264: 'Adding_Folders','Docs_Overview', 'Load_Map',
1265: 'Supplemental', 'Score_Upload_Form',
1266: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
1267: 'Check_Resource_Versions','Verify_Content') {
1268: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
1269: }
1270: # Composite help files
1271: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
1272: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
1273: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
1274: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1275: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
1276: 'Option_Response_Simple');
1277: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
1278: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1279: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
1280: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1281: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1282:
1283: if ($ENV{'form.verify'}) {
1284: &verifycontent($r);
1285: } elsif ($ENV{'form.versions'}) {
1286: &checkversions($r);
1287: } elsif ($ENV{'form.dumpcourse'}) {
1288: &dumpcourse($r);
1289: } elsif ($ENV{'form.exportcourse'}) {
1290: &exportcourse($r);
1291: } else {
1292: # is this a standard course?
1293:
1294: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1295: my $forcestandard;
1296: my $forcesupplement;
1297: my $script='';
1298: my $allowed;
1299: my $events='';
1300: my $showdoc=0;
1301: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1302: ['folderpath']);
1303: if ($ENV{'form.folderpath'}) {
1304: my (@folderpath)=split('&',$ENV{'form.folderpath'});
1305: $ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
1306: $ENV{'form.folder'}=pop(@folderpath);
1307: }
1308: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1309: $showdoc='/'.$1;
1310: }
1311: unless ($showdoc) { # got called from remote
1312: $forcestandard=($ENV{'form.folder'}=~/^default_/);
1313: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1314:
1315: # does this user have privileges to post, etc?
1316: $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1317: if ($allowed) {
1318: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1319: $script=&Apache::lonratedt::editscript('simple');
1320: }
1321: } else { # got called in sequence from course
1322: $allowed=0;
1323: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
1324: $events='onLoad="'.&Apache::lonmenu::loadevents.
1325: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1326: }
1327:
1328: # get course data
1329: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
1330: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1331:
1332: # get personal data
1333:
1334: my $uname=$ENV{'user.name'};
1335: my $udom=$ENV{'user.domain'};
1336: my $plainname=&Apache::lonnet::escape(
1337: &Apache::loncommon::plainname($uname,$udom));
1338:
1339: # graphics settings
1340:
1341: $iconpath = $r->dir_config('lonIconsURL') . "/";
1342:
1343: my $now=time;
1344:
1345: # print screen
1346: $r->print(<<ENDDOCUMENT);
1347: <html>
1348: <head>
1349: <title>The LearningOnline Network with CAPA</title>
1350: <script>
1351: $script
1352: </script>
1353: ENDDOCUMENT
1354: if ($allowed) {
1355: $r->print(<<ENDNEWSCRIPT);
1356: <script>
1357: function makenewfolder(targetform,folderseq) {
1358: var foldername=prompt('Name of New Folder','New Folder');
1359: if (foldername) {
1360: targetform.importdetail.value=foldername+"="+folderseq;
1361: targetform.submit();
1362: }
1363: }
1364:
1365: function makenewext(targetname) {
1366: this.document.forms.extimport.useform.value=targetname;
1367: window.open('/adm/rat/extpickframe.html');
1368: }
1369:
1370: function makeexamupload() {
1371: var title=prompt('Listed Title for the Uploaded Score');
1372: if (title) {
1373: this.document.forms.newexamupload.importdetail.value=
1374: title+'=/res/lib/templates/examupload.problem';
1375: this.document.forms.newexamupload.submit();
1376: }
1377: }
1378:
1379: function makesmppage() {
1380: var title=prompt('Listed Title for the Page');
1381: if (title) {
1382: this.document.forms.newsmppg.importdetail.value=
1383: title+'=/adm/$udom/$uname/$now/smppg';
1384: this.document.forms.newsmppg.submit();
1385: }
1386: }
1387:
1388: function makesmpproblem() {
1389: var title=prompt('Listed Title for the Problem');
1390: if (title) {
1391: this.document.forms.newsmpproblem.importdetail.value=
1392: title+'=/res/lib/templates/simpleproblem.problem';
1393: this.document.forms.newsmpproblem.submit();
1394: }
1395: }
1396:
1397: function makebulboard() {
1398: var title=prompt('Listed Title for the Bulletin Board');
1399: if (title) {
1400: this.document.forms.newbul.importdetail.value=
1401: title+'=/adm/$udom/$uname/$now/bulletinboard';
1402: this.document.forms.newbul.submit();
1403: }
1404: }
1405:
1406: function makeabout() {
1407: var user=prompt("Enter user\@domain for User's 'About Me' Page");
1408: if (user) {
1409: var comp=new Array();
1410: comp=user.split('\@');
1411: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
1412: if ((comp[0]) && (comp[1])) {
1413: this.document.forms.newaboutsomeone.importdetail.value=
1414: 'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1415: this.document.forms.newaboutsomeone.submit();
1416: }
1417: }
1418: }
1419: }
1420:
1421: function makeims() {
1422: var caller = document.forms.ims.folder.value
1423: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
1424: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
1425: newWindow.location.href = newlocation
1426: }
1427:
1428:
1429: function finishpick() {
1430: var title=this.document.forms.extimport.title.value;
1431: var url=this.document.forms.extimport.url.value;
1432: var form=this.document.forms.extimport.useform.value;
1433: eval
1434: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
1435: '";this.document.forms.'+form+'.submit();');
1436: }
1437:
1438: function changename(folderpath,index,oldtitle) {
1439: var title=prompt('New Title',oldtitle);
1440: if (title) {
1441: this.document.forms.renameform.title.value=title;
1442: this.document.forms.renameform.cmd.value='rename_'+index;
1443: this.document.forms.renameform.folderpath.value=folderpath;
1444: this.document.forms.renameform.submit();
1445: }
1446: }
1447:
1448: function removeres(folderpath,index,oldtitle) {
1449: if (confirm('Remove "'+oldtitle+'"?')) {
1450: this.document.forms.renameform.cmd.value='del_'+index;
1451: this.document.forms.renameform.folderpath.value=folderpath;
1452: this.document.forms.renameform.submit();
1453: }
1454: }
1455:
1456: </script>
1457:
1458: ENDNEWSCRIPT
1459: }
1460: # -------------------------------------------------------------------- Body tag
1461: $r->print('</head>'.
1462: &Apache::loncommon::bodytag('Course Documents','',$events,
1463: '','',$showdoc).
1464: &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
1465: unless ($showdoc) {
1466: # -----------------------------------------------------------------------------
1467: my %lt=&Apache::lonlocal::texthash(
1468: 'uplm' => 'Upload a new main course document',
1469: 'upls' => 'Upload a new supplemental course document',
1470: 'impp' => 'Import a published document',
1471: 'spec' => 'Special documents',
1472: 'upld' => 'Upload Document',
1473: 'srch' => 'Search',
1474: 'impo' => 'Import',
1475: 'selm' => 'Select Map',
1476: 'load' => 'Load Map',
1477: 'newf' => 'New Folder',
1478: 'extr' => 'External Resource',
1479: 'syll' => 'Syllabus',
1480: 'navc' => 'Navigate Contents',
1481: 'sipa' => 'Simple Page',
1482: 'sipr' => 'Simple Problem',
1483: 'scuf' => 'Score Upload Form',
1484: 'bull' => 'Bulletin Board',
1485: 'mypi' => 'My Personal Info',
1486: 'abou' => 'About User',
1487: 'imsf' => 'Import IMS package',
1488: 'file' => 'File',
1489: 'title' => 'Title',
1490: 'comment' => 'Comment'
1491: );
1492: # -----------------------------------------------------------------------------
1493: if ($allowed) {
1494: my $dumpbut=&dumpbutton();
1495: my $exportbut=&exportbutton();
1496: my %lt=&Apache::lonlocal::texthash(
1497: 'vc' => 'Verify Content',
1498: 'cv' => 'Check/Set Resource Versions',
1499: );
1500:
1501: my $folderpath=$ENV{'form.folderpath'};
1502: if (!$folderpath) {
1503: if ($ENV{'form.folder'} eq '' ||
1504: $ENV{'form.folder'} eq 'supplemental') {
1505: $folderpath='default&'.
1506: &Apache::lonnet::escape(&mt('Main Course Documents'));
1507: }
1508: }
1509: $r->print(<<ENDCOURSEVERIFY);
1510: <form name="renameform" method="post" action="/adm/coursedocs">
1511: <input type="hidden" name="title" />
1512: <input type="hidden" name="cmd" />
1513: <input type="hidden" name="folderpath" />
1514: </form>
1515: <form name="simpleedit" method="post" action="/adm/coursedocs">
1516: <input type=hidden name="importdetail" value="">
1517: <input type="hidden" name="folderpath" value="$folderpath" />
1518: </form>
1519: <form action="/adm/coursedocs" method="post" name="courseverify">
1520: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
1521: <tr><td bgcolor="#DDDDCC">
1522: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
1523: </td><td bgcolor="#DDDDCC">
1524: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
1525: $dumpbut
1526: $exportbut
1527: </td></tr></table>
1528: </form>
1529: ENDCOURSEVERIFY
1530: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1531: &mt('Editing the Table of Contents for your Course')));
1532: }
1533: # --------------------------------------------------------- Standard documents
1534: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1535: if (($standard) && ($allowed) && (!$forcesupplement)) {
1536: $r->print('<tr><td bgcolor="#BBBBBB">');
1537: # '<h2>'.&mt('Main Course Documents').
1538: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1539: my $folder=$ENV{'form.folder'};
1540: if ($folder eq '' || $folder eq 'supplemental') {
1541: $folder='default';
1542: $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
1543: }
1544: my $postexec='';
1545: if ($folder eq 'default') {
1546: $r->print('<script>this.window.name="loncapaclient";</script>');
1547: } else {
1548: #$postexec='self.close();';
1549: }
1550: $hadchanges=0;
1551: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1552: if ($hadchanges) {
1553: &mark_hash_old()
1554: }
1555: &changewarning($r,$postexec);
1556: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
1557: '.sequence';
1558: $r->print(<<ENDFORM);
1559: <table cellspacing=4 cellpadding=4><tr>
1560: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
1561: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
1562: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1563: </tr>
1564: <tr><td bgcolor="#DDDDDD">
1565: $lt{'file'}:<br />
1566: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1567: <input type="file" name="uploaddoc" size="40">
1568: <br />
1569: $lt{'title'}:<br />
1570: <input type="text" size="50" name="comment">
1571: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1572: <input type="hidden" name="cmd" value="upload_default">
1573: <nobr>
1574: <input type="submit" value="$lt{'upld'}">
1575: $help{'Uploading_From_Harddrive'}
1576: </nobr>
1577: </form>
1578: </td>
1579: <td bgcolor="#DDDDDD">
1580: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1581: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1582: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
1583: <nobr>
1584: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
1585: $help{'Importing_LON-CAPA_Resource'}
1586: </nobr>
1587: <p>
1588: <hr />
1589: <input type="text" size="20" name="importmap"><br />
1590: <nobr><input type=button
1591: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1592: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
1593: $help{'Load_Map'}</nobr>
1594: </p>
1595: </form>
1596: </td><td bgcolor="#DDDDDD">
1597: <form action="/adm/coursedocs" method="post" name="newfolder">
1598: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1599: <input type=hidden name="importdetail" value="">
1600: <nobr>
1601: <input name="newfolder" type="button"
1602: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1603: value="$lt{'newf'}" />$help{'Adding_Folders'}
1604: </nobr>
1605: </form>
1606: <form action="/adm/coursedocs" method="post" name="newext">
1607: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1608: <input type=hidden name="importdetail" value="">
1609: <nobr>
1610: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
1611: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1612: </nobr>
1613: </form>
1614: <form action="/adm/coursedocs" method="post" name="newsyl">
1615: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1616: <input type=hidden name="importdetail"
1617: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1618: <nobr>
1619: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1620: $help{'Syllabus'}
1621: </nobr>
1622: </form>
1623: <form action="/adm/coursedocs" method="post" name="newnav">
1624: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1625: <input type=hidden name="importdetail"
1626: value="Navigate Content=/adm/navmaps">
1627: <nobr>
1628: <input name="newnav" type="submit" value="$lt{'navc'}" />
1629: $help{'Navigate_Content'}
1630: </nobr>
1631: </form>
1632: <form action="/adm/coursedocs" method="post" name="newsmppg">
1633: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1634: <input type=hidden name="importdetail" value="">
1635: <nobr>
1636: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1637: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1638: </nobr>
1639: </form>
1640: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1641: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1642: <input type=hidden name="importdetail" value="">
1643: <nobr>
1644: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1645: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1646: </nobr>
1647: </form>
1648: <form action="/adm/coursedocs" method="post" name="newexamupload">
1649: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1650: <input type=hidden name="importdetail" value="">
1651: <nobr>
1652: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1653: onClick="javascript:makeexamupload();" />
1654: $help{'Score_Upload_Form'}
1655: </nobr>
1656: </form>
1657: <form action="/adm/coursedocs" method="post" name="newbul">
1658: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1659: <input type=hidden name="importdetail" value="">
1660: <nobr>
1661: <input name="newbulletin" type="button" value="$lt{'bull'}"
1662: onClick="javascript:makebulboard();" />
1663: $help{'Bulletin Board'}
1664: </nobr>
1665: </form>
1666: <form action="/adm/coursedocs" method="post" name="newaboutme">
1667: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1668: <input type=hidden name="importdetail"
1669: value="$plainname=/adm/$udom/$uname/aboutme">
1670: <nobr>
1671: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1672: $help{'My Personal Info'}
1673: </nobr>
1674: </form>
1675: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1676: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1677: <input type=hidden name="importdetail" value="">
1678: <nobr>
1679: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
1680: onClick="javascript:makeabout();" />
1681: </nobr>
1682: </form>
1683: <form action="/adm/imsimportdocs" method="post" name="ims">
1684: <input type="hidden" name="folder" value="$folder" />
1685: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
1686: </nobr>
1687: </form>
1688: </td></tr>
1689: </table>
1690: ENDFORM
1691: $r->print('</td></tr>');
1692: }
1693: # ----------------------------------------------------- Supplemental documents
1694: if (!$forcestandard) {
1695: $r->print('<tr><td bgcolor="#BBBBBB">');
1696: # '<h2>'.&mt('Supplemental Course Documents').
1697: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1698: my $folder=$ENV{'form.folder'};
1699: unless ($folder=~/^supplemental/) {
1700: $folder='supplemental';
1701: }
1702: if ($folder =~ /^supplemental$/ &&
1703: $ENV{'form.folderpath'} =~ /^default\&/) {
1704: $ENV{'form.folderpath'}='supplemental&'.
1705: &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
1706: }
1707: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1708: if ($allowed) {
1709: my $folderseq=
1710: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
1711: '.sequence';
1712:
1713: $r->print(<<ENDSUPFORM);
1714: <table cellspacing=4 cellpadding=4><tr>
1715: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
1716: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1717: </tr>
1718: <tr><td bgcolor="#DDDDDD">
1719: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1720: <input type="file" name="uploaddoc" size="40">
1721: <br />$lt{'comment'}:<br />
1722: <textarea cols=50 rows=4 name='comment'>
1723: </textarea>
1724: <br />
1725: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1726: <input type="hidden" name="cmd" value="upload_supplemental">
1727: <nobr>
1728: <input type="submit" value="$lt{'upld'}">
1729: $help{'Uploading_From_Harddrive'}
1730: </nobr>
1731: </form>
1732: </td>
1733: <td bgcolor="#DDDDDD">
1734: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1735: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1736: <input type=hidden name="importdetail" value="">
1737: <nobr>
1738: <input name="newfolder" type="button"
1739: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1740: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1741: </nobr>
1742: </form>
1743: <form action="/adm/coursedocs" method="post" name="supnewext">
1744: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1745: <input type=hidden name="importdetail" value="">
1746: <nobr>
1747: <input name="newext" type="button"
1748: onClick="javascript:makenewext('supnewext');"
1749: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1750: </nobr>
1751: </form>
1752: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1753: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1754: <input type=hidden name="importdetail"
1755: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1756: <nobr>
1757: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1758: $help{'Syllabus'}
1759: </nobr>
1760: </form>
1761: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1762: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1763: <input type=hidden name="importdetail"
1764: value="$plainname=/adm/$udom/$uname/aboutme">
1765: <nobr>
1766: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1767: $help{'My Personal Info'}
1768: </nobr>
1769: </form>
1770: </td></tr>
1771: </table></td></tr>
1772: ENDSUPFORM
1773: }
1774: }
1775: if ($allowed) {
1776: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
1777: }
1778: $r->print('</table>');
1779: } else {
1780: # -------------------------------------------------------- This is showdoc mode
1781: $r->print("<h1>".&mt('Uploaded Document').'</h1><p>'.
1782: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
1783: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
1784: }
1785: }
1786: $r->print('</body></html>');
1787: return OK;
1788: }
1789:
1790: 1;
1791: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>