File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.5: download - view: text, annotated - select for diffs
Wed Jul 31 15:23:55 2002 UTC (21 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Token security file upload

    1: # The LearningOnline Network
    2: # Documents
    3: #
    4: # $Id: londocs.pm,v 1.5 2002/07/31 15:23:55 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: 	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
   80:     $r->print(<<ENDDOCUMENT);
   81: <html>
   82: <head>
   83: <title>The LearningOnline Network with CAPA</title>
   84: </head>
   85: <body bgcolor="#FFFFFF">
   86: <h1>Course Documents</h1>
   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: 		     &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: 	   }
  103:        }
  104:    }
  105: # ----------------------------------------------------------------- Upload form
  106:    if ($allowed) {
  107:        $r->print(<<ENDFORM);
  108: <hr />
  109: <h3>Post a new course document</h3>
  110: <form method="post" enctype="multipart/form-data">
  111: <input type="file" name="uploaddoc" size="50">
  112: <br />Comment:<br />
  113: <textarea cols=50 rows=4 name='comment'>
  114: </textarea>
  115: <input type="submit" value="Upload Document">
  116: </form>
  117: ENDFORM
  118:     }
  119:     $r->print('</body></html>');
  120:     return OK;
  121: } 
  122: 
  123: 1;
  124: __END__

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