1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.14 2002/08/31 00:43:12 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: # Group import/search
116: if ($ENV{'form.importdetail'}) {
117: foreach (split(/\&/,$ENV{'form.importdetail'})) {
118: if (defined($_)) {
119: my ($name,$url)=split(/\=/,$_);
120: $name=&Apache::lonnet::unescape($name);
121: $url=&Apache::lonnet::unescape($url);
122: if ($url) {
123: my $idx=$#Apache::lonratedt::resources+1;
124: $Apache::lonratedt::order
125: [$#Apache::lonratedt::order+1]=$idx;
126: my $ext='false';
127: if ($url=~/^http\:\/\//) { $ext='true'; }
128: $url=~s/\:/\:/g;
129: $Apache::lonratedt::resources[$idx]=
130: $name.':'.$url.':'.$ext.':normal:res';
131: }
132: }
133: }
134: # Store the changed version
135: &storemap($coursenum,$coursedom,$folder.'.sequence');
136: }
137: }
138: # ---------------------------------------------------------------- Print screen
139: my $idx=0;
140: $r->print('<table>');
141: foreach (@Apache::lonratedt::order) {
142: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
143: unless ($name) { $name=(split(/\//,$url))[-1]; }
144: unless ($name) { $name='EMPTY'; }
145: $r->print(&entryline($idx,$name,$url,$folder,$allowed));
146: $idx++;
147: }
148: $r->print('</table>');
149: }
150: }
151:
152: # --------------------------------------------------------------- An entry line
153:
154: sub entryline {
155: my ($index,$title,$url,$folder,$allowed)=@_;
156: my $line='<tr>';
157: # Edit commands
158: if ($allowed) {
159: $line.=(<<END);
160: <td><table border='0' cellspacing='0' cellpadding='0'>
161: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
162: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
163: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
164: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
165: </table></td><td>
166: <a href='/adm/coursedocs?folder=$folder&cmd=del_$index'>Remove</td>
167: END
168: }
169: # URL
170: if ($url=~/^\/*uploaded\//) {
171: $url=&Apache::lonnet::tokenwrapper($url);
172: }
173: $line.='<td><a href="'.$url.'">View</a></td>';
174: # Title
175: $title=&Apache::lonnet::unescape($title);
176: if ($title=~
177: /^(\d+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(.*)$/
178: ) { $title='<i>'.localtime($1).'</i> '.$2.' at '.$3.': <br>'.
179: &Apache::lontexconvert::msgtexconverted($4);
180: }
181: $line.="<td>$title</td>";
182: $line.='</tr>';
183: return $line;
184: }
185:
186: # ================================================================ Main Handler
187: sub handler {
188: my $r = shift;
189: $r->content_type('text/html');
190: $r->send_http_header;
191: return OK if $r->header_only;
192:
193: # is this a standard course?
194:
195: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
196: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
197: my $forcestandard=($ENV{'form.folder'}=~/^default_/);
198: my $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
199:
200: # does this user have privileges to post, etc?
201: my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
202: my $script='';
203: if ($allowed) {
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
205: $script=&Apache::lonratedt::editscript('simple');
206: }
207:
208: # get course data
209: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
210: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
211:
212: # get personal data
213:
214: my $uname=$ENV{'user.name'};
215: my $udom=$ENV{'user.domain'};
216: my $plainname=&Apache::lonnet::escape(
217: &Apache::loncommon::plainname($uname,$udom));
218:
219: # graphics settings
220:
221: $iconpath = $r->dir_config('lonIconsURL') . "/";
222:
223: # print screen
224: $r->print(<<ENDDOCUMENT);
225: <html>
226: <head>
227: <title>The LearningOnline Network with CAPA</title>
228: <script>$script</script>
229: </head>
230: ENDDOCUMENT
231: $r->print(&Apache::loncommon::bodytag('Course Documents'));
232: # --------------------------------------------------0------ Standard documents
233: if (($standard) && ($allowed) && (!$forcesupplement)) {
234: $r->print('<h2>Main Course Documents</h2>');
235: my $folder=$ENV{'form.folder'};
236: unless ($folder=~/^default/) { $folder='default'; }
237: &editor($r,$coursenum,$coursedom,$folder,$allowed);
238: $r->print(<<ENDFORM);
239: <table><tr>
240: <th>Upload a new main course document</th>
241: <th>Import a published document</th>
242: <th>Special documents</th>
243: </tr>
244: <tr><td>
245: File:<br />
246: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
247: <input type="file" name="uploaddoc" size="50">
248: <br />
249: Title:<br />
250: <input type="text" size="50" name="comment">
251: <input type="hidden" name="folder" value="$folder">
252: <input type="hidden" name="cmd" value="upload_default">
253: <input type="submit" value="Upload Document">
254: </form>
255: </td>
256: <td>
257: <form action="/adm/coursedocs" method="post" name="simpleedit">
258: <input type=hidden name="importdetail" value="">
259: <input type=button onClick=
260: "javascript:groupsearch()" value="Group Search">
261: <input type=button onClick=
262: "javascript:groupimport();" value="Group Import">
263: </form>
264: </td><td>
265: <form action="/adm/coursedocs" method="post" name="newfolder">
266: <input type=hidden name="importdetail" value="">
267: <input name="newfolder" type="button" onClick="javascript:newfolder();"
268: value="New Folder" />
269: </form>
270: <form action="/adm/coursedocs" method="post" name="newext">
271: <input type=hidden name="importdetail" value="">
272: <input name="newext" type="button" onClick="javascript:newext();"
273: value="External Resource" />
274: </form>
275: <form action="/adm/coursedocs" method="post" name="newsyl">
276: <input type=hidden name="importdetail"
277: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
278: <input name="newsyl" type="submit" value="Syllabus" />
279: </form>
280: <form action="/adm/coursedocs" method="post" name="newaboutme">
281: <input type=hidden name="importdetail"
282: value="$plainname=/adm/$udom/$uname/aboutme">
283: <input name="newaboutme" type="submit" onClick="javascript:newaboutme();"
284: value="My Personal Info" />
285: </form>
286: </td></tr>
287: </table>
288: ENDFORM
289: $r->print('<hr />');
290: }
291: # ----------------------------------------------------- Supplemental documents
292: if (!$forcestandard) {
293: $r->print('<h2>Supplemental Course Documents</h2>');
294: my $folder=$ENV{'form.folder'};
295: unless ($folder=~/supplemental/) { $folder='supplemental'; }
296: &editor($r,$coursenum,$coursedom,$folder,$allowed);
297: if ($allowed) {
298: $r->print(<<ENDSUPFORM);
299: <h3>Post a new supplemental course document</h3>
300: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
301: <input type="file" name="uploaddoc" size="50">
302: <br />Comment:<br />
303: <textarea cols=50 rows=4 name='comment'>
304: </textarea>
305: <input type="hidden" name="folder" value="$folder">
306: <input type="hidden" name="cmd" value="upload_supplemental">
307: <input type="submit" value="Upload Document">
308: </form>
309: ENDSUPFORM
310: }
311: }
312:
313: $r->print('</body></html>');
314: return OK;
315: }
316:
317: 1;
318: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>