File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.119: download - view: text, annotated - select for diffs
Sat Apr 24 23:03:49 2004 UTC (20 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
Saving my work till I can get DOCS-courses to work again.

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

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