File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.232: download - view: text, annotated - select for diffs
Mon Jun 19 09:40:17 2006 UTC (17 years, 11 months ago) by www
Branches: MAIN
CVS tags: HEAD
* don't forget selected items when switching from Search to Import
* Bug #2674, Bug #563: import from bookmarks
* Bug #3154: visually separate Search and Import in DOCS

    1: # The LearningOnline Network
    2: # Documents
    3: #
    4: # $Id: londocs.pm,v 1.232 2006/06/19 09:40:17 www 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: }
  980: 
  981: sub editor {
  982:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output)=@_;
  983:     my $errtext='';
  984:     my $fatal=0;
  985:     my $container='sequence';
  986:     if ($env{'form.pagepath'}) {
  987:         $container='page';
  988:     }
  989:     ($errtext,$fatal)=
  990:               &mapread($coursenum,$coursedom,$folder.'.'.$container);
  991:     if ($#Apache::lonratedt::order<1) {
  992: 	my $idx=&Apache::lonratedt::getresidx();
  993: 	if ($idx<=0) { $idx=1; }
  994:        	$Apache::lonratedt::order[0]=$idx;
  995:         $Apache::lonratedt::resources[$idx]='';
  996:     }
  997:     if (defined($env{'form.markcopy'})) {
  998: # Mark for copying
  999: 	my ($title,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$env{'form.markcopy'}]]);
 1000: 	$env{'form.markedcopy_title'}=$title;
 1001: 	$env{'form.markedcopy_url'}=$url;
 1002:     }
 1003:     $r->print(&breadcrumbs($folder));
 1004:     if ($fatal) {
 1005: 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
 1006:     } else {
 1007: # ------------------------------------------------------------ Process commands
 1008: 
 1009: # ---------------- if they are for this folder and user allowed to make changes
 1010: 	if (($allowed) && ($env{'form.folder'} eq $folder)) {
 1011: # set parameters and change order
 1012: 	    if (defined($env{'form.setparms'})) {
 1013: 		my $idx=$env{'form.setparms'};
 1014: # set parameters
 1015: 		if ($env{'form.randpick_'.$idx}) {
 1016: 		    &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos');
 1017: 		} else {
 1018: 		    &Apache::lonratedt::delparameter($idx,'parameter_randompick');
 1019: 		}
 1020: 		if ($env{'form.hidprs_'.$idx}) {
 1021: 		    &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
 1022: 		} else {
 1023: 		    &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
 1024: 		}
 1025: 		if ($env{'form.encprs_'.$idx}) {
 1026: 		    &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
 1027: 		} else {
 1028: 		    &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
 1029: 		}
 1030: 
 1031: 		if ($env{'form.newpos'}) {
 1032: # change order
 1033: 
 1034: 		    my $newpos=$env{'form.newpos'}-1;
 1035: 		    my $currentpos=$env{'form.currentpos'}-1;
 1036: 		    my $i;
 1037: 		    my @neworder=();
 1038: 		    if ($newpos>$currentpos) {
 1039: # moving stuff up
 1040: 			for ($i=0;$i<$currentpos;$i++) {
 1041: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
 1042: 			}
 1043: 			for ($i=$currentpos;$i<$newpos;$i++) {
 1044: 			    $neworder[$i]=$Apache::lonratedt::order[$i+1];
 1045: 			}
 1046:                         $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
 1047: 			for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
 1048: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
 1049: 			}
 1050: 		    } else {
 1051: # moving stuff down
 1052: 			for ($i=0;$i<$newpos;$i++) {
 1053: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
 1054: 			}
 1055: 			$neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
 1056: 			for ($i=$newpos+1;$i<$currentpos+1;$i++) {
 1057: 			    $neworder[$i]=$Apache::lonratedt::order[$i-1];
 1058: 			}
 1059: 			for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
 1060: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
 1061: 			}
 1062: 		    }
 1063: 		    @Apache::lonratedt::order=@neworder;
 1064: 		}
 1065: # store the changed version
 1066: 
 1067: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
 1068: 		if ($fatal) {
 1069: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
 1070: 		    return;
 1071: 		}
 1072: 		
 1073: 	    }
 1074: 	    if ($env{'form.pastemarked'}) {
 1075: # paste resource to end of list
 1076:                 my $url=$env{'form.markedcopy_url'};
 1077: 		my $title=$env{'form.markedcopy_title'};
 1078: # Maps need to be copied first
 1079: 		if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) {
 1080: 		    $title=&mt('Copy of').' '.$title;
 1081:                     my $newid=$$.time;
 1082: 		    $url=~/^(.+)\.(\w+)$/;
 1083: 		    my $newurl=$1.$newid.'.'.$2;
 1084: 		    my $storefn=$newurl;
 1085:                     $storefn=~s/^\/\w+\/\w+\/\w+\///;
 1086: 		    &Apache::loncreatecourse::writefile
 1087: 			($env{'request.course.id'},$storefn,
 1088: 			 &Apache::lonnet::getfile($url));
 1089: 		    $url=$newurl;
 1090: 		}
 1091: 		$title=~s/\</\&lt\;/g;
 1092: 		$title=~s/\>/\&gt\;/g;
 1093: 		$title=~s/\:/\&colon;/g;
 1094: 		my $ext='false';
 1095: 		if ($url=~/^http\:\/\//) { $ext='true'; }
 1096: 		$url=~s/\:/\&colon;/g;
 1097: # Now insert the URL at the bottom
 1098:                 my $newidx=&Apache::lonratedt::getresidx($url);
 1099: 		$Apache::lonratedt::resources[$newidx]=
 1100: 		    $title.':'.$url.':'.$ext.':normal:res';
 1101: 		$Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
 1102: # Store the result
 1103: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
 1104: 		if ($fatal) {
 1105: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
 1106: 		    return;
 1107: 		}
 1108: 
 1109: 	    }
 1110:             $r->print($upload_output);
 1111: 	    if ($env{'form.cmd'}) {
 1112:                 my ($cmd,$idx)=split(/\_/,$env{'form.cmd'});
 1113:                 if ($cmd eq 'del') {
 1114: 		    my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
 1115: 		    if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
 1116: 			($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
 1117: 			&Apache::lonnet::removeuploadedurl($url);
 1118: 		    } else {
 1119: 			&Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]);
 1120: 		    }
 1121: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
 1122:                         $Apache::lonratedt::order[$i]=
 1123:                           $Apache::lonratedt::order[$i+1];
 1124:                     }
 1125:                     $#Apache::lonratedt::order--;
 1126:                 } elsif ($cmd eq 'cut') {
 1127: 		    my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
 1128: 		    &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]);
 1129: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
 1130:                         $Apache::lonratedt::order[$i]=
 1131:                           $Apache::lonratedt::order[$i+1];
 1132:                     }
 1133:                     $#Apache::lonratedt::order--;
 1134:                 } elsif ($cmd eq 'up') {
 1135: 		  if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
 1136:                     my $i=$Apache::lonratedt::order[$idx-1];
 1137:                     $Apache::lonratedt::order[$idx-1]=
 1138: 			$Apache::lonratedt::order[$idx];
 1139:                     $Apache::lonratedt::order[$idx]=$i;
 1140: 		   }
 1141:                 } elsif ($cmd eq 'down') {
 1142: 		   if (defined($Apache::lonratedt::order[$idx+1])) {
 1143:                     my $i=$Apache::lonratedt::order[$idx+1];
 1144:                     $Apache::lonratedt::order[$idx+1]=
 1145: 			$Apache::lonratedt::order[$idx];
 1146:                     $Apache::lonratedt::order[$idx]=$i;
 1147: 		   }
 1148:                 } elsif ($cmd eq 'rename') {
 1149:                     my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]];
 1150:                     my ($rtitle,@rrest)=split(/\:/,
 1151:                        $Apache::lonratedt::resources[
 1152: 				       $Apache::lonratedt::order[$idx]]);
 1153:                     my $comment=
 1154:                      &HTML::Entities::decode($env{'form.title'});
 1155:                     $comment=~s/\</\&lt\;/g;
 1156:                     $comment=~s/\>/\&gt\;/g;
 1157:                     $comment=~s/\:/\&colon;/g;
 1158: 		    if ($comment=~/\S/) {
 1159: 			$Apache::lonratedt::resources[
 1160: 				       $Apache::lonratedt::order[$idx]]=
 1161: 				            $comment.':'.join(':',@rrest);
 1162: 		    }
 1163:                 }
 1164: # Store the changed version
 1165: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
 1166: 					    $folder.'.'.$container);
 1167: 		if ($fatal) {
 1168: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
 1169: 		    return;
 1170: 		}
 1171:             }
 1172: # Group import/search
 1173: 	    if ($env{'form.importdetail'}) {
 1174: 		my @imports;
 1175: 		foreach (split(/\&/,$env{'form.importdetail'})) {
 1176: 		    if (defined($_)) {
 1177: 			my ($name,$url)=split(/\=/,$_);
 1178: 			$name=&unescape($name);
 1179: 			$url=&unescape($url);
 1180: 			push @imports, $name, $url;
 1181: 		    }
 1182: 		}
 1183: # Store the changed version
 1184: 		($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
 1185: 					       $container,'londocs',@imports);
 1186: 		if ($fatal) {
 1187: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
 1188: 		    return;
 1189: 		}
 1190:             }
 1191: # Loading a complete map
 1192: 	   if ($env{'form.loadmap'}) {
 1193:                if ($env{'form.importmap'}=~/\w/) {
 1194: 	          foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
 1195: 		      my ($title,$url,$ext,$type)=split(/\:/,$_);
 1196:                       my $idx=&Apache::lonratedt::getresidx($url);
 1197:                       $Apache::lonratedt::resources[$idx]=$_;
 1198:                       $Apache::lonratedt::order
 1199: 		          [$#Apache::lonratedt::order+1]=$idx;
 1200: 	          }
 1201: # Store the changed version
 1202:   	          ($errtext,$fatal)=&storemap($coursenum,$coursedom,
 1203: 					   $folder.'.'.$container);
 1204: 	          if ($fatal) {
 1205: 		      $r->print('<p><font color="red">'.$errtext.'</font></p>');
 1206: 		      return;
 1207: 	          }
 1208:                } else {
 1209:                    $r->print('<p><font color="red">'.&mt('No map selected.').'</font></p>');
 1210:                }
 1211:            }
 1212:        }
 1213: # ---------------------------------------------------------------- End commands
 1214: # ---------------------------------------------------------------- Print screen
 1215:         my $idx=0;
 1216: 	my $shown=0;
 1217:         $r->print('<table>');
 1218:         foreach (@Apache::lonratedt::order) {
 1219:            my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
 1220: 	   $name=&Apache::lonratsrv::qtescape($name);
 1221: 	   $url=&Apache::lonratsrv::qtescape($url);
 1222:            unless ($name) {  $name=(split(/\//,$url))[-1]; }
 1223:            unless ($name) { $idx++; next; }
 1224:            $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
 1225:            $idx++;
 1226: 	   $shown++;
 1227:         }
 1228: 	unless ($shown) {
 1229: 	    $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
 1230: 	}
 1231:         $r->print("\n</table>\n");
 1232: 	if ($env{'form.markedcopy_url'}) {
 1233: 	    $r->print(<<ENDPASTE);
 1234: <p><form name="pasteform" action="/adm/coursedocs" method="post">
 1235: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
 1236: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
 1237: ENDPASTE
 1238:             $r->print(
 1239: 	   '<input type="submit" name="pastemarked" value="'.&mt('Paste').
 1240: 		      '" /> '.&Apache::loncommon::filedescription(
 1241: 		(split(/\./,$env{'form.markedcopy_url'}))[-1]).': '.
 1242: 		      $env{'form.markedcopy_title'});
 1243:             if ($container eq 'page') {
 1244: 		$r->print(<<PAGEINFO);
 1245: <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />
 1246: <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />
 1247: PAGEINFO
 1248:             } else {
 1249: 		$r->print(<<FOLDERINFO);
 1250: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
 1251: FOLDERINFO
 1252: 	    }
 1253: 	    $r->print('</form></p>');
 1254: 	}
 1255:     }
 1256: }
 1257: 
 1258: sub process_file_upload {
 1259:     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
 1260: # upload a file, if present
 1261:     my $parseaction;
 1262:    if ($env{'form.parserflag'}) {
 1263:         $parseaction = 'parse';
 1264:     }
 1265:     my $phase_status;
 1266:     my $folder=$env{'form.folder'};
 1267:     if ($folder eq '') {
 1268:         $folder='default';
 1269:     }
 1270:     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
 1271:         my $errtext='';
 1272:         my $fatal=0;
 1273:         my $container='sequence';
 1274:         if ($env{'form.pagepath'}) {
 1275:             $container='page';
 1276:         }
 1277:         ($errtext,$fatal)=
 1278:               &mapread($coursenum,$coursedom,$folder.'.'.$container);
 1279:         if ($#Apache::lonratedt::order<1) {
 1280:             $Apache::lonratedt::order[0]=1;
 1281:             $Apache::lonratedt::resources[1]='';
 1282:         }
 1283:         if ($fatal) {
 1284:             return 'failed';
 1285:         }
 1286:         my $destination = 'docs/';
 1287:         if ($folder =~ /^supplemental/) {
 1288:             $destination = 'supplemental/';
 1289:         }
 1290:         if (($folder eq 'default') || ($folder eq 'supplemental')) {
 1291:             $destination .= 'default/';
 1292:         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
 1293:             $destination .=  $2.'/';
 1294:         }
 1295: # this is for a course, not a user, so set coursedoc flag
 1296: # probably the only place in the system where this should be "1"
 1297:         my $newidx=&Apache::lonratedt::getresidx();
 1298:         $destination .= $newidx;
 1299:         my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
 1300: 						$parseaction,$allfiles,
 1301: 						$codebase);
 1302:         my $ext='false';
 1303:         if ($url=~/^http\:\/\//) { $ext='true'; }
 1304:         $url=~s/\:/\&colon;/g;
 1305:         my $comment=$env{'form.comment'};
 1306:         $comment=~s/\</\&lt\;/g;
 1307:         $comment=~s/\>/\&gt\;/g;
 1308:         $comment=~s/\:/\&colon;/g;
 1309:         if ($folder=~/^supplemental/) {
 1310:               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
 1311:                   $env{'user.domain'}.'___&&&___'.$comment;
 1312:         }
 1313: 
 1314:         $Apache::lonratedt::resources[$newidx]=
 1315:                   $comment.':'.$url.':'.$ext.':normal:res';
 1316:         $Apache::lonratedt::order[$#Apache::lonratedt::order+1]= $newidx;
 1317:         ($errtext,$fatal)=&storemap($coursenum,$coursedom,
 1318: 				    $folder.'.'.$container);
 1319:         if ($fatal) {
 1320:             $$upload_output .= '<p><font color="red">'.$errtext.'</font></p>';
 1321:             return 'failed';
 1322:         } else {
 1323:             if ($parseaction eq 'parse') {
 1324:                 my $total_embedded = keys(%{$allfiles});
 1325:                 if ($total_embedded > 0) {
 1326:                     my $num = 0;
 1327:                     $$upload_output .= 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />
 1328:    <form name="upload_embedded" action="/adm/coursedocs"
 1329:                   method="post" enctype="multipart/form-data">
 1330:    <input type="hidden" name="folderpath" value="'.$env{'form.folderpath'}.'" />   <input type="hidden" name="cmd" value="upload_embedded" />
 1331:    <input type="hidden" name="newidx" value="'.$newidx.'" />
 1332:    <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
 1333:    <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
 1334:                     $$upload_output .= '<b>Upload embedded files</b>:<br />
 1335:    <table>';
 1336:                     foreach my $embed_file (keys(%{$allfiles})) {
 1337:                         $$upload_output .= '<tr><td>'.$embed_file.
 1338:           '<input name="embedded_item_'.$num.'" type="file" />
 1339:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
 1340:                         my $attrib;
 1341:                         if (@{$$allfiles{$embed_file}} > 1) {
 1342:                             $attrib = join(':',@{$$allfiles{$embed_file}});
 1343:                         } else {
 1344:                             $attrib = $$allfiles{$embed_file}[0];
 1345:                         }
 1346:                         $$upload_output .=
 1347:            '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.$attrib.'" />';
 1348:                         if (exists($$codebase{$embed_file})) {
 1349:                             $$upload_output .= 
 1350:           '<input name="codebase_'.$num.'" type="hidden" value="'.&escape($$codebase{$embed_file}).'" />';
 1351:                         }
 1352:                         $$upload_output .= '</td></tr>';
 1353:                         $num ++;
 1354:                     }
 1355:                     $phase_status = 'phasetwo';
 1356:                     $$upload_output .= '</table><br />
 1357:    <input type ="submit" value="Complete upload" />
 1358:    </form>';
 1359:                 } else {
 1360:                     $$upload_output .= 'No embedded items identified<br />';
 1361:                 }
 1362:             }
 1363:         }
 1364:     }
 1365:     return $phase_status;
 1366: }
 1367: 
 1368: sub process_secondary_uploads {
 1369:     my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
 1370:     my $folder=$env{'form.folder'};
 1371:     my $destination = 'docs/';
 1372:     if ($folder =~ /^supplemental/) {
 1373:         $destination = 'supplemental/';
 1374:     }
 1375:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
 1376:         $destination .= 'default/';
 1377:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
 1378:         $destination .=  $2.'/';
 1379:     }
 1380:     $destination .= $newidx;
 1381:     my ($url,$filename);
 1382:     $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
 1383:     ($filename) = ($url =~ m-^/uploaded/$coursedom/$coursenum/$destination/(.+)$-);
 1384:     return $filename;
 1385: }
 1386: 
 1387: # --------------------------------------------------------------- An entry line
 1388: 
 1389: sub entryline {
 1390:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
 1391:     $title=~s/\&colon\;/\:/g;
 1392:     $title=&HTML::Entities::encode(&HTML::Entities::decode(
 1393:      &unescape($title)),'"<>&\'');
 1394:     my $renametitle=$title;
 1395:     my $foldertitle=$title;
 1396:     my $pagetitle=$title;
 1397:     my $orderidx=$Apache::lonratedt::order[$index];
 1398:     if ($title=~ /^(\d+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(.*)$/	) { 
 1399: 	$foldertitle=&Apache::lontexconvert::msgtexconverted($4);
 1400: 	$renametitle=$4;
 1401: 	$title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
 1402: 	    &Apache::loncommon::plainname($2,$3).': <br />'.
 1403: 	    $foldertitle;
 1404:     }
 1405:     $renametitle=~s/\\/\\\\/g;
 1406:     $renametitle=~s/\&quot\;/\\\"/g;
 1407:     my $line='<tr>';
 1408: # Edit commands
 1409:     my $container;
 1410:     my $folderpath;
 1411:     if ($env{'form.folderpath'}) {
 1412:         $container = 'sequence';
 1413: 	$folderpath=&escape($env{'form.folderpath'});
 1414: 	# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
 1415:     }
 1416:     my ($pagepath,$pagesymb);
 1417:     if ($env{'form.pagepath'}) {
 1418:         $container = 'page';
 1419:         $pagepath=&escape($env{'form.pagepath'});
 1420:         $pagesymb=&escape($env{'form.pagesymb'});
 1421:     }
 1422:     my $cpinfo='';
 1423:     if ($env{'form.markedcopy_url'}) {
 1424:        $cpinfo='&markedcopy_url='.
 1425:                &escape($env{'form.markedcopy_url'}).
 1426:                '&markedcopy_title='.
 1427:                &escape($env{'form.markedcopy_title'});
 1428:     }
 1429:     if ($allowed) {
 1430: 	my $incindex=$index+1;
 1431: 	my $selectbox='';
 1432: 	if (($folder!~/^supplemental/) &&
 1433: 	    ($#Apache::lonratedt::order>0) && 
 1434: 	    ((split(/\:/,
 1435: 	     $Apache::lonratedt::resources[$Apache::lonratedt::order[0]]))[1] 
 1436: 	     ne '') && 
 1437: 	    ((split(/\:/,
 1438: 	     $Apache::lonratedt::resources[$Apache::lonratedt::order[1]]))[1] 
 1439: 	     ne '')) {
 1440: 	    $selectbox=
 1441: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
 1442: 		'<select name="newpos" onChange="this.form.submit()">';
 1443: 	    for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
 1444: 		if ($i==$incindex) {
 1445: 		    $selectbox.='<option value="" selected="1">('.$i.')</option>';
 1446: 		} else {
 1447: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
 1448: 		}
 1449: 	    }
 1450: 	    $selectbox.='</select>';
 1451: 	}
 1452: 	my %lt=&Apache::lonlocal::texthash(
 1453:                 'up' => 'Move Up',
 1454: 		'dw' => 'Move Down',
 1455: 		'rm' => 'Remove',
 1456:                 'ct' => 'Cut',
 1457: 		'rn' => 'Rename',
 1458: 		'cp' => 'Copy');
 1459: 	my $nocopy=0;
 1460:         if ($url=~/\.(page|sequence)$/) {
 1461: 	    foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url))) {
 1462: 		my ($title,$url,$ext,$type)=split(/\:/,$_);
 1463: 		if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
 1464: 		    $nocopy=1;
 1465: 		    last;
 1466: 		}
 1467: 	    }
 1468: 	}
 1469:         my $copylink='&nbsp;';
 1470:         if ($env{'form.pagepath'}) {
 1471:            unless ($nocopy) {
 1472:                $copylink=(<<ENDCOPY);
 1473: <a href='javascript:markcopy("$pagepath","$index","$renametitle","page","$pagesymb");'>
 1474: <font size="-2" color="#000099">$lt{'cp'}</font></a></td>
 1475: ENDCOPY
 1476:             }
 1477:             $line.=(<<END);
 1478: <form name="entry_$index" action="/adm/coursedocs" method="post">
 1479: <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />
 1480: <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />
 1481: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
 1482: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
 1483: <input type="hidden" name="setparms" value="$orderidx" />
 1484: <td><table border='0' cellspacing='2' cellpadding='0'>
 1485: <tr><td bgcolor="#DDDDDD">
 1486: <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
 1487: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
 1488: <tr><td bgcolor="#DDDDDD">
 1489: <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
 1490: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
 1491: </table></td>
 1492: <td>$selectbox
 1493: </td><td bgcolor="#DDDDDD">
 1494: <a href='javascript:removeres("$pagepath","$index","$renametitle","page","$pagesymb");'>
 1495: <font size="-2" color="#990000">$lt{'rm'}</font></a>
 1496: <a href='javascript:cutres("$pagepath","$index","$renametitle","page","$pagesymb");'>
 1497: <font size="-2" color="#550044">$lt{'ct'}</font></a>
 1498: <a href='javascript:changename("$pagepath","$index","$renametitle","page","$pagesymb");'>
 1499: <font size="-2" color="#009900">$lt{'rn'}</font></a>
 1500: $copylink
 1501: END
 1502:         } else {
 1503:            unless ($nocopy) {
 1504:                $copylink=(<<ENDCOPY);
 1505: <a href='javascript:markcopy("$folderpath","$index","$renametitle","sequence");'>
 1506: <font size="-2" color="#000099">$lt{'cp'}</font></a></td>
 1507: ENDCOPY
 1508:             }
 1509:             $line.=(<<END); 
 1510: <form name="entry_$index" action="/adm/coursedocs" method="post">
 1511: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
 1512: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
 1513: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
 1514: <input type="hidden" name="setparms" value="$orderidx" />
 1515: <td><table border='0' cellspacing='2' cellpadding='0'>
 1516: <tr><td bgcolor="#DDDDDD">
 1517: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath$cpinfo'>
 1518: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
 1519: <tr><td bgcolor="#DDDDDD">
 1520: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath$cpinfo'>
 1521: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
 1522: </table></td>
 1523: <td>$selectbox
 1524: </td><td bgcolor="#DDDDDD">
 1525: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
 1526: <font size="-2" color="#990000">$lt{'rm'}</font></a>
 1527: <a href='javascript:cutres("$folderpath","$index","$renametitle","sequence");'>
 1528: <font size="-2" color="#550044">$lt{'ct'}</font></a>
 1529: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
 1530: <font size="-2" color="#009900">$lt{'rn'}</font></a>
 1531: $copylink
 1532: END
 1533:         }
 1534:     }
 1535: # Figure out what kind of a resource this is
 1536:     my ($extension)=($url=~/\.(\w+)$/);
 1537:     my $uploaded=($url=~/^\/*uploaded\//);
 1538:     my $icon=&Apache::loncommon::icon($url);
 1539:     my $isfolder=0;
 1540:     my $ispage=0;
 1541:     my $folderarg;
 1542:     my $pagearg;
 1543:     my $pagefile;
 1544:     if ($uploaded) {
 1545: 	if ($extension eq 'sequence') {
 1546: 	    $icon=$iconpath.'/folder_closed.gif';
 1547: 	    $url=~/$coursenum\/([\/\w]+)\.sequence$/;
 1548: 	    $url='/adm/coursedocs?';
 1549: 	    $folderarg=$1;
 1550: 	    $isfolder=1;
 1551:         } elsif ($extension eq 'page') {
 1552:             $icon=$iconpath.'/page.gif';
 1553:             $url=~/$coursenum\/([\/\w]+)\.page$/;
 1554:             $pagearg=$1;
 1555:             $url='/adm/coursedocs?';
 1556:             $ispage=1;
 1557: 	} else {
 1558: 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
 1559: 	}
 1560:     }
 1561:     $url=~s-^http(\&colon\;|:)//-/adm/wrapper/ext/-;
 1562:     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
 1563: 	my $symb=&Apache::lonnet::symbclean(
 1564:           &Apache::lonnet::declutter('uploaded/'.
 1565:            $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
 1566:            $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
 1567:            '.sequence').
 1568:            '___'.$residx.'___'.
 1569: 	   &Apache::lonnet::declutter($url));
 1570: 	(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
 1571: 	$url=&Apache::lonnet::clutter($url);
 1572: 	if ($url=~/^\/*uploaded\//) {
 1573: 	    $url=~/\.(\w+)$/;
 1574: 	    my $embstyle=&Apache::loncommon::fileembstyle($1);
 1575: 	    if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
 1576: 		$url='/adm/wrapper'.$url;
 1577: 	    } elsif ($embstyle eq 'ssi') {
 1578: 		#do nothing with these
 1579: 	    } elsif ($url!~/\.(sequence|page)$/) {
 1580: 		$url='/adm/coursedocs/showdoc'.$url;
 1581: 	    }
 1582: 	} elsif ($url=~m|^/ext/|) { 
 1583: 	    $url='/adm/wrapper'.$url;
 1584: 	}
 1585: 	$url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
 1586: 	if ($container eq 'page') {
 1587: 	    my $symb=$env{'form.pagesymb'};
 1588: 	    	    
 1589: 	    $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
 1590: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
 1591: 	}
 1592:     }
 1593:     my $parameterset='&nbsp;';
 1594:     if ($isfolder || $extension eq 'sequence') {
 1595: 	my $foldername=&escape($foldertitle);
 1596: 	my $folderpath=$env{'form.folderpath'};
 1597: 	if ($folderpath) { $folderpath.='&' };
 1598: 	$folderpath.=$folderarg.'&'.$foldername;
 1599: 	$url.='folderpath='.&escape($folderpath).$cpinfo;
 1600: 	$parameterset='<label>'.&mt('Randomly Pick: ').
 1601: 	    '<input type="text" size="4" onChange="this.form.submit()" name="randpick_'.$orderidx.'" value="'.
 1602: 	    (&Apache::lonratedt::getparameter($orderidx,
 1603:                                               'parameter_randompick'))[0].
 1604:                                               '" />'.
 1605: '<font size="-2"><a href="javascript:void(0)">'.&mt('Store').'</a></font></label>';
 1606:        
 1607:     }
 1608:     if ($ispage) {
 1609:         my $pagename=&escape($pagetitle);
 1610:         my $pagepath;
 1611:         my $folderpath=$env{'form.folderpath'};
 1612:         if ($folderpath) { $pagepath = $folderpath.'&' };
 1613:         $pagepath.=$pagearg.'&'.$pagename;
 1614: 	my $symb=$env{'form.pagesymb'};
 1615: 	if (!$symb) {
 1616: 	    my $path='uploaded/'.
 1617: 		$env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
 1618: 		$env{'course.'.$env{'request.course.id'}.'.num'}.'/';
 1619: 	    $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
 1620: 					       $residx,
 1621: 					       $path.$pagearg.'.page');
 1622: 	}
 1623: 	$url.='pagepath='.&escape($pagepath).
 1624: 	    '&pagesymb='.&escape($symb).$cpinfo;
 1625:     }
 1626:     $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
 1627: 	'" border="0"></a></td>'.
 1628:         "<td bgcolor='#FFFFBB'><a href=\"$url\">$title</a></td>";
 1629:     if (($allowed) && ($folder!~/^supplemental/)) {
 1630:  	my %lt=&Apache::lonlocal::texthash(
 1631:  			      'hd' => 'Hidden',
 1632:  			      'ec' => 'URL hidden');
 1633: 	my $enctext=
 1634: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
 1635: 	my $hidtext=
 1636: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
 1637: 	$line.=(<<ENDPARMS);
 1638: <td bgcolor="#BBBBFF"><font size='-2'>
 1639: <nobr><label><input type="checkbox" name="hidprs_$orderidx" onClick="this.form.submit()" $hidtext /> $lt{'hd'}</label></nobr></td>
 1640: <td bgcolor="#BBBBFF"><font size='-2'>
 1641: <nobr><label><input type="checkbox" name="encprs_$orderidx" onClick="this.form.submit()" $enctext /> $lt{'ec'}</label></nobr></td>
 1642: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
 1643: ENDPARMS
 1644:     }
 1645:     $line.="</form></tr>";
 1646:     return $line;
 1647: }
 1648: 
 1649: # ---------------------------------------------------------------- tie the hash
 1650: 
 1651: sub tiehash {
 1652:     my ($mode)=@_;
 1653:     $hashtied=0;
 1654:     if ($env{'request.course.fn'}) {
 1655: 	if ($mode eq 'write') {
 1656: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
 1657: 		    &GDBM_WRCREAT(),0640)) {
 1658:                 $hashtied=2;
 1659: 	    }
 1660: 	} else {
 1661: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
 1662: 		    &GDBM_READER(),0640)) {
 1663:                 $hashtied=1;
 1664: 	    }
 1665: 	}
 1666:     }    
 1667: }
 1668: 
 1669: sub untiehash {
 1670:     if ($hashtied) { untie %hash; }
 1671:     $hashtied=0;
 1672:     return OK;
 1673: }
 1674: 
 1675: # --------------------------------------------------------------- check on this
 1676: 
 1677: sub checkonthis {
 1678:     my ($r,$url,$level,$title)=@_;
 1679:     $url=&unescape($url);
 1680:     $alreadyseen{$url}=1;
 1681:     $r->rflush();
 1682:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
 1683:        $r->print("\n<br />");
 1684:        for (my $i=0;$i<=$level*5;$i++) {
 1685:            $r->print('&nbsp;');
 1686:        }
 1687:        $r->print('<a href="'.$url.'" target="cat">'.
 1688: 		 ($title?$title:$url).'</a> ');
 1689:        if ($url=~/^\/res\//) {
 1690: 	  my $result=&Apache::lonnet::repcopy(
 1691:                               &Apache::lonnet::filelocation('',$url));
 1692:           if ($result eq 'ok') {
 1693:              $r->print('<font color="green">'.&mt('ok').'</font>');
 1694:              $r->rflush();
 1695:              &Apache::lonnet::countacc($url);
 1696:              $url=~/\.(\w+)$/;
 1697:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
 1698: 		 $r->print('<br />');
 1699:                  $r->rflush();
 1700:                  for (my $i=0;$i<=$level*5;$i++) {
 1701:                      $r->print('&nbsp;');
 1702:                  }
 1703:                  $r->print('- '.&mt('Rendering').': ');
 1704: 		 my ($errorcount,$warningcount)=split(/:/,
 1705: 	       &Apache::lonnet::ssi_body($url,
 1706: 			       ('grade_target'=>'web',
 1707: 				'return_only_error_and_warning_counts' => 1)));
 1708:                  if (($errorcount) ||
 1709:                      ($warningcount)) {
 1710: 		     if ($errorcount) {
 1711:                         $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
 1712: 			  $errorcount.' '.
 1713: 				  &mt('error(s)').'</b></font> ');
 1714:                      }
 1715: 		     if ($warningcount) {
 1716:                         $r->print('<font color="blue">'.
 1717: 			  $warningcount.' '.
 1718: 				  &mt('warning(s)').'</font>');
 1719:                      }
 1720:                  } else {
 1721:                      $r->print('<font color="green">'.&mt('ok').'</font>');
 1722:                  }
 1723:                  $r->rflush();
 1724:              }
 1725: 	     my $dependencies=
 1726:                 &Apache::lonnet::metadata($url,'dependencies');
 1727:              foreach (split(/\,/,$dependencies)) {
 1728: 		 if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
 1729:                     &checkonthis($r,$_,$level+1);
 1730:                  }
 1731:              }
 1732:           } elsif ($result eq 'unavailable') {
 1733:              $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
 1734:           } elsif ($result eq 'not_found') {
 1735: 	      unless ($url=~/\$/) {
 1736: 		  $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
 1737: 	      } else {
 1738: 		  $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
 1739: 	      }
 1740:           } else {
 1741:              $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
 1742:           }
 1743:       }
 1744:    }
 1745: }
 1746: 
 1747: 
 1748: #
 1749: # ----------------------------------------------------------------- List Symbs
 1750: # 
 1751: sub list_symbs {
 1752:     my ($r) = @_;
 1753: 
 1754:     $r->print(&Apache::loncommon::start_page('Symb List'));
 1755:     my $navmap = Apache::lonnavmaps::navmap->new();
 1756:     $r->print("<pre>\n");
 1757:     foreach my $res ($navmap->retrieveResources()) {
 1758: 	$r->print($res->compTitle()."\t".$res->symb()."\n");
 1759:     }
 1760:     $r->print("\n</pre>\n");
 1761:     $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
 1762: }
 1763: 
 1764: 
 1765: #
 1766: # -------------------------------------------------------------- Verify Content
 1767: # 
 1768: sub verifycontent {
 1769:     my ($r) = @_;
 1770:     my $type = &Apache::loncommon::course_type();
 1771:    my $loaderror=&Apache::lonnet::overloaderror($r);
 1772:    if ($loaderror) { return $loaderror; }
 1773:    $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
 1774:    $hashtied=0;
 1775:    undef %alreadyseen;
 1776:    %alreadyseen=();
 1777:    &tiehash();
 1778:    foreach (keys %hash) {
 1779:        if ($hash{$_}=~/\.(page|sequence)$/) {
 1780: 	   if (($_=~/^src_/) && ($alreadyseen{&unescape($hash{$_})})) {
 1781: 	       $r->print('<hr /><font color="red">'.
 1782: 			 &mt('The following sequence or page is included more than once in your '.$type.': ').
 1783: 			 &unescape($hash{$_}).'</font><br />'.
 1784: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
 1785: 	   }
 1786:        }
 1787:        if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$_})})) {
 1788:            &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
 1789:        }
 1790:    }
 1791:    &untiehash();
 1792:    $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
 1793: 	     &mt('Return to DOCS').'</a>');
 1794: }
 1795: 
 1796: 
 1797: # -------------------------------------------------------------- Check Versions
 1798: 
 1799: sub devalidateversioncache {
 1800:     my $src=shift;
 1801:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
 1802: 					  &Apache::lonnet::clutter($src));
 1803: }
 1804: 
 1805: sub checkversions {
 1806:     my ($r) = @_;
 1807:     my $type = &Apache::loncommon::course_type();
 1808:     $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
 1809:     my $header='';
 1810:     my $startsel='';
 1811:     my $monthsel='';
 1812:     my $weeksel='';
 1813:     my $daysel='';
 1814:     my $allsel='';
 1815:     my %changes=();
 1816:     my $starttime=0;
 1817:     my $haschanged=0;
 1818:     my %setversions=&Apache::lonnet::dump('resourceversions',
 1819: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
 1820: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
 1821: 
 1822:     $hashtied=0;
 1823:     &tiehash();
 1824:     my %newsetversions=();
 1825:     if ($env{'form.setmostrecent'}) {
 1826: 	$haschanged=1;
 1827: 	foreach (keys %hash) {
 1828: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
 1829: 		$newsetversions{$1}='mostrecent';
 1830:                 &devalidateversioncache($1);
 1831: 	    }
 1832: 	}
 1833:     } elsif ($env{'form.setcurrent'}) {
 1834: 	$haschanged=1;
 1835: 	foreach (keys %hash) {
 1836: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
 1837: 		my $getvers=&Apache::lonnet::getversion($1);
 1838: 		if ($getvers>0) {
 1839: 		    $newsetversions{$1}=$getvers;
 1840: 		    &devalidateversioncache($1);
 1841: 		}
 1842: 	    }
 1843: 	}
 1844:     } elsif ($env{'form.setversions'}) {
 1845: 	$haschanged=1;
 1846: 	foreach (keys %env) {
 1847: 	    if ($_=~/^form\.set_version_(.+)$/) {
 1848: 		my $src=$1;
 1849: 		if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
 1850: 		    $newsetversions{$src}=$env{$_};
 1851: 		    &devalidateversioncache($src);
 1852: 		}
 1853: 	    }
 1854: 	}
 1855:     }
 1856:     if ($haschanged) {
 1857:         if (&Apache::lonnet::put('resourceversions',\%newsetversions,
 1858: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
 1859: 			  $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {		
 1860: 	    $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
 1861: 	} else {
 1862: 	    $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
 1863: 	}
 1864: 	&mark_hash_old();
 1865:     }
 1866:     &changewarning($r,'');
 1867:     if ($env{'form.timerange'} eq 'all') {
 1868: # show all documents
 1869: 	$header=&mt('All Documents in '.$type);
 1870: 	$allsel=1;
 1871: 	foreach (keys %hash) {
 1872: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
 1873: 		my $src=$1;
 1874: 		$changes{$src}=1;
 1875: 	    }
 1876: 	}
 1877:     } else {
 1878: # show documents which changed
 1879: 	%changes=&Apache::lonnet::dump
 1880: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
 1881:                      $env{'course.'.$env{'request.course.id'}.'.num'});
 1882: 	my $firstkey=(keys %changes)[0];
 1883: 	unless ($firstkey=~/^error\:/) {
 1884: 	    unless ($env{'form.timerange'}) {
 1885: 		$env{'form.timerange'}=604800;
 1886: 	    }
 1887: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
 1888: 		.&mt('seconds');
 1889: 	    if ($env{'form.timerange'}==-1) {
 1890: 		$seltext='since start of course';
 1891: 		$startsel='selected';
 1892: 		$env{'form.timerange'}=time;
 1893: 	    }
 1894: 	    $starttime=time-$env{'form.timerange'};
 1895: 	    if ($env{'form.timerange'}==2592000) {
 1896: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
 1897: 		$monthsel='selected';
 1898: 	    } elsif ($env{'form.timerange'}==604800) {
 1899: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
 1900: 		$weeksel='selected';
 1901: 	    } elsif ($env{'form.timerange'}==86400) {
 1902: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
 1903: 		$daysel='selected';
 1904: 	    }
 1905: 	    $header=&mt('Content changed').' '.$seltext;
 1906: 	} else {
 1907: 	    $header=&mt('No content modifications yet.');
 1908: 	}
 1909:     }
 1910:     %setversions=&Apache::lonnet::dump('resourceversions',
 1911: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
 1912: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
 1913:     my %lt=&Apache::lonlocal::texthash
 1914: 	      ('st' => 'Version changes since start of '.$type,
 1915: 	       'lm' => 'Version changes since last Month',
 1916: 	       'lw' => 'Version changes since last Week',
 1917: 	       'sy' => 'Version changes since Yesterday',
 1918:                'al' => 'All Resources (possibly large output)',
 1919: 	       'sd' => 'Display',
 1920: 	       'fi' => 'File',
 1921: 	       'md' => 'Modification Date',
 1922:                'mr' => 'Most recently published Version',
 1923: 	       've' => 'Version used in '.$type,
 1924:                'vu' => 'Set Version to be used in '.$type,
 1925: 'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
 1926: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
 1927: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
 1928: 	       'di' => 'Differences');
 1929:     $r->print(<<ENDHEADERS);
 1930: <form action="/adm/coursedocs" method="post">
 1931: <input type="hidden" name="versions" value="1" />
 1932: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
 1933: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
 1934: <select name="timerange">
 1935: <option value='all' $allsel>$lt{'al'}</option>
 1936: <option value="-1" $startsel>$lt{'st'}</option>
 1937: <option value="2592000" $monthsel>$lt{'lm'}</option>
 1938: <option value="604800" $weeksel>$lt{'lw'}</option>
 1939: <option value="86400" $daysel>$lt{'sy'}</option>
 1940: </select>
 1941: <input type="submit" name="display" value="$lt{'sd'}" />
 1942: <h3>$header</h3>
 1943: <input type="submit" name="setversions" value="$lt{'sv'}" />
 1944: <table border="0">
 1945: ENDHEADERS
 1946:     foreach (sort keys %changes) {
 1947: 	if ($changes{$_}>$starttime) {
 1948: 	    my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
 1949: 	    my $currentversion=&Apache::lonnet::getversion($_);
 1950: 	    if ($currentversion<0) {
 1951: 		$currentversion=&mt('Could not be determined.');
 1952: 	    }
 1953: 	    my $linkurl=&Apache::lonnet::clutter($_);
 1954: 	    $r->print(
 1955: 		      '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
 1956: 		      &Apache::lonnet::gettitle($linkurl).
 1957:                       '</b></font></td></tr>'.
 1958:                       '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
 1959:                       '<td colspan="4">'.
 1960:                       '<a href="'.$linkurl.'" target="cat">'.$linkurl.
 1961: 		      '</a></td></tr>'.
 1962:                       '<tr><td></td>'.
 1963:                       '<td title="'.$lt{'md'}.'">'.
 1964: 		      &Apache::lonlocal::locallocaltime(
 1965:                            &Apache::lonnet::metadata($root.'.'.$extension,
 1966:                                                      'lastrevisiondate')
 1967:                                                         ).
 1968:                       '</td>'.
 1969:                       '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
 1970:                       '<font size="+1">'.$currentversion.'</font>'.
 1971:                       '</nobr></td>'.
 1972:                       '<td title="'.$lt{'ve'}.'"><nobr>In '.$type.': '.
 1973:                       '<font size="+1">');
 1974: # Used in course
 1975: 	    my $usedversion=$hash{'version_'.$linkurl};
 1976: 	    if (($usedversion) && ($usedversion ne 'mostrecent')) {
 1977: 		$r->print($usedversion);
 1978: 	    } else {
 1979: 		$r->print($currentversion);
 1980: 	    }
 1981: 	    $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
 1982:                       '<nobr>Use: ');
 1983: # Set version
 1984: 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
 1985: 						      'set_version_'.$linkurl,
 1986: 						      ('select_form_order' =>
 1987: 						       ['',1..$currentversion,'mostrecent'],
 1988: 						       '' => '',
 1989: 						       'mostrecent' => 'most recent',
 1990: 						       map {$_,$_} (1..$currentversion))));
 1991: 	    $r->print('</nobr></td></tr><tr><td></td>');
 1992: 	    my $lastold=1;
 1993: 	    for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
 1994: 		my $url=$root.'.'.$prevvers.'.'.$extension;
 1995: 		if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
 1996: 		    $starttime) {
 1997: 		    $lastold=$prevvers;
 1998: 		}
 1999: 	    }
 2000:             # 
 2001:             # Code to figure out how many version entries should go in
 2002:             # each of the four columns
 2003:             my $entries_per_col = 0;
 2004:             my $num_entries = ($currentversion-$lastold);
 2005:             if ($num_entries % 4 == 0) {
 2006:                 $entries_per_col = $num_entries/4;
 2007:             } else {
 2008:                 $entries_per_col = $num_entries/4 + 1;
 2009:             }
 2010:             my $entries_count = 0;
 2011:             $r->print('<td valign="top"><font size="-2">'); 
 2012:             my $cols_output = 1;
 2013:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
 2014: 		my $url=$root.'.'.$prevvers.'.'.$extension;
 2015: 		$r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
 2016: 			  '">'.&mt('Version').' '.$prevvers.'</a> ('.
 2017: 			  &Apache::lonlocal::locallocaltime(
 2018:                                 &Apache::lonnet::metadata($url,
 2019:                                                           'lastrevisiondate')
 2020:                                                             ).
 2021: 			  ')');
 2022: 		if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
 2023:                     $r->print(' <a href="/adm/diff?filename='.
 2024: 			      &Apache::lonnet::clutter($root.'.'.$extension).
 2025: 			      '&versionone='.$prevvers.
 2026: 			      '">'.&mt('Diffs').'</a>');
 2027: 		}
 2028: 		$r->print('</nobr><br />');
 2029:                 if (++$entries_count % $entries_per_col == 0) {
 2030:                     $r->print('</font></td>');
 2031:                     if ($cols_output != 4) {
 2032:                         $r->print('<td valign="top"><font size="-2">');
 2033:                         $cols_output++;
 2034:                     }
 2035:                 }
 2036: 	    }
 2037:             while($cols_output++ < 4) {
 2038:                 $r->print('</font></td><td><font>')
 2039:             }
 2040: 	    $r->print('</font></td></tr>'."\n");
 2041: 	}
 2042:     }
 2043:     $r->print('</table></form>');
 2044:     $r->print('<h1>'.&mt('Done').'.</h1>');
 2045: 
 2046:     &untiehash();
 2047: }
 2048: 
 2049: sub mark_hash_old {
 2050:     my $retie_hash=0;
 2051:     if ($hashtied) {
 2052: 	$retie_hash=1;
 2053: 	&untiehash();
 2054:     }
 2055:     &tiehash('write');
 2056:     $hash{'old'}=1;
 2057:     &untiehash();
 2058:     if ($retie_hash) { &tiehash(); }
 2059: }
 2060: 
 2061: sub is_hash_old {
 2062:     my $untie_hash=0;
 2063:     if (!$hashtied) {
 2064: 	$untie_hash=1;
 2065: 	&tiehash();
 2066:     }
 2067:     my $return=$hash{'old'};
 2068:     if ($untie_hash) { &untiehash(); }
 2069:     return $return;
 2070: }
 2071: 
 2072: sub changewarning {
 2073:     my ($r,$postexec,$message,$url)=@_;
 2074:     if (!&is_hash_old()) { return; }
 2075:     my $pathvar='folderpath';
 2076:     my $path=&escape($env{'form.folderpath'});
 2077:     if (!defined($url)) {
 2078: 	if (defined($env{'form.pagepath'})) {
 2079: 	    $pathvar='pagepath';
 2080: 	    $path=&escape($env{'form.pagepath'});
 2081: 	    $path.='&amp;pagesymb='.&escape($env{'form.pagesymb'});
 2082: 	}
 2083: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
 2084:     }
 2085:     my $course_type = &Apache::loncommon::course_type();
 2086:     if (!defined($message)) {
 2087: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
 2088:     }
 2089:     $r->print("\n\n".
 2090: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n". 
 2091: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
 2092: '<input type="hidden" name="orgurl" value="'.$url.
 2093: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
 2094: &mt($message,' <input type="hidden" name="'.
 2095:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
 2096:     &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />').
 2097: $help{'Caching'}.'</font></h3></form>'."\n\n");
 2098: }
 2099: 
 2100: # ================================================================ Main Handler
 2101: sub handler {
 2102:     my $r = shift;
 2103:     &Apache::loncommon::content_type($r,'text/html');
 2104:     $r->send_http_header;
 2105:     return OK if $r->header_only;
 2106:     my $type = &Apache::loncommon::course_type();
 2107: 
 2108: # --------------------------------------------- Initialize help topics for this
 2109:     foreach ('Adding_Course_Doc','Main_Course_Documents',
 2110: 	     'Adding_External_Resource','Navigate_Content',
 2111: 	     'Adding_Folders','Docs_Overview', 'Load_Map',
 2112: 	     'Supplemental','Score_Upload_Form','Adding_Pages',
 2113: 	     'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
 2114: 	     'Check_Resource_Versions','Verify_Content') {
 2115: 	$help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
 2116:     }
 2117:     # Composite help files
 2118:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
 2119: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
 2120:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
 2121: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
 2122:     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
 2123: 		    'Option_Response_Simple');
 2124:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
 2125: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
 2126:     $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
 2127: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
 2128:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
 2129: 
 2130: # does this user have privileges to modify docs
 2131:     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
 2132: 
 2133:   if ($allowed && $env{'form.verify'}) {
 2134:       &verifycontent($r);
 2135:   } elsif ($allowed && $env{'form.listsymbs'}) {
 2136:       &list_symbs($r);
 2137:   } elsif ($allowed && $env{'form.versions'}) {
 2138:       &checkversions($r);
 2139:   } elsif ($allowed && $env{'form.dumpcourse'}) {
 2140:       &dumpcourse($r);
 2141:   } elsif ($allowed && $env{'form.exportcourse'}) {
 2142:       &exportcourse($r);
 2143:   } else {
 2144: # is this a standard course?
 2145: 
 2146:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
 2147:     my $forcestandard = 0;
 2148:     my $forcesupplement;
 2149:     my $script='';
 2150:     my $showdoc=0;
 2151:     my $containertag;
 2152:     my $uploadtag;
 2153:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 2154: 					    ['folderpath','pagepath',
 2155: 					     'pagesymb','markedcopy_url',
 2156: 					     'markedcopy_title']);
 2157:     if ($env{'form.folderpath'}) {
 2158: 	my (@folderpath)=split('&',$env{'form.folderpath'});
 2159: 	$env{'form.foldername'}=&unescape(pop(@folderpath));
 2160: 	$env{'form.folder'}=pop(@folderpath);
 2161:     }
 2162:     if ($env{'form.pagepath'}) {
 2163:         my (@pagepath)=split('&',$env{'form.pagepath'});
 2164:         $env{'form.pagename'}=&unescape(pop(@pagepath));
 2165:         $env{'form.folder'}=pop(@pagepath);
 2166:         $containertag = '<input type="hidden" name="pagepath" value="" />'.
 2167: 	    '<input type="hidden" name="pagesymb" value="" />';
 2168:         $uploadtag = '<input type="hidden" name="pagepath" value="'.$env{'form.pagepath'}.'" />'.
 2169: 	    '<input type="hidden" name="pagesymb" value="'.$env{'form.pagesymb'}.'" />';
 2170:     }
 2171:     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
 2172:        $showdoc='/'.$1;
 2173:     }
 2174:     unless ($showdoc) { # got called from remote
 2175:        if (($env{'form.folder'}=~/^default_/) || 
 2176:           ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
 2177:            $forcestandard = 1;
 2178:        } 
 2179:        $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
 2180: 
 2181:        if ($allowed) { 
 2182:          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
 2183:          $script=&Apache::lonratedt::editscript('simple'); 
 2184:        }
 2185:     } else { # got called in sequence from course
 2186:        $allowed=0;
 2187:     }
 2188: 
 2189: # get course data
 2190:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
 2191:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
 2192: 
 2193: # get personal data 
 2194:     my $uname=$env{'user.name'};
 2195:     my $udom=$env{'user.domain'};
 2196:     my $plainname=&escape(
 2197:                      &Apache::loncommon::plainname($uname,$udom));
 2198: 
 2199: # graphics settings
 2200: 
 2201:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
 2202: 
 2203:     if ($allowed) {
 2204: 	$script .= &editing_js($udom,$uname);
 2205:     }
 2206: # -------------------------------------------------------------------- Body tag
 2207:     $script = '<script type="text/javascript">'."\n".$script."\n".'</script>';
 2208:     $r->print(&Apache::loncommon::start_page("$type Documents", $script,
 2209: 					     {'force_register' => $showdoc,}).
 2210: 	      &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
 2211:   
 2212:   my %allfiles = ();
 2213:   my %codebase = ();
 2214:   my ($upload_result,$upload_output);
 2215:   if ($allowed) {
 2216:       if (($env{'form.uploaddoc.filename'}) &&                                               ($env{'form.cmd'}=~/^upload_(\w+)/)) {
 2217: # Process file upload - phase one - upload and parse primary file.  
 2218:           $upload_result = &process_file_upload(\$upload_output,$coursenum,
 2219: 						$coursedom,\%allfiles,
 2220: 						\%codebase,$1);
 2221:           if ($upload_result eq 'phasetwo') {
 2222:               $r->print($upload_output);
 2223:           }
 2224:       } elsif ($env{'form.phasetwo'}) {
 2225:           my %newname = ();
 2226:           my %origname = ();
 2227:           my %attribs = ();
 2228:           my $updateflag = 0;
 2229:           my $residx = $env{'form.newidx'};
 2230:           my $primary_url = &unescape($env{'form.primaryurl'});
 2231: # Process file upload - phase two - gather secondary files.
 2232:           for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
 2233:               if ($env{'form.embedded_item_'.$i.'.filename'}) {
 2234:                   my $javacodebase;
 2235:                   $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
 2236:                   $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
 2237:                   if (exists($env{'form.embedded_codebase_'.$i})) {
 2238:                       $javacodebase =  &unescape($env{'form.embedded_codebase_'.$i});  
 2239:                       $origname{$i} =~ s#^\Q$javacodebase\E/##; 
 2240:                   }
 2241:                   my @attributes = ();
 2242:                   if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
 2243:                       @attributes = split/:/,$env{'form.embedded_attrib_'.$i};
 2244:                   } else {
 2245:                       @attributes = ($env{'form.embedded_attrib_'.$i});
 2246:                   }
 2247:                   foreach (@attributes) {
 2248:                       push(@{$attribs{$i}},&unescape($_));
 2249:                   }
 2250:                   if ($javacodebase) {
 2251:                       $codebase{$i} = $javacodebase;
 2252:                       $codebase{$i} =~ s#/$##;
 2253:                       $updateflag = 1;
 2254:                   }
 2255:               }
 2256:               unless ($newname{$i} eq $origname{$i}) {
 2257:                   $updateflag = 1;
 2258:               }
 2259:           }
 2260: # Process file upload - phase three - modify primary file
 2261:           if ($updateflag) {
 2262:               my ($content,$rtncode);
 2263:               my $updateflag = 0;
 2264:               my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
 2265:               if ($getstatus eq 'ok') {
 2266:                   foreach my $item (keys %newname) {
 2267:                       if ($newname{$item} ne $origname{$item}) {
 2268:                           my $attrib_regexp = '';
 2269:                           if (@{$attribs{$item}} > 1) {
 2270:                               $attrib_regexp = join('|',@{$attribs{$item}});
 2271:                           } else {
 2272:                               $attrib_regexp = $attribs{$item}[0];
 2273:                           }
 2274:                           if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
 2275:                           } 
 2276:                           $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi; 
 2277:                       }
 2278:                       if (exists($codebase{$item})) {
 2279:                           $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
 2280:                       }
 2281:                   }
 2282: # Save edited file.
 2283:                   my $saveresult;
 2284:                   my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
 2285:                   my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
 2286:                   my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
 2287:               } else {
 2288:                   &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus); 
 2289:               }
 2290:           }
 2291:       }
 2292:   }
 2293: 
 2294:   unless ($showdoc ||  $upload_result eq 'phasetwo') {
 2295: # -----------------------------------------------------------------------------
 2296:        my %lt=&Apache::lonlocal::texthash(
 2297:                 'uplm' => 'Upload a new main '.lc($type).' document',
 2298:                 'upls' => 'Upload a new supplemental '.lc($type).' document',
 2299:                 'impp' => 'Import a document',
 2300:                 'pubd' => 'Published documents',
 2301: 		'copm' => 'All documents out of a published map into this folder',
 2302:                 'spec' => 'Special documents',
 2303:                 'upld' => 'Upload Document',
 2304:                 'srch' => 'Search',
 2305:                 'impo' => 'Import',
 2306: 		'book' => 'Import Bookmarks',
 2307:                 'selm' => 'Select Map',
 2308:                 'load' => 'Load Map',
 2309:                 'reco' => 'Recover Deleted Resources',
 2310:                 'newf' => 'New Folder',
 2311:                 'newp' => 'New Composite Page',
 2312:                 'extr' => 'External Resource',
 2313:                 'syll' => 'Syllabus',
 2314:                 'navc' => 'Navigate Contents',
 2315:                 'sipa' => 'Simple Page',
 2316:                 'sipr' => 'Simple Problem',
 2317:                 'drbx' => 'Drop Box',
 2318:                 'scuf' => 'Score Upload Form',
 2319:                 'bull' => 'Bulletin Board',
 2320:                 'mypi' => 'My Personal Info',
 2321: 		'abou' => 'About User',
 2322:                 'imsf' => 'Import IMS package',
 2323:                 'file' =>  'File',
 2324:                 'title' => 'Title',
 2325:                 'comment' => 'Comment',
 2326:                 'parse' => 'If HTML file, upload embedded images/multimedia files'
 2327: 					  );
 2328: # -----------------------------------------------------------------------------
 2329:     if ($allowed) {
 2330:        my $dumpbut=&dumpbutton();
 2331:        my $exportbut=&exportbutton();
 2332:        my %lt=&Apache::lonlocal::texthash(
 2333: 					 'vc' => 'Verify Content',
 2334: 					 'cv' => 'Check/Set Resource Versions',
 2335: 					 'ls' => 'List Symbs',
 2336: 					  );
 2337: 
 2338:        my $folderpath=$env{'form.folderpath'};
 2339:        if (!$folderpath) {
 2340: 	   if ($env{'form.folder'} eq '' ||
 2341: 	       $env{'form.folder'} eq 'supplemental') {
 2342: 	       $folderpath='default&'.
 2343: 		   &escape(&mt('Main '.$type.' Documents'));
 2344: 	   }
 2345:        }
 2346:        unless ($env{'form.pagepath'}) {
 2347:            $containertag = '<input type="hidden" name="folderpath" value="" />';
 2348:            $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
 2349:        }
 2350: 
 2351:        $r->print(<<ENDCOURSEVERIFY);
 2352: <form name="renameform" method="post" action="/adm/coursedocs">
 2353: <input type="hidden" name="title" />
 2354: <input type="hidden" name="cmd" />
 2355: <input type="hidden" name="markcopy" />
 2356: $containertag
 2357: </form>
 2358: <form name="simpleedit" method="post" action="/adm/coursedocs">
 2359: <input type=hidden name="importdetail" value="">
 2360: $uploadtag
 2361: </form>
 2362: <form action="/adm/coursedocs" method="post" name="courseverify">
 2363: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
 2364: <tr><td bgcolor="#DDDDCC">
 2365: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
 2366: </td><td bgcolor="#DDDDCC">
 2367:     <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
 2368: $dumpbut
 2369: $exportbut
 2370: </td><td bgcolor="#DDDDCC">
 2371:     <input type="submit" name="listsymbs" value="$lt{'ls'}" />
 2372: </td></tr></table>
 2373: </form>
 2374: ENDCOURSEVERIFY
 2375:        $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
 2376: 		     &mt('Editing the Table of Contents for your '.$type)));
 2377:     }
 2378: # --------------------------------------------------------- Standard documents
 2379:     $r->print('<table border=2 cellspacing=4 cellpadding=4>');
 2380:     if (($standard) && ($allowed) && (!$forcesupplement)) {
 2381: 	$r->print('<tr><td bgcolor="#BBBBBB">');
 2382: #  '<h2>'.&mt('Main Course Documents').
 2383: #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
 2384:        my $folder=$env{'form.folder'};
 2385:        if ($folder eq '' || $folder eq 'supplemental') {
 2386:            $folder='default';
 2387: 	   $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
 2388:        }
 2389:        my $postexec='';
 2390:        if ($folder eq 'default') {
 2391: 	   $r->print('<script>this.window.name="loncapaclient";</script>');
 2392:        } else {
 2393:            #$postexec='self.close();';
 2394:        }
 2395:        $hadchanges=0;
 2396:        &editor($r,$coursenum,$coursedom,$folder,$allowed,$upload_output);
 2397:        if ($hadchanges) {
 2398: 	   &mark_hash_old()
 2399:        }
 2400:        &changewarning($r,$postexec);
 2401:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 2402:                      '.sequence';
 2403:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 2404:                      '.page';
 2405: 	my $container='sequence';
 2406: 	if ($env{'form.pagepath'}) {
 2407: 	    $container='page';
 2408: 	}
 2409: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
 2410:        $r->print(<<ENDFORM);
 2411: <table cellspacing=4 cellpadding=4><tr>
 2412: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
 2413: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
 2414: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
 2415: </tr>
 2416: <tr><td bgcolor="#DDDDDD">
 2417: $lt{'file'}:<br />
 2418: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
 2419: <input type="file" name="uploaddoc" size="40">
 2420: <br />
 2421: $lt{'title'}:<br />
 2422: <input type="text" size="50" name="comment">
 2423: $uploadtag
 2424: <input type="hidden" name="cmd" value="upload_default">
 2425: <br />
 2426: <nobr>
 2427: <label>$lt{'parse'}?
 2428: <input type="checkbox" name="parserflag" />
 2429: </label>
 2430: </nobr>
 2431: <br />
 2432: <br />
 2433: <nobr>
 2434: <input type="submit" value="$lt{'upld'}">
 2435:  $help{'Uploading_From_Harddrive'}
 2436: </nobr>
 2437: </form>
 2438: </td>
 2439: <td bgcolor="#DDDDDD">
 2440: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
 2441: $lt{'pubd'}<br />
 2442: $uploadtag
 2443: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}" />
 2444: <br />
 2445: <nobr>
 2446: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}" />
 2447: $help{'Importing_LON-CAPA_Resource'}
 2448: </nobr>
 2449: <br />
 2450: <input type=button onClick="javascript:groupopen(0,1,1);" value="$lt{'book'}" />
 2451: <p>
 2452: <hr />
 2453: $lt{'copm'}<br />
 2454: <input type="text" size="40" name="importmap"><br />
 2455: <nobr><input type=button 
 2456: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
 2457: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
 2458: $help{'Load_Map'}</nobr>
 2459: </p>
 2460: </form>
 2461: <hr />
 2462: <form action="/adm/groupsort" method="post" name="recover">
 2463: <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />
 2464: </form>
 2465: ENDFORM
 2466:        unless ($env{'form.pagepath'}) {
 2467: 	   $r->print(<<ENDFORM);
 2468: <hr />
 2469: <form action="/adm/coursedocs" method="post" name="newext">
 2470: $uploadtag
 2471: <input type=hidden name="importdetail" value="">
 2472: <nobr>
 2473: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
 2474: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
 2475: </nobr>
 2476: </form>
 2477: <br /><form action="/adm/imsimportdocs" method="post" name="ims">
 2478: <input type="hidden" name="folder" value="$folder" />
 2479: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
 2480: </nobr>
 2481: </form>
 2482: ENDFORM
 2483:        }
 2484:        $r->print('</td><td bgcolor="#DDDDDD">');
 2485:        unless ($env{'form.pagepath'}) {
 2486:            $r->print(<<ENDFORM);
 2487: <br /><form action="/adm/coursedocs" method="post" name="newfolder">
 2488: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
 2489: <input type=hidden name="importdetail" value="">
 2490: <nobr>
 2491: <input name="newfolder" type="button"
 2492: onClick="javascript:makenewfolder(this.form,'$folderseq');"
 2493: value="$lt{'newf'}" />$help{'Adding_Folders'}
 2494: </nobr>
 2495: </form>
 2496: <br /><form action="/adm/coursedocs" method="post" name="newpage">
 2497: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
 2498: <input type=hidden name="importdetail" value="">
 2499: <nobr>
 2500: <input name="newpage" type="button"
 2501: onClick="javascript:makenewpage(this.form,'$pageseq');"
 2502: value="$lt{'newp'}" />$help{'Adding_Pages'}
 2503: </nobr>
 2504: </form>
 2505: <br /><form action="/adm/coursedocs" method="post" name="newsyl">
 2506: $uploadtag
 2507: <input type=hidden name="importdetail" 
 2508: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
 2509: <nobr>
 2510: <input name="newsyl" type="submit" value="$lt{'syll'}" /> 
 2511:  $help{'Syllabus'}
 2512: </nobr>
 2513: </form>
 2514: <br /><form action="/adm/coursedocs" method="post" name="newnav">
 2515: $uploadtag
 2516: <input type=hidden name="importdetail" 
 2517: value="Navigate Content=/adm/navmaps">
 2518: <nobr>
 2519: <input name="newnav" type="submit" value="$lt{'navc'}" />
 2520: $help{'Navigate_Content'}
 2521: </nobr>
 2522: </form>
 2523: <br /><form action="/adm/coursedocs" method="post" name="newsmppg">
 2524: $uploadtag
 2525: <input type=hidden name="importdetail" value="">
 2526: <nobr>
 2527: <input name="newsmppg" type="button" value="$lt{'sipa'}"
 2528: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
 2529: </nobr>
 2530: </form>
 2531: <br /><form action="/adm/coursedocs" method="post" name="newsmpproblem">
 2532: $uploadtag
 2533: <input type=hidden name="importdetail" value="">
 2534: <nobr>
 2535: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
 2536: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
 2537: </nobr>
 2538: </form>
 2539: <br /><form action="/adm/coursedocs" method="post" name="newdropbox">
 2540: $uploadtag      
 2541: <input type=hidden name="importdetail" value="">
 2542: <nobr>          
 2543: <input name="newdropbox" type="button" value="$lt{'drbx'}"
 2544: onClick="javascript:makedropbox();" />
 2545: </nobr>         
 2546: </form> 
 2547: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
 2548: $uploadtag
 2549: <input type=hidden name="importdetail" value="">
 2550: <nobr>
 2551: <input name="newexamupload" type="button" value="$lt{'scuf'}"
 2552: onClick="javascript:makeexamupload();" />
 2553: $help{'Score_Upload_Form'}
 2554: </nobr>
 2555: </form>
 2556: <br /><form action="/adm/coursedocs" method="post" name="newbul">
 2557: $uploadtag
 2558: <input type=hidden name="importdetail" value="">
 2559: <nobr>
 2560: <input name="newbulletin" type="button" value="$lt{'bull'}"
 2561: onClick="javascript:makebulboard();" />
 2562: $help{'Bulletin Board'}
 2563: </nobr>
 2564: </form>
 2565: <br /><form action="/adm/coursedocs" method="post" name="newaboutme">
 2566: $uploadtag
 2567: <input type=hidden name="importdetail" 
 2568: value="$plainname=/adm/$udom/$uname/aboutme">
 2569: <nobr>
 2570: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
 2571: $help{'My Personal Info'}
 2572: </nobr>
 2573: </form>
 2574: <br /><form action="/adm/coursedocs" method="post" name="newaboutsomeone">
 2575: $uploadtag
 2576: <input type=hidden name="importdetail" value="">
 2577: <nobr>
 2578: <input name="newaboutsomeone" type="button" value="$lt{'abou'}" 
 2579: onClick="javascript:makeabout();" />
 2580: </nobr>
 2581: </form>
 2582: ENDFORM
 2583:        }
 2584:        if ($env{'form.pagepath'}) {
 2585:            $r->print(<<ENDBLOCK);
 2586: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
 2587: $uploadtag
 2588: <input type=hidden name="importdetail" value="">
 2589: <nobr>
 2590: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
 2591: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
 2592: </nobr>
 2593: </form>
 2594: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
 2595: $uploadtag
 2596: <input type=hidden name="importdetail" value="">
 2597: <nobr>
 2598: <input name="newexamupload" type="button" value="$lt{'scuf'}"
 2599: onClick="javascript:makeexamupload();" />
 2600: $help{'Score_Upload_Form'}
 2601: </nobr>
 2602: </form>
 2603: ENDBLOCK
 2604:        }
 2605:        $r->print('</td></tr>'."\n".
 2606: '</table>');
 2607:        $r->print('</td></tr>');
 2608:     }
 2609: # ----------------------------------------------------- Supplemental documents
 2610:     if (!$forcestandard) {
 2611:        $r->print('<tr><td bgcolor="#BBBBBB">');
 2612: # '<h2>'.&mt('Supplemental Course Documents').
 2613: #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
 2614:        my $folder=$env{'form.folder'};
 2615:        unless ($folder=~/^supplemental/) {
 2616: 	   $folder='supplemental';
 2617:        }
 2618:        if ($folder =~ /^supplemental$/ &&
 2619: 	   $env{'form.folderpath'} =~ /^default\&/) {
 2620: 	   $env{'form.folderpath'}='supplemental&'.
 2621: 	       &escape(&mt('Supplemental '.$type.' Documents'));
 2622:        }
 2623:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
 2624:        if ($allowed) {
 2625:        my $folderseq=
 2626:                   '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
 2627:                      '.sequence';
 2628: 
 2629:           $r->print(<<ENDSUPFORM);
 2630: <table cellspacing=4 cellpadding=4><tr>
 2631: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
 2632: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
 2633: </tr>
 2634: <tr><td bgcolor="#DDDDDD">
 2635: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
 2636: <input type="file" name="uploaddoc" size="40">
 2637: <br />
 2638: <br />
 2639: <nobr>
 2640: <label>$lt{'parse'}?
 2641: <input type="checkbox" name="parserflag" />
 2642: </label>
 2643: </nobr>
 2644: <br /><br />
 2645: $lt{'comment'}:<br />
 2646: <textarea cols=50 rows=4 name='comment'>
 2647: </textarea>
 2648: <br />
 2649: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
 2650: <input type="hidden" name="cmd" value="upload_supplemental">
 2651: <nobr>
 2652: <input type="submit" value="$lt{'upld'}">
 2653:  $help{'Uploading_From_Harddrive'}
 2654: </nobr>
 2655: </form>
 2656: </td>
 2657: <td bgcolor="#DDDDDD">
 2658: <form action="/adm/coursedocs" method="post" name="supnewfolder">
 2659: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
 2660: <input type=hidden name="importdetail" value="">
 2661: <nobr>
 2662: <input name="newfolder" type="button"
 2663: onClick="javascript:makenewfolder(this.form,'$folderseq');"
 2664: value="$lt{'newf'}" /> $help{'Adding_Folders'}
 2665: </nobr>
 2666: </form>
 2667: <br /><form action="/adm/coursedocs" method="post" name="supnewext">
 2668: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
 2669: <input type=hidden name="importdetail" value="">
 2670: <nobr>
 2671: <input name="newext" type="button" 
 2672: onClick="javascript:makenewext('supnewext');"
 2673: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
 2674: </nobr>
 2675: </form>
 2676: <br /><form action="/adm/coursedocs" method="post" name="supnewsyl">
 2677: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
 2678: <input type=hidden name="importdetail" 
 2679: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
 2680: <nobr>
 2681: <input name="newsyl" type="submit" value="$lt{'syll'}" />
 2682: $help{'Syllabus'}
 2683: </nobr>
 2684: </form>
 2685: <br /><form action="/adm/coursedocs" method="post" name="subnewaboutme">
 2686: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
 2687: <input type=hidden name="importdetail" 
 2688: value="$plainname=/adm/$udom/$uname/aboutme">
 2689: <nobr>
 2690: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
 2691: $help{'My Personal Info'}
 2692: </nobr>
 2693: </form>
 2694: </td></tr>
 2695: </table></td></tr>
 2696: ENDSUPFORM
 2697:        }
 2698:     }
 2699:     if ($allowed) {
 2700: 	$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>');
 2701:     }
 2702:     $r->print('</table>');
 2703:   } else {
 2704:       unless ($upload_result eq 'phasetwo') {
 2705: # -------------------------------------------------------- This is showdoc mode
 2706:           $r->print("<h1>".&mt('Uploaded Document').' - '.
 2707: 		&Apache::lonnet::gettitle($r->uri).'</h1><p>'.
 2708: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
 2709:           &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
 2710:       }
 2711:   }
 2712:  }
 2713:  $r->print(&Apache::loncommon::end_page());
 2714:  return OK;
 2715: } 
 2716: 
 2717: 
 2718: sub editing_js {
 2719:     my ($udom,$uname) = @_;
 2720:     my $now = time();
 2721: 
 2722:     return <<ENDNEWSCRIPT;
 2723: function makenewfolder(targetform,folderseq) {
 2724:     var foldername=prompt('Name of New Folder','New Folder');
 2725:     if (foldername) {
 2726:        targetform.importdetail.value=foldername+"="+folderseq;
 2727:         targetform.submit();
 2728:     }
 2729: }
 2730: 
 2731: function makenewpage(targetform,folderseq) {
 2732:     var pagename=prompt('Name of New Page','New Page');
 2733:     if (pagename) {
 2734:         targetform.importdetail.value=pagename+"="+folderseq;
 2735:         targetform.submit();
 2736:     }
 2737: }
 2738: 
 2739: function makenewext(targetname) {
 2740:     this.document.forms.extimport.useform.value=targetname;
 2741:     window.open('/adm/rat/extpickframe.html');
 2742: }
 2743: 
 2744: function makeexamupload() {
 2745:    var title=prompt('Listed Title for the Uploaded Score');
 2746:    if (title) { 
 2747:     this.document.forms.newexamupload.importdetail.value=
 2748: 	title+'=/res/lib/templates/examupload.problem';
 2749:     this.document.forms.newexamupload.submit();
 2750:    }
 2751: }
 2752: 
 2753: function makesmppage() {
 2754:    var title=prompt('Listed Title for the Page');
 2755:    if (title) { 
 2756:     this.document.forms.newsmppg.importdetail.value=
 2757: 	title+'=/adm/$udom/$uname/$now/smppg';
 2758:     this.document.forms.newsmppg.submit();
 2759:    }
 2760: }
 2761: 
 2762: function makesmpproblem() {
 2763:    var title=prompt('Listed Title for the Problem');
 2764:    if (title) { 
 2765:     this.document.forms.newsmpproblem.importdetail.value=
 2766: 	title+'=/res/lib/templates/simpleproblem.problem';
 2767:     this.document.forms.newsmpproblem.submit();
 2768:    }
 2769: }
 2770: 
 2771: function makedropbox() {
 2772:    var title=prompt('Listed Title for the Drop Box');
 2773:    if (title) { 
 2774:     this.document.forms.newdropbox.importdetail.value=
 2775:         title+'=/res/lib/templates/DropBox.problem';
 2776:     this.document.forms.newdropbox.submit();
 2777:    }
 2778: }
 2779: 
 2780: function makebulboard() {
 2781:    var title=prompt('Listed Title for the Bulletin Board');
 2782:    if (title) {
 2783:     this.document.forms.newbul.importdetail.value=
 2784: 	title+'=/adm/$udom/$uname/$now/bulletinboard';
 2785:     this.document.forms.newbul.submit();
 2786:    }
 2787: }
 2788: 
 2789: function makeabout() {
 2790:    var user=prompt("Enter user\@domain for User's 'About Me' Page");
 2791:    if (user) {
 2792:        var comp=new Array();
 2793:        comp=user.split('\@');
 2794:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
 2795: 	   if ((comp[0]) && (comp[1])) {
 2796: 	       this.document.forms.newaboutsomeone.importdetail.value=
 2797: 		   'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
 2798: 	       this.document.forms.newaboutsomeone.submit();
 2799: 	   } else {
 2800:                alert("Not a valid user\@domain");
 2801:            }
 2802:        } else {
 2803:            alert("Please enter both user and domain in the format user\@domain"); 
 2804:        }
 2805:    }
 2806: }
 2807: 
 2808: function makeims() {
 2809:     var caller = document.forms.ims.folder.value;
 2810:     var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
 2811:     newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
 2812:     newWindow.location.href = newlocation;
 2813: }
 2814: 
 2815: 
 2816: function finishpick() {
 2817:     var title=this.document.forms.extimport.title.value;
 2818:     var url=this.document.forms.extimport.url.value;
 2819:     var form=this.document.forms.extimport.useform.value;
 2820:     eval
 2821:      ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
 2822:     '";this.document.forms.'+form+'.submit();');
 2823: }
 2824: 
 2825: function changename(folderpath,index,oldtitle,container,pagesymb) {
 2826:     var title=prompt('New Title',oldtitle);
 2827:     if (title) {
 2828: 	this.document.forms.renameform.title.value=title;
 2829: 	this.document.forms.renameform.cmd.value='rename_'+index;
 2830:         if (container == 'sequence') {
 2831: 	    this.document.forms.renameform.folderpath.value=folderpath;
 2832:         }
 2833:         if (container == 'page') {
 2834:             this.document.forms.renameform.pagepath.value=folderpath;
 2835:             this.document.forms.renameform.pagesymb.value=pagesymb;
 2836:         }
 2837:         this.document.forms.renameform.submit();
 2838:     }
 2839: }
 2840: 
 2841: function removeres(folderpath,index,oldtitle,container,pagesymb) {
 2842:     if (confirm('WARNING: Removing a resource makes associated grades and scores inaccessible!\\nRemove "'+oldtitle+'"?')) {
 2843: 	this.document.forms.renameform.cmd.value='del_'+index;
 2844:         if (container == 'sequence') {
 2845:             this.document.forms.renameform.folderpath.value=folderpath;
 2846:         }
 2847:         if (container == 'page') {
 2848:             this.document.forms.renameform.pagepath.value=folderpath;
 2849:             this.document.forms.renameform.pagesymb.value=pagesymb;
 2850:         }
 2851:         this.document.forms.renameform.submit();
 2852:     }
 2853: }
 2854: 
 2855: function cutres(folderpath,index,oldtitle,container,pagesymb) {
 2856:     if (confirm('WARNING: Cutting a resource makes associated grades and scores inaccessible!\\nGrades remain inaccessible if resource is pasted into another folder.\\nCut "'+oldtitle+'"?')) {
 2857: 	this.document.forms.renameform.cmd.value='cut_'+index;
 2858: 	this.document.forms.renameform.markcopy.value=index;
 2859:         if (container == 'sequence') {
 2860:             this.document.forms.renameform.folderpath.value=folderpath;
 2861:         }
 2862:         if (container == 'page') {
 2863:             this.document.forms.renameform.pagepath.value=folderpath;
 2864:             this.document.forms.renameform.pagesymb.value=pagesymb;
 2865:         }
 2866:         this.document.forms.renameform.submit();
 2867:     }
 2868: }
 2869: 
 2870: function markcopy(folderpath,index,oldtitle,container,pagesymb) {
 2871:     this.document.forms.renameform.markcopy.value=index;
 2872:     if (container == 'sequence') {
 2873: 	this.document.forms.renameform.folderpath.value=folderpath;
 2874:     }
 2875:     if (container == 'page') {
 2876: 	this.document.forms.renameform.pagepath.value=folderpath;
 2877: 	this.document.forms.renameform.pagesymb.value=pagesymb;
 2878:     }
 2879:     this.document.forms.renameform.submit();
 2880: }
 2881: 
 2882: ENDNEWSCRIPT
 2883: }
 2884: 1;
 2885: __END__

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