File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.11: download - view: text, annotated - select for diffs
Tue Aug 27 12:18:13 2002 UTC (21 years, 9 months ago) by www
Branches: MAIN
CVS tags: HEAD
Course Documents can now Group Import and Search

    1: # The LearningOnline Network
    2: # Documents
    3: #
    4: # $Id: londocs.pm,v 1.11 2002/08/27 12:18:13 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: # @order 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='';
   63:     my $fatal=0;
   64:     ($errtext,$fatal)=
   65:           &mapread($coursenum,$coursedom,$folder.'.sequence');
   66:     if ($fatal) {
   67: 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
   68:     } else {
   69: # ------------------------------------------------------------ Process commands
   70: 	if ($allowed) {
   71: # upload a file, if present
   72:            if (($ENV{'form.uploaddoc.filename'}) &&
   73:                ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
   74: 	    if ($folder=~/^$1/) {
   75: # this is for a course, not a user, so set coursedoc flag
   76: # probably the only place in the system where this should be "1"
   77: 	      my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
   78:               my $ext='false';
   79:               if ($url=~/^http\:\/\//) { $ext='true'; }
   80:               $url=~s/\:/\&colon;/g;
   81: 	      my $comment=$ENV{'form.comment'};
   82:               $comment=~s/\</\&lt\;/g;
   83:               $comment=~s/\>/\&gt\;/g;
   84:               $comment=~s/\:/\&colon;/g;
   85:               my $newidx=$#Apache::lonratedt::resources+1;
   86:               $Apache::lonratedt::resources[$newidx]=
   87:                   $comment.':'.$url.':'.$ext.':normal:res';
   88:               $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
   89:                                                               $newidx;       
   90:  	      &storemap($coursenum,$coursedom,$folder.'.sequence');
   91: 	     }
   92:             }
   93: 	    if ($ENV{'form.cmd'}) {
   94:                 my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
   95:                 if ($cmd eq 'del') {
   96: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
   97:                         $Apache::lonratedt::order[$i]=
   98:                           $Apache::lonratedt::order[$i+1];
   99:                     }
  100:                     $#Apache::lonratedt::order--;
  101:                 } elsif ($cmd eq 'up') {
  102:                     my $i=$Apache::lonratedt::order[$idx-1];
  103:                     $Apache::lonratedt::order[$idx-1]=
  104: 			$Apache::lonratedt::order[$idx];
  105:                     $Apache::lonratedt::order[$idx]=$i;
  106:                 } elsif ($cmd eq 'down') {
  107:                     my $i=$Apache::lonratedt::order[$idx+1];
  108:                     $Apache::lonratedt::order[$idx+1]=
  109: 			$Apache::lonratedt::order[$idx];
  110:                     $Apache::lonratedt::order[$idx]=$i;
  111:                 }
  112: # Store the changed version
  113: 		&storemap($coursenum,$coursedom,$folder.'.sequence');
  114:             }
  115: # Group import/search
  116: 	    if ($ENV{'form.importdetail'}) {
  117:                foreach (split(/\&/,$ENV{'form.importdetail'})) {
  118:                   if (defined($_)) {
  119: 	             my ($name,$url)=split(/\=/,$_);
  120:                      $name=&Apache::lonnet::unescape($name);
  121:                      $url=&Apache::lonnet::unescape($url);
  122:                      if ($url) {
  123: 	                my $idx=$#Apache::lonratedt::resources+1;
  124:                         $Apache::lonratedt::order
  125:                            [$#Apache::lonratedt::order+1]=$idx;
  126:                         my $ext='false';
  127:                         if ($url=~/^http\:\/\//) { $ext='true'; }
  128:                         $url=~s/\:/\&colon;/g;
  129:                         $Apache::lonratedt::resources[$idx]=
  130:                            $name.':'.$url.':'.$ext.':normal:res';
  131: 	             }
  132:                  }
  133: 	      }
  134: # Store the changed version
  135: 		&storemap($coursenum,$coursedom,$folder.'.sequence');
  136:             }
  137: 	}
  138: # ---------------------------------------------------------------- Print screen
  139:         my $idx=0;
  140:         $r->print('<table>');
  141:         foreach (@Apache::lonratedt::order) {
  142:            my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
  143:            unless ($name) {  $name=(split(/\//,$url))[-1]; }
  144:            unless ($name) { $name='EMPTY'; }
  145:            $r->print(&entryline($idx,$name,$url,$folder,$allowed));
  146:            $idx++;
  147:         }
  148:         $r->print('</table>');
  149:     }
  150: }
  151: 
  152: # --------------------------------------------------------------- An entry line
  153: 
  154: sub entryline {
  155:     my ($index,$title,$url,$folder,$allowed)=@_;
  156:     my $line='<tr>';
  157: # Edit commands
  158:     if ($allowed) {
  159:        $line.=(<<END);
  160: <td><table border='0' cellspacing='0' cellpadding='0'>
  161: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
  162: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
  163: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
  164: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
  165: </table></td><td>
  166: <a href='/adm/coursedocs?folder=$folder&cmd=del_$index'>Remove</td>
  167: END
  168:     }
  169: # URL
  170:     if ($url=~/^\/*uploaded\//) {
  171: 	$url=&Apache::lonnet::tokenwrapper($url);
  172:     }
  173:     $line.='<td><a href="'.$url.'">View</a></td>';
  174: # Title
  175:     $title=&Apache::lonnet::unescape($title);
  176:     if ($title=~
  177:  /^(\d+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(.*)$/
  178: 	) { $title='<i>'.localtime($1).'</i> '.$2.' at '.$3.': <br>'.
  179: 		&Apache::lontexconvert::msgtexconverted($4);
  180: 	}
  181:     $line.="<td>$title</td>";
  182:     $line.='</tr>';
  183:     return $line;
  184: }
  185: 
  186: # ================================================================ Main Handler
  187: sub handler {
  188:     my $r = shift;
  189:     $r->content_type('text/html');
  190:     $r->send_http_header;
  191:     return OK if $r->header_only;
  192: 
  193: # is this a standard course?
  194: 
  195:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
  196:     my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
  197:     my $forcestandard=($ENV{'form.folder'}=~/^default_/);
  198:     my $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
  199: 
  200: # does this user have privileges to post, etc?
  201:     my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
  202:     my $script='';
  203:     if ($allowed) { 
  204:        &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
  205:        $script=&Apache::lonratedt::editscript('simple'); 
  206:     }
  207: 
  208: # get course data
  209:     my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
  210:     my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
  211: 
  212: # graphics settings
  213: 
  214:     $iconpath = $r->dir_config('lonIconsURL') . "/";
  215: 
  216: # print screen
  217:     $r->print(<<ENDDOCUMENT);
  218: <html>
  219: <head>
  220: <title>The LearningOnline Network with CAPA</title>
  221: <script>$script</script>
  222: </head>
  223: ENDDOCUMENT
  224: $r->print(&Apache::loncommon::bodytag('Course Documents'));
  225: # --------------------------------------------------0------ Standard documents
  226:     if (($standard) && ($allowed) && (!$forcesupplement)) {
  227:        $r->print('<h2>Main Course Documents</h2>');
  228:        my $folder=$ENV{'form.folder'};
  229:        unless ($folder=~/^default/) { $folder='default'; }
  230:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
  231:        $r->print(<<ENDFORM);
  232: <table><tr>
  233: <th>Upload a new main course document</th>
  234: <th>Import a published document</th>
  235: <th>Special documents</th>
  236: </tr>
  237: <tr><td>
  238: File:<br />
  239: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
  240: <input type="file" name="uploaddoc" size="50">
  241: <br />
  242: Title:<br /> 
  243: <input type="text" size="50" name="comment">
  244: <input type="hidden" name="folder" value="$folder">
  245: <input type="hidden" name="cmd" value="upload_default">
  246: <input type="submit" value="Upload Document">
  247: </form>
  248: </td>
  249: <td>
  250: <form action="/adm/coursedocs" method="post" name="simpleedit">
  251: <input type=hidden name="importdetail" value="">
  252: <input type=button onClick=
  253: "javascript:groupsearch()" value="Group Search">
  254: <input type=button onClick=
  255: "javascript:groupimport();" value="Group Import">
  256: </form>
  257: </td><td>
  258: <form action="/adm/coursedocs" method="post" name="newfolder">
  259: <input name="newfolder" type="button" onClick="javascript:newfolder();"
  260: value="New Folder" />
  261: </form>
  262: <form action="/adm/coursedocs" method="post" name="newext">
  263: <input name="newext" type="button" onClick="javascript:newext();"
  264: value="External Resource" />
  265: </form>
  266: <form action="/adm/coursedocs" method="post" name="newsyl">
  267: <input name="newsyl" type="button" onClick="javascript:newsyl();"
  268: value="Syllabus" />
  269: </form>
  270: </td></tr>
  271: </table>
  272: ENDFORM
  273:        $r->print('<hr />');
  274:     }
  275: # ----------------------------------------------------- Supplemental documents
  276:     if (!$forcestandard) {
  277:        $r->print('<h2>Supplemental Course Documents</h2>');
  278:        my $folder=$ENV{'form.folder'};
  279:        unless ($folder=~/supplemental/) { $folder='supplemental'; }
  280:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
  281:        if ($allowed) {
  282:           $r->print(<<ENDSUPFORM);
  283: <h3>Post a new supplemental course document</h3>
  284: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
  285: <input type="file" name="uploaddoc" size="50">
  286: <br />Comment:<br />
  287: <textarea cols=50 rows=4 name='comment'>
  288: </textarea>
  289: <input type="hidden" name="folder" value="$folder">
  290: <input type="hidden" name="cmd" value="upload_supplemental">
  291: <input type="submit" value="Upload Document">
  292: </form>
  293: ENDSUPFORM
  294:        }
  295:     }
  296: 
  297:     $r->print('</body></html>');
  298:     return OK;
  299: } 
  300: 
  301: 1;
  302: __END__

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