File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.173: download - view: text, annotated - select for diffs
Mon Apr 4 23:51:54 2005 UTC (19 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
-likely should specifiy a target when doing an ssi, as it was by default wpicking grade, then web which meant it thatought there where 00 rather that 0 warnings.
- inhibit the ok if nothing is wrong, it just looks odd where it is

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

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