1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.10 2002/08/26 12:44:45 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:
38: my $iconpath;
39:
40: # Mapread read maps into lonratedt::global arrays
41: # @order and @resources, determines status
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)=@_;
62: my $errtext='';
63: my $fatal=0;
64: ($errtext,$fatal)=
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) {
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: }
93: if ($ENV{'form.cmd'}) {
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');
114: }
115: }
116: # ---------------------------------------------------------------- Print screen
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>');
127: }
128: }
129:
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
148: if ($url=~/^\/*uploaded\//) {
149: $url=&Apache::lonnet::tokenwrapper($url);
150: }
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: }
159: $line.="<td>$title</td>";
160: $line.='</tr>';
161: return $line;
162: }
163:
164: # ================================================================ Main Handler
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:
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_/);
176: my $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
177:
178: # does this user have privileges to post, etc?
179: my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
180: my $script='';
181: if ($allowed) {
182: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
183: $script=&Apache::lonratedt::editscript('docs');
184: }
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:
190: # graphics settings
191:
192: $iconpath = $r->dir_config('lonIconsURL') . "/";
193:
194: # print screen
195: $r->print(<<ENDDOCUMENT);
196: <html>
197: <head>
198: <title>The LearningOnline Network with CAPA</title>
199: <script>$script</script>
200: </head>
201: ENDDOCUMENT
202: $r->print(&Apache::loncommon::bodytag('Course Documents'));
203: # --------------------------------------------------0------ Standard documents
204: if (($standard) && ($allowed) && (!$forcesupplement)) {
205: $r->print('<h2>Main Course Documents</h2>');
206: my $folder=$ENV{'form.folder'};
207: unless ($folder=~/^default/) { $folder='default'; }
208: &editor($r,$coursenum,$coursedom,$folder,$allowed);
209: $r->print(<<ENDFORM);
210: <h3>Post a new main course document</h3>
211: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
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">
216: <input type="hidden" name="cmd" value="upload_default">
217: <input type="submit" value="Upload Document">
218: </form>
219: ENDFORM
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'};
226: unless ($folder=~/supplemental/) { $folder='supplemental'; }
227: &editor($r,$coursenum,$coursedom,$folder,$allowed);
228: if ($allowed) {
229: $r->print(<<ENDSUPFORM);
230: <h3>Post a new supplemental course document</h3>
231: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
232: <input type="file" name="uploaddoc" size="50">
233: <br />Comment:<br />
234: <textarea cols=50 rows=4 name='comment'>
235: </textarea>
236: <input type="hidden" name="folder" value="$folder">
237: <input type="hidden" name="cmd" value="upload_supplemental">
238: <input type="submit" value="Upload Document">
239: </form>
240: ENDSUPFORM
241: }
242: }
243:
244: $r->print('</body></html>');
245: return OK;
246: }
247:
248: 1;
249: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>