File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.234: download - view: text, annotated - select for diffs
Fri Jun 30 00:47:14 2006 UTC (17 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- remove unsightly pixels from location bars in DOCS BUG#4866

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

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