Annotation of loncom/interface/londocs.pm, revision 1.13

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Documents
1.1       www         3: #
1.13    ! www         4: # $Id: londocs.pm,v 1.12 2002/08/27 13:01:26 www Exp $
1.1       www         5: #
1.3       www         6: # Copyright Michigan State University Board of Trustees
1.1       www         7: #
1.3       www         8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
1.1       www         9: #
1.3       www        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.
1.1       www        14: #
1.3       www        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: 
1.2       www        29: package Apache::londocs;
1.1       www        30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
1.4       www        33: use Apache::lonnet;
                     34: use Apache::loncommon;
1.7       www        35: use Apache::lonratedt;
                     36: use Apache::lonratsrv;
                     37: 
1.8       www        38: my $iconpath;
1.7       www        39: 
                     40: # Mapread read maps into lonratedt::global arrays 
1.10      www        41: # @order and @resources, determines status
1.7       www        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)=@_;
1.10      www        62:     my $errtext='';
                     63:     my $fatal=0;
                     64:     ($errtext,$fatal)=
1.7       www        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) {
1.10      www        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:             }
1.8       www        93: 	    if ($ENV{'form.cmd'}) {
1.10      www        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');
1.8       www       114:             }
1.11      www       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:             }
1.7       www       137: 	}
                    138: # ---------------------------------------------------------------- Print screen
1.10      www       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>');
1.7       www       149:     }
                    150: }
1.1       www       151: 
1.8       www       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
1.10      www       170:     if ($url=~/^\/*uploaded\//) {
                    171: 	$url=&Apache::lonnet::tokenwrapper($url);
                    172:     }
1.8       www       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: 	}
1.10      www       181:     $line.="<td>$title</td>";
1.8       www       182:     $line.='</tr>';
                    183:     return $line;
                    184: }
                    185: 
                    186: # ================================================================ Main Handler
1.1       www       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: 
1.7       www       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_/);
1.10      www       198:     my $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1.7       www       199: 
1.4       www       200: # does this user have privileges to post, etc?
                    201:     my $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
1.8       www       202:     my $script='';
1.4       www       203:     if ($allowed) { 
1.8       www       204:        &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1.11      www       205:        $script=&Apache::lonratedt::editscript('simple'); 
1.3       www       206:     }
1.4       www       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: 
1.8       www       212: # graphics settings
1.4       www       213: 
1.8       www       214:     $iconpath = $r->dir_config('lonIconsURL') . "/";
                    215: 
1.4       www       216: # print screen
1.1       www       217:     $r->print(<<ENDDOCUMENT);
                    218: <html>
                    219: <head>
                    220: <title>The LearningOnline Network with CAPA</title>
1.8       www       221: <script>$script</script>
1.1       www       222: </head>
1.4       www       223: ENDDOCUMENT
1.9       www       224: $r->print(&Apache::loncommon::bodytag('Course Documents'));
1.7       www       225: # --------------------------------------------------0------ Standard documents
                    226:     if (($standard) && ($allowed) && (!$forcesupplement)) {
                    227:        $r->print('<h2>Main Course Documents</h2>');
                    228:        my $folder=$ENV{'form.folder'};
1.10      www       229:        unless ($folder=~/^default/) { $folder='default'; }
1.7       www       230:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8       www       231:        $r->print(<<ENDFORM);
1.11      www       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 />
1.10      www       239: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.8       www       240: <input type="file" name="uploaddoc" size="50">
                    241: <br />
1.11      www       242: Title:<br /> 
                    243: <input type="text" size="50" name="comment">
1.8       www       244: <input type="hidden" name="folder" value="$folder">
1.10      www       245: <input type="hidden" name="cmd" value="upload_default">
1.8       www       246: <input type="submit" value="Upload Document">
                    247: </form>
1.11      www       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">
1.13    ! www       259: <input type=hidden name="importdetail" value="">
1.11      www       260: <input name="newfolder" type="button" onClick="javascript:newfolder();"
                    261: value="New Folder" />
                    262: </form>
                    263: <form action="/adm/coursedocs" method="post" name="newext">
1.13    ! www       264: <input type=hidden name="importdetail" value="">
1.11      www       265: <input name="newext" type="button" onClick="javascript:newext();"
                    266: value="External Resource" />
                    267: </form>
                    268: <form action="/adm/coursedocs" method="post" name="newsyl">
1.13    ! www       269: <input type=hidden name="importdetail" value="">
1.11      www       270: <input name="newsyl" type="button" onClick="javascript:newsyl();"
                    271: value="Syllabus" />
1.12      www       272: </form>
                    273: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.13    ! www       274: <input type=hidden name="importdetail" value="">
1.12      www       275: <input name="newaboutme" type="button" onClick="javascript:newaboutme();"
                    276: value="My Personal Info" />
1.11      www       277: </form>
                    278: </td></tr>
                    279: </table>
1.8       www       280: ENDFORM
1.7       www       281:        $r->print('<hr />');
                    282:     }
                    283: # ----------------------------------------------------- Supplemental documents
                    284:     if (!$forcestandard) {
                    285:        $r->print('<h2>Supplemental Course Documents</h2>');
                    286:        my $folder=$ENV{'form.folder'};
1.10      www       287:        unless ($folder=~/supplemental/) { $folder='supplemental'; }
1.7       www       288:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8       www       289:        if ($allowed) {
                    290:           $r->print(<<ENDSUPFORM);
                    291: <h3>Post a new supplemental course document</h3>
1.10      www       292: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.4       www       293: <input type="file" name="uploaddoc" size="50">
                    294: <br />Comment:<br />
                    295: <textarea cols=50 rows=4 name='comment'>
                    296: </textarea>
1.8       www       297: <input type="hidden" name="folder" value="$folder">
1.10      www       298: <input type="hidden" name="cmd" value="upload_supplemental">
1.3       www       299: <input type="submit" value="Upload Document">
                    300: </form>
1.8       www       301: ENDSUPFORM
                    302:        }
1.7       www       303:     }
                    304: 
1.4       www       305:     $r->print('</body></html>');
1.1       www       306:     return OK;
                    307: } 
                    308: 
                    309: 1;
                    310: __END__

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