Annotation of loncom/interface/londocs.pm, revision 1.14
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.14 ! www 4: # $Id: londocs.pm,v 1.13 2002/08/28 14:11:27 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.11 www 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: }
1.7 www 137: }
138: # ---------------------------------------------------------------- Print screen
1.10 www 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>');
1.7 www 149: }
150: }
1.1 www 151:
1.8 www 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
1.10 www 170: if ($url=~/^\/*uploaded\//) {
171: $url=&Apache::lonnet::tokenwrapper($url);
172: }
1.8 www 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: }
1.10 www 181: $line.="<td>$title</td>";
1.8 www 182: $line.='</tr>';
183: return $line;
184: }
185:
186: # ================================================================ Main Handler
1.1 www 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:
1.7 www 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_/);
1.10 www 198: my $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1.7 www 199:
1.4 www 200: # does this user have privileges to post, etc?
201: my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
1.8 www 202: my $script='';
1.4 www 203: if ($allowed) {
1.8 www 204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1.11 www 205: $script=&Apache::lonratedt::editscript('simple');
1.3 www 206: }
1.4 www 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:
1.14 ! www 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:
1.8 www 219: # graphics settings
1.4 www 220:
1.8 www 221: $iconpath = $r->dir_config('lonIconsURL') . "/";
222:
1.4 www 223: # print screen
1.1 www 224: $r->print(<<ENDDOCUMENT);
225: <html>
226: <head>
227: <title>The LearningOnline Network with CAPA</title>
1.8 www 228: <script>$script</script>
1.1 www 229: </head>
1.4 www 230: ENDDOCUMENT
1.9 www 231: $r->print(&Apache::loncommon::bodytag('Course Documents'));
1.7 www 232: # --------------------------------------------------0------ Standard documents
233: if (($standard) && ($allowed) && (!$forcesupplement)) {
234: $r->print('<h2>Main Course Documents</h2>');
235: my $folder=$ENV{'form.folder'};
1.10 www 236: unless ($folder=~/^default/) { $folder='default'; }
1.7 www 237: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 www 238: $r->print(<<ENDFORM);
1.11 www 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 />
1.10 www 246: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.8 www 247: <input type="file" name="uploaddoc" size="50">
248: <br />
1.11 www 249: Title:<br />
250: <input type="text" size="50" name="comment">
1.8 www 251: <input type="hidden" name="folder" value="$folder">
1.10 www 252: <input type="hidden" name="cmd" value="upload_default">
1.8 www 253: <input type="submit" value="Upload Document">
254: </form>
1.11 www 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">
1.13 www 266: <input type=hidden name="importdetail" value="">
1.11 www 267: <input name="newfolder" type="button" onClick="javascript:newfolder();"
268: value="New Folder" />
269: </form>
270: <form action="/adm/coursedocs" method="post" name="newext">
1.13 www 271: <input type=hidden name="importdetail" value="">
1.11 www 272: <input name="newext" type="button" onClick="javascript:newext();"
273: value="External Resource" />
274: </form>
275: <form action="/adm/coursedocs" method="post" name="newsyl">
1.14 ! www 276: <input type=hidden name="importdetail"
! 277: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
! 278: <input name="newsyl" type="submit" value="Syllabus" />
1.12 www 279: </form>
280: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.14 ! www 281: <input type=hidden name="importdetail"
! 282: value="$plainname=/adm/$udom/$uname/aboutme">
! 283: <input name="newaboutme" type="submit" onClick="javascript:newaboutme();"
1.12 www 284: value="My Personal Info" />
1.11 www 285: </form>
286: </td></tr>
287: </table>
1.8 www 288: ENDFORM
1.7 www 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'};
1.10 www 295: unless ($folder=~/supplemental/) { $folder='supplemental'; }
1.7 www 296: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 www 297: if ($allowed) {
298: $r->print(<<ENDSUPFORM);
299: <h3>Post a new supplemental course document</h3>
1.10 www 300: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.4 www 301: <input type="file" name="uploaddoc" size="50">
302: <br />Comment:<br />
303: <textarea cols=50 rows=4 name='comment'>
304: </textarea>
1.8 www 305: <input type="hidden" name="folder" value="$folder">
1.10 www 306: <input type="hidden" name="cmd" value="upload_supplemental">
1.3 www 307: <input type="submit" value="Upload Document">
308: </form>
1.8 www 309: ENDSUPFORM
310: }
1.7 www 311: }
312:
1.4 www 313: $r->print('</body></html>');
1.1 www 314: return OK;
315: }
316:
317: 1;
318: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>