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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Documents
1.1       www         3: #
1.4     ! www         4: # $Id: londocs.pm,v 1.3 2002/07/31 13:50:38 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/\</\&lt\;/g;
        !            63:            $comment=~s/\>/\&gt\;/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>'.
        !            93: 		     $currentdocs{$1.'_'.$2.'_'.$3.'.comment'}.
        !            94:                      '</blockquote><a href="'.$currentdocs{$_}.'">View</a>');
        !            95:        }
        !            96:    }
        !            97: # ----------------------------------------------------------------- Upload form
        !            98:    if ($allowed) {
        !            99:        $r->print(<<ENDFORM);
        !           100: <hr />
        !           101: <h3>Post a new course document</h3>
1.3       www       102: <form method="post" enctype="multipart/form-data">
1.4     ! www       103: <input type="file" name="uploaddoc" size="50">
        !           104: <br />Comment:<br />
        !           105: <textarea cols=50 rows=4 name='comment'>
        !           106: </textarea>
1.3       www       107: <input type="submit" value="Upload Document">
                    108: </form>
1.4     ! www       109: ENDFORM
        !           110:     }
        !           111:     $r->print('</body></html>');
1.1       www       112:     return OK;
                    113: } 
                    114: 
                    115: 1;
                    116: __END__

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