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

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

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