File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.21:
download - view:
text,
annotated -
select for diffs
Fri Sep 6 15:18:23 2002 UTC (21 years, 11 months ago) by
www
Branches:
MAIN
CVS tags:
HEAD
"showdoc" needs to be URL-encode like all the other functionality in order to
properly register with the remote. Remote has now additional fields to store symb, but
nothing is done with them yet. Eventually, this should improve navigation and contents
display for resources showing up multiple times.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.21 2002/09/06 15:18:23 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);
33: use Apache::lonnet;
34: use Apache::loncommon;
35: use Apache::lonratedt;
36: use Apache::lonratsrv;
37: use Apache::lonxml;
38:
39: my $iconpath;
40:
41: # Mapread read maps into lonratedt::global arrays
42: # @order and @resources, determines status
43: # sets @order - pointer to resources in right order
44: # sets @resources - array with the resources with correct idx
45: #
46:
47: sub mapread {
48: my ($coursenum,$coursedom,$map)=@_;
49: return
50: &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
51: $map);
52: }
53:
54: sub storemap {
55: my ($coursenum,$coursedom,$map)=@_;
56: return
57: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
58: $map,1);
59: }
60:
61: sub editor {
62: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
63: if ($ENV{'form.foldername'}) {
64: $r->print('<h3>Folder: '.$ENV{'form.foldername'}.'</h3>');
65: }
66: my $errtext='';
67: my $fatal=0;
68: ($errtext,$fatal)=
69: &mapread($coursenum,$coursedom,$folder.'.sequence');
70: if ($#Apache::lonratedt::order<1) {
71: $Apache::lonratedt::order[0]=1;
72: $Apache::lonratedt::resources[1]='';
73: }
74: if ($fatal) {
75: $r->print('<p><font color="red">'.$errtext.'</font></p>');
76: } else {
77: # ------------------------------------------------------------ Process commands
78: # ---------------- if they are for this folder and user allowed to make changes
79: if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
80: # upload a file, if present
81: if (($ENV{'form.uploaddoc.filename'}) &&
82: ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
83: if ($folder=~/^$1/) {
84: # this is for a course, not a user, so set coursedoc flag
85: # probably the only place in the system where this should be "1"
86: my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
87: my $ext='false';
88: if ($url=~/^http\:\/\//) { $ext='true'; }
89: $url=~s/\:/\:/g;
90: my $comment=$ENV{'form.comment'};
91: $comment=~s/\</\<\;/g;
92: $comment=~s/\>/\>\;/g;
93: $comment=~s/\:/\:/g;
94: if ($folder=~/^supplemental/) {
95: $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
96: $ENV{'user.domain'}.'___&&&___'.$comment;
97: }
98: my $newidx=$#Apache::lonratedt::resources+1;
99: $Apache::lonratedt::resources[$newidx]=
100: $comment.':'.$url.':'.$ext.':normal:res';
101: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
102: $newidx;
103: &storemap($coursenum,$coursedom,$folder.'.sequence');
104: }
105: }
106: if ($ENV{'form.cmd'}) {
107: my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
108: if ($cmd eq 'del') {
109: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
110: $Apache::lonratedt::order[$i]=
111: $Apache::lonratedt::order[$i+1];
112: }
113: $#Apache::lonratedt::order--;
114: } elsif ($cmd eq 'up') {
115: my $i=$Apache::lonratedt::order[$idx-1];
116: $Apache::lonratedt::order[$idx-1]=
117: $Apache::lonratedt::order[$idx];
118: $Apache::lonratedt::order[$idx]=$i;
119: } elsif ($cmd eq 'down') {
120: my $i=$Apache::lonratedt::order[$idx+1];
121: $Apache::lonratedt::order[$idx+1]=
122: $Apache::lonratedt::order[$idx];
123: $Apache::lonratedt::order[$idx]=$i;
124: }
125: # Store the changed version
126: &storemap($coursenum,$coursedom,$folder.'.sequence');
127: }
128: # Group import/search
129: if ($ENV{'form.importdetail'}) {
130: foreach (split(/\&/,$ENV{'form.importdetail'})) {
131: if (defined($_)) {
132: my ($name,$url)=split(/\=/,$_);
133: $name=&Apache::lonnet::unescape($name);
134: $url=&Apache::lonnet::unescape($url);
135: if ($url) {
136: my $idx=$#Apache::lonratedt::resources+1;
137: $Apache::lonratedt::order
138: [$#Apache::lonratedt::order+1]=$idx;
139: my $ext='false';
140: if ($url=~/^http\:\/\//) { $ext='true'; }
141: $url=~s/\:/\:/g;
142: $Apache::lonratedt::resources[$idx]=
143: $name.':'.$url.':'.$ext.':normal:res';
144: }
145: }
146: }
147: # Store the changed version
148: &storemap($coursenum,$coursedom,$folder.'.sequence');
149: }
150: }
151: # ---------------------------------------------------------------- End commands
152: # ---------------------------------------------------------------- Print screen
153: my $idx=0;
154: $r->print('<table>');
155: foreach (@Apache::lonratedt::order) {
156: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
157: unless ($name) { $name=(split(/\//,$url))[-1]; }
158: unless ($name) { $name='EMPTY'; }
159: $r->print(&entryline($idx,$name,$url,$folder,$allowed));
160: $idx++;
161: }
162: $r->print('</table>');
163: }
164: }
165:
166: # --------------------------------------------------------------- An entry line
167:
168: sub entryline {
169: my ($index,$title,$url,$folder,$allowed)=@_;
170: my $line='<tr>';
171: # Edit commands
172: if ($allowed) {
173: $line.=(<<END);
174: <td><table border='0' cellspacing='0' cellpadding='0'>
175: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
176: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
177: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
178: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
179: </table></td><td>
180: <a href='/adm/coursedocs?folder=$folder&cmd=del_$index'>Remove</td>
181: END
182: }
183: # Figure out what kind of a resource this is
184: my ($extension)=($url=~/\.(\w+)$/);
185: my $uploaded=($url=~/^\/*uploaded\//);
186: my $icon='unknown';
187: if (-e "/home/httpd/html/adm/lonIcons/$extension.gif") {
188: $icon=$extension;
189: }
190: my $isfolder=0;
191: if ($uploaded) {
192: if ($extension eq 'sequence') {
193: $icon='folder_closed';
194: $url=~/\/(\w+)\.sequence/;
195: $url='/adm/coursedocs?folder='.$1;
196: $isfolder=1;
197: } else {
198: $url=&Apache::lonnet::tokenwrapper($url);
199: }
200: }
201: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
202: # Title
203: $title=&Apache::lonnet::unescape($title);
204: my $foldertitle=$title;
205: if ($title=~
206: /^(\d+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(.*)$/
207: ) {
208: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
209: $title='<i>'.localtime($1).'</i> '.
210: &Apache::loncommon::plainname($2,$3).': <br>'.
211: $foldertitle;
212: }
213: if ($isfolder) { $url.='&foldername='.$foldertitle; }
214: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="/adm/lonIcons/'.
215: $icon.'.gif" border="0"></a></td>'.
216: "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td></tr>";
217: return $line;
218: }
219:
220: # ================================================================ Main Handler
221: sub handler {
222: my $r = shift;
223: $r->content_type('text/html');
224: $r->send_http_header;
225: return OK if $r->header_only;
226:
227: # is this a standard course?
228:
229: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
230: my $forcestandard;
231: my $forcesupplement;
232: my $script='';
233: my $allowed;
234: my $events='';
235: my $showdoc=0;
236: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
237: ['folder','foldername']);
238: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
239: $showdoc=$1;
240: }
241: unless ($showdoc) { # got called from remote
242: $forcestandard=($ENV{'form.folder'}=~/^default_/);
243: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
244:
245: # does this user have privileges to post, etc?
246: $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
247: if ($allowed) {
248: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
249: $script=&Apache::lonratedt::editscript('simple');
250: }
251: } else { # got called in sequence from course
252: $allowed=0;
253: $script='</script>'.&Apache::lonxml::registerurl(1,undef).'<script>';
254: $events='onLoad="'.&Apache::lonxml::loadevents.
255: '" onUnload="'.&Apache::lonxml::unloadevents.'"';
256: }
257:
258: # get course data
259: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
260: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
261:
262: # get personal data
263:
264: my $uname=$ENV{'user.name'};
265: my $udom=$ENV{'user.domain'};
266: my $plainname=&Apache::lonnet::escape(
267: &Apache::loncommon::plainname($uname,$udom));
268:
269: # graphics settings
270:
271: $iconpath = $r->dir_config('lonIconsURL') . "/";
272:
273: # print screen
274: $r->print(<<ENDDOCUMENT);
275: <html>
276: <head>
277: <title>The LearningOnline Network with CAPA</title>
278: <script>
279: $script
280: </script>
281: ENDDOCUMENT
282: if ($allowed) {
283: $r->print(<<ENDNEWSCRIPT);
284: <script>
285: function makenewfolder(targetform,folderseq) {
286: var foldername=prompt('Name of New Folder','New Folder');
287: if (foldername) {
288: targetform.importdetail.value=foldername+"="+folderseq;
289: targetform.submit();
290: }
291: }
292:
293: function makenewext(targetname) {
294: this.document.forms.extimport.useform.value=targetname;
295: window.open('/adm/rat/extpickframe.html');
296: }
297:
298: function finishpick() {
299: var title=this.document.forms.extimport.title.value;
300: var url=this.document.forms.extimport.url.value;
301: var form=this.document.forms.extimport.useform.value;
302: eval
303: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
304: '";this.document.forms.'+form+'.submit();');
305: }
306: </script>
307: ENDNEWSCRIPT
308: }
309: # -------------------------------------------------------------------- Body tag
310: $r->print('</head>'.
311: &Apache::loncommon::bodytag('Course Documents','',$events));
312: unless ($showdoc) {
313: # --------------------------------------------------------- Standard documents
314: if (($standard) && ($allowed) && (!$forcesupplement)) {
315: $r->print('<h2>Main Course Documents</h2>');
316: my $folder=$ENV{'form.folder'};
317: unless ($folder=~/^default/) { $folder='default'; }
318: &editor($r,$coursenum,$coursedom,$folder,$allowed);
319: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
320: '.sequence';
321: $r->print(<<ENDFORM);
322: <table cellspacing=2><tr>
323: <th bgcolor="#DDDDDD">Upload a new main course document</th>
324: <th bgcolor="#DDDDDD">Import a published document</th>
325: <th bgcolor="#DDDDDD">Special documents</th>
326: </tr>
327: <tr><td bgcolor="#DDDDDD">
328: File:<br />
329: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
330: <input type="file" name="uploaddoc" size="50">
331: <br />
332: Title:<br />
333: <input type="text" size="50" name="comment">
334: <input type="hidden" name="folder" value="$folder">
335: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
336: <input type="hidden" name="cmd" value="upload_default">
337: <input type="submit" value="Upload Document">
338: </form>
339: </td>
340: <td bgcolor="#DDDDDD">
341: <form action="/adm/coursedocs" method="post" name="simpleedit">
342: <input type="hidden" name="folder" value="$folder">
343: <input type=hidden name="importdetail" value="">
344: <input type=button onClick=
345: "javascript:groupsearch()" value="Search">
346: <input type=button onClick=
347: "javascript:groupimport();" value="Import">
348: </form>
349: </td><td bgcolor="#DDDDDD">
350: <form action="/adm/coursedocs" method="post" name="newfolder">
351: <input type="hidden" name="folder" value="$folder">
352: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
353: <input type=hidden name="importdetail" value="">
354: <input name="newfolder" type="button"
355: onClick="javascript:makenewfolder(this.form,'$folderseq');"
356: value="New Folder" />
357: </form>
358: <form action="/adm/coursedocs" method="post" name="newext">
359: <input type="hidden" name="folder" value="$folder">
360: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
361: <input type=hidden name="importdetail" value="">
362: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
363: value="External Resource" />
364: </form>
365: <form action="/adm/coursedocs" method="post" name="newsyl">
366: <input type="hidden" name="folder" value="$folder">
367: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
368: <input type=hidden name="importdetail"
369: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
370: <input name="newsyl" type="submit" value="Syllabus" />
371: </form>
372: <form action="/adm/coursedocs" method="post" name="newnav">
373: <input type="hidden" name="folder" value="$folder">
374: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
375: <input type=hidden name="importdetail"
376: value="Navigate Content=/adm/navmaps">
377: <input name="newnav" type="submit" value="Navigate Content" />
378: </form>
379: <form action="/adm/coursedocs" method="post" name="newaboutme">
380: <input type="hidden" name="folder" value="$folder">
381: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
382: <input type=hidden name="importdetail"
383: value="$plainname=/adm/$udom/$uname/aboutme">
384: <input name="newaboutme" type="submit" value="My Personal Info" />
385: </form>
386: </td></tr>
387: </table>
388: ENDFORM
389: $r->print('<hr />');
390: }
391: # ----------------------------------------------------- Supplemental documents
392: if (!$forcestandard) {
393: $r->print('<h2>Supplemental Course Documents</h2>');
394: my $folder=$ENV{'form.folder'};
395: unless ($folder=~/supplemental/) { $folder='supplemental'; }
396: &editor($r,$coursenum,$coursedom,$folder,$allowed);
397: if ($allowed) {
398: my $folderseq=
399: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
400: '.sequence';
401:
402: $r->print(<<ENDSUPFORM);
403: <table cellspacing=2><tr>
404: <th bgcolor="#DDDDDD">Upload a new supplemental course document</th>
405: <th bgcolor="#DDDDDD">Import a published document</th>
406: <th bgcolor="#DDDDDD">Special documents</th>
407: </tr>
408: <tr><td bgcolor="#DDDDDD">
409: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
410: <input type="file" name="uploaddoc" size="50">
411: <br />Comment:<br />
412: <textarea cols=50 rows=4 name='comment'>
413: </textarea>
414: <input type="hidden" name="folder" value="$folder">
415: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
416: <input type="hidden" name="cmd" value="upload_supplemental">
417: <input type="submit" value="Upload Document">
418: </form>
419: </td>
420: <td bgcolor="#DDDDDD">
421: <form action="/adm/coursedocs" method="post" name="simpleedit">
422: <input type="hidden" name="folder" value="$folder">
423: <input type=hidden name="importdetail" value="">
424: <input type=button onClick=
425: "javascript:groupsearch()" value="Search">
426: <input type=button onClick=
427: "javascript:groupimport();" value="Import">
428: </form>
429: </td><td bgcolor="#DDDDDD">
430: <form action="/adm/coursedocs" method="post" name="supnewfolder">
431: <input type="hidden" name="folder" value="$folder">
432: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
433: <input type=hidden name="importdetail" value="">
434: <input name="newfolder" type="button"
435: onClick="javascript:makenewfolder(this.form,'$folderseq');"
436: value="New Folder" />
437: </form>
438: <form action="/adm/coursedocs" method="post" name="supnewext">
439: <input type="hidden" name="folder" value="$folder">
440: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
441: <input type=hidden name="importdetail" value="">
442: <input name="newext" type="button"
443: onClick="javascript:makenewext('supnewext');"
444: value="External Resource" />
445: </form>
446: <form action="/adm/coursedocs" method="post" name="supnewsyl">
447: <input type="hidden" name="folder" value="$folder">
448: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
449: <input type=hidden name="importdetail"
450: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
451: <input name="newsyl" type="submit" value="Syllabus" />
452: </form>
453: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
454: <input type="hidden" name="folder" value="$folder">
455: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
456: <input type=hidden name="importdetail"
457: value="$plainname=/adm/$udom/$uname/aboutme">
458: <input name="newaboutme" type="submit" value="My Personal Info" />
459: </form>
460: </td></tr>
461: </table>
462: ENDSUPFORM
463: }
464: }
465: if ($allowed) {
466: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
467: }
468: } else {
469: # -------------------------------------------------------- This is showdoc mode
470: $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>".
471: &entryline(0,"Click to download or use your browser's Save Link function",$showdoc).'</table></p>');
472: }
473: $r->print('</body></html>');
474: return OK;
475: }
476:
477: 1;
478: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>