File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.122: download - view: text, annotated - select for diffs
Mon Apr 26 17:50:37 2004 UTC (20 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #883: Being able to set parameters in DOCS

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

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