File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.6:
download - view:
text,
annotated -
select for diffs
Thu Aug 1 15:26:23 2002 UTC (22 years ago) by
www
Branches:
MAIN
CVS tags:
version_0_5_1,
version_0_5,
HEAD
Following public outcry, the logic of user file uploads is being changed.
This does currently not work anymore.
Plan:
When file is uploaded, the home server of course or user is notified to grep
the file (lond command needed for that) - goes into user home dir
When file is requested, home server checks session environment of user for
access permission to file (lond command needed for that)
Modification of lontokacc needed to be more like lonracc for inter-server
transfer
URL redirect needed for actual download on homeserver
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.6 2002/08/01 15:26:23 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:
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:
42: # does this user have privileges to post, etc?
43: my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
44:
45: if ($allowed) {
46: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
47: ['remove'])
48: }
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: # this is for a course, not a user, so set coursedoc flag
59: # probably the only place in the system where this should be "1"
60: my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
61: if ($url=~/^error\:/) {
62: } else {
63: my $comment=$ENV{'form.comment'};
64: $comment=~s/\</\<\;/g;
65: $comment=~s/\>/\>\;/g;
66: &Apache::lonnet::put('coursedocs',
67: { $id.'.url' => $url,
68: $id.'.comment' => $comment },
69: $coursedom,$coursenum);
70: }
71: }
72:
73: # delete a file
74: if ($ENV{'form.remove'}=~/$ENV{'user.name'}\_$ENV{'user.domain'}$/) {
75: my $id=$ENV{'form.remove'};
76: &Apache::lonnet::del('coursedocs',
77: [$id.'.url',$id.'.comment'],
78: $coursedom,$coursenum);
79: }
80:
81: # print screen
82: $r->print(<<ENDDOCUMENT);
83: <html>
84: <head>
85: <title>The LearningOnline Network with CAPA</title>
86: </head>
87: <body bgcolor="#FFFFFF">
88: <h1>Course Documents</h1>
89: ENDDOCUMENT
90: # ------------------------------------------------------- Print headers to docs
91: my %currentdocs=&Apache::lonnet::dump('coursedocs',$coursedom,$coursenum);
92: foreach (sort keys (%currentdocs)) {
93: if ($_=~/(\d+)\_(\w+)\_(\w+)\.url/) {
94: $r->print('<hr>'.localtime($1).' '.$2.' '.$3.'<blockquote>'.
95: &Apache::lontexconvert::msgtexconverted(
96: $currentdocs{$1.'_'.$2.'_'.$3.'.comment'}
97: ).
98: '</blockquote><a href="'.
99: &Apache::lonnet::tokenwrapper($currentdocs{$_}).'">View</a>');
100: if (($2 eq $ENV{'user.name'}) && ($3 eq $ENV{'user.domain'})
101: && ($allowed)) {
102: $r->print(' <a href="/adm/coursedocs?remove='.
103: $1.'_'.$2.'_'.$3.'">Remove</a>');
104: }
105: }
106: }
107: # ----------------------------------------------------------------- Upload form
108: if ($allowed) {
109: $r->print(<<ENDFORM);
110: <hr />
111: <h3>Post a new course document</h3>
112: <form method="post" enctype="multipart/form-data">
113: <input type="file" name="uploaddoc" size="50">
114: <br />Comment:<br />
115: <textarea cols=50 rows=4 name='comment'>
116: </textarea>
117: <input type="submit" value="Upload Document">
118: </form>
119: ENDFORM
120: }
121: $r->print('</body></html>');
122: return OK;
123: }
124:
125: 1;
126: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>