Annotation of loncom/interface/londocs.pm, revision 1.10
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.10 ! www 4: # $Id: londocs.pm,v 1.9 2002/08/21 17:18:08 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;
32: use Apache::Constants qw(:common);
1.4 www 33: use Apache::lonnet;
34: use Apache::loncommon;
1.7 www 35: use Apache::lonratedt;
36: use Apache::lonratsrv;
37:
1.8 www 38: my $iconpath;
1.7 www 39:
40: # Mapread read maps into lonratedt::global arrays
1.10 ! www 41: # @order and @resources, determines status
1.7 www 42: # sets @order - pointer to resources in right order
43: # sets @resources - array with the resources with correct idx
44: #
45:
46: sub mapread {
47: my ($coursenum,$coursedom,$map)=@_;
48: return
49: &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
50: $map);
51: }
52:
53: sub storemap {
54: my ($coursenum,$coursedom,$map)=@_;
55: return
56: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
57: $map);
58: }
59:
60: sub editor {
61: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
1.10 ! www 62: my $errtext='';
! 63: my $fatal=0;
! 64: ($errtext,$fatal)=
1.7 www 65: &mapread($coursenum,$coursedom,$folder.'.sequence');
66: if ($fatal) {
67: $r->print('<p><font color="red">'.$errtext.'</font></p>');
68: } else {
69: # ------------------------------------------------------------ Process commands
70: if ($allowed) {
1.10 ! www 71: # upload a file, if present
! 72: if (($ENV{'form.uploaddoc.filename'}) &&
! 73: ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
! 74: if ($folder=~/^$1/) {
! 75: # this is for a course, not a user, so set coursedoc flag
! 76: # probably the only place in the system where this should be "1"
! 77: my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
! 78: my $ext='false';
! 79: if ($url=~/^http\:\/\//) { $ext='true'; }
! 80: $url=~s/\:/\:/g;
! 81: my $comment=$ENV{'form.comment'};
! 82: $comment=~s/\</\<\;/g;
! 83: $comment=~s/\>/\>\;/g;
! 84: $comment=~s/\:/\:/g;
! 85: my $newidx=$#Apache::lonratedt::resources+1;
! 86: $Apache::lonratedt::resources[$newidx]=
! 87: $comment.':'.$url.':'.$ext.':normal:res';
! 88: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
! 89: $newidx;
! 90: &storemap($coursenum,$coursedom,$folder.'.sequence');
! 91: }
! 92: }
1.8 www 93: if ($ENV{'form.cmd'}) {
1.10 ! www 94: my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
! 95: if ($cmd eq 'del') {
! 96: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
! 97: $Apache::lonratedt::order[$i]=
! 98: $Apache::lonratedt::order[$i+1];
! 99: }
! 100: $#Apache::lonratedt::order--;
! 101: } elsif ($cmd eq 'up') {
! 102: my $i=$Apache::lonratedt::order[$idx-1];
! 103: $Apache::lonratedt::order[$idx-1]=
! 104: $Apache::lonratedt::order[$idx];
! 105: $Apache::lonratedt::order[$idx]=$i;
! 106: } elsif ($cmd eq 'down') {
! 107: my $i=$Apache::lonratedt::order[$idx+1];
! 108: $Apache::lonratedt::order[$idx+1]=
! 109: $Apache::lonratedt::order[$idx];
! 110: $Apache::lonratedt::order[$idx]=$i;
! 111: }
! 112: # Store the changed version
! 113: &storemap($coursenum,$coursedom,$folder.'.sequence');
1.8 www 114: }
1.7 www 115: }
116: # ---------------------------------------------------------------- Print screen
1.10 ! www 117: my $idx=0;
! 118: $r->print('<table>');
! 119: foreach (@Apache::lonratedt::order) {
! 120: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
! 121: unless ($name) { $name=(split(/\//,$url))[-1]; }
! 122: unless ($name) { $name='EMPTY'; }
! 123: $r->print(&entryline($idx,$name,$url,$folder,$allowed));
! 124: $idx++;
! 125: }
! 126: $r->print('</table>');
1.7 www 127: }
128: }
1.1 www 129:
1.8 www 130: # --------------------------------------------------------------- An entry line
131:
132: sub entryline {
133: my ($index,$title,$url,$folder,$allowed)=@_;
134: my $line='<tr>';
135: # Edit commands
136: if ($allowed) {
137: $line.=(<<END);
138: <td><table border='0' cellspacing='0' cellpadding='0'>
139: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
140: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
141: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
142: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
143: </table></td><td>
144: <a href='/adm/coursedocs?folder=$folder&cmd=del_$index'>Remove</td>
145: END
146: }
147: # URL
1.10 ! www 148: if ($url=~/^\/*uploaded\//) {
! 149: $url=&Apache::lonnet::tokenwrapper($url);
! 150: }
1.8 www 151: $line.='<td><a href="'.$url.'">View</a></td>';
152: # Title
153: $title=&Apache::lonnet::unescape($title);
154: if ($title=~
155: /^(\d+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(.*)$/
156: ) { $title='<i>'.localtime($1).'</i> '.$2.' at '.$3.': <br>'.
157: &Apache::lontexconvert::msgtexconverted($4);
158: }
1.10 ! www 159: $line.="<td>$title</td>";
1.8 www 160: $line.='</tr>';
161: return $line;
162: }
163:
164: # ================================================================ Main Handler
1.1 www 165: sub handler {
166: my $r = shift;
167: $r->content_type('text/html');
168: $r->send_http_header;
169: return OK if $r->header_only;
170:
1.7 www 171: # is this a standard course?
172:
173: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
174: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
175: my $forcestandard=($ENV{'form.folder'}=~/^default_/);
1.10 ! www 176: my $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1.7 www 177:
1.4 www 178: # does this user have privileges to post, etc?
179: my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
1.8 www 180: my $script='';
1.4 www 181: if ($allowed) {
1.8 www 182: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
183: $script=&Apache::lonratedt::editscript('docs');
1.3 www 184: }
1.4 www 185:
186: # get course data
187: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
188: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
189:
1.8 www 190: # graphics settings
1.4 www 191:
1.8 www 192: $iconpath = $r->dir_config('lonIconsURL') . "/";
193:
1.4 www 194: # print screen
1.1 www 195: $r->print(<<ENDDOCUMENT);
196: <html>
197: <head>
198: <title>The LearningOnline Network with CAPA</title>
1.8 www 199: <script>$script</script>
1.1 www 200: </head>
1.4 www 201: ENDDOCUMENT
1.9 www 202: $r->print(&Apache::loncommon::bodytag('Course Documents'));
1.7 www 203: # --------------------------------------------------0------ Standard documents
204: if (($standard) && ($allowed) && (!$forcesupplement)) {
205: $r->print('<h2>Main Course Documents</h2>');
206: my $folder=$ENV{'form.folder'};
1.10 ! www 207: unless ($folder=~/^default/) { $folder='default'; }
1.7 www 208: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 www 209: $r->print(<<ENDFORM);
210: <h3>Post a new main course document</h3>
1.10 ! www 211: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.8 www 212: <input type="file" name="uploaddoc" size="50">
213: <br />
214: Title: <input type="text" size="50" name="comment">
215: <input type="hidden" name="folder" value="$folder">
1.10 ! www 216: <input type="hidden" name="cmd" value="upload_default">
1.8 www 217: <input type="submit" value="Upload Document">
218: </form>
219: ENDFORM
1.7 www 220: $r->print('<hr />');
221: }
222: # ----------------------------------------------------- Supplemental documents
223: if (!$forcestandard) {
224: $r->print('<h2>Supplemental Course Documents</h2>');
225: my $folder=$ENV{'form.folder'};
1.10 ! www 226: unless ($folder=~/supplemental/) { $folder='supplemental'; }
1.7 www 227: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 www 228: if ($allowed) {
229: $r->print(<<ENDSUPFORM);
230: <h3>Post a new supplemental course document</h3>
1.10 ! www 231: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.4 www 232: <input type="file" name="uploaddoc" size="50">
233: <br />Comment:<br />
234: <textarea cols=50 rows=4 name='comment'>
235: </textarea>
1.8 www 236: <input type="hidden" name="folder" value="$folder">
1.10 ! www 237: <input type="hidden" name="cmd" value="upload_supplemental">
1.3 www 238: <input type="submit" value="Upload Document">
239: </form>
1.8 www 240: ENDSUPFORM
241: }
1.7 www 242: }
243:
1.4 www 244: $r->print('</body></html>');
1.1 www 245: return OK;
246: }
247:
248: 1;
249: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>