File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.116: download - view: text, annotated - select for diffs
Wed Apr 7 22:32:18 2004 UTC (20 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- supplemental is still dysfunctional, but Main Course Docs looks and acts correctly

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

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