Annotation of loncom/interface/londocs.pm, revision 1.7
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.7 ! www 4: # $Id: londocs.pm,v 1.6 2002/08/01 15:26:23 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:
! 38:
! 39: # Mapread read maps into lonratedt::global arrays
! 40: # @links and @resources, determines status
! 41: # sets @order - pointer to resources in right order
! 42: # sets @resources - array with the resources with correct idx
! 43: #
! 44:
! 45: sub mapread {
! 46: my ($coursenum,$coursedom,$map)=@_;
! 47: return
! 48: &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
! 49: $map);
! 50: }
! 51:
! 52: sub storemap {
! 53: my ($coursenum,$coursedom,$map)=@_;
! 54: return
! 55: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
! 56: $map);
! 57: }
! 58:
! 59: sub editor {
! 60: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
! 61: my ($errtext,$fatal)=
! 62: &mapread($coursenum,$coursedom,$folder.'.sequence');
! 63: if ($fatal) {
! 64: $r->print('<p><font color="red">'.$errtext.'</font></p>');
! 65: } else {
! 66: # ------------------------------------------------------------ Process commands
! 67: if ($allowed) {
! 68: }
! 69: # ---------------------------------------------------------------- Print screen
! 70: }
! 71: }
1.1 www 72:
73: sub handler {
74: my $r = shift;
75: $r->content_type('text/html');
76: $r->send_http_header;
77: return OK if $r->header_only;
78:
1.7 ! www 79: # is this a standard course?
! 80:
! 81: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
! 82: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
! 83: my $forcestandard=($ENV{'form.folder'}=~/^default_/);
! 84: my $forcesupplement=($ENV{'form.folder'}=~/^supplement_/);
! 85:
1.4 www 86: # does this user have privileges to post, etc?
87: my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
1.3 www 88:
1.4 www 89: if ($allowed) {
90: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.7 ! www 91: ['remove']);
1.3 www 92: }
1.4 www 93:
94: # get course data
95: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
96: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
97:
98:
99: # upload a file
100: if (($ENV{'form.uploaddoc.filename'}) && ($allowed)) {
101: my $id=time.'_'.$ENV{'user.name'}.'_'.$ENV{'user.domain'};
1.6 www 102: # this is for a course, not a user, so set coursedoc flag
103: # probably the only place in the system where this should be "1"
104: my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
1.4 www 105: if ($url=~/^error\:/) {
106: } else {
107: my $comment=$ENV{'form.comment'};
108: $comment=~s/\</\<\;/g;
109: $comment=~s/\>/\>\;/g;
110: &Apache::lonnet::put('coursedocs',
111: { $id.'.url' => $url,
112: $id.'.comment' => $comment },
113: $coursedom,$coursenum);
114: }
115: }
116:
117: # delete a file
118: if ($ENV{'form.remove'}=~/$ENV{'user.name'}\_$ENV{'user.domain'}$/) {
119: my $id=$ENV{'form.remove'};
120: &Apache::lonnet::del('coursedocs',
121: [$id.'.url',$id.'.comment'],
122: $coursedom,$coursenum);
123: }
124:
125: # print screen
1.1 www 126: $r->print(<<ENDDOCUMENT);
127: <html>
128: <head>
129: <title>The LearningOnline Network with CAPA</title>
130: </head>
131: <body bgcolor="#FFFFFF">
1.3 www 132: <h1>Course Documents</h1>
1.4 www 133: ENDDOCUMENT
1.7 ! www 134: # --------------------------------------------------0------ Standard documents
! 135: if (($standard) && ($allowed) && (!$forcesupplement)) {
! 136: $r->print('<h2>Main Course Documents</h2>');
! 137: my $folder=$ENV{'form.folder'};
! 138: unless ($folder) { $folder='default'; }
! 139: &editor($r,$coursenum,$coursedom,$folder,$allowed);
! 140: $r->print('<hr />');
! 141: }
! 142: # ----------------------------------------------------- Supplemental documents
! 143: if (!$forcestandard) {
! 144: $r->print('<h2>Supplemental Course Documents</h2>');
! 145: my $folder=$ENV{'form.folder'};
! 146: unless ($folder) { $folder='supplemental'; }
! 147: &editor($r,$coursenum,$coursedom,$folder,$allowed);
! 148: }
1.4 www 149: # ------------------------------------------------------- Print headers to docs
150: my %currentdocs=&Apache::lonnet::dump('coursedocs',$coursedom,$coursenum);
151: foreach (sort keys (%currentdocs)) {
152: if ($_=~/(\d+)\_(\w+)\_(\w+)\.url/) {
153: $r->print('<hr>'.localtime($1).' '.$2.' '.$3.'<blockquote>'.
1.5 www 154: &Apache::lontexconvert::msgtexconverted(
155: $currentdocs{$1.'_'.$2.'_'.$3.'.comment'}
156: ).
157: '</blockquote><a href="'.
158: &Apache::lonnet::tokenwrapper($currentdocs{$_}).'">View</a>');
159: if (($2 eq $ENV{'user.name'}) && ($3 eq $ENV{'user.domain'})
160: && ($allowed)) {
161: $r->print(' <a href="/adm/coursedocs?remove='.
162: $1.'_'.$2.'_'.$3.'">Remove</a>');
163: }
1.4 www 164: }
165: }
166: # ----------------------------------------------------------------- Upload form
167: if ($allowed) {
168: $r->print(<<ENDFORM);
169: <hr />
170: <h3>Post a new course document</h3>
1.3 www 171: <form method="post" enctype="multipart/form-data">
1.4 www 172: <input type="file" name="uploaddoc" size="50">
173: <br />Comment:<br />
174: <textarea cols=50 rows=4 name='comment'>
175: </textarea>
1.3 www 176: <input type="submit" value="Upload Document">
177: </form>
1.4 www 178: ENDFORM
179: }
1.7 ! www 180:
! 181: foreach (@Apache::lonratedt::resources) {
! 182: $r->print($_.'<br>');
! 183: }
! 184:
1.4 www 185: $r->print('</body></html>');
1.1 www 186: return OK;
187: }
188:
189: 1;
190: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>