Annotation of loncom/interface/londocs.pm, revision 1.6

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Documents
1.1       www         3: #
1.6     ! www         4: # $Id: londocs.pm,v 1.5 2002/07/31 15:23:55 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'};
1.6     ! www        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);
1.4       www        61:         if ($url=~/^error\:/) {
                     62:         } else {
                     63: 	    my $comment=$ENV{'form.comment'};
                     64:            $comment=~s/\</\&lt\;/g;
                     65:            $comment=~s/\>/\&gt\;/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
1.1       www        82:     $r->print(<<ENDDOCUMENT);
                     83: <html>
                     84: <head>
                     85: <title>The LearningOnline Network with CAPA</title>
                     86: </head>
                     87: <body bgcolor="#FFFFFF">
1.3       www        88: <h1>Course Documents</h1>
1.4       www        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>'.
1.5       www        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: 	   }
1.4       www       105:        }
                    106:    }
                    107: # ----------------------------------------------------------------- Upload form
                    108:    if ($allowed) {
                    109:        $r->print(<<ENDFORM);
                    110: <hr />
                    111: <h3>Post a new course document</h3>
1.3       www       112: <form method="post" enctype="multipart/form-data">
1.4       www       113: <input type="file" name="uploaddoc" size="50">
                    114: <br />Comment:<br />
                    115: <textarea cols=50 rows=4 name='comment'>
                    116: </textarea>
1.3       www       117: <input type="submit" value="Upload Document">
                    118: </form>
1.4       www       119: ENDFORM
                    120:     }
                    121:     $r->print('</body></html>');
1.1       www       122:     return OK;
                    123: } 
                    124: 
                    125: 1;
                    126: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>