File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.115: download - view: text, annotated - select for diffs
Wed Apr 7 21:40:21 2004 UTC (20 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- BUG#1331, okay all of the main/supp buttons work for nested folders, however they don't currently work on the the main folders, need to debug why

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

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