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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Documents
1.1       www         3: #
1.37    ! www         4: # $Id: londocs.pm,v 1.36 2002/10/25 13:39:36 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;
1.28      www        32: use Apache::Constants qw(:common :http);
1.4       www        33: use Apache::lonnet;
                     34: use Apache::loncommon;
1.7       www        35: use Apache::lonratedt;
                     36: use Apache::lonratsrv;
1.15      www        37: use Apache::lonxml;
1.27      www        38: use GDBM_File;
1.7       www        39: 
1.8       www        40: my $iconpath;
1.7       www        41: 
1.27      www        42: my %hash;
                     43: 
                     44: my $hashtied;
1.29      www        45: my %alreadyseen=();
1.27      www        46: 
1.7       www        47: # Mapread read maps into lonratedt::global arrays 
1.10      www        48: # @order and @resources, determines status
1.7       www        49: # sets @order - pointer to resources in right order
                     50: # sets @resources - array with the resources with correct idx
                     51: #
                     52: 
                     53: sub mapread {
                     54:     my ($coursenum,$coursedom,$map)=@_;
                     55:     return
                     56:       &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                     57:                                 $map);
                     58: }
                     59: 
                     60: sub storemap {
                     61:     my ($coursenum,$coursedom,$map)=@_;
                     62:     return
                     63:       &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.15      www        64:                                 $map,1);
1.7       www        65: }
                     66: 
                     67: sub editor {
                     68:     my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
1.17      www        69:     if ($ENV{'form.foldername'}) {
                     70: 	$r->print('<h3>Folder: '.$ENV{'form.foldername'}.'</h3>');
                     71:     }
1.10      www        72:     my $errtext='';
                     73:     my $fatal=0;
                     74:     ($errtext,$fatal)=
1.7       www        75:           &mapread($coursenum,$coursedom,$folder.'.sequence');
1.17      www        76:     if ($#Apache::lonratedt::order<1) {
                     77:        	$Apache::lonratedt::order[0]=1;
                     78:         $Apache::lonratedt::resources[1]='';
                     79:     }
1.7       www        80:     if ($fatal) {
                     81: 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
                     82:     } else {
                     83: # ------------------------------------------------------------ Process commands
1.16      www        84: # ---------------- if they are for this folder and user allowed to make changes
                     85: 	if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
1.10      www        86: # upload a file, if present
                     87:            if (($ENV{'form.uploaddoc.filename'}) &&
                     88:                ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
                     89: 	    if ($folder=~/^$1/) {
                     90: # this is for a course, not a user, so set coursedoc flag
                     91: # probably the only place in the system where this should be "1"
                     92: 	      my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
                     93:               my $ext='false';
                     94:               if ($url=~/^http\:\/\//) { $ext='true'; }
                     95:               $url=~s/\:/\&colon;/g;
                     96: 	      my $comment=$ENV{'form.comment'};
                     97:               $comment=~s/\</\&lt\;/g;
                     98:               $comment=~s/\>/\&gt\;/g;
                     99:               $comment=~s/\:/\&colon;/g;
1.17      www       100:               if ($folder=~/^supplemental/) {
                    101: 		  $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
                    102: 		      $ENV{'user.domain'}.'___&&&___'.$comment;
                    103:               }
1.10      www       104:               my $newidx=$#Apache::lonratedt::resources+1;
                    105:               $Apache::lonratedt::resources[$newidx]=
                    106:                   $comment.':'.$url.':'.$ext.':normal:res';
                    107:               $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
                    108:                                                               $newidx;       
                    109:  	      &storemap($coursenum,$coursedom,$folder.'.sequence');
                    110: 	     }
                    111:             }
1.8       www       112: 	    if ($ENV{'form.cmd'}) {
1.10      www       113:                 my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
                    114:                 if ($cmd eq 'del') {
                    115: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
                    116:                         $Apache::lonratedt::order[$i]=
                    117:                           $Apache::lonratedt::order[$i+1];
                    118:                     }
                    119:                     $#Apache::lonratedt::order--;
                    120:                 } elsif ($cmd eq 'up') {
                    121:                     my $i=$Apache::lonratedt::order[$idx-1];
                    122:                     $Apache::lonratedt::order[$idx-1]=
                    123: 			$Apache::lonratedt::order[$idx];
                    124:                     $Apache::lonratedt::order[$idx]=$i;
                    125:                 } elsif ($cmd eq 'down') {
                    126:                     my $i=$Apache::lonratedt::order[$idx+1];
                    127:                     $Apache::lonratedt::order[$idx+1]=
                    128: 			$Apache::lonratedt::order[$idx];
                    129:                     $Apache::lonratedt::order[$idx]=$i;
1.36      www       130:                 } elsif ($cmd eq 'rename') {
                    131:                     my ($rtitle,@rrest)=split(/\:/,
                    132:                        $Apache::lonratedt::resources[
                    133: 				       $Apache::lonratedt::order[$idx]]);
                    134:                     my $comment=$ENV{'form.title'};
                    135:                     $comment=~s/\</\&lt\;/g;
                    136:                     $comment=~s/\>/\&gt\;/g;
                    137:                     $comment=~s/\:/\&colon;/g;
                    138:                     $Apache::lonratedt::resources[
                    139: 				       $Apache::lonratedt::order[$idx]]=
                    140:                              $comment.':'.join(':',@rrest);
                    141:                     
1.10      www       142:                 }
                    143: # Store the changed version
                    144: 		&storemap($coursenum,$coursedom,$folder.'.sequence');
1.8       www       145:             }
1.11      www       146: # Group import/search
                    147: 	    if ($ENV{'form.importdetail'}) {
                    148:                foreach (split(/\&/,$ENV{'form.importdetail'})) {
                    149:                   if (defined($_)) {
                    150: 	             my ($name,$url)=split(/\=/,$_);
                    151:                      $name=&Apache::lonnet::unescape($name);
                    152:                      $url=&Apache::lonnet::unescape($url);
                    153:                      if ($url) {
                    154: 	                my $idx=$#Apache::lonratedt::resources+1;
                    155:                         $Apache::lonratedt::order
                    156:                            [$#Apache::lonratedt::order+1]=$idx;
                    157:                         my $ext='false';
                    158:                         if ($url=~/^http\:\/\//) { $ext='true'; }
                    159:                         $url=~s/\:/\&colon;/g;
                    160:                         $Apache::lonratedt::resources[$idx]=
                    161:                            $name.':'.$url.':'.$ext.':normal:res';
                    162: 	             }
                    163:                  }
                    164: 	      }
                    165: # Store the changed version
                    166: 		&storemap($coursenum,$coursedom,$folder.'.sequence');
                    167:             }
1.16      www       168:        }
                    169: # ---------------------------------------------------------------- End commands
1.7       www       170: # ---------------------------------------------------------------- Print screen
1.10      www       171:         my $idx=0;
                    172:         $r->print('<table>');
                    173:         foreach (@Apache::lonratedt::order) {
                    174:            my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
                    175:            unless ($name) {  $name=(split(/\//,$url))[-1]; }
1.37    ! www       176:            unless ($name) { $name='NO RESOURCE'; $url='/adm/notfound.html'; }
1.10      www       177:            $r->print(&entryline($idx,$name,$url,$folder,$allowed));
                    178:            $idx++;
                    179:         }
                    180:         $r->print('</table>');
1.7       www       181:     }
                    182: }
1.1       www       183: 
1.8       www       184: # --------------------------------------------------------------- An entry line
                    185: 
                    186: sub entryline {
                    187:     my ($index,$title,$url,$folder,$allowed)=@_;
                    188:     my $line='<tr>';
                    189: # Edit commands
                    190:     if ($allowed) {
                    191:        $line.=(<<END);
                    192: <td><table border='0' cellspacing='0' cellpadding='0'>
                    193: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
                    194: <img src="${iconpath}move_up.gif" alt='UP' border='0' /></a></td></tr>
                    195: <tr><td><a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
                    196: <img src="${iconpath}move_down.gif" alt='DOWN' border='0' /></a></td></tr>
                    197: </table></td><td>
1.36      www       198: <a href='/adm/coursedocs?folder=$folder&cmd=del_$index'>
                    199: <font size="-2">Remove</font></a>
                    200: <a href='javascript:changename("$folder","$index","$title");'>
                    201: <font size="-2">Rename</font></a></td>
1.8       www       202: END
                    203:     }
1.16      www       204: # Figure out what kind of a resource this is
                    205:     my ($extension)=($url=~/\.(\w+)$/);
                    206:     my $uploaded=($url=~/^\/*uploaded\//);
                    207:     my $icon='unknown';
                    208:     if (-e "/home/httpd/html/adm/lonIcons/$extension.gif") {
                    209: 	$icon=$extension;
1.10      www       210:     }
1.17      www       211:     my $isfolder=0;
1.16      www       212:     if ($uploaded) {
                    213:        if ($extension eq 'sequence') {
                    214: 	  $icon='folder_closed';
                    215:           $url=~/\/(\w+)\.sequence/;
                    216:           $url='/adm/coursedocs?folder='.$1;
1.17      www       217:           $isfolder=1;
1.16      www       218:        } else {
                    219: 	  $url=&Apache::lonnet::tokenwrapper($url);
                    220:        } 
                    221:     }
1.18      www       222:     $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
1.8       www       223: # Title
                    224:     $title=&Apache::lonnet::unescape($title);
1.17      www       225:     my $foldertitle=$title;
1.8       www       226:     if ($title=~
                    227:  /^(\d+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(\w+)\_\_\_\&\&\&\_\_\_(.*)$/
1.17      www       228: 	) { 
                    229:             $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
                    230:             $title='<i>'.localtime($1).'</i> '.
                    231:                 &Apache::loncommon::plainname($2,$3).': <br>'.
                    232: 		$foldertitle;
1.8       www       233: 	}
1.17      www       234:     if ($isfolder) { $url.='&foldername='.$foldertitle; }
1.23      www       235:     $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'" target="cat_'.$folder.
                    236: '"><img src="/adm/lonIcons/'.
1.17      www       237:         $icon.'.gif" border="0"></a></td>'.
1.23      www       238:         "<td bgcolor='#FFFFBB'><a href='$url' target='cat_$folder'>$title</a></td></tr>";
1.8       www       239:     return $line;
                    240: }
                    241: 
1.27      www       242: # ---------------------------------------------------------------- tie the hash
                    243: 
                    244: sub tiehash {
                    245:     $hashtied=0;
                    246:     if ($ENV{'request.course.fn'}) {
                    247:         if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
                    248:             &GDBM_READER(),0640)) {
                    249:                 $hashtied=1;
                    250:         }
                    251:     }    
                    252: }
                    253: 
                    254: sub untiehash {
                    255:     if ($hashtied) { untie %hash; }
                    256:     $hashtied=0;
                    257: }
                    258: 
1.29      www       259: # --------------------------------------------------------------- check on this
                    260: 
                    261: sub checkonthis {
                    262:     my ($r,$url,$level,$title)=@_;
                    263:     $alreadyseen{$url}=1;
                    264:     $r->rflush();
                    265:     if ($url) {
                    266:        $r->print('<br />');
                    267:        for (my $i=0;$i<=$level*5;$i++) {
                    268:            $r->print('&nbsp;');
                    269:        }
                    270:        $r->print('<a href="'.$url.'" target="cat">'.
                    271: 		 ($title?$title:$url).'</a> ');
                    272:        if ($url=~/^\/res\//) {
                    273: 	  my $result=&Apache::lonnet::repcopy(
                    274:                               &Apache::lonnet::filelocation('',$url));
                    275:           if ($result==OK) {
                    276:              $r->print('<font color="green">ok</font>');
                    277:              $r->rflush();
1.34      www       278:              &Apache::lonnet::countacc($url);
                    279:              $url=~/\.(\w+)$/;
                    280:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                    281: 		 $r->print('<br />');
                    282:                  $r->rflush();
                    283:                  for (my $i=0;$i<=$level*5;$i++) {
                    284:                      $r->print('&nbsp;');
                    285:                  }
                    286:                  $r->print('- Rendering: ');
                    287:                  &Apache::lonxml::xmlparse($r,'web',
                    288:                    &Apache::lonnet::getfile(
1.35      albertel  289:                     &Apache::lonnet::filelocation('',$url)));
1.34      www       290:                  if (($Apache::lonxml::errorcount) ||
                    291:                      ($Apache::lonxml::warningcount)) {
                    292: 		     if ($Apache::lonxml::errorcount) {
                    293:                         $r->print('<font color="red"><b>'.
                    294: 			  $Apache::lonxml::errorcount.' error(s)</b></font> ');
                    295:                      }
                    296: 		     if ($Apache::lonxml::warningcount) {
                    297:                         $r->print('<font color="blue">'.
                    298: 			  $Apache::lonxml::warningcount.' warning(s)</font>');
                    299:                      }
                    300:                  } else {
                    301:                      $r->print('<font color="green">ok</font>');
                    302:                  }
                    303:                  $r->rflush();
                    304:              }
1.29      www       305: 	     my $dependencies=
                    306:                 &Apache::lonnet::metadata($url,'dependencies');
                    307:              foreach (split(/\,/,$dependencies)) {
                    308: 		 if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
                    309:                     &checkonthis($r,$_,$level+1);
                    310:                  }
                    311:              }
                    312:           } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
                    313:              $r->print('<font color="red"><b>connection down</b></font>');
                    314:           } elsif ($result==HTTP_NOT_FOUND) {
                    315:              $r->print('<font color="red"><b>not found</b></font>');
                    316:           } else {
                    317:              $r->print('<font color="red"><b>access denied</b></font>');
                    318:           }
                    319:       }
                    320:    }
                    321: }
                    322: 
1.8       www       323: # ================================================================ Main Handler
1.1       www       324: sub handler {
                    325:     my $r = shift;
                    326:     $r->content_type('text/html');
                    327:     $r->send_http_header;
                    328:     return OK if $r->header_only;
                    329: 
1.27      www       330:   
1.26      www       331:   if ($ENV{'form.verify'}) {
                    332:  
                    333:    my $loaderror=&Apache::lonnet::overloaderror($r);
                    334:    if ($loaderror) { return $loaderror; }
                    335: 
                    336:    $r->print('<html><head><title>Verify Content</title></head>'.
                    337:               &Apache::loncommon::bodytag('Verify Course Documents'));
1.27      www       338:    $hashtied=0;
1.30      www       339:    undef %alreadyseen;
                    340:    %alreadyseen=();
1.27      www       341:    &tiehash();
                    342:    foreach (keys %hash) {
1.28      www       343:        if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
1.29      www       344:            &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27      www       345:        }
                    346:    }
                    347:    &untiehash();
1.26      www       348:   } elsif ($ENV{'form.versions'}) {
                    349:     $r->print('<html><head><title>Check Versions</title></head>'.
                    350:               &Apache::loncommon::bodytag('Check Course Document Versions'));
1.27      www       351:    $hashtied=0;
                    352:    &tiehash();
1.30      www       353:    my %changes=&Apache::lonnet::dump
                    354:     ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    355:                      $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.31      www       356:    my $firstkey=(keys %changes)[0];
                    357:    unless ($firstkey=~/^error\:/) {
                    358:        unless ($ENV{'form.timerange'}) {
                    359: 	   $ENV{'form.timerange'}=604800;
                    360:        }
                    361:        my $seltext='during the last '.$ENV{'form.timerange'}.' seconds';
                    362:        my $startsel='';
                    363:        my $monthsel='';
                    364:        my $weeksel='';
                    365:        my $daysel='';
                    366:        if ($ENV{'form.timerange'}==-1) {
                    367: 	   $seltext='since start of course';
                    368:            $startsel='selected';
1.32      www       369:            $ENV{'form.timerange'}=time;
                    370:        }
                    371:        my $starttime=time-$ENV{'form.timerange'};
                    372:        if ($ENV{'form.timerange'}==2592000) {
                    373:            $seltext='during the last month ('.localtime($starttime).')';
1.31      www       374:            $monthsel='selected';
                    375:        } elsif ($ENV{'form.timerange'}==604800) {
1.32      www       376:            $seltext='during the last week ('.localtime($starttime).')';
1.31      www       377:            $weeksel='selected';
                    378:        } elsif ($ENV{'form.timerange'}==86400) {
1.32      www       379:            $seltext='since yesterday ('.localtime($starttime).')';
1.31      www       380:            $daysel='selected';
                    381:        }
1.32      www       382:  
1.31      www       383:        $r->print(<<ENDHEADERS);
                    384: <form action="/adm/coursedocs" method="post">
                    385: <select name="timerange">
                    386: <option value="-1" $startsel>Since Start of Course</option>
                    387: <option value="2592000" $monthsel>Last Month</option>
                    388: <option value="604800" $weeksel>Last Week</option>
                    389: <option value="86400" $daysel>Since Yesterday</option>
                    390: </select>
                    391: <input type="submit" name="versions" value="Display" />
                    392: </form>
1.32      www       393: <h3>Content changed $seltext</h3>
1.31      www       394: <table border="2">
                    395: <tr>
                    396: <th>File</th><th>Modification Date</th>
                    397: <th>Version</th><th>Differences</th></tr>
                    398: ENDHEADERS
                    399:        foreach (keys %changes) {
1.32      www       400: 	  if ($changes{$_}>$starttime) {
                    401: 	     my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
                    402:              my $currentversion=&Apache::lonnet::getversion($_);
                    403:              my $linkurl=&Apache::lonnet::clutter($_);
                    404:              $r->print(
                    405:                  '<tr><td><a href="'.$linkurl.'" target="cat">'.$linkurl.
                    406:                  '</a></td><td>'.
                    407:                  localtime($changes{$_}).'</td><td>'.$currentversion.'</td>'.
                    408: 		       '<td>');
                    409:              my $lastold=1;
                    410:              for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                    411:                  my $url=$root.'.'.$prevvers.'.'.$extension;
                    412:                  if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
                    413:                                                              $starttime) {
                    414:                      $lastold=$prevvers;
                    415:                  }
                    416:              }
                    417:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
                    418:                  my $url=$root.'.'.$prevvers.'.'.$extension;
                    419:                  $r->print('<a href="'.&Apache::lonnet::clutter($url).
                    420:                    '">Version '.$prevvers.' ('.
                    421:                  localtime(&Apache::lonnet::metadata($url,'lastrevisiondate')).
1.33      www       422:                  ')</a>');
                    423:                  if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
                    424:                     $r->print(' <a href="/adm/diff?filename='.
                    425:                             &Apache::lonnet::clutter($root.'.'.$extension).
                    426:                             '&versionone='.$prevvers.
                    427: 			     '">Diffs</a>');
                    428:                  }
                    429:                  $r->print('<br />');
1.32      www       430:              }
                    431:              $r->print('</td></tr>');
                    432:           }
1.31      www       433:        }
                    434:        $r->print('</table>');
                    435:    } else {
                    436:        $r->print('<p>No content modifications yet.</p>');
1.30      www       437:    }
1.27      www       438:    &untiehash();
1.26      www       439:   } else {
1.7       www       440: # is this a standard course?
                    441: 
                    442:     my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1.15      www       443:     my $forcestandard;
                    444:     my $forcesupplement;
                    445:     my $script='';
                    446:     my $allowed;
                    447:     my $events='';
1.19      www       448:     my $showdoc=0;
1.15      www       449:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.21      www       450:        ['folder','foldername']);
                    451:     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
                    452:        $showdoc=$1;
                    453:     }
                    454:     unless ($showdoc) { # got called from remote
1.15      www       455:        $forcestandard=($ENV{'form.folder'}=~/^default_/);
                    456:        $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1.7       www       457: 
1.4       www       458: # does this user have privileges to post, etc?
1.15      www       459:        $allowed=&Apache::lonnet::allowed('srm',$ENV{'request.course.id'});
                    460:        if ($allowed) { 
                    461:          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                    462:          $script=&Apache::lonratedt::editscript('simple'); 
                    463:        }
                    464:     } else { # got called in sequence from course
                    465:        $allowed=0;
1.21      www       466:        $script='</script>'.&Apache::lonxml::registerurl(1,undef).'<script>';
1.15      www       467:        $events='onLoad="'.&Apache::lonxml::loadevents.
                    468:            '" onUnload="'.&Apache::lonxml::unloadevents.'"';
1.3       www       469:     }
1.4       www       470: 
                    471: # get course data
                    472:     my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                    473:     my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                    474: 
1.14      www       475: # get personal data
                    476:  
                    477:     my $uname=$ENV{'user.name'};
                    478:     my $udom=$ENV{'user.domain'};
                    479:     my $plainname=&Apache::lonnet::escape(
                    480:                      &Apache::loncommon::plainname($uname,$udom));
                    481: 
1.8       www       482: # graphics settings
1.4       www       483: 
1.8       www       484:     $iconpath = $r->dir_config('lonIconsURL') . "/";
                    485: 
1.22      www       486:     my $now=time;
                    487: 
1.4       www       488: # print screen
1.1       www       489:     $r->print(<<ENDDOCUMENT);
                    490: <html>
                    491: <head>
                    492: <title>The LearningOnline Network with CAPA</title>
1.16      www       493: <script>
                    494: $script
1.20      www       495: </script>
1.19      www       496: ENDDOCUMENT
                    497:    if ($allowed) {
                    498:     $r->print(<<ENDNEWSCRIPT);
1.20      www       499: <script>
1.16      www       500: function makenewfolder(targetform,folderseq) {
                    501:     var foldername=prompt('Name of New Folder','New Folder');
                    502:     if (foldername) {
                    503: 	targetform.importdetail.value=foldername+"="+folderseq;
                    504:         targetform.submit();
                    505:     }
                    506: }
                    507: 
1.18      www       508: function makenewext(targetname) {
                    509:     this.document.forms.extimport.useform.value=targetname;
                    510:     window.open('/adm/rat/extpickframe.html');
                    511: }
                    512: 
1.22      www       513: function makesmppage() {
                    514:     var title=prompt('Listed Title for the Page');
                    515:     this.document.forms.newsmppg.importdetail.value=
                    516: 	title+'=/adm/$udom/$uname/$now/smppg';
                    517:     this.document.forms.newsmppg.submit();
                    518: }
                    519: 
                    520: function makebulboard() {
                    521:     var title=prompt('Listed Title for the Bulletin Board');
                    522:     this.document.forms.newbul.importdetail.value=
                    523: 	title+'=/adm/$udom/$uname/$now/bulletinboard';
                    524:     this.document.forms.newbul.submit();
                    525: }
                    526: 
1.18      www       527: function finishpick() {
                    528:     var title=this.document.forms.extimport.title.value;
                    529:     var url=this.document.forms.extimport.url.value;
                    530:     var form=this.document.forms.extimport.useform.value;
                    531:     eval
                    532:      ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
                    533:     '";this.document.forms.'+form+'.submit();');
1.16      www       534: }
1.36      www       535: 
                    536: function changename(folder,index,oldtitle) {
                    537:     var title=prompt('New Title',oldtitle);
                    538:     if (title) {
                    539: 	this.document.forms.renameform.title.value=title;
                    540: 	this.document.forms.renameform.cmd.value='rename_'+index;
                    541: 	this.document.forms.renameform.folder.value=folder;
                    542:         this.document.forms.renameform.submit();
                    543:     }
                    544: }
1.16      www       545: </script>
1.36      www       546: <form name="renameform" method="post" action="/adm/coursedocs">
                    547: <input type="hidden" name="title" />
                    548: <input type="hidden" name="cmd" />
                    549: <input type="hidden" name="folder" />
                    550: </form>
1.19      www       551: ENDNEWSCRIPT
                    552:   }
                    553: # -------------------------------------------------------------------- Body tag
1.20      www       554:   $r->print('</head>'.
                    555:             &Apache::loncommon::bodytag('Course Documents','',$events));
1.19      www       556:   unless ($showdoc) {
1.25      www       557:     if ($allowed) {
                    558:        $r->print(<<ENDCOURSEVERIFY);
1.26      www       559: <form action="/adm/coursedocs" method="post" name="courseverify">
1.25      www       560: <input type="submit" name="verify" value="Verify Content" />
                    561: <input type="submit" name="versions" value="Check Resource Versions" />
                    562: </form>
                    563: ENDCOURSEVERIFY
                    564:     }
1.17      www       565: # --------------------------------------------------------- Standard documents
1.24      www       566:     $r->print('<table>');
1.7       www       567:     if (($standard) && ($allowed) && (!$forcesupplement)) {
1.24      www       568:        $r->print('<tr><td bgcolor="#FFFFBB"><h2>Main Course Documents</h2>');
1.7       www       569:        my $folder=$ENV{'form.folder'};
1.10      www       570:        unless ($folder=~/^default/) { $folder='default'; }
1.7       www       571:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.16      www       572:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                    573:                      '.sequence';
1.8       www       574:        $r->print(<<ENDFORM);
1.16      www       575: <table cellspacing=2><tr>
                    576: <th bgcolor="#DDDDDD">Upload a new main course document</th>
                    577: <th bgcolor="#DDDDDD">Import a published document</th>
                    578: <th bgcolor="#DDDDDD">Special documents</th>
1.11      www       579: </tr>
1.16      www       580: <tr><td bgcolor="#DDDDDD">
1.11      www       581: File:<br />
1.10      www       582: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.8       www       583: <input type="file" name="uploaddoc" size="50">
                    584: <br />
1.11      www       585: Title:<br /> 
                    586: <input type="text" size="50" name="comment">
1.8       www       587: <input type="hidden" name="folder" value="$folder">
1.17      www       588: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.10      www       589: <input type="hidden" name="cmd" value="upload_default">
1.8       www       590: <input type="submit" value="Upload Document">
                    591: </form>
1.11      www       592: </td>
1.16      www       593: <td bgcolor="#DDDDDD">
1.11      www       594: <form action="/adm/coursedocs" method="post" name="simpleedit">
1.16      www       595: <input type="hidden" name="folder" value="$folder">
1.11      www       596: <input type=hidden name="importdetail" value="">
                    597: <input type=button onClick=
1.16      www       598: "javascript:groupsearch()" value="Search">
1.11      www       599: <input type=button onClick=
1.16      www       600: "javascript:groupimport();" value="Import">
1.11      www       601: </form>
1.16      www       602: </td><td bgcolor="#DDDDDD">
1.11      www       603: <form action="/adm/coursedocs" method="post" name="newfolder">
1.16      www       604: <input type="hidden" name="folder" value="$folder">
1.17      www       605: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.13      www       606: <input type=hidden name="importdetail" value="">
1.16      www       607: <input name="newfolder" type="button"
                    608: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.11      www       609: value="New Folder" />
                    610: </form>
                    611: <form action="/adm/coursedocs" method="post" name="newext">
1.16      www       612: <input type="hidden" name="folder" value="$folder">
1.17      www       613: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.13      www       614: <input type=hidden name="importdetail" value="">
1.18      www       615: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
1.11      www       616: value="External Resource" />
                    617: </form>
                    618: <form action="/adm/coursedocs" method="post" name="newsyl">
1.16      www       619: <input type="hidden" name="folder" value="$folder">
1.17      www       620: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.14      www       621: <input type=hidden name="importdetail" 
                    622: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
                    623: <input name="newsyl" type="submit" value="Syllabus" />
1.15      www       624: </form>
1.17      www       625: <form action="/adm/coursedocs" method="post" name="newnav">
1.20      www       626: <input type="hidden" name="folder" value="$folder">
                    627: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.15      www       628: <input type=hidden name="importdetail" 
                    629: value="Navigate Content=/adm/navmaps">
1.20      www       630: <input name="newnav" type="submit" value="Navigate Content" />
1.22      www       631: </form>
                    632: <form action="/adm/coursedocs" method="post" name="newsmppg">
                    633: <input type="hidden" name="folder" value="$folder">
                    634: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
                    635: <input type=hidden name="importdetail" value="">
                    636: <input name="newsmppg" type="button" value="Simple Page"
                    637: onClick="javascript:makesmppage();" />
                    638: </form>
                    639: <form action="/adm/coursedocs" method="post" name="newbul">
                    640: <input type="hidden" name="folder" value="$folder">
                    641: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
                    642: <input type=hidden name="importdetail" value="">
                    643: <input name="newbulletin" type="button" value="Bulletin Board"
                    644: onClick="javascript:makebulboard();" />
1.12      www       645: </form>
                    646: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.16      www       647: <input type="hidden" name="folder" value="$folder">
1.17      www       648: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.14      www       649: <input type=hidden name="importdetail" 
                    650: value="$plainname=/adm/$udom/$uname/aboutme">
1.16      www       651: <input name="newaboutme" type="submit" value="My Personal Info" />
1.11      www       652: </form>
                    653: </td></tr>
                    654: </table>
1.8       www       655: ENDFORM
1.24      www       656:        $r->print('</td></tr>');
1.7       www       657:     }
                    658: # ----------------------------------------------------- Supplemental documents
                    659:     if (!$forcestandard) {
1.24      www       660:        $r->print(
                    661:   '<tr><td bgcolor="#BBFFFF"><h2>Supplemental Course Documents</h2>');
1.7       www       662:        my $folder=$ENV{'form.folder'};
1.10      www       663:        unless ($folder=~/supplemental/) { $folder='supplemental'; }
1.7       www       664:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8       www       665:        if ($allowed) {
1.17      www       666:        my $folderseq=
                    667:                   '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
                    668:                      '.sequence';
                    669: 
1.8       www       670:           $r->print(<<ENDSUPFORM);
1.17      www       671: <table cellspacing=2><tr>
                    672: <th bgcolor="#DDDDDD">Upload a new supplemental course document</th>
                    673: <th bgcolor="#DDDDDD">Import a published document</th>
                    674: <th bgcolor="#DDDDDD">Special documents</th>
                    675: </tr>
                    676: <tr><td bgcolor="#DDDDDD">
1.10      www       677: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.4       www       678: <input type="file" name="uploaddoc" size="50">
                    679: <br />Comment:<br />
                    680: <textarea cols=50 rows=4 name='comment'>
                    681: </textarea>
1.8       www       682: <input type="hidden" name="folder" value="$folder">
1.17      www       683: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
1.10      www       684: <input type="hidden" name="cmd" value="upload_supplemental">
1.3       www       685: <input type="submit" value="Upload Document">
                    686: </form>
1.17      www       687: </td>
                    688: <td bgcolor="#DDDDDD">
                    689: <form action="/adm/coursedocs" method="post" name="simpleedit">
                    690: <input type="hidden" name="folder" value="$folder">
                    691: <input type=hidden name="importdetail" value="">
                    692: <input type=button onClick=
                    693: "javascript:groupsearch()" value="Search">
                    694: <input type=button onClick=
                    695: "javascript:groupimport();" value="Import">
                    696: </form>
                    697: </td><td bgcolor="#DDDDDD">
1.18      www       698: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.17      www       699: <input type="hidden" name="folder" value="$folder">
                    700: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
                    701: <input type=hidden name="importdetail" value="">
                    702: <input name="newfolder" type="button"
                    703: onClick="javascript:makenewfolder(this.form,'$folderseq');"
                    704: value="New Folder" />
                    705: </form>
1.18      www       706: <form action="/adm/coursedocs" method="post" name="supnewext">
1.17      www       707: <input type="hidden" name="folder" value="$folder">
                    708: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
                    709: <input type=hidden name="importdetail" value="">
1.18      www       710: <input name="newext" type="button" 
                    711: onClick="javascript:makenewext('supnewext');"
1.17      www       712: value="External Resource" />
                    713: </form>
1.18      www       714: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.17      www       715: <input type="hidden" name="folder" value="$folder">
                    716: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
                    717: <input type=hidden name="importdetail" 
                    718: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
                    719: <input name="newsyl" type="submit" value="Syllabus" />
                    720: </form>
1.18      www       721: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.17      www       722: <input type="hidden" name="folder" value="$folder">
                    723: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
                    724: <input type=hidden name="importdetail" 
                    725: value="$plainname=/adm/$udom/$uname/aboutme">
                    726: <input name="newaboutme" type="submit" value="My Personal Info" />
                    727: </form>
                    728: </td></tr>
1.24      www       729: </table></td></tr>
1.8       www       730: ENDSUPFORM
                    731:        }
1.7       www       732:     }
1.18      www       733:     if ($allowed) {
                    734: 	$r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
                    735:     }
1.24      www       736:     $r->print('</table>');
1.19      www       737:   } else {
                    738: # -------------------------------------------------------- This is showdoc mode
                    739:       $r->print("<h1>Uploaded Document</h1><p>It is recommended that you use an up-to-date virus scanner before handling this file.</p><p><table>".
1.21      www       740:          &entryline(0,"Click to download or use your browser's Save Link function",$showdoc).'</table></p>');
1.19      www       741:   }
1.26      www       742:  }
                    743:  $r->print('</body></html>');
                    744:  return OK;
1.1       www       745: } 
                    746: 
                    747: 1;
                    748: __END__

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