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