File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.106: download - view: text, annotated - select for diffs
Fri Feb 13 14:59:48 2004 UTC (20 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #1645: do not say "NO RESOURCE" anymore (not needed anymore since
automatically cleaned up)

    1: # The LearningOnline Network
    2: # Documents
    3: #
    4: # $Id: londocs.pm,v 1.106 2004/02/13 14:59:48 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   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.
   14: #
   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: 
   29: package Apache::londocs;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common :http);
   33: use Apache::lonnet;
   34: use Apache::loncommon;
   35: use Apache::lonratedt;
   36: use Apache::lonratsrv;
   37: use Apache::lonxml;
   38: use Apache::loncreatecourse;
   39: use HTML::Entities;
   40: use GDBM_File;
   41: use Apache::lonlocal;
   42: 
   43: my $iconpath;
   44: 
   45: my %hash;
   46: 
   47: my $hashtied;
   48: my %alreadyseen=();
   49: 
   50: my $hadchanges;
   51: 
   52: # Available help topics
   53: 
   54: my %help=();
   55: 
   56: # Mapread read maps into lonratedt::global arrays 
   57: # @order and @resources, determines status
   58: # sets @order - pointer to resources in right order
   59: # sets @resources - array with the resources with correct idx
   60: #
   61: 
   62: sub mapread {
   63:     my ($coursenum,$coursedom,$map)=@_;
   64:     return
   65:       &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
   66:                                 $map);
   67: }
   68: 
   69: sub storemap {
   70:     my ($coursenum,$coursedom,$map)=@_;
   71:     my ($outtext,$errtext)=
   72:       &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
   73:                                 $map,1);
   74:     if ($errtext) { return ($errtext,2); }
   75:     
   76:     $hadchanges=1;
   77:     return ($errtext,0);
   78: }
   79: 
   80: # ----------------------------------------- Return hash with valid author names
   81: 
   82: sub authorhosts {
   83:     my %outhash=();
   84:     my $home=0;
   85:     my $other=0;
   86:     foreach (keys %ENV) {
   87: 	if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
   88: 	    my $role=$1;
   89: 	    my $realm=$2;
   90: 	    my ($start,$end)=split(/\./,$ENV{$_});
   91: 	    if (($start) && ($start>time)) { next; }
   92: 	    if (($end) && (time>$end)) { next; }
   93: 	    my $ca; my $cd;
   94: 	    if ($1 eq 'au') {
   95: 		$ca=$ENV{'user.name'};
   96: 		$cd=$ENV{'user.domain'};
   97: 	    } else {
   98: 		($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
   99: 	    }
  100: 	    if (&Apache::lonnet::homeserver($ca,$cd) eq 
  101: 		$Apache::lonnet::perlvar{'lonHostID'}) {
  102: 		$home++;
  103: 		$outhash{'home_'.$ca.'@'.$cd}=1;
  104: 	    } else {
  105: 		$outhash{'otherhome_'.$ca.'@'.$cd}=
  106: 		    &Apache::lonnet::homeserver($ca,$cd);
  107: 		$other++;
  108: 	    }
  109: 	}
  110:     }
  111:     return ($home,$other,%outhash);
  112: }
  113: # ------------------------------------------------------ Generate "dump" button
  114: 
  115: sub dumpbutton {
  116:     my ($home,$other,%outhash)=&authorhosts();
  117:     if ($home+$other==0) { return ''; }
  118:     my $output='</td><td bgcolor="#DDDDCC">';
  119:     if ($home) {
  120: 	return '</td><td bgcolor="#DDDDCC">'.
  121: 	    '<input type="submit" name="dumpcourse" value="'.
  122: 	    &mt('Dump Course DOCS to Construction Space').'" />';
  123:     } else {
  124: 	return'</td><td bgcolor="#DDDDCC">'.
  125:      &mt('Dump Course DOCS to Construction Space: available on other servers');
  126:     }
  127: }
  128: 
  129: # -------------------------------------------------------- Actually dump course
  130: 
  131: sub dumpcourse {
  132:     my $r=shift;
  133:     $r->print('<html><head><title>Dump DOCS</title></head>'.
  134:         &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
  135: 	      '<form name="dumpdoc" method="post">');
  136:     my ($home,$other,%outhash)=&authorhosts();
  137:     unless ($home) { return ''; }
  138:     my $origcrsid=$ENV{'request.course.id'};
  139:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  140:     if (($ENV{'form.authorspace'}) && ($ENV{'form.authorfolder'}=~/\w/)) {
  141: # Do the dumping
  142: 	unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
  143: 	my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
  144: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
  145: 	my $title=$ENV{'form.authorfolder'};
  146: 	$title=~s/[^\w\/]+/\_/g;
  147: 	my %replacehash=();
  148: 	foreach (keys %ENV) {
  149: 	    if ($_=~/^form\.namefor\_(.+)/) {
  150: 		$replacehash{$1}=$ENV{$_};
  151: 	    }
  152: 	}
  153: 	my $crs='/uploaded/'.$ENV{'request.course.id'}.'/';
  154: 	$crs=~s/\_/\//g;
  155: 	foreach (keys %replacehash) {
  156: 	    my $newfilename=$title.'/'.$replacehash{$_};
  157: 	    $newfilename=~s/[^\w\/\.]+/\_/g;
  158: 	    my @dirs=split(/\//,$newfilename);
  159: 	    my $path='/home/'.$ca.'/public_html';
  160: 	    my $makepath=$path;
  161: 	    my $fail=0;
  162: 	    for (my $i=0;$i<$#dirs;$i++) {
  163: 		$makepath.='/'.$dirs[$i];
  164: 		unless (-e $makepath) { 
  165: 		    unless(mkdir($makepath,0777)) { $fail=1; } 
  166: 		}
  167: 	    }
  168: 	    $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
  169: 	    if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
  170: 		if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
  171: 		    print $fh &Apache::loncreatecourse::rewritefile(
  172:          &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_),
  173: 				     (%replacehash,$crs => '')
  174: 								    );
  175: 		} else {
  176: 		    print $fh
  177:          &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_);
  178: 		       }
  179: 		$fh->close();
  180: 	    } else {
  181: 		$fail=1;
  182: 	    }
  183: 	    if ($fail) {
  184: 		$r->print('<font color="red">fail</font>');
  185: 	    } else {
  186: 		$r->print('<font color="green">ok</font>');
  187: 	    }
  188: 	}
  189:     } else {
  190: # Input form
  191: 	unless ($home==1) {
  192: 	    $r->print(
  193: 		      '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
  194: 	}
  195: 	foreach (sort keys %outhash) {
  196: 	    if ($_=~/^home_(.+)$/) {
  197: 		if ($home==1) {
  198: 		    $r->print(
  199: 		  '<input type="hidden" name="authorspace" value="'.$1.'" />');
  200: 		} else {
  201: 		    $r->print('<option value="'.$1.'">'.$_.'</option>');
  202: 		}
  203: 	    }
  204: 	}
  205: 	unless ($home==1) {
  206: 	    $r->print('</select>');
  207: 	}
  208: 	my $title=$origcrsdata{'description'};
  209: 	$title=~s/\s+/\_/gs;
  210: 	$title=~s/\W//gs;
  211: 	$r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
  212: 	&tiehash();
  213: 	$r->print('<h3>'.&mt('Filenames in Construction Space').'</h3><table border="2"><tr><th>'.&mt('Internal Filename').'</th><th>'.&mt('Title').'</th><th>'.&mt('Save as ...').'</th></tr>');
  214: 	foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
  215: 	    $r->print('<tr><td>'.$_.'</td>');
  216: 	    my ($ext)=($_=~/\.(\w+)$/);
  217: 	    my $title=$hash{'title_'.$hash{
  218: 		'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
  219: 	    $r->print('<td>'.($title?$title:'&nbsp;').'</td>');
  220: 	    unless ($title) {
  221: 		$title=$_;
  222: 	    }
  223: 	    $title=~s/\.(\w+)$//;
  224: 	    $title=~s/\W+/\_/gs;
  225: 	    $title.='.'.$ext;
  226: 	    $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
  227: 	}
  228: 	$r->print("</table>\n");
  229: 	&untiehash();
  230: 	$r->print(
  231:   '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump Course DOCS').'" /></p></form>');
  232:     }
  233: }
  234: 
  235: 
  236: # Imports the given (name, url) resources into the course
  237: # coursenum, coursedom, and folder must precede the list
  238: sub group_import {
  239:     my $coursenum = shift;
  240:     my $coursedom = shift;
  241:     my $folder = shift;
  242:     while (@_) {
  243: 	my $name = shift;
  244: 	my $url = shift;
  245: 	if ($url) {
  246: 	    my $idx = $#Apache::lonratedt::resources + 1;
  247: 	    $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
  248: 	    my $ext = 'false';
  249: 	    if ($url=~/^http:\/\//) { $ext = 'true'; }
  250: 	    $url =~ s/:/\&colon;/g;
  251: 	    $name =~ s/:/\&colon;/g;
  252: 	    $Apache::lonratedt::resources[$idx] = 
  253: 		join ':', ($name, $url, $ext, 'normal', 'res');
  254: 	}
  255:     }
  256:     return &storemap($coursenum, $coursedom, $folder.'.sequence');
  257: }
  258: 
  259: sub editor {
  260:     my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
  261:     if ($ENV{'form.foldername'}) {
  262: 	$r->print('<h3>Folder: '.$ENV{'form.foldername'}.'</h3>');
  263:     }
  264:     my $errtext='';
  265:     my $fatal=0;
  266:     ($errtext,$fatal)=
  267:           &mapread($coursenum,$coursedom,$folder.'.sequence');
  268:     if ($#Apache::lonratedt::order<1) {
  269:        	$Apache::lonratedt::order[0]=1;
  270:         $Apache::lonratedt::resources[1]='';
  271:     }
  272:     if ($fatal) {
  273: 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
  274:     } else {
  275: # ------------------------------------------------------------ Process commands
  276: # ---------------- if they are for this folder and user allowed to make changes
  277: 	if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
  278: # upload a file, if present
  279:            if (($ENV{'form.uploaddoc.filename'}) &&
  280:                ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
  281: 	    if ($folder=~/^$1/) {
  282: # this is for a course, not a user, so set coursedoc flag
  283: # probably the only place in the system where this should be "1"
  284: 	      my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
  285:               my $ext='false';
  286:               if ($url=~/^http\:\/\//) { $ext='true'; }
  287:               $url=~s/\:/\&colon;/g;
  288: 	      my $comment=$ENV{'form.comment'};
  289:               $comment=~s/\</\&lt\;/g;
  290:               $comment=~s/\>/\&gt\;/g;
  291:               $comment=~s/\:/\&colon;/g;
  292:               if ($folder=~/^supplemental/) {
  293: 		  $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
  294: 		      $ENV{'user.domain'}.'___&&&___'.$comment;
  295:               }
  296:               my $newidx=$#Apache::lonratedt::resources+1;
  297:               $Apache::lonratedt::resources[$newidx]=
  298:                   $comment.':'.$url.':'.$ext.':normal:res';
  299:               $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
  300:                                                               $newidx;       
  301: 
  302: 	      ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
  303: 	      if ($fatal) {
  304: 		  $r->print('<p><font color="red">'.$errtext.'</font></p>');
  305: 		  return;
  306: 	      }
  307: 	     }
  308:             }
  309: 	    if ($ENV{'form.cmd'}) {
  310:                 my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
  311:                 if ($cmd eq 'del') {
  312: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
  313:                         $Apache::lonratedt::order[$i]=
  314:                           $Apache::lonratedt::order[$i+1];
  315:                     }
  316:                     $#Apache::lonratedt::order--;
  317:                 } elsif ($cmd eq 'up') {
  318: 		  if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
  319:                     my $i=$Apache::lonratedt::order[$idx-1];
  320:                     $Apache::lonratedt::order[$idx-1]=
  321: 			$Apache::lonratedt::order[$idx];
  322:                     $Apache::lonratedt::order[$idx]=$i;
  323: 		   }
  324:                 } elsif ($cmd eq 'down') {
  325: 		   if (defined($Apache::lonratedt::order[$idx+1])) {
  326:                     my $i=$Apache::lonratedt::order[$idx+1];
  327:                     $Apache::lonratedt::order[$idx+1]=
  328: 			$Apache::lonratedt::order[$idx];
  329:                     $Apache::lonratedt::order[$idx]=$i;
  330: 		   }
  331:                 } elsif ($cmd eq 'rename') {
  332:                     my ($rtitle,@rrest)=split(/\:/,
  333:                        $Apache::lonratedt::resources[
  334: 				       $Apache::lonratedt::order[$idx]]);
  335:                     my $comment=
  336:                      &HTML::Entities::decode($ENV{'form.title'});
  337:                     $comment=~s/\</\&lt\;/g;
  338:                     $comment=~s/\>/\&gt\;/g;
  339:                     $comment=~s/\:/\&colon;/g;
  340:                     $Apache::lonratedt::resources[
  341: 				       $Apache::lonratedt::order[$idx]]=
  342:                              $comment.':'.join(':',@rrest);
  343:                     
  344:                 }
  345: # Store the changed version
  346: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
  347: 					    $folder.'.sequence');
  348: 		if ($fatal) {
  349: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
  350: 		    return;
  351: 		}
  352:             }
  353: # Group import/search
  354: 	    if ($ENV{'form.importdetail'}) {
  355: 		my @imports;
  356: 		foreach (split(/\&/,$ENV{'form.importdetail'})) {
  357: 		    if (defined($_)) {
  358: 			my ($name,$url)=split(/\=/,$_);
  359: 			$name=&Apache::lonnet::unescape($name);
  360: 			$url=&Apache::lonnet::unescape($url);
  361: 			push @imports, $name, $url;
  362: 		    }
  363: 		}
  364: # Store the changed version
  365: 		($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
  366: 					       @imports);
  367: 		if ($fatal) {
  368: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
  369: 		    return;
  370: 		}
  371:             }
  372: # Loading a complete map
  373: 	   if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
  374: 	       foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
  375:                    my $idx=$#Apache::lonratedt::resources;
  376:                    $idx++;
  377:                    $Apache::lonratedt::resources[$idx]=$_;
  378:                    $Apache::lonratedt::order
  379: 		       [$#Apache::lonratedt::order+1]=$idx;
  380: 	       }
  381: 
  382: # Store the changed version
  383: 	       ($errtext,$fatal)=&storemap($coursenum,$coursedom,
  384: 					   $folder.'.sequence');
  385: 	       if ($fatal) {
  386: 		   $r->print('<p><font color="red">'.$errtext.'</font></p>');
  387: 		   return;
  388: 	       }
  389:            }
  390:        }
  391: # ---------------------------------------------------------------- End commands
  392: # ---------------------------------------------------------------- Print screen
  393:         my $idx=0;
  394:         $r->print('<table>');
  395:         foreach (@Apache::lonratedt::order) {
  396:            my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
  397:            unless ($name) {  $name=(split(/\//,$url))[-1]; }
  398:            unless ($name) { next; }
  399:            $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_));
  400:            $idx++;
  401:         }
  402:         $r->print('</table>');
  403:     }
  404: }
  405: 
  406: # --------------------------------------------------------------- An entry line
  407: 
  408: sub entryline {
  409:     my ($index,$title,$url,$folder,$allowed,$residx)=@_;
  410:     $title=~s/\&colon\;/\:/g;
  411:     $title=&HTML::Entities::encode(&HTML::Entities::decode(
  412:      &Apache::lonnet::unescape($title)),'\"\<\>\&\'');
  413:     my $renametitle=$title;
  414:     my $foldertitle=$title;
  415:     if ($title=~
  416:  /^(\d+)\_\_\_\&amp\;\&amp\;\&amp\;\_\_\_(\w+)\_\_\_\&amp\;\&amp\;\&amp\;\_\_\_(\w+)\_\_\_\&amp\;\&amp\;\&amp\;\_\_\_(.*)$/
  417: 	) { 
  418:             $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
  419:             $renametitle=$4;
  420:             $title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
  421:                 &Apache::loncommon::plainname($2,$3).': <br />'.
  422: 		$foldertitle;
  423: 	}
  424:     $renametitle=~s/\&quot\;/\\\"/g;
  425:     my $line='<tr>';
  426: # Edit commands
  427:      if ($allowed) {
  428: 	 my %lt=('up' => 'Move Up',
  429: 		 'dw' => 'Move Down',
  430: 		 'rm' => 'Remove',
  431: 		 'rn' => 'Rename');
  432:       $line.=(<<END);
  433: <td><table border='0' cellspacing='2' cellpadding='0'>
  434: <tr><td bgcolor="#DDDDDD">
  435: <a href='/adm/coursedocs?folder=$folder&cmd=up_$index'>
  436: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
  437: <tr><td bgcolor="#DDDDDD">
  438: <a href='/adm/coursedocs?folder=$folder&cmd=down_$index'>
  439: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
  440: </table></td><td bgcolor="#DDDDDD">
  441: <a href='javascript:removeres("$folder","$index","$renametitle");'>
  442: <font size="-2" color="#990000">$lt{'rm'}</font></a>
  443: <a href='javascript:changename("$folder","$index","$renametitle");'>
  444: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
  445: END
  446:     }
  447: # Figure out what kind of a resource this is
  448:     my ($extension)=($url=~/\.(\w+)$/);
  449:     my $uploaded=($url=~/^\/*uploaded\//);
  450:     my $icon=&Apache::loncommon::icon($url);
  451:     my $isfolder=0;
  452:     if ($uploaded) {
  453:        if ($extension eq 'sequence') {
  454: 	  $icon=$iconpath.'/folder_closed.gif';
  455:           $url=~/\/(\w+)\.sequence/;
  456:           $url='/adm/coursedocs?folder='.$1;
  457:           $isfolder=1;
  458:        } else {
  459: 	  $url=&Apache::lonnet::tokenwrapper($url);
  460:        } 
  461:     }
  462:     $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
  463:     if (($residx) && ($folder!~/supplemental/)) {
  464:        $url.=(($url=~/\?/)?'&':'?').'symb='.
  465:        &Apache::lonnet::escape(&Apache::lonnet::symbclean(
  466:           &Apache::lonnet::declutter('uploaded/'.
  467:            $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
  468:            $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
  469:            '.sequence').
  470:            '___'.$residx.'___'.
  471: 	   &Apache::lonnet::declutter($url)));
  472:     }
  473:     if ($isfolder) { $url.='&foldername='.
  474:        &Apache::lonnet::escape($foldertitle); }
  475:     $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'" target="cat_'.$folder.
  476: 	'"><img src="'.$icon.'" border="0"></a></td>'.
  477:         "<td bgcolor='#FFFFBB'><a href='$url' target='cat_$folder'>$title</a></td></tr>";
  478:     return $line;
  479: }
  480: 
  481: # ---------------------------------------------------------------- tie the hash
  482: 
  483: sub tiehash {
  484:     $hashtied=0;
  485:     if ($ENV{'request.course.fn'}) {
  486:         if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
  487:             &GDBM_READER(),0640)) {
  488:                 $hashtied=1;
  489:         }
  490:     }    
  491: }
  492: 
  493: sub untiehash {
  494:     if ($hashtied) { untie %hash; }
  495:     $hashtied=0;
  496: }
  497: 
  498: # --------------------------------------------------------------- check on this
  499: 
  500: sub checkonthis {
  501:     my ($r,$url,$level,$title)=@_;
  502:     $alreadyseen{$url}=1;
  503:     $r->rflush();
  504:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
  505:        $r->print('<br />');
  506:        for (my $i=0;$i<=$level*5;$i++) {
  507:            $r->print('&nbsp;');
  508:        }
  509:        $r->print('<a href="'.$url.'" target="cat">'.
  510: 		 ($title?$title:$url).'</a> ');
  511:        if ($url=~/^\/res\//) {
  512: 	  my $result=&Apache::lonnet::repcopy(
  513:                               &Apache::lonnet::filelocation('',$url));
  514:           if ($result==OK) {
  515:              $r->print('<font color="green">'.&mt('ok').'</font>');
  516:              $r->rflush();
  517:              &Apache::lonnet::countacc($url);
  518:              $url=~/\.(\w+)$/;
  519:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
  520: 		 $r->print('<br />');
  521:                  $r->rflush();
  522:                  for (my $i=0;$i<=$level*5;$i++) {
  523:                      $r->print('&nbsp;');
  524:                  }
  525:                  $r->print('- '.&mt('Rendering').': ');
  526:                  my $oldpath=$ENV{'request.filename'};
  527:                  $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
  528:                  &Apache::lonxml::xmlparse($r,'web',
  529:                    &Apache::lonnet::getfile(
  530:                     &Apache::lonnet::filelocation('',$url)));
  531: 		 undef($Apache::lonhomework::parsing_a_problem);
  532: 		 $ENV{'request.filename'}=$oldpath;
  533:                  if (($Apache::lonxml::errorcount) ||
  534:                      ($Apache::lonxml::warningcount)) {
  535: 		     if ($Apache::lonxml::errorcount) {
  536:                         $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
  537: 			  $Apache::lonxml::errorcount.' '.
  538: 				  &mt('error(s)').'</b></font> ');
  539:                      }
  540: 		     if ($Apache::lonxml::warningcount) {
  541:                         $r->print('<font color="blue">'.
  542: 			  $Apache::lonxml::warningcount.' '.
  543: 				  &mt('warning(s)').'</font>');
  544:                      }
  545:                  } else {
  546:                      $r->print('<font color="green">'.&mt('ok').'</font>');
  547:                  }
  548:                  $r->rflush();
  549:              }
  550: 	     my $dependencies=
  551:                 &Apache::lonnet::metadata($url,'dependencies');
  552:              foreach (split(/\,/,$dependencies)) {
  553: 		 if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
  554:                     &checkonthis($r,$_,$level+1);
  555:                  }
  556:              }
  557:           } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
  558:              $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
  559:           } elsif ($result==HTTP_NOT_FOUND) {
  560: 	      unless ($url=~/\$/) {
  561: 		  $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
  562: 	      } else {
  563: 		  $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
  564: 	      }
  565:           } else {
  566:              $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
  567:           }
  568:       }
  569:    }
  570: }
  571: 
  572: 
  573: #
  574: # -------------------------------------------------------------- Verify Content
  575: # 
  576: sub verifycontent {
  577:    my $r=shift; 
  578:    my $loaderror=&Apache::lonnet::overloaderror($r);
  579:    if ($loaderror) { return $loaderror; }
  580: 
  581:    $r->print('<html><head><title>Verify Content</title></head>'.
  582:               &Apache::loncommon::bodytag('Verify Course Documents'));
  583:    $hashtied=0;
  584:    undef %alreadyseen;
  585:    %alreadyseen=();
  586:    &tiehash();
  587:    foreach (keys %hash) {
  588:        if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
  589:            &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
  590:        }
  591:    }
  592:    &untiehash();
  593:    $r->print('<h1>'.&mt('Done').'.</h1>');
  594: }
  595: 
  596: # -------------------------------------------------------------- Check Versions
  597: 
  598: sub checkversions {
  599:     my $r=shift;
  600:     $r->print('<html><head><title>Check Versions</title></head>'.
  601:               &Apache::loncommon::bodytag('Check Course Document Versions'));
  602:     my $header='';
  603:     my $startsel='';
  604:     my $monthsel='';
  605:     my $weeksel='';
  606:     my $daysel='';
  607:     my $allsel='';
  608:     my %changes=();
  609:     my $starttime=0;
  610:     my $haschanged=0;
  611:     my %setversions=&Apache::lonnet::dump('resourceversions',
  612: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  613: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  614: 
  615:     $hashtied=0;
  616:     &tiehash();
  617:     my %newsetversions=();
  618:     if ($ENV{'form.setmostrecent'}) {
  619: 	$haschanged=1;
  620: 	foreach (keys %hash) {
  621: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
  622: 		$newsetversions{$1}='mostrecent';
  623: 	    }
  624: 	}
  625:     } elsif ($ENV{'form.setcurrent'}) {
  626: 	$haschanged=1;
  627: 	foreach (keys %hash) {
  628: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
  629: 		my $getvers=&Apache::lonnet::getversion($1);
  630: 		if ($getvers>0) {
  631: 		    $newsetversions{$1}=$getvers;
  632: 		}
  633: 	    }
  634: 	}
  635:     } elsif ($ENV{'form.setversions'}) {
  636: 	$haschanged=1;
  637: 	foreach (keys %ENV) {
  638: 	    if ($_=~/^form\.set_version_(.+)$/) {
  639: 		my $src=$1;
  640: 		&Apache::lonnet::logthis('Found: '.$1.' '.$ENV{$_});
  641: 		if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
  642: 		    $newsetversions{$src}=$ENV{$_};
  643: 		}
  644: 	    }
  645: 	}
  646:     }
  647:     if ($haschanged) {
  648:         if (&Apache::lonnet::put('resourceversions',\%newsetversions,
  649: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  650: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {		
  651: 	    $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
  652: 	} else {
  653: 	    $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
  654: 	}
  655: 	&changewarning($r,'');
  656:     }
  657:     if ($ENV{'form.timerange'} eq 'all') {
  658: # show all documents
  659: 	$header=&mt('All Documents in Course');
  660: 	$allsel=1;
  661: 	foreach (keys %hash) {
  662: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
  663: 		my $src=$1;
  664: 		$changes{$src}=1;
  665: 	    }
  666: 	}
  667:     } else {
  668: # show documents which changed
  669: 	%changes=&Apache::lonnet::dump
  670: 	 ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  671:                      $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  672: 	my $firstkey=(keys %changes)[0];
  673: 	unless ($firstkey=~/^error\:/) {
  674: 	    unless ($ENV{'form.timerange'}) {
  675: 		$ENV{'form.timerange'}=604800;
  676: 	    }
  677: 	    my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
  678: 		.&mt('seconds');
  679: 	    if ($ENV{'form.timerange'}==-1) {
  680: 		$seltext='since start of course';
  681: 		$startsel='selected';
  682: 		$ENV{'form.timerange'}=time;
  683: 	    }
  684: 	    $starttime=time-$ENV{'form.timerange'};
  685: 	    if ($ENV{'form.timerange'}==2592000) {
  686: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
  687: 		$monthsel='selected';
  688: 	    } elsif ($ENV{'form.timerange'}==604800) {
  689: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
  690: 		$weeksel='selected';
  691: 	    } elsif ($ENV{'form.timerange'}==86400) {
  692: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
  693: 		$daysel='selected';
  694: 	    }
  695: 	    $header=&mt('Content changed').' '.$seltext;
  696: 	} else {
  697: 	    $header=&mt('No content modifications yet.');
  698: 	}
  699:     }
  700:     %setversions=&Apache::lonnet::dump('resourceversions',
  701: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  702: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  703:     my %lt=&Apache::lonlocal::texthash
  704: 	      ('st' => 'Version changes since start of Course',
  705: 	       'lm' => 'Version changes since last Month',
  706: 	       'lw' => 'Version changes since last Week',
  707: 	       'sy' => 'Version changes since Yesterday',
  708:                'al' => 'All Resources (possibly large output)',
  709: 	       'sd' => 'Display',
  710: 	       'fi' => 'File',
  711: 	       'md' => 'Modification Date',
  712:                'mr' => 'Most recently published Version',
  713: 	       've' => 'Version used in Course',
  714:                'vu' => 'Set Version to be used in Course',
  715: 'sv' => 'Set Versions to be used in Course according to Selections below',
  716: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
  717: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
  718: 	       'di' => 'Differences');
  719:     $r->print(<<ENDHEADERS);
  720: <form action="/adm/coursedocs" method="post">
  721: <input type="hidden" name="versions" value="1" />
  722: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
  723: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
  724: <select name="timerange">
  725: <option value='all' $allsel>$lt{'al'}</option>
  726: <option value="-1" $startsel>$lt{'st'}</option>
  727: <option value="2592000" $monthsel>$lt{'lm'}</option>
  728: <option value="604800" $weeksel>$lt{'lw'}</option>
  729: <option value="86400" $daysel>$lt{'sy'}</option>
  730: </select>
  731: <input type="submit" name="display" value="$lt{'sd'}" />
  732: <h3>$header</h3>
  733: <input type="submit" name="setversions" value="$lt{'sv'}" />
  734: <table border="0">
  735: ENDHEADERS
  736:     foreach (sort keys %changes) {
  737: 	if ($changes{$_}>$starttime) {
  738: 	    my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
  739: 	    my $currentversion=&Apache::lonnet::getversion($_);
  740: 	    if ($currentversion<0) {
  741: 		$currentversion=&mt('Could not be determined.');
  742: 	    }
  743: 	    my $linkurl=&Apache::lonnet::clutter($_);
  744: 	    $r->print(
  745: 		      '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
  746: 		      &Apache::lonnet::gettitle($linkurl).
  747:                       '</b></font></td></tr>'.
  748:                       '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
  749:                       '<td colspan="4">'.
  750:                       '<a href="'.$linkurl.'" target="cat">'.$linkurl.
  751: 		      '</a></td></tr>'.
  752:                       '<tr><td></td>'.
  753:                       '<td title="'.$lt{'md'}.'">'.
  754: 		      &Apache::lonlocal::locallocaltime(
  755:                            &Apache::lonnet::metadata($root.'.'.$extension,
  756:                                                      'lastrevisiondate')
  757:                                                         ).
  758:                       '</td>'.
  759:                       '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
  760:                       '<font size="+1">'.$currentversion.'</font>'.
  761:                       '</nobr></td>'.
  762:                       '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
  763:                       '<font size="+1">');
  764: # Used in course
  765: 	    my $usedversion=$hash{'version_'.$linkurl};
  766: 	    if (($usedversion) && ($usedversion ne 'mostrecent')) {
  767: 		$r->print($usedversion);
  768: 	    } else {
  769: 		$r->print($currentversion);
  770: 	    }
  771: 	    $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
  772:                       '<nobr>Use: ');
  773: # Set version
  774: 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
  775: 						      'set_version_'.$linkurl,
  776: 						      ('' => '',
  777: 						       'mostrecent' => 'most recent',
  778: 						       map {$_,$_} (1..$currentversion))));
  779: 	    $r->print('</nobr></td></tr><tr><td></td>');
  780: 	    my $lastold=1;
  781: 	    for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
  782: 		my $url=$root.'.'.$prevvers.'.'.$extension;
  783: 		if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
  784: 		    $starttime) {
  785: 		    $lastold=$prevvers;
  786: 		}
  787: 	    }
  788:             # 
  789:             # Code to figure out how many version entries should go in
  790:             # each of the four columns
  791:             my $entries_per_col = 0;
  792:             my $num_entries = ($currentversion-$lastold);
  793:             if ($num_entries % 4 == 0) {
  794:                 $entries_per_col = $num_entries/4;
  795:             } else {
  796:                 $entries_per_col = $num_entries/4 + 1;
  797:             }
  798:             my $entries_count = 0;
  799:             $r->print('<td valign="top"><font size="-2">'); 
  800:             my $cols_output = 1;
  801:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
  802: 		my $url=$root.'.'.$prevvers.'.'.$extension;
  803: 		$r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
  804: 			  '">'.&mt('Version').' '.$prevvers.'</a> ('.
  805: 			  &Apache::lonlocal::locallocaltime(
  806:                                 &Apache::lonnet::metadata($url,
  807:                                                           'lastrevisiondate')
  808:                                                             ).
  809: 			  ')');
  810: 		if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
  811:                     $r->print(' <a href="/adm/diff?filename='.
  812: 			      &Apache::lonnet::clutter($root.'.'.$extension).
  813: 			      '&versionone='.$prevvers.
  814: 			      '">'.&mt('Diffs').'</a>');
  815: 		}
  816: 		$r->print('</nobr><br />');
  817:                 if (++$entries_count % $entries_per_col == 0) {
  818:                     $r->print('</font></td>');
  819:                     if ($cols_output != 4) {
  820:                         $r->print('<td valign="top"><font size="-2">');
  821:                         $cols_output++;
  822:                     }
  823:                 }
  824: 	    }
  825:             while($cols_output++ < 4) {
  826:                 $r->print('</font></td><td><font>')
  827:             }
  828: 	    $r->print('</font></td></tr>'."\n");
  829: 	}
  830:     }
  831:     $r->print('</table></form>');
  832:     $r->print('<h1>'.&mt('Done').'.</h1>');
  833: 
  834:     &untiehash();
  835: }
  836: 
  837: sub changewarning {
  838:     my ($r,$postexec)=@_;
  839:     $r->print(
  840: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'. 
  841: '<form method="post" action="/adm/roles" target="loncapaclient">'.
  842: '<input type="hidden" name="orgurl" value="/adm/coursedocs" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
  843: &mt('Changes will become active for your current session after').
  844: ' <input type="hidden" name="'.
  845: $ENV{'request.role'}.'" value="1" /><input type="button" value="'.
  846: &mt('re-initializing course').'" onClick="reinit(this.form)"/>'.&mt(', or the next time you log in.').
  847: $help{'Caching'}.'</font></h3></form>');
  848: }
  849: 
  850: # ================================================================ Main Handler
  851: sub handler {
  852:     my $r = shift;
  853:     &Apache::loncommon::content_type($r,'text/html');
  854:     $r->send_http_header;
  855:     return OK if $r->header_only;
  856: 
  857: # --------------------------------------------- Initialize help topics for this
  858:   foreach ('Adding_Course_Doc','Main_Course_Documents',
  859:            'Adding_External_Resource','Navigate_Content',
  860:            'Adding_Folders','Docs_Overview', 'Load_Map',
  861:            'Supplemental', 'Score_Upload_Form',
  862:            'Importing_LON-CAPA_Resource','Uploading_From_Harddrive') {
  863:       $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
  864:   }
  865:     # Composite help files
  866:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
  867: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
  868:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
  869: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
  870:     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
  871: 		    'Option_Response_Simple');
  872:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
  873: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
  874:     $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
  875: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
  876:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
  877:  
  878:   if ($ENV{'form.verify'}) {
  879:       &verifycontent($r);
  880:   } elsif ($ENV{'form.versions'}) {
  881:       &checkversions($r);
  882:   } elsif ($ENV{'form.dumpcourse'}) {
  883:       &dumpcourse($r);
  884:   } else {
  885: # is this a standard course?
  886: 
  887:     my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
  888:     my $forcestandard;
  889:     my $forcesupplement;
  890:     my $script='';
  891:     my $allowed;
  892:     my $events='';
  893:     my $showdoc=0;
  894:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  895:        ['folder','foldername']);
  896:     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
  897:        $showdoc=$1;
  898:     }
  899:     unless ($showdoc) { # got called from remote
  900:        $forcestandard=($ENV{'form.folder'}=~/^default_/);
  901:        $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
  902: 
  903: # does this user have privileges to post, etc?
  904:        $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
  905:        if ($allowed) { 
  906:          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
  907:          $script=&Apache::lonratedt::editscript('simple'); 
  908:        }
  909:     } else { # got called in sequence from course
  910:        $allowed=0;
  911:        $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
  912:        $events='onLoad="'.&Apache::lonmenu::loadevents.
  913:            '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
  914:     }
  915: 
  916: # get course data
  917:     my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
  918:     my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
  919: 
  920: # get personal data
  921:  
  922:     my $uname=$ENV{'user.name'};
  923:     my $udom=$ENV{'user.domain'};
  924:     my $plainname=&Apache::lonnet::escape(
  925:                      &Apache::loncommon::plainname($uname,$udom));
  926: 
  927: # graphics settings
  928: 
  929:     $iconpath = $r->dir_config('lonIconsURL') . "/";
  930: 
  931:     my $now=time;
  932: 
  933: # print screen
  934:     $r->print(<<ENDDOCUMENT);
  935: <html>
  936: <head>
  937: <title>The LearningOnline Network with CAPA</title>
  938: <script>
  939: $script
  940: </script>
  941: ENDDOCUMENT
  942:    if ($allowed) {
  943:     $r->print(<<ENDNEWSCRIPT);
  944: <script>
  945: function makenewfolder(targetform,folderseq) {
  946:     var foldername=prompt('Name of New Folder','New Folder');
  947:     if (foldername) {
  948: 	targetform.importdetail.value=foldername+"="+folderseq;
  949:         targetform.submit();
  950:     }
  951: }
  952: 
  953: function makenewext(targetname) {
  954:     this.document.forms.extimport.useform.value=targetname;
  955:     window.open('/adm/rat/extpickframe.html');
  956: }
  957: 
  958: function makeexamupload() {
  959:    var title=prompt('Listed Title for the Uploaded Score');
  960:    if (title) { 
  961:     this.document.forms.newexamupload.importdetail.value=
  962: 	title+'=/res/lib/templates/examupload.problem';
  963:     this.document.forms.newexamupload.submit();
  964:    }
  965: }
  966: 
  967: function makesmppage() {
  968:    var title=prompt('Listed Title for the Page');
  969:    if (title) { 
  970:     this.document.forms.newsmppg.importdetail.value=
  971: 	title+'=/adm/$udom/$uname/$now/smppg';
  972:     this.document.forms.newsmppg.submit();
  973:    }
  974: }
  975: 
  976: function makesmpproblem() {
  977:    var title=prompt('Listed Title for the Problem');
  978:    if (title) { 
  979:     this.document.forms.newsmpproblem.importdetail.value=
  980: 	title+'=/res/lib/templates/simpleproblem.problem';
  981:     this.document.forms.newsmpproblem.submit();
  982:    }
  983: }
  984: 
  985: function makebulboard() {
  986:    var title=prompt('Listed Title for the Bulletin Board');
  987:    if (title) {
  988:     this.document.forms.newbul.importdetail.value=
  989: 	title+'=/adm/$udom/$uname/$now/bulletinboard';
  990:     this.document.forms.newbul.submit();
  991:    }
  992: }
  993: 
  994: function makeabout() {
  995:    var user=prompt("Enter user\@domain for User's 'About Me' Page");
  996:    if (user) {
  997:        var comp=new Array();
  998:        comp=user.split('\@');
  999:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
 1000: 	   if ((comp[0]) && (comp[1])) {
 1001: 	       this.document.forms.newaboutsomeone.importdetail.value=
 1002: 		   'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
 1003: 	       this.document.forms.newaboutsomeone.submit();
 1004: 	   }
 1005:        }
 1006:    }
 1007: }
 1008: 
 1009: function finishpick() {
 1010:     var title=this.document.forms.extimport.title.value;
 1011:     var url=this.document.forms.extimport.url.value;
 1012:     var form=this.document.forms.extimport.useform.value;
 1013:     eval
 1014:      ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
 1015:     '";this.document.forms.'+form+'.submit();');
 1016: }
 1017: 
 1018: function changename(folder,index,oldtitle) {
 1019:     var title=prompt('New Title',oldtitle);
 1020:     if (title) {
 1021: 	this.document.forms.renameform.title.value=title;
 1022: 	this.document.forms.renameform.cmd.value='rename_'+index;
 1023: 	this.document.forms.renameform.folder.value=folder;
 1024:         this.document.forms.renameform.submit();
 1025:     }
 1026: }
 1027: 
 1028: function removeres(folder,index,oldtitle) {
 1029:     if (confirm('Remove "'+oldtitle+'"?')) {
 1030: 	this.document.forms.renameform.cmd.value='del_'+index;
 1031: 	this.document.forms.renameform.folder.value=folder;
 1032:         this.document.forms.renameform.submit();
 1033:     }
 1034: }
 1035: </script>
 1036: 
 1037: ENDNEWSCRIPT
 1038:   }
 1039: # -------------------------------------------------------------------- Body tag
 1040:   $r->print('</head>'.
 1041:             &Apache::loncommon::bodytag('Course Documents','',$events,
 1042: 					'','',$showdoc).
 1043: 	    &Apache::loncommon::help_open_faq(273).
 1044: 	    &Apache::loncommon::help_open_bug('RAT'));
 1045:   unless ($showdoc) {
 1046: # -----------------------------------------------------------------------------
 1047:        my %lt=&Apache::lonlocal::texthash(
 1048:                 'uplm' => 'Upload a new main course document',
 1049:                 'upls' => 'Upload a new supplemental course document',
 1050:                 'impp' => 'Import a published document',
 1051:                 'spec' => 'Special documents',
 1052:                 'upld' => 'Upload Document',
 1053:                 'srch' => 'Search',
 1054:                 'impo' => 'Import',
 1055:                 'selm' => 'Select Map',
 1056:                 'load' => 'Load Map',
 1057:                 'newf' => 'New Folder',
 1058:                 'extr' => 'External Resource',
 1059:                 'syll' => 'Syllabus',
 1060:                 'navc' => 'Navigate Contents',
 1061:                 'sipa' => 'Simple Page',
 1062:                 'sipr' => 'Simple Problem',
 1063:                 'scuf' => 'Score Upload Form',
 1064:                 'bull' => 'Bulletin Board',
 1065:                 'mypi' => 'My Personal Info',
 1066: 		'abou' => 'About User',
 1067:                 'file' =>  'File',
 1068:                 'title' => 'Title',
 1069:                 'comment' => 'Comment' 
 1070: 					  );
 1071: # -----------------------------------------------------------------------------
 1072:     if ($allowed) {
 1073:        my $dumpbut=&dumpbutton();
 1074:        my %lt=&Apache::lonlocal::texthash(
 1075: 					 'vc' => 'Verify Content',
 1076: 					 'cv' => 'Check/Set Resource Versions',
 1077: 					  );
 1078:        $r->print(<<ENDCOURSEVERIFY);
 1079: <form name="renameform" method="post" action="/adm/coursedocs">
 1080: <input type="hidden" name="title" />
 1081: <input type="hidden" name="cmd" />
 1082: <input type="hidden" name="folder" />
 1083: </form>
 1084: <form name="simpleedit" method="post" action="/adm/coursedocs">
 1085: <input type=hidden name="importdetail" value="">
 1086: <input type="hidden" name="folder" />
 1087: </form>
 1088: <form action="/adm/coursedocs" method="post" name="courseverify">
 1089: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
 1090: <tr><td bgcolor="#DDDDCC">
 1091: <input type="submit" name="verify" value="$lt{'vc'}" />
 1092: </td><td bgcolor="#DDDDCC">
 1093: <input type="submit" name="versions" value="$lt{'cv'}" />
 1094: $dumpbut
 1095: </td></tr></table>
 1096: </form>
 1097: ENDCOURSEVERIFY
 1098:        $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
 1099: 		     &mt('Editing the Table of Contents for your Course')));
 1100:     }
 1101: # --------------------------------------------------------- Standard documents
 1102:     $r->print('<table border=2 cellspacing=4 cellpadding=4>');
 1103:     if (($standard) && ($allowed) && (!$forcesupplement)) {
 1104:        $r->print('<tr><td bgcolor="#BBBBBB"><h2>'.&mt('Main Course Documents').
 1105:   ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
 1106:        my $folder=$ENV{'form.folder'};
 1107:        unless ($folder=~/^default/) { $folder='default'; }
 1108:        my $postexec='';
 1109:        if ($folder eq 'default') {
 1110: 	   $r->print('<script>this.window.name="loncapaclient";</script>');
 1111:        } else {
 1112:            $postexec='self.close();';
 1113:        }
 1114:        $hadchanges=0;
 1115:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
 1116:        if ($hadchanges) {
 1117: 	   &changewarning($r,$postexec);
 1118:        }
 1119:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 1120:                      '.sequence';
 1121:        $r->print(<<ENDFORM);
 1122: <table cellspacing=4 cellpadding=4><tr>
 1123: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
 1124: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
 1125: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
 1126: </tr>
 1127: <tr><td bgcolor="#DDDDDD">
 1128: $lt{'file'}:<br />
 1129: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
 1130: <input type="file" name="uploaddoc" size="40">
 1131: <br />
 1132: $lt{'title'}:<br />
 1133: <input type="text" size="50" name="comment">
 1134: <input type="hidden" name="folder" value="$folder">
 1135: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1136: <input type="hidden" name="cmd" value="upload_default">
 1137: <input type="submit" value="$lt{'upld'}">
 1138: <nobr>
 1139:  $help{'Uploading_From_Harddrive'}
 1140: </nobr>
 1141: </form>
 1142: </td>
 1143: <td bgcolor="#DDDDDD">
 1144: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
 1145: <input type="hidden" name="folder" value="$folder">
 1146: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1147: <input type=button onClick=
 1148: "javascript:document.forms.simpleedit.folder.value='$folder';groupsearch()" value="$lt{'srch'}">
 1149: <nobr>
 1150: <input type=button onClick=
 1151: "javascript:document.forms.simpleedit.folder.value='$folder';groupimport();" value="$lt{'impo'}">
 1152: $help{'Importing_LON-CAPA_Resource'}
 1153: </nobr>
 1154: <p>
 1155: <hr />
 1156: <input type="text" size="20" name="importmap"><br />
 1157: <nobr><input type=button 
 1158: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
 1159: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
 1160: $help{'Load_Map'}</nobr>
 1161: </p>
 1162: </form>
 1163: </td><td bgcolor="#DDDDDD">
 1164: <form action="/adm/coursedocs" method="post" name="newfolder">
 1165: <input type="hidden" name="folder" value="$folder">
 1166: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1167: <input type=hidden name="importdetail" value="">
 1168: <nobr>
 1169: <input name="newfolder" type="button"
 1170: onClick="javascript:makenewfolder(this.form,'$folderseq');"
 1171: value="$lt{'newf'}" />$help{'Adding_Folders'}
 1172: </nobr>
 1173: </form>
 1174: <form action="/adm/coursedocs" method="post" name="newext">
 1175: <input type="hidden" name="folder" value="$folder">
 1176: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1177: <input type=hidden name="importdetail" value="">
 1178: <nobr>
 1179: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
 1180: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
 1181: </nobr>
 1182: </form>
 1183: <form action="/adm/coursedocs" method="post" name="newsyl">
 1184: <input type="hidden" name="folder" value="$folder">
 1185: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1186: <input type=hidden name="importdetail" 
 1187: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
 1188: <nobr>
 1189: <input name="newsyl" type="submit" value="$lt{'syll'}" /> 
 1190:  $help{'Syllabus'}
 1191: </nobr>
 1192: </form>
 1193: <form action="/adm/coursedocs" method="post" name="newnav">
 1194: <input type="hidden" name="folder" value="$folder">
 1195: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1196: <input type=hidden name="importdetail" 
 1197: value="Navigate Content=/adm/navmaps">
 1198: <nobr>
 1199: <input name="newnav" type="submit" value="$lt{'navc'}" />
 1200: $help{'Navigate_Content'}
 1201: </nobr>
 1202: </form>
 1203: <form action="/adm/coursedocs" method="post" name="newsmppg">
 1204: <input type="hidden" name="folder" value="$folder">
 1205: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1206: <input type=hidden name="importdetail" value="">
 1207: <nobr>
 1208: <input name="newsmppg" type="button" value="$lt{'sipa'}"
 1209: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
 1210: </nobr>
 1211: </form>
 1212: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
 1213: <input type="hidden" name="folder" value="$folder">
 1214: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1215: <input type=hidden name="importdetail" value="">
 1216: <nobr>
 1217: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
 1218: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
 1219: </nobr>
 1220: </form>
 1221: <form action="/adm/coursedocs" method="post" name="newexamupload">
 1222: <input type="hidden" name="folder" value="$folder">
 1223: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1224: <input type=hidden name="importdetail" value="">
 1225: <nobr>
 1226: <input name="newexamupload" type="button" value="$lt{'scuf'}"
 1227: onClick="javascript:makeexamupload();" />
 1228: $help{'Score_Upload_Form'}
 1229: </nobr>
 1230: </form>
 1231: <form action="/adm/coursedocs" method="post" name="newbul">
 1232: <input type="hidden" name="folder" value="$folder">
 1233: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1234: <input type=hidden name="importdetail" value="">
 1235: <nobr>
 1236: <input name="newbulletin" type="button" value="$lt{'bull'}"
 1237: onClick="javascript:makebulboard();" />
 1238: $help{'Bulletin Board'}
 1239: </nobr>
 1240: </form>
 1241: <form action="/adm/coursedocs" method="post" name="newaboutme">
 1242: <input type="hidden" name="folder" value="$folder">
 1243: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1244: <input type=hidden name="importdetail" 
 1245: value="$plainname=/adm/$udom/$uname/aboutme">
 1246: <nobr>
 1247: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
 1248: $help{'My Personal Info'}
 1249: </nobr>
 1250: </form>
 1251: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
 1252: <input type="hidden" name="folder" value="$folder">
 1253: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1254: <input type=hidden name="importdetail" value="">
 1255: <nobr>
 1256: <input name="newaboutsomeone" type="button" value="$lt{'abou'}" 
 1257: onClick="javascript:makeabout();" />
 1258: </nobr>
 1259: </form>
 1260: </td></tr>
 1261: </table>
 1262: ENDFORM
 1263:        $r->print('</td></tr>');
 1264:     }
 1265: # ----------------------------------------------------- Supplemental documents
 1266:     if (!$forcestandard) {
 1267:        $r->print(
 1268:   '<tr><td bgcolor="#BBBBBB"><h2>'.&mt('Supplemental Course Documents').
 1269:   ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
 1270:        my $folder=$ENV{'form.folder'};
 1271:        unless ($folder=~/supplemental/) { $folder='supplemental'; }
 1272:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
 1273:        if ($allowed) {
 1274:        my $folderseq=
 1275:                   '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
 1276:                      '.sequence';
 1277: 
 1278:           $r->print(<<ENDSUPFORM);
 1279: <table cellspacing=4 cellpadding=4><tr>
 1280: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
 1281: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
 1282: </tr>
 1283: <tr><td bgcolor="#DDDDDD">
 1284: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
 1285: <input type="file" name="uploaddoc" size="40">
 1286: <br />$lt{'comment'}:<br />
 1287: <textarea cols=50 rows=4 name='comment'>
 1288: </textarea>
 1289: <input type="hidden" name="folder" value="$folder">
 1290: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1291: <input type="hidden" name="cmd" value="upload_supplemental">
 1292: <nobr>
 1293: <input type="submit" value="$lt{'upld'}">
 1294:  $help{'Uploading_From_Harddrive'}
 1295: </nobr>
 1296: </form>
 1297: </td>
 1298: <td bgcolor="#DDDDDD">
 1299: <form action="/adm/coursedocs" method="post" name="supnewfolder">
 1300: <input type="hidden" name="folder" value="$folder">
 1301: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1302: <input type=hidden name="importdetail" value="">
 1303: <nobr>
 1304: <input name="newfolder" type="button"
 1305: onClick="javascript:makenewfolder(this.form,'$folderseq');"
 1306: value="$lt{'newf'}" /> $help{'Adding_Folders'}
 1307: </nobr>
 1308: </form>
 1309: <form action="/adm/coursedocs" method="post" name="supnewext">
 1310: <input type="hidden" name="folder" value="$folder">
 1311: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1312: <input type=hidden name="importdetail" value="">
 1313: <nobr>
 1314: <input name="newext" type="button" 
 1315: onClick="javascript:makenewext('supnewext');"
 1316: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
 1317: </nobr>
 1318: </form>
 1319: <form action="/adm/coursedocs" method="post" name="supnewsyl">
 1320: <input type="hidden" name="folder" value="$folder">
 1321: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1322: <input type=hidden name="importdetail" 
 1323: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
 1324: <nobr>
 1325: <input name="newsyl" type="submit" value="$lt{'syll'}" />
 1326: $help{'Syllabus'}
 1327: </nobr>
 1328: </form>
 1329: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
 1330: <input type="hidden" name="folder" value="$folder">
 1331: <input type="hidden" name="foldername" value="$ENV{'form.foldername'}">
 1332: <input type=hidden name="importdetail" 
 1333: value="$plainname=/adm/$udom/$uname/aboutme">
 1334: <nobr>
 1335: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
 1336: $help{'My Personal Info'}
 1337: </nobr>
 1338: </form>
 1339: </td></tr>
 1340: </table></td></tr>
 1341: ENDSUPFORM
 1342:        }
 1343:     }
 1344:     if ($allowed) {
 1345: 	$r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
 1346:     }
 1347:     $r->print('</table>');
 1348:   } else {
 1349: # -------------------------------------------------------- This is showdoc mode
 1350:       $r->print("<h1>".&mt('Uploaded Document').'</h1><p>'.
 1351: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
 1352:          &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
 1353:   }
 1354:  }
 1355:  $r->print('</body></html>');
 1356:  return OK;
 1357: } 
 1358: 
 1359: 1;
 1360: __END__

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