Annotation of loncom/interface/londocs.pm, revision 1.8
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.8 ! www 4: # $Id: londocs.pm,v 1.7 2002/08/19 21:15: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
41: # @links 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,$fatal)=
63: &mapread($coursenum,$coursedom,$folder.'.sequence');
64: if ($fatal) {
65: $r->print('<p><font color="red">'.$errtext.'</font></p>');
66: } else {
67: # ------------------------------------------------------------ Process commands
68: if ($allowed) {
1.8 ! www 69: if ($ENV{'form.cmd'}) {
! 70:
! 71: }
1.7 www 72: }
73: # ---------------------------------------------------------------- Print screen
74: }
75: }
1.1 www 76:
1.8 ! www 77: # --------------------------------------------------------------- An entry line
! 78:
! 79: sub entryline {
! 80: my ($index,$title,$url,$folder,$allowed)=@_;
! 81: my $line='<tr>';
! 82: # Edit commands
! 83: if ($allowed) {
! 84: $line.=(<<END);
! 85: <td><table border='0' cellspacing='0' cellpadding='0'>
! 86: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
! 87: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
! 88: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
! 89: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
! 90: </table></td><td>
! 91: <a href='/adm/coursedocs?folder=$folder&cmd=del_$index'>Remove</td>
! 92: END
! 93: }
! 94: # URL
! 95: $line.='<td><a href="'.$url.'">View</a></td>';
! 96: # Title
! 97: $title=&Apache::lonnet::unescape($title);
! 98: if ($title=~
! 99: /^(\d+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(.*)$/
! 100: ) { $title='<i>'.localtime($1).'</i> '.$2.' at '.$3.': <br>'.
! 101: &Apache::lontexconvert::msgtexconverted($4);
! 102: }
! 103: $line.='<td>$title</td>';
! 104: $line.='</tr>';
! 105: return $line;
! 106: }
! 107:
! 108: # ================================================================ Main Handler
1.1 www 109: sub handler {
110: my $r = shift;
111: $r->content_type('text/html');
112: $r->send_http_header;
113: return OK if $r->header_only;
114:
1.7 www 115: # is this a standard course?
116:
117: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
118: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
119: my $forcestandard=($ENV{'form.folder'}=~/^default_/);
120: my $forcesupplement=($ENV{'form.folder'}=~/^supplement_/);
121:
1.4 www 122: # does this user have privileges to post, etc?
123: my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
1.8 ! www 124: my $script='';
1.4 www 125: if ($allowed) {
1.8 ! www 126: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
! 127: $script=&Apache::lonratedt::editscript('docs');
1.3 www 128: }
1.4 www 129:
130: # get course data
131: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
132: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
133:
1.8 ! www 134: # graphics settings
1.4 www 135:
1.8 ! www 136: $iconpath = $r->dir_config('lonIconsURL') . "/";
! 137:
! 138: # upload a file, if present
1.4 www 139: if (($ENV{'form.uploaddoc.filename'}) && ($allowed)) {
1.6 www 140: # this is for a course, not a user, so set coursedoc flag
141: # probably the only place in the system where this should be "1"
142: my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
1.8 ! www 143: my $comment=$ENV{'form.comment'};
! 144: $comment=~s/\</\<\;/g;
! 145: $comment=~s/\>/\>\;/g;
1.4 www 146: }
147:
148: # print screen
1.1 www 149: $r->print(<<ENDDOCUMENT);
150: <html>
151: <head>
152: <title>The LearningOnline Network with CAPA</title>
1.8 ! www 153: <script>$script</script>
1.1 www 154: </head>
155: <body bgcolor="#FFFFFF">
1.3 www 156: <h1>Course Documents</h1>
1.4 www 157: ENDDOCUMENT
1.7 www 158: # --------------------------------------------------0------ Standard documents
159: if (($standard) && ($allowed) && (!$forcesupplement)) {
160: $r->print('<h2>Main Course Documents</h2>');
161: my $folder=$ENV{'form.folder'};
162: unless ($folder) { $folder='default'; }
163: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 ! www 164: $r->print(<<ENDFORM);
! 165: <h3>Post a new main course document</h3>
! 166: <form method="post" enctype="multipart/form-data">
! 167: <input type="file" name="uploaddoc" size="50">
! 168: <br />
! 169: Title: <input type="text" size="50" name="comment">
! 170: <input type="hidden" name="folder" value="$folder">
! 171: <input type="hidden" name="cmd" value="upload_main">
! 172: <input type="submit" value="Upload Document">
! 173: </form>
! 174: ENDFORM
1.7 www 175: $r->print('<hr />');
176: }
177: # ----------------------------------------------------- Supplemental documents
178: if (!$forcestandard) {
179: $r->print('<h2>Supplemental Course Documents</h2>');
180: my $folder=$ENV{'form.folder'};
181: unless ($folder) { $folder='supplemental'; }
182: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 ! www 183: if ($allowed) {
! 184: $r->print(<<ENDSUPFORM);
! 185: <h3>Post a new supplemental course document</h3>
1.3 www 186: <form method="post" enctype="multipart/form-data">
1.4 www 187: <input type="file" name="uploaddoc" size="50">
188: <br />Comment:<br />
189: <textarea cols=50 rows=4 name='comment'>
190: </textarea>
1.8 ! www 191: <input type="hidden" name="folder" value="$folder">
! 192: <input type="hidden" name="cmd" value="upload_suppl">
1.3 www 193: <input type="submit" value="Upload Document">
194: </form>
1.8 ! www 195: ENDSUPFORM
! 196: }
1.7 www 197: }
198:
1.4 www 199: $r->print('</body></html>');
1.1 www 200: return OK;
201: }
202:
203: 1;
204: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>