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

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

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