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

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

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