1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.141 2004/09/09 18:56:01 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::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: $url=&Apache::lonnet::unescape($url);
878: $alreadyseen{$url}=1;
879: $r->rflush();
880: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
881: $r->print("\n<br />");
882: for (my $i=0;$i<=$level*5;$i++) {
883: $r->print(' ');
884: }
885: $r->print('<a href="'.$url.'" target="cat">'.
886: ($title?$title:$url).'</a> ');
887: if ($url=~/^\/res\//) {
888: my $result=&Apache::lonnet::repcopy(
889: &Apache::lonnet::filelocation('',$url));
890: if ($result==OK) {
891: $r->print('<font color="green">'.&mt('ok').'</font>');
892: $r->rflush();
893: &Apache::lonnet::countacc($url);
894: $url=~/\.(\w+)$/;
895: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
896: $r->print('<br />');
897: $r->rflush();
898: for (my $i=0;$i<=$level*5;$i++) {
899: $r->print(' ');
900: }
901: $r->print('- '.&mt('Rendering').': ');
902: my $oldpath=$ENV{'request.filename'};
903: $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
904: &Apache::lonxml::xmlparse($r,'web',
905: &Apache::lonnet::getfile(
906: &Apache::lonnet::filelocation('',$url)));
907: undef($Apache::lonhomework::parsing_a_problem);
908: $ENV{'request.filename'}=$oldpath;
909: if (($Apache::lonxml::errorcount) ||
910: ($Apache::lonxml::warningcount)) {
911: if ($Apache::lonxml::errorcount) {
912: $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
913: $Apache::lonxml::errorcount.' '.
914: &mt('error(s)').'</b></font> ');
915: }
916: if ($Apache::lonxml::warningcount) {
917: $r->print('<font color="blue">'.
918: $Apache::lonxml::warningcount.' '.
919: &mt('warning(s)').'</font>');
920: }
921: } else {
922: $r->print('<font color="green">'.&mt('ok').'</font>');
923: }
924: $r->rflush();
925: }
926: my $dependencies=
927: &Apache::lonnet::metadata($url,'dependencies');
928: foreach (split(/\,/,$dependencies)) {
929: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
930: &checkonthis($r,$_,$level+1);
931: }
932: }
933: } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
934: $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
935: } elsif ($result==HTTP_NOT_FOUND) {
936: unless ($url=~/\$/) {
937: $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
938: } else {
939: $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
940: }
941: } else {
942: $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
943: }
944: }
945: }
946: }
947:
948:
949: #
950: # -------------------------------------------------------------- Verify Content
951: #
952: sub verifycontent {
953: my $r=shift;
954: my $loaderror=&Apache::lonnet::overloaderror($r);
955: if ($loaderror) { return $loaderror; }
956:
957: $r->print('<html><head><title>Verify Content</title></head>'.
958: &Apache::loncommon::bodytag('Verify Course Documents'));
959: $hashtied=0;
960: undef %alreadyseen;
961: %alreadyseen=();
962: &tiehash();
963: foreach (keys %hash) {
964: if ($hash{$_}=~/\.(page|sequence)$/) {
965: if (($_=~/^src_/) && ($alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
966: $r->print('<hr /><font color="red">'.
967: &mt('The following sequence or page is included more than once in your course: ').
968: &Apache::lonnet::unescape($hash{$_}).'</font><br />'.
969: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
970: }
971: }
972: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
973: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
974: }
975: }
976: &untiehash();
977: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
978: &mt('Return to DOCS').'</a>');
979: }
980:
981: # -------------------------------------------------------------- Check Versions
982:
983: sub checkversions {
984: my $r=shift;
985: $r->print('<html><head><title>Check Versions</title></head>'.
986: &Apache::loncommon::bodytag('Check Course Document Versions'));
987: my $header='';
988: my $startsel='';
989: my $monthsel='';
990: my $weeksel='';
991: my $daysel='';
992: my $allsel='';
993: my %changes=();
994: my $starttime=0;
995: my $haschanged=0;
996: my %setversions=&Apache::lonnet::dump('resourceversions',
997: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
998: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
999:
1000: $hashtied=0;
1001: &tiehash();
1002: my %newsetversions=();
1003: if ($ENV{'form.setmostrecent'}) {
1004: $haschanged=1;
1005: foreach (keys %hash) {
1006: if ($_=~/^ids\_(\/res\/.+)$/) {
1007: $newsetversions{$1}='mostrecent';
1008: }
1009: }
1010: } elsif ($ENV{'form.setcurrent'}) {
1011: $haschanged=1;
1012: foreach (keys %hash) {
1013: if ($_=~/^ids\_(\/res\/.+)$/) {
1014: my $getvers=&Apache::lonnet::getversion($1);
1015: if ($getvers>0) {
1016: $newsetversions{$1}=$getvers;
1017: }
1018: }
1019: }
1020: } elsif ($ENV{'form.setversions'}) {
1021: $haschanged=1;
1022: foreach (keys %ENV) {
1023: if ($_=~/^form\.set_version_(.+)$/) {
1024: my $src=$1;
1025: if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
1026: $newsetversions{$src}=$ENV{$_};
1027: }
1028: }
1029: }
1030: }
1031: if ($haschanged) {
1032: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
1033: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1034: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {
1035: $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
1036: } else {
1037: $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
1038: }
1039: &mark_hash_old();
1040: }
1041: &changewarning($r,'');
1042: if ($ENV{'form.timerange'} eq 'all') {
1043: # show all documents
1044: $header=&mt('All Documents in Course');
1045: $allsel=1;
1046: foreach (keys %hash) {
1047: if ($_=~/^ids\_(\/res\/.+)$/) {
1048: my $src=$1;
1049: $changes{$src}=1;
1050: }
1051: }
1052: } else {
1053: # show documents which changed
1054: %changes=&Apache::lonnet::dump
1055: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1056: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1057: my $firstkey=(keys %changes)[0];
1058: unless ($firstkey=~/^error\:/) {
1059: unless ($ENV{'form.timerange'}) {
1060: $ENV{'form.timerange'}=604800;
1061: }
1062: my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
1063: .&mt('seconds');
1064: if ($ENV{'form.timerange'}==-1) {
1065: $seltext='since start of course';
1066: $startsel='selected';
1067: $ENV{'form.timerange'}=time;
1068: }
1069: $starttime=time-$ENV{'form.timerange'};
1070: if ($ENV{'form.timerange'}==2592000) {
1071: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1072: $monthsel='selected';
1073: } elsif ($ENV{'form.timerange'}==604800) {
1074: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1075: $weeksel='selected';
1076: } elsif ($ENV{'form.timerange'}==86400) {
1077: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1078: $daysel='selected';
1079: }
1080: $header=&mt('Content changed').' '.$seltext;
1081: } else {
1082: $header=&mt('No content modifications yet.');
1083: }
1084: }
1085: %setversions=&Apache::lonnet::dump('resourceversions',
1086: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1087: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1088: my %lt=&Apache::lonlocal::texthash
1089: ('st' => 'Version changes since start of Course',
1090: 'lm' => 'Version changes since last Month',
1091: 'lw' => 'Version changes since last Week',
1092: 'sy' => 'Version changes since Yesterday',
1093: 'al' => 'All Resources (possibly large output)',
1094: 'sd' => 'Display',
1095: 'fi' => 'File',
1096: 'md' => 'Modification Date',
1097: 'mr' => 'Most recently published Version',
1098: 've' => 'Version used in Course',
1099: 'vu' => 'Set Version to be used in Course',
1100: 'sv' => 'Set Versions to be used in Course according to Selections below',
1101: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
1102: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1103: 'di' => 'Differences');
1104: $r->print(<<ENDHEADERS);
1105: <form action="/adm/coursedocs" method="post">
1106: <input type="hidden" name="versions" value="1" />
1107: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
1108: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1109: <select name="timerange">
1110: <option value='all' $allsel>$lt{'al'}</option>
1111: <option value="-1" $startsel>$lt{'st'}</option>
1112: <option value="2592000" $monthsel>$lt{'lm'}</option>
1113: <option value="604800" $weeksel>$lt{'lw'}</option>
1114: <option value="86400" $daysel>$lt{'sy'}</option>
1115: </select>
1116: <input type="submit" name="display" value="$lt{'sd'}" />
1117: <h3>$header</h3>
1118: <input type="submit" name="setversions" value="$lt{'sv'}" />
1119: <table border="0">
1120: ENDHEADERS
1121: foreach (sort keys %changes) {
1122: if ($changes{$_}>$starttime) {
1123: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
1124: my $currentversion=&Apache::lonnet::getversion($_);
1125: if ($currentversion<0) {
1126: $currentversion=&mt('Could not be determined.');
1127: }
1128: my $linkurl=&Apache::lonnet::clutter($_);
1129: $r->print(
1130: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1131: &Apache::lonnet::gettitle($linkurl).
1132: '</b></font></td></tr>'.
1133: '<tr><td> </td>'.
1134: '<td colspan="4">'.
1135: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
1136: '</a></td></tr>'.
1137: '<tr><td></td>'.
1138: '<td title="'.$lt{'md'}.'">'.
1139: &Apache::lonlocal::locallocaltime(
1140: &Apache::lonnet::metadata($root.'.'.$extension,
1141: 'lastrevisiondate')
1142: ).
1143: '</td>'.
1144: '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
1145: '<font size="+1">'.$currentversion.'</font>'.
1146: '</nobr></td>'.
1147: '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
1148: '<font size="+1">');
1149: # Used in course
1150: my $usedversion=$hash{'version_'.$linkurl};
1151: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1152: $r->print($usedversion);
1153: } else {
1154: $r->print($currentversion);
1155: }
1156: $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
1157: '<nobr>Use: ');
1158: # Set version
1159: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1160: 'set_version_'.$linkurl,
1161: ('select_form_order' =>
1162: ['',1..$currentversion,'mostrecent'],
1163: '' => '',
1164: 'mostrecent' => 'most recent',
1165: map {$_,$_} (1..$currentversion))));
1166: $r->print('</nobr></td></tr><tr><td></td>');
1167: my $lastold=1;
1168: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
1169: my $url=$root.'.'.$prevvers.'.'.$extension;
1170: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
1171: $starttime) {
1172: $lastold=$prevvers;
1173: }
1174: }
1175: #
1176: # Code to figure out how many version entries should go in
1177: # each of the four columns
1178: my $entries_per_col = 0;
1179: my $num_entries = ($currentversion-$lastold);
1180: if ($num_entries % 4 == 0) {
1181: $entries_per_col = $num_entries/4;
1182: } else {
1183: $entries_per_col = $num_entries/4 + 1;
1184: }
1185: my $entries_count = 0;
1186: $r->print('<td valign="top"><font size="-2">');
1187: my $cols_output = 1;
1188: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1189: my $url=$root.'.'.$prevvers.'.'.$extension;
1190: $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
1191: '">'.&mt('Version').' '.$prevvers.'</a> ('.
1192: &Apache::lonlocal::locallocaltime(
1193: &Apache::lonnet::metadata($url,
1194: 'lastrevisiondate')
1195: ).
1196: ')');
1197: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1198: $r->print(' <a href="/adm/diff?filename='.
1199: &Apache::lonnet::clutter($root.'.'.$extension).
1200: '&versionone='.$prevvers.
1201: '">'.&mt('Diffs').'</a>');
1202: }
1203: $r->print('</nobr><br />');
1204: if (++$entries_count % $entries_per_col == 0) {
1205: $r->print('</font></td>');
1206: if ($cols_output != 4) {
1207: $r->print('<td valign="top"><font size="-2">');
1208: $cols_output++;
1209: }
1210: }
1211: }
1212: while($cols_output++ < 4) {
1213: $r->print('</font></td><td><font>')
1214: }
1215: $r->print('</font></td></tr>'."\n");
1216: }
1217: }
1218: $r->print('</table></form>');
1219: $r->print('<h1>'.&mt('Done').'.</h1>');
1220:
1221: &untiehash();
1222: }
1223:
1224: sub mark_hash_old {
1225: my $retie_hash=0;
1226: if ($hashtied) {
1227: $retie_hash=1;
1228: &untiehash();
1229: }
1230: &tiehash('write');
1231: $hash{'old'}=1;
1232: &untiehash();
1233: if ($retie_hash) { &tiehash(); }
1234: }
1235:
1236: sub is_hash_old {
1237: my $untie_hash=0;
1238: if (!$hashtied) {
1239: $untie_hash=1;
1240: &tiehash();
1241: }
1242: my $return=$hash{'old'};
1243: if ($untie_hash) { &untiehash(); }
1244: return $return;
1245: }
1246:
1247: sub changewarning {
1248: my ($r,$postexec)=@_;
1249: if (!&is_hash_old()) { return; }
1250: $r->print(
1251: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
1252: '<form method="post" action="/adm/roles" target="loncapaclient">'.
1253: '<input type="hidden" name="orgurl" value="/adm/coursedocs?folderpath='.
1254: &Apache::lonnet::escape($ENV{'form.folderpath'}).
1255: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1256: &mt('Changes will become active for your current session after').
1257: ' <input type="hidden" name="'.
1258: $ENV{'request.role'}.'" value="1" /><input type="button" value="'.
1259: &mt('re-initializing course').'" onClick="reinit(this.form)"/>'.&mt(', or the next time you log in.').
1260: $help{'Caching'}.'</font></h3></form>');
1261: }
1262:
1263: # ================================================================ Main Handler
1264: sub handler {
1265: my $r = shift;
1266: &Apache::loncommon::content_type($r,'text/html');
1267: $r->send_http_header;
1268: return OK if $r->header_only;
1269:
1270: # --------------------------------------------- Initialize help topics for this
1271: foreach ('Adding_Course_Doc','Main_Course_Documents',
1272: 'Adding_External_Resource','Navigate_Content',
1273: 'Adding_Folders','Docs_Overview', 'Load_Map',
1274: 'Supplemental', 'Score_Upload_Form',
1275: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
1276: 'Check_Resource_Versions','Verify_Content') {
1277: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
1278: }
1279: # Composite help files
1280: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
1281: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
1282: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
1283: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1284: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
1285: 'Option_Response_Simple');
1286: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
1287: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1288: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
1289: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1290: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1291:
1292: if ($ENV{'form.verify'}) {
1293: &verifycontent($r);
1294: } elsif ($ENV{'form.versions'}) {
1295: &checkversions($r);
1296: } elsif ($ENV{'form.dumpcourse'}) {
1297: &dumpcourse($r);
1298: } elsif ($ENV{'form.exportcourse'}) {
1299: &exportcourse($r);
1300: } else {
1301: # is this a standard course?
1302:
1303: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1304: my $forcestandard;
1305: my $forcesupplement;
1306: my $script='';
1307: my $allowed;
1308: my $events='';
1309: my $showdoc=0;
1310: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1311: ['folderpath']);
1312: if ($ENV{'form.folderpath'}) {
1313: my (@folderpath)=split('&',$ENV{'form.folderpath'});
1314: $ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
1315: $ENV{'form.folder'}=pop(@folderpath);
1316: }
1317: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1318: $showdoc='/'.$1;
1319: }
1320: unless ($showdoc) { # got called from remote
1321: $forcestandard=($ENV{'form.folder'}=~/^default_/);
1322: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1323:
1324: # does this user have privileges to post, etc?
1325: $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1326: if ($allowed) {
1327: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1328: $script=&Apache::lonratedt::editscript('simple');
1329: }
1330: } else { # got called in sequence from course
1331: $allowed=0;
1332: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
1333: $events='onLoad="'.&Apache::lonmenu::loadevents.
1334: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1335: }
1336:
1337: # get course data
1338: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
1339: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1340:
1341: # get personal data
1342:
1343: my $uname=$ENV{'user.name'};
1344: my $udom=$ENV{'user.domain'};
1345: my $plainname=&Apache::lonnet::escape(
1346: &Apache::loncommon::plainname($uname,$udom));
1347:
1348: # graphics settings
1349:
1350: $iconpath = $r->dir_config('lonIconsURL') . "/";
1351:
1352: my $now=time;
1353:
1354: # print screen
1355: $r->print(<<ENDDOCUMENT);
1356: <html>
1357: <head>
1358: <title>The LearningOnline Network with CAPA</title>
1359: <script>
1360: $script
1361: </script>
1362: ENDDOCUMENT
1363: if ($allowed) {
1364: $r->print(<<ENDNEWSCRIPT);
1365: <script>
1366: function makenewfolder(targetform,folderseq) {
1367: var foldername=prompt('Name of New Folder','New Folder');
1368: if (foldername) {
1369: targetform.importdetail.value=foldername+"="+folderseq;
1370: targetform.submit();
1371: }
1372: }
1373:
1374: function makenewext(targetname) {
1375: this.document.forms.extimport.useform.value=targetname;
1376: window.open('/adm/rat/extpickframe.html');
1377: }
1378:
1379: function makeexamupload() {
1380: var title=prompt('Listed Title for the Uploaded Score');
1381: if (title) {
1382: this.document.forms.newexamupload.importdetail.value=
1383: title+'=/res/lib/templates/examupload.problem';
1384: this.document.forms.newexamupload.submit();
1385: }
1386: }
1387:
1388: function makesmppage() {
1389: var title=prompt('Listed Title for the Page');
1390: if (title) {
1391: this.document.forms.newsmppg.importdetail.value=
1392: title+'=/adm/$udom/$uname/$now/smppg';
1393: this.document.forms.newsmppg.submit();
1394: }
1395: }
1396:
1397: function makesmpproblem() {
1398: var title=prompt('Listed Title for the Problem');
1399: if (title) {
1400: this.document.forms.newsmpproblem.importdetail.value=
1401: title+'=/res/lib/templates/simpleproblem.problem';
1402: this.document.forms.newsmpproblem.submit();
1403: }
1404: }
1405:
1406: function makebulboard() {
1407: var title=prompt('Listed Title for the Bulletin Board');
1408: if (title) {
1409: this.document.forms.newbul.importdetail.value=
1410: title+'=/adm/$udom/$uname/$now/bulletinboard';
1411: this.document.forms.newbul.submit();
1412: }
1413: }
1414:
1415: function makeabout() {
1416: var user=prompt("Enter user\@domain for User's 'About Me' Page");
1417: if (user) {
1418: var comp=new Array();
1419: comp=user.split('\@');
1420: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
1421: if ((comp[0]) && (comp[1])) {
1422: this.document.forms.newaboutsomeone.importdetail.value=
1423: 'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1424: this.document.forms.newaboutsomeone.submit();
1425: }
1426: }
1427: }
1428: }
1429:
1430: function makeims() {
1431: var caller = document.forms.ims.folder.value
1432: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
1433: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
1434: newWindow.location.href = newlocation
1435: }
1436:
1437:
1438: function finishpick() {
1439: var title=this.document.forms.extimport.title.value;
1440: var url=this.document.forms.extimport.url.value;
1441: var form=this.document.forms.extimport.useform.value;
1442: eval
1443: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
1444: '";this.document.forms.'+form+'.submit();');
1445: }
1446:
1447: function changename(folderpath,index,oldtitle) {
1448: var title=prompt('New Title',oldtitle);
1449: if (title) {
1450: this.document.forms.renameform.title.value=title;
1451: this.document.forms.renameform.cmd.value='rename_'+index;
1452: this.document.forms.renameform.folderpath.value=folderpath;
1453: this.document.forms.renameform.submit();
1454: }
1455: }
1456:
1457: function removeres(folderpath,index,oldtitle) {
1458: if (confirm('Remove "'+oldtitle+'"?')) {
1459: this.document.forms.renameform.cmd.value='del_'+index;
1460: this.document.forms.renameform.folderpath.value=folderpath;
1461: this.document.forms.renameform.submit();
1462: }
1463: }
1464:
1465: </script>
1466:
1467: ENDNEWSCRIPT
1468: }
1469: # -------------------------------------------------------------------- Body tag
1470: $r->print('</head>'.
1471: &Apache::loncommon::bodytag('Course Documents','',$events,
1472: '','',$showdoc).
1473: &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
1474: unless ($showdoc) {
1475: # -----------------------------------------------------------------------------
1476: my %lt=&Apache::lonlocal::texthash(
1477: 'uplm' => 'Upload a new main course document',
1478: 'upls' => 'Upload a new supplemental course document',
1479: 'impp' => 'Import a published document',
1480: 'spec' => 'Special documents',
1481: 'upld' => 'Upload Document',
1482: 'srch' => 'Search',
1483: 'impo' => 'Import',
1484: 'selm' => 'Select Map',
1485: 'load' => 'Load Map',
1486: 'newf' => 'New Folder',
1487: 'extr' => 'External Resource',
1488: 'syll' => 'Syllabus',
1489: 'navc' => 'Navigate Contents',
1490: 'sipa' => 'Simple Page',
1491: 'sipr' => 'Simple Problem',
1492: 'scuf' => 'Score Upload Form',
1493: 'bull' => 'Bulletin Board',
1494: 'mypi' => 'My Personal Info',
1495: 'abou' => 'About User',
1496: 'imsf' => 'Import IMS package',
1497: 'file' => 'File',
1498: 'title' => 'Title',
1499: 'comment' => 'Comment'
1500: );
1501: # -----------------------------------------------------------------------------
1502: if ($allowed) {
1503: my $dumpbut=&dumpbutton();
1504: my $exportbut=&exportbutton();
1505: my %lt=&Apache::lonlocal::texthash(
1506: 'vc' => 'Verify Content',
1507: 'cv' => 'Check/Set Resource Versions',
1508: );
1509:
1510: my $folderpath=$ENV{'form.folderpath'};
1511: if (!$folderpath) {
1512: if ($ENV{'form.folder'} eq '' ||
1513: $ENV{'form.folder'} eq 'supplemental') {
1514: $folderpath='default&'.
1515: &Apache::lonnet::escape(&mt('Main Course Documents'));
1516: }
1517: }
1518: $r->print(<<ENDCOURSEVERIFY);
1519: <form name="renameform" method="post" action="/adm/coursedocs">
1520: <input type="hidden" name="title" />
1521: <input type="hidden" name="cmd" />
1522: <input type="hidden" name="folderpath" />
1523: </form>
1524: <form name="simpleedit" method="post" action="/adm/coursedocs">
1525: <input type=hidden name="importdetail" value="">
1526: <input type="hidden" name="folderpath" value="$folderpath" />
1527: </form>
1528: <form action="/adm/coursedocs" method="post" name="courseverify">
1529: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
1530: <tr><td bgcolor="#DDDDCC">
1531: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
1532: </td><td bgcolor="#DDDDCC">
1533: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
1534: $dumpbut
1535: $exportbut
1536: </td></tr></table>
1537: </form>
1538: ENDCOURSEVERIFY
1539: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1540: &mt('Editing the Table of Contents for your Course')));
1541: }
1542: # --------------------------------------------------------- Standard documents
1543: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1544: if (($standard) && ($allowed) && (!$forcesupplement)) {
1545: $r->print('<tr><td bgcolor="#BBBBBB">');
1546: # '<h2>'.&mt('Main Course Documents').
1547: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1548: my $folder=$ENV{'form.folder'};
1549: if ($folder eq '' || $folder eq 'supplemental') {
1550: $folder='default';
1551: $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
1552: }
1553: my $postexec='';
1554: if ($folder eq 'default') {
1555: $r->print('<script>this.window.name="loncapaclient";</script>');
1556: } else {
1557: #$postexec='self.close();';
1558: }
1559: $hadchanges=0;
1560: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1561: if ($hadchanges) {
1562: &mark_hash_old()
1563: }
1564: &changewarning($r,$postexec);
1565: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
1566: '.sequence';
1567: $r->print(<<ENDFORM);
1568: <table cellspacing=4 cellpadding=4><tr>
1569: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
1570: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
1571: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1572: </tr>
1573: <tr><td bgcolor="#DDDDDD">
1574: $lt{'file'}:<br />
1575: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1576: <input type="file" name="uploaddoc" size="40">
1577: <br />
1578: $lt{'title'}:<br />
1579: <input type="text" size="50" name="comment">
1580: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1581: <input type="hidden" name="cmd" value="upload_default">
1582: <nobr>
1583: <input type="submit" value="$lt{'upld'}">
1584: $help{'Uploading_From_Harddrive'}
1585: </nobr>
1586: </form>
1587: </td>
1588: <td bgcolor="#DDDDDD">
1589: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1590: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1591: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
1592: <nobr>
1593: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
1594: $help{'Importing_LON-CAPA_Resource'}
1595: </nobr>
1596: <p>
1597: <hr />
1598: <input type="text" size="20" name="importmap"><br />
1599: <nobr><input type=button
1600: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1601: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
1602: $help{'Load_Map'}</nobr>
1603: </p>
1604: </form>
1605: </td><td bgcolor="#DDDDDD">
1606: <form action="/adm/coursedocs" method="post" name="newfolder">
1607: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1608: <input type=hidden name="importdetail" value="">
1609: <nobr>
1610: <input name="newfolder" type="button"
1611: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1612: value="$lt{'newf'}" />$help{'Adding_Folders'}
1613: </nobr>
1614: </form>
1615: <form action="/adm/coursedocs" method="post" name="newext">
1616: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1617: <input type=hidden name="importdetail" value="">
1618: <nobr>
1619: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
1620: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1621: </nobr>
1622: </form>
1623: <form action="/adm/coursedocs" method="post" name="newsyl">
1624: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1625: <input type=hidden name="importdetail"
1626: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1627: <nobr>
1628: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1629: $help{'Syllabus'}
1630: </nobr>
1631: </form>
1632: <form action="/adm/coursedocs" method="post" name="newnav">
1633: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1634: <input type=hidden name="importdetail"
1635: value="Navigate Content=/adm/navmaps">
1636: <nobr>
1637: <input name="newnav" type="submit" value="$lt{'navc'}" />
1638: $help{'Navigate_Content'}
1639: </nobr>
1640: </form>
1641: <form action="/adm/coursedocs" method="post" name="newsmppg">
1642: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1643: <input type=hidden name="importdetail" value="">
1644: <nobr>
1645: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1646: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1647: </nobr>
1648: </form>
1649: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1650: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1651: <input type=hidden name="importdetail" value="">
1652: <nobr>
1653: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1654: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1655: </nobr>
1656: </form>
1657: <form action="/adm/coursedocs" method="post" name="newexamupload">
1658: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1659: <input type=hidden name="importdetail" value="">
1660: <nobr>
1661: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1662: onClick="javascript:makeexamupload();" />
1663: $help{'Score_Upload_Form'}
1664: </nobr>
1665: </form>
1666: <form action="/adm/coursedocs" method="post" name="newbul">
1667: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1668: <input type=hidden name="importdetail" value="">
1669: <nobr>
1670: <input name="newbulletin" type="button" value="$lt{'bull'}"
1671: onClick="javascript:makebulboard();" />
1672: $help{'Bulletin Board'}
1673: </nobr>
1674: </form>
1675: <form action="/adm/coursedocs" method="post" name="newaboutme">
1676: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1677: <input type=hidden name="importdetail"
1678: value="$plainname=/adm/$udom/$uname/aboutme">
1679: <nobr>
1680: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1681: $help{'My Personal Info'}
1682: </nobr>
1683: </form>
1684: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1685: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1686: <input type=hidden name="importdetail" value="">
1687: <nobr>
1688: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
1689: onClick="javascript:makeabout();" />
1690: </nobr>
1691: </form>
1692: <form action="/adm/imsimportdocs" method="post" name="ims">
1693: <input type="hidden" name="folder" value="$folder" />
1694: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
1695: </nobr>
1696: </form>
1697: </td></tr>
1698: </table>
1699: ENDFORM
1700: $r->print('</td></tr>');
1701: }
1702: # ----------------------------------------------------- Supplemental documents
1703: if (!$forcestandard) {
1704: $r->print('<tr><td bgcolor="#BBBBBB">');
1705: # '<h2>'.&mt('Supplemental Course Documents').
1706: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1707: my $folder=$ENV{'form.folder'};
1708: unless ($folder=~/^supplemental/) {
1709: $folder='supplemental';
1710: }
1711: if ($folder =~ /^supplemental$/ &&
1712: $ENV{'form.folderpath'} =~ /^default\&/) {
1713: $ENV{'form.folderpath'}='supplemental&'.
1714: &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
1715: }
1716: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1717: if ($allowed) {
1718: my $folderseq=
1719: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
1720: '.sequence';
1721:
1722: $r->print(<<ENDSUPFORM);
1723: <table cellspacing=4 cellpadding=4><tr>
1724: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
1725: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1726: </tr>
1727: <tr><td bgcolor="#DDDDDD">
1728: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1729: <input type="file" name="uploaddoc" size="40">
1730: <br />$lt{'comment'}:<br />
1731: <textarea cols=50 rows=4 name='comment'>
1732: </textarea>
1733: <br />
1734: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1735: <input type="hidden" name="cmd" value="upload_supplemental">
1736: <nobr>
1737: <input type="submit" value="$lt{'upld'}">
1738: $help{'Uploading_From_Harddrive'}
1739: </nobr>
1740: </form>
1741: </td>
1742: <td bgcolor="#DDDDDD">
1743: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1744: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1745: <input type=hidden name="importdetail" value="">
1746: <nobr>
1747: <input name="newfolder" type="button"
1748: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1749: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1750: </nobr>
1751: </form>
1752: <form action="/adm/coursedocs" method="post" name="supnewext">
1753: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1754: <input type=hidden name="importdetail" value="">
1755: <nobr>
1756: <input name="newext" type="button"
1757: onClick="javascript:makenewext('supnewext');"
1758: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1759: </nobr>
1760: </form>
1761: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1762: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1763: <input type=hidden name="importdetail"
1764: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1765: <nobr>
1766: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1767: $help{'Syllabus'}
1768: </nobr>
1769: </form>
1770: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1771: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1772: <input type=hidden name="importdetail"
1773: value="$plainname=/adm/$udom/$uname/aboutme">
1774: <nobr>
1775: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1776: $help{'My Personal Info'}
1777: </nobr>
1778: </form>
1779: </td></tr>
1780: </table></td></tr>
1781: ENDSUPFORM
1782: }
1783: }
1784: if ($allowed) {
1785: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
1786: }
1787: $r->print('</table>');
1788: } else {
1789: # -------------------------------------------------------- This is showdoc mode
1790: $r->print("<h1>".&mt('Uploaded Document').' - '.
1791: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
1792: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
1793: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
1794: }
1795: }
1796: $r->print('</body></html>');
1797: return OK;
1798: }
1799:
1800: 1;
1801: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>