File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.144: download - view: text, annotated - select for diffs
Sat Sep 18 17:03:25 2004 UTC (19 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- doan't allow things to be renamed as nothign

    1: # The LearningOnline Network
    2: # Documents
    3: #
    4: # $Id: londocs.pm,v 1.144 2004/09/18 17:03:25 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 Apache::lonnavmaps;
   40: use HTML::Entities;
   41: use GDBM_File;
   42: use Apache::lonlocal;
   43: use Cwd;
   44: 
   45: my $iconpath;
   46: 
   47: my %hash;
   48: 
   49: my $hashtied;
   50: my %alreadyseen=();
   51: 
   52: my $hadchanges;
   53: 
   54: # Available help topics
   55: 
   56: my %help=();
   57: 
   58: # Mapread read maps into lonratedt::global arrays 
   59: # @order and @resources, determines status
   60: # sets @order - pointer to resources in right order
   61: # sets @resources - array with the resources with correct idx
   62: #
   63: 
   64: sub mapread {
   65:     my ($coursenum,$coursedom,$map)=@_;
   66:     return
   67:       &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
   68:                                 $map);
   69: }
   70: 
   71: sub storemap {
   72:     my ($coursenum,$coursedom,$map)=@_;
   73:     my ($outtext,$errtext)=
   74:       &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
   75:                                 $map,1);
   76:     if ($errtext) { return ($errtext,2); }
   77:     
   78:     $hadchanges=1;
   79:     return ($errtext,0);
   80: }
   81: 
   82: # ----------------------------------------- Return hash with valid author names
   83: 
   84: sub authorhosts {
   85:     my %outhash=();
   86:     my $home=0;
   87:     my $other=0;
   88:     foreach (keys %ENV) {
   89: 	if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
   90: 	    my $role=$1;
   91: 	    my $realm=$2;
   92: 	    my ($start,$end)=split(/\./,$ENV{$_});
   93: 	    if (($start) && ($start>time)) { next; }
   94: 	    if (($end) && (time>$end)) { next; }
   95: 	    my $ca; my $cd;
   96: 	    if ($1 eq 'au') {
   97: 		$ca=$ENV{'user.name'};
   98: 		$cd=$ENV{'user.domain'};
   99: 	    } else {
  100: 		($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
  101: 	    }
  102: 	    my $allowed=0;
  103: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
  104: 	    my @ids=&Apache::lonnet::current_machine_ids();
  105: 	    foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
  106: 	    if ($allowed) {
  107: 		$home++;
  108: 		$outhash{'home_'.$ca.'@'.$cd}=1;
  109: 	    } else {
  110: 		$outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
  111: 		$other++;
  112: 	    }
  113: 	}
  114:     }
  115:     return ($home,$other,%outhash);
  116: }
  117: # ------------------------------------------------------ Generate "dump" button
  118: 
  119: sub dumpbutton {
  120:     my ($home,$other,%outhash)=&authorhosts();
  121:     if ($home+$other==0) { return ''; }
  122:     my $output='</td><td bgcolor="#DDDDCC">';
  123:     if ($home) {
  124: 	return '</td><td bgcolor="#DDDDCC">'.
  125: 	    '<input type="submit" name="dumpcourse" value="'.
  126: 	    &mt('Dump Course DOCS to Construction Space').'" />'.
  127: 	    &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
  128:     } else {
  129: 	return'</td><td bgcolor="#DDDDCC">'.
  130:      &mt('Dump Course DOCS to Construction Space: available on other servers');
  131:     }
  132: }
  133: 
  134: # -------------------------------------------------------- Actually dump course
  135: 
  136: sub dumpcourse {
  137:     my $r=shift;
  138:     $r->print('<html><head><title>Dump DOCS</title></head>'.
  139:         &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
  140: 	      '<form name="dumpdoc" method="post">');
  141:     my ($home,$other,%outhash)=&authorhosts();
  142:     unless ($home) { return ''; }
  143:     my $origcrsid=$ENV{'request.course.id'};
  144:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  145:     if (($ENV{'form.authorspace'}) && ($ENV{'form.authorfolder'}=~/\w/)) {
  146: # Do the dumping
  147: 	unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
  148: 	my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
  149: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
  150: 	my $title=$ENV{'form.authorfolder'};
  151: 	$title=~s/[^\w\/]+/\_/g;
  152: 	my %replacehash=();
  153: 	foreach (keys %ENV) {
  154: 	    if ($_=~/^form\.namefor\_(.+)/) {
  155: 		$replacehash{$1}=$ENV{$_};
  156: 	    }
  157: 	}
  158: 	my $crs='/uploaded/'.$ENV{'request.course.id'}.'/';
  159: 	$crs=~s/\_/\//g;
  160: 	foreach (keys %replacehash) {
  161: 	    my $newfilename=$title.'/'.$replacehash{$_};
  162: 	    $newfilename=~s/[^\w\/\.\/]+/\_/g;
  163: 	    my @dirs=split(/\//,$newfilename);
  164: 	    my $path='/home/'.$ca.'/public_html';
  165: 	    my $makepath=$path;
  166: 	    my $fail=0;
  167: 	    for (my $i=0;$i<$#dirs;$i++) {
  168: 		$makepath.='/'.$dirs[$i];
  169: 		unless (-e $makepath) { 
  170: 		    unless(mkdir($makepath,0777)) { $fail=1; } 
  171: 		}
  172: 	    }
  173: 	    $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
  174: 	    if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
  175: 		if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
  176: 		    print $fh &Apache::loncreatecourse::rewritefile(
  177:          &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_),
  178: 				     (%replacehash,$crs => '')
  179: 								    );
  180: 		} else {
  181: 		    print $fh
  182:          &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_);
  183: 		       }
  184: 		$fh->close();
  185: 	    } else {
  186: 		$fail=1;
  187: 	    }
  188: 	    if ($fail) {
  189: 		$r->print('<font color="red">fail</font>');
  190: 	    } else {
  191: 		$r->print('<font color="green">ok</font>');
  192: 	    }
  193: 	}
  194:     } else {
  195: # Input form
  196: 	unless ($home==1) {
  197: 	    $r->print(
  198: 		      '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
  199: 	}
  200: 	foreach (sort keys %outhash) {
  201: 	    if ($_=~/^home_(.+)$/) {
  202: 		if ($home==1) {
  203: 		    $r->print(
  204: 		  '<input type="hidden" name="authorspace" value="'.$1.'" />');
  205: 		} else {
  206: 		    $r->print('<option value="'.$1.'">'.$1.' - '.
  207: 			      &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
  208: 		}
  209: 	    }
  210: 	}
  211: 	unless ($home==1) {
  212: 	    $r->print('</select>');
  213: 	}
  214: 	my $title=$origcrsdata{'description'};
  215: 	$title=~s/\s+/\_/gs;
  216: 	$title=~s/\W//gs;
  217: 	$r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
  218: 	&tiehash();
  219: 	$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>');
  220: 	foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
  221: 	    $r->print('<tr><td>'.$_.'</td>');
  222: 	    my ($ext)=($_=~/\.(\w+)$/);
  223: 	    my $title=$hash{'title_'.$hash{
  224: 		'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
  225: 	    $r->print('<td>'.($title?$title:'&nbsp;').'</td>');
  226: 	    unless ($title) {
  227: 		$title=$_;
  228: 	    }
  229: 	    $title=~s/\.(\w+)$//;
  230: 	    $title=~s/[^\w\/]+/\_/gs;
  231: 	    $title.='.'.$ext;
  232: 	    $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
  233: 	}
  234: 	$r->print("</table>\n");
  235: 	&untiehash();
  236: 	$r->print(
  237:   '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump Course DOCS').'" /></p></form>');
  238:     }
  239: }
  240: 
  241: # ------------------------------------------------------ Generate "export" button
  242: 
  243: sub exportbutton {
  244:     return '</td><td bgcolor="#DDDDCC">'.
  245:             '<input type="submit" name="exportcourse" value="'.
  246:             &mt('Export Course to IMS').'" />'.
  247:             &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
  248: }
  249: 
  250: sub exportcourse {
  251:     my $r=shift;
  252:     my %discussiontime = &Apache::lonnet::dump('discussiontimes',
  253:                                                $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  254:     my $numdisc = keys %discussiontime;
  255:     my $navmap = Apache::lonnavmaps::navmap->new();
  256:     my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
  257:     my $curRes;
  258:     my $outcome;
  259: 
  260:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  261:                                             ['finishexport']);
  262:     if ($ENV{'form.finishexport'}) {
  263:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  264:                                             ['archive','discussion']);
  265: 
  266:         my @exportitems = ();
  267:         if (defined($ENV{'form.archive'})) {
  268:             if (ref($ENV{'form.archive'}) eq 'ARRAY') {
  269:                 @exportitems = @{$ENV{'form.archive'}};
  270:             } else {
  271:                 $exportitems[0] = $ENV{'form.archive'};
  272:             }
  273:         }
  274:         my @discussions = ();
  275:         if (defined($ENV{'form.discussion'})) {
  276:             if (ref($ENV{'form.discussion'}) eq 'ARRAY') {
  277:                 @discussions = $ENV{'form.discussion'};
  278:             } else {
  279:                 $discussions[0] = $ENV{'form.discussion'};
  280:             }
  281:         }
  282:         if (@exportitems == 0 && @discussions == 0) {
  283:             $outcome = '<br />As you did not select any content items or discussions for export, an IMS package has not been created.  Please <a href="javascript:history.go(-1)">go back</a> to select either content items or discussions for export';
  284:         } else {
  285:             my $now = time;
  286:             my $count = 0;
  287:             my %symbs;
  288:             my $manifestok = 0;
  289:             my $imsresources;
  290:             my $tempexport;
  291:             my $copyresult;
  292:             my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
  293:             if ($manifestok) {
  294:                 &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,\$tempexport,\$copyresult,$ims_manifest);
  295:                 close($ims_manifest);
  296: 
  297: #Create zip file in prtspool
  298:                 my $imszipfile = '/prtspool/'.
  299:                 $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
  300:                    time.'_'.rand(1000000000).'.zip';
  301: # zip can cause an sh launch which can pass along all of %ENV
  302: # which can be too large for /bin/sh to handle
  303:                 my %oldENV=%ENV;
  304:                 undef(%ENV);
  305:                 my $cwd = &Cwd::getcwd();
  306:                 my $imszip = '/home/httpd/'.$imszipfile;
  307:                 chdir $tempexport;
  308:                 open(OUTPUT, "zip -r $imszip *  2> /dev/null |");
  309:                 close(OUTPUT);
  310:                 chdir $cwd;
  311:                 %ENV=%oldENV;
  312:                 undef(%oldENV);
  313:                 $outcome .= 'Download the zip file from <a href="'.$imszipfile.'">IMS course archive</a><br />';
  314:                 if ($copyresult) {
  315:                     $outcome .= 'The following errors occurred during export - '.$copyresult;
  316:                 }
  317:             } else {
  318:                 $outcome = '<br />Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file.<br />';
  319:             }
  320:         }
  321: 
  322:         $r->print('<html><head><title>Export Course</title></head>'.
  323:             &Apache::loncommon::bodytag('Export course to IMS or SCORM content package'));
  324:         $r->print($outcome);
  325:         $r->print('</body></html>');
  326:     } else {
  327:         my $display;
  328:         $display = '<form name="exportdoc" method="post">'."\n";
  329:         $display .= 'Choose which items you wish to export from your course.<br /><br />';
  330:         $display .= '<table border="0" cellspacing="0" cellpadding="3">'.
  331:                     '<tr><td><fieldset><legend>&nbsp;<b>Content items</b></legend>'.
  332:                     '<input type="button" value="check all" '.
  333:                     'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
  334:                     '&nbsp;&nbsp;<input type="button" value="uncheck all"'.
  335:                     ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.
  336:                     '<td>&nbsp;</td><td>&nbsp;</td>'.
  337:                     '<td align="right"><fieldset><legend>&nbsp;<b>Discussion posts'.
  338:                     '</b></legend><input type="button" value="check all"'.
  339:                     ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
  340:                     '&nbsp;&nbsp;<input type="button" value="uncheck all"'.
  341:                     ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.
  342:                     '</tr></table>';
  343:         my $curRes;
  344:         my $depth = 0;
  345:         my $count = 0;
  346:         my $boards = 0;
  347:         my $startcount = 5;
  348:         my %parent = ();
  349:         my %children = ();
  350:         my $lastcontainer = $startcount;
  351:         my @bgcolors = ('#F6F6F6','#FFFFFF');
  352:         $display .= '<table cellspacing="0"><tr>'.
  353:             '<td><b>Export content item?<br /></b></td><td>&nbsp;</td><td align="right">'."\n";
  354:         if ($numdisc > 0) {
  355:             $display.='<b>Export&nbsp;discussion posts?</b>'."\n";
  356:         }
  357:         $display.='&nbsp;</td></tr>';
  358:         while ($curRes = $it->next()) {
  359:             if (ref($curRes)) {
  360:                 $count ++;
  361:             }
  362:             if ($curRes == $it->BEGIN_MAP()) {
  363:                 $depth++;
  364:                 $parent{$depth} = $lastcontainer;
  365:             }
  366:             if ($curRes == $it->END_MAP()) {
  367:                 $depth--;
  368:                 $lastcontainer = $parent{$depth};
  369:             }
  370:             if (ref($curRes)) {
  371:                 my $symb = $curRes->symb();
  372:                 my $color = $count%2;
  373:                 $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".
  374:                     '<input type="checkbox" name="archive" value="'.$count.'" ';
  375:                 if (($curRes->is_sequence()) || ($curRes->is_page())) {
  376:                     my $checkitem = $count + $boards + $startcount;
  377:                     $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';
  378:                 }
  379:                 $display .= ' />'."\n";
  380:                 for (my $i=0; $i<$depth; $i++) {
  381:                     $display .= '<img src="/adm/lonIcons/whitespace1.gif" width="25" height="1" alt="" border="0" /><img src="/adm/lonIcons/whitespace1.gif" width="25" height="1" alt="" border="0" />'."\n";
  382:                 }
  383:                 if ($curRes->is_sequence()) {
  384:                     $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif">&nbsp;'."\n";
  385:                     $lastcontainer = $count + $startcount + $boards;
  386:                 } elsif ($curRes->is_page()) {
  387:                     $display .= '<img src="/adm/lonIcons/navmap.page.open.gif">&nbsp;'."\n";
  388:                     $lastcontainer = $count + $startcount + $boards;
  389:                 }
  390:                 my $currelem = $count+$boards+$startcount;
  391:                 $children{$parent{$depth}} .= $currelem.':';
  392:                 $display .= '&nbsp;'.$curRes->title().'</td>';
  393:                 if ($discussiontime{$symb} > 0) {
  394:                     $boards ++;
  395:                     $currelem = $count+$boards+$startcount;
  396:                     $display .= '<td>&nbsp;</td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" />&nbsp;</td>'."\n";
  397:                 } else {
  398:                     $display .= '<td colspan="2">&nbsp;</td>'."\n";
  399:                 }
  400:             }
  401:         }
  402:         my $scripttag = qq|
  403: <script>
  404: 
  405: function checkAll(field) {
  406:     for (i = 0; i < field.length; i++)
  407:         field[i].checked = true ;
  408: }
  409: 
  410: function uncheckAll(field) {
  411:     for (i = 0; i < field.length; i++)
  412:         field[i].checked = false ;
  413: }
  414: 
  415: function propagateCheck(item) {
  416:     if (document.exportdoc.elements[item].checked == true) {
  417:         containerCheck(item)
  418:     }
  419: } 
  420: 
  421: function containerCheck(item) {
  422:     document.exportdoc.elements[item].checked = true
  423:     var numitems = $count + $boards + $startcount
  424:     var parents = new Array(numitems)
  425:     for (var i=$startcount; i<numitems; i++) {
  426:         parents[i] = new Array
  427:     }
  428:         |;
  429: 
  430:         foreach my $container (sort { $a <=> $b } keys %children) {
  431:             my @contents = split/:/,$children{$container};
  432:             for (my $i=0; $i<@contents; $i ++) {
  433:                 $scripttag .= '    parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
  434:             }
  435:         }
  436: 
  437:         $scripttag .= qq|
  438:     if (parents[item].length > 0) {
  439:         for (var j=0; j<parents[item].length; j++) {
  440:             containerCheck(parents[item][j])
  441:         }
  442:      }   
  443: }
  444: 
  445: </script>
  446:         |;
  447:         $r->print('<html><head><title>Export Course</title>'.$scripttag.'</head>'.
  448:             &Apache::loncommon::bodytag('Export course to IMS or SCORM content package'
  449: ));
  450: 
  451:         $r->print($display.'</table>'.
  452:                   '<p><input type="hidden" name="finishexport" value="1">'.
  453:                   '<input type="submit" name="exportcourse" value="'.
  454:                   &mt('Export Course DOCS').'" /></p></form></body></html>');
  455:     }
  456: }
  457: 
  458: sub create_ims_store {
  459:     my ($now,$manifestok,$outcome,$tempexport) = @_;
  460:     $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
  461:     my $ims_manifest;
  462:     if (!-e $$tempexport) {
  463:         mkdir($$tempexport,0700);
  464:     }
  465:     $$tempexport .= '/'.$now;
  466:     if (!-e $$tempexport) {
  467:         mkdir($$tempexport,0700);
  468:     }
  469:     $$tempexport .= '/'.$ENV{'user.domain'}.'_'.$ENV{'user.name'};
  470:     if (!-e $$tempexport) {
  471:         mkdir($$tempexport,0700);
  472:     }
  473: # open manifest file
  474:     my $manifest = '/imsmanifest.xml';
  475:     my $manifestfilename = $$tempexport.$manifest;
  476:     if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
  477:         $$manifestok=1;
  478:         print $ims_manifest
  479: '<?xml version="1.0" encoding="UTF-8"?>'."\n".
  480: '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
  481: ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
  482: ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
  483: ' identifier="MANIFEST-'.$ENV{'request.course.id'}.'-'.$now.'"'.
  484: '  xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
  485: '  http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
  486: '  <organizations default="ORG-."'.$ENV{'request,course.id'}.'-'.$now.'">'."\n".
  487: '    <organization identifier="ORG-'.$ENV{'request.course.id'}.'-'.$now.'"'.
  488: ' structure="hierarchical">'."\n".
  489: '      <title>'.$ENV{'request.'.$ENV{'request.course.id'}.'.description'}.'</title>'
  490:     } else {
  491:         $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
  492: ;
  493:     }
  494:     return $ims_manifest;
  495: }
  496: 
  497: sub build_package {
  498:     my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
  499: # first iterator to look for dependencies
  500:     my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
  501:     my $curRes;
  502:     my $count = 0;
  503:     my $depth = 0;
  504:     my $lastcontainer = 0;
  505:     my %parent = ();
  506:     my @dependencies = ();
  507:     my $cnum = $ENV{'request.'.$ENV{'request.course.id'}.'.num'};
  508:     my $cdom = $ENV{'request.'.$ENV{'request.course.id'}.'.domain'};
  509:     while ($curRes = $it->next()) {
  510:         if (ref($curRes)) {
  511:             $count ++;
  512:         }
  513:         if ($curRes == $it->BEGIN_MAP()) {
  514:             $depth++;
  515:             $parent{$depth} = $lastcontainer;
  516:         }
  517:         if ($curRes == $it->END_MAP()) {
  518:             $depth--;
  519:             $lastcontainer = $parent{$depth};
  520:         }
  521:         if (ref($curRes)) {
  522:             if ($curRes->is_sequence() || $curRes->is_page()) {
  523:                 $lastcontainer = $count;
  524:             }
  525:             if (grep/^$count$/,@$exportitems) {
  526:                 &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
  527:             }
  528:         }
  529:     }
  530: # second iterator to build manifest and store resources
  531:     $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
  532:     $depth = 0;
  533:     my $prevdepth;
  534:     $count = 0;
  535:     my $imsresources;
  536:     my $pkgdepth;
  537:     if ($curRes == $it->BEGIN_MAP()) {
  538:         $prevdepth = $depth;
  539:         $depth++;
  540:     }
  541:     if ($curRes == $it->END_MAP()) {
  542:         $prevdepth = $depth;
  543:         $depth--;
  544:     }
  545: 
  546:     if (ref($curRes)) {
  547:         if ((grep/^$count$/,@$exportitems) || (grep/^$count$/,@dependencies)) {
  548:             my $symb = $curRes->symb();
  549:             my $isvisible = 'true';
  550:             my $resourceref;
  551:             if ($curRes->randomout()) {
  552:                 $isvisible = 'false';
  553:             }
  554:             unless ($curRes->is_sequence()) {
  555:                 $resourceref = 'identifierref="RES-'.$ENV{'request.course.id'}.'-'.$count.'"';
  556:             }
  557:             if (($depth <= $prevdepth) && ($count > 1)) {
  558:                 print $ims_manifest '  </item>'."\n";
  559:             }
  560:             $prevdepth = $depth;
  561: 
  562:             my $itementry =
  563:               '<item identifier="ITEM-'.$ENV{'request.course.id'}.'-'.$count.
  564:               '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
  565:               '<title>'.$curRes->title().'</title>';
  566:             print $ims_manifest "\n".$itementry;
  567: 
  568:             unless ($curRes->is_sequence()) {
  569:                 my $content_file;
  570:                 my @hrefs = ();
  571:                 &process_content($count,$curRes,$cdom,$cnum,$symb,$content_file,\@hrefs,$copyresult,$tempexport);
  572:                 if ($content_file) {
  573:                     $imsresources .= "\n".
  574:                      '   <resource identifier="RES-'.$ENV{'request.course.id'}.'-'.$count.
  575:                      '" type="webcontent" href="'.$content_file.'">'."\n".
  576:                      '       <file href="'.$content_file.'" />'."\n";
  577:                     foreach (@hrefs) {
  578:                         $imsresources .=
  579:                      '        <file href="'.$_.'" />'."\n";
  580:                     }
  581:                     $imsresources .= '    </resource>'."\n";
  582:                 }
  583:             }
  584:             $pkgdepth = $depth;
  585:         }
  586:     }
  587:     while ($pkgdepth > -1) {
  588:         print $ims_manifest "    </item>\n";
  589:         $pkgdepth --;
  590:     }
  591:     my $resource_text = qq|
  592:     </organization>
  593:   </organizations>
  594:   <resources>
  595:     $imsresources
  596:   </resources>
  597: </manifest>
  598:     |;
  599:     print $ims_manifest $resource_text;
  600: }
  601: 
  602: sub get_dependencies {
  603:     my ($exportitems,$parent,$depth,$dependencies) = @_;
  604:     if ($depth > 1) {
  605:         unless (grep/^$$parent{$depth}$/,@$exportitems || grep/^$$parent{$depth}$/,@$dependencies) {
  606:             push @$dependencies, $$parent{$depth};
  607:             if ($depth > 2) {
  608:                 &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
  609:             }
  610:         }
  611:     }
  612: }
  613: 
  614: sub process_content {
  615:     my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
  616:     my $content_type;
  617:     my $message;
  618: # find where user is author or co-author
  619:     my %roleshash = &Appache::lonnet::get_my_roles();
  620:     if ($curRes->is_page()) {
  621:         $content_type = 'page';
  622:     } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
  623:         $content_type = 'syllabus';
  624:     } elsif ($symb =~ m-\.sequence____\d+____ext-) {
  625:         $content_type = 'external';
  626:     } elsif ($symb =~ m-adm/navmaps$-) {
  627:         $content_type =  'navmap';
  628:     } elsif ($symb =~ m-adm/$cdom/$cnum/\d+/smppg$-) {
  629:         $content_type = 'simplepage';
  630:     } elsif ($symb =~ m-$-) {
  631:         $content_type = 'simpleproblem';
  632:     } elsif ($symb =~ m-adm/$cdom/$cnum/\d+/bulletinboard$-) {
  633:         $content_type = 'bulletinboard';
  634:     } elsif ($symb =~ m-adm/$cdom/$cnum/\d+/aboutme$-) {
  635:         $content_type = 'aboutme';
  636:     } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
  637:         &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,'uploaded');
  638:     } elsif ($symb =~ m-\.sequence____\d+____([^/])/([^/])-) {
  639:         my $coauth = $2.':'.$1.':ca';
  640:         my $canedit = 0;
  641:         if ($1 eq $ENV{'user.domain'} && $2 eq $ENV{'user.name'})  {
  642:             $canedit= 1;
  643:         } elsif (defined($roleshash{$coauth})) {
  644:             if ($roleshash{$coauth} =~ /(\d+):(\d+)/) {
  645:                 if (($1 < time || $1 == 0) && ($2 == 0 || $2 >= time)) {
  646:                     $canedit = 1;
  647:                 }
  648:             } elsif ($roleshash{$coauth} eq ':') {
  649:                 $canedit = 1;
  650:             }
  651:         }
  652:         if ($canedit) {
  653:             &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,'resource');
  654:         } else {
  655:             &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,'noedit');
  656:         }
  657:     }
  658:     $$copyresult .= $message."\n";
  659: }
  660: 
  661: sub replicate_content {
  662:     my ($cdom,$cnum,$tempexport,$symb,$count,$message,$caller) = @_;
  663:     my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  664:     my $feedurl = &Apache::lonnet::clutter($url);
  665: 
  666:     my $content;
  667:     my $filename;
  668:     my $repstatus;
  669:     if ($url =~ m-[^/]/(.+)$-) {
  670:         $filename = $1;
  671:         if (!-e $tempexport.'/resources') {
  672:             mkdir($tempexport.'/resources',0700);
  673:         }
  674:         if (!-e $tempexport.'/resources') {
  675:             mkdir($tempexport.'/resources/'.$count,0700);
  676:         }
  677:         my $destination = $$tempexport.'/resources/'.$count.'/'.$filename;
  678:         my $copiedfile;
  679:         if ($copiedfile = Apache::File->new('>'.$destination)) {
  680:             my $content;
  681:             if ($caller eq 'uploaded' || $caller eq 'resource') {
  682:                 $content = &Apache::lonnet::getfile($url);
  683:                 if ($content eq -1) {
  684:                     $$message = 'Could not copy file '.$filename;
  685:                 } else {
  686:                     $repstatus = 'ok';
  687:                 }
  688:             } elsif ($caller eq 'noedit') {
  689:                 my $rtncode;
  690:                 $repstatus = &getuploaded('GET',$url,$cdom,$cnum,$content,$rtncode);
  691:                 unless ($repstatus eq 'ok') {
  692:                     $$message = 'Could not render '.$url.' server message - '.$rtncode;
  693:                 }
  694:             }
  695:             if ($repstatus eq 'ok') {
  696:                 print $copiedfile $content;
  697:             }
  698:             close($copiedfile);
  699:         } else {
  700:             $$message = 'Could not open destination file for '.$filename."\n";
  701:         }
  702:     } else {
  703:         $$message = 'Could not determine name of file for ';
  704:     }
  705:     return $repstatus;
  706: }
  707: 
  708: # Imports the given (name, url) resources into the course
  709: # coursenum, coursedom, and folder must precede the list
  710: sub group_import {
  711:     my $coursenum = shift;
  712:     my $coursedom = shift;
  713:     my $folder = shift;
  714:     my $container = shift;
  715:     my $caller = shift;
  716:     while (@_) {
  717: 	my $name = shift;
  718: 	my $url = shift;
  719:         if (($url =~ m#^/uploaded/$coursedom/$coursenum/(default_\d+\.)(page|sequence)$#) && ($caller eq 'londocs')) {
  720:             my $errtext = '';
  721:             my $fatal = 0;
  722:             my $newmapstr = '<map>'."\n".
  723:                             '<resource id="1" src="" type="start"></resource>'."\n".
  724:                             '<link from="1" to="2" index="1"></link>'."\n".
  725:                             '<resource id="2" src="" type="finish"></resource>'."\n".
  726:                             '</map>';
  727:             $ENV{'form.output'}=$newmapstr;
  728:             my $home=&Apache::lonnet::homeserver($coursenum,$coursedom);
  729:             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$home,
  730:                                                 'output',$1.$2);
  731:             if ($result != m|^/uploaded/|) {
  732:                 $errtext.='Map not saved: A network error occured when trying to save the new map. ';
  733:                 $fatal = 2;
  734:             }
  735:             if ($fatal) {
  736:                 return ($errtext,$fatal);
  737:             }
  738:         }
  739: 	if ($url) {
  740: 	    my $idx = $#Apache::lonratedt::resources + 1;
  741: 	    $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
  742: 	    my $ext = 'false';
  743: 	    if ($url=~/^http:\/\//) { $ext = 'true'; }
  744: 	    $url =~ s/:/\&colon;/g;
  745: 	    $name =~ s/:/\&colon;/g;
  746: 	    $Apache::lonratedt::resources[$idx] = 
  747: 		join ':', ($name, $url, $ext, 'normal', 'res');
  748: 	}
  749:     }
  750:     return &storemap($coursenum, $coursedom, $folder.'.'.$container);
  751: }
  752: 
  753: sub breadcrumbs {
  754:     my ($where)=@_;
  755:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  756:     my (@folders);
  757:     if ($ENV{'form.pagepath'}) {
  758:         @folders = split('&',$ENV{'form.pagepath'});
  759:     } else {
  760:         @folders=split('&',$ENV{'form.folderpath'});
  761:     }
  762:     my $folderpath;
  763:     while (@folders) {
  764: 	my $folder=shift(@folders);
  765: 	my $foldername=shift(@folders);
  766: 	if ($folderpath) {$folderpath.='&';}
  767: 	$folderpath.=$folder.'&'.$foldername;
  768: 	my $url='/adm/coursedocs?folderpath='.
  769: 	    &Apache::lonnet::escape($folderpath);
  770: 	    &Apache::lonhtmlcommon::add_breadcrumb(
  771: 		      {'href'=>$url,
  772: 		       'title'=>&Apache::lonnet::unescape($foldername),
  773: 		       'text'=>'<font size="+1">'.
  774: 			   &Apache::lonnet::unescape($foldername).'</font>'
  775: 		       });
  776: 		       
  777: 						 
  778:     }
  779:     return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,
  780: 					       0,'nohelp');
  781: }
  782: 
  783: sub editor {
  784:     my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
  785: 
  786:     $r->print(&breadcrumbs($folder));
  787:     my $errtext='';
  788:     my $fatal=0;
  789:     my $container='sequence';
  790:     if ($ENV{'form.pagepath'}) {
  791:         $container='page';
  792:     }
  793:     ($errtext,$fatal)=
  794:               &mapread($coursenum,$coursedom,$folder.'.'.$container);
  795:     if ($#Apache::lonratedt::order<1) {
  796:        	$Apache::lonratedt::order[0]=1;
  797:         $Apache::lonratedt::resources[1]='';
  798:     }
  799:     if ($fatal) {
  800: 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
  801:     } else {
  802: # ------------------------------------------------------------ Process commands
  803: 
  804: # ---------------- if they are for this folder and user allowed to make changes
  805: 	if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
  806: # set parameters and change order
  807: 	    if (defined($ENV{'form.setparms'})) {
  808: 		my $idx=$ENV{'form.setparms'};
  809: # set parameters
  810: 		if ($ENV{'form.randpick_'.$idx}) {
  811: 		    &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
  812: 		} else {
  813: 		    &Apache::lonratedt::delparameter($idx,'parameter_randompick');
  814: 		}
  815: 		if ($ENV{'form.hidprs_'.$idx}) {
  816: 		    &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
  817: 		} else {
  818: 		    &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
  819: 		}
  820: 		if ($ENV{'form.encprs_'.$idx}) {
  821: 		    &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
  822: 		} else {
  823: 		    &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
  824: 		}
  825: 
  826: 		if ($ENV{'form.newpos'}) {
  827: # change order
  828: 
  829: 		    my $newpos=$ENV{'form.newpos'}-1;
  830: 		    my $currentpos=$ENV{'form.currentpos'}-1;
  831: 		    my $i;
  832: 		    my @neworder=();
  833: 		    if ($newpos>$currentpos) {
  834: # moving stuff up
  835: 			for ($i=0;$i<$currentpos;$i++) {
  836: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
  837: 			}
  838: 			for ($i=$currentpos;$i<$newpos;$i++) {
  839: 			    $neworder[$i]=$Apache::lonratedt::order[$i+1];
  840: 			}
  841:                         $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
  842: 			for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
  843: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
  844: 			}
  845: 		    } else {
  846: # moving stuff down
  847: 			for ($i=0;$i<$newpos;$i++) {
  848: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
  849: 			}
  850: 			$neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
  851: 			for ($i=$newpos+1;$i<$currentpos+1;$i++) {
  852: 			    $neworder[$i]=$Apache::lonratedt::order[$i-1];
  853: 			}
  854: 			for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
  855: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
  856: 			}
  857: 		    }
  858: 		    @Apache::lonratedt::order=@neworder;
  859: 		}
  860: # store the changed version
  861: 
  862: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
  863: 		if ($fatal) {
  864: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
  865: 		    return;
  866: 		}
  867: 		
  868: 	    }
  869: 
  870: # upload a file, if present
  871:            if (($ENV{'form.uploaddoc.filename'}) &&
  872:                ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
  873: 	    if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
  874: # this is for a course, not a user, so set coursedoc flag
  875: # probably the only place in the system where this should be "1"
  876: 	      my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
  877:               my $ext='false';
  878:               if ($url=~/^http\:\/\//) { $ext='true'; }
  879:               $url=~s/\:/\&colon;/g;
  880: 	      my $comment=$ENV{'form.comment'};
  881:               $comment=~s/\</\&lt\;/g;
  882:               $comment=~s/\>/\&gt\;/g;
  883:               $comment=~s/\:/\&colon;/g;
  884:               if ($folder=~/^supplemental/) {
  885: 		  $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
  886: 		      $ENV{'user.domain'}.'___&&&___'.$comment;
  887:               }
  888:               my $newidx=$#Apache::lonratedt::resources+1;
  889:               $Apache::lonratedt::resources[$newidx]=
  890:                   $comment.':'.$url.':'.$ext.':normal:res';
  891:               $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
  892:                                                               $newidx;       
  893: 
  894: 	      ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
  895: 	      if ($fatal) {
  896: 		  $r->print('<p><font color="red">'.$errtext.'</font></p>');
  897: 		  return;
  898: 	      }
  899: 	     }
  900:             }
  901: 	    if ($ENV{'form.cmd'}) {
  902:                 my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
  903:                 if ($cmd eq 'del') {
  904: 		    my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
  905: 		    if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) {
  906: 			&Apache::lonnet::removeuploadedurl($url);
  907: 		    }
  908: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
  909:                         $Apache::lonratedt::order[$i]=
  910:                           $Apache::lonratedt::order[$i+1];
  911:                     }
  912:                     $#Apache::lonratedt::order--;
  913:                 } elsif ($cmd eq 'up') {
  914: 		  if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
  915:                     my $i=$Apache::lonratedt::order[$idx-1];
  916:                     $Apache::lonratedt::order[$idx-1]=
  917: 			$Apache::lonratedt::order[$idx];
  918:                     $Apache::lonratedt::order[$idx]=$i;
  919: 		   }
  920:                 } elsif ($cmd eq 'down') {
  921: 		   if (defined($Apache::lonratedt::order[$idx+1])) {
  922:                     my $i=$Apache::lonratedt::order[$idx+1];
  923:                     $Apache::lonratedt::order[$idx+1]=
  924: 			$Apache::lonratedt::order[$idx];
  925:                     $Apache::lonratedt::order[$idx]=$i;
  926: 		   }
  927:                 } elsif ($cmd eq 'rename') {
  928:                     my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]];
  929:                     my ($rtitle,@rrest)=split(/\:/,
  930:                        $Apache::lonratedt::resources[
  931: 				       $Apache::lonratedt::order[$idx]]);
  932:                     my $comment=
  933:                      &HTML::Entities::decode($ENV{'form.title'});
  934:                     $comment=~s/\</\&lt\;/g;
  935:                     $comment=~s/\>/\&gt\;/g;
  936:                     $comment=~s/\:/\&colon;/g;
  937: 		    if ($comment=~/\S/) {
  938: 			$Apache::lonratedt::resources[
  939: 				       $Apache::lonratedt::order[$idx]]=
  940: 				            $comment.':'.join(':',@rrest);
  941: 		    }
  942:                 }
  943: # Store the changed version
  944: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
  945: 					    $folder.'.'.$container);
  946: 		if ($fatal) {
  947: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
  948: 		    return;
  949: 		}
  950:             }
  951: # Group import/search
  952: 	    if ($ENV{'form.importdetail'}) {
  953: 		my @imports;
  954: 		foreach (split(/\&/,$ENV{'form.importdetail'})) {
  955: 		    if (defined($_)) {
  956: 			my ($name,$url)=split(/\=/,$_);
  957: 			$name=&Apache::lonnet::unescape($name);
  958: 			$url=&Apache::lonnet::unescape($url);
  959: 			push @imports, $name, $url;
  960: 		    }
  961: 		}
  962: # Store the changed version
  963: 		($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
  964: 					       $container,'londocs',@imports);
  965: 		if ($fatal) {
  966: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
  967: 		    return;
  968: 		}
  969:             }
  970: # Loading a complete map
  971: 	   if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
  972: 	       foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
  973:                    my $idx=$#Apache::lonratedt::resources;
  974:                    $idx++;
  975:                    $Apache::lonratedt::resources[$idx]=$_;
  976:                    $Apache::lonratedt::order
  977: 		       [$#Apache::lonratedt::order+1]=$idx;
  978: 	       }
  979: 
  980: # Store the changed version
  981: 	       ($errtext,$fatal)=&storemap($coursenum,$coursedom,
  982: 					   $folder.'.'.$container);
  983: 	       if ($fatal) {
  984: 		   $r->print('<p><font color="red">'.$errtext.'</font></p>');
  985: 		   return;
  986: 	       }
  987:            }
  988:        }
  989: # ---------------------------------------------------------------- End commands
  990: # ---------------------------------------------------------------- Print screen
  991:         my $idx=0;
  992:         $r->print('<table>');
  993:         foreach (@Apache::lonratedt::order) {
  994:            my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
  995:            unless ($name) {  $name=(split(/\//,$url))[-1]; }
  996:            unless ($name) { next; }
  997:            $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
  998:            $idx++;
  999:         }
 1000: 	unless ($idx) {
 1001: 	    $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
 1002: 	}
 1003:         $r->print('</table>');
 1004:     }
 1005: }
 1006: 
 1007: # --------------------------------------------------------------- An entry line
 1008: 
 1009: sub entryline {
 1010:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
 1011:     $title=~s/\&colon\;/\:/g;
 1012:     $title=&HTML::Entities::encode(&HTML::Entities::decode(
 1013:      &Apache::lonnet::unescape($title)),'"<>&\'');
 1014:     my $renametitle=$title;
 1015:     my $foldertitle=$title;
 1016:     my $pagetitle=$title;
 1017:     my $orderidx=$Apache::lonratedt::order[$index];
 1018:     if ($title=~ /^(\d+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(.*)$/	) { 
 1019: 	$foldertitle=&Apache::lontexconvert::msgtexconverted($4);
 1020: 	$renametitle=$4;
 1021: 	$title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
 1022: 	    &Apache::loncommon::plainname($2,$3).': <br />'.
 1023: 	    $foldertitle;
 1024:     }
 1025:     $renametitle=~s/\&quot\;/\\\"/g;
 1026:     my $line='<tr>';
 1027: # Edit commands
 1028:     my $container;
 1029:     my $folderpath;
 1030:     if ($ENV{'form.folderpath'}) {
 1031:         $container = 'sequence';
 1032: 	$folderpath=&Apache::lonnet::escape($ENV{'form.folderpath'});
 1033: 	# $htmlfoldername=&HTML::Entities::encode($ENV{'form.foldername'},'<>&"');
 1034:     }
 1035:     my $pagepath;
 1036:     if ($ENV{'form.pagepath'}) {
 1037:         $container = 'page';
 1038:         $pagepath=&Apache::lonnet::escape($ENV{'form.pagepath'});
 1039:     }
 1040:     if ($allowed) {
 1041: 	my $incindex=$index+1;
 1042: 	my $selectbox='';
 1043: 	if ($folder!~/^supplemental/) {
 1044: 	    $selectbox=
 1045: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
 1046: 		'<select name="newpos" onChange="this.form.submit()">';
 1047: 	    for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
 1048: 		if ($i==$incindex) {
 1049: 		    $selectbox.='<option value="" selected="1">('.$i.')</option>';
 1050: 		} else {
 1051: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
 1052: 		}
 1053: 	    }
 1054: 	    $selectbox.='</select>';
 1055: 	}
 1056: 	my %lt=&Apache::lonlocal::texthash(
 1057:                 'up' => 'Move Up',
 1058: 		'dw' => 'Move Down',
 1059: 		'rm' => 'Remove',
 1060: 		'rn' => 'Rename');
 1061:         if ($ENV{'form.pagepath'}) {
 1062:             $line.=(<<END);
 1063: <form name="entry_$index" action="/adm/coursedocs" method="post">
 1064: <input type="hidden" name="pagepath" value="$ENV{'form.pagepath'}" />
 1065: <input type="hidden" name="setparms" value="$orderidx" />
 1066: <td><table border='0' cellspacing='2' cellpadding='0'>
 1067: <tr><td bgcolor="#DDDDDD">
 1068: <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath'>
 1069: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
 1070: <tr><td bgcolor="#DDDDDD">
 1071: <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath'>
 1072: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
 1073: </table></td>
 1074: <td>$selectbox
 1075: </td><td bgcolor="#DDDDDD">
 1076: <a href='javascript:removeres("$pagepath","$index","$renametitle","page");'>
 1077: <font size="-2" color="#990000">$lt{'rm'}</font></a>
 1078: <a href='javascript:changename("$pagepath","$index","$renametitle","page");'>
 1079: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
 1080: END
 1081:         } else {
 1082:             $line.=(<<END); 
 1083: <form name="entry_$index" action="/adm/coursedocs" method="post">
 1084: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 1085: <input type="hidden" name="setparms" value="$orderidx" />
 1086: <td><table border='0' cellspacing='2' cellpadding='0'>
 1087: <tr><td bgcolor="#DDDDDD">
 1088: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath'>
 1089: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
 1090: <tr><td bgcolor="#DDDDDD">
 1091: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath'>
 1092: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
 1093: </table></td>
 1094: <td>$selectbox
 1095: </td><td bgcolor="#DDDDDD">
 1096: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
 1097: <font size="-2" color="#990000">$lt{'rm'}</font></a>
 1098: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
 1099: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
 1100: END
 1101:         }
 1102:     }
 1103: # Figure out what kind of a resource this is
 1104:     my ($extension)=($url=~/\.(\w+)$/);
 1105:     my $uploaded=($url=~/^\/*uploaded\//);
 1106:     my $icon=&Apache::loncommon::icon($url);
 1107:     my $isfolder=0;
 1108:     my $ispage=0;
 1109:     my $folderarg;
 1110:     my $pagearg;
 1111:     my $pagefile;
 1112:     if ($uploaded) {
 1113: 	if ($extension eq 'sequence') {
 1114: 	    $icon=$iconpath.'/folder_closed.gif';
 1115: 	    $url=~/$coursenum\/([\/\w]+)\.sequence$/;
 1116: 	    $url='/adm/coursedocs?';
 1117: 	    $folderarg=$1;
 1118: 	    $isfolder=1;
 1119:         } elsif ($extension eq 'page') {
 1120:             $icon=$iconpath.'/page.gif';
 1121:             $url=~/$coursenum\/([\/\w]+)\.page$/;
 1122:             $pagearg=$1;
 1123:             $url='/adm/coursedocs?';
 1124:             $ispage=1;
 1125: 	} else {
 1126: 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
 1127: 	}
 1128:     }
 1129:     $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
 1130:     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
 1131: 	my $symb=&Apache::lonnet::symbclean(
 1132:           &Apache::lonnet::declutter('uploaded/'.
 1133:            $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
 1134:            $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
 1135:            '.sequence').
 1136:            '___'.$residx.'___'.
 1137: 	   &Apache::lonnet::declutter($url));
 1138: 	(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
 1139: 	$url=&Apache::lonnet::clutter($url);
 1140: 	if ($url=~/^\/*uploaded\//) {
 1141: 	    $url=~/\.(\w+)$/;
 1142: 	    my $embstyle=&Apache::loncommon::fileembstyle($1);
 1143: 	    if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
 1144: 		$url='/adm/wrapper'.$url;
 1145: 	    } elsif ($embstyle eq 'ssi') {
 1146: 		#do nothing with these
 1147: 	    } elsif ($url!~/\.(sequence|page)$/) {
 1148: 		$url='/adm/coursedocs/showdoc'.$url;
 1149: 	    }
 1150: 	}
 1151:         unless ($container eq 'page') {
 1152: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
 1153:         }
 1154:     }
 1155:     my $parameterset='&nbsp;';
 1156:     if ($isfolder) {
 1157: 	my $foldername=&Apache::lonnet::escape($foldertitle);
 1158: 	my $folderpath=$ENV{'form.folderpath'};
 1159: 	if ($folderpath) { $folderpath.='&' };
 1160: 	$folderpath.=$folderarg.'&'.$foldername;
 1161: 	$url.='folderpath='.&Apache::lonnet::escape($folderpath);
 1162: 	$parameterset=&mt('Randomly Pick: ').
 1163: 	    '<input type="text" size="4" name="randpick_'.$orderidx.'" value="'.
 1164: 	    (&Apache::lonratedt::getparameter($orderidx,'parameter_randompick'))[0].'" />';
 1165:     }
 1166:     if ($ispage) {
 1167:         my $pagename=&Apache::lonnet::escape($pagetitle);
 1168:         my $pagepath;
 1169:         my $folderpath=$ENV{'form.folderpath'};
 1170:         if ($folderpath) { $pagepath = $folderpath.'&' };
 1171:         $pagepath.=$pagearg.'&'.$pagename;
 1172:         $url.='pagepath='.&Apache::lonnet::escape($pagepath);
 1173:     }
 1174:     $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
 1175: 	'" border="0"></a></td>'.
 1176:         "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
 1177:     if (($allowed) && ($folder!~/^supplemental/)) {
 1178:  	my %lt=&Apache::lonlocal::texthash(
 1179:  			      'hd' => 'Hidden',
 1180:  			      'ec' => 'URL hidden',
 1181:  			      'sp' => 'Store Parameters');
 1182: 	my $enctext=
 1183: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
 1184: 	my $hidtext=
 1185: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
 1186: 	$line.=(<<ENDPARMS);
 1187: <td bgcolor="#BBBBFF"><font size='-2'>
 1188: <input type="checkbox" name="hidprs_$orderidx" $hidtext/> $lt{'hd'}</td>
 1189: <!--<td bgcolor="#BBBBFF"><font size='-2'>
 1190: <input type="checkbox" name="encprs_$orderidx" $enctext/> $lt{'ec'}</td>-->
 1191: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
 1192: <td bgcolor="#BBBBFF"><font size='-2'>
 1193: <input type="submit" value="$lt{'sp'}" />
 1194: </font></td>
 1195: ENDPARMS
 1196:     }
 1197:     $line.="</form></tr>";
 1198:     return $line;
 1199: }
 1200: 
 1201: # ---------------------------------------------------------------- tie the hash
 1202: 
 1203: sub tiehash {
 1204:     my ($mode)=@_;
 1205:     $hashtied=0;
 1206:     if ($ENV{'request.course.fn'}) {
 1207: 	if ($mode eq 'write') {
 1208: 	    if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
 1209: 		    &GDBM_WRCREAT(),0640)) {
 1210:                 $hashtied=2;
 1211: 	    }
 1212: 	} else {
 1213: 	    if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
 1214: 		    &GDBM_READER(),0640)) {
 1215:                 $hashtied=1;
 1216: 	    }
 1217: 	}
 1218:     }    
 1219: }
 1220: 
 1221: sub untiehash {
 1222:     if ($hashtied) { untie %hash; }
 1223:     $hashtied=0;
 1224: }
 1225: 
 1226: # --------------------------------------------------------------- check on this
 1227: 
 1228: sub checkonthis {
 1229:     my ($r,$url,$level,$title)=@_;
 1230:     $url=&Apache::lonnet::unescape($url);
 1231:     $alreadyseen{$url}=1;
 1232:     $r->rflush();
 1233:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
 1234:        $r->print("\n<br />");
 1235:        for (my $i=0;$i<=$level*5;$i++) {
 1236:            $r->print('&nbsp;');
 1237:        }
 1238:        $r->print('<a href="'.$url.'" target="cat">'.
 1239: 		 ($title?$title:$url).'</a> ');
 1240:        if ($url=~/^\/res\//) {
 1241: 	  my $result=&Apache::lonnet::repcopy(
 1242:                               &Apache::lonnet::filelocation('',$url));
 1243:           if ($result==OK) {
 1244:              $r->print('<font color="green">'.&mt('ok').'</font>');
 1245:              $r->rflush();
 1246:              &Apache::lonnet::countacc($url);
 1247:              $url=~/\.(\w+)$/;
 1248:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
 1249: 		 $r->print('<br />');
 1250:                  $r->rflush();
 1251:                  for (my $i=0;$i<=$level*5;$i++) {
 1252:                      $r->print('&nbsp;');
 1253:                  }
 1254:                  $r->print('- '.&mt('Rendering').': ');
 1255:                  my $oldpath=$ENV{'request.filename'};
 1256:                  $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
 1257:                  &Apache::lonxml::xmlparse($r,'web',
 1258:                    &Apache::lonnet::getfile(
 1259:                     &Apache::lonnet::filelocation('',$url)));
 1260: 		 undef($Apache::lonhomework::parsing_a_problem);
 1261: 		 $ENV{'request.filename'}=$oldpath;
 1262:                  if (($Apache::lonxml::errorcount) ||
 1263:                      ($Apache::lonxml::warningcount)) {
 1264: 		     if ($Apache::lonxml::errorcount) {
 1265:                         $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
 1266: 			  $Apache::lonxml::errorcount.' '.
 1267: 				  &mt('error(s)').'</b></font> ');
 1268:                      }
 1269: 		     if ($Apache::lonxml::warningcount) {
 1270:                         $r->print('<font color="blue">'.
 1271: 			  $Apache::lonxml::warningcount.' '.
 1272: 				  &mt('warning(s)').'</font>');
 1273:                      }
 1274:                  } else {
 1275:                      $r->print('<font color="green">'.&mt('ok').'</font>');
 1276:                  }
 1277:                  $r->rflush();
 1278:              }
 1279: 	     my $dependencies=
 1280:                 &Apache::lonnet::metadata($url,'dependencies');
 1281:              foreach (split(/\,/,$dependencies)) {
 1282: 		 if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
 1283:                     &checkonthis($r,$_,$level+1);
 1284:                  }
 1285:              }
 1286:           } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
 1287:              $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
 1288:           } elsif ($result==HTTP_NOT_FOUND) {
 1289: 	      unless ($url=~/\$/) {
 1290: 		  $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
 1291: 	      } else {
 1292: 		  $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
 1293: 	      }
 1294:           } else {
 1295:              $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
 1296:           }
 1297:       }
 1298:    }
 1299: }
 1300: 
 1301: 
 1302: #
 1303: # -------------------------------------------------------------- Verify Content
 1304: # 
 1305: sub verifycontent {
 1306:    my $r=shift; 
 1307:    my $loaderror=&Apache::lonnet::overloaderror($r);
 1308:    if ($loaderror) { return $loaderror; }
 1309: 
 1310:    $r->print('<html><head><title>Verify Content</title></head>'.
 1311:               &Apache::loncommon::bodytag('Verify Course Documents'));
 1312:    $hashtied=0;
 1313:    undef %alreadyseen;
 1314:    %alreadyseen=();
 1315:    &tiehash();
 1316:    foreach (keys %hash) {
 1317:        if ($hash{$_}=~/\.(page|sequence)$/) {
 1318: 	   if (($_=~/^src_/) && ($alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
 1319: 	       $r->print('<hr /><font color="red">'.
 1320: 			 &mt('The following sequence or page is included more than once in your course: ').
 1321: 			 &Apache::lonnet::unescape($hash{$_}).'</font><br />'.
 1322: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
 1323: 	   }
 1324:        }
 1325:        if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
 1326:            &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
 1327:        }
 1328:    }
 1329:    &untiehash();
 1330:    $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
 1331: 	     &mt('Return to DOCS').'</a>');
 1332: }
 1333: 
 1334: # -------------------------------------------------------------- Check Versions
 1335: 
 1336: sub checkversions {
 1337:     my $r=shift;
 1338:     $r->print('<html><head><title>Check Versions</title></head>'.
 1339:               &Apache::loncommon::bodytag('Check Course Document Versions'));
 1340:     my $header='';
 1341:     my $startsel='';
 1342:     my $monthsel='';
 1343:     my $weeksel='';
 1344:     my $daysel='';
 1345:     my $allsel='';
 1346:     my %changes=();
 1347:     my $starttime=0;
 1348:     my $haschanged=0;
 1349:     my %setversions=&Apache::lonnet::dump('resourceversions',
 1350: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1351: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1352: 
 1353:     $hashtied=0;
 1354:     &tiehash();
 1355:     my %newsetversions=();
 1356:     if ($ENV{'form.setmostrecent'}) {
 1357: 	$haschanged=1;
 1358: 	foreach (keys %hash) {
 1359: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
 1360: 		$newsetversions{$1}='mostrecent';
 1361: 	    }
 1362: 	}
 1363:     } elsif ($ENV{'form.setcurrent'}) {
 1364: 	$haschanged=1;
 1365: 	foreach (keys %hash) {
 1366: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
 1367: 		my $getvers=&Apache::lonnet::getversion($1);
 1368: 		if ($getvers>0) {
 1369: 		    $newsetversions{$1}=$getvers;
 1370: 		}
 1371: 	    }
 1372: 	}
 1373:     } elsif ($ENV{'form.setversions'}) {
 1374: 	$haschanged=1;
 1375: 	foreach (keys %ENV) {
 1376: 	    if ($_=~/^form\.set_version_(.+)$/) {
 1377: 		my $src=$1;
 1378: 		if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
 1379: 		    $newsetversions{$src}=$ENV{$_};
 1380: 		}
 1381: 	    }
 1382: 	}
 1383:     }
 1384:     if ($haschanged) {
 1385:         if (&Apache::lonnet::put('resourceversions',\%newsetversions,
 1386: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1387: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {		
 1388: 	    $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
 1389: 	} else {
 1390: 	    $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
 1391: 	}
 1392: 	&mark_hash_old();
 1393:     }
 1394:     &changewarning($r,'');
 1395:     if ($ENV{'form.timerange'} eq 'all') {
 1396: # show all documents
 1397: 	$header=&mt('All Documents in Course');
 1398: 	$allsel=1;
 1399: 	foreach (keys %hash) {
 1400: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
 1401: 		my $src=$1;
 1402: 		$changes{$src}=1;
 1403: 	    }
 1404: 	}
 1405:     } else {
 1406: # show documents which changed
 1407: 	%changes=&Apache::lonnet::dump
 1408: 	 ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1409:                      $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1410: 	my $firstkey=(keys %changes)[0];
 1411: 	unless ($firstkey=~/^error\:/) {
 1412: 	    unless ($ENV{'form.timerange'}) {
 1413: 		$ENV{'form.timerange'}=604800;
 1414: 	    }
 1415: 	    my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
 1416: 		.&mt('seconds');
 1417: 	    if ($ENV{'form.timerange'}==-1) {
 1418: 		$seltext='since start of course';
 1419: 		$startsel='selected';
 1420: 		$ENV{'form.timerange'}=time;
 1421: 	    }
 1422: 	    $starttime=time-$ENV{'form.timerange'};
 1423: 	    if ($ENV{'form.timerange'}==2592000) {
 1424: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
 1425: 		$monthsel='selected';
 1426: 	    } elsif ($ENV{'form.timerange'}==604800) {
 1427: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
 1428: 		$weeksel='selected';
 1429: 	    } elsif ($ENV{'form.timerange'}==86400) {
 1430: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
 1431: 		$daysel='selected';
 1432: 	    }
 1433: 	    $header=&mt('Content changed').' '.$seltext;
 1434: 	} else {
 1435: 	    $header=&mt('No content modifications yet.');
 1436: 	}
 1437:     }
 1438:     %setversions=&Apache::lonnet::dump('resourceversions',
 1439: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1440: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1441:     my %lt=&Apache::lonlocal::texthash
 1442: 	      ('st' => 'Version changes since start of Course',
 1443: 	       'lm' => 'Version changes since last Month',
 1444: 	       'lw' => 'Version changes since last Week',
 1445: 	       'sy' => 'Version changes since Yesterday',
 1446:                'al' => 'All Resources (possibly large output)',
 1447: 	       'sd' => 'Display',
 1448: 	       'fi' => 'File',
 1449: 	       'md' => 'Modification Date',
 1450:                'mr' => 'Most recently published Version',
 1451: 	       've' => 'Version used in Course',
 1452:                'vu' => 'Set Version to be used in Course',
 1453: 'sv' => 'Set Versions to be used in Course according to Selections below',
 1454: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
 1455: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
 1456: 	       'di' => 'Differences');
 1457:     $r->print(<<ENDHEADERS);
 1458: <form action="/adm/coursedocs" method="post">
 1459: <input type="hidden" name="versions" value="1" />
 1460: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
 1461: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
 1462: <select name="timerange">
 1463: <option value='all' $allsel>$lt{'al'}</option>
 1464: <option value="-1" $startsel>$lt{'st'}</option>
 1465: <option value="2592000" $monthsel>$lt{'lm'}</option>
 1466: <option value="604800" $weeksel>$lt{'lw'}</option>
 1467: <option value="86400" $daysel>$lt{'sy'}</option>
 1468: </select>
 1469: <input type="submit" name="display" value="$lt{'sd'}" />
 1470: <h3>$header</h3>
 1471: <input type="submit" name="setversions" value="$lt{'sv'}" />
 1472: <table border="0">
 1473: ENDHEADERS
 1474:     foreach (sort keys %changes) {
 1475: 	if ($changes{$_}>$starttime) {
 1476: 	    my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
 1477: 	    my $currentversion=&Apache::lonnet::getversion($_);
 1478: 	    if ($currentversion<0) {
 1479: 		$currentversion=&mt('Could not be determined.');
 1480: 	    }
 1481: 	    my $linkurl=&Apache::lonnet::clutter($_);
 1482: 	    $r->print(
 1483: 		      '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
 1484: 		      &Apache::lonnet::gettitle($linkurl).
 1485:                       '</b></font></td></tr>'.
 1486:                       '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
 1487:                       '<td colspan="4">'.
 1488:                       '<a href="'.$linkurl.'" target="cat">'.$linkurl.
 1489: 		      '</a></td></tr>'.
 1490:                       '<tr><td></td>'.
 1491:                       '<td title="'.$lt{'md'}.'">'.
 1492: 		      &Apache::lonlocal::locallocaltime(
 1493:                            &Apache::lonnet::metadata($root.'.'.$extension,
 1494:                                                      'lastrevisiondate')
 1495:                                                         ).
 1496:                       '</td>'.
 1497:                       '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
 1498:                       '<font size="+1">'.$currentversion.'</font>'.
 1499:                       '</nobr></td>'.
 1500:                       '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
 1501:                       '<font size="+1">');
 1502: # Used in course
 1503: 	    my $usedversion=$hash{'version_'.$linkurl};
 1504: 	    if (($usedversion) && ($usedversion ne 'mostrecent')) {
 1505: 		$r->print($usedversion);
 1506: 	    } else {
 1507: 		$r->print($currentversion);
 1508: 	    }
 1509: 	    $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
 1510:                       '<nobr>Use: ');
 1511: # Set version
 1512: 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
 1513: 						      'set_version_'.$linkurl,
 1514: 						      ('select_form_order' =>
 1515: 						       ['',1..$currentversion,'mostrecent'],
 1516: 						       '' => '',
 1517: 						       'mostrecent' => 'most recent',
 1518: 						       map {$_,$_} (1..$currentversion))));
 1519: 	    $r->print('</nobr></td></tr><tr><td></td>');
 1520: 	    my $lastold=1;
 1521: 	    for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
 1522: 		my $url=$root.'.'.$prevvers.'.'.$extension;
 1523: 		if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
 1524: 		    $starttime) {
 1525: 		    $lastold=$prevvers;
 1526: 		}
 1527: 	    }
 1528:             # 
 1529:             # Code to figure out how many version entries should go in
 1530:             # each of the four columns
 1531:             my $entries_per_col = 0;
 1532:             my $num_entries = ($currentversion-$lastold);
 1533:             if ($num_entries % 4 == 0) {
 1534:                 $entries_per_col = $num_entries/4;
 1535:             } else {
 1536:                 $entries_per_col = $num_entries/4 + 1;
 1537:             }
 1538:             my $entries_count = 0;
 1539:             $r->print('<td valign="top"><font size="-2">'); 
 1540:             my $cols_output = 1;
 1541:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
 1542: 		my $url=$root.'.'.$prevvers.'.'.$extension;
 1543: 		$r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
 1544: 			  '">'.&mt('Version').' '.$prevvers.'</a> ('.
 1545: 			  &Apache::lonlocal::locallocaltime(
 1546:                                 &Apache::lonnet::metadata($url,
 1547:                                                           'lastrevisiondate')
 1548:                                                             ).
 1549: 			  ')');
 1550: 		if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
 1551:                     $r->print(' <a href="/adm/diff?filename='.
 1552: 			      &Apache::lonnet::clutter($root.'.'.$extension).
 1553: 			      '&versionone='.$prevvers.
 1554: 			      '">'.&mt('Diffs').'</a>');
 1555: 		}
 1556: 		$r->print('</nobr><br />');
 1557:                 if (++$entries_count % $entries_per_col == 0) {
 1558:                     $r->print('</font></td>');
 1559:                     if ($cols_output != 4) {
 1560:                         $r->print('<td valign="top"><font size="-2">');
 1561:                         $cols_output++;
 1562:                     }
 1563:                 }
 1564: 	    }
 1565:             while($cols_output++ < 4) {
 1566:                 $r->print('</font></td><td><font>')
 1567:             }
 1568: 	    $r->print('</font></td></tr>'."\n");
 1569: 	}
 1570:     }
 1571:     $r->print('</table></form>');
 1572:     $r->print('<h1>'.&mt('Done').'.</h1>');
 1573: 
 1574:     &untiehash();
 1575: }
 1576: 
 1577: sub mark_hash_old {
 1578:     my $retie_hash=0;
 1579:     if ($hashtied) {
 1580: 	$retie_hash=1;
 1581: 	&untiehash();
 1582:     }
 1583:     &tiehash('write');
 1584:     $hash{'old'}=1;
 1585:     &untiehash();
 1586:     if ($retie_hash) { &tiehash(); }
 1587: }
 1588: 
 1589: sub is_hash_old {
 1590:     my $untie_hash=0;
 1591:     if (!$hashtied) {
 1592: 	$untie_hash=1;
 1593: 	&tiehash();
 1594:     }
 1595:     my $return=$hash{'old'};
 1596:     if ($untie_hash) { &untiehash(); }
 1597:     return $return;
 1598: }
 1599: 
 1600: sub changewarning {
 1601:     my ($r,$postexec)=@_;
 1602:     if (!&is_hash_old()) { return; }
 1603:     $r->print(
 1604: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'. 
 1605: '<form method="post" action="/adm/roles" target="loncapaclient">'.
 1606: '<input type="hidden" name="orgurl" value="/adm/coursedocs?folderpath='.
 1607: &Apache::lonnet::escape($ENV{'form.folderpath'}).
 1608: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
 1609: &mt('Changes will become active for your current session after').
 1610: ' <input type="hidden" name="'.
 1611: $ENV{'request.role'}.'" value="1" /><input type="button" value="'.
 1612: &mt('re-initializing course').'" onClick="reinit(this.form)"/>'.&mt(', or the next time you log in.').
 1613: $help{'Caching'}.'</font></h3></form>');
 1614: }
 1615: 
 1616: # ================================================================ Main Handler
 1617: sub handler {
 1618:     my $r = shift;
 1619:     &Apache::loncommon::content_type($r,'text/html');
 1620:     $r->send_http_header;
 1621:     return OK if $r->header_only;
 1622: 
 1623: # --------------------------------------------- Initialize help topics for this
 1624:   foreach ('Adding_Course_Doc','Main_Course_Documents',
 1625:            'Adding_External_Resource','Navigate_Content',
 1626:            'Adding_Folders','Docs_Overview', 'Load_Map',
 1627:            'Supplemental','Score_Upload_Form','Adding_Pages',
 1628:            'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
 1629: 	   'Check_Resource_Versions','Verify_Content') {
 1630:       $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
 1631:   }
 1632:     # Composite help files
 1633:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
 1634: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
 1635:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
 1636: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
 1637:     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
 1638: 		    'Option_Response_Simple');
 1639:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
 1640: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
 1641:     $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
 1642: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
 1643:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
 1644: 
 1645:   if ($ENV{'form.verify'}) {
 1646:       &verifycontent($r);
 1647:   } elsif ($ENV{'form.versions'}) {
 1648:       &checkversions($r);
 1649:   } elsif ($ENV{'form.dumpcourse'}) {
 1650:       &dumpcourse($r);
 1651:   } elsif ($ENV{'form.exportcourse'}) {
 1652:       &exportcourse($r);
 1653:   } else {
 1654: # is this a standard course?
 1655: 
 1656:     my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
 1657:     my $forcestandard;
 1658:     my $forcesupplement;
 1659:     my $script='';
 1660:     my $allowed;
 1661:     my $events='';
 1662:     my $showdoc=0;
 1663:     my $containertag;
 1664:     my $uploadtag;
 1665:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 1666: 					    ['folderpath','pagepath']);
 1667:     if ($ENV{'form.folderpath'}) {
 1668: 	my (@folderpath)=split('&',$ENV{'form.folderpath'});
 1669: 	$ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
 1670: 	$ENV{'form.folder'}=pop(@folderpath);
 1671:     }
 1672:     if ($ENV{'form.pagepath'}) {
 1673:         my (@pagepath)=split('&',$ENV{'form.pagepath'});
 1674:         $ENV{'form.pagename'}=&Apache::lonnet::unescape(pop(@pagepath));
 1675:         $ENV{'form.folder'}=pop(@pagepath);
 1676:         $containertag = '<input type="hidden" name="pagepath" value="" />';
 1677:         $uploadtag = '<input type="hidden" name="pagepath" value="'.$ENV{'form.pagepath'}.'" />';
 1678:     }
 1679:     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
 1680:        $showdoc='/'.$1;
 1681:     }
 1682:     unless ($showdoc) { # got called from remote
 1683:        $forcestandard=($ENV{'form.folder'}=~/^default_/);
 1684:        $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
 1685: 
 1686: # does this user have privileges to post, etc?
 1687:        $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
 1688:        if ($allowed) { 
 1689:          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
 1690:          $script=&Apache::lonratedt::editscript('simple'); 
 1691:        }
 1692:     } else { # got called in sequence from course
 1693:        $allowed=0;
 1694:        $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
 1695:        $events='onLoad="'.&Apache::lonmenu::loadevents.
 1696:            '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
 1697:     }
 1698: 
 1699: # get course data
 1700:     my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
 1701:     my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
 1702: 
 1703: # get personal data
 1704:  
 1705:     my $uname=$ENV{'user.name'};
 1706:     my $udom=$ENV{'user.domain'};
 1707:     my $plainname=&Apache::lonnet::escape(
 1708:                      &Apache::loncommon::plainname($uname,$udom));
 1709: 
 1710: # graphics settings
 1711: 
 1712:     $iconpath = $r->dir_config('lonIconsURL') . "/";
 1713: 
 1714:     my $now=time;
 1715: 
 1716: # print screen
 1717:     $r->print(<<ENDDOCUMENT);
 1718: <html>
 1719: <head>
 1720: <title>The LearningOnline Network with CAPA</title>
 1721: <script>
 1722: $script
 1723: </script>
 1724: ENDDOCUMENT
 1725:    if ($allowed) {
 1726:     $r->print(<<ENDNEWSCRIPT);
 1727: <script>
 1728: function makenewfolder(targetform,folderseq) {
 1729:     var foldername=prompt('Name of New Folder','New Folder');
 1730:     if (foldername) {
 1731: 	targetform.importdetail.value=foldername+"="+folderseq;
 1732:         targetform.submit();
 1733:     }
 1734: }
 1735: 
 1736: function makenewpage(targetform,folderseq) {
 1737:     var pagename=prompt('Name of New Page','New Page');
 1738:     if (pagename) {
 1739:         targetform.importdetail.value=pagename+"="+folderseq;
 1740:         targetform.submit();
 1741:     }
 1742: }
 1743: 
 1744: function makenewext(targetname) {
 1745:     this.document.forms.extimport.useform.value=targetname;
 1746:     window.open('/adm/rat/extpickframe.html');
 1747: }
 1748: 
 1749: function makeexamupload() {
 1750:    var title=prompt('Listed Title for the Uploaded Score');
 1751:    if (title) { 
 1752:     this.document.forms.newexamupload.importdetail.value=
 1753: 	title+'=/res/lib/templates/examupload.problem';
 1754:     this.document.forms.newexamupload.submit();
 1755:    }
 1756: }
 1757: 
 1758: function makesmppage() {
 1759:    var title=prompt('Listed Title for the Page');
 1760:    if (title) { 
 1761:     this.document.forms.newsmppg.importdetail.value=
 1762: 	title+'=/adm/$udom/$uname/$now/smppg';
 1763:     this.document.forms.newsmppg.submit();
 1764:    }
 1765: }
 1766: 
 1767: function makesmpproblem() {
 1768:    var title=prompt('Listed Title for the Problem');
 1769:    if (title) { 
 1770:     this.document.forms.newsmpproblem.importdetail.value=
 1771: 	title+'=/res/lib/templates/simpleproblem.problem';
 1772:     this.document.forms.newsmpproblem.submit();
 1773:    }
 1774: }
 1775: 
 1776: function makebulboard() {
 1777:    var title=prompt('Listed Title for the Bulletin Board');
 1778:    if (title) {
 1779:     this.document.forms.newbul.importdetail.value=
 1780: 	title+'=/adm/$udom/$uname/$now/bulletinboard';
 1781:     this.document.forms.newbul.submit();
 1782:    }
 1783: }
 1784: 
 1785: function makeabout() {
 1786:    var user=prompt("Enter user\@domain for User's 'About Me' Page");
 1787:    if (user) {
 1788:        var comp=new Array();
 1789:        comp=user.split('\@');
 1790:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
 1791: 	   if ((comp[0]) && (comp[1])) {
 1792: 	       this.document.forms.newaboutsomeone.importdetail.value=
 1793: 		   'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
 1794: 	       this.document.forms.newaboutsomeone.submit();
 1795: 	   }
 1796:        }
 1797:    }
 1798: }
 1799: 
 1800: function makeims() {
 1801:     var caller = document.forms.ims.folder.value
 1802:     var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
 1803:     newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
 1804:     newWindow.location.href = newlocation
 1805: }
 1806: 
 1807: 
 1808: function finishpick() {
 1809:     var title=this.document.forms.extimport.title.value;
 1810:     var url=this.document.forms.extimport.url.value;
 1811:     var form=this.document.forms.extimport.useform.value;
 1812:     eval
 1813:      ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
 1814:     '";this.document.forms.'+form+'.submit();');
 1815: }
 1816: 
 1817: function changename(folderpath,index,oldtitle,container) {
 1818:     var title=prompt('New Title',oldtitle);
 1819:     if (title) {
 1820: 	this.document.forms.renameform.title.value=title;
 1821: 	this.document.forms.renameform.cmd.value='rename_'+index;
 1822:         if (container == 'sequence') {
 1823: 	    this.document.forms.renameform.folderpath.value=folderpath;
 1824:         }
 1825:         if (container == 'page') {
 1826:             this.document.forms.renameform.pagepath.value=folderpath;
 1827:         }
 1828:         this.document.forms.renameform.submit();
 1829:     }
 1830: }
 1831: 
 1832: function removeres(folderpath,index,oldtitle,container) {
 1833:     if (confirm('Remove "'+oldtitle+'"?')) {
 1834: 	this.document.forms.renameform.cmd.value='del_'+index;
 1835:         if (container == 'sequence') {
 1836:             this.document.forms.renameform.folderpath.value=folderpath;
 1837:         }
 1838:         if (container == 'page') {
 1839:             this.document.forms.renameform.pagepath.value=folderpath;
 1840:         }
 1841:         this.document.forms.renameform.submit();
 1842:     }
 1843: }
 1844: 
 1845: </script>
 1846: 
 1847: ENDNEWSCRIPT
 1848:   }
 1849: # -------------------------------------------------------------------- Body tag
 1850:   $r->print('</head>'.
 1851:             &Apache::loncommon::bodytag('Course Documents','',$events,
 1852: 					'','',$showdoc).
 1853: 	    &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
 1854:   unless ($showdoc) {
 1855: # -----------------------------------------------------------------------------
 1856:        my %lt=&Apache::lonlocal::texthash(
 1857:                 'uplm' => 'Upload a new main course document',
 1858:                 'upls' => 'Upload a new supplemental course document',
 1859:                 'impp' => 'Import a published document',
 1860:                 'spec' => 'Special documents',
 1861:                 'upld' => 'Upload Document',
 1862:                 'srch' => 'Search',
 1863:                 'impo' => 'Import',
 1864:                 'selm' => 'Select Map',
 1865:                 'load' => 'Load Map',
 1866:                 'newf' => 'New Folder',
 1867:                 'newp' => 'New Composite Page',
 1868:                 'extr' => 'External Resource',
 1869:                 'syll' => 'Syllabus',
 1870:                 'navc' => 'Navigate Contents',
 1871:                 'sipa' => 'Simple Page',
 1872:                 'sipr' => 'Simple Problem',
 1873:                 'scuf' => 'Score Upload Form',
 1874:                 'bull' => 'Bulletin Board',
 1875:                 'mypi' => 'My Personal Info',
 1876: 		'abou' => 'About User',
 1877:                 'imsf' => 'Import IMS package',
 1878:                 'file' =>  'File',
 1879:                 'title' => 'Title',
 1880:                 'comment' => 'Comment' 
 1881: 					  );
 1882: # -----------------------------------------------------------------------------
 1883:     if ($allowed) {
 1884:        my $dumpbut=&dumpbutton();
 1885:        my $exportbut=&exportbutton();
 1886:        my %lt=&Apache::lonlocal::texthash(
 1887: 					 'vc' => 'Verify Content',
 1888: 					 'cv' => 'Check/Set Resource Versions',
 1889: 					  );
 1890: 
 1891:        my $folderpath=$ENV{'form.folderpath'};
 1892:        if (!$folderpath) {
 1893: 	   if ($ENV{'form.folder'} eq '' ||
 1894: 	       $ENV{'form.folder'} eq 'supplemental') {
 1895: 	       $folderpath='default&'.
 1896: 		   &Apache::lonnet::escape(&mt('Main Course Documents'));
 1897: 	   }
 1898:        }
 1899:        unless ($ENV{'form.pagepath'}) {
 1900:            $containertag = '<input type="hidden" name="folderpath" value="" />';
 1901:            $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
 1902:        }
 1903: 
 1904:        $r->print(<<ENDCOURSEVERIFY);
 1905: <form name="renameform" method="post" action="/adm/coursedocs">
 1906: <input type="hidden" name="title" />
 1907: <input type="hidden" name="cmd" />
 1908: $containertag
 1909: </form>
 1910: <form name="simpleedit" method="post" action="/adm/coursedocs">
 1911: <input type=hidden name="importdetail" value="">
 1912: $uploadtag
 1913: </form>
 1914: <form action="/adm/coursedocs" method="post" name="courseverify">
 1915: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
 1916: <tr><td bgcolor="#DDDDCC">
 1917: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
 1918: </td><td bgcolor="#DDDDCC">
 1919:     <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
 1920: $dumpbut
 1921: $exportbut
 1922: </td></tr></table>
 1923: </form>
 1924: ENDCOURSEVERIFY
 1925:        $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
 1926: 		     &mt('Editing the Table of Contents for your Course')));
 1927:     }
 1928: # --------------------------------------------------------- Standard documents
 1929:     $r->print('<table border=2 cellspacing=4 cellpadding=4>');
 1930:     if (($standard) && ($allowed) && (!$forcesupplement)) {
 1931: 	$r->print('<tr><td bgcolor="#BBBBBB">');
 1932: #  '<h2>'.&mt('Main Course Documents').
 1933: #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
 1934:        my $folder=$ENV{'form.folder'};
 1935:        if ($folder eq '' || $folder eq 'supplemental') {
 1936:            $folder='default';
 1937: 	   $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
 1938:        }
 1939:        my $postexec='';
 1940:        if ($folder eq 'default') {
 1941: 	   $r->print('<script>this.window.name="loncapaclient";</script>');
 1942:        } else {
 1943:            #$postexec='self.close();';
 1944:        }
 1945:        $hadchanges=0;
 1946:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
 1947:        if ($hadchanges) {
 1948: 	   &mark_hash_old()
 1949:        }
 1950:        &changewarning($r,$postexec);
 1951:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 1952:                      '.sequence';
 1953:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 1954:                      '.page';
 1955: 
 1956:        $r->print(<<ENDFORM);
 1957: <table cellspacing=4 cellpadding=4><tr>
 1958: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
 1959: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
 1960: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
 1961: </tr>
 1962: <tr><td bgcolor="#DDDDDD">
 1963: $lt{'file'}:<br />
 1964: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
 1965: <input type="file" name="uploaddoc" size="40">
 1966: <br />
 1967: $lt{'title'}:<br />
 1968: <input type="text" size="50" name="comment">
 1969: $uploadtag
 1970: <input type="hidden" name="cmd" value="upload_default">
 1971: <nobr>
 1972: <input type="submit" value="$lt{'upld'}">
 1973:  $help{'Uploading_From_Harddrive'}
 1974: </nobr>
 1975: </form>
 1976: </td>
 1977: <td bgcolor="#DDDDDD">
 1978: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
 1979: $uploadtag
 1980: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
 1981: <nobr>
 1982: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
 1983: $help{'Importing_LON-CAPA_Resource'}
 1984: </nobr>
 1985: <p>
 1986: <hr />
 1987: <input type="text" size="20" name="importmap"><br />
 1988: <nobr><input type=button 
 1989: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
 1990: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
 1991: $help{'Load_Map'}</nobr>
 1992: </p>
 1993: </form>
 1994: </td>
 1995: <td bgcolor="#DDDDDD">
 1996: ENDFORM
 1997:        unless ($ENV{'form.pagepath'}) {
 1998:            $r->print(<<ENDFORM);
 1999: <form action="/adm/coursedocs" method="post" name="newfolder">
 2000: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 2001: <input type=hidden name="importdetail" value="">
 2002: <nobr>
 2003: <input name="newfolder" type="button"
 2004: onClick="javascript:makenewfolder(this.form,'$folderseq');"
 2005: value="$lt{'newf'}" />$help{'Adding_Folders'}
 2006: </nobr>
 2007: </form>
 2008: <form action="/adm/coursedocs" method="post" name="newpage">
 2009: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 2010: <input type=hidden name="importdetail" value="">
 2011: <nobr>
 2012: <input name="newpage" type="button"
 2013: onClick="javascript:makenewpage(this.form,'$pageseq');"
 2014: value="$lt{'newp'}" />$help{'Adding_Pages'}
 2015: </nobr>
 2016: </form>
 2017: <form action="/adm/coursedocs" method="post" name="newext">
 2018: $uploadtag
 2019: <input type=hidden name="importdetail" value="">
 2020: <nobr>
 2021: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
 2022: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
 2023: </nobr>
 2024: </form>
 2025: <form action="/adm/coursedocs" method="post" name="newsyl">
 2026: $uploadtag
 2027: <input type=hidden name="importdetail" 
 2028: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
 2029: <nobr>
 2030: <input name="newsyl" type="submit" value="$lt{'syll'}" /> 
 2031:  $help{'Syllabus'}
 2032: </nobr>
 2033: </form>
 2034: <form action="/adm/coursedocs" method="post" name="newnav">
 2035: $uploadtag
 2036: <input type=hidden name="importdetail" 
 2037: value="Navigate Content=/adm/navmaps">
 2038: <nobr>
 2039: <input name="newnav" type="submit" value="$lt{'navc'}" />
 2040: $help{'Navigate_Content'}
 2041: </nobr>
 2042: </form>
 2043: <form action="/adm/coursedocs" method="post" name="newsmppg">
 2044: $uploadtag
 2045: <input type=hidden name="importdetail" value="">
 2046: <nobr>
 2047: <input name="newsmppg" type="button" value="$lt{'sipa'}"
 2048: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
 2049: </nobr>
 2050: </form>
 2051: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
 2052: $uploadtag
 2053: <input type=hidden name="importdetail" value="">
 2054: <nobr>
 2055: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
 2056: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
 2057: </nobr>
 2058: </form>
 2059: <form action="/adm/coursedocs" method="post" name="newexamupload">
 2060: $uploadtag
 2061: <input type=hidden name="importdetail" value="">
 2062: <nobr>
 2063: <input name="newexamupload" type="button" value="$lt{'scuf'}"
 2064: onClick="javascript:makeexamupload();" />
 2065: $help{'Score_Upload_Form'}
 2066: </nobr>
 2067: </form>
 2068: <form action="/adm/coursedocs" method="post" name="newbul">
 2069: $uploadtag
 2070: <input type=hidden name="importdetail" value="">
 2071: <nobr>
 2072: <input name="newbulletin" type="button" value="$lt{'bull'}"
 2073: onClick="javascript:makebulboard();" />
 2074: $help{'Bulletin Board'}
 2075: </nobr>
 2076: </form>
 2077: <form action="/adm/coursedocs" method="post" name="newaboutme">
 2078: $uploadtag
 2079: <input type=hidden name="importdetail" 
 2080: value="$plainname=/adm/$udom/$uname/aboutme">
 2081: <nobr>
 2082: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
 2083: $help{'My Personal Info'}
 2084: </nobr>
 2085: </form>
 2086: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
 2087: $uploadtag
 2088: <input type=hidden name="importdetail" value="">
 2089: <nobr>
 2090: <input name="newaboutsomeone" type="button" value="$lt{'abou'}" 
 2091: onClick="javascript:makeabout();" />
 2092: </nobr>
 2093: ENDFORM
 2094:        }
 2095:        if ($ENV{'form.pagepath'}) {
 2096:            $r->print(<<ENDBLOCK);
 2097: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
 2098: $uploadtag
 2099: <input type=hidden name="importdetail" value="">
 2100: <nobr>
 2101: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
 2102: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
 2103: </nobr>
 2104: </form>
 2105: <form action="/adm/coursedocs" method="post" name="newexamupload">
 2106: $uploadtag
 2107: <input type=hidden name="importdetail" value="">
 2108: <nobr>
 2109: <input name="newexamupload" type="button" value="$lt{'scuf'}"
 2110: onClick="javascript:makeexamupload();" />
 2111: $help{'Score_Upload_Form'}
 2112: </nobr>
 2113: </form>
 2114: ENDBLOCK
 2115:        } else {
 2116:            $r->print(<<ENDFORM);
 2117: </form>
 2118: <form action="/adm/imsimportdocs" method="post" name="ims">
 2119: <input type="hidden" name="folder" value="$folder" />
 2120: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
 2121: </nobr>
 2122: </form>
 2123: ENDFORM
 2124:        }
 2125:        $r->print('</td></tr>'."\n".
 2126: '</table>');
 2127:        $r->print('</td></tr>');
 2128:     }
 2129: # ----------------------------------------------------- Supplemental documents
 2130:     if (!$forcestandard) {
 2131:        $r->print('<tr><td bgcolor="#BBBBBB">');
 2132: # '<h2>'.&mt('Supplemental Course Documents').
 2133: #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
 2134:        my $folder=$ENV{'form.folder'};
 2135:        unless ($folder=~/^supplemental/) {
 2136: 	   $folder='supplemental';
 2137:        }
 2138:        if ($folder =~ /^supplemental$/ &&
 2139: 	   $ENV{'form.folderpath'} =~ /^default\&/) {
 2140: 	   $ENV{'form.folderpath'}='supplemental&'.
 2141: 	       &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
 2142:        }
 2143:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
 2144:        if ($allowed) {
 2145:        my $folderseq=
 2146:                   '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
 2147:                      '.sequence';
 2148: 
 2149:           $r->print(<<ENDSUPFORM);
 2150: <table cellspacing=4 cellpadding=4><tr>
 2151: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
 2152: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
 2153: </tr>
 2154: <tr><td bgcolor="#DDDDDD">
 2155: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
 2156: <input type="file" name="uploaddoc" size="40">
 2157: <br />$lt{'comment'}:<br />
 2158: <textarea cols=50 rows=4 name='comment'>
 2159: </textarea>
 2160: <br />
 2161: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 2162: <input type="hidden" name="cmd" value="upload_supplemental">
 2163: <nobr>
 2164: <input type="submit" value="$lt{'upld'}">
 2165:  $help{'Uploading_From_Harddrive'}
 2166: </nobr>
 2167: </form>
 2168: </td>
 2169: <td bgcolor="#DDDDDD">
 2170: <form action="/adm/coursedocs" method="post" name="supnewfolder">
 2171: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 2172: <input type=hidden name="importdetail" value="">
 2173: <nobr>
 2174: <input name="newfolder" type="button"
 2175: onClick="javascript:makenewfolder(this.form,'$folderseq');"
 2176: value="$lt{'newf'}" /> $help{'Adding_Folders'}
 2177: </nobr>
 2178: </form>
 2179: <form action="/adm/coursedocs" method="post" name="supnewext">
 2180: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 2181: <input type=hidden name="importdetail" value="">
 2182: <nobr>
 2183: <input name="newext" type="button" 
 2184: onClick="javascript:makenewext('supnewext');"
 2185: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
 2186: </nobr>
 2187: </form>
 2188: <form action="/adm/coursedocs" method="post" name="supnewsyl">
 2189: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 2190: <input type=hidden name="importdetail" 
 2191: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
 2192: <nobr>
 2193: <input name="newsyl" type="submit" value="$lt{'syll'}" />
 2194: $help{'Syllabus'}
 2195: </nobr>
 2196: </form>
 2197: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
 2198: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 2199: <input type=hidden name="importdetail" 
 2200: value="$plainname=/adm/$udom/$uname/aboutme">
 2201: <nobr>
 2202: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
 2203: $help{'My Personal Info'}
 2204: </nobr>
 2205: </form>
 2206: </td></tr>
 2207: </table></td></tr>
 2208: ENDSUPFORM
 2209:        }
 2210:     }
 2211:     if ($allowed) {
 2212: 	$r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
 2213:     }
 2214:     $r->print('</table>');
 2215:   } else {
 2216: # -------------------------------------------------------- This is showdoc mode
 2217:       $r->print("<h1>".&mt('Uploaded Document').' - '.
 2218: 		&Apache::lonnet::gettitle($r->uri).'</h1><p>'.
 2219: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
 2220:          &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
 2221:   }
 2222:  }
 2223:  $r->print('</body></html>');
 2224:  return OK;
 2225: } 
 2226: 
 2227: 1;
 2228: __END__

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