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