File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.15: download - view: text, annotated - select for diffs
Mon Sep 2 15:27:08 2002 UTC (21 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
BUGFIX tmp file mechanism for lonratedt
  - display right after "Save" and "Revert"

Can override ratedt tmp-mechanism for coursedocs
Does NAV as resource in coursemaps
Start on showdoc mechanism for uploaded docs in main sequence

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

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