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

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

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