File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.121: download - view: text, annotated - select for diffs
Mon Apr 26 16:56:26 2004 UTC (20 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
Saving my work on DOCS parameter setting. Currently only works for first
resource.

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

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