1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.79 2003/09/15 17:58:21 www 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:
42: my $iconpath;
43:
44: my %hash;
45:
46: my $hashtied;
47: my %alreadyseen=();
48:
49: my $hadchanges;
50:
51: # Available help topics
52:
53: my %help=();
54:
55: # Mapread read maps into lonratedt::global arrays
56: # @order and @resources, determines status
57: # sets @order - pointer to resources in right order
58: # sets @resources - array with the resources with correct idx
59: #
60:
61: sub mapread {
62: my ($coursenum,$coursedom,$map)=@_;
63: return
64: &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
65: $map);
66: }
67:
68: sub storemap {
69: my ($coursenum,$coursedom,$map)=@_;
70: $hadchanges=1;
71: return
72: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
73: $map,1);
74: }
75:
76: # ----------------------------------------- Return hash with valid author names
77:
78: sub authorhosts {
79: my %outhash=();
80: my $home=0;
81: my $other=0;
82: foreach (keys %ENV) {
83: if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
84: my $role=$1;
85: my $realm=$2;
86: my ($start,$end)=split(/\./,$ENV{$_});
87: if (($start) && ($start>time)) { next; }
88: if (($end) && (time>$end)) { next; }
89: my $ca; my $cd;
90: if ($1 eq 'au') {
91: $ca=$ENV{'user.name'};
92: $cd=$ENV{'user.domain'};
93: } else {
94: ($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
95: }
96: if (&Apache::lonnet::homeserver($ca,$cd) eq
97: $Apache::lonnet::perlvar{'lonHostID'}) {
98: $home++;
99: $outhash{'home_'.$ca.'@'.$cd}=1;
100: } else {
101: $outhash{'otherhome_'.$ca.'@'.$cd}=
102: &Apache::lonnet::homeserver($ca,$cd);
103: $other++;
104: }
105: }
106: }
107: return ($home,$other,%outhash);
108: }
109: # ------------------------------------------------------ Generate "dump" button
110:
111: sub dumpbutton {
112: my ($home,$other,%outhash)=&authorhosts();
113: if ($home+$other==0) { return ''; }
114: my $output='</td><td bgcolor="#DDDDCC">';
115: if ($home) {
116: return '</td><td bgcolor="#DDDDCC">'.
117: '<input type="submit" name="dumpcourse" value="Dump Course DOCS to Construction Space" />';
118: } else {
119: return'</td><td bgcolor="#DDDDCC">'.
120: 'Dump Course DOCS to Construction Space: available on other servers';
121: }
122: }
123:
124: # -------------------------------------------------------- Actually dump course
125:
126: sub dumpcourse {
127: my $r=shift;
128: $r->print('<html><head><title>Dump DOCS</title></head>'.
129: &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
130: '<form name="dumpdoc" method="post">');
131: my ($home,$other,%outhash)=&authorhosts();
132: unless ($home) { return ''; }
133: my $origcrsid=$ENV{'request.course.id'};
134: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
135: if (($ENV{'form.authorspace'}) && ($ENV{'form.authorfolder'}=~/\w/)) {
136: # Do the dumping
137: unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
138: my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
139: $r->print('<h3>Copying Files</h3>');
140: my $title=$ENV{'form.authorfolder'};
141: $title=~s/[^\w\/]+/\_/g;
142: my %replacehash=();
143: foreach (keys %ENV) {
144: if ($_=~/^form\.namefor\_(.+)/) {
145: $replacehash{$1}=$ENV{$_};
146: }
147: }
148: my $crs='/uploaded/'.$ENV{'request.course.id'}.'/';
149: $crs=~s/\_/\//g;
150: foreach (keys %replacehash) {
151: my $newfilename=$title.'/'.$replacehash{$_};
152: $newfilename=~s/[^\w\/\.]+/\_/g;
153: my @dirs=split(/\//,$newfilename);
154: my $path='/home/'.$ca.'/public_html';
155: my $makepath=$path;
156: my $fail=0;
157: for (my $i=0;$i<$#dirs;$i++) {
158: $makepath.='/'.$dirs[$i];
159: unless (-e $makepath) {
160: unless(mkdir($makepath,0777)) { $fail=1; }
161: }
162: }
163: $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
164: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
165: if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
166: print $fh &Apache::loncreatecourse::rewritefile(
167: &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_),
168: (%replacehash,$crs => '')
169: );
170: } else {
171: print $fh
172: &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_);
173: }
174: $fh->close();
175: } else {
176: $fail=1;
177: }
178: if ($fail) {
179: $r->print('<font color="red">fail</font>');
180: } else {
181: $r->print('<font color="green">ok</font>');
182: }
183: }
184: } else {
185: # Input form
186: unless ($home==1) {
187: $r->print(
188: '<h3>Select the Construction Space</h3><select name="authorspace">');
189: }
190: foreach (sort keys %outhash) {
191: if ($_=~/^home_(.+)$/) {
192: if ($home==1) {
193: $r->print(
194: '<input type="hidden" name="authorspace" value="'.$1.'" />');
195: } else {
196: $r->print('<option value="'.$1.'">'.$_.'</option>');
197: }
198: }
199: }
200: unless ($home==1) {
201: $r->print('</select>');
202: }
203: my $title=$origcrsdata{'description'};
204: $title=~s/\s+/\_/gs;
205: $title=~s/\W//gs;
206: $r->print('<h3>Folder in Construction Space</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
207: &tiehash();
208: $r->print('<h3>Filenames in Construction Space</h3><table border="2"><tr><th>Internal Filename</th><th>Title</th><th>Save as ...</th></tr>');
209: foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
210: $r->print('<tr><td>'.$_.'</td>');
211: my ($ext)=($_=~/\.(\w+)$/);
212: my $title=$hash{'title_'.$hash{
213: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
214: $r->print('<td>'.($title?$title:' ').'</td>');
215: unless ($title) {
216: $title=$_;
217: }
218: $title=~s/\.(\w+)$//;
219: $title=~s/\W+/\_/gs;
220: $title.='.'.$ext;
221: $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
222: }
223: $r->print("</table>\n");
224: &untiehash();
225: $r->print(
226: '<p><input type="submit" name="dumpcourse" value="Dump Course DOCS" /></p></form>');
227: }
228: }
229:
230:
231: # Imports the given (name, url) resources into the course
232: # coursenum, coursedom, and folder must precede the list
233: sub group_import {
234: my $coursenum = shift;
235: my $coursedom = shift;
236: my $folder = shift;
237: while (@_) {
238: my $name = shift;
239: my $url = shift;
240: if ($url) {
241: my $idx = $#Apache::lonratedt::resources + 1;
242: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
243: my $ext = 'false';
244: if ($url=~/^http:\/\//) { $ext = 'true'; }
245: $url =~ s/:/\:/g;
246: $name =~ s/:/\:/g;
247: $Apache::lonratedt::resources[$idx] =
248: join ':', ($name, $url, $ext, 'normal', 'res');
249: }
250: }
251: &storemap($coursenum, $coursedom, $folder);
252: }
253:
254: sub editor {
255: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
256: if ($ENV{'form.foldername'}) {
257: $r->print('<h3>Folder: '.$ENV{'form.foldername'}.'</h3>');
258: }
259: my $errtext='';
260: my $fatal=0;
261: ($errtext,$fatal)=
262: &mapread($coursenum,$coursedom,$folder.'.sequence');
263: if ($#Apache::lonratedt::order<1) {
264: $Apache::lonratedt::order[0]=1;
265: $Apache::lonratedt::resources[1]='';
266: }
267: if ($fatal) {
268: $r->print('<p><font color="red">'.$errtext.'</font></p>');
269: } else {
270: # ------------------------------------------------------------ Process commands
271: # ---------------- if they are for this folder and user allowed to make changes
272: if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
273: # upload a file, if present
274: if (($ENV{'form.uploaddoc.filename'}) &&
275: ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
276: if ($folder=~/^$1/) {
277: # this is for a course, not a user, so set coursedoc flag
278: # probably the only place in the system where this should be "1"
279: my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
280: my $ext='false';
281: if ($url=~/^http\:\/\//) { $ext='true'; }
282: $url=~s/\:/\:/g;
283: my $comment=$ENV{'form.comment'};
284: $comment=~s/\</\<\;/g;
285: $comment=~s/\>/\>\;/g;
286: $comment=~s/\:/\:/g;
287: if ($folder=~/^supplemental/) {
288: $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
289: $ENV{'user.domain'}.'___&&&___'.$comment;
290: }
291: my $newidx=$#Apache::lonratedt::resources+1;
292: $Apache::lonratedt::resources[$newidx]=
293: $comment.':'.$url.':'.$ext.':normal:res';
294: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
295: $newidx;
296: &storemap($coursenum,$coursedom,$folder.'.sequence');
297: }
298: }
299: if ($ENV{'form.cmd'}) {
300: my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
301: if ($cmd eq 'del') {
302: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
303: $Apache::lonratedt::order[$i]=
304: $Apache::lonratedt::order[$i+1];
305: }
306: $#Apache::lonratedt::order--;
307: } elsif ($cmd eq 'up') {
308: if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
309: my $i=$Apache::lonratedt::order[$idx-1];
310: $Apache::lonratedt::order[$idx-1]=
311: $Apache::lonratedt::order[$idx];
312: $Apache::lonratedt::order[$idx]=$i;
313: }
314: } elsif ($cmd eq 'down') {
315: if (defined($Apache::lonratedt::order[$idx+1])) {
316: my $i=$Apache::lonratedt::order[$idx+1];
317: $Apache::lonratedt::order[$idx+1]=
318: $Apache::lonratedt::order[$idx];
319: $Apache::lonratedt::order[$idx]=$i;
320: }
321: } elsif ($cmd eq 'rename') {
322: my ($rtitle,@rrest)=split(/\:/,
323: $Apache::lonratedt::resources[
324: $Apache::lonratedt::order[$idx]]);
325: my $comment=
326: &HTML::Entities::decode($ENV{'form.title'});
327: $comment=~s/\</\<\;/g;
328: $comment=~s/\>/\>\;/g;
329: $comment=~s/\:/\:/g;
330: $Apache::lonratedt::resources[
331: $Apache::lonratedt::order[$idx]]=
332: $comment.':'.join(':',@rrest);
333:
334: }
335: # Store the changed version
336: &storemap($coursenum,$coursedom,$folder.'.sequence');
337: }
338: # Group import/search
339: if ($ENV{'form.importdetail'}) {
340: my @imports;
341: foreach (split(/\&/,$ENV{'form.importdetail'})) {
342: if (defined($_)) {
343: my ($name,$url)=split(/\=/,$_);
344: $name=&Apache::lonnet::unescape($name);
345: $url=&Apache::lonnet::unescape($url);
346: push @imports, $name, $url;
347: }
348: }
349: # Store the changed version
350: group_import($coursenum, $coursedom, $folder, @imports);
351: }
352: # Loading a complete map
353: if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
354: foreach
355: (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
356: my $idx=$#Apache::lonratedt::resources;
357: $idx++;
358: $Apache::lonratedt::resources[$idx]=$_;
359: $Apache::lonratedt::order
360: [$#Apache::lonratedt::order+1]=$idx;
361: }
362:
363: # Store the changed version
364: &storemap($coursenum,$coursedom,$folder.'.sequence');
365: }
366: }
367: # ---------------------------------------------------------------- End commands
368: # ---------------------------------------------------------------- Print screen
369: my $idx=0;
370: $r->print('<table>');
371: foreach (@Apache::lonratedt::order) {
372: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
373: unless ($name) { $name=(split(/\//,$url))[-1]; }
374: unless ($name) { $name='NO RESOURCE'; $url='/adm/notfound.html'; }
375: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_));
376: $idx++;
377: }
378: $r->print('</table>');
379: }
380: }
381:
382: # --------------------------------------------------------------- An entry line
383:
384: sub entryline {
385: my ($index,$title,$url,$folder,$allowed,$residx)=@_;
386: $title=~s/\&colon\;/\:/g;
387: $title=&HTML::Entities::encode(&HTML::Entities::decode(
388: &Apache::lonnet::unescape($title)),'\"\<\>\&\'');
389: my $renametitle=$title;
390: my $foldertitle=$title;
391: if ($title=~
392: /^(\d+)\_\_\_\&\;\&\;\&\;\_\_\_(\w+)\_\_\_\&\;\&\;\&\;\_\_\_(\w+)\_\_\_\&\;\&\;\&\;\_\_\_(.*)$/
393: ) {
394: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
395: $renametitle=$4;
396: $title='<i>'.localtime($1).'</i> '.
397: &Apache::loncommon::plainname($2,$3).': <br>'.
398: $foldertitle;
399: }
400: $renametitle=~s/\"\;/\\\"/g;
401: my $line='<tr>';
402: # Edit commands
403: if ($allowed) {
404: $line.=(<<END);
405: <td><table border='0' cellspacing='2' cellpadding='0'>
406: <tr><td bgcolor="#DDDDDD">
407: <a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
408: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
409: <tr><td bgcolor="#DDDDDD">
410: <a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
411: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
412: </table></td><td bgcolor="#DDDDDD">
413: <a href='javascript:removeres("$folder","$index","$renametitle");'>
414: <font size="-2" color="#990000">Remove</font></a>
415: <a href='javascript:changename("$folder","$index","$renametitle");'>
416: <font size="-2" color="#009900">Rename</font></a></td>
417: END
418: }
419: # Figure out what kind of a resource this is
420: my ($extension)=($url=~/\.(\w+)$/);
421: my $uploaded=($url=~/^\/*uploaded\//);
422: my $icon='unknown';
423: if (-e "/home/httpd/html/adm/lonIcons/$extension.gif") {
424: $icon=$extension;
425: }
426: my $isfolder=0;
427: if ($uploaded) {
428: if ($extension eq 'sequence') {
429: $icon='folder_closed';
430: $url=~/\/(\w+)\.sequence/;
431: $url='/adm/coursedocs?folder='.$1;
432: $isfolder=1;
433: } else {
434: $url=&Apache::lonnet::tokenwrapper($url);
435: }
436: }
437: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
438: if (($residx) && ($folder!~/supplemental/)) {
439: $url.=(($url=~/\?/)?'&':'?').'symb='.
440: &Apache::lonnet::escape(&Apache::lonnet::symbclean(
441: &Apache::lonnet::declutter('uploaded/'.
442: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
443: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
444: '.sequence').
445: '___'.$residx.'___'.
446: &Apache::lonnet::declutter($url)));
447: }
448: if ($isfolder) { $url.='&foldername='.
449: &Apache::lonnet::escape($foldertitle); }
450: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'" target="cat_'.$folder.
451: '"><img src="/adm/lonIcons/'.
452: $icon.'.gif" border="0"></a></td>'.
453: "<td bgcolor='#FFFFBB'><a href='$url' target='cat_$folder'>$title</a></td></tr>";
454: return $line;
455: }
456:
457: # ---------------------------------------------------------------- tie the hash
458:
459: sub tiehash {
460: $hashtied=0;
461: if ($ENV{'request.course.fn'}) {
462: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
463: &GDBM_READER(),0640)) {
464: $hashtied=1;
465: }
466: }
467: }
468:
469: sub untiehash {
470: if ($hashtied) { untie %hash; }
471: $hashtied=0;
472: }
473:
474: # --------------------------------------------------------------- check on this
475:
476: sub checkonthis {
477: my ($r,$url,$level,$title)=@_;
478: $alreadyseen{$url}=1;
479: $r->rflush();
480: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
481: $r->print('<br />');
482: for (my $i=0;$i<=$level*5;$i++) {
483: $r->print(' ');
484: }
485: $r->print('<a href="'.$url.'" target="cat">'.
486: ($title?$title:$url).'</a> ');
487: if ($url=~/^\/res\//) {
488: my $result=&Apache::lonnet::repcopy(
489: &Apache::lonnet::filelocation('',$url));
490: if ($result==OK) {
491: $r->print('<font color="green">ok</font>');
492: $r->rflush();
493: &Apache::lonnet::countacc($url);
494: $url=~/\.(\w+)$/;
495: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
496: $r->print('<br />');
497: $r->rflush();
498: for (my $i=0;$i<=$level*5;$i++) {
499: $r->print(' ');
500: }
501: $r->print('- Rendering: ');
502: my $oldpath=$ENV{'request.filename'};
503: $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
504: &Apache::lonxml::xmlparse($r,'web',
505: &Apache::lonnet::getfile(
506: &Apache::lonnet::filelocation('',$url)));
507: $ENV{'request.filename'}=$oldpath;
508: if (($Apache::lonxml::errorcount) ||
509: ($Apache::lonxml::warningcount)) {
510: if ($Apache::lonxml::errorcount) {
511: $r->print('<font color="red"><b>'.
512: $Apache::lonxml::errorcount.' error(s)</b></font> ');
513: }
514: if ($Apache::lonxml::warningcount) {
515: $r->print('<font color="blue">'.
516: $Apache::lonxml::warningcount.' warning(s)</font>');
517: }
518: } else {
519: $r->print('<font color="green">ok</font>');
520: }
521: $r->rflush();
522: }
523: my $dependencies=
524: &Apache::lonnet::metadata($url,'dependencies');
525: foreach (split(/\,/,$dependencies)) {
526: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
527: &checkonthis($r,$_,$level+1);
528: }
529: }
530: } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
531: $r->print('<font color="red"><b>connection down</b></font>');
532: } elsif ($result==HTTP_NOT_FOUND) {
533: $r->print('<font color="red"><b>not found</b></font>');
534: } else {
535: $r->print('<font color="red"><b>access denied</b></font>');
536: }
537: }
538: }
539: }
540:
541:
542: #
543: # -------------------------------------------------------------- Verify Content
544: #
545: sub verifycontent {
546: my $r=shift;
547: my $loaderror=&Apache::lonnet::overloaderror($r);
548: if ($loaderror) { return $loaderror; }
549:
550: $r->print('<html><head><title>Verify Content</title></head>'.
551: &Apache::loncommon::bodytag('Verify Course Documents'));
552: $hashtied=0;
553: undef %alreadyseen;
554: %alreadyseen=();
555: &tiehash();
556: foreach (keys %hash) {
557: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
558: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
559: }
560: }
561: &untiehash();
562: $r->print('<h1>Done.</h1>');
563: }
564:
565: # -------------------------------------------------------------- Check Versions
566:
567: sub checkversions {
568: my $r=shift;
569: $r->print('<html><head><title>Check Versions</title></head>'.
570: &Apache::loncommon::bodytag('Check Course Document Versions'));
571: $hashtied=0;
572: &tiehash();
573: my %changes=&Apache::lonnet::dump
574: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
575: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
576: my $firstkey=(keys %changes)[0];
577: unless ($firstkey=~/^error\:/) {
578: unless ($ENV{'form.timerange'}) {
579: $ENV{'form.timerange'}=604800;
580: }
581: my $seltext='during the last '.$ENV{'form.timerange'}.' seconds';
582: my $startsel='';
583: my $monthsel='';
584: my $weeksel='';
585: my $daysel='';
586: if ($ENV{'form.timerange'}==-1) {
587: $seltext='since start of course';
588: $startsel='selected';
589: $ENV{'form.timerange'}=time;
590: }
591: my $starttime=time-$ENV{'form.timerange'};
592: if ($ENV{'form.timerange'}==2592000) {
593: $seltext='during the last month ('.localtime($starttime).')';
594: $monthsel='selected';
595: } elsif ($ENV{'form.timerange'}==604800) {
596: $seltext='during the last week ('.localtime($starttime).')';
597: $weeksel='selected';
598: } elsif ($ENV{'form.timerange'}==86400) {
599: $seltext='since yesterday ('.localtime($starttime).')';
600: $daysel='selected';
601: }
602:
603: $r->print(<<ENDHEADERS);
604: <form action="/adm/coursedocs" method="post">
605: <select name="timerange">
606: <option value="-1" $startsel>Since Start of Course</option>
607: <option value="2592000" $monthsel>Last Month</option>
608: <option value="604800" $weeksel>Last Week</option>
609: <option value="86400" $daysel>Since Yesterday</option>
610: </select>
611: <input type="submit" name="versions" value="Display" />
612: </form>
613: <h3>Content changed $seltext</h3>
614: <table border="2">
615: <tr>
616: <th>File</th><th>Modification Date</th>
617: <th>Version</th><th>Differences</th></tr>
618: ENDHEADERS
619: foreach (keys %changes) {
620: if ($changes{$_}>$starttime) {
621: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
622: my $currentversion=&Apache::lonnet::getversion($_);
623: my $linkurl=&Apache::lonnet::clutter($_);
624: $r->print(
625: '<tr><td><a href="'.$linkurl.'" target="cat">'.$linkurl.
626: '</a></td><td>'.
627: localtime($changes{$_}).'</td><td>'.$currentversion.'</td>'.
628: '<td>');
629: my $lastold=1;
630: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
631: my $url=$root.'.'.$prevvers.'.'.$extension;
632: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
633: $starttime) {
634: $lastold=$prevvers;
635: }
636: }
637: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
638: my $url=$root.'.'.$prevvers.'.'.$extension;
639: $r->print('<a href="'.&Apache::lonnet::clutter($url).
640: '">Version '.$prevvers.' ('.
641: localtime(&Apache::lonnet::metadata($url,'lastrevisiondate')).
642: ')</a>');
643: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
644: $r->print(' <a href="/adm/diff?filename='.
645: &Apache::lonnet::clutter($root.'.'.$extension).
646: '&versionone='.$prevvers.
647: '">Diffs</a>');
648: }
649: $r->print('<br />');
650: }
651: $r->print('</td></tr>');
652: }
653: }
654: $r->print('</table>');
655: $r->print('<h1>Done.</h1>');
656: } else {
657: $r->print('<p>No content modifications yet.</p>');
658: }
659: &untiehash();
660: }
661:
662: # ================================================================ Main Handler
663: sub handler {
664: my $r = shift;
665: $r->content_type('text/html');
666: $r->send_http_header;
667: return OK if $r->header_only;
668:
669: # --------------------------------------------- Initialize help topics for this
670: foreach ('Adding_Course_Doc','Main_Course_Documents',
671: 'Adding_External_Resource','Navigate_Content',
672: 'Adding_Folders','Docs_Overview', 'Load_Map',
673: 'Supplemental', 'Score_Upload_Form',
674: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive') {
675: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
676: }
677: # Composite help files
678: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
679: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
680: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
681: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
682: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
683: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
684: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
685: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
686: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
687:
688: if ($ENV{'form.verify'}) {
689: &verifycontent($r);
690: } elsif ($ENV{'form.versions'}) {
691: &checkversions($r);
692: } elsif ($ENV{'form.dumpcourse'}) {
693: &dumpcourse($r);
694: } else {
695: # is this a standard course?
696:
697: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
698: my $forcestandard;
699: my $forcesupplement;
700: my $script='';
701: my $allowed;
702: my $events='';
703: my $showdoc=0;
704: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
705: ['folder','foldername']);
706: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
707: $showdoc=$1;
708: }
709: unless ($showdoc) { # got called from remote
710: $forcestandard=($ENV{'form.folder'}=~/^default_/);
711: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
712:
713: # does this user have privileges to post, etc?
714: $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
715: if ($allowed) {
716: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
717: $script=&Apache::lonratedt::editscript('simple');
718: }
719: } else { # got called in sequence from course
720: $allowed=0;
721: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
722: $events='onLoad="'.&Apache::lonmenu::loadevents.
723: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
724: }
725:
726: # get course data
727: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
728: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
729:
730: # get personal data
731:
732: my $uname=$ENV{'user.name'};
733: my $udom=$ENV{'user.domain'};
734: my $plainname=&Apache::lonnet::escape(
735: &Apache::loncommon::plainname($uname,$udom));
736:
737: # graphics settings
738:
739: $iconpath = $r->dir_config('lonIconsURL') . "/";
740:
741: my $now=time;
742:
743: # print screen
744: $r->print(<<ENDDOCUMENT);
745: <html>
746: <head>
747: <title>The LearningOnline Network with CAPA</title>
748: <script>
749: $script
750: </script>
751: ENDDOCUMENT
752: if ($allowed) {
753: $r->print(<<ENDNEWSCRIPT);
754: <script>
755: function makenewfolder(targetform,folderseq) {
756: var foldername=prompt('Name of New Folder','New Folder');
757: if (foldername) {
758: targetform.importdetail.value=foldername+"="+folderseq;
759: targetform.submit();
760: }
761: }
762:
763: function makenewext(targetname) {
764: this.document.forms.extimport.useform.value=targetname;
765: window.open('/adm/rat/extpickframe.html');
766: }
767:
768: function makeexamupload() {
769: var title=prompt('Listed Title for the Uploaded Score');
770: if (title) {
771: this.document.forms.newexamupload.importdetail.value=
772: title+'=/res/lib/templates/examupload.problem';
773: this.document.forms.newexamupload.submit();
774: }
775: }
776:
777: function makesmppage() {
778: var title=prompt('Listed Title for the Page');
779: if (title) {
780: this.document.forms.newsmppg.importdetail.value=
781: title+'=/adm/$udom/$uname/$now/smppg';
782: this.document.forms.newsmppg.submit();
783: }
784: }
785:
786: function makesmpproblem() {
787: var title=prompt('Listed Title for the Problem');
788: if (title) {
789: this.document.forms.newsmpproblem.importdetail.value=
790: title+'=/res/lib/templates/simpleproblem.problem';
791: this.document.forms.newsmpproblem.submit();
792: }
793: }
794:
795: function makebulboard() {
796: var title=prompt('Listed Title for the Bulletin Board');
797: if (title) {
798: this.document.forms.newbul.importdetail.value=
799: title+'=/adm/$udom/$uname/$now/bulletinboard';
800: this.document.forms.newbul.submit();
801: }
802: }
803:
804: function finishpick() {
805: var title=this.document.forms.extimport.title.value;
806: var url=this.document.forms.extimport.url.value;
807: var form=this.document.forms.extimport.useform.value;
808: eval
809: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
810: '";this.document.forms.'+form+'.submit();');
811: }
812:
813: function changename(folder,index,oldtitle) {
814: var title=prompt('New Title',oldtitle);
815: if (title) {
816: this.document.forms.renameform.title.value=title;
817: this.document.forms.renameform.cmd.value='rename_'+index;
818: this.document.forms.renameform.folder.value=folder;
819: this.document.forms.renameform.submit();
820: }
821: }
822:
823: function removeres(folder,index,oldtitle) {
824: if ((oldtitle=='NO RESOURCE') || (confirm('Remove "'+oldtitle+'"?'))) {
825: this.document.forms.renameform.cmd.value='del_'+index;
826: this.document.forms.renameform.folder.value=folder;
827: this.document.forms.renameform.submit();
828: }
829: }
830: </script>
831:
832: ENDNEWSCRIPT
833: }
834: # -------------------------------------------------------------------- Body tag
835: $r->print('</head>'.
836: &Apache::loncommon::bodytag('Course Documents','',$events,
837: '','',$showdoc));
838: unless ($showdoc) {
839: if ($allowed) {
840: my $dumpbut=&dumpbutton();
841: $r->print(<<ENDCOURSEVERIFY);
842: <form name="renameform" method="post" action="/adm/coursedocs">
843: <input type="hidden" name="title" />
844: <input type="hidden" name="cmd" />
845: <input type="hidden" name="folder" />
846: </form>
847: <form name="simpleedit" method="post" action="/adm/coursedocs">
848: <input type=hidden name="importdetail" value="">
849: <input type="hidden" name="folder" />
850: </form>
851: <form action="/adm/coursedocs" method="post" name="courseverify">
852: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
853: <tr><td bgcolor="#DDDDCC">
854: <input type="submit" name="verify" value="Verify Content" />
855: </td><td bgcolor="#DDDDCC">
856: <input type="submit" name="versions" value="Check Resource Versions" />
857: $dumpbut
858: </td></tr></table>
859: </form>
860: ENDCOURSEVERIFY
861: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
862: 'Editing the Table of Contents for your Course'));
863: }
864: # --------------------------------------------------------- Standard documents
865: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
866: if (($standard) && ($allowed) && (!$forcesupplement)) {
867: $r->print('<tr><td bgcolor="#BBBBBB"><h2>Main Course Documents'.
868: ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
869: my $folder=$ENV{'form.folder'};
870: unless ($folder=~/^default/) { $folder='default'; }
871: my $postexec='';
872: if ($folder eq 'default') {
873: $r->print('<script>this.window.name="loncapaclient";</script>');
874: } else {
875: $postexec='self.close();';
876: }
877: $hadchanges=0;
878: &editor($r,$coursenum,$coursedom,$folder,$allowed);
879: if ($hadchanges) {
880: $r->print(
881: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
882: '<form method="post" action="/adm/roles" target="loncapaclient">'.
883: '<input type="hidden" name="orgurl" value="/adm/coursedocs" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">Changes will become active for your current session after <input type="hidden" name="'.
884: $ENV{'request.role'}.'" value="1" /><input type="button" value="re-initializing course" onClick="reinit(this.form)"/>, or the next time you log in.'.
885: $help{'Caching'}.'</font></h3></form>');
886: }
887: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
888: '.sequence';
889:
890: $r->print(<<ENDFORM);
891: <table cellspacing=4 cellpadding=4><tr>
892: <th bgcolor="#DDDDDD">Upload a new main course document</th>
893: <th bgcolor="#DDDDDD">Import a published document</th>
894: <th bgcolor="#DDDDDD">Special documents</th>
895: </tr>
896: <tr><td bgcolor="#DDDDDD">
897: File:<br />
898: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
899: <input type="file" name="uploaddoc" size="40">
900: <br />
901: Title:<br />
902: <input type="text" size="50" name="comment">
903: <input type="hidden" name="folder" value="$folder">
904: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
905: <input type="hidden" name="cmd" value="upload_default">
906: <input type="submit" value="Upload Document">
907: <nobr>
908: $help{'Uploading_From_Harddrive'}
909: </nobr>
910: </form>
911: </td>
912: <td bgcolor="#DDDDDD">
913: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
914: <input type="hidden" name="folder" value="$folder">
915: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
916: <input type=button onClick=
917: "javascript:document.forms.simpleedit.folder.value='$folder';groupsearch()" value="Search">
918: <nobr>
919: <input type=button onClick=
920: "javascript:document.forms.simpleedit.folder.value='$folder';groupimport();" value="Import">
921: $help{'Importing_LON-CAPA_Resource'}
922: </nobr>
923: <p>
924: <hr />
925: <input type="text" size="20" name="importmap"><br />
926: <nobr><input type=button
927: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
928: value="Select Map"> <input type="submit" name="loadmap" value="Load Map">
929: $help{'Load_Map'}</nobr>
930: </p>
931: </form>
932: </td><td bgcolor="#DDDDDD">
933: <form action="/adm/coursedocs" method="post" name="newfolder">
934: <input type="hidden" name="folder" value="$folder">
935: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
936: <input type=hidden name="importdetail" value="">
937: <nobr>
938: <input name="newfolder" type="button"
939: onClick="javascript:makenewfolder(this.form,'$folderseq');"
940: value="New Folder" />$help{'Adding_Folders'}
941: </nobr>
942: </form>
943: <form action="/adm/coursedocs" method="post" name="newext">
944: <input type="hidden" name="folder" value="$folder">
945: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
946: <input type=hidden name="importdetail" value="">
947: <nobr>
948: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
949: value="External Resource" /> $help{'Adding_External_Resource'}
950: </nobr>
951: </form>
952: <form action="/adm/coursedocs" method="post" name="newsyl">
953: <input type="hidden" name="folder" value="$folder">
954: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
955: <input type=hidden name="importdetail"
956: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
957: <nobr>
958: <input name="newsyl" type="submit" value="Syllabus" />
959: $help{'Syllabus'}
960: </nobr>
961: </form>
962: <form action="/adm/coursedocs" method="post" name="newnav">
963: <input type="hidden" name="folder" value="$folder">
964: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
965: <input type=hidden name="importdetail"
966: value="Navigate Content=/adm/navmaps">
967: <nobr>
968: <input name="newnav" type="submit" value="Navigate Content" />
969: $help{'Navigate_Content'}
970: </nobr>
971: </form>
972: <form action="/adm/coursedocs" method="post" name="newsmppg">
973: <input type="hidden" name="folder" value="$folder">
974: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
975: <input type=hidden name="importdetail" value="">
976: <nobr>
977: <input name="newsmppg" type="button" value="Simple Page"
978: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
979: </nobr>
980: </form>
981: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
982: <input type="hidden" name="folder" value="$folder">
983: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
984: <input type=hidden name="importdetail" value="">
985: <nobr>
986: <input name="newsmpproblem" type="button" value="Simple Problem"
987: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
988: </nobr>
989: </form>
990: <form action="/adm/coursedocs" method="post" name="newexamupload">
991: <input type="hidden" name="folder" value="$folder">
992: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
993: <input type=hidden name="importdetail" value="">
994: <nobr>
995: <input name="newexamupload" type="button" value="Score Upload Form"
996: onClick="javascript:makeexamupload();" />
997: $help{'Score_Upload_Form'}
998: </nobr>
999: </form>
1000: <form action="/adm/coursedocs" method="post" name="newbul">
1001: <input type="hidden" name="folder" value="$folder">
1002: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1003: <input type=hidden name="importdetail" value="">
1004: <nobr>
1005: <input name="newbulletin" type="button" value="Bulletin Board"
1006: onClick="javascript:makebulboard();" />
1007: $help{'Bulletin Board'}
1008: </nobr>
1009: </form>
1010: <form action="/adm/coursedocs" method="post" name="newaboutme">
1011: <input type="hidden" name="folder" value="$folder">
1012: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1013: <input type=hidden name="importdetail"
1014: value="$plainname=/adm/$udom/$uname/aboutme">
1015: <nobr>
1016: <input name="newaboutme" type="submit" value="My Personal Info" />
1017: $help{'My Personal Info'}
1018: </nobr>
1019: </form>
1020: </td></tr>
1021: </table>
1022: ENDFORM
1023: $r->print('</td></tr>');
1024: }
1025: # ----------------------------------------------------- Supplemental documents
1026: if (!$forcestandard) {
1027: $r->print(
1028: '<tr><td bgcolor="#BBBBBB"><h2>Supplemental Course Documents'.
1029: ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1030: my $folder=$ENV{'form.folder'};
1031: unless ($folder=~/supplemental/) { $folder='supplemental'; }
1032: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1033: if ($allowed) {
1034: my $folderseq=
1035: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
1036: '.sequence';
1037:
1038: $r->print(<<ENDSUPFORM);
1039: <table cellspacing=4 cellpadding=4><tr>
1040: <th bgcolor="#DDDDDD">Upload a new supplemental course document</th>
1041: <th bgcolor="#DDDDDD">Import a published document</th>
1042: <th bgcolor="#DDDDDD">Special documents</th>
1043: </tr>
1044: <tr><td bgcolor="#DDDDDD">
1045: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1046: <input type="file" name="uploaddoc" size="40">
1047: <br />Comment:<br />
1048: <textarea cols=50 rows=4 name='comment'>
1049: </textarea>
1050: <input type="hidden" name="folder" value="$folder">
1051: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1052: <input type="hidden" name="cmd" value="upload_supplemental">
1053: <nobr>
1054: <input type="submit" value="Upload Document">
1055: $help{'Uploading_From_Harddrive'}
1056: </nobr>
1057: </form>
1058: </td>
1059: <td bgcolor="#DDDDDD">
1060: <form action="/adm/coursedocs" method="post" name="simpleeditsupplement">
1061: <input type="hidden" name="folder" value="$folder">
1062: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1063: <input type=hidden name="importdetail" value="">
1064: <input type=button onClick=
1065: "javascript:document.forms.simpleedit.folder.value='$folder';groupsearch()" value="Search">
1066: <input type=button onClick=
1067: "javascript:document.forms.simpleedit.folder.value='$folder';groupimport();" value="Import">$help{'Importing_LON-CAPA_Resource'}
1068: <p>
1069: <hr />
1070: <input type="text" size="20" name="importmap">
1071: <input type=button
1072: onClick="javascript:openbrowser('simpleeditsupplement','importmap','sequence,page','')"
1073: value="Select Map"><input type="submit" name="loadmap" value="Load Map">
1074: </p>
1075: </form>
1076: </td><td bgcolor="#DDDDDD">
1077: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1078: <input type="hidden" name="folder" value="$folder">
1079: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1080: <input type=hidden name="importdetail" value="">
1081: <nobr>
1082: <input name="newfolder" type="button"
1083: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1084: value="New Folder" /> $help{'Adding_Folders'}
1085: </nobr>
1086: </form>
1087: <form action="/adm/coursedocs" method="post" name="supnewext">
1088: <input type="hidden" name="folder" value="$folder">
1089: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1090: <input type=hidden name="importdetail" value="">
1091: <nobr>
1092: <input name="newext" type="button"
1093: onClick="javascript:makenewext('supnewext');"
1094: value="External Resource" /> $help{'Adding_External_Resource'}
1095: </nobr>
1096: </form>
1097: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1098: <input type="hidden" name="folder" value="$folder">
1099: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1100: <input type=hidden name="importdetail"
1101: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1102: <nobr>
1103: <input name="newsyl" type="submit" value="Syllabus" />
1104: $help{'Syllabus'}
1105: </nobr>
1106: </form>
1107: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1108: <input type="hidden" name="folder" value="$folder">
1109: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1110: <input type=hidden name="importdetail"
1111: value="$plainname=/adm/$udom/$uname/aboutme">
1112: <nobr>
1113: <input name="newaboutme" type="submit" value="My Personal Info" />
1114: $help{'My Personal Info'}
1115: </nobr>
1116: </form>
1117: </td></tr>
1118: </table></td></tr>
1119: ENDSUPFORM
1120: }
1121: }
1122: if ($allowed) {
1123: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
1124: }
1125: $r->print('</table>');
1126: } else {
1127: # -------------------------------------------------------- This is showdoc mode
1128: $r->print("<h1>Uploaded Document</h1><p>It is recommended that you use an up-to-date virus scanner before handling this file.</p><p><table>".
1129: &entryline(0,"Click to download or use your browser's Save Link function",$showdoc).'</table></p>');
1130: }
1131: }
1132: $r->print('</body></html>');
1133: return OK;
1134: }
1135:
1136: 1;
1137: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>