File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.8: download - view: text, annotated - select for diffs
Tue Aug 20 13:02:41 2002 UTC (21 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Unstable: interface to upload course documents.

    1: # The LearningOnline Network
    2: # Documents
    3: #
    4: # $Id: londocs.pm,v 1.8 2002/08/20 13:02:41 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: use Apache::lonratedt;
   36: use Apache::lonratsrv;
   37: 
   38: my $iconpath;
   39: 
   40: # Mapread read maps into lonratedt::global arrays 
   41: # @links and @resources, determines status
   42: # sets @order - pointer to resources in right order
   43: # sets @resources - array with the resources with correct idx
   44: #
   45: 
   46: sub mapread {
   47:     my ($coursenum,$coursedom,$map)=@_;
   48:     return
   49:       &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
   50:                                 $map);
   51: }
   52: 
   53: sub storemap {
   54:     my ($coursenum,$coursedom,$map)=@_;
   55:     return
   56:       &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
   57:                                 $map);
   58: }
   59: 
   60: sub editor {
   61:     my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
   62:     my ($errtext,$fatal)=
   63:           &mapread($coursenum,$coursedom,$folder.'.sequence');
   64:     if ($fatal) {
   65: 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
   66:     } else {
   67: # ------------------------------------------------------------ Process commands
   68: 	if ($allowed) {
   69: 	    if ($ENV{'form.cmd'}) {
   70: 
   71:             }
   72: 	}
   73: # ---------------------------------------------------------------- Print screen
   74:     }
   75: }
   76: 
   77: # --------------------------------------------------------------- An entry line
   78: 
   79: sub entryline {
   80:     my ($index,$title,$url,$folder,$allowed)=@_;
   81:     my $line='<tr>';
   82: # Edit commands
   83:     if ($allowed) {
   84:        $line.=(<<END);
   85: <td><table border='0' cellspacing='0' cellpadding='0'>
   86: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
   87: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
   88: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
   89: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
   90: </table></td><td>
   91: <a href='/adm/coursedocs?folder=$folder&cmd=del_$index'>Remove</td>
   92: END
   93:     }
   94: # URL
   95:     $line.='<td><a href="'.$url.'">View</a></td>';
   96: # Title
   97:     $title=&Apache::lonnet::unescape($title);
   98:     if ($title=~
   99:  /^(\d+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(.*)$/
  100: 	) { $title='<i>'.localtime($1).'</i> '.$2.' at '.$3.': <br>'.
  101: 		&Apache::lontexconvert::msgtexconverted($4);
  102: 	}
  103:     $line.='<td>$title</td>';
  104:     $line.='</tr>';
  105:     return $line;
  106: }
  107: 
  108: # ================================================================ Main Handler
  109: sub handler {
  110:     my $r = shift;
  111:     $r->content_type('text/html');
  112:     $r->send_http_header;
  113:     return OK if $r->header_only;
  114: 
  115: # is this a standard course?
  116: 
  117:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
  118:     my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
  119:     my $forcestandard=($ENV{'form.folder'}=~/^default_/);
  120:     my $forcesupplement=($ENV{'form.folder'}=~/^supplement_/);
  121: 
  122: # does this user have privileges to post, etc?
  123:     my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
  124:     my $script='';
  125:     if ($allowed) { 
  126:        &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
  127:        $script=&Apache::lonratedt::editscript('docs'); 
  128:     }
  129: 
  130: # get course data
  131:     my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
  132:     my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
  133: 
  134: # graphics settings
  135: 
  136:     $iconpath = $r->dir_config('lonIconsURL') . "/";
  137: 
  138: # upload a file, if present
  139:     if (($ENV{'form.uploaddoc.filename'}) && ($allowed)) {
  140: # this is for a course, not a user, so set coursedoc flag
  141: # probably the only place in the system where this should be "1"
  142: 	my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
  143: 	my $comment=$ENV{'form.comment'};
  144:         $comment=~s/\</\&lt\;/g;
  145:         $comment=~s/\>/\&gt\;/g;        
  146:     }
  147: 
  148: # print screen
  149:     $r->print(<<ENDDOCUMENT);
  150: <html>
  151: <head>
  152: <title>The LearningOnline Network with CAPA</title>
  153: <script>$script</script>
  154: </head>
  155: <body bgcolor="#FFFFFF">
  156: <h1>Course Documents</h1>
  157: ENDDOCUMENT
  158: # --------------------------------------------------0------ Standard documents
  159:     if (($standard) && ($allowed) && (!$forcesupplement)) {
  160:        $r->print('<h2>Main Course Documents</h2>');
  161:        my $folder=$ENV{'form.folder'};
  162:        unless ($folder) { $folder='default'; }
  163:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
  164:        $r->print(<<ENDFORM);
  165: <h3>Post a new main course document</h3>
  166: <form method="post" enctype="multipart/form-data">
  167: <input type="file" name="uploaddoc" size="50">
  168: <br />
  169: Title: <input type="text" size="50" name="comment">
  170: <input type="hidden" name="folder" value="$folder">
  171: <input type="hidden" name="cmd" value="upload_main">
  172: <input type="submit" value="Upload Document">
  173: </form>
  174: ENDFORM
  175:        $r->print('<hr />');
  176:     }
  177: # ----------------------------------------------------- Supplemental documents
  178:     if (!$forcestandard) {
  179:        $r->print('<h2>Supplemental Course Documents</h2>');
  180:        my $folder=$ENV{'form.folder'};
  181:        unless ($folder) { $folder='supplemental'; }
  182:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
  183:        if ($allowed) {
  184:           $r->print(<<ENDSUPFORM);
  185: <h3>Post a new supplemental course document</h3>
  186: <form method="post" enctype="multipart/form-data">
  187: <input type="file" name="uploaddoc" size="50">
  188: <br />Comment:<br />
  189: <textarea cols=50 rows=4 name='comment'>
  190: </textarea>
  191: <input type="hidden" name="folder" value="$folder">
  192: <input type="hidden" name="cmd" value="upload_suppl">
  193: <input type="submit" value="Upload Document">
  194: </form>
  195: ENDSUPFORM
  196:        }
  197:     }
  198: 
  199:     $r->print('</body></html>');
  200:     return OK;
  201: } 
  202: 
  203: 1;
  204: __END__

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