File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.9: download - view: text, annotated - select for diffs
Wed Aug 21 17:18:08 2002 UTC (21 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Starting to implement common header and color scheme for LON-CAPA handlers
(non-content pages).

Instead of <body bgcolor="#...."><h1>... call

   &Apache::loncommon::bodytag(title,[role],[add_body_parms]);

title: what it says in the header
role (OPTIONAL): override role choice
                 ('admin','coordinator','student','author')
add_body_parms: additional parameters to be put into the body tag, for
                example 'onLoad="init();" or stuff

Colors and layout will likely change in the future, including domain
customization, help function calls, (css?)

    1: # The LearningOnline Network
    2: # Documents
    3: #
    4: # $Id: londocs.pm,v 1.9 2002/08/21 17:18:08 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: ENDDOCUMENT
  156: $r->print(&Apache::loncommon::bodytag('Course Documents'));
  157: # --------------------------------------------------0------ Standard documents
  158:     if (($standard) && ($allowed) && (!$forcesupplement)) {
  159:        $r->print('<h2>Main Course Documents</h2>');
  160:        my $folder=$ENV{'form.folder'};
  161:        unless ($folder) { $folder='default'; }
  162:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
  163:        $r->print(<<ENDFORM);
  164: <h3>Post a new main course document</h3>
  165: <form method="post" enctype="multipart/form-data">
  166: <input type="file" name="uploaddoc" size="50">
  167: <br />
  168: Title: <input type="text" size="50" name="comment">
  169: <input type="hidden" name="folder" value="$folder">
  170: <input type="hidden" name="cmd" value="upload_main">
  171: <input type="submit" value="Upload Document">
  172: </form>
  173: ENDFORM
  174:        $r->print('<hr />');
  175:     }
  176: # ----------------------------------------------------- Supplemental documents
  177:     if (!$forcestandard) {
  178:        $r->print('<h2>Supplemental Course Documents</h2>');
  179:        my $folder=$ENV{'form.folder'};
  180:        unless ($folder) { $folder='supplemental'; }
  181:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
  182:        if ($allowed) {
  183:           $r->print(<<ENDSUPFORM);
  184: <h3>Post a new supplemental course document</h3>
  185: <form method="post" enctype="multipart/form-data">
  186: <input type="file" name="uploaddoc" size="50">
  187: <br />Comment:<br />
  188: <textarea cols=50 rows=4 name='comment'>
  189: </textarea>
  190: <input type="hidden" name="folder" value="$folder">
  191: <input type="hidden" name="cmd" value="upload_suppl">
  192: <input type="submit" value="Upload Document">
  193: </form>
  194: ENDSUPFORM
  195:        }
  196:     }
  197: 
  198:     $r->print('</body></html>');
  199:     return OK;
  200: } 
  201: 
  202: 1;
  203: __END__

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