Annotation of loncom/interface/londocs.pm, revision 1.70
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.70 ! www 4: # $Id: londocs.pm,v 1.69 2003/07/22 19:39:58 albertel 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);
1.54 www 235: <td><table border='0' cellspacing='2' cellpadding='0'>
236: <tr><td bgcolor="#DDDDDD">
237: <a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
1.8 www 238: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
1.54 www 239: <tr><td bgcolor="#DDDDDD">
240: <a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
1.8 www 241: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
1.54 www 242: </table></td><td bgcolor="#DDDDDD">
243: <a href='javascript:removeres("$folder","$index","$renametitle");'>
244: <font size="-2" color="#990000">Remove</font></a>
1.38 www 245: <a href='javascript:changename("$folder","$index","$renametitle");'>
1.54 www 246: <font size="-2" color="#009900">Rename</font></a></td>
1.8 www 247: END
248: }
1.16 www 249: # Figure out what kind of a resource this is
250: my ($extension)=($url=~/\.(\w+)$/);
251: my $uploaded=($url=~/^\/*uploaded\//);
252: my $icon='unknown';
253: if (-e "/home/httpd/html/adm/lonIcons/$extension.gif") {
254: $icon=$extension;
1.10 www 255: }
1.17 www 256: my $isfolder=0;
1.16 www 257: if ($uploaded) {
258: if ($extension eq 'sequence') {
259: $icon='folder_closed';
260: $url=~/\/(\w+)\.sequence/;
261: $url='/adm/coursedocs?folder='.$1;
1.17 www 262: $isfolder=1;
1.16 www 263: } else {
264: $url=&Apache::lonnet::tokenwrapper($url);
265: }
266: }
1.18 www 267: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
1.50 www 268: if ($residx) {
269: $url.=(($url=~/\?/)?'&':'?').'symb='.
270: &Apache::lonnet::escape(&Apache::lonnet::symbclean(
271: &Apache::lonnet::declutter('uploaded/'.
272: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
273: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
274: '.sequence').
275: '___'.$residx.'___'.
276: &Apache::lonnet::declutter($url)));
277: }
1.48 www 278: if ($isfolder) { $url.='&foldername='.
279: &Apache::lonnet::escape($foldertitle); }
1.23 www 280: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'" target="cat_'.$folder.
281: '"><img src="/adm/lonIcons/'.
1.17 www 282: $icon.'.gif" border="0"></a></td>'.
1.23 www 283: "<td bgcolor='#FFFFBB'><a href='$url' target='cat_$folder'>$title</a></td></tr>";
1.8 www 284: return $line;
285: }
286:
1.27 www 287: # ---------------------------------------------------------------- tie the hash
288:
289: sub tiehash {
290: $hashtied=0;
291: if ($ENV{'request.course.fn'}) {
292: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
293: &GDBM_READER(),0640)) {
294: $hashtied=1;
295: }
296: }
297: }
298:
299: sub untiehash {
300: if ($hashtied) { untie %hash; }
301: $hashtied=0;
302: }
303:
1.29 www 304: # --------------------------------------------------------------- check on this
305:
306: sub checkonthis {
307: my ($r,$url,$level,$title)=@_;
308: $alreadyseen{$url}=1;
309: $r->rflush();
1.41 www 310: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1.29 www 311: $r->print('<br />');
312: for (my $i=0;$i<=$level*5;$i++) {
313: $r->print(' ');
314: }
315: $r->print('<a href="'.$url.'" target="cat">'.
316: ($title?$title:$url).'</a> ');
317: if ($url=~/^\/res\//) {
318: my $result=&Apache::lonnet::repcopy(
319: &Apache::lonnet::filelocation('',$url));
320: if ($result==OK) {
321: $r->print('<font color="green">ok</font>');
322: $r->rflush();
1.34 www 323: &Apache::lonnet::countacc($url);
324: $url=~/\.(\w+)$/;
325: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
326: $r->print('<br />');
327: $r->rflush();
328: for (my $i=0;$i<=$level*5;$i++) {
329: $r->print(' ');
330: }
331: $r->print('- Rendering: ');
1.69 albertel 332: my $oldpath=$ENV{'request.filename'};
333: $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
1.34 www 334: &Apache::lonxml::xmlparse($r,'web',
335: &Apache::lonnet::getfile(
1.35 albertel 336: &Apache::lonnet::filelocation('',$url)));
1.69 albertel 337: $ENV{'request.filename'}=$oldpath;
1.34 www 338: if (($Apache::lonxml::errorcount) ||
339: ($Apache::lonxml::warningcount)) {
340: if ($Apache::lonxml::errorcount) {
341: $r->print('<font color="red"><b>'.
342: $Apache::lonxml::errorcount.' error(s)</b></font> ');
343: }
344: if ($Apache::lonxml::warningcount) {
345: $r->print('<font color="blue">'.
346: $Apache::lonxml::warningcount.' warning(s)</font>');
347: }
348: } else {
349: $r->print('<font color="green">ok</font>');
350: }
351: $r->rflush();
352: }
1.29 www 353: my $dependencies=
354: &Apache::lonnet::metadata($url,'dependencies');
355: foreach (split(/\,/,$dependencies)) {
356: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
357: &checkonthis($r,$_,$level+1);
358: }
359: }
360: } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
361: $r->print('<font color="red"><b>connection down</b></font>');
362: } elsif ($result==HTTP_NOT_FOUND) {
363: $r->print('<font color="red"><b>not found</b></font>');
364: } else {
365: $r->print('<font color="red"><b>access denied</b></font>');
366: }
367: }
368: }
369: }
370:
1.8 www 371: # ================================================================ Main Handler
1.1 www 372: sub handler {
373: my $r = shift;
374: $r->content_type('text/html');
375: $r->send_http_header;
376: return OK if $r->header_only;
377:
1.47 www 378: # --------------------------------------------- Initialize help topics for this
379: foreach ('Adding_Course_Doc','Main_Course_Documents',
380: 'Adding_External_Resource','Navigate_Content',
1.68 bowersj2 381: 'Adding_Folders','Docs_Overview', 'Load_Map',
1.66 bowersj2 382: 'Supplemental', 'Score_Upload_Form',
1.47 www 383: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive') {
384: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
385: }
1.65 bowersj2 386: # Composite help files
387: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
388: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
389: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
390: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
391: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
392: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
393: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
1.67 www 394: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
395: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
396:
1.26 www 397: if ($ENV{'form.verify'}) {
398:
399: my $loaderror=&Apache::lonnet::overloaderror($r);
400: if ($loaderror) { return $loaderror; }
401:
402: $r->print('<html><head><title>Verify Content</title></head>'.
403: &Apache::loncommon::bodytag('Verify Course Documents'));
1.27 www 404: $hashtied=0;
1.30 www 405: undef %alreadyseen;
406: %alreadyseen=();
1.27 www 407: &tiehash();
408: foreach (keys %hash) {
1.28 www 409: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
1.29 www 410: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27 www 411: }
412: }
413: &untiehash();
1.70 ! www 414: $r->print('<h1>Done.</h1>');
1.26 www 415: } elsif ($ENV{'form.versions'}) {
416: $r->print('<html><head><title>Check Versions</title></head>'.
417: &Apache::loncommon::bodytag('Check Course Document Versions'));
1.27 www 418: $hashtied=0;
419: &tiehash();
1.30 www 420: my %changes=&Apache::lonnet::dump
421: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
422: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.31 www 423: my $firstkey=(keys %changes)[0];
424: unless ($firstkey=~/^error\:/) {
425: unless ($ENV{'form.timerange'}) {
426: $ENV{'form.timerange'}=604800;
427: }
428: my $seltext='during the last '.$ENV{'form.timerange'}.' seconds';
429: my $startsel='';
430: my $monthsel='';
431: my $weeksel='';
432: my $daysel='';
433: if ($ENV{'form.timerange'}==-1) {
434: $seltext='since start of course';
435: $startsel='selected';
1.32 www 436: $ENV{'form.timerange'}=time;
437: }
438: my $starttime=time-$ENV{'form.timerange'};
439: if ($ENV{'form.timerange'}==2592000) {
440: $seltext='during the last month ('.localtime($starttime).')';
1.31 www 441: $monthsel='selected';
442: } elsif ($ENV{'form.timerange'}==604800) {
1.32 www 443: $seltext='during the last week ('.localtime($starttime).')';
1.31 www 444: $weeksel='selected';
445: } elsif ($ENV{'form.timerange'}==86400) {
1.32 www 446: $seltext='since yesterday ('.localtime($starttime).')';
1.31 www 447: $daysel='selected';
448: }
1.32 www 449:
1.31 www 450: $r->print(<<ENDHEADERS);
451: <form action="/adm/coursedocs" method="post">
452: <select name="timerange">
453: <option value="-1" $startsel>Since Start of Course</option>
454: <option value="2592000" $monthsel>Last Month</option>
455: <option value="604800" $weeksel>Last Week</option>
456: <option value="86400" $daysel>Since Yesterday</option>
457: </select>
458: <input type="submit" name="versions" value="Display" />
459: </form>
1.32 www 460: <h3>Content changed $seltext</h3>
1.31 www 461: <table border="2">
462: <tr>
463: <th>File</th><th>Modification Date</th>
464: <th>Version</th><th>Differences</th></tr>
465: ENDHEADERS
466: foreach (keys %changes) {
1.32 www 467: if ($changes{$_}>$starttime) {
468: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
469: my $currentversion=&Apache::lonnet::getversion($_);
470: my $linkurl=&Apache::lonnet::clutter($_);
471: $r->print(
472: '<tr><td><a href="'.$linkurl.'" target="cat">'.$linkurl.
473: '</a></td><td>'.
474: localtime($changes{$_}).'</td><td>'.$currentversion.'</td>'.
475: '<td>');
476: my $lastold=1;
477: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
478: my $url=$root.'.'.$prevvers.'.'.$extension;
479: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
480: $starttime) {
481: $lastold=$prevvers;
482: }
483: }
484: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
485: my $url=$root.'.'.$prevvers.'.'.$extension;
486: $r->print('<a href="'.&Apache::lonnet::clutter($url).
487: '">Version '.$prevvers.' ('.
488: localtime(&Apache::lonnet::metadata($url,'lastrevisiondate')).
1.33 www 489: ')</a>');
490: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
491: $r->print(' <a href="/adm/diff?filename='.
492: &Apache::lonnet::clutter($root.'.'.$extension).
493: '&versionone='.$prevvers.
494: '">Diffs</a>');
495: }
496: $r->print('<br />');
1.32 www 497: }
498: $r->print('</td></tr>');
499: }
1.31 www 500: }
501: $r->print('</table>');
1.70 ! www 502: $r->print('<h1>Done.</h1>');
1.31 www 503: } else {
504: $r->print('<p>No content modifications yet.</p>');
1.30 www 505: }
1.27 www 506: &untiehash();
1.26 www 507: } else {
1.7 www 508: # is this a standard course?
509:
510: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1.15 www 511: my $forcestandard;
512: my $forcesupplement;
513: my $script='';
514: my $allowed;
515: my $events='';
1.49 www 516: my $buttons='';
1.19 www 517: my $showdoc=0;
1.15 www 518: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.21 www 519: ['folder','foldername']);
520: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
521: $showdoc=$1;
522: }
523: unless ($showdoc) { # got called from remote
1.15 www 524: $forcestandard=($ENV{'form.folder'}=~/^default_/);
525: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1.7 www 526:
1.4 www 527: # does this user have privileges to post, etc?
1.15 www 528: $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
529: if ($allowed) {
530: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
531: $script=&Apache::lonratedt::editscript('simple');
532: }
533: } else { # got called in sequence from course
534: $allowed=0;
1.49 www 535: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
536: $events='onLoad="'.&Apache::lonmenu::loadevents.
537: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
538: $buttons=&Apache::lonmenu::menubuttons(1,undef);
1.3 www 539: }
1.4 www 540:
541: # get course data
542: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
543: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
544:
1.14 www 545: # get personal data
546:
547: my $uname=$ENV{'user.name'};
548: my $udom=$ENV{'user.domain'};
549: my $plainname=&Apache::lonnet::escape(
550: &Apache::loncommon::plainname($uname,$udom));
551:
1.8 www 552: # graphics settings
1.4 www 553:
1.8 www 554: $iconpath = $r->dir_config('lonIconsURL') . "/";
555:
1.22 www 556: my $now=time;
1.64 www 557:
1.4 www 558: # print screen
1.1 www 559: $r->print(<<ENDDOCUMENT);
560: <html>
561: <head>
562: <title>The LearningOnline Network with CAPA</title>
1.16 www 563: <script>
564: $script
1.20 www 565: </script>
1.19 www 566: ENDDOCUMENT
567: if ($allowed) {
568: $r->print(<<ENDNEWSCRIPT);
1.20 www 569: <script>
1.16 www 570: function makenewfolder(targetform,folderseq) {
571: var foldername=prompt('Name of New Folder','New Folder');
572: if (foldername) {
573: targetform.importdetail.value=foldername+"="+folderseq;
574: targetform.submit();
575: }
576: }
577:
1.18 www 578: function makenewext(targetname) {
579: this.document.forms.extimport.useform.value=targetname;
580: window.open('/adm/rat/extpickframe.html');
581: }
582:
1.62 www 583: function makeexamupload() {
584: var title=prompt('Listed Title for the Uploaded Score');
585: if (title) {
586: this.document.forms.newexamupload.importdetail.value=
587: title+'=/res/lib/templates/examupload.problem';
588: this.document.forms.newexamupload.submit();
589: }
590: }
591:
1.22 www 592: function makesmppage() {
1.38 www 593: var title=prompt('Listed Title for the Page');
594: if (title) {
1.22 www 595: this.document.forms.newsmppg.importdetail.value=
596: title+'=/adm/$udom/$uname/$now/smppg';
597: this.document.forms.newsmppg.submit();
1.38 www 598: }
1.22 www 599: }
600:
1.55 www 601: function makesmpproblem() {
602: var title=prompt('Listed Title for the Problem');
603: if (title) {
604: this.document.forms.newsmpproblem.importdetail.value=
1.63 www 605: title+'=/res/lib/templates/simpleproblem.problem';
1.55 www 606: this.document.forms.newsmpproblem.submit();
607: }
608: }
609:
1.22 www 610: function makebulboard() {
1.38 www 611: var title=prompt('Listed Title for the Bulletin Board');
612: if (title) {
1.22 www 613: this.document.forms.newbul.importdetail.value=
614: title+'=/adm/$udom/$uname/$now/bulletinboard';
615: this.document.forms.newbul.submit();
1.38 www 616: }
1.22 www 617: }
618:
1.18 www 619: function finishpick() {
620: var title=this.document.forms.extimport.title.value;
621: var url=this.document.forms.extimport.url.value;
622: var form=this.document.forms.extimport.useform.value;
623: eval
624: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
625: '";this.document.forms.'+form+'.submit();');
1.16 www 626: }
1.36 www 627:
628: function changename(folder,index,oldtitle) {
629: var title=prompt('New Title',oldtitle);
630: if (title) {
631: this.document.forms.renameform.title.value=title;
632: this.document.forms.renameform.cmd.value='rename_'+index;
1.54 www 633: this.document.forms.renameform.folder.value=folder;
634: this.document.forms.renameform.submit();
635: }
636: }
637:
638: function removeres(folder,index,oldtitle) {
1.57 www 639: if ((oldtitle=='NO RESOURCE') || (confirm('Remove "'+oldtitle+'"?'))) {
1.54 www 640: this.document.forms.renameform.cmd.value='del_'+index;
1.36 www 641: this.document.forms.renameform.folder.value=folder;
642: this.document.forms.renameform.submit();
643: }
644: }
1.16 www 645: </script>
1.42 www 646:
647: ENDNEWSCRIPT
648: }
649: # -------------------------------------------------------------------- Body tag
650: $r->print('</head>'.
1.49 www 651: &Apache::loncommon::bodytag('Course Documents','',$events).
652: $buttons);
1.42 www 653: unless ($showdoc) {
654: if ($allowed) {
1.47 www 655: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
656: 'Editing the Table of Contents for your Course'));
1.42 www 657: $r->print(<<ENDCOURSEVERIFY);
1.36 www 658: <form name="renameform" method="post" action="/adm/coursedocs">
659: <input type="hidden" name="title" />
660: <input type="hidden" name="cmd" />
661: <input type="hidden" name="folder" />
662: </form>
1.39 www 663: <form name="simpleedit" method="post" action="/adm/coursedocs">
664: <input type=hidden name="importdetail" value="">
665: <input type="hidden" name="folder" />
666: </form>
1.26 www 667: <form action="/adm/coursedocs" method="post" name="courseverify">
1.25 www 668: <input type="submit" name="verify" value="Verify Content" />
669: <input type="submit" name="versions" value="Check Resource Versions" />
670: </form>
671: ENDCOURSEVERIFY
672: }
1.17 www 673: # --------------------------------------------------------- Standard documents
1.43 www 674: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1.7 www 675: if (($standard) && ($allowed) && (!$forcesupplement)) {
1.47 www 676: $r->print('<tr><td bgcolor="#BBBBBB"><h2>Main Course Documents'.
677: ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1.7 www 678: my $folder=$ENV{'form.folder'};
1.10 www 679: unless ($folder=~/^default/) { $folder='default'; }
1.51 www 680: my $postexec='';
681: if ($folder eq 'default') {
682: $r->print('<script>this.window.name="loncapaclient";</script>');
683: } else {
684: $postexec='self.close();';
685: }
1.40 www 686: $hadchanges=0;
1.7 www 687: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.40 www 688: if ($hadchanges) {
1.51 www 689: $r->print(
690: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
691: '<form method="post" action="/adm/roles" target="loncapaclient">'.
692: '<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="'.
1.67 www 693: $ENV{'request.role'}.'" value="1" /><input type="button" value="re-initializing course" onClick="reinit(this.form)"/>, or the next time you log in.'.
694: $help{'Caching'}.'</font></h3></form>');
1.40 www 695: }
1.16 www 696: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
697: '.sequence';
1.47 www 698:
1.8 www 699: $r->print(<<ENDFORM);
1.43 www 700: <table cellspacing=4 cellpadding=4><tr>
1.16 www 701: <th bgcolor="#DDDDDD">Upload a new main course document</th>
702: <th bgcolor="#DDDDDD">Import a published document</th>
703: <th bgcolor="#DDDDDD">Special documents</th>
1.11 www 704: </tr>
1.16 www 705: <tr><td bgcolor="#DDDDDD">
1.11 www 706: File:<br />
1.10 www 707: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59 www 708: <input type="file" name="uploaddoc" size="40">
1.8 www 709: <br />
1.58 albertel 710: Title:<br />
1.11 www 711: <input type="text" size="50" name="comment">
1.8 www 712: <input type="hidden" name="folder" value="$folder">
1.17 www 713: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.10 www 714: <input type="hidden" name="cmd" value="upload_default">
1.8 www 715: <input type="submit" value="Upload Document">
1.59 www 716: <nobr>
1.60 albertel 717: $help{'Uploading_From_Harddrive'}
1.58 albertel 718: </nobr>
1.60 albertel 719: </form>
1.11 www 720: </td>
1.16 www 721: <td bgcolor="#DDDDDD">
1.39 www 722: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.53 www 723: <input type="hidden" name="folder" value="$folder">
724: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.11 www 725: <input type=button onClick=
1.39 www 726: "javascript:document.forms.simpleedit.folder.value='$folder';groupsearch()" value="Search">
1.58 albertel 727: <nobr>
1.11 www 728: <input type=button onClick=
1.39 www 729: "javascript:document.forms.simpleedit.folder.value='$folder';groupimport();" value="Import">
1.58 albertel 730: $help{'Importing_LON-CAPA_Resource'}
731: </nobr>
1.59 www 732: <p>
733: <hr />
1.68 bowersj2 734: <input type="text" size="20" name="importmap"><br />
735: <nobr><input type=button
1.52 www 736: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.68 bowersj2 737: value="Select Map"> <input type="submit" name="loadmap" value="Load Map">
738: $help{'Load_Map'}</nobr>
1.59 www 739: </p>
1.52 www 740: </form>
1.16 www 741: </td><td bgcolor="#DDDDDD">
1.11 www 742: <form action="/adm/coursedocs" method="post" name="newfolder">
1.16 www 743: <input type="hidden" name="folder" value="$folder">
1.17 www 744: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.13 www 745: <input type=hidden name="importdetail" value="">
1.58 albertel 746: <nobr>
1.16 www 747: <input name="newfolder" type="button"
748: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.58 albertel 749: value="New Folder" />$help{'Adding_Folders'}
750: </nobr>
1.11 www 751: </form>
752: <form action="/adm/coursedocs" method="post" name="newext">
1.16 www 753: <input type="hidden" name="folder" value="$folder">
1.17 www 754: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.13 www 755: <input type=hidden name="importdetail" value="">
1.58 albertel 756: <nobr>
1.18 www 757: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
1.47 www 758: value="External Resource" /> $help{'Adding_External_Resource'}
1.58 albertel 759: </nobr>
1.11 www 760: </form>
761: <form action="/adm/coursedocs" method="post" name="newsyl">
1.16 www 762: <input type="hidden" name="folder" value="$folder">
1.17 www 763: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.14 www 764: <input type=hidden name="importdetail"
765: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58 albertel 766: <nobr>
1.47 www 767: <input name="newsyl" type="submit" value="Syllabus" />
1.65 bowersj2 768: $help{'Syllabus'}
1.58 albertel 769: </nobr>
770: </form>
1.17 www 771: <form action="/adm/coursedocs" method="post" name="newnav">
1.20 www 772: <input type="hidden" name="folder" value="$folder">
773: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.15 www 774: <input type=hidden name="importdetail"
775: value="Navigate Content=/adm/navmaps">
1.58 albertel 776: <nobr>
1.20 www 777: <input name="newnav" type="submit" value="Navigate Content" />
1.47 www 778: $help{'Navigate_Content'}
1.58 albertel 779: </nobr>
1.22 www 780: </form>
781: <form action="/adm/coursedocs" method="post" name="newsmppg">
782: <input type="hidden" name="folder" value="$folder">
783: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
784: <input type=hidden name="importdetail" value="">
1.58 albertel 785: <nobr>
1.22 www 786: <input name="newsmppg" type="button" value="Simple Page"
1.65 bowersj2 787: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1.58 albertel 788: </nobr>
1.55 www 789: </form>
790: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
791: <input type="hidden" name="folder" value="$folder">
792: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
793: <input type=hidden name="importdetail" value="">
1.58 albertel 794: <nobr>
1.55 www 795: <input name="newsmpproblem" type="button" value="Simple Problem"
1.65 bowersj2 796: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.62 www 797: </nobr>
798: </form>
799: <form action="/adm/coursedocs" method="post" name="newexamupload">
800: <input type="hidden" name="folder" value="$folder">
801: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
802: <input type=hidden name="importdetail" value="">
803: <nobr>
804: <input name="newexamupload" type="button" value="Score Upload Form"
805: onClick="javascript:makeexamupload();" />
1.66 bowersj2 806: $help{'Score_Upload_Form'}
1.58 albertel 807: </nobr>
1.22 www 808: </form>
809: <form action="/adm/coursedocs" method="post" name="newbul">
810: <input type="hidden" name="folder" value="$folder">
811: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
812: <input type=hidden name="importdetail" value="">
1.58 albertel 813: <nobr>
1.22 www 814: <input name="newbulletin" type="button" value="Bulletin Board"
815: onClick="javascript:makebulboard();" />
1.65 bowersj2 816: $help{'Bulletin Board'}
1.58 albertel 817: </nobr>
818: </form>
1.12 www 819: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.16 www 820: <input type="hidden" name="folder" value="$folder">
1.17 www 821: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.14 www 822: <input type=hidden name="importdetail"
823: value="$plainname=/adm/$udom/$uname/aboutme">
1.58 albertel 824: <nobr>
1.16 www 825: <input name="newaboutme" type="submit" value="My Personal Info" />
1.65 bowersj2 826: $help{'My Personal Info'}
1.58 albertel 827: </nobr>
828: </form>
1.11 www 829: </td></tr>
830: </table>
1.8 www 831: ENDFORM
1.24 www 832: $r->print('</td></tr>');
1.7 www 833: }
834: # ----------------------------------------------------- Supplemental documents
835: if (!$forcestandard) {
1.24 www 836: $r->print(
1.47 www 837: '<tr><td bgcolor="#BBBBBB"><h2>Supplemental Course Documents'.
838: ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1.7 www 839: my $folder=$ENV{'form.folder'};
1.10 www 840: unless ($folder=~/supplemental/) { $folder='supplemental'; }
1.7 www 841: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 www 842: if ($allowed) {
1.17 www 843: my $folderseq=
844: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
845: '.sequence';
846:
1.8 www 847: $r->print(<<ENDSUPFORM);
1.43 www 848: <table cellspacing=4 cellpadding=4><tr>
1.17 www 849: <th bgcolor="#DDDDDD">Upload a new supplemental 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">
1.10 www 854: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59 www 855: <input type="file" name="uploaddoc" size="40">
1.4 www 856: <br />Comment:<br />
857: <textarea cols=50 rows=4 name='comment'>
858: </textarea>
1.8 www 859: <input type="hidden" name="folder" value="$folder">
1.17 www 860: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.10 www 861: <input type="hidden" name="cmd" value="upload_supplemental">
1.58 albertel 862: <nobr>
1.3 www 863: <input type="submit" value="Upload Document">
1.58 albertel 864: $help{'Uploading_From_Harddrive'}
865: </nobr>
866: </form>
1.17 www 867: </td>
868: <td bgcolor="#DDDDDD">
1.39 www 869: <form action="/adm/coursedocs" method="post" name="simpleeditsupplement">
1.53 www 870: <input type="hidden" name="folder" value="$folder">
871: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.17 www 872: <input type=hidden name="importdetail" value="">
873: <input type=button onClick=
1.39 www 874: "javascript:document.forms.simpleedit.folder.value='$folder';groupsearch()" value="Search">
1.17 www 875: <input type=button onClick=
1.47 www 876: "javascript:document.forms.simpleedit.folder.value='$folder';groupimport();" value="Import">$help{'Importing_LON-CAPA_Resource'}
1.59 www 877: <p>
878: <hr />
1.53 www 879: <input type="text" size="20" name="importmap">
880: <input type=button
881: onClick="javascript:openbrowser('simpleeditsupplement','importmap','sequence,page','')"
1.61 www 882: value="Select Map"><input type="submit" name="loadmap" value="Load Map">
1.59 www 883: </p>
1.17 www 884: </form>
885: </td><td bgcolor="#DDDDDD">
1.18 www 886: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.17 www 887: <input type="hidden" name="folder" value="$folder">
888: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
889: <input type=hidden name="importdetail" value="">
1.58 albertel 890: <nobr>
1.17 www 891: <input name="newfolder" type="button"
892: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.47 www 893: value="New Folder" /> $help{'Adding_Folders'}
1.58 albertel 894: </nobr>
1.17 www 895: </form>
1.18 www 896: <form action="/adm/coursedocs" method="post" name="supnewext">
1.17 www 897: <input type="hidden" name="folder" value="$folder">
898: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
899: <input type=hidden name="importdetail" value="">
1.58 albertel 900: <nobr>
1.18 www 901: <input name="newext" type="button"
902: onClick="javascript:makenewext('supnewext');"
1.47 www 903: value="External Resource" /> $help{'Adding_External_Resource'}
1.58 albertel 904: </nobr>
1.17 www 905: </form>
1.18 www 906: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.17 www 907: <input type="hidden" name="folder" value="$folder">
908: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
909: <input type=hidden name="importdetail"
910: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58 albertel 911: <nobr>
1.17 www 912: <input name="newsyl" type="submit" value="Syllabus" />
1.65 bowersj2 913: $help{'Syllabus'}
1.58 albertel 914: </nobr>
915: </form>
1.18 www 916: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.17 www 917: <input type="hidden" name="folder" value="$folder">
918: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
919: <input type=hidden name="importdetail"
920: value="$plainname=/adm/$udom/$uname/aboutme">
1.58 albertel 921: <nobr>
1.17 www 922: <input name="newaboutme" type="submit" value="My Personal Info" />
1.65 bowersj2 923: $help{'My Personal Info'}
1.58 albertel 924: </nobr>
925: </form>
1.17 www 926: </td></tr>
1.24 www 927: </table></td></tr>
1.8 www 928: ENDSUPFORM
929: }
1.7 www 930: }
1.18 www 931: if ($allowed) {
932: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
933: }
1.24 www 934: $r->print('</table>');
1.19 www 935: } else {
936: # -------------------------------------------------------- This is showdoc mode
937: $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 938: &entryline(0,"Click to download or use your browser's Save Link function",$showdoc).'</table></p>');
1.19 www 939: }
1.26 www 940: }
941: $r->print('</body></html>');
942: return OK;
1.1 www 943: }
944:
945: 1;
946: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>