File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.55:
download - view:
text,
annotated -
select for diffs
Tue May 13 15:41:20 2003 UTC (21 years, 3 months ago) by
www
Branches:
MAIN
CVS tags:
HEAD
Button to insert new uploaded problem. No way to edit or generate such a file
yet. Appears to be working when copying an existing problem file by hand into
the user space, but needs to be tested between different machines.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.55 2003/05/13 15:41:20 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 HTML::Entities;
39: use GDBM_File;
40:
41: my $iconpath;
42:
43: my %hash;
44:
45: my $hashtied;
46: my %alreadyseen=();
47:
48: my $hadchanges;
49:
50: # Available help topics
51:
52: my %help=();
53:
54: # Mapread read maps into lonratedt::global arrays
55: # @order and @resources, determines status
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)=@_;
69: $hadchanges=1;
70: return
71: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
72: $map,1);
73: }
74:
75: sub editor {
76: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
77: if ($ENV{'form.foldername'}) {
78: $r->print('<h3>Folder: '.$ENV{'form.foldername'}.'</h3>');
79: }
80: my $errtext='';
81: my $fatal=0;
82: ($errtext,$fatal)=
83: &mapread($coursenum,$coursedom,$folder.'.sequence');
84: if ($#Apache::lonratedt::order<1) {
85: $Apache::lonratedt::order[0]=1;
86: $Apache::lonratedt::resources[1]='';
87: }
88: if ($fatal) {
89: $r->print('<p><font color="red">'.$errtext.'</font></p>');
90: } else {
91: # ------------------------------------------------------------ Process commands
92: # ---------------- if they are for this folder and user allowed to make changes
93: if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
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;
108: if ($folder=~/^supplemental/) {
109: $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
110: $ENV{'user.domain'}.'___&&&___'.$comment;
111: }
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: }
120: if ($ENV{'form.cmd'}) {
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') {
129: if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
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;
134: }
135: } elsif ($cmd eq 'down') {
136: if (defined($Apache::lonratedt::order[$idx+1])) {
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;
141: }
142: } elsif ($cmd eq 'rename') {
143: my ($rtitle,@rrest)=split(/\:/,
144: $Apache::lonratedt::resources[
145: $Apache::lonratedt::order[$idx]]);
146: my $comment=
147: &HTML::Entities::decode($ENV{'form.title'});
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:
155: }
156: # Store the changed version
157: &storemap($coursenum,$coursedom,$folder.'.sequence');
158: }
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;
173: $name=~s/\:/\:/g;
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: }
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: }
196: }
197: # ---------------------------------------------------------------- End commands
198: # ---------------------------------------------------------------- Print screen
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]; }
204: unless ($name) { $name='NO RESOURCE'; $url='/adm/notfound.html'; }
205: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_));
206: $idx++;
207: }
208: $r->print('</table>');
209: }
210: }
211:
212: # --------------------------------------------------------------- An entry line
213:
214: sub entryline {
215: my ($index,$title,$url,$folder,$allowed,$residx)=@_;
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;
231: my $line='<tr>';
232: # Edit commands
233: if ($allowed) {
234: $line.=(<<END);
235: <td><table border='0' cellspacing='2' cellpadding='0'>
236: <tr><td bgcolor="#DDDDDD">
237: <a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
238: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
239: <tr><td bgcolor="#DDDDDD">
240: <a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
241: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
242: </table></td><td bgcolor="#DDDDDD">
243: <a href='javascript:removeres("$folder","$index","$renametitle");'>
244: <font size="-2" color="#990000">Remove</font></a>
245: <a href='javascript:changename("$folder","$index","$renametitle");'>
246: <font size="-2" color="#009900">Rename</font></a></td>
247: END
248: }
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;
255: }
256: my $isfolder=0;
257: if ($uploaded) {
258: if ($extension eq 'sequence') {
259: $icon='folder_closed';
260: $url=~/\/(\w+)\.sequence/;
261: $url='/adm/coursedocs?folder='.$1;
262: $isfolder=1;
263: } else {
264: $url=&Apache::lonnet::tokenwrapper($url);
265: }
266: }
267: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
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: }
278: if ($isfolder) { $url.='&foldername='.
279: &Apache::lonnet::escape($foldertitle); }
280: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'" target="cat_'.$folder.
281: '"><img src="/adm/lonIcons/'.
282: $icon.'.gif" border="0"></a></td>'.
283: "<td bgcolor='#FFFFBB'><a href='$url' target='cat_$folder'>$title</a></td></tr>";
284: return $line;
285: }
286:
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:
304: # --------------------------------------------------------------- check on this
305:
306: sub checkonthis {
307: my ($r,$url,$level,$title)=@_;
308: $alreadyseen{$url}=1;
309: $r->rflush();
310: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
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();
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: ');
332: &Apache::lonxml::xmlparse($r,'web',
333: &Apache::lonnet::getfile(
334: &Apache::lonnet::filelocation('',$url)));
335: if (($Apache::lonxml::errorcount) ||
336: ($Apache::lonxml::warningcount)) {
337: if ($Apache::lonxml::errorcount) {
338: $r->print('<font color="red"><b>'.
339: $Apache::lonxml::errorcount.' error(s)</b></font> ');
340: }
341: if ($Apache::lonxml::warningcount) {
342: $r->print('<font color="blue">'.
343: $Apache::lonxml::warningcount.' warning(s)</font>');
344: }
345: } else {
346: $r->print('<font color="green">ok</font>');
347: }
348: $r->rflush();
349: }
350: my $dependencies=
351: &Apache::lonnet::metadata($url,'dependencies');
352: foreach (split(/\,/,$dependencies)) {
353: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
354: &checkonthis($r,$_,$level+1);
355: }
356: }
357: } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
358: $r->print('<font color="red"><b>connection down</b></font>');
359: } elsif ($result==HTTP_NOT_FOUND) {
360: $r->print('<font color="red"><b>not found</b></font>');
361: } else {
362: $r->print('<font color="red"><b>access denied</b></font>');
363: }
364: }
365: }
366: }
367:
368: # ================================================================ Main Handler
369: sub handler {
370: my $r = shift;
371: $r->content_type('text/html');
372: $r->send_http_header;
373: return OK if $r->header_only;
374:
375: # --------------------------------------------- Initialize help topics for this
376: foreach ('Adding_Course_Doc','Main_Course_Documents',
377: 'Adding_External_Resource','Navigate_Content',
378: 'Adding_Folders','Docs_Overview',
379: 'Creating_From_Template','Supplemental',
380: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive') {
381: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
382: }
383:
384: if ($ENV{'form.verify'}) {
385:
386: my $loaderror=&Apache::lonnet::overloaderror($r);
387: if ($loaderror) { return $loaderror; }
388:
389: $r->print('<html><head><title>Verify Content</title></head>'.
390: &Apache::loncommon::bodytag('Verify Course Documents'));
391: $hashtied=0;
392: undef %alreadyseen;
393: %alreadyseen=();
394: &tiehash();
395: foreach (keys %hash) {
396: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
397: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
398: }
399: }
400: &untiehash();
401: } elsif ($ENV{'form.versions'}) {
402: $r->print('<html><head><title>Check Versions</title></head>'.
403: &Apache::loncommon::bodytag('Check Course Document Versions'));
404: $hashtied=0;
405: &tiehash();
406: my %changes=&Apache::lonnet::dump
407: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
408: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
409: my $firstkey=(keys %changes)[0];
410: unless ($firstkey=~/^error\:/) {
411: unless ($ENV{'form.timerange'}) {
412: $ENV{'form.timerange'}=604800;
413: }
414: my $seltext='during the last '.$ENV{'form.timerange'}.' seconds';
415: my $startsel='';
416: my $monthsel='';
417: my $weeksel='';
418: my $daysel='';
419: if ($ENV{'form.timerange'}==-1) {
420: $seltext='since start of course';
421: $startsel='selected';
422: $ENV{'form.timerange'}=time;
423: }
424: my $starttime=time-$ENV{'form.timerange'};
425: if ($ENV{'form.timerange'}==2592000) {
426: $seltext='during the last month ('.localtime($starttime).')';
427: $monthsel='selected';
428: } elsif ($ENV{'form.timerange'}==604800) {
429: $seltext='during the last week ('.localtime($starttime).')';
430: $weeksel='selected';
431: } elsif ($ENV{'form.timerange'}==86400) {
432: $seltext='since yesterday ('.localtime($starttime).')';
433: $daysel='selected';
434: }
435:
436: $r->print(<<ENDHEADERS);
437: <form action="/adm/coursedocs" method="post">
438: <select name="timerange">
439: <option value="-1" $startsel>Since Start of Course</option>
440: <option value="2592000" $monthsel>Last Month</option>
441: <option value="604800" $weeksel>Last Week</option>
442: <option value="86400" $daysel>Since Yesterday</option>
443: </select>
444: <input type="submit" name="versions" value="Display" />
445: </form>
446: <h3>Content changed $seltext</h3>
447: <table border="2">
448: <tr>
449: <th>File</th><th>Modification Date</th>
450: <th>Version</th><th>Differences</th></tr>
451: ENDHEADERS
452: foreach (keys %changes) {
453: if ($changes{$_}>$starttime) {
454: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
455: my $currentversion=&Apache::lonnet::getversion($_);
456: my $linkurl=&Apache::lonnet::clutter($_);
457: $r->print(
458: '<tr><td><a href="'.$linkurl.'" target="cat">'.$linkurl.
459: '</a></td><td>'.
460: localtime($changes{$_}).'</td><td>'.$currentversion.'</td>'.
461: '<td>');
462: my $lastold=1;
463: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
464: my $url=$root.'.'.$prevvers.'.'.$extension;
465: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
466: $starttime) {
467: $lastold=$prevvers;
468: }
469: }
470: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
471: my $url=$root.'.'.$prevvers.'.'.$extension;
472: $r->print('<a href="'.&Apache::lonnet::clutter($url).
473: '">Version '.$prevvers.' ('.
474: localtime(&Apache::lonnet::metadata($url,'lastrevisiondate')).
475: ')</a>');
476: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
477: $r->print(' <a href="/adm/diff?filename='.
478: &Apache::lonnet::clutter($root.'.'.$extension).
479: '&versionone='.$prevvers.
480: '">Diffs</a>');
481: }
482: $r->print('<br />');
483: }
484: $r->print('</td></tr>');
485: }
486: }
487: $r->print('</table>');
488: } else {
489: $r->print('<p>No content modifications yet.</p>');
490: }
491: &untiehash();
492: } else {
493: # is this a standard course?
494:
495: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
496: my $forcestandard;
497: my $forcesupplement;
498: my $script='';
499: my $allowed;
500: my $events='';
501: my $buttons='';
502: my $showdoc=0;
503: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
504: ['folder','foldername']);
505: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
506: $showdoc=$1;
507: }
508: unless ($showdoc) { # got called from remote
509: $forcestandard=($ENV{'form.folder'}=~/^default_/);
510: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
511:
512: # does this user have privileges to post, etc?
513: $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
514: if ($allowed) {
515: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
516: $script=&Apache::lonratedt::editscript('simple');
517: }
518: } else { # got called in sequence from course
519: $allowed=0;
520: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
521: $events='onLoad="'.&Apache::lonmenu::loadevents.
522: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
523: $buttons=&Apache::lonmenu::menubuttons(1,undef);
524: }
525:
526: # get course data
527: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
528: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
529:
530: # get personal data
531:
532: my $uname=$ENV{'user.name'};
533: my $udom=$ENV{'user.domain'};
534: my $plainname=&Apache::lonnet::escape(
535: &Apache::loncommon::plainname($uname,$udom));
536:
537: # graphics settings
538:
539: $iconpath = $r->dir_config('lonIconsURL') . "/";
540:
541: my $now=time;
542:
543: # print screen
544: $r->print(<<ENDDOCUMENT);
545: <html>
546: <head>
547: <title>The LearningOnline Network with CAPA</title>
548: <script>
549: $script
550: </script>
551: ENDDOCUMENT
552: if ($allowed) {
553: $r->print(<<ENDNEWSCRIPT);
554: <script>
555: function makenewfolder(targetform,folderseq) {
556: var foldername=prompt('Name of New Folder','New Folder');
557: if (foldername) {
558: targetform.importdetail.value=foldername+"="+folderseq;
559: targetform.submit();
560: }
561: }
562:
563: function makenewext(targetname) {
564: this.document.forms.extimport.useform.value=targetname;
565: window.open('/adm/rat/extpickframe.html');
566: }
567:
568: function makesmppage() {
569: var title=prompt('Listed Title for the Page');
570: if (title) {
571: this.document.forms.newsmppg.importdetail.value=
572: title+'=/adm/$udom/$uname/$now/smppg';
573: this.document.forms.newsmppg.submit();
574: }
575: }
576:
577: function makesmpproblem() {
578: var title=prompt('Listed Title for the Problem');
579: if (title) {
580: this.document.forms.newsmpproblem.importdetail.value=
581: title+'=/adm/wrapper/uploaded/$udom/$uname/$now.problem';
582: this.document.forms.newsmpproblem.submit();
583: }
584: }
585:
586: function makebulboard() {
587: var title=prompt('Listed Title for the Bulletin Board');
588: if (title) {
589: this.document.forms.newbul.importdetail.value=
590: title+'=/adm/$udom/$uname/$now/bulletinboard';
591: this.document.forms.newbul.submit();
592: }
593: }
594:
595: function finishpick() {
596: var title=this.document.forms.extimport.title.value;
597: var url=this.document.forms.extimport.url.value;
598: var form=this.document.forms.extimport.useform.value;
599: eval
600: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
601: '";this.document.forms.'+form+'.submit();');
602: }
603:
604: function changename(folder,index,oldtitle) {
605: var title=prompt('New Title',oldtitle);
606: if (title) {
607: this.document.forms.renameform.title.value=title;
608: this.document.forms.renameform.cmd.value='rename_'+index;
609: this.document.forms.renameform.folder.value=folder;
610: this.document.forms.renameform.submit();
611: }
612: }
613:
614: function removeres(folder,index,oldtitle) {
615: if (confirm('Remove "'+oldtitle+'"?')) {
616: this.document.forms.renameform.cmd.value='del_'+index;
617: this.document.forms.renameform.folder.value=folder;
618: this.document.forms.renameform.submit();
619: }
620: }
621: </script>
622:
623: ENDNEWSCRIPT
624: }
625: # -------------------------------------------------------------------- Body tag
626: $r->print('</head>'.
627: &Apache::loncommon::bodytag('Course Documents','',$events).
628: $buttons);
629: unless ($showdoc) {
630: if ($allowed) {
631: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
632: 'Editing the Table of Contents for your Course'));
633: $r->print(<<ENDCOURSEVERIFY);
634: <form name="renameform" method="post" action="/adm/coursedocs">
635: <input type="hidden" name="title" />
636: <input type="hidden" name="cmd" />
637: <input type="hidden" name="folder" />
638: </form>
639: <form name="simpleedit" method="post" action="/adm/coursedocs">
640: <input type=hidden name="importdetail" value="">
641: <input type="hidden" name="folder" />
642: </form>
643: <form action="/adm/coursedocs" method="post" name="courseverify">
644: <input type="submit" name="verify" value="Verify Content" />
645: <input type="submit" name="versions" value="Check Resource Versions" />
646: </form>
647: ENDCOURSEVERIFY
648: }
649: # --------------------------------------------------------- Standard documents
650: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
651: if (($standard) && ($allowed) && (!$forcesupplement)) {
652: $r->print('<tr><td bgcolor="#BBBBBB"><h2>Main Course Documents'.
653: ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
654: my $folder=$ENV{'form.folder'};
655: unless ($folder=~/^default/) { $folder='default'; }
656: my $postexec='';
657: if ($folder eq 'default') {
658: $r->print('<script>this.window.name="loncapaclient";</script>');
659: } else {
660: $postexec='self.close();';
661: }
662: $hadchanges=0;
663: &editor($r,$coursenum,$coursedom,$folder,$allowed);
664: if ($hadchanges) {
665: $r->print(
666: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
667: '<form method="post" action="/adm/roles" target="loncapaclient">'.
668: '<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="'.
669: $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>');
670: }
671: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
672: '.sequence';
673:
674: $r->print(<<ENDFORM);
675: <table cellspacing=4 cellpadding=4><tr>
676: <th bgcolor="#DDDDDD">Upload a new main course document</th>
677: <th bgcolor="#DDDDDD">Import a published document</th>
678: <th bgcolor="#DDDDDD">Special documents</th>
679: </tr>
680: <tr><td bgcolor="#DDDDDD">
681: File:<br />
682: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
683: <input type="file" name="uploaddoc" size="50">
684: <br />
685: Title:<br />
686: <input type="text" size="50" name="comment">
687: <input type="hidden" name="folder" value="$folder">
688: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
689: <input type="hidden" name="cmd" value="upload_default">
690: <input type="submit" value="Upload Document">
691: $help{'Uploading_From_Harddrive'}</form>
692: </td>
693: <td bgcolor="#DDDDDD">
694: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
695: <input type="hidden" name="folder" value="$folder">
696: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
697: <input type=button onClick=
698: "javascript:document.forms.simpleedit.folder.value='$folder';groupsearch()" value="Search">
699: <input type=button onClick=
700: "javascript:document.forms.simpleedit.folder.value='$folder';groupimport();" value="Import">
701: $help{'Importing_LON-CAPA_Resource'}<br />
702: <input type="text" size="20" name="importmap">
703: <input type=button
704: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
705: value="Browse"><input type="submit" name="loadmap" value="Load Map">
706: </form>
707: </td><td bgcolor="#DDDDDD">
708: <form action="/adm/coursedocs" method="post" name="newfolder">
709: <input type="hidden" name="folder" value="$folder">
710: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
711: <input type=hidden name="importdetail" value="">
712: <input name="newfolder" type="button"
713: onClick="javascript:makenewfolder(this.form,'$folderseq');"
714: value="New Folder" /> $help{'Adding_Folders'}
715: </form>
716: <form action="/adm/coursedocs" method="post" name="newext">
717: <input type="hidden" name="folder" value="$folder">
718: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
719: <input type=hidden name="importdetail" value="">
720: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
721: value="External Resource" /> $help{'Adding_External_Resource'}
722: </form>
723: <form action="/adm/coursedocs" method="post" name="newsyl">
724: <input type="hidden" name="folder" value="$folder">
725: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
726: <input type=hidden name="importdetail"
727: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
728: <input name="newsyl" type="submit" value="Syllabus" />
729: $help{'Creating_From_Template'}</form>
730: <form action="/adm/coursedocs" method="post" name="newnav">
731: <input type="hidden" name="folder" value="$folder">
732: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
733: <input type=hidden name="importdetail"
734: value="Navigate Content=/adm/navmaps">
735: <input name="newnav" type="submit" value="Navigate Content" />
736: $help{'Navigate_Content'}
737: </form>
738: <form action="/adm/coursedocs" method="post" name="newsmppg">
739: <input type="hidden" name="folder" value="$folder">
740: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
741: <input type=hidden name="importdetail" value="">
742: <input name="newsmppg" type="button" value="Simple Page"
743: onClick="javascript:makesmppage();" /> $help{'Creating_From_Template'}
744: </form>
745: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
746: <input type="hidden" name="folder" value="$folder">
747: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
748: <input type=hidden name="importdetail" value="">
749: <input name="newsmpproblem" type="button" value="Simple Problem"
750: onClick="javascript:makesmpproblem();" /> $help{'Creating_From_Template'}
751: </form>
752: <form action="/adm/coursedocs" method="post" name="newbul">
753: <input type="hidden" name="folder" value="$folder">
754: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
755: <input type=hidden name="importdetail" value="">
756: <input name="newbulletin" type="button" value="Bulletin Board"
757: onClick="javascript:makebulboard();" />
758: $help{'Creating_From_Template'}</form>
759: <form action="/adm/coursedocs" method="post" name="newaboutme">
760: <input type="hidden" name="folder" value="$folder">
761: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
762: <input type=hidden name="importdetail"
763: value="$plainname=/adm/$udom/$uname/aboutme">
764: <input name="newaboutme" type="submit" value="My Personal Info" />
765: $help{'Creating_From_Template'}</form>
766: </td></tr>
767: </table>
768: ENDFORM
769: $r->print('</td></tr>');
770: }
771: # ----------------------------------------------------- Supplemental documents
772: if (!$forcestandard) {
773: $r->print(
774: '<tr><td bgcolor="#BBBBBB"><h2>Supplemental Course Documents'.
775: ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
776: my $folder=$ENV{'form.folder'};
777: unless ($folder=~/supplemental/) { $folder='supplemental'; }
778: &editor($r,$coursenum,$coursedom,$folder,$allowed);
779: if ($allowed) {
780: my $folderseq=
781: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
782: '.sequence';
783:
784: $r->print(<<ENDSUPFORM);
785: <table cellspacing=4 cellpadding=4><tr>
786: <th bgcolor="#DDDDDD">Upload a new supplemental course document</th>
787: <th bgcolor="#DDDDDD">Import a published document</th>
788: <th bgcolor="#DDDDDD">Special documents</th>
789: </tr>
790: <tr><td bgcolor="#DDDDDD">
791: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
792: <input type="file" name="uploaddoc" size="50">
793: <br />Comment:<br />
794: <textarea cols=50 rows=4 name='comment'>
795: </textarea>
796: <input type="hidden" name="folder" value="$folder">
797: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
798: <input type="hidden" name="cmd" value="upload_supplemental">
799: <input type="submit" value="Upload Document">
800: $help{'Uploading_From_Harddrive'}</form>
801: </td>
802: <td bgcolor="#DDDDDD">
803: <form action="/adm/coursedocs" method="post" name="simpleeditsupplement">
804: <input type="hidden" name="folder" value="$folder">
805: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
806: <input type=hidden name="importdetail" value="">
807: <input type=button onClick=
808: "javascript:document.forms.simpleedit.folder.value='$folder';groupsearch()" value="Search">
809: <input type=button onClick=
810: "javascript:document.forms.simpleedit.folder.value='$folder';groupimport();" value="Import">$help{'Importing_LON-CAPA_Resource'}
811: <br />
812: <input type="text" size="20" name="importmap">
813: <input type=button
814: onClick="javascript:openbrowser('simpleeditsupplement','importmap','sequence,page','')"
815: value="Browse"><input type="submit" name="loadmap" value="Load Map">
816: </form>
817: </td><td bgcolor="#DDDDDD">
818: <form action="/adm/coursedocs" method="post" name="supnewfolder">
819: <input type="hidden" name="folder" value="$folder">
820: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
821: <input type=hidden name="importdetail" value="">
822: <input name="newfolder" type="button"
823: onClick="javascript:makenewfolder(this.form,'$folderseq');"
824: value="New Folder" /> $help{'Adding_Folders'}
825: </form>
826: <form action="/adm/coursedocs" method="post" name="supnewext">
827: <input type="hidden" name="folder" value="$folder">
828: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
829: <input type=hidden name="importdetail" value="">
830: <input name="newext" type="button"
831: onClick="javascript:makenewext('supnewext');"
832: value="External Resource" /> $help{'Adding_External_Resource'}
833: </form>
834: <form action="/adm/coursedocs" method="post" name="supnewsyl">
835: <input type="hidden" name="folder" value="$folder">
836: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
837: <input type=hidden name="importdetail"
838: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
839: <input name="newsyl" type="submit" value="Syllabus" />
840: $help{'Creating_From_Template'}</form>
841: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
842: <input type="hidden" name="folder" value="$folder">
843: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
844: <input type=hidden name="importdetail"
845: value="$plainname=/adm/$udom/$uname/aboutme">
846: <input name="newaboutme" type="submit" value="My Personal Info" />
847: $help{'Creating_From_Template'}</form>
848: </td></tr>
849: </table></td></tr>
850: ENDSUPFORM
851: }
852: }
853: if ($allowed) {
854: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
855: }
856: $r->print('</table>');
857: } else {
858: # -------------------------------------------------------- This is showdoc mode
859: $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>".
860: &entryline(0,"Click to download or use your browser's Save Link function",$showdoc).'</table></p>');
861: }
862: }
863: $r->print('</body></html>');
864: return OK;
865: }
866:
867: 1;
868: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>