Annotation of loncom/interface/londocs.pm, revision 1.5
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.5 ! www 4: # $Id: londocs.pm,v 1.4 2002/07/31 14:56:36 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.1 www 35:
36: sub handler {
37: my $r = shift;
38: $r->content_type('text/html');
39: $r->send_http_header;
40: return OK if $r->header_only;
41:
1.4 www 42: # does this user have privileges to post, etc?
43: my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
1.3 www 44:
1.4 www 45: if ($allowed) {
46: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
47: ['remove'])
1.3 www 48: }
1.4 www 49:
50: # get course data
51: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
52: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
53:
54:
55: # upload a file
56: if (($ENV{'form.uploaddoc.filename'}) && ($allowed)) {
57: my $id=time.'_'.$ENV{'user.name'}.'_'.$ENV{'user.domain'};
58: my $url=&Apache::lonnet::userfileupload('uploaddoc');
59: if ($url=~/^error\:/) {
60: } else {
61: my $comment=$ENV{'form.comment'};
62: $comment=~s/\</\<\;/g;
63: $comment=~s/\>/\>\;/g;
64: &Apache::lonnet::put('coursedocs',
65: { $id.'.url' => $url,
66: $id.'.comment' => $comment },
67: $coursedom,$coursenum);
68: }
69: }
70:
71: # delete a file
72: if ($ENV{'form.remove'}=~/$ENV{'user.name'}\_$ENV{'user.domain'}$/) {
73: my $id=$ENV{'form.remove'};
74: &Apache::lonnet::del('coursedocs',
75: [$id.'.url',$id.'.comment'],
76: $coursedom,$coursenum);
77: }
78:
79: # print screen
1.1 www 80: $r->print(<<ENDDOCUMENT);
81: <html>
82: <head>
83: <title>The LearningOnline Network with CAPA</title>
84: </head>
85: <body bgcolor="#FFFFFF">
1.3 www 86: <h1>Course Documents</h1>
1.4 www 87: ENDDOCUMENT
88: # ------------------------------------------------------- Print headers to docs
89: my %currentdocs=&Apache::lonnet::dump('coursedocs',$coursedom,$coursenum);
90: foreach (sort keys (%currentdocs)) {
91: if ($_=~/(\d+)\_(\w+)\_(\w+)\.url/) {
92: $r->print('<hr>'.localtime($1).' '.$2.' '.$3.'<blockquote>'.
1.5 ! www 93: &Apache::lontexconvert::msgtexconverted(
! 94: $currentdocs{$1.'_'.$2.'_'.$3.'.comment'}
! 95: ).
! 96: '</blockquote><a href="'.
! 97: &Apache::lonnet::tokenwrapper($currentdocs{$_}).'">View</a>');
! 98: if (($2 eq $ENV{'user.name'}) && ($3 eq $ENV{'user.domain'})
! 99: && ($allowed)) {
! 100: $r->print(' <a href="/adm/coursedocs?remove='.
! 101: $1.'_'.$2.'_'.$3.'">Remove</a>');
! 102: }
1.4 www 103: }
104: }
105: # ----------------------------------------------------------------- Upload form
106: if ($allowed) {
107: $r->print(<<ENDFORM);
108: <hr />
109: <h3>Post a new course document</h3>
1.3 www 110: <form method="post" enctype="multipart/form-data">
1.4 www 111: <input type="file" name="uploaddoc" size="50">
112: <br />Comment:<br />
113: <textarea cols=50 rows=4 name='comment'>
114: </textarea>
1.3 www 115: <input type="submit" value="Upload Document">
116: </form>
1.4 www 117: ENDFORM
118: }
119: $r->print('</body></html>');
1.1 www 120: return OK;
121: }
122:
123: 1;
124: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>