Annotation of loncom/interface/londocs.pm, revision 1.53
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.53 ! www 4: # $Id: londocs.pm,v 1.52 2003/04/30 21:09:12 www Exp $
1.1 www 5: #
1.3 www 6: # Copyright Michigan State University Board of Trustees
1.1 www 7: #
1.3 www 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
1.1 www 9: #
1.3 www 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.
1.1 www 14: #
1.3 www 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:
1.2 www 29: package Apache::londocs;
1.1 www 30:
31: use strict;
1.28 www 32: use Apache::Constants qw(:common :http);
1.4 www 33: use Apache::lonnet;
34: use Apache::loncommon;
1.7 www 35: use Apache::lonratedt;
36: use Apache::lonratsrv;
1.15 www 37: use Apache::lonxml;
1.38 www 38: use HTML::Entities;
1.27 www 39: use GDBM_File;
1.7 www 40:
1.8 www 41: my $iconpath;
1.7 www 42:
1.27 www 43: my %hash;
44:
45: my $hashtied;
1.29 www 46: my %alreadyseen=();
1.27 www 47:
1.40 www 48: my $hadchanges;
49:
1.47 www 50: # Available help topics
51:
52: my %help=();
53:
1.7 www 54: # Mapread read maps into lonratedt::global arrays
1.10 www 55: # @order and @resources, determines status
1.7 www 56: # sets @order - pointer to resources in right order
57: # sets @resources - array with the resources with correct idx
58: #
59:
60: sub mapread {
61: my ($coursenum,$coursedom,$map)=@_;
62: return
63: &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
64: $map);
65: }
66:
67: sub storemap {
68: my ($coursenum,$coursedom,$map)=@_;
1.40 www 69: $hadchanges=1;
1.7 www 70: return
71: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.15 www 72: $map,1);
1.7 www 73: }
74:
75: sub editor {
76: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
1.17 www 77: if ($ENV{'form.foldername'}) {
78: $r->print('<h3>Folder: '.$ENV{'form.foldername'}.'</h3>');
79: }
1.10 www 80: my $errtext='';
81: my $fatal=0;
82: ($errtext,$fatal)=
1.7 www 83: &mapread($coursenum,$coursedom,$folder.'.sequence');
1.17 www 84: if ($#Apache::lonratedt::order<1) {
85: $Apache::lonratedt::order[0]=1;
86: $Apache::lonratedt::resources[1]='';
87: }
1.7 www 88: if ($fatal) {
89: $r->print('<p><font color="red">'.$errtext.'</font></p>');
90: } else {
91: # ------------------------------------------------------------ Process commands
1.16 www 92: # ---------------- if they are for this folder and user allowed to make changes
93: if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
1.10 www 94: # upload a file, if present
95: if (($ENV{'form.uploaddoc.filename'}) &&
96: ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
97: if ($folder=~/^$1/) {
98: # this is for a course, not a user, so set coursedoc flag
99: # probably the only place in the system where this should be "1"
100: my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
101: my $ext='false';
102: if ($url=~/^http\:\/\//) { $ext='true'; }
103: $url=~s/\:/\:/g;
104: my $comment=$ENV{'form.comment'};
105: $comment=~s/\</\<\;/g;
106: $comment=~s/\>/\>\;/g;
107: $comment=~s/\:/\:/g;
1.17 www 108: if ($folder=~/^supplemental/) {
109: $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
110: $ENV{'user.domain'}.'___&&&___'.$comment;
111: }
1.10 www 112: my $newidx=$#Apache::lonratedt::resources+1;
113: $Apache::lonratedt::resources[$newidx]=
114: $comment.':'.$url.':'.$ext.':normal:res';
115: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
116: $newidx;
117: &storemap($coursenum,$coursedom,$folder.'.sequence');
118: }
119: }
1.8 www 120: if ($ENV{'form.cmd'}) {
1.10 www 121: my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
122: if ($cmd eq 'del') {
123: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
124: $Apache::lonratedt::order[$i]=
125: $Apache::lonratedt::order[$i+1];
126: }
127: $#Apache::lonratedt::order--;
128: } elsif ($cmd eq 'up') {
1.38 www 129: if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
1.10 www 130: my $i=$Apache::lonratedt::order[$idx-1];
131: $Apache::lonratedt::order[$idx-1]=
132: $Apache::lonratedt::order[$idx];
133: $Apache::lonratedt::order[$idx]=$i;
1.38 www 134: }
1.10 www 135: } elsif ($cmd eq 'down') {
1.38 www 136: if (defined($Apache::lonratedt::order[$idx+1])) {
1.10 www 137: my $i=$Apache::lonratedt::order[$idx+1];
138: $Apache::lonratedt::order[$idx+1]=
139: $Apache::lonratedt::order[$idx];
140: $Apache::lonratedt::order[$idx]=$i;
1.38 www 141: }
1.36 www 142: } elsif ($cmd eq 'rename') {
143: my ($rtitle,@rrest)=split(/\:/,
144: $Apache::lonratedt::resources[
145: $Apache::lonratedt::order[$idx]]);
1.38 www 146: my $comment=
147: &HTML::Entities::decode($ENV{'form.title'});
1.36 www 148: $comment=~s/\</\<\;/g;
149: $comment=~s/\>/\>\;/g;
150: $comment=~s/\:/\:/g;
151: $Apache::lonratedt::resources[
152: $Apache::lonratedt::order[$idx]]=
153: $comment.':'.join(':',@rrest);
154:
1.10 www 155: }
156: # Store the changed version
157: &storemap($coursenum,$coursedom,$folder.'.sequence');
1.8 www 158: }
1.11 www 159: # Group import/search
160: if ($ENV{'form.importdetail'}) {
161: foreach (split(/\&/,$ENV{'form.importdetail'})) {
162: if (defined($_)) {
163: my ($name,$url)=split(/\=/,$_);
164: $name=&Apache::lonnet::unescape($name);
165: $url=&Apache::lonnet::unescape($url);
166: if ($url) {
167: my $idx=$#Apache::lonratedt::resources+1;
168: $Apache::lonratedt::order
169: [$#Apache::lonratedt::order+1]=$idx;
170: my $ext='false';
171: if ($url=~/^http\:\/\//) { $ext='true'; }
172: $url=~s/\:/\:/g;
1.46 www 173: $name=~s/\:/\:/g;
1.11 www 174: $Apache::lonratedt::resources[$idx]=
175: $name.':'.$url.':'.$ext.':normal:res';
176: }
177: }
178: }
179: # Store the changed version
180: &storemap($coursenum,$coursedom,$folder.'.sequence');
181: }
1.53 ! www 182: # Loading a complete map
! 183: if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
! 184: foreach
! 185: (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
! 186: my $idx=$#Apache::lonratedt::resources;
! 187: $idx++;
! 188: $Apache::lonratedt::resources[$idx]=$_;
! 189: $Apache::lonratedt::order
! 190: [$#Apache::lonratedt::order+1]=$idx;
! 191: }
! 192:
! 193: # Store the changed version
! 194: &storemap($coursenum,$coursedom,$folder.'.sequence');
! 195: }
1.16 www 196: }
197: # ---------------------------------------------------------------- End commands
1.7 www 198: # ---------------------------------------------------------------- Print screen
1.10 www 199: my $idx=0;
200: $r->print('<table>');
201: foreach (@Apache::lonratedt::order) {
202: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
203: unless ($name) { $name=(split(/\//,$url))[-1]; }
1.37 www 204: unless ($name) { $name='NO RESOURCE'; $url='/adm/notfound.html'; }
1.50 www 205: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_));
1.10 www 206: $idx++;
207: }
208: $r->print('</table>');
1.7 www 209: }
210: }
1.1 www 211:
1.8 www 212: # --------------------------------------------------------------- An entry line
213:
214: sub entryline {
1.50 www 215: my ($index,$title,$url,$folder,$allowed,$residx)=@_;
1.38 www 216: $title=~s/\&colon\;/\:/g;
217: $title=&HTML::Entities::encode(&HTML::Entities::decode(
218: &Apache::lonnet::unescape($title)),'\"\<\>\&\'');
219: my $renametitle=$title;
220: my $foldertitle=$title;
221: if ($title=~
222: /^(\d+)\_\_\_\&\;\&\;\&\;\_\_\_(\w+)\_\_\_\&\;\&\;\&\;\_\_\_(\w+)\_\_\_\&\;\&\;\&\;\_\_\_(.*)$/
223: ) {
224: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
225: $renametitle=$4;
226: $title='<i>'.localtime($1).'</i> '.
227: &Apache::loncommon::plainname($2,$3).': <br>'.
228: $foldertitle;
229: }
230: $renametitle=~s/\"\;/\\\"/g;
1.8 www 231: my $line='<tr>';
232: # Edit commands
233: if ($allowed) {
234: $line.=(<<END);
235: <td><table border='0' cellspacing='0' cellpadding='0'>
236: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
237: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
238: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
239: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
240: </table></td><td>
1.36 www 241: <a href='/adm/coursedocs?folder=$folder&cmd=del_$index'>
242: <font size="-2">Remove</font></a>
1.38 www 243: <a href='javascript:changename("$folder","$index","$renametitle");'>
1.36 www 244: <font size="-2">Rename</font></a></td>
1.8 www 245: END
246: }
1.16 www 247: # Figure out what kind of a resource this is
248: my ($extension)=($url=~/\.(\w+)$/);
249: my $uploaded=($url=~/^\/*uploaded\//);
250: my $icon='unknown';
251: if (-e "/home/httpd/html/adm/lonIcons/$extension.gif") {
252: $icon=$extension;
1.10 www 253: }
1.17 www 254: my $isfolder=0;
1.16 www 255: if ($uploaded) {
256: if ($extension eq 'sequence') {
257: $icon='folder_closed';
258: $url=~/\/(\w+)\.sequence/;
259: $url='/adm/coursedocs?folder='.$1;
1.17 www 260: $isfolder=1;
1.16 www 261: } else {
262: $url=&Apache::lonnet::tokenwrapper($url);
263: }
264: }
1.18 www 265: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
1.50 www 266: if ($residx) {
267: $url.=(($url=~/\?/)?'&':'?').'symb='.
268: &Apache::lonnet::escape(&Apache::lonnet::symbclean(
269: &Apache::lonnet::declutter('uploaded/'.
270: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
271: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
272: '.sequence').
273: '___'.$residx.'___'.
274: &Apache::lonnet::declutter($url)));
275: }
1.48 www 276: if ($isfolder) { $url.='&foldername='.
277: &Apache::lonnet::escape($foldertitle); }
1.23 www 278: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'" target="cat_'.$folder.
279: '"><img src="/adm/lonIcons/'.
1.17 www 280: $icon.'.gif" border="0"></a></td>'.
1.23 www 281: "<td bgcolor='#FFFFBB'><a href='$url' target='cat_$folder'>$title</a></td></tr>";
1.8 www 282: return $line;
283: }
284:
1.27 www 285: # ---------------------------------------------------------------- tie the hash
286:
287: sub tiehash {
288: $hashtied=0;
289: if ($ENV{'request.course.fn'}) {
290: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
291: &GDBM_READER(),0640)) {
292: $hashtied=1;
293: }
294: }
295: }
296:
297: sub untiehash {
298: if ($hashtied) { untie %hash; }
299: $hashtied=0;
300: }
301:
1.29 www 302: # --------------------------------------------------------------- check on this
303:
304: sub checkonthis {
305: my ($r,$url,$level,$title)=@_;
306: $alreadyseen{$url}=1;
307: $r->rflush();
1.41 www 308: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1.29 www 309: $r->print('<br />');
310: for (my $i=0;$i<=$level*5;$i++) {
311: $r->print(' ');
312: }
313: $r->print('<a href="'.$url.'" target="cat">'.
314: ($title?$title:$url).'</a> ');
315: if ($url=~/^\/res\//) {
316: my $result=&Apache::lonnet::repcopy(
317: &Apache::lonnet::filelocation('',$url));
318: if ($result==OK) {
319: $r->print('<font color="green">ok</font>');
320: $r->rflush();
1.34 www 321: &Apache::lonnet::countacc($url);
322: $url=~/\.(\w+)$/;
323: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
324: $r->print('<br />');
325: $r->rflush();
326: for (my $i=0;$i<=$level*5;$i++) {
327: $r->print(' ');
328: }
329: $r->print('- Rendering: ');
330: &Apache::lonxml::xmlparse($r,'web',
331: &Apache::lonnet::getfile(
1.35 albertel 332: &Apache::lonnet::filelocation('',$url)));
1.34 www 333: if (($Apache::lonxml::errorcount) ||
334: ($Apache::lonxml::warningcount)) {
335: if ($Apache::lonxml::errorcount) {
336: $r->print('<font color="red"><b>'.
337: $Apache::lonxml::errorcount.' error(s)</b></font> ');
338: }
339: if ($Apache::lonxml::warningcount) {
340: $r->print('<font color="blue">'.
341: $Apache::lonxml::warningcount.' warning(s)</font>');
342: }
343: } else {
344: $r->print('<font color="green">ok</font>');
345: }
346: $r->rflush();
347: }
1.29 www 348: my $dependencies=
349: &Apache::lonnet::metadata($url,'dependencies');
350: foreach (split(/\,/,$dependencies)) {
351: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
352: &checkonthis($r,$_,$level+1);
353: }
354: }
355: } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
356: $r->print('<font color="red"><b>connection down</b></font>');
357: } elsif ($result==HTTP_NOT_FOUND) {
358: $r->print('<font color="red"><b>not found</b></font>');
359: } else {
360: $r->print('<font color="red"><b>access denied</b></font>');
361: }
362: }
363: }
364: }
365:
1.8 www 366: # ================================================================ Main Handler
1.1 www 367: sub handler {
368: my $r = shift;
369: $r->content_type('text/html');
370: $r->send_http_header;
371: return OK if $r->header_only;
372:
1.47 www 373: # --------------------------------------------- Initialize help topics for this
374: foreach ('Adding_Course_Doc','Main_Course_Documents',
375: 'Adding_External_Resource','Navigate_Content',
376: 'Adding_Folders','Docs_Overview',
377: 'Creating_From_Template','Supplemental',
378: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive') {
379: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
380: }
381:
1.26 www 382: if ($ENV{'form.verify'}) {
383:
384: my $loaderror=&Apache::lonnet::overloaderror($r);
385: if ($loaderror) { return $loaderror; }
386:
387: $r->print('<html><head><title>Verify Content</title></head>'.
388: &Apache::loncommon::bodytag('Verify Course Documents'));
1.27 www 389: $hashtied=0;
1.30 www 390: undef %alreadyseen;
391: %alreadyseen=();
1.27 www 392: &tiehash();
393: foreach (keys %hash) {
1.28 www 394: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
1.29 www 395: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27 www 396: }
397: }
398: &untiehash();
1.26 www 399: } elsif ($ENV{'form.versions'}) {
400: $r->print('<html><head><title>Check Versions</title></head>'.
401: &Apache::loncommon::bodytag('Check Course Document Versions'));
1.27 www 402: $hashtied=0;
403: &tiehash();
1.30 www 404: my %changes=&Apache::lonnet::dump
405: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
406: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.31 www 407: my $firstkey=(keys %changes)[0];
408: unless ($firstkey=~/^error\:/) {
409: unless ($ENV{'form.timerange'}) {
410: $ENV{'form.timerange'}=604800;
411: }
412: my $seltext='during the last '.$ENV{'form.timerange'}.' seconds';
413: my $startsel='';
414: my $monthsel='';
415: my $weeksel='';
416: my $daysel='';
417: if ($ENV{'form.timerange'}==-1) {
418: $seltext='since start of course';
419: $startsel='selected';
1.32 www 420: $ENV{'form.timerange'}=time;
421: }
422: my $starttime=time-$ENV{'form.timerange'};
423: if ($ENV{'form.timerange'}==2592000) {
424: $seltext='during the last month ('.localtime($starttime).')';
1.31 www 425: $monthsel='selected';
426: } elsif ($ENV{'form.timerange'}==604800) {
1.32 www 427: $seltext='during the last week ('.localtime($starttime).')';
1.31 www 428: $weeksel='selected';
429: } elsif ($ENV{'form.timerange'}==86400) {
1.32 www 430: $seltext='since yesterday ('.localtime($starttime).')';
1.31 www 431: $daysel='selected';
432: }
1.32 www 433:
1.31 www 434: $r->print(<<ENDHEADERS);
435: <form action="/adm/coursedocs" method="post">
436: <select name="timerange">
437: <option value="-1" $startsel>Since Start of Course</option>
438: <option value="2592000" $monthsel>Last Month</option>
439: <option value="604800" $weeksel>Last Week</option>
440: <option value="86400" $daysel>Since Yesterday</option>
441: </select>
442: <input type="submit" name="versions" value="Display" />
443: </form>
1.32 www 444: <h3>Content changed $seltext</h3>
1.31 www 445: <table border="2">
446: <tr>
447: <th>File</th><th>Modification Date</th>
448: <th>Version</th><th>Differences</th></tr>
449: ENDHEADERS
450: foreach (keys %changes) {
1.32 www 451: if ($changes{$_}>$starttime) {
452: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
453: my $currentversion=&Apache::lonnet::getversion($_);
454: my $linkurl=&Apache::lonnet::clutter($_);
455: $r->print(
456: '<tr><td><a href="'.$linkurl.'" target="cat">'.$linkurl.
457: '</a></td><td>'.
458: localtime($changes{$_}).'</td><td>'.$currentversion.'</td>'.
459: '<td>');
460: my $lastold=1;
461: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
462: my $url=$root.'.'.$prevvers.'.'.$extension;
463: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
464: $starttime) {
465: $lastold=$prevvers;
466: }
467: }
468: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
469: my $url=$root.'.'.$prevvers.'.'.$extension;
470: $r->print('<a href="'.&Apache::lonnet::clutter($url).
471: '">Version '.$prevvers.' ('.
472: localtime(&Apache::lonnet::metadata($url,'lastrevisiondate')).
1.33 www 473: ')</a>');
474: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
475: $r->print(' <a href="/adm/diff?filename='.
476: &Apache::lonnet::clutter($root.'.'.$extension).
477: '&versionone='.$prevvers.
478: '">Diffs</a>');
479: }
480: $r->print('<br />');
1.32 www 481: }
482: $r->print('</td></tr>');
483: }
1.31 www 484: }
485: $r->print('</table>');
486: } else {
487: $r->print('<p>No content modifications yet.</p>');
1.30 www 488: }
1.27 www 489: &untiehash();
1.26 www 490: } else {
1.7 www 491: # is this a standard course?
492:
493: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1.15 www 494: my $forcestandard;
495: my $forcesupplement;
496: my $script='';
497: my $allowed;
498: my $events='';
1.49 www 499: my $buttons='';
1.19 www 500: my $showdoc=0;
1.15 www 501: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.21 www 502: ['folder','foldername']);
503: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
504: $showdoc=$1;
505: }
506: unless ($showdoc) { # got called from remote
1.15 www 507: $forcestandard=($ENV{'form.folder'}=~/^default_/);
508: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1.7 www 509:
1.4 www 510: # does this user have privileges to post, etc?
1.15 www 511: $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
512: if ($allowed) {
513: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
514: $script=&Apache::lonratedt::editscript('simple');
515: }
516: } else { # got called in sequence from course
517: $allowed=0;
1.49 www 518: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
519: $events='onLoad="'.&Apache::lonmenu::loadevents.
520: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
521: $buttons=&Apache::lonmenu::menubuttons(1,undef);
1.3 www 522: }
1.4 www 523:
524: # get course data
525: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
526: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
527:
1.14 www 528: # get personal data
529:
530: my $uname=$ENV{'user.name'};
531: my $udom=$ENV{'user.domain'};
532: my $plainname=&Apache::lonnet::escape(
533: &Apache::loncommon::plainname($uname,$udom));
534:
1.8 www 535: # graphics settings
1.4 www 536:
1.8 www 537: $iconpath = $r->dir_config('lonIconsURL') . "/";
538:
1.22 www 539: my $now=time;
540:
1.4 www 541: # print screen
1.1 www 542: $r->print(<<ENDDOCUMENT);
543: <html>
544: <head>
545: <title>The LearningOnline Network with CAPA</title>
1.16 www 546: <script>
547: $script
1.20 www 548: </script>
1.19 www 549: ENDDOCUMENT
550: if ($allowed) {
551: $r->print(<<ENDNEWSCRIPT);
1.20 www 552: <script>
1.16 www 553: function makenewfolder(targetform,folderseq) {
554: var foldername=prompt('Name of New Folder','New Folder');
555: if (foldername) {
556: targetform.importdetail.value=foldername+"="+folderseq;
557: targetform.submit();
558: }
559: }
560:
1.18 www 561: function makenewext(targetname) {
562: this.document.forms.extimport.useform.value=targetname;
563: window.open('/adm/rat/extpickframe.html');
564: }
565:
1.22 www 566: function makesmppage() {
1.38 www 567: var title=prompt('Listed Title for the Page');
568: if (title) {
1.22 www 569: this.document.forms.newsmppg.importdetail.value=
570: title+'=/adm/$udom/$uname/$now/smppg';
571: this.document.forms.newsmppg.submit();
1.38 www 572: }
1.22 www 573: }
574:
575: function makebulboard() {
1.38 www 576: var title=prompt('Listed Title for the Bulletin Board');
577: if (title) {
1.22 www 578: this.document.forms.newbul.importdetail.value=
579: title+'=/adm/$udom/$uname/$now/bulletinboard';
580: this.document.forms.newbul.submit();
1.38 www 581: }
1.22 www 582: }
583:
1.18 www 584: function finishpick() {
585: var title=this.document.forms.extimport.title.value;
586: var url=this.document.forms.extimport.url.value;
587: var form=this.document.forms.extimport.useform.value;
588: eval
589: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
590: '";this.document.forms.'+form+'.submit();');
1.16 www 591: }
1.36 www 592:
593: function changename(folder,index,oldtitle) {
594: var title=prompt('New Title',oldtitle);
595: if (title) {
596: this.document.forms.renameform.title.value=title;
597: this.document.forms.renameform.cmd.value='rename_'+index;
598: this.document.forms.renameform.folder.value=folder;
599: this.document.forms.renameform.submit();
600: }
601: }
1.16 www 602: </script>
1.42 www 603:
604: ENDNEWSCRIPT
605: }
606: # -------------------------------------------------------------------- Body tag
607: $r->print('</head>'.
1.49 www 608: &Apache::loncommon::bodytag('Course Documents','',$events).
609: $buttons);
1.42 www 610: unless ($showdoc) {
611: if ($allowed) {
1.47 www 612: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
613: 'Editing the Table of Contents for your Course'));
1.42 www 614: $r->print(<<ENDCOURSEVERIFY);
1.36 www 615: <form name="renameform" method="post" action="/adm/coursedocs">
616: <input type="hidden" name="title" />
617: <input type="hidden" name="cmd" />
618: <input type="hidden" name="folder" />
619: </form>
1.39 www 620: <form name="simpleedit" method="post" action="/adm/coursedocs">
621: <input type=hidden name="importdetail" value="">
622: <input type="hidden" name="folder" />
623: </form>
1.26 www 624: <form action="/adm/coursedocs" method="post" name="courseverify">
1.25 www 625: <input type="submit" name="verify" value="Verify Content" />
626: <input type="submit" name="versions" value="Check Resource Versions" />
627: </form>
628: ENDCOURSEVERIFY
629: }
1.17 www 630: # --------------------------------------------------------- Standard documents
1.43 www 631: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1.7 www 632: if (($standard) && ($allowed) && (!$forcesupplement)) {
1.47 www 633: $r->print('<tr><td bgcolor="#BBBBBB"><h2>Main Course Documents'.
634: ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1.7 www 635: my $folder=$ENV{'form.folder'};
1.10 www 636: unless ($folder=~/^default/) { $folder='default'; }
1.51 www 637: my $postexec='';
638: if ($folder eq 'default') {
639: $r->print('<script>this.window.name="loncapaclient";</script>');
640: } else {
641: $postexec='self.close();';
642: }
1.40 www 643: $hadchanges=0;
1.7 www 644: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.40 www 645: if ($hadchanges) {
1.51 www 646: $r->print(
647: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
648: '<form method="post" action="/adm/roles" target="loncapaclient">'.
649: '<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="'.
650: $ENV{'request.role'}.'" value="1" /><input type="button" value="re-initializing course" onClick="reinit(this.form)"/>, or the next time you log in.</font></h3></form>');
1.40 www 651: }
1.16 www 652: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
653: '.sequence';
1.47 www 654:
1.8 www 655: $r->print(<<ENDFORM);
1.43 www 656: <table cellspacing=4 cellpadding=4><tr>
1.16 www 657: <th bgcolor="#DDDDDD">Upload a new main course document</th>
658: <th bgcolor="#DDDDDD">Import a published document</th>
659: <th bgcolor="#DDDDDD">Special documents</th>
1.11 www 660: </tr>
1.16 www 661: <tr><td bgcolor="#DDDDDD">
1.11 www 662: File:<br />
1.10 www 663: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.8 www 664: <input type="file" name="uploaddoc" size="50">
665: <br />
1.11 www 666: Title:<br />
667: <input type="text" size="50" name="comment">
1.8 www 668: <input type="hidden" name="folder" value="$folder">
1.17 www 669: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.10 www 670: <input type="hidden" name="cmd" value="upload_default">
1.8 www 671: <input type="submit" value="Upload Document">
1.47 www 672: $help{'Uploading_From_Harddrive'}</form>
1.11 www 673: </td>
1.16 www 674: <td bgcolor="#DDDDDD">
1.39 www 675: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.53 ! www 676: <input type="hidden" name="folder" value="$folder">
! 677: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.11 www 678: <input type=button onClick=
1.39 www 679: "javascript:document.forms.simpleedit.folder.value='$folder';groupsearch()" value="Search">
1.11 www 680: <input type=button onClick=
1.39 www 681: "javascript:document.forms.simpleedit.folder.value='$folder';groupimport();" value="Import">
1.52 www 682: $help{'Importing_LON-CAPA_Resource'}<br />
683: <input type="text" size="20" name="importmap">
684: <input type=button
685: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
686: value="Browse"><input type="submit" name="loadmap" value="Load Map">
687: </form>
1.16 www 688: </td><td bgcolor="#DDDDDD">
1.11 www 689: <form action="/adm/coursedocs" method="post" name="newfolder">
1.16 www 690: <input type="hidden" name="folder" value="$folder">
1.17 www 691: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.13 www 692: <input type=hidden name="importdetail" value="">
1.16 www 693: <input name="newfolder" type="button"
694: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.47 www 695: value="New Folder" /> $help{'Adding_Folders'}
1.11 www 696: </form>
697: <form action="/adm/coursedocs" method="post" name="newext">
1.16 www 698: <input type="hidden" name="folder" value="$folder">
1.17 www 699: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.13 www 700: <input type=hidden name="importdetail" value="">
1.18 www 701: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
1.47 www 702: value="External Resource" /> $help{'Adding_External_Resource'}
1.11 www 703: </form>
704: <form action="/adm/coursedocs" method="post" name="newsyl">
1.16 www 705: <input type="hidden" name="folder" value="$folder">
1.17 www 706: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.14 www 707: <input type=hidden name="importdetail"
708: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.47 www 709: <input name="newsyl" type="submit" value="Syllabus" />
710: $help{'Creating_From_Template'}</form>
1.17 www 711: <form action="/adm/coursedocs" method="post" name="newnav">
1.20 www 712: <input type="hidden" name="folder" value="$folder">
713: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.15 www 714: <input type=hidden name="importdetail"
715: value="Navigate Content=/adm/navmaps">
1.20 www 716: <input name="newnav" type="submit" value="Navigate Content" />
1.47 www 717: $help{'Navigate_Content'}
1.22 www 718: </form>
719: <form action="/adm/coursedocs" method="post" name="newsmppg">
720: <input type="hidden" name="folder" value="$folder">
721: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
722: <input type=hidden name="importdetail" value="">
723: <input name="newsmppg" type="button" value="Simple Page"
1.47 www 724: onClick="javascript:makesmppage();" /> $help{'Creating_From_Template'}
1.22 www 725: </form>
726: <form action="/adm/coursedocs" method="post" name="newbul">
727: <input type="hidden" name="folder" value="$folder">
728: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
729: <input type=hidden name="importdetail" value="">
730: <input name="newbulletin" type="button" value="Bulletin Board"
731: onClick="javascript:makebulboard();" />
1.47 www 732: $help{'Creating_From_Template'}</form>
1.12 www 733: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.16 www 734: <input type="hidden" name="folder" value="$folder">
1.17 www 735: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.14 www 736: <input type=hidden name="importdetail"
737: value="$plainname=/adm/$udom/$uname/aboutme">
1.16 www 738: <input name="newaboutme" type="submit" value="My Personal Info" />
1.47 www 739: $help{'Creating_From_Template'}</form>
1.11 www 740: </td></tr>
741: </table>
1.8 www 742: ENDFORM
1.24 www 743: $r->print('</td></tr>');
1.7 www 744: }
745: # ----------------------------------------------------- Supplemental documents
746: if (!$forcestandard) {
1.24 www 747: $r->print(
1.47 www 748: '<tr><td bgcolor="#BBBBBB"><h2>Supplemental Course Documents'.
749: ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1.7 www 750: my $folder=$ENV{'form.folder'};
1.10 www 751: unless ($folder=~/supplemental/) { $folder='supplemental'; }
1.7 www 752: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 www 753: if ($allowed) {
1.17 www 754: my $folderseq=
755: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
756: '.sequence';
757:
1.8 www 758: $r->print(<<ENDSUPFORM);
1.43 www 759: <table cellspacing=4 cellpadding=4><tr>
1.17 www 760: <th bgcolor="#DDDDDD">Upload a new supplemental course document</th>
761: <th bgcolor="#DDDDDD">Import a published document</th>
762: <th bgcolor="#DDDDDD">Special documents</th>
763: </tr>
764: <tr><td bgcolor="#DDDDDD">
1.10 www 765: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.4 www 766: <input type="file" name="uploaddoc" size="50">
767: <br />Comment:<br />
768: <textarea cols=50 rows=4 name='comment'>
769: </textarea>
1.8 www 770: <input type="hidden" name="folder" value="$folder">
1.17 www 771: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.10 www 772: <input type="hidden" name="cmd" value="upload_supplemental">
1.3 www 773: <input type="submit" value="Upload Document">
1.47 www 774: $help{'Uploading_From_Harddrive'}</form>
1.17 www 775: </td>
776: <td bgcolor="#DDDDDD">
1.39 www 777: <form action="/adm/coursedocs" method="post" name="simpleeditsupplement">
1.53 ! www 778: <input type="hidden" name="folder" value="$folder">
! 779: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.17 www 780: <input type=hidden name="importdetail" value="">
781: <input type=button onClick=
1.39 www 782: "javascript:document.forms.simpleedit.folder.value='$folder';groupsearch()" value="Search">
1.17 www 783: <input type=button onClick=
1.47 www 784: "javascript:document.forms.simpleedit.folder.value='$folder';groupimport();" value="Import">$help{'Importing_LON-CAPA_Resource'}
1.53 ! www 785: <br />
! 786: <input type="text" size="20" name="importmap">
! 787: <input type=button
! 788: onClick="javascript:openbrowser('simpleeditsupplement','importmap','sequence,page','')"
! 789: value="Browse"><input type="submit" name="loadmap" value="Load Map">
1.17 www 790: </form>
791: </td><td bgcolor="#DDDDDD">
1.18 www 792: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.17 www 793: <input type="hidden" name="folder" value="$folder">
794: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
795: <input type=hidden name="importdetail" value="">
796: <input name="newfolder" type="button"
797: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.47 www 798: value="New Folder" /> $help{'Adding_Folders'}
1.17 www 799: </form>
1.18 www 800: <form action="/adm/coursedocs" method="post" name="supnewext">
1.17 www 801: <input type="hidden" name="folder" value="$folder">
802: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
803: <input type=hidden name="importdetail" value="">
1.18 www 804: <input name="newext" type="button"
805: onClick="javascript:makenewext('supnewext');"
1.47 www 806: value="External Resource" /> $help{'Adding_External_Resource'}
1.17 www 807: </form>
1.18 www 808: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.17 www 809: <input type="hidden" name="folder" value="$folder">
810: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
811: <input type=hidden name="importdetail"
812: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
813: <input name="newsyl" type="submit" value="Syllabus" />
1.47 www 814: $help{'Creating_From_Template'}</form>
1.18 www 815: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.17 www 816: <input type="hidden" name="folder" value="$folder">
817: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
818: <input type=hidden name="importdetail"
819: value="$plainname=/adm/$udom/$uname/aboutme">
820: <input name="newaboutme" type="submit" value="My Personal Info" />
1.47 www 821: $help{'Creating_From_Template'}</form>
1.17 www 822: </td></tr>
1.24 www 823: </table></td></tr>
1.8 www 824: ENDSUPFORM
825: }
1.7 www 826: }
1.18 www 827: if ($allowed) {
828: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
829: }
1.24 www 830: $r->print('</table>');
1.19 www 831: } else {
832: # -------------------------------------------------------- This is showdoc mode
833: $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>".
1.21 www 834: &entryline(0,"Click to download or use your browser's Save Link function",$showdoc).'</table></p>');
1.19 www 835: }
1.26 www 836: }
837: $r->print('</body></html>');
838: return OK;
1.1 www 839: }
840:
841: 1;
842: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>