File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.417: download - view: text, annotated - select for diffs
Sat Jan 30 13:06:43 2010 UTC (14 years, 4 months ago) by droeschl
Branches: MAIN
CVS tags: HEAD
- Alignment of top most line improved.

Course Editor:
- Bug #6178: icons are now clickable
- slight visual improvements
- Renamed Upload Document to Import Documents
- moved:
    o External Resource from Tools to Import Documents (on both tabs)
    o IMS Import from Tools to Import Documents

    1: # The LearningOnline Network
    2: # Documents
    3: #
    4: # $Id: londocs.pm,v 1.417 2010/01/30 13:06:43 droeschl 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: 
   30: 
   31: package Apache::londocs;
   32: 
   33: use strict;
   34: use Apache::Constants qw(:common :http);
   35: use Apache::imsexport;
   36: use Apache::lonnet;
   37: use Apache::loncommon;
   38: use Apache::lonhtmlcommon;
   39: use LONCAPA::map();
   40: use Apache::lonratedt();
   41: use Apache::lonxml;
   42: use Apache::lonclonecourse;
   43: use Apache::lonnavmaps;
   44: use HTML::Entities;
   45: use GDBM_File;
   46: use Apache::lonlocal;
   47: use Cwd;
   48: use LONCAPA qw(:DEFAULT :match);
   49: 
   50: my $iconpath;
   51: 
   52: my %hash;
   53: 
   54: my $hashtied;
   55: my %alreadyseen=();
   56: 
   57: my $hadchanges;
   58: 
   59: 
   60: my %help=();
   61: 
   62: 
   63: sub mapread {
   64:     my ($coursenum,$coursedom,$map)=@_;
   65:     return
   66:       &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
   67: 			     $map);
   68: }
   69: 
   70: sub storemap {
   71:     my ($coursenum,$coursedom,$map)=@_;
   72:     my ($outtext,$errtext)=
   73:       &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
   74: 			      $map,1);
   75:     if ($errtext) { return ($errtext,2); }
   76: 
   77:     $hadchanges=1;
   78:     return ($errtext,0);
   79: }
   80: 
   81: 
   82: 
   83: sub authorhosts {
   84:     my %outhash=();
   85:     my $home=0;
   86:     my $other=0;
   87:     foreach my $key (keys(%env)) {
   88: 	if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
   89: 	    my $role=$1;
   90: 	    my $realm=$2;
   91: 	    my ($start,$end)=split(/\./,$env{$key});
   92: 	    if (($start) && ($start>time)) { next; }
   93: 	    if (($end) && (time>$end)) { next; }
   94: 	    my ($ca,$cd);
   95: 	    if ($1 eq 'au') {
   96: 		$ca=$env{'user.name'};
   97: 		$cd=$env{'user.domain'};
   98: 	    } else {
   99: 		($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
  100: 	    }
  101: 	    my $allowed=0;
  102: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
  103: 	    my @ids=&Apache::lonnet::current_machine_ids();
  104: 	    foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
  105: 	    if ($allowed) {
  106: 		$home++;
  107: 		$outhash{'home_'.$ca.'@'.$cd}=1;
  108: 	    } else {
  109: 		$outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
  110: 		$other++;
  111: 	    }
  112: 	}
  113:     }
  114:     return ($home,$other,%outhash);
  115: }
  116: 
  117: 
  118: sub dumpbutton {
  119:     my ($home,$other,%outhash)=&authorhosts();
  120:     my $crstype = &Apache::loncommon::course_type();
  121:     if ($home+$other==0) { return ''; }
  122:     if ($home) {
  123: 	my $link = "<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"dumpcourse\", \"".&mt('Dump '.$crstype.' DOCS to Construction Space')."\")'>".&mt('Dump '.$crstype.' DOCS to Construction Space')."</a>";
  124: 	return $link.' '.
  125: 	    &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').'<br />';
  126:     } else {
  127: 	return &mt('Dump '.$crstype.
  128: 	 ' DOCS to Construction Space: available on other servers');
  129:     }
  130: }
  131: 
  132: sub clean {
  133:     my ($title)=@_;
  134:     $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
  135:     return $title;
  136: }
  137: 
  138: 
  139: 
  140: sub dumpcourse {
  141:     my ($r) = @_;
  142:     my $crstype = &Apache::loncommon::course_type();
  143:     $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' DOCS to Construction Space').
  144: 	      '<form name="dumpdoc" action="" method="post">');
  145:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' DOCS to Construction Space'));
  146:     my ($home,$other,%outhash)=&authorhosts();
  147:     unless ($home) { return ''; }
  148:     my $origcrsid=$env{'request.course.id'};
  149:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
  150:     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
  151: # Do the dumping
  152: 	unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }
  153: 	my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
  154: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
  155: 	my $title=$env{'form.authorfolder'};
  156: 	$title=&clean($title);
  157: 	my %replacehash=();
  158: 	foreach my $key (keys(%env)) {
  159: 	    if ($key=~/^form\.namefor\_(.+)/) {
  160: 		$replacehash{$1}=$env{$key};
  161: 	    }
  162: 	}
  163: 	my $crs='/uploaded/'.$env{'request.course.id'}.'/';
  164: 	$crs=~s/\_/\//g;
  165: 	foreach my $item (keys(%replacehash)) {
  166: 	    my $newfilename=$title.'/'.$replacehash{$item};
  167: 	    $newfilename=~s/\.(\w+)$//;
  168: 	    my $ext=$1;
  169: 	    $newfilename=&clean($newfilename);
  170: 	    $newfilename.='.'.$ext;
  171: 	    my @dirs=split(/\//,$newfilename);
  172: 	    my $path='/home/'.$ca.'/public_html';
  173: 	    my $makepath=$path;
  174: 	    my $fail=0;
  175: 	    for (my $i=0;$i<$#dirs;$i++) {
  176: 		$makepath.='/'.$dirs[$i];
  177: 		unless (-e $makepath) {
  178: 		    unless(mkdir($makepath,0777)) { $fail=1; }
  179: 		}
  180: 	    }
  181: 	    $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
  182: 	    if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
  183: 		if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
  184: 		    print $fh &Apache::lonclonecourse::rewritefile(
  185:          &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
  186: 				     (%replacehash,$crs => '')
  187: 								    );
  188: 		} else {
  189: 		    print $fh
  190:          &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
  191: 		       }
  192: 		$fh->close();
  193: 	    } else {
  194: 		$fail=1;
  195: 	    }
  196: 	    if ($fail) {
  197: 		$r->print('<span class="LC_error">'.&mt('fail').'</span>');
  198: 	    } else {
  199: 		$r->print('<span class="LC_success">'.&mt('ok').'</span>');
  200: 	    }
  201: 	}
  202:     } else {
  203: # Input form
  204: 	unless ($home==1) {
  205: 	    $r->print(
  206: 		      '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
  207: 	}
  208: 	foreach my $key (sort(keys(%outhash))) {
  209: 	    if ($key=~/^home_(.+)$/) {
  210: 		if ($home==1) {
  211: 		    $r->print(
  212: 		  '<input type="hidden" name="authorspace" value="'.$1.'" />');
  213: 		} else {
  214: 		    $r->print('<option value="'.$1.'">'.$1.' - '.
  215: 			      &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
  216: 		}
  217: 	    }
  218: 	}
  219: 	unless ($home==1) {
  220: 	    $r->print('</select>');
  221: 	}
  222: 	my $title=$origcrsdata{'description'};
  223: 	$title=~s/[\/\s]+/\_/gs;
  224: 	$title=&clean($title);
  225: 	$r->print('<h3>'.&mt('Folder in Construction Space').'</h3>'
  226:                  .'<input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
  227: 	&tiehash();
  228: 	$r->print('<h3>'.&mt('Filenames in Construction Space').'</h3>'
  229:                  .&Apache::loncommon::start_data_table()
  230:                  .&Apache::loncommon::start_data_table_header_row()
  231:                  .'<th>'.&mt('Internal Filename').'</th>'
  232:                  .'<th>'.&mt('Title').'</th>'
  233:                  .'<th>'.&mt('Save as ...').'</th>'
  234:                  .&Apache::loncommon::end_data_table_header_row());
  235: 	foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
  236: 	    $r->print(&Apache::loncommon::start_data_table_row()
  237:                      .'<td>'.$file.'</td>');
  238: 	    my ($ext)=($file=~/\.(\w+)$/);
  239: 	    my $title=$hash{'title_'.$hash{
  240: 		'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
  241: 	    $r->print('<td>'.($title?$title:'&nbsp;').'</td>');
  242: 	    if (!$title) {
  243: 		$title=$file;
  244: 	    } else {
  245: 		$title=~s|/|_|g;
  246: 	    }
  247: 	    $title=~s/\.(\w+)$//;
  248: 	    $title=&clean($title);
  249: 	    $title.='.'.$ext;
  250: 	    $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
  251:                      .&Apache::loncommon::end_data_table_row());
  252: 	}
  253: 	$r->print(&Apache::loncommon::end_data_table());
  254: 	&untiehash();
  255: 	$r->print(
  256:   '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype DOCS").'" /></p></form>');
  257:     }
  258: }
  259: 
  260: 
  261: 
  262: sub exportbutton {
  263:     my $crstype = &Apache::loncommon::course_type();
  264:     return "<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"exportcourse\", \"".&mt('IMS Export')."\")'>".&mt('IMS Export')."</a>".
  265:     &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'<br />';
  266: }
  267: 
  268: 
  269: 
  270: sub exportcourse {
  271:     my $r=shift;
  272:     my $crstype = &Apache::loncommon::course_type();
  273:     my %discussiontime = &Apache::lonnet::dump('discussiontimes',
  274:                                                $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
  275:     my $numdisc = keys(%discussiontime);
  276:     my $navmap = Apache::lonnavmaps::navmap->new();
  277:     if (!defined($navmap)) {
  278:         $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package').
  279:                   '<h2>'.&mt('IMS Export Failed').'</h2>'.
  280:                   '<div class="LC_error">');
  281:         if ($crstype eq 'Community') {
  282:             $r->print(&mt('Unable to retrieve information about community contents'));
  283:         } else {
  284:             $r->print(&mt('Unable to retrieve information about course contents'));
  285:         }
  286:         $r->print('</div><a href="/adm/coursedocs">');
  287:         if ($crstype eq 'Community') {
  288:             $r->print(&mt('Return to Community Editor'));
  289:         } else {
  290:             $r->print(&mt('Return to Course Editor'));
  291:         }
  292:         $r->print('</a>');
  293:         &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
  294:         return;
  295:     }
  296:     my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
  297:     my $curRes;
  298:     my $outcome;
  299: 
  300:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  301:                                             ['finishexport']);
  302:     if ($env{'form.finishexport'}) {
  303:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  304:                                             ['archive','discussion']);
  305: 
  306:         my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
  307:         my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
  308:         if (@exportitems == 0 && @discussions == 0) {
  309:             $outcome = 
  310:                 '<p class="LC_warning">'
  311:                .&mt('As you did not select any content items or discussions'
  312:                    .' for export, an IMS package has not been created.')
  313:                .'</p>'
  314:                .'<p>'
  315:                .&mt('Please [_1]go back[_2] to select either content items'
  316:                    .' or discussions for export.'
  317:                        ,'<a href="javascript:history.go(-1)">'
  318:                        ,'</a>')
  319:                .'</p>';
  320:         } else {
  321:             my $now = time;
  322:             my %symbs;
  323:             my $manifestok = 0;
  324:             my $imsresources;
  325:             my $tempexport;
  326:             my $copyresult;
  327:             my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
  328:             if ($manifestok) {
  329:                 &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
  330:                 close($ims_manifest);
  331: 
  332: #Create zip file in prtspool
  333:                 my $imszipfile = '/prtspool/'.
  334:                 $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
  335:                    time.'_'.rand(1000000000).'.zip';
  336:                 my $cwd = &Cwd::getcwd();
  337:                 my $imszip = '/home/httpd/'.$imszipfile;
  338:                 chdir $tempexport;
  339:                 open(OUTPUT, "zip -r $imszip *  2> /dev/null |");
  340:                 close(OUTPUT);
  341:                 chdir $cwd;
  342:                 $outcome .= '<p>'
  343:                            .&mt('[_1]Your IMS package[_2] is ready for download.'
  344:                                ,'<a href="'.$imszipfile.'">','</a>')
  345:                            .'</p>';
  346:                 if ($copyresult) {
  347:                     $outcome .= '<p class="LC_error">'
  348:                                .&mt('The following errors occurred during export - [_1]'
  349:                                    ,$copyresult)
  350:                                .'</p>';
  351:                 }
  352:             } else {
  353:                 $outcome = '<p class="LC_error">'
  354:                           .&mt('Unfortunately you will not be able to retrieve'
  355:                               .' an IMS archive of your course at this time,'
  356:                               .' because there was a problem creating a'
  357:                               .' manifest file.')
  358:                           .'</p>'
  359:                           .'<p><a href="javascript:history.go(-1)">'
  360:                           .&mt('Go Back')
  361:                           .'</a></p>';
  362:             }
  363:         }
  364:         $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package'));
  365: 	$r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));
  366:         $r->print($outcome);
  367:         $r->print(&Apache::loncommon::end_page());
  368:     } else {
  369:         my $display='<form name="exportdoc" action="" method="post">'."\n".
  370:                     '<p>'.
  371:                     &mt('Choose which items you wish to export from your '.$crstype.'.').
  372:                     '</p>'.
  373:                     '<div class="LC_columnSection"><fieldset>'.
  374:                     '<legend>'.&mt('Content items').'</legend>'.
  375:                     '<input type="button" value="'.&mt('check all').'" '.
  376:                     'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
  377:                     '&nbsp;&nbsp;<input type="button" value="'.&mt('uncheck all').'"'.
  378:                     ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset>';
  379:         if ($numdisc > 0) {
  380:             $display .= '<fieldset>'.
  381:                         '<legend>'.&mt('Discussion posts').'</legend>'.
  382:                         '<input type="button" value="'.&mt('check all').'"'.
  383:                         ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
  384:                         '&nbsp;&nbsp;<input type="button" value="'.&mt('uncheck all').'"'.
  385:                         ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" />'.
  386:                         '</fieldset>';
  387:         }
  388:         $display .= '</div>';
  389:         my $curRes;
  390:         my $depth = 0;
  391:         my $count = 0;
  392:         my $boards = 0;
  393:         my $startcount = 5;
  394:         my %parent = ();
  395:         my %children = ();
  396:         my $lastcontainer = $startcount;
  397:         $display .= &Apache::loncommon::start_data_table()
  398:                    .&Apache::loncommon::start_data_table_header_row()
  399:                    .'<th>'.&mt('Export content item?').'</th>';
  400:         if ($numdisc > 0) {
  401:             $display .= '<th>'.&mt('Export discussion posts?').'</th>';
  402:         }
  403:         $display .= &Apache::loncommon::end_data_table_header_row();
  404:         while ($curRes = $it->next()) {
  405:             if (ref($curRes)) {
  406:                 $count ++;
  407:             }
  408:             if ($curRes == $it->BEGIN_MAP()) {
  409:                 $depth++;
  410:                 $parent{$depth} = $lastcontainer;
  411:             }
  412:             if ($curRes == $it->END_MAP()) {
  413:                 $depth--;
  414:                 $lastcontainer = $parent{$depth};
  415:             }
  416:             if (ref($curRes)) {
  417:                 my $symb = $curRes->symb();
  418:                 my $ressymb = $symb;
  419:                 if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
  420:                     unless ($ressymb =~ m|adm/wrapper/adm|) {
  421:                         $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
  422:                     }
  423:                 }
  424:                 my $currelem = $count+$boards+$startcount;
  425:                 $display .= &Apache::loncommon::start_data_table_row()
  426:                            .'<td>'."\n"
  427:                            .'<input type="checkbox" name="archive" value="'.$count.'" ';
  428:                 if (($curRes->is_sequence()) || ($curRes->is_page())) {
  429:                     $lastcontainer = $currelem;
  430:                     $display .= 'onclick="javascript:propagateCheck('."'$currelem'".')"';
  431:                 }
  432:                 $display .= ' />'."\n";
  433:                 for (my $i=0; $i<$depth; $i++) {
  434:                     $display .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
  435:                 }
  436:                 if ($curRes->is_sequence()) {
  437:                     $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />&nbsp;'."\n";
  438:                 } elsif ($curRes->is_page()) {
  439:                     $display .= '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" />&nbsp;'."\n";
  440:                 }
  441:                 $children{$parent{$depth}} .= $currelem.':';
  442:                 $display .= '&nbsp;'.$curRes->title().'</td>'."\n";
  443: 
  444:                 # Existing discussion posts?
  445:                 if ($discussiontime{$ressymb} > 0) {
  446:                     $boards ++;
  447:                     $display .= '<td align="right">'
  448:                                .'<input type="checkbox" name="discussion" value="'.$count.'" />'
  449:                                .'</td>'."\n";
  450:                 } elsif ($numdisc > 0) {
  451:                     $display .= '<td>&nbsp;</td>'."\n";
  452:                 }
  453:                 $display .= &Apache::loncommon::end_data_table_row();
  454:             }
  455:         }
  456:         $display .= &Apache::loncommon::end_data_table();
  457:         my $scripttag = qq|
  458: <script type="text/javascript">
  459: // <![CDATA[
  460: function checkAll(field) {
  461:     if (field.length > 0) {
  462:         for (i = 0; i < field.length; i++) {
  463:             field[i].checked = true ;
  464:         }
  465:     } else {
  466:         field.checked = true
  467:     }
  468: }
  469: 
  470: function uncheckAll(field) {
  471:     if (field.length > 0) {
  472:         for (i = 0; i < field.length; i++) {
  473:             field[i].checked = false ;
  474:         }
  475:     } else {
  476:         field.checked = false ;
  477:     }
  478: }
  479: 
  480: function propagateCheck(item) {
  481:     if (document.exportdoc.elements[item].checked == true) {
  482:         containerCheck(item)
  483:     }
  484: }
  485: 
  486: function containerCheck(item) {
  487:     document.exportdoc.elements[item].checked = true
  488:     var numitems = $count + $boards + $startcount
  489:     var parents = new Array(numitems)
  490:     for (var i=$startcount; i<numitems; i++) {
  491:         parents[i] = new Array
  492:     }
  493:         |;
  494: 
  495:         foreach my $container (sort { $a <=> $b } (keys(%children))) {
  496:             my @contents = split(/:/,$children{$container});
  497:             for (my $i=0; $i<@contents; $i ++) {
  498:                 $scripttag .= '    parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
  499:             }
  500:         }
  501: 
  502:         $scripttag .= qq|
  503:     if (parents[item].length > 0) {
  504:         for (var j=0; j<parents[item].length; j++) {
  505:             containerCheck(parents[item][j])
  506:         }
  507:      }
  508: }
  509: // ]]>
  510: </script>
  511:         |;
  512: 	$r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package',
  513: 						 $scripttag));
  514: 	$r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));
  515: 	$r->print($display.
  516:                   '<p><input type="hidden" name="finishexport" value="1" />'.
  517:                   '<input type="submit" name="exportcourse" value="'.
  518:                   &mt('Export').'" /></p></form>');
  519:     }
  520: }
  521: 
  522: sub create_ims_store {
  523:     my ($now,$manifestok,$outcome,$tempexport) = @_;
  524:     $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
  525:     my $ims_manifest;
  526:     if (!-e $$tempexport) {
  527:         mkdir($$tempexport,0700);
  528:     }
  529:     $$tempexport .= '/'.$now;
  530:     if (!-e $$tempexport) {
  531:         mkdir($$tempexport,0700);
  532:     }
  533:     $$tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
  534:     if (!-e $$tempexport) {
  535:         mkdir($$tempexport,0700);
  536:     }
  537:     if (!-e "$$tempexport/resources") {
  538:         mkdir("$$tempexport/resources",0700);
  539:     }
  540: # open manifest file
  541:     my $manifest = '/imsmanifest.xml';
  542:     my $manifestfilename = $$tempexport.$manifest;
  543:     if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
  544:         $$manifestok=1;
  545:         print $ims_manifest
  546: '<?xml version="1.0" encoding="UTF-8"?>'."\n".
  547: '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
  548: ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
  549: ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
  550: ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'.
  551: '  xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
  552: '  http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
  553: '  <metadata>
  554:     <schema></schema>
  555:     <imsmd:lom>
  556:       <imsmd:general>
  557:         <imsmd:identifier>'.$env{'request.course.id'}.'</imsmd:identifier>
  558:         <imsmd:title>
  559:           <imsmd:langstring xml:lang="en">'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</imsmd:langstring>
  560:         </imsmd:title>
  561:       </imsmd:general>
  562:     </imsmd:lom>
  563:   </metadata>'."\n".
  564: '  <organizations default="ORG-'.$env{'request.course.id'}.'-'.$now.'">'."\n".
  565: '    <organization identifier="ORG-'.$env{'request.course.id'}.'-'.$now.'"'.
  566: ' structure="hierarchical">'."\n".
  567: '      <title>'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</title>'
  568:     } else {
  569:         $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
  570: ;
  571:     }
  572:     return $ims_manifest;
  573: }
  574: 
  575: sub build_package {
  576:     my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
  577: # first iterator to look for dependencies
  578:     my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
  579:     my $curRes;
  580:     my $count = 0;
  581:     my $depth = 0;
  582:     my $lastcontainer = 0;
  583:     my %parent = ();
  584:     my @dependencies = ();
  585:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  586:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  587:     while ($curRes = $it->next()) {
  588:         if (ref($curRes)) {
  589:             $count ++;
  590:         }
  591:         if ($curRes == $it->BEGIN_MAP()) {
  592:             $depth++;
  593:             $parent{$depth} = $lastcontainer;
  594:         }
  595:         if ($curRes == $it->END_MAP()) {
  596:             $depth--;
  597:             $lastcontainer = $parent{$depth};
  598:         }
  599:         if (ref($curRes)) {
  600:             if ($curRes->is_sequence() || $curRes->is_page()) {
  601:                 $lastcontainer = $count;
  602:             }
  603:             if (grep(/^$count$/,@$exportitems)) {
  604:                 &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
  605:             }
  606:         }
  607:     }
  608: # second iterator to build manifest and store resources
  609:     $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
  610:     $depth = 0;
  611:     my $prevdepth;
  612:     $count = 0;
  613:     my $imsresources;
  614:     my $pkgdepth;
  615:     while ($curRes = $it->next()) {
  616:         if ($curRes == $it->BEGIN_MAP()) {
  617:             $prevdepth = $depth;
  618:             $depth++;
  619:         }
  620:         if ($curRes == $it->END_MAP()) {
  621:             $prevdepth = $depth;
  622:             $depth--;
  623:         }
  624: 
  625:         if (ref($curRes)) {
  626:             $count ++;
  627:             if ((grep(/^$count$/,@$exportitems)) || (grep(/^$count$/,@dependencies))) {
  628:                 my $symb = $curRes->symb();
  629:                 my $isvisible = 'true';
  630:                 my $resourceref;
  631:                 if ($curRes->randomout()) {
  632:                     $isvisible = 'false';
  633:                 }
  634:                 unless ($curRes->is_sequence()) {
  635:                     $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"';
  636:                 }
  637:                 my $step = $prevdepth - $depth;
  638:                 if (($step >= 0) && ($count > 1)) {
  639:                     while ($step >= 0) {
  640:                         print $ims_manifest "\n".'  </item>'."\n";
  641:                         $step --;
  642:                     }
  643:                 }
  644:                 $prevdepth = $depth;
  645: 
  646:                 my $itementry =
  647:               '<item identifier="ITEM-'.$env{'request.course.id'}.'-'.$count.
  648:               '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
  649:               '<title>'.$curRes->title().'</title>';
  650:                 print $ims_manifest "\n".$itementry;
  651: 
  652:                 unless ($curRes->is_sequence()) {
  653:                     my $content_file;
  654:                     my @hrefs = ();
  655:                     &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
  656:                     if ($content_file) {
  657:                         $imsresources .= "\n".
  658:                      '   <resource identifier="RES-'.$env{'request.course.id'}.'-'.$count.
  659:                      '" type="webcontent" href="'.$content_file.'">'."\n".
  660:                      '       <file href="'.$content_file.'" />'."\n";
  661:                         foreach my $item (@hrefs) {
  662:                             $imsresources .=
  663:                      '        <file href="'.$item.'" />'."\n";
  664:                         }
  665:                         if (grep(/^$count$/,@$discussions)) {
  666:                             my $ressymb = $symb;
  667:                             my $mode;
  668:                             if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
  669:                                 unless ($ressymb =~ m|adm/wrapper/adm|) {
  670:                                     $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
  671:                                 }
  672:                                 $mode = 'board';
  673:                             }
  674:                             my %extras = (
  675:                                           caller => 'imsexport',
  676:                                           tempexport => $tempexport.'/resources',
  677:                                           count => $count
  678:                                          );
  679:                             my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
  680:                         }
  681:                         $imsresources .= '    </resource>'."\n";
  682:                     }
  683:                 }
  684:                 $pkgdepth = $depth;
  685:             }
  686:         }
  687:     }
  688:     while ($pkgdepth > 0) {
  689:         print $ims_manifest "    </item>\n";
  690:         $pkgdepth --;
  691:     }
  692:     my $resource_text = qq|
  693:     </organization>
  694:   </organizations>
  695:   <resources>
  696:     $imsresources
  697:   </resources>
  698: </manifest>
  699:     |;
  700:     print $ims_manifest $resource_text;
  701: }
  702: 
  703: sub get_dependencies {
  704:     my ($exportitems,$parent,$depth,$dependencies) = @_;
  705:     if ($depth > 1) {
  706:         if ((!grep(/^$$parent{$depth}$/,@$exportitems)) && (!grep(/^$$parent{$depth}$/,@$dependencies))) {
  707:             push(@{$dependencies},$$parent{$depth});
  708:             if ($depth > 2) {
  709:                 &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
  710:             }
  711:         }
  712:     }
  713: }
  714: 
  715: sub process_content {
  716:     my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
  717:     my $content_type;
  718:     my $message;
  719:     my @uploads = ();
  720:     if ($curRes->is_sequence()) {
  721:         $content_type = 'sequence';
  722:     } elsif ($curRes->is_page()) {
  723:         $content_type = 'page'; # need to handle individual items in pages.
  724:     } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
  725:         $content_type = 'syllabus';
  726:         my $contents = &Apache::imsexport::templatedpage($content_type);
  727:         if ($contents) {
  728:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
  729:         }
  730:     } elsif ($symb =~ m-\.sequence___\d+___ext-) {
  731:         $content_type = 'external';
  732:         my $title = $curRes->title;
  733:         my $contents =  &Apache::imsexport::external($symb,$title);
  734:         if ($contents) {
  735:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
  736:         }
  737:     } elsif ($symb =~ m-adm/navmaps$-) {
  738:         $content_type =  'navmap';
  739:     } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
  740:         $content_type = 'simplepage';
  741:         my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);
  742:         if ($contents) {
  743:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
  744:         }
  745:     } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {
  746:         $content_type = 'simpleproblem';
  747:         my $contents =  &Apache::imsexport::simpleproblem($symb);
  748:         if ($contents) {
  749:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
  750:         }
  751:     } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {
  752:         $content_type = 'examupload';
  753:     } elsif ($symb =~ m-adm/($match_domain)/($match_username)/(\d+)/bulletinboard$-) {
  754:         $content_type = 'bulletinboard';
  755:         my $contents =  &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);
  756:         if ($contents) {
  757:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
  758:         }
  759:     } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {
  760:         $content_type = 'aboutme';
  761:         my $contents =  &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);
  762:         if ($contents) {
  763:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
  764:         }
  765:     } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
  766:         $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
  767:     } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
  768:         my $canedit = 0;
  769:         if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'})  {
  770:             $canedit= 1;
  771:         }
  772: # only include problem code where current user is author
  773:         if ($canedit) {
  774:             $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
  775:         } else {
  776:             $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
  777:         }
  778:     } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
  779:         $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
  780:     }
  781:     if (@uploads > 0) {
  782:         foreach my $item (@uploads) {
  783:             my $uploadmsg = '';
  784:             &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
  785:             if ($uploadmsg) {
  786:                 $$copyresult .= $uploadmsg."\n";
  787:             }
  788:         }
  789:     }
  790:     if ($message) {
  791:         $$copyresult .= $message."\n";
  792:     }
  793: }
  794: 
  795: sub replicate_content {
  796:     my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
  797:     my ($map,$ind,$url);
  798:     if ($caller eq 'templateupload') {
  799:         $url = $symb;
  800:         $url =~ s#//#/#g;
  801:     } else {
  802:         ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
  803:     }
  804:     my $content;
  805:     my $filename;
  806:     my $repstatus;
  807:     my $content_name;
  808:     if ($url =~ m-/([^/]+)$-) {
  809:         $filename = $1;
  810:         if (!-e $tempexport.'/resources') {
  811:             mkdir($tempexport.'/resources',0700);
  812:         }
  813:         if (!-e $tempexport.'/resources/'.$count) {
  814:             mkdir($tempexport.'/resources/'.$count,0700);
  815:         }
  816:         my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
  817:         my $copiedfile;
  818:         if ($copiedfile = Apache::File->new('>'.$destination)) {
  819:             my $content;
  820:             if ($caller eq 'resource') {
  821:                 my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
  822:                 my $filepath = &Apache::lonnet::filelocation($respath,$url);
  823:                 $content = &Apache::lonnet::getfile($filepath);
  824:                 if ($content eq -1) {
  825:                     $$message = 'Could not copy file '.$filename;
  826:                 } else {
  827:                     &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');
  828:                     $repstatus = 'ok';
  829:                 }
  830:             } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
  831:                 my $rtncode;
  832:                 $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
  833:                 if ($repstatus eq 'ok') {
  834:                     if ($url =~ /\.html?$/i) {
  835:                         &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');
  836:                     }
  837:                 } else {
  838:                     $$message = 'Could not render '.$url.' server message - '.$rtncode."<br />\n";
  839:                 }
  840:             } elsif ($caller eq 'noedit') {
  841: # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
  842:                 $repstatus = 'ok';
  843:                 $content = 'Not the owner of this resource';
  844:             }
  845:             if ($repstatus eq 'ok') {
  846:                 print $copiedfile $content;
  847:             }
  848:             close($copiedfile);
  849:         } else {
  850:             $$message = 'Could not open destination file for '.$filename."<br />\n";
  851:         }
  852:     } else {
  853:         $$message = 'Could not determine name of file for '.$symb."<br />\n";
  854:     }
  855:     if ($repstatus eq 'ok') {
  856:         $content_name = 'resources/'.$count.'/'.$filename;
  857:     }
  858:     return $content_name;
  859: }
  860: 
  861: sub extract_media {
  862:     my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
  863:     my ($dirpath,$container);
  864:     my %allfiles = ();
  865:     my %codebase = ();
  866:     if ($url =~ m-(.*/)([^/]+)$-) {
  867:         $dirpath = $1;
  868:         $container = $2;
  869:     } else {
  870:         $dirpath = $url;
  871:         $container = '';
  872:     }
  873:     &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,$content);
  874:     foreach my $embed_file (keys(%allfiles)) {
  875:         my $filename;
  876:         if ($embed_file =~ m#([^/]+)$#) {
  877:             $filename = $1;
  878:         } else {
  879:             $filename = $embed_file;
  880:         }
  881:         my $newname = 'res/'.$filename;
  882:         my ($rtncode,$embed_content,$repstatus);
  883:         my $embed_url;
  884:         if ($embed_file =~ m-^/-) {
  885:             $embed_url = $embed_file;           # points to absolute path
  886:         } else {
  887:             if ($embed_file =~ m-https?://-) {
  888:                 next;                           # points to url
  889:             } else {
  890:                 $embed_url = $dirpath.$embed_file;  # points to relative path
  891:             }
  892:         }
  893:         if ($caller eq 'resource') {
  894:             my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
  895:             my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
  896:             $embed_content = &Apache::lonnet::getfile($embed_path);
  897:             unless ($embed_content eq -1) {
  898:                 $repstatus = 'ok';
  899:             }
  900:         } elsif ($caller eq 'uploaded') {
  901: 
  902:             $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
  903:         }
  904:         if ($repstatus eq 'ok') {
  905:             my $destination = $tempexport.'/resources/'.$count.'/res';
  906:             if (!-e "$destination") {
  907:                 mkdir($destination,0755);
  908:             }
  909:             $destination .= '/'.$filename;
  910:             my $copiedfile;
  911:             if ($copiedfile = Apache::File->new('>'.$destination)) {
  912:                 print $copiedfile $embed_content;
  913:                 push(@{$href},'resources/'.$count.'/res/'.$filename);
  914:                 my $attrib_regexp = '';
  915:                 if (@{$allfiles{$embed_file}} > 1) {
  916:                     $attrib_regexp = join('|',@{$allfiles{$embed_file}});
  917:                 } else {
  918:                     $attrib_regexp = $allfiles{$embed_file}[0];
  919:                 }
  920:                 $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
  921:                 if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {
  922:                     $$content =~ s#\Q$embed_file\E#$newname#gi;
  923:                 }
  924:             }
  925:         } else {
  926:             $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";
  927:         }
  928:     }
  929:     return;
  930: }
  931: 
  932: sub store_template {
  933:     my ($contents,$tempexport,$count,$content_type) = @_;
  934:     if ($contents) {
  935:         if ($tempexport) {
  936:             if (!-e $tempexport.'/resources') {
  937:                 mkdir($tempexport.'/resources',0700);
  938:             }
  939:             if (!-e $tempexport.'/resources/'.$count) {
  940:                 mkdir($tempexport.'/resources/'.$count,0700);
  941:             }
  942:             my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
  943:             my $storetemplate;
  944:             if ($storetemplate = Apache::File->new('>'.$destination)) {
  945:                 print $storetemplate $contents;
  946:                 close($storetemplate);
  947:             }
  948:             if ($content_type eq 'external') {
  949:                 return 'resources/'.$count.'/'.$content_type.'.html';
  950:             } else {
  951:                 return 'resources/'.$count.'/'.$content_type.'.xml';
  952:             }
  953:         }
  954:     }
  955: }
  956: 
  957: 
  958: sub group_import {
  959:     my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
  960: 
  961:     while (@files) {
  962: 	my ($name, $url, $residx) = @{ shift(@files) };
  963:         if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
  964: 	     && ($caller eq 'londocs')
  965: 	     && (!&Apache::lonnet::stat_file($url))) {
  966: 
  967:             my $errtext = '';
  968:             my $fatal = 0;
  969:             my $newmapstr = '<map>'."\n".
  970:                             '<resource id="1" src="" type="start"></resource>'."\n".
  971:                             '<link from="1" to="2" index="1"></link>'."\n".
  972:                             '<resource id="2" src="" type="finish"></resource>'."\n".
  973:                             '</map>';
  974:             $env{'form.output'}=$newmapstr;
  975:             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
  976:                                                 'output',$1.$2);
  977:             if ($result != m|^/uploaded/|) {
  978:                 $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
  979:                 $fatal = 2;
  980:             }
  981:             if ($fatal) {
  982:                 return ($errtext,$fatal);
  983:             }
  984:         }
  985: 	if ($url) {
  986: 	    if (!$residx
  987: 		|| defined($LONCAPA::map::zombies[$residx])) {
  988: 		$residx = &LONCAPA::map::getresidx($url,$residx);
  989: 		push(@LONCAPA::map::order, $residx);
  990: 	    }
  991: 	    my $ext = 'false';
  992: 	    if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
  993: 	    $url  = &LONCAPA::map::qtunescape($url);
  994: 	    $name = &LONCAPA::map::qtunescape($name);
  995: 	    $LONCAPA::map::resources[$residx] =
  996: 		join(':', ($name, $url, $ext, 'normal', 'res'));
  997: 	}
  998:     }
  999:     return &storemap($coursenum, $coursedom, $folder.'.'.$container);
 1000: }
 1001: 
 1002: sub breadcrumbs {
 1003:     my ($allowed,$crstype)=@_;
 1004:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 1005:     my (@folders);
 1006:     if ($env{'form.pagepath'}) {
 1007:         @folders = split('&',$env{'form.pagepath'});
 1008:     } else {
 1009:         @folders=split('&',$env{'form.folderpath'});
 1010:     }
 1011:     my $folderpath;
 1012:     my $cpinfo='';
 1013:     my $plain='';
 1014:     my $randompick=-1;
 1015:     my $isencrypted=0;
 1016:     my $ishidden=0;
 1017:     my $is_random_order=0;
 1018:     if (!$allowed) {
 1019:         my $description = $env{'course.'.$env{'request.course.id'}.'.description'};
 1020:         &Apache::lonhtmlcommon::add_breadcrumb(
 1021:                                                {'href' => '/adm/menu',
 1022:                                                 'title'=> 'Go to main menu',
 1023:                                                 'text' => $description,
 1024:                                                });
 1025:         $plain .= $description.' &gt;';
 1026:     }
 1027:     while (@folders) {
 1028: 	my $folder=shift(@folders);
 1029:     	my $foldername=shift(@folders);
 1030: 	if ($folderpath) {$folderpath.='&';}
 1031: 	$folderpath.=$folder.'&'.$foldername;
 1032: 	my $url='/adm/coursedocs?folderpath='.
 1033: 	    &escape($folderpath);
 1034: 	    my $name=&unescape($foldername);
 1035: # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
 1036:  	    $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
 1037: 	    if ($1 ne '') {
 1038:                $randompick=$1;
 1039:             } else {
 1040:                $randompick=-1;
 1041:             }
 1042:             if ($2) { $ishidden=1; }
 1043:             if ($3) { $isencrypted=1; }
 1044: 	    if ($4 ne '') { $is_random_order = 1; }
 1045:             if ($folder eq 'supplemental') {
 1046:                 $name = &mt('Supplemental '.$crstype.' Documents');
 1047:             }
 1048: 	    &Apache::lonhtmlcommon::add_breadcrumb(
 1049: 		      {'href'=>$url.$cpinfo,
 1050: 		       'title'=>$name,
 1051: 		       'text'=>$name,
 1052: 		       'no_mt'=>1,
 1053: 		       });
 1054: 	$plain.=$name.' &gt; ';
 1055:     }
 1056:     $plain=~s/\&gt\;\s*$//;
 1057:     return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
 1058: 					       undef, undef, 1 ),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
 1059: }
 1060: 
 1061: sub log_docs {
 1062:     return &Apache::lonnet::instructor_log('docslog',@_);
 1063: }
 1064: 
 1065: {
 1066:     my @oldresources=();
 1067:     my @oldorder=();
 1068:     my $parmidx;
 1069:     my %parmaction=();
 1070:     my %parmvalue=();
 1071:     my $changedflag;
 1072: 
 1073:     sub snapshotbefore {
 1074:         @oldresources=@LONCAPA::map::resources;
 1075:         @oldorder=@LONCAPA::map::order;
 1076:         $parmidx=undef;
 1077:         %parmaction=();
 1078:         %parmvalue=();
 1079:         $changedflag=0;
 1080:     }
 1081: 
 1082:     sub remember_parms {
 1083:         my ($idx,$parameter,$action,$value)=@_;
 1084:         $parmidx=$idx;
 1085:         $parmaction{$parameter}=$action;
 1086:         $parmvalue{$parameter}=$value;
 1087:         $changedflag=1;
 1088:     }
 1089: 
 1090:     sub log_differences {
 1091:         my ($plain)=@_;
 1092:         my %storehash=('folder' => $plain,
 1093:                        'currentfolder' => $env{'form.folder'});
 1094:         if ($parmidx) {
 1095:            $storehash{'parameter_res'}=$oldresources[$parmidx];
 1096:            foreach my $parm (keys(%parmaction)) {
 1097:               $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
 1098:               $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
 1099:            }
 1100:         }
 1101:         my $maxidx=$#oldresources;
 1102:         if ($#LONCAPA::map::resources>$#oldresources) {
 1103:            $maxidx=$#LONCAPA::map::resources;
 1104:         }
 1105:         for (my $idx=0; $idx<=$maxidx; $idx++) {
 1106:            if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
 1107:               $storehash{'before_resources_'.$idx}=$oldresources[$idx];
 1108:               $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
 1109:               $changedflag=1;
 1110:            }
 1111:            if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
 1112:               $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
 1113:               $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
 1114:               $changedflag=1;
 1115:            }
 1116:         }
 1117: 	$storehash{'maxidx'}=$maxidx;
 1118:         if ($changedflag) { &log_docs(\%storehash); }
 1119:     }
 1120: }
 1121: 
 1122: 
 1123: 
 1124: 
 1125: 
 1126: sub docs_change_log {
 1127:     my ($r)=@_;
 1128:     my $folder=$env{'form.folder'};
 1129:     $r->print(&Apache::loncommon::start_page('Course Document Change Log'));
 1130:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));
 1131:     my %docslog=&Apache::lonnet::dump('nohist_docslog',
 1132:                                       $env{'course.'.$env{'request.course.id'}.'.domain'},
 1133:                                       $env{'course.'.$env{'request.course.id'}.'.num'});
 1134: 
 1135:     if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
 1136: 
 1137:     $r->print('<form action="/adm/coursedocs" method="post" name="docslog">'.
 1138:               '<input type="hidden" name="docslog" value="1" />');
 1139: 
 1140:     my %saveable_parameters = ('show' => 'scalar',);
 1141:     &Apache::loncommon::store_course_settings('docs_log',
 1142:                                               \%saveable_parameters);
 1143:     &Apache::loncommon::restore_course_settings('docs_log',
 1144:                                                 \%saveable_parameters);
 1145:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
 1146:     my %lt=('hiddenresource' => 'Resources hidden',
 1147: 	    'encrypturl'     => 'URL hidden',
 1148: 	    'randompick'     => 'Randomly pick',
 1149: 	    'randomorder'    => 'Randomly ordered',
 1150: 	    'set'            => 'set to',
 1151: 	    'del'            => 'deleted');
 1152:     $r->print(&Apache::loncommon::display_filter().
 1153:               '<input type="hidden" name="folder" value="'.$folder.'" />'.
 1154:               '<input type="submit" value="'.&mt('Display').'" /></form>');
 1155:     $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
 1156:               '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
 1157:               &mt('After').'</th>'.
 1158:               &Apache::loncommon::end_data_table_header_row());
 1159:     my $shown=0;
 1160:     foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
 1161: 	if ($env{'form.displayfilter'} eq 'currentfolder') {
 1162: 	    if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
 1163: 	}
 1164:         my @changes=keys(%{$docslog{$id}{'logentry'}});
 1165:         if ($env{'form.displayfilter'} eq 'containing') {
 1166: 	    my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
 1167: 		&Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
 1168: 	    foreach my $key (@changes) {
 1169: 		$wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
 1170: 	    }
 1171: 	    if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
 1172: 	}
 1173:         my $count = 0;
 1174:         my $time =
 1175:             &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
 1176:         my $plainname =
 1177:             &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
 1178:                                           $docslog{$id}{'exe_udom'});
 1179:         my $about_me_link =
 1180:             &Apache::loncommon::aboutmewrapper($plainname,
 1181:                                                $docslog{$id}{'exe_uname'},
 1182:                                                $docslog{$id}{'exe_udom'});
 1183:         my $send_msg_link='';
 1184:         if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
 1185:              || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
 1186:             $send_msg_link ='<br />'.
 1187:                 &Apache::loncommon::messagewrapper(&mt('Send message'),
 1188:                                                    $docslog{$id}{'exe_uname'},
 1189:                                                    $docslog{$id}{'exe_udom'});
 1190:         }
 1191:         $r->print(&Apache::loncommon::start_data_table_row());
 1192:         $r->print('<td>'.$time.'</td>
 1193:                        <td>'.$about_me_link.
 1194:                   '<br /><tt>'.$docslog{$id}{'exe_uname'}.
 1195:                                   ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
 1196:                   $send_msg_link.'</td><td>'.
 1197:                   $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
 1198: # Before
 1199: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
 1200: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
 1201: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
 1202: 	    if ($oldname ne $newname) {
 1203: 		$r->print(&LONCAPA::map::qtescape($oldname));
 1204: 	    }
 1205: 	}
 1206: 	$r->print('<ul>');
 1207: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
 1208:             if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
 1209: 		$r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');
 1210: 	    }
 1211: 	}
 1212: 	$r->print('</ul>');
 1213: # After
 1214:         $r->print('</td><td>');
 1215: 
 1216: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
 1217: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
 1218: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
 1219: 	    if ($oldname ne '' && $oldname ne $newname) {
 1220: 		$r->print(&LONCAPA::map::qtescape($newname));
 1221: 	    }
 1222: 	}
 1223: 	$r->print('<ul>');
 1224: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
 1225:             if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
 1226: 		$r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');
 1227: 	    }
 1228: 	}
 1229: 	$r->print('</ul>');
 1230: 	if ($docslog{$id}{'logentry'}{'parameter_res'}) {
 1231: 	    $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
 1232: 	    foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
 1233: 		if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
 1234: 		    $r->print('<li>'.
 1235: 			      &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
 1236: 				  $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
 1237: 			      .'</li>');
 1238: 		}
 1239: 	    }
 1240: 	    $r->print('</ul>');
 1241: 	}
 1242: # End
 1243:         $r->print('</td>'.&Apache::loncommon::end_data_table_row());
 1244:         $shown++;
 1245:         if (!($env{'form.show'} eq &mt('all')
 1246:               || $shown<=$env{'form.show'})) { last; }
 1247:     }
 1248:     $r->print(&Apache::loncommon::end_data_table());
 1249: }
 1250: 
 1251: sub update_paste_buffer {
 1252:     my ($coursenum,$coursedom) = @_;
 1253: 
 1254:     return if (!defined($env{'form.markcopy'}));
 1255:     return if (!defined($env{'form.copyfolder'}));
 1256:     return if ($env{'form.markcopy'} < 0);
 1257: 
 1258:     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
 1259: 				    $env{'form.copyfolder'});
 1260: 
 1261:     return if ($fatal);
 1262: 
 1263: # Mark for copying
 1264:     my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
 1265:     if (&is_supplemental_title($title)) {
 1266:         &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
 1267: 	($title) = &parse_supplemental_title($title);
 1268:     } elsif ($env{'docs.markedcopy_supplemental'}) {
 1269:         &Apache::lonnet::delenv('docs.markedcopy_supplemental');
 1270:     }
 1271:     $url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
 1272: 
 1273:     &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,
 1274: 			    'docs.markedcopy_url'   => $url});
 1275:     delete($env{'form.markcopy'});
 1276: }
 1277: 
 1278: sub print_paste_buffer {
 1279:     my ($r,$container) = @_;
 1280:     return if (!defined($env{'docs.markedcopy_url'}));
 1281: 
 1282:     $r->print('<fieldset>'
 1283:              .'<legend>'.&mt('Clipboard').'</legend>'
 1284:              .'<form name="pasteform" action="/adm/coursedocs" method="post">'
 1285:              .'<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> '
 1286:     );
 1287: 
 1288:     my $type;
 1289:     if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
 1290: 	$type = &mt('External Resource');
 1291: 	$r->print($type.': '.
 1292: 		  &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
 1293: 		  &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
 1294:     }  else {
 1295: 	my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
 1296: 	my $icon = &Apache::loncommon::icon($extension);
 1297: 	if ($extension eq 'sequence' &&
 1298: 	    $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
 1299: 	    $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
 1300: 	    $icon .= '/navmap.folder.closed.gif';
 1301: 	}
 1302: 	$icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
 1303: 	$r->print($icon.$type.': '.  &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
 1304:     }
 1305:     if ($container eq 'page') {
 1306: 	$r->print('
 1307: 	<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />
 1308: 	<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />
 1309: ');
 1310:     } else {
 1311: 	$r->print('
 1312:         <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
 1313: ');
 1314:     }
 1315:     $r->print('</form></fieldset>');
 1316: }
 1317: 
 1318: sub do_paste_from_buffer {
 1319:     my ($coursenum,$coursedom,$folder) = @_;
 1320: 
 1321:     if (!$env{'form.pastemarked'}) {
 1322:         return;
 1323:     }
 1324: 
 1325: # paste resource to end of list
 1326:     my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
 1327:     my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
 1328: # Maps need to be copied first
 1329:     if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
 1330: 	$title=&mt('Copy of').' '.$title;
 1331: 	my $newid=$$.int(rand(100)).time;
 1332: 	my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
 1333:         if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
 1334:             my $path = $1;
 1335:             my $prefix = $2;
 1336:             my $ancestor = $3;
 1337:             if (length($ancestor) > 10) {
 1338:                 $ancestor = substr($ancestor,-10,10);
 1339:             }
 1340:             $oldid = $path.$prefix.$ancestor;
 1341:         }
 1342:         my $counter = 0;
 1343:         my $newurl=$oldid.$newid.'.'.$ext;
 1344:         my $is_unique = &uniqueness_check($newurl);
 1345:         while (!$is_unique && $counter < 100) {
 1346:             $counter ++;
 1347:             $newid ++;
 1348:             $newurl = $oldid.$newid;
 1349:             $is_unique = &uniqueness_check($newurl);
 1350:         }
 1351:         if (!$is_unique) {
 1352:             if ($url=~/\.page$/) {
 1353:                 return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
 1354:             } else {
 1355:                 return &mt('Paste failed: an error occurred creating a unique URL for the folder');
 1356:             }
 1357:         }
 1358: 	my $storefn=$newurl;
 1359: 	$storefn=~s{^/\w+/$match_domain/$match_username/}{};
 1360: 	my $paste_map_result =
 1361:             &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
 1362: 					       &Apache::lonnet::getfile($url));
 1363:         if ($paste_map_result eq '/adm/notfound.html') {
 1364:             if ($url=~/\.page$/) {
 1365:                 return &mt('Paste failed: an error occurred saving the composite page');
 1366:             } else {
 1367:                 return &mt('Paste failed: an error occurred saving the folder');
 1368:             }
 1369:         }
 1370: 	$url = $newurl;
 1371:     }
 1372: # published maps can only exists once, so remove it from paste buffer when done
 1373:     if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
 1374: 	&Apache::lonnet::delenv('docs.markedcopy');
 1375:     }
 1376:     if ($url=~ m{/smppg$}) {
 1377: 	my $db_name = &Apache::lonsimplepage::get_db_name($url);
 1378: 	if ($db_name =~ /^smppage_/) {
 1379: 	    #simple pages, need to copy the db contents to a new one.
 1380: 	    my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
 1381: 	    my $now = time();
 1382: 	    $db_name =~ s{_\d*$ }{_$now}x;
 1383: 	    my $result=&Apache::lonnet::put($db_name,\%contents,
 1384: 					    $coursedom,$coursenum);
 1385: 	    $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
 1386: 	    $title=&mt('Copy of').' '.$title;
 1387: 	}
 1388:     }
 1389:     $title = &LONCAPA::map::qtunescape($title);
 1390:     my $ext='false';
 1391:     if ($url=~m{^http(|s)://}) { $ext='true'; }
 1392:     $url       = &LONCAPA::map::qtunescape($url);
 1393: # Now insert the URL at the bottom
 1394:     my $newidx = &LONCAPA::map::getresidx($url);
 1395:     if ($env{'docs.markedcopy_supplemental'}) {
 1396:         if ($folder =~ /^supplemental/) {
 1397:             $title = $env{'docs.markedcopy_supplemental'};
 1398:         } else {
 1399:             (undef,undef,$title) =
 1400:                 &parse_supplemental_title($env{'docs.markedcopy_supplemental'});
 1401:         }
 1402:     } else {
 1403:         if ($folder=~/^supplemental/) {
 1404:            $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
 1405:                   $env{'user.domain'}.'___&&&___'.$title;
 1406:         }
 1407:     }
 1408: 
 1409:     $LONCAPA::map::resources[$newidx]= 	$title.':'.$url.':'.$ext.':normal:res';
 1410:     push(@LONCAPA::map::order, $newidx);
 1411:     return 'ok';
 1412: # Store the result
 1413: }
 1414: 
 1415: sub uniqueness_check {
 1416:     my ($newurl) = @_;
 1417:     my $unique = 1;
 1418:     foreach my $res (@LONCAPA::map::order) {
 1419:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
 1420:         $url=&LONCAPA::map::qtescape($url);
 1421:         if ($newurl eq $url) {
 1422:             $unique = 0;
 1423:             last;
 1424:         }
 1425:     }
 1426:     return $unique;
 1427: }
 1428: 
 1429: my %parameter_type = ( 'randompick'     => 'int_pos',
 1430: 		       'hiddenresource' => 'string_yesno',
 1431: 		       'encrypturl'     => 'string_yesno',
 1432: 		       'randomorder'    => 'string_yesno',);
 1433: my $valid_parameters_re = join('|',keys(%parameter_type));
 1434: # set parameters
 1435: sub update_parameter {
 1436: 
 1437:     return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
 1438: 
 1439:     my $which = $env{'form.changeparms'};
 1440:     my $idx = $env{'form.setparms'};
 1441:     if ($env{'form.'.$which.'_'.$idx}) {
 1442: 	my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
 1443: 	                                     : 'yes';
 1444: 	&LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
 1445: 				      $parameter_type{$which});
 1446: 	&remember_parms($idx,$which,'set',$value);
 1447:     } else {
 1448: 	&LONCAPA::map::delparameter($idx,'parameter_'.$which);
 1449: 
 1450: 	&remember_parms($idx,$which,'del');
 1451:     }
 1452:     return 1;
 1453: }
 1454: 
 1455: 
 1456: sub handle_edit_cmd {
 1457:     my ($coursenum,$coursedom) =@_;
 1458: 
 1459:     my ($cmd,$idx)=split('_',$env{'form.cmd'});
 1460: 
 1461:     my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
 1462:     my ($title, $url, @rrest) = split(':', $ratstr);
 1463: 
 1464:     if ($cmd eq 'del') {
 1465: 	if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
 1466: 	    ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
 1467: 	    &Apache::lonnet::removeuploadedurl($url);
 1468: 	} else {
 1469: 	    &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
 1470: 	}
 1471: 	splice(@LONCAPA::map::order, $idx, 1);
 1472: 
 1473:     } elsif ($cmd eq 'cut') {
 1474: 	&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
 1475: 	splice(@LONCAPA::map::order, $idx, 1);
 1476: 
 1477:     } elsif ($cmd eq 'up'
 1478: 	     && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
 1479: 	@LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
 1480: 
 1481:     } elsif ($cmd eq 'down'
 1482: 	     && defined($LONCAPA::map::order[$idx+1])) {
 1483: 	@LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
 1484: 
 1485:     } elsif ($cmd eq 'rename') {
 1486: 
 1487: 	my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
 1488: 	if ($comment=~/\S/) {
 1489: 	    $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
 1490: 		$comment.':'.join(':', $url, @rrest);
 1491: 	}
 1492: # Devalidate title cache
 1493: 	my $renamed_url=&LONCAPA::map::qtescape($url);
 1494: 	&Apache::lonnet::devalidate_title_cache($renamed_url);
 1495:     } else {
 1496: 	return 0;
 1497:     }
 1498:     return 1;
 1499: }
 1500: 
 1501: sub editor {
 1502:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype)=@_;
 1503:     my $container= ($env{'form.pagepath'}) ? 'page'
 1504: 		                           : 'sequence';
 1505: 
 1506:     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
 1507: 				    $folder.'.'.$container);
 1508:     return $errtext if ($fatal);
 1509: 
 1510:     if ($#LONCAPA::map::order<1) {
 1511: 	my $idx=&LONCAPA::map::getresidx();
 1512: 	if ($idx<=0) { $idx=1; }
 1513:        	$LONCAPA::map::order[0]=$idx;
 1514:         $LONCAPA::map::resources[$idx]='';
 1515:     }
 1516: 
 1517:     my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
 1518:     if ($allowed) {
 1519:         ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
 1520: 	    &breadcrumbs($allowed,$crstype);
 1521:         $r->print($breadcrumbtrail);
 1522:     } else {
 1523:         $randompick = -1;
 1524:     }
 1525: 
 1526: # ------------------------------------------------------------ Process commands
 1527: 
 1528: # ---------------- if they are for this folder and user allowed to make changes
 1529:     if (($allowed) && ($env{'form.folder'} eq $folder)) {
 1530: # set parameters and change order
 1531: 	&snapshotbefore();
 1532: 
 1533: 	if (&update_parameter()) {
 1534: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
 1535: 	    return $errtext if ($fatal);
 1536: 	}
 1537: 
 1538: 	if ($env{'form.newpos'} && $env{'form.currentpos'}) {
 1539: # change order
 1540: 	    my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
 1541: 	    splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
 1542: 
 1543: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
 1544: 	    return $errtext if ($fatal);
 1545: 	}
 1546: 
 1547: 	if ($env{'form.pastemarked'}) {
 1548:             my $paste_res =
 1549:                 &do_paste_from_buffer($coursenum,$coursedom,$folder);
 1550:             if ($paste_res eq 'ok') {
 1551:                 ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
 1552:                 return $errtext if ($fatal);
 1553:             } elsif ($paste_res ne '') {
 1554:                 $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
 1555:             }
 1556: 	}
 1557: 
 1558: 	$r->print($upload_output);
 1559: 
 1560: 	if (&handle_edit_cmd()) {
 1561: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
 1562: 	    return $errtext if ($fatal);
 1563: 	}
 1564: # Group import/search
 1565: 	if ($env{'form.importdetail'}) {
 1566: 	    my @imports;
 1567: 	    foreach my $item (split(/\&/,$env{'form.importdetail'})) {
 1568: 		if (defined($item)) {
 1569: 		    my ($name,$url,$residx)=
 1570: 			map {&unescape($_)} split(/\=/,$item);
 1571: 		    push(@imports, [$name, $url, $residx]);
 1572: 		}
 1573: 	    }
 1574: 	    ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
 1575: 					    $container,'londocs',@imports);
 1576: 	    return $errtext if ($fatal);
 1577: 	}
 1578: # Loading a complete map
 1579: 	if ($env{'form.loadmap'}) {
 1580: 	    if ($env{'form.importmap'}=~/\w/) {
 1581: 		foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
 1582: 		    my ($title,$url,$ext,$type)=split(/\:/,$res);
 1583: 		    my $idx=&LONCAPA::map::getresidx($url);
 1584: 		    $LONCAPA::map::resources[$idx]=$res;
 1585: 		    $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
 1586: 		}
 1587: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
 1588: 					    $folder.'.'.$container);
 1589: 		return $errtext if ($fatal);
 1590: 	    } else {
 1591: 		$r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
 1592: 
 1593: 	    }
 1594: 	}
 1595: 	&log_differences($plain);
 1596:     }
 1597: # ---------------------------------------------------------------- End commands
 1598: # ---------------------------------------------------------------- Print screen
 1599:     my $idx=0;
 1600:     my $shown=0;
 1601:     if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
 1602: 	$r->print('<div class="LC_Box">'.
 1603:           '<p>'.&mt('Parameters:').
 1604:           '<ul>'.
 1605: 		  ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
 1606: 		  ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
 1607: 		  ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
 1608: 		  ($is_random_order?'<li>'.&mt('random order').'</li>':'').
 1609: 		  '</ul></p>');
 1610:         if ($randompick>=0) {
 1611:             $r->print('<p class="LC_warning">'
 1612:                  .&mt('Caution: this folder is set to randomly pick a subset'
 1613:                      .' of resources. Adding or removing resources from this'
 1614:                      .' folder will change the set of resources that the'
 1615:                      .' students see, resulting in spurious or missing credit'
 1616:                      .' for completed problems, not limited to ones you'
 1617:                      .' modify. Do not modify the contents of this folder if'
 1618:                      .' it is in active student use.')
 1619:                  .'</p>'
 1620:             );
 1621:         }
 1622:         if ($is_random_order) {
 1623:             $r->print('<p class="LC_warning">'
 1624:                  .&mt('Caution: this folder is set to randomly order its'
 1625:                      .' contents. Adding or removing resources from this folder'
 1626:                      .' will change the order of resources shown.')
 1627:                  .'</p>'
 1628:             );
 1629:         }
 1630:         $r->print('</div>');
 1631:     }
 1632: 
 1633:     my $output;
 1634:     foreach my $res (@LONCAPA::map::order) {
 1635:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
 1636:         $name=&LONCAPA::map::qtescape($name);
 1637:         $url=&LONCAPA::map::qtescape($url);
 1638:         unless ($name) {  $name=(split(/\//,$url))[-1]; }
 1639:         unless ($name) { $idx++; next; }
 1640:         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
 1641:                               $coursenum,$crstype);
 1642:         $idx++;
 1643:         $shown++;
 1644:     }
 1645:     if ($shown) {
 1646:         $r->print(&Apache::loncommon::start_data_table());
 1647:         if ($allowed) {
 1648:             $r->print(&Apache::loncommon::start_data_table_header_row()
 1649:                      .'<th colspan="2">'.&mt('Move').'</th>'
 1650:                      .'<th>'.&mt('Actions').'</th>'
 1651:                      .'<th colspan="2">'.&mt('Document').'</th>');
 1652:             if ($folder !~ /^supplemental/) {
 1653:                 $->print('<th colspan="4">'.&mt('Settings').'</th>');
 1654:             }
 1655:             $r->print(&Apache::loncommon::end_data_table_header_row());
 1656:         }
 1657:         $r->print($output
 1658:                  .&Apache::loncommon::end_data_table()
 1659:         );
 1660:     } else {
 1661:         $r->print('<p class="LC_info">'
 1662:                  .&mt('Currently no documents.')
 1663:                  .'</p>'
 1664:         );
 1665:     }
 1666:     if ($allowed) {
 1667:         &print_paste_buffer($r,$container);
 1668:     }
 1669:     return;
 1670: }
 1671: 
 1672: sub process_file_upload {
 1673:     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
 1674: # upload a file, if present
 1675:     my $parseaction;
 1676:    if ($env{'form.parserflag'}) {
 1677:         $parseaction = 'parse';
 1678:     }
 1679:     my $phase_status;
 1680:     my $folder=$env{'form.folder'};
 1681:     if ($folder eq '') {
 1682:         $folder='default';
 1683:     }
 1684:     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
 1685:         my $errtext='';
 1686:         my $fatal=0;
 1687:         my $container='sequence';
 1688:         if ($env{'form.pagepath'}) {
 1689:             $container='page';
 1690:         }
 1691:         ($errtext,$fatal)=
 1692:               &mapread($coursenum,$coursedom,$folder.'.'.$container);
 1693:         if ($#LONCAPA::map::order<1) {
 1694:             $LONCAPA::map::order[0]=1;
 1695:             $LONCAPA::map::resources[1]='';
 1696:         }
 1697:         if ($fatal) {
 1698:             return 'failed';
 1699:         }
 1700:         my $destination = 'docs/';
 1701:         if ($folder =~ /^supplemental/) {
 1702:             $destination = 'supplemental/';
 1703:         }
 1704:         if (($folder eq 'default') || ($folder eq 'supplemental')) {
 1705:             $destination .= 'default/';
 1706:         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
 1707:             $destination .=  $2.'/';
 1708:         }
 1709: # this is for a course, not a user, so set coursedoc flag
 1710: # probably the only place in the system where this should be "1"
 1711:         my $newidx=&LONCAPA::map::getresidx();
 1712:         $destination .= $newidx;
 1713:         my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
 1714: 						$parseaction,$allfiles,
 1715: 						$codebase);
 1716:         my $ext='false';
 1717:         if ($url=~m{^http://}) { $ext='true'; }
 1718: 	$url     = &LONCAPA::map::qtunescape($url);
 1719:         my $comment=$env{'form.comment'};
 1720: 	$comment = &LONCAPA::map::qtunescape($comment);
 1721:         if ($folder=~/^supplemental/) {
 1722:               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
 1723:                   $env{'user.domain'}.'___&&&___'.$comment;
 1724:         }
 1725: 
 1726:         $LONCAPA::map::resources[$newidx]=
 1727: 	    $comment.':'.$url.':'.$ext.':normal:res';
 1728:         $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
 1729:         ($errtext,$fatal)=&storemap($coursenum,$coursedom,
 1730: 				    $folder.'.'.$container);
 1731:         if ($fatal) {
 1732:             $$upload_output .= '<p><span class="LC_error">'.$errtext.'</span></p>';
 1733:             return 'failed';
 1734:         } else {
 1735:             if ($parseaction eq 'parse') {
 1736:                 my $total_embedded = scalar(keys(%{$allfiles}));
 1737:                 if ($total_embedded > 0) {
 1738:                     my $num = 0;
 1739: 		    my $state = '
 1740:    <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
 1741:    <input type="hidden" name="cmd" value="upload_embedded" />
 1742:    <input type="hidden" name="newidx" value="'.$newidx.'" />
 1743:    <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
 1744:    <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
 1745: 		    $phase_status = 'phasetwo';
 1746: 
 1747:                     $$upload_output .=
 1748: 			'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />'.
 1749: 			&Apache::loncommon::ask_for_embedded_content(
 1750:                             '/adm/coursedocs',$state,$allfiles,$codebase);
 1751:                 } else {
 1752:                     $$upload_output .= 'No embedded items identified<br />';
 1753:                 }
 1754:             }
 1755:         }
 1756:     }
 1757:     return $phase_status;
 1758: }
 1759: 
 1760: sub process_secondary_uploads {
 1761:     my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
 1762:     my $folder=$env{'form.folder'};
 1763:     my $destination = 'docs/';
 1764:     if ($folder =~ /^supplemental/) {
 1765:         $destination = 'supplemental/';
 1766:     }
 1767:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
 1768:         $destination .= 'default/';
 1769:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
 1770:         $destination .=  $2.'/';
 1771:     }
 1772:     $destination .= $newidx;
 1773:     my ($url,$filename);
 1774:     $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
 1775:     ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
 1776:     return $filename;
 1777: }
 1778: 
 1779: sub is_supplemental_title {
 1780:     my ($title) = @_;
 1781:     return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
 1782: }
 1783: 
 1784: sub parse_supplemental_title {
 1785:     my ($title) = @_;
 1786: 
 1787:     my ($foldertitle,$renametitle);
 1788:     if ($title =~ /&amp;&amp;&amp;/) {
 1789: 	$title = &HTML::Entites::decode($title);
 1790:     }
 1791:  if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
 1792: 	$renametitle=$4;
 1793: 	my ($time,$uname,$udom) = ($1,$2,$3);
 1794: 	$foldertitle=&Apache::lontexconvert::msgtexconverted($4);
 1795: 	my $name =  &Apache::loncommon::plainname($uname,$udom);
 1796: 	$name = &HTML::Entities::encode($name,'"<>&\'');
 1797: 	$title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
 1798: 	    $name.': <br />'.$foldertitle;
 1799:     }
 1800:     if (wantarray) {
 1801: 	return ($title,$foldertitle,$renametitle);
 1802:     }
 1803:     return $title;
 1804: }
 1805: 
 1806: # --------------------------------------------------------------- An entry line
 1807: 
 1808: sub entryline {
 1809:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$crstype)=@_;
 1810:     my ($foldertitle,$pagetitle,$renametitle);
 1811:     if (&is_supplemental_title($title)) {
 1812: 	($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
 1813: 	$pagetitle = $foldertitle;
 1814:     } else {
 1815: 	$title=&HTML::Entities::encode($title,'"<>&\'');
 1816: 	$renametitle=$title;
 1817: 	$foldertitle=$title;
 1818: 	$pagetitle=$title;
 1819:     }
 1820: 
 1821:     my $orderidx=$LONCAPA::map::order[$index];
 1822: 
 1823: 
 1824:     $renametitle=~s/\\/\\\\/g;
 1825:     $renametitle=~s/\&quot\;/\\\"/g;
 1826:     $renametitle=~s/ /%20/g;
 1827:     my $line=&Apache::loncommon::start_data_table_row();
 1828:     my ($form_start,$form_end);
 1829: # Edit commands
 1830:     my ($container, $type, $esc_path, $path, $symb);
 1831:     if ($env{'form.folderpath'}) {
 1832: 	$type = 'folder';
 1833:         $container = 'sequence';
 1834: 	$esc_path=&escape($env{'form.folderpath'});
 1835: 	$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
 1836: 	# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
 1837:     }
 1838:     if ($env{'form.pagepath'}) {
 1839:         $type = $container = 'page';
 1840:         $esc_path=&escape($path = $env{'form.pagepath'});
 1841: 	$path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
 1842:         $symb=&escape($env{'form.pagesymb'});
 1843:     }
 1844:     my $cpinfo='';
 1845:     if ($allowed) {
 1846: 	my $incindex=$index+1;
 1847: 	my $selectbox='';
 1848: 	if (($folder!~/^supplemental/) &&
 1849: 	    ($#LONCAPA::map::order>0) &&
 1850: 	    ((split(/\:/,
 1851: 	     $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
 1852: 	     ne '') &&
 1853: 	    ((split(/\:/,
 1854: 	     $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
 1855: 	     ne '')) {
 1856: 	    $selectbox=
 1857: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
 1858: 		'<select name="newpos" onchange="this.form.submit()">';
 1859: 	    for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
 1860: 		if ($i==$incindex) {
 1861: 		    $selectbox.='<option value="" selected="selected">('.$i.')</option>';
 1862: 		} else {
 1863: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
 1864: 		}
 1865: 	    }
 1866: 	    $selectbox.='</select>';
 1867: 	}
 1868: 	my %lt=&Apache::lonlocal::texthash(
 1869:                 'up' => 'Move Up',
 1870: 		'dw' => 'Move Down',
 1871: 		'rm' => 'Remove',
 1872:                 'ct' => 'Cut',
 1873: 		'rn' => 'Rename',
 1874: 		'cp' => 'Copy');
 1875: 	my $nocopy=0;
 1876:         my $nocut=0;
 1877:         if ($url=~/\.(page|sequence)$/) {
 1878: 	    if ($url =~ m{/res/}) {
 1879: 		# no copy for published maps
 1880: 		$nocopy = 1;
 1881: 	    } else {
 1882: 		foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
 1883: 		    my ($title,$url,$ext,$type)=split(/\:/,$item);
 1884: 		    if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
 1885: 			$nocopy=1;
 1886: 			last;
 1887: 		    }
 1888: 		}
 1889: 	    }
 1890: 	}
 1891:         if ($url=~/^\/res\/lib\/templates\//) {
 1892:            $nocopy=1;
 1893:            $nocut=1;
 1894:         }
 1895:         my $copylink='&nbsp;';
 1896:         my $cutlink='&nbsp;';
 1897: 
 1898: 	my $skip_confirm = 0;
 1899: 	if ( $folder =~ /^supplemental/
 1900: 	     || ($url =~ m{( /smppg$
 1901: 			    |/syllabus$
 1902: 			    |/aboutme$
 1903: 			    |/navmaps$
 1904: 			    |/bulletinboard$
 1905: 			    |\.html$
 1906: 			    |^/adm/wrapper/ext)}x)) {
 1907: 	    $skip_confirm = 1;
 1908: 	}
 1909: 
 1910: 	if (!$nocopy) {
 1911: 	    $copylink=(<<ENDCOPY);
 1912: <a href='javascript:markcopy("$esc_path","$index","$renametitle","$container","$symb","$folder");' class="LC_docs_copy">$lt{'cp'}</a>
 1913: ENDCOPY
 1914:         }
 1915: 	if (!$nocut) {
 1916: 	    $cutlink=(<<ENDCUT);
 1917: <a href='javascript:cutres("$esc_path","$index","$renametitle","$container","$symb","$folder",$skip_confirm);' class="LC_docs_cut">$lt{'ct'}</a>
 1918: ENDCUT
 1919:         }
 1920: 	$form_start = (<<END);
 1921:    <form  action="/adm/coursedocs" method="post">
 1922:    <input type="hidden" name="${type}path" value="$path" />
 1923:    <input type="hidden" name="${type}symb" value="$symb" />
 1924:    <input type="hidden" name="setparms" value="$orderidx" />
 1925:    <input type="hidden" name="changeparms" value="0" />
 1926: END
 1927:         $form_end = '</form>';
 1928: 	$line.=(<<END);
 1929: <td>
 1930: <div class="LC_docs_entry_move">
 1931:   <a href='/adm/coursedocs?cmd=up_$index&amp;${type}path=$esc_path&amp;${type}symb=$symb$cpinfo'>
 1932:     <img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" />
 1933:   </a>
 1934: </div>
 1935: <div class="LC_docs_entry_move">
 1936:   <a href='/adm/coursedocs?cmd=down_$index&amp;${type}path=$esc_path&amp;${type}symb=$symb$cpinfo'>
 1937:     <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" />
 1938:   </a>
 1939: </div>
 1940: </td>
 1941: <td>
 1942:    $form_start
 1943:    $selectbox
 1944:    $form_end
 1945: </td>
 1946: <td class="LC_docs_entry_commands">
 1947:    <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
 1948: $cutlink
 1949:    <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
 1950: $copylink
 1951: </td>
 1952: END
 1953: 
 1954:     }
 1955: # Figure out what kind of a resource this is
 1956:     my ($extension)=($url=~/\.(\w+)$/);
 1957:     my $uploaded=($url=~/^\/*uploaded\//);
 1958:     my $icon=&Apache::loncommon::icon($url);
 1959:     my $isfolder=0;
 1960:     my $ispage=0;
 1961:     my $folderarg;
 1962:     my $pagearg;
 1963:     my $pagefile;
 1964:     if ($uploaded) {
 1965: 	if ($extension eq 'sequence') {
 1966: 	    $icon=$iconpath.'/navmap.folder.closed.gif';
 1967: 	    $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;
 1968: 	    $url='/adm/coursedocs?';
 1969: 	    $folderarg=$1;
 1970: 	    $isfolder=1;
 1971:         } elsif ($extension eq 'page') {
 1972:             $icon=$iconpath.'/page.gif';
 1973:             $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;
 1974:             $pagearg=$1;
 1975:             $url='/adm/coursedocs?';
 1976:             $ispage=1;
 1977: 	} else {
 1978: 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
 1979: 	}
 1980:     }
 1981: 
 1982:     my $orig_url = $url;
 1983:     $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
 1984:     my $external = ($url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/});
 1985:     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
 1986: 	my $symb=&Apache::lonnet::symbclean(
 1987:           &Apache::lonnet::declutter('uploaded/'.
 1988:            $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
 1989:            $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
 1990:            '.sequence').
 1991:            '___'.$residx.'___'.
 1992: 	   &Apache::lonnet::declutter($url));
 1993: 	(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
 1994: 	$url=&Apache::lonnet::clutter($url);
 1995: 	if ($url=~/^\/*uploaded\//) {
 1996: 	    $url=~/\.(\w+)$/;
 1997: 	    my $embstyle=&Apache::loncommon::fileembstyle($1);
 1998: 	    if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
 1999: 		$url='/adm/wrapper'.$url;
 2000: 	    } elsif ($embstyle eq 'ssi') {
 2001: 		#do nothing with these
 2002: 	    } elsif ($url!~/\.(sequence|page)$/) {
 2003: 		$url='/adm/coursedocs/showdoc'.$url;
 2004: 	    }
 2005: 	} elsif ($url=~m|^/ext/|) {
 2006: 	    $url='/adm/wrapper'.$url;
 2007: 	    $external = 1;
 2008: 	}
 2009:         if (&Apache::lonnet::symbverify($symb,$url)) {
 2010: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
 2011:         } else {
 2012:             $url='';
 2013:         }
 2014: 	if ($container eq 'page') {
 2015: 	    my $symb=$env{'form.pagesymb'};
 2016: 
 2017: 	    $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
 2018: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
 2019: 	}
 2020:     }
 2021:     my ($parameterset,$rand_order_text) = ('&nbsp;', '&nbsp;');
 2022:     if ($isfolder || $extension eq 'sequence') {
 2023: 	my $foldername=&escape($foldertitle);
 2024: 	my $folderpath=$env{'form.folderpath'};
 2025: 	if ($folderpath) { $folderpath.='&' };
 2026: # Append randompick number, hidden, and encrypted with ":" to foldername,
 2027: # so it gets transferred between levels
 2028: 	$folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
 2029:                                               'parameter_randompick'))[0]
 2030:                                                .':'.((&LONCAPA::map::getparameter($orderidx,
 2031:                                               'parameter_hiddenresource'))[0]=~/^yes$/i)
 2032:                                                .':'.((&LONCAPA::map::getparameter($orderidx,
 2033:                                               'parameter_encrypturl'))[0]=~/^yes$/i)
 2034:                                                .':'.((&LONCAPA::map::getparameter($orderidx,
 2035:                                               'parameter_randomorder'))[0]=~/^yes$/i);
 2036: 	$url.='folderpath='.&escape($folderpath).$cpinfo;
 2037: 	$parameterset='<label>'.&mt('Randomly Pick: ').
 2038: 	    '<input type="text" size="4" onchange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randompick_'.$orderidx.'" value="'.
 2039: 	    (&LONCAPA::map::getparameter($orderidx,
 2040:                                               'parameter_randompick'))[0].
 2041:                                               '" />'.
 2042: '<a href="javascript:void(0)">'.&mt('Save').'</a></label>';
 2043:     	my $ro_set=
 2044: 	    ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
 2045: 	$rand_order_text ='
 2046: <span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onclick="this.form.changeparms.value=\'randomorder\';this.form.submit()" '.$ro_set.' /> '.&mt('Random Order').' </label></span>';
 2047:     }
 2048:     if ($ispage) {
 2049:         my $pagename=&escape($pagetitle);
 2050:         my $pagepath;
 2051:         my $folderpath=$env{'form.folderpath'};
 2052:         if ($folderpath) { $pagepath = $folderpath.'&' };
 2053:         $pagepath.=$pagearg.'&'.$pagename;
 2054: 	my $symb=$env{'form.pagesymb'};
 2055: 	if (!$symb) {
 2056: 	    my $path='uploaded/'.
 2057: 		$env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
 2058: 		$env{'course.'.$env{'request.course.id'}.'.num'}.'/';
 2059: 	    $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
 2060: 					       $residx,
 2061: 					       $path.$pagearg.'.page');
 2062: 	}
 2063: 	$url.='pagepath='.&escape($pagepath).
 2064: 	    '&amp;pagesymb='.&escape($symb).$cpinfo;
 2065:     }
 2066:     if (($external) && ($allowed)) {
 2067: 	my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
 2068: 	$external = '&nbsp;<a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
 2069:     } else {
 2070: 	undef($external);
 2071:     }
 2072:     my $reinit;
 2073:     if ($crstype eq 'Community') {
 2074:         $reinit = &mt('(re-initialize community to access)');
 2075:     } else {
 2076:         $reinit = &mt('(re-initialize course to access)');
 2077:     }  
 2078:     $line.='
 2079:   <td>
 2080:     '.($url?'<a href="'.$url.'">':'').'<img src="'.$icon.'" alt="" class="LC_icon" />'.($url?'</a>':'').'
 2081:   </td>
 2082:   <td>
 2083:     '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.$reinit.'</span>').$external."
 2084:   </td>";
 2085:     if (($allowed) && ($folder!~/^supplemental/)) {
 2086:  	my %lt=&Apache::lonlocal::texthash(
 2087:  			      'hd' => 'Hidden',
 2088:  			      'ec' => 'URL hidden');
 2089: 	my $enctext=
 2090: 	    ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
 2091: 	my $hidtext=
 2092: 	    ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
 2093: 	$line.=(<<ENDPARMS);
 2094:   <td class="LC_docs_entry_parameter">
 2095:     $form_start
 2096:     <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
 2097:     $form_end
 2098:   </td>
 2099:   <td class="LC_docs_entry_parameter">
 2100:     $form_start
 2101:     <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
 2102:     $form_end
 2103:   </td>
 2104:   <td class="LC_docs_entry_parameter">$form_start $rand_order_text $form_end</td>
 2105:   <td class="LC_docs_entry_parameter">$form_start $parameterset $form_end</td>
 2106: ENDPARMS
 2107:     }
 2108:     $line.=&Apache::loncommon::end_data_table_row();
 2109:     return $line;
 2110: }
 2111: 
 2112: =pod
 2113: 
 2114: =item tiehash()
 2115: 
 2116: tie the hash
 2117: 
 2118: =cut
 2119: 
 2120: sub tiehash {
 2121:     my ($mode)=@_;
 2122:     $hashtied=0;
 2123:     if ($env{'request.course.fn'}) {
 2124: 	if ($mode eq 'write') {
 2125: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
 2126: 		    &GDBM_WRCREAT(),0640)) {
 2127:                 $hashtied=2;
 2128: 	    }
 2129: 	} else {
 2130: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
 2131: 		    &GDBM_READER(),0640)) {
 2132:                 $hashtied=1;
 2133: 	    }
 2134: 	}
 2135:     }
 2136: }
 2137: 
 2138: sub untiehash {
 2139:     if ($hashtied) { untie %hash; }
 2140:     $hashtied=0;
 2141:     return OK;
 2142: }
 2143: 
 2144: 
 2145: 
 2146: 
 2147: sub checkonthis {
 2148:     my ($r,$url,$level,$title)=@_;
 2149:     $url=&unescape($url);
 2150:     $alreadyseen{$url}=1;
 2151:     $r->rflush();
 2152:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
 2153:        $r->print("\n<br />");
 2154:        if ($level==0) {
 2155:            $r->print("<br />");
 2156:        }
 2157:        for (my $i=0;$i<=$level*5;$i++) {
 2158:            $r->print('&nbsp;');
 2159:        }
 2160:        $r->print('<a href="'.$url.'" target="cat">'.
 2161: 		 ($title?$title:$url).'</a> ');
 2162:        if ($url=~/^\/res\//) {
 2163: 	  my $result=&Apache::lonnet::repcopy(
 2164:                               &Apache::lonnet::filelocation('',$url));
 2165:           if ($result eq 'ok') {
 2166:              $r->print('<span class="LC_success">'.&mt('ok').'</span>');
 2167:              $r->rflush();
 2168:              &Apache::lonnet::countacc($url);
 2169:              $url=~/\.(\w+)$/;
 2170:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
 2171: 		 $r->print('<br />');
 2172:                  $r->rflush();
 2173:                  for (my $i=0;$i<=$level*5;$i++) {
 2174:                      $r->print('&nbsp;');
 2175:                  }
 2176:                  $r->print('- '.&mt('Rendering:').' ');
 2177: 		 my ($errorcount,$warningcount)=split(/:/,
 2178: 	       &Apache::lonnet::ssi_body($url,
 2179: 			       ('grade_target'=>'web',
 2180: 				'return_only_error_and_warning_counts' => 1)));
 2181:                  if (($errorcount) ||
 2182:                      ($warningcount)) {
 2183: 		     if ($errorcount) {
 2184:                         $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
 2185:                           &mt('[quant,_1,error]',$errorcount).'</span>');
 2186:                      }
 2187: 		     if ($warningcount) {
 2188:                         $r->print('<span class="LC_warning">'.
 2189:                           &mt('[quant,_1,warning]',$warningcount).'</span>');
 2190:                      }
 2191:                  } else {
 2192:                      $r->print('<span class="LC_success">'.&mt('ok').'</span>');
 2193:                  }
 2194:                  $r->rflush();
 2195:              }
 2196: 	     my $dependencies=
 2197:                 &Apache::lonnet::metadata($url,'dependencies');
 2198:              foreach my $dep (split(/\,/,$dependencies)) {
 2199: 		 if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
 2200:                     &checkonthis($r,$dep,$level+1);
 2201:                  }
 2202:              }
 2203:           } elsif ($result eq 'unavailable') {
 2204:              $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
 2205:           } elsif ($result eq 'not_found') {
 2206: 	      unless ($url=~/\$/) {
 2207: 		  $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
 2208: 	      } else {
 2209: 		  $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
 2210: 	      }
 2211:           } else {
 2212:              $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
 2213:           }
 2214:        }
 2215:     }
 2216: }
 2217: 
 2218: 
 2219: 
 2220: =pod
 2221: 
 2222: =item list_symbs()
 2223: 
 2224: List Symbs
 2225: 
 2226: =cut
 2227: 
 2228: sub list_symbs {
 2229:     my ($r) = @_;
 2230: 
 2231:     my $crstype = &Apache::loncommon::course_type();
 2232:     $r->print(&Apache::loncommon::start_page('Symb List'));
 2233:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
 2234:     my $navmap = Apache::lonnavmaps::navmap->new();
 2235:     if (!defined($navmap)) {
 2236:         $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
 2237:                   '<div class="LC_error">'.
 2238:                   &mt('Unable to retrieve information about course contents').
 2239:                   '</div>');
 2240:         &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
 2241:     } else {
 2242:         $r->print("<pre>\n");
 2243:         foreach my $res ($navmap->retrieveResources()) {
 2244: 	    $r->print($res->compTitle()."\t".$res->symb()."\n");
 2245:         }
 2246:         $r->print("\n</pre>\n");
 2247:     }
 2248:     $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
 2249: }
 2250: 
 2251: 
 2252: sub verifycontent {
 2253:     my ($r) = @_;
 2254:     my $crstype = &Apache::loncommon::course_type();
 2255:    my $loaderror=&Apache::lonnet::overloaderror($r);
 2256:    if ($loaderror) { return $loaderror; }
 2257:    $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
 2258:    $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
 2259:    $hashtied=0;
 2260:    undef %alreadyseen;
 2261:    %alreadyseen=();
 2262:    &tiehash();
 2263:    foreach my $key (keys(%hash)) {
 2264:        if ($hash{$key}=~/\.(page|sequence)$/) {
 2265: 	   if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
 2266: 	       $r->print('<hr /><span class="LC_error">'.
 2267: 			 &mt('The following sequence or page is included more than once in your '.$crstype.': ').
 2268: 			 &unescape($hash{$key}).'</span><br />'.
 2269: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
 2270: 	   }
 2271:        }
 2272:        if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
 2273:            &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
 2274:        }
 2275:    }
 2276:    &untiehash();
 2277:    $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
 2278: 	     &mt('Return to DOCS').'</a>');
 2279: }
 2280: 
 2281: 
 2282: sub devalidateversioncache {
 2283:     my $src=shift;
 2284:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
 2285: 					  &Apache::lonnet::clutter($src));
 2286: }
 2287: 
 2288: sub checkversions {
 2289:     my ($r) = @_;
 2290:     my $crstype = &Apache::loncommon::course_type();
 2291:     $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
 2292:     $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
 2293:     my $header='';
 2294:     my $startsel='';
 2295:     my $monthsel='';
 2296:     my $weeksel='';
 2297:     my $daysel='';
 2298:     my $allsel='';
 2299:     my %changes=();
 2300:     my $starttime=0;
 2301:     my $haschanged=0;
 2302:     my %setversions=&Apache::lonnet::dump('resourceversions',
 2303: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
 2304: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
 2305: 
 2306:     $hashtied=0;
 2307:     &tiehash();
 2308:     my %newsetversions=();
 2309:     if ($env{'form.setmostrecent'}) {
 2310: 	$haschanged=1;
 2311: 	foreach my $key (keys(%hash)) {
 2312: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
 2313: 		$newsetversions{$1}='mostrecent';
 2314:                 &devalidateversioncache($1);
 2315: 	    }
 2316: 	}
 2317:     } elsif ($env{'form.setcurrent'}) {
 2318: 	$haschanged=1;
 2319: 	foreach my $key (keys(%hash)) {
 2320: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
 2321: 		my $getvers=&Apache::lonnet::getversion($1);
 2322: 		if ($getvers>0) {
 2323: 		    $newsetversions{$1}=$getvers;
 2324: 		    &devalidateversioncache($1);
 2325: 		}
 2326: 	    }
 2327: 	}
 2328:     } elsif ($env{'form.setversions'}) {
 2329: 	$haschanged=1;
 2330: 	foreach my $key (keys(%env)) {
 2331: 	    if ($key=~/^form\.set_version_(.+)$/) {
 2332: 		my $src=$1;
 2333: 		if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
 2334: 		    $newsetversions{$src}=$env{$key};
 2335: 		    &devalidateversioncache($src);
 2336: 		}
 2337: 	    }
 2338: 	}
 2339:     }
 2340:     if ($haschanged) {
 2341:         if (&Apache::lonnet::put('resourceversions',\%newsetversions,
 2342: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
 2343: 			  $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
 2344: 	    $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');
 2345: 	} else {
 2346: 	    $r->print('<h1><span class="LC_error">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</span></h1>');
 2347: 	}
 2348: 	&mark_hash_old();
 2349:     }
 2350:     &changewarning($r,'');
 2351:     if ($env{'form.timerange'} eq 'all') {
 2352: # show all documents
 2353: 	$header=&mt('All Documents in '.$crstype);
 2354: 	$allsel=1;
 2355: 	foreach my $key (keys(%hash)) {
 2356: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
 2357: 		my $src=$1;
 2358: 		$changes{$src}=1;
 2359: 	    }
 2360: 	}
 2361:     } else {
 2362: # show documents which changed
 2363: 	%changes=&Apache::lonnet::dump
 2364: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
 2365:                      $env{'course.'.$env{'request.course.id'}.'.num'});
 2366: 	my $firstkey=(keys(%changes))[0];
 2367: 	unless ($firstkey=~/^error\:/) {
 2368: 	    unless ($env{'form.timerange'}) {
 2369: 		$env{'form.timerange'}=604800;
 2370: 	    }
 2371: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
 2372: 		.&mt('seconds');
 2373: 	    if ($env{'form.timerange'}==-1) {
 2374: 		$seltext='since start of course';
 2375: 		$startsel='selected';
 2376: 		$env{'form.timerange'}=time;
 2377: 	    }
 2378: 	    $starttime=time-$env{'form.timerange'};
 2379: 	    if ($env{'form.timerange'}==2592000) {
 2380: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
 2381: 		$monthsel='selected';
 2382: 	    } elsif ($env{'form.timerange'}==604800) {
 2383: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
 2384: 		$weeksel='selected';
 2385: 	    } elsif ($env{'form.timerange'}==86400) {
 2386: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
 2387: 		$daysel='selected';
 2388: 	    }
 2389: 	    $header=&mt('Content changed').' '.$seltext;
 2390: 	} else {
 2391: 	    $header=&mt('No content modifications yet.');
 2392: 	}
 2393:     }
 2394:     %setversions=&Apache::lonnet::dump('resourceversions',
 2395: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
 2396: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
 2397:     my %lt=&Apache::lonlocal::texthash
 2398: 	      ('st' => 'Version changes since start of '.$crstype,
 2399: 	       'lm' => 'Version changes since last Month',
 2400: 	       'lw' => 'Version changes since last Week',
 2401: 	       'sy' => 'Version changes since Yesterday',
 2402:                'al' => 'All Resources (possibly large output)',
 2403: 	       'sd' => 'Display',
 2404: 	       'fi' => 'File',
 2405: 	       'md' => 'Modification Date',
 2406:                'mr' => 'Most recently published Version',
 2407: 	       've' => 'Version used in '.$crstype,
 2408:                'vu' => 'Set Version to be used in '.$crstype,
 2409: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
 2410: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
 2411: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
 2412: 	       'di' => 'Differences');
 2413:     $r->print(<<ENDHEADERS);
 2414: <form action="/adm/coursedocs" method="post">
 2415: <input type="hidden" name="versions" value="1" />
 2416: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
 2417: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
 2418: <select name="timerange">
 2419: <option value='all' $allsel>$lt{'al'}</option>
 2420: <option value="-1" $startsel>$lt{'st'}</option>
 2421: <option value="2592000" $monthsel>$lt{'lm'}</option>
 2422: <option value="604800" $weeksel>$lt{'lw'}</option>
 2423: <option value="86400" $daysel>$lt{'sy'}</option>
 2424: </select>
 2425: <input type="submit" name="display" value="$lt{'sd'}" />
 2426: <h3>$header</h3>
 2427: <input type="submit" name="setversions" value="$lt{'sv'}" />
 2428: <table border="0">
 2429: ENDHEADERS
 2430:     foreach my $key (sort(keys(%changes))) {
 2431: 	if ($changes{$key}>$starttime) {
 2432: 	    my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
 2433: 	    my $currentversion=&Apache::lonnet::getversion($key);
 2434: 	    if ($currentversion<0) {
 2435: 		$currentversion=&mt('Could not be determined.');
 2436: 	    }
 2437: 	    my $linkurl=&Apache::lonnet::clutter($key);
 2438: 	    $r->print(
 2439: 		      '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
 2440: 		      &Apache::lonnet::gettitle($linkurl).
 2441:                       '</b></font></td></tr>'.
 2442:                       '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
 2443:                       '<td colspan="4">'.
 2444:                       '<a href="'.$linkurl.'" target="cat">'.$linkurl.
 2445: 		      '</a></td></tr>'.
 2446:                       '<tr><td></td>'.
 2447:                       '<td title="'.$lt{'md'}.'">'.
 2448: 		      &Apache::lonlocal::locallocaltime(
 2449:                            &Apache::lonnet::metadata($root.'.'.$extension,
 2450:                                                      'lastrevisiondate')
 2451:                                                         ).
 2452:                       '</td>'.
 2453:                       '<td title="'.$lt{'mr'}.'"><span class="LC_nobreak">Most Recent: '.
 2454:                       '<font size="+1">'.$currentversion.'</font>'.
 2455:                       '</span></td>'.
 2456:                       '<td title="'.$lt{'ve'}.'"><span class="LC_nobreak">In '.$crstype.': '.
 2457:                       '<font size="+1">');
 2458: # Used in course
 2459: 	    my $usedversion=$hash{'version_'.$linkurl};
 2460: 	    if (($usedversion) && ($usedversion ne 'mostrecent')) {
 2461: 		$r->print($usedversion);
 2462: 	    } else {
 2463: 		$r->print($currentversion);
 2464: 	    }
 2465: 	    $r->print('</font></span></td><td title="'.$lt{'vu'}.'">'.
 2466:                       '<span class="LC_nobreak">Use: ');
 2467: # Set version
 2468: 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
 2469: 						      'set_version_'.$linkurl,
 2470: 						      ('select_form_order' =>
 2471: 						       ['',1..$currentversion,'mostrecent'],
 2472: 						       '' => '',
 2473: 						       'mostrecent' => &mt('most recent'),
 2474: 						       map {$_,$_} (1..$currentversion))));
 2475: 	    $r->print('</span></td></tr><tr><td></td>');
 2476: 	    my $lastold=1;
 2477: 	    for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
 2478: 		my $url=$root.'.'.$prevvers.'.'.$extension;
 2479: 		if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
 2480: 		    $starttime) {
 2481: 		    $lastold=$prevvers;
 2482: 		}
 2483: 	    }
 2484:             #
 2485:             # Code to figure out how many version entries should go in
 2486:             # each of the four columns
 2487:             my $entries_per_col = 0;
 2488:             my $num_entries = ($currentversion-$lastold);
 2489:             if ($num_entries % 4 == 0) {
 2490:                 $entries_per_col = $num_entries/4;
 2491:             } else {
 2492:                 $entries_per_col = $num_entries/4 + 1;
 2493:             }
 2494:             my $entries_count = 0;
 2495:             $r->print('<td valign="top"><font size="-2">');
 2496:             my $cols_output = 1;
 2497:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
 2498: 		my $url=$root.'.'.$prevvers.'.'.$extension;
 2499: 		$r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
 2500: 			  '">'.&mt('Version').' '.$prevvers.'</a> ('.
 2501: 			  &Apache::lonlocal::locallocaltime(
 2502:                                 &Apache::lonnet::metadata($url,
 2503:                                                           'lastrevisiondate')
 2504:                                                             ).
 2505: 			  ')');
 2506: 		if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
 2507:                     $r->print(' <a href="/adm/diff?filename='.
 2508: 			      &Apache::lonnet::clutter($root.'.'.$extension).
 2509: 			      '&versionone='.$prevvers.
 2510: 			      '">'.&mt('Diffs').'</a>');
 2511: 		}
 2512: 		$r->print('</span><br />');
 2513:                 if (++$entries_count % $entries_per_col == 0) {
 2514:                     $r->print('</font></td>');
 2515:                     if ($cols_output != 4) {
 2516:                         $r->print('<td valign="top"><font size="-2">');
 2517:                         $cols_output++;
 2518:                     }
 2519:                 }
 2520: 	    }
 2521:             while($cols_output++ < 4) {
 2522:                 $r->print('</font></td><td><font>')
 2523:             }
 2524: 	    $r->print('</font></td></tr>'."\n");
 2525: 	}
 2526:     }
 2527:     $r->print('</table></form>');
 2528:     $r->print('<h1>'.&mt('Done').'.</h1>');
 2529: 
 2530:     &untiehash();
 2531: }
 2532: 
 2533: sub mark_hash_old {
 2534:     my $retie_hash=0;
 2535:     if ($hashtied) {
 2536: 	$retie_hash=1;
 2537: 	&untiehash();
 2538:     }
 2539:     &tiehash('write');
 2540:     $hash{'old'}=1;
 2541:     &untiehash();
 2542:     if ($retie_hash) { &tiehash(); }
 2543: }
 2544: 
 2545: sub is_hash_old {
 2546:     my $untie_hash=0;
 2547:     if (!$hashtied) {
 2548: 	$untie_hash=1;
 2549: 	&tiehash();
 2550:     }
 2551:     my $return=$hash{'old'};
 2552:     if ($untie_hash) { &untiehash(); }
 2553:     return $return;
 2554: }
 2555: 
 2556: sub changewarning {
 2557:     my ($r,$postexec,$message,$url)=@_;
 2558:     if (!&is_hash_old()) { return; }
 2559:     my $pathvar='folderpath';
 2560:     my $path=&escape($env{'form.folderpath'});
 2561:     if (!defined($url)) {
 2562: 	if (defined($env{'form.pagepath'})) {
 2563: 	    $pathvar='pagepath';
 2564: 	    $path=&escape($env{'form.pagepath'});
 2565: 	    $path.='&amp;pagesymb='.&escape($env{'form.pagesymb'});
 2566: 	}
 2567: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
 2568:     }
 2569:     my $course_type = &Apache::loncommon::course_type();
 2570:     if (!defined($message)) {
 2571: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
 2572:     }
 2573:     $r->print("\n\n".
 2574: '<script type="text/javascript">'."\n".
 2575: '// <![CDATA['."\n".
 2576: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
 2577: '// ]]>'."\n".
 2578: '</script>'."\n".
 2579: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
 2580: '<input type="hidden" name="orgurl" value="'.$url.
 2581: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
 2582: &mt($message,' <input type="hidden" name="'.
 2583:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
 2584:     &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
 2585: $help{'Caching'}.'</p></form>'."\n\n");
 2586: }
 2587: 
 2588: 
 2589: sub init_breadcrumbs {
 2590:     my ($form,$text)=@_;
 2591:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 2592:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
 2593: 					    text=>&Apache::loncommon::course_type().' Editor',
 2594: 					    faq=>273,
 2595: 					    bug=>'Instructor Interface',
 2596:                                             help => 'Docs_Adding_Course_Doc'});
 2597:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
 2598: 					    text=>$text,
 2599: 					    faq=>273,
 2600: 					    bug=>'Instructor Interface'});
 2601: }
 2602: 
 2603: 
 2604: 
 2605: 
 2606: sub handler {
 2607:     my $r = shift;
 2608:     &Apache::loncommon::content_type($r,'text/html');
 2609:     $r->send_http_header;
 2610:     return OK if $r->header_only;
 2611:     my $crstype = &Apache::loncommon::course_type();
 2612: 
 2613: 
 2614: # --------------------------------------------- Initialize help topics for this
 2615:     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
 2616: 	               'Adding_External_Resource','Navigate_Content',
 2617: 	               'Adding_Folders','Docs_Overview', 'Load_Map',
 2618: 	               'Supplemental','Score_Upload_Form','Adding_Pages',
 2619: 	               'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
 2620: 	               'Check_Resource_Versions','Verify_Content') {
 2621: 	$help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
 2622:     }
 2623:     # Composite help files
 2624:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
 2625: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
 2626:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
 2627: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
 2628:     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
 2629: 		    'Option_Response_Simple');
 2630:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
 2631: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
 2632:     $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
 2633: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
 2634:     $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
 2635:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
 2636: 
 2637: # does this user have privileges to modify docs
 2638:     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
 2639:   if ($allowed && $env{'form.verify'}) {
 2640:       &init_breadcrumbs('verify','Verify Content');
 2641:       &verifycontent($r);
 2642:   } elsif ($allowed && $env{'form.listsymbs'}) {
 2643:       &init_breadcrumbs('listsymbs','List Symbs');
 2644:       &list_symbs($r);
 2645:   } elsif ($allowed && $env{'form.docslog'}) {
 2646:       &init_breadcrumbs('docslog','Show Log');
 2647:       &docs_change_log($r);
 2648:   } elsif ($allowed && $env{'form.versions'}) {
 2649:       &init_breadcrumbs('versions','Check/Set Resource Versions');
 2650:       &checkversions($r);
 2651:   } elsif ($allowed && $env{'form.dumpcourse'}) {
 2652:       &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
 2653:       &dumpcourse($r);
 2654:   } elsif ($allowed && $env{'form.exportcourse'}) {
 2655:       &init_breadcrumbs('exportcourse','IMS Export');
 2656:       &exportcourse($r);
 2657:   } else {
 2658: # is this a standard course?
 2659: 
 2660:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
 2661:     my $forcestandard = 0;
 2662:     my $forcesupplement;
 2663:     my $script='';
 2664:     my $showdoc=0;
 2665:     my $containertag;
 2666:     my $uploadtag;
 2667: 
 2668: 
 2669:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 2670: 					    ['folderpath','pagepath',
 2671: 					     'pagesymb']);
 2672: # No folderpath, no pagepath, see if we have something stored
 2673:     if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
 2674:         &Apache::loncommon::restore_course_settings('docs_folderpath',
 2675:                                               {'folderpath' => 'scalar'});
 2676:     }
 2677:     if (!$allowed) {
 2678:         unless($env{'form.folderpath'} =~ /^supplemental/) {
 2679:             $env{'form.folderpath'} = '';
 2680:         }
 2681:     }
 2682:     if (!$env{'form.folderpath'} && $allowed) {
 2683:         &Apache::loncommon::restore_course_settings('docs_folderpath',
 2684:                                               {'pagepath' => 'scalar'});
 2685:     }
 2686:     if ($env{'form.pagepath'}) {
 2687:        $env{'form.folderpath'}='';
 2688:     }
 2689:     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
 2690:         $env{'form.folderpath'} = 'supplemental&'.
 2691:                                   &escape(&mt('Supplemental '.$crstype.' Documents')).'&'.
 2692:                                   $env{'form.folderpath'};
 2693:     }
 2694:     &Apache::loncommon::store_course_settings('docs_folderpath',
 2695:                                                 {'pagepath' => 'scalar',
 2696:                                                  'folderpath' => 'scalar'});
 2697:     if ($env{'form.folderpath'}) {
 2698: 	my (@folderpath)=split('&',$env{'form.folderpath'});
 2699: 	$env{'form.foldername'}=&unescape(pop(@folderpath));
 2700: 	$env{'form.folder'}=pop(@folderpath);
 2701:     }
 2702:     if ($env{'form.pagepath'}) {
 2703:         my (@pagepath)=split('&',$env{'form.pagepath'});
 2704:         $env{'form.pagename'}=&unescape(pop(@pagepath));
 2705:         $env{'form.folder'}=pop(@pagepath);
 2706:         $containertag = '<input type="hidden" name="pagepath" value="" />'.
 2707: 	    '<input type="hidden" name="pagesymb" value="" />';
 2708:         $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
 2709: 	    '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';
 2710:     }
 2711:     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
 2712:        $showdoc='/'.$1;
 2713:     }
 2714:     if ($showdoc) { # got called in sequence from course
 2715: 	$allowed=0; 
 2716:     } else {
 2717:        if (($env{'form.folder'}=~/^(?:group|default)_/) ||
 2718:           ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
 2719:            $forcestandard = 1;
 2720:        }
 2721:        $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
 2722: 
 2723:        if ($allowed) {
 2724:          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
 2725:          $script=&Apache::lonratedt::editscript('simple');
 2726:        }
 2727:     }
 2728: 
 2729: # subroutine to list form elements
 2730: sub create_list_elements {
 2731:    my @formarr = @_; 
 2732:    my $list = '';
 2733:    for my $button (@formarr){
 2734: 	for my $picture(keys %$button) {
 2735: 		#my $link = Apache::lonhtmlcommon::htmltag('a' ,$button->{$picture}, {href => "test"}); 
 2736: 		$list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});	
 2737: 	}
 2738:    }
 2739:    return $list;
 2740: }
 2741: 
 2742: # subroutine to create ul from list elements
 2743: sub create_form_ul {
 2744:    my $list = shift;
 2745:    my $ul = Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
 2746:    return $ul;
 2747: }
 2748: 
 2749: # get course data
 2750:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
 2751:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
 2752: 
 2753: # get personal data
 2754:     my $uname=$env{'user.name'};
 2755:     my $udom=$env{'user.domain'};
 2756:     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
 2757: 
 2758: # graphics settings
 2759: 
 2760:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
 2761: 
 2762:     if ($allowed) {
 2763: 	$script .= &editing_js($udom,$uname);
 2764:     }
 2765: # -------------------------------------------------------------------- Body tag
 2766:     $script = '<script type="text/javascript">'."\n"
 2767:               .'// <![CDATA['."\n"
 2768:               .$script."\n"
 2769:               .'// ]]>'."\n"
 2770:               .'</script>'."\n";
 2771: 
 2772:     # Breadcrumbs
 2773:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 2774:     if ($allowed) {
 2775:         &Apache::lonhtmlcommon::add_breadcrumb({
 2776:             href=>"/adm/coursedocs",text=>"$crstype Editor"});
 2777: 
 2778:         $r->print(&Apache::loncommon::start_page("$crstype Editor", $script,
 2779:                                                  {'force_register' => $showdoc,})
 2780:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
 2781:                  .&Apache::lonhtmlcommon::breadcrumbs(
 2782:                      'Editing the Table of Contents for your '.$crstype,
 2783:                      'Docs_Adding_Course_Doc')
 2784:         );
 2785:     } elsif ($showdoc) {
 2786:         $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
 2787:                                                 {'force_register' => $showdoc,}));
 2788:     } else {
 2789:         my $folder=$env{'form.folder'};
 2790:         if ($folder eq '' || $folder eq 'supplemental') {
 2791:             $env{'form.folderpath'} = 'supplemental&'.
 2792:                                       &escape(&mt('Supplemental '.$crstype.' Documents'));
 2793:         }
 2794:         my ($breadcrumbtrail) = &breadcrumbs($allowed,$crstype);
 2795:         $r->print(&Apache::loncommon::start_page("Supplemental documents").
 2796:                   $breadcrumbtrail);
 2797:     }
 2798: 
 2799:   my %allfiles = ();
 2800:   my %codebase = ();
 2801:   my ($upload_result,$upload_output);
 2802:   if ($allowed) {
 2803:       if (($env{'form.uploaddoc.filename'}) &&
 2804: 	  ($env{'form.cmd'}=~/^upload_(\w+)/)) {
 2805: # Process file upload - phase one - upload and parse primary file.
 2806: 	  undef($hadchanges);
 2807:           $upload_result = &process_file_upload(\$upload_output,$coursenum,
 2808: 						$coursedom,\%allfiles,
 2809: 						\%codebase,$1);
 2810: 	  if ($hadchanges) {
 2811: 	      &mark_hash_old();
 2812: 	  }
 2813:           if ($upload_result eq 'phasetwo') {
 2814:               $r->print($upload_output);
 2815:           }
 2816:       } elsif ($env{'form.phasetwo'}) {
 2817:           my %newname = ();
 2818:           my %origname = ();
 2819:           my %attribs = ();
 2820:           my $updateflag = 0;
 2821:           my $residx = $env{'form.newidx'};
 2822:           my $primary_url = &unescape($env{'form.primaryurl'});
 2823: # Process file upload - phase two - gather secondary files.
 2824:           for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
 2825:               if ($env{'form.embedded_item_'.$i.'.filename'}) {
 2826:                   my $javacodebase;
 2827:                   $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
 2828:                   $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
 2829:                   if (exists($env{'form.embedded_codebase_'.$i})) {
 2830:                       $javacodebase =  &unescape($env{'form.embedded_codebase_'.$i});
 2831:                       $origname{$i} =~ s#^\Q$javacodebase\E/##;
 2832:                   }
 2833:                   my @attributes = ();
 2834:                   if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
 2835:                       @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});
 2836:                   } else {
 2837:                       @attributes = ($env{'form.embedded_attrib_'.$i});
 2838:                   }
 2839:                   foreach my $attr (@attributes) {
 2840:                       push(@{$attribs{$i}},&unescape($attr));
 2841:                   }
 2842:                   if ($javacodebase) {
 2843:                       $codebase{$i} = $javacodebase;
 2844:                       $codebase{$i} =~ s#/$##;
 2845:                       $updateflag = 1;
 2846:                   }
 2847:               }
 2848:               unless ($newname{$i} eq $origname{$i}) {
 2849:                   $updateflag = 1;
 2850:               }
 2851:           }
 2852: # Process file upload - phase three - modify primary file
 2853:           if ($updateflag) {
 2854:               my ($content,$rtncode);
 2855:               my $updateflag = 0;
 2856:               my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
 2857:               if ($getstatus eq 'ok') {
 2858:                   foreach my $item (keys(%newname)) {
 2859:                       if ($newname{$item} ne $origname{$item}) {
 2860:                           my $attrib_regexp = '';
 2861:                           if (@{$attribs{$item}} > 1) {
 2862:                               $attrib_regexp = join('|',@{$attribs{$item}});
 2863:                           } else {
 2864:                               $attrib_regexp = $attribs{$item}[0];
 2865:                           }
 2866:                           if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
 2867:                           }
 2868:                           $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
 2869:                       }
 2870:                       if (exists($codebase{$item})) {
 2871:                           $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
 2872:                       }
 2873:                   }
 2874: # Save edited file.
 2875:                   my $saveresult;
 2876:                   my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
 2877:                   my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
 2878:                   my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
 2879:               } else {
 2880:                   &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
 2881:               }
 2882:           }
 2883:       }
 2884:   }
 2885: 
 2886:   unless ($showdoc ||  $upload_result eq 'phasetwo') {
 2887: # -----------------------------------------------------------------------------
 2888:        my %lt=&Apache::lonlocal::texthash(
 2889:                 'uplm' => 'Upload a new main '.lc($crstype).' document',
 2890:                 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
 2891:                 'impp' => 'Import a document',
 2892: 		'copm' => 'All documents out of a published map into this folder',
 2893:                 'upld' => 'Import Document',
 2894:                 'srch' => 'Search',
 2895:                 'impo' => 'Import',
 2896: 		'book' => 'Import Bookmarks',
 2897:                 'selm' => 'Select Map',
 2898:                 'load' => 'Load Map',
 2899:                 'reco' => 'Recover Deleted Resources',
 2900:                 'newf' => 'New Folder',
 2901:                 'newp' => 'New Composite Page',
 2902:                 'extr' => 'External Resource',
 2903:                 'syll' => 'Syllabus',
 2904:                 'navc' => 'Navigate Contents',
 2905:                 'sipa' => 'Simple Course Page',
 2906:                 'sipr' => 'Simple Problem',
 2907:                 'drbx' => 'Drop Box',
 2908:                 'scuf' => 'Score Upload Form',
 2909:                 'bull' => 'Discussion Board',
 2910:                 'mypi' => 'My Personal Information Page',
 2911:                 'grpo' => 'Group Portfolio',
 2912:                 'rost' => 'Course Roster',
 2913: 				'abou' => 'Personal Information Page for a User',
 2914:                 'imsf' => 'IMS Import',
 2915:                 'imsl' => 'Import IMS package',
 2916:                 'file' =>  'File',
 2917:                 'title' => 'Title',
 2918:                 'comment' => 'Comment',
 2919:                 'parse' => 'Upload embedded images/multimedia files if HTML file',
 2920: 		'nd' => 'Upload Document',
 2921: 		'pm' => 'Published Map',
 2922: 		'sd' => 'Special Document',
 2923: 		'mo' => 'More Options',
 2924: 					  );
 2925: # -----------------------------------------------------------------------------
 2926: 	my $fileupload=(<<FIUP);
 2927: 	$lt{'file'}:<br />
 2928: 	<input type="file" name="uploaddoc" size="40" />
 2929: FIUP
 2930: 
 2931: 	my $checkbox=(<<CHBO);
 2932: 	<!-- <label>$lt{'parse'}?
 2933: 	<input type="checkbox" name="parserflag" />
 2934: 	</label> -->
 2935: 	<label>
 2936: 	<input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
 2937: 	</label>
 2938: CHBO
 2939: 
 2940:     my $fileuploada = "<input type='submit' value='".$lt{'upld'}."' /> $help{'Uploading_From_Harddrive'}";
 2941: 	my $fileuploadform=(<<FUFORM);
 2942: 	<form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
 2943: 	<input type="hidden" name="active" value="aa" />
 2944: 	$fileupload
 2945: 	<br />
 2946: 	$lt{'title'}:<br />
 2947: 	<input type="text" size="50" name="comment" />
 2948: 	$uploadtag
 2949: 	<input type="hidden" name="cmd" value="upload_default" />
 2950: 	<br />
 2951: 	<span class="LC_nobreak">
 2952: 	$checkbox
 2953: 	</span>
 2954: FUFORM
 2955:     #$list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});	
 2956:     #$fileuploadform .= create_form_ul(create_list_elements(@fileuploada));
 2957:     $fileuploadform .= create_form_ul(Apache::lonhtmlcommon::htmltag('li',$fileuploada,{class => 'LC_menubuttons_inline_text'}));
 2958: 	$fileuploadform .= (<<FUFORM);
 2959: 	</form>
 2960: FUFORM
 2961: 
 2962: 	my $simpleeditdefaultform=(<<SEDFFORM);
 2963: 	<form action="/adm/coursedocs" method="post" name="simpleeditdefault">
 2964: 	<input type="hidden" name="active" value="bb" />
 2965: SEDFFORM
 2966: 	my @simpleeditdefaultforma = ( 
 2967: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'"  onclick="javascript:groupsearch()" />' => "$uploadtag<a onclick='javascript:groupsearch()'>$lt{'srch'}</a>" },
 2968: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'"  onclick="javascript:groupimport();"/>' => "<a onclick='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
 2969: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/vbkm.png" alt="'.$lt{book}.'" onclick="javascript:groupopen(0,1,1);" />' => "<a onclick='javascript:groupopen(0,1,1);'>$lt{'book'}</a>" },
 2970: 	);
 2971: 	$simpleeditdefaultform .= create_form_ul(create_list_elements(@simpleeditdefaultforma));
 2972: 	$simpleeditdefaultform .=(<<SEDFFORM);
 2973: 	<hr />
 2974: 	<p>
 2975: 	$lt{'copm'}<br />
 2976: 	<input type="text" size="40" name="importmap" /><br />
 2977: 	<span class="LC_nobreak"><input type="button"
 2978: 	onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
 2979: 	value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
 2980: 	$help{'Load_Map'}</span>
 2981: 	</p>
 2982: 	</form>
 2983: SEDFFORM
 2984: 
 2985: 	my $extresourcesform=(<<ERFORM);
 2986: 	<form action="/adm/coursedocs" method="post" name="newext">
 2987: 	$uploadtag
 2988: 	<input type="hidden" name="importdetail" value="" />
 2989: 	<a onclick="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
 2990: 	</form>
 2991: ERFORM
 2992: 
 2993:     if ($allowed) {
 2994: 	&update_paste_buffer($coursenum,$coursedom);
 2995:        my %lt=&Apache::lonlocal::texthash(
 2996: 					 'vc' => 'Verify Content',
 2997: 					 'cv' => 'Check/Set Resource Versions',
 2998: 					 'ls' => 'List Symbs',
 2999:                                          'sl' => 'Show Log'
 3000: 					  );
 3001: 
 3002:        my $folderpath=$env{'form.folderpath'};
 3003:        if (!$folderpath) {
 3004: 	   if ($env{'form.folder'} eq '' ||
 3005: 	       $env{'form.folder'} eq 'supplemental') {
 3006: 	       $folderpath='default&'.
 3007: 		   &escape(&mt('Main '.$crstype.' Documents'));
 3008: 	   }
 3009:        }
 3010:        unless ($env{'form.pagepath'}) {
 3011:            $containertag = '<input type="hidden" name="folderpath" value="" />';
 3012:            $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
 3013:        }
 3014: 	$r->print(<<HIDDENFORM);
 3015: 	<form name="renameform" method="post" action="/adm/coursedocs">
 3016:    <input type="hidden" name="title" />
 3017:    <input type="hidden" name="cmd" />
 3018:    <input type="hidden" name="markcopy" />
 3019:    <input type="hidden" name="copyfolder" />
 3020:    $containertag
 3021:  </form>
 3022:  <form name="simpleedit" method="post" action="/adm/coursedocs">
 3023:    <input type="hidden" name="importdetail" value="" />
 3024:    $uploadtag
 3025:  </form>
 3026: HIDDENFORM
 3027:     }
 3028: # --------------------------------------------------------- Main tab structure
 3029:  
 3030:     my $activeClass = 1;
 3031:     my $active = '';
 3032:     my %tabtitles = (
 3033:                        main => {
 3034:                                  Course => &mt('Main Course Documents'),
 3035:                                  Community => &mt('Main Community Documents'),
 3036:                                },
 3037:                        supplemental => {
 3038:                                  Course => &mt('Supplemental Course Documents'),        
 3039:                                  Community => &mt('Supplemental Community Documents'),
 3040:                                },
 3041:                     );
 3042:     if ($allowed) {
 3043:         $r->print('<ul class="LC_TabContentBigger" id="mainnav">');
 3044:         if (($standard) && ($allowed) && (!$forcesupplement) && (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'}eq"" || ($env{'form.pagepath'}))) {
 3045:             if($activeClass == 1){
 3046:                 $active = 'class="active"';
 3047: 	        $activeClass = 0;
 3048: 	    }
 3049:         }
 3050:         $r->print('<li '.$active.' onclick="javascript:showPage(this,\'mainCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.$tabtitles{'main'}{$crstype}.'</b></a></li>');
 3051:         $active = '';
 3052:         if (!$forcestandard || ($env{'form.folderpath'}=~/^supplemental/)) {
 3053:             if($activeClass == 1){
 3054:                 $active = 'class="active"';
 3055:             }
 3056:         }
 3057:         $r->print('<li '.$active.' onclick="javascript:showPage(this,\'supplCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.$tabtitles{'supplemental'}{$crstype}.'</b></a></li>');
 3058:         $r->print('</ul>');
 3059:     } else {
 3060:         $r->print('<br />');
 3061:     }
 3062:     $r->print('<div class="LC_Box" style="clear:both;margin:0;">'
 3063:              .'<div id="maincoursedoc" style="margin:0 0;padding:0 0;">');
 3064: # --------------------------------------------------------- Standard documents
 3065:        my $savefolderpath;
 3066:        $active = 'style="display: none;"';
 3067:        if($activeClass == 0){
 3068:           $active = 'style="display: block;"';
 3069:        }
 3070:        if ($allowed) {
 3071:        $r->print('<div class="LC_ContentBox" id="mainCourseDocuments" '.$active.'>');
 3072:        my $folder=$env{'form.folder'};
 3073:        if ($folder eq '' || $folder=~/^supplemental/) {
 3074:            $folder='default';
 3075: 	   $savefolderpath = $env{'form.folderpath'};
 3076: 	   $env{'form.folderpath'}='default&'.&escape($tabtitles{'main'}{$crstype});
 3077:            $uploadtag = '<input type="hidden" name="folderpath" value="'.
 3078: 	       &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
 3079:        }
 3080:        my $postexec='';
 3081:        if ($folder eq 'default') {
 3082:            $r->print('<script type="text/javascript">'."\n"
 3083:                     .'// <![CDATA['."\n"
 3084:                     .'this.window.name="loncapaclient";'."\n"
 3085:                     .'// ]]>'."\n"
 3086:                     .'</script>'."\n"
 3087:        );
 3088:        } else {
 3089:            #$postexec='self.close();';
 3090:        }
 3091:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 3092:                      '.sequence';
 3093:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 3094:                      '.page';
 3095: 	my $container='sequence';
 3096: 	if ($env{'form.pagepath'}) {
 3097: 	    $container='page';
 3098: 	}
 3099: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
 3100: 
 3101: 
 3102: 
 3103: 	my $recoverform=(<<RFORM);
 3104: 	<form action="/adm/groupsort" method="post" name="recover">
 3105: 	<a onclick="javascript:groupopen('$readfile',1,0)">$lt{'reco'}</a>
 3106: 	</form>
 3107: RFORM
 3108: 
 3109: 	my $imspform=(<<IMSPFORM);
 3110: 	<form action="/adm/imsimportdocs" method="post" name="ims">
 3111: 	<input type="hidden" name="folder" value="$folder" />
 3112: 	<a onclick="javascript:makeims();">$lt{'imsf'}</a>
 3113: 	</form>
 3114: IMSPFORM
 3115: 
 3116: 	my $newnavform=(<<NNFORM);
 3117: 	<form action="/adm/coursedocs" method="post" name="newnav">
 3118: 	<input type="hidden" name="active" value="cc" />
 3119: 	$uploadtag
 3120: 	<input type="hidden" name="importdetail" 
 3121: 	value="$lt{'navc'}=/adm/navmaps" />
 3122: 	<a onclick="document.newnav.submit()">$lt{'navc'}</a>
 3123: 	$help{'Navigate_Content'}
 3124: 	</form>
 3125: NNFORM
 3126: 	my $newsmppageform=(<<NSPFORM);
 3127: 	<form action="/adm/coursedocs" method="post" name="newsmppg">
 3128: 	<input type="hidden" name="active" value="cc" />
 3129: 	$uploadtag
 3130: 	<input type="hidden" name="importdetail" value="" />
 3131: 	<a onclick="javascript:makesmppage();"> $lt{'sipa'}</a>
 3132: 	$help{'Simple Page'}
 3133: 	</form>
 3134: NSPFORM
 3135: 
 3136: 	my $newsmpproblemform=(<<NSPROBFORM);
 3137: 	<form action="/adm/coursedocs" method="post" name="newsmpproblem">
 3138: 	<input type="hidden" name="active" value="cc" />
 3139: 	$uploadtag
 3140: 	<input type="hidden" name="importdetail" value="" />
 3141: 	<a onclick="javascript:makesmpproblem();">$lt{'sipr'}</a>
 3142: 	$help{'Simple Problem'}
 3143: 	</form>
 3144: 
 3145: NSPROBFORM
 3146: 
 3147: 	my $newdropboxform=(<<NDBFORM);
 3148: 	<form action="/adm/coursedocs" method="post" name="newdropbox">
 3149: 	<input type="hidden" name="active" value="cc" />
 3150: 	$uploadtag
 3151: 	<input type="hidden" name="importdetail" value="" />
 3152: 	<a onclick="javascript:makedropbox();">$lt{'drbx'}</a>
 3153: 	</form>
 3154: NDBFORM
 3155: 
 3156: 	my $newexuploadform=(<<NEXUFORM);
 3157: 	<form action="/adm/coursedocs" method="post" name="newexamupload">
 3158: 	<input type="hidden" name="active" value="cc" />
 3159: 	$uploadtag
 3160: 	<input type="hidden" name="importdetail" value="" />
 3161: 	<a onclick="javascript:makeexamupload();">$lt{'scuf'}</a>
 3162: 	$help{'Score_Upload_Form'}
 3163: 	</form>
 3164: NEXUFORM
 3165: 
 3166: 	my $newbulform=(<<NBFORM);
 3167: 	<form action="/adm/coursedocs" method="post" name="newbul">
 3168: 	<input type="hidden" name="active" value="cc" />
 3169: 	$uploadtag
 3170: 	<input type="hidden" name="importdetail" value="" />
 3171: 	<a onclick="javascript:makebulboard();" >$lt{'bull'}</a>
 3172: 	$help{'Bulletin Board'}
 3173: 	</form>
 3174: NBFORM
 3175: 
 3176: 	my $newaboutmeform=(<<NAMFORM);
 3177: 	<form action="/adm/coursedocs" method="post" name="newaboutme">
 3178: 	<input type="hidden" name="active" value="cc" />
 3179: 	$uploadtag
 3180: 	<input type="hidden" name="importdetail" 
 3181: 	value="$plainname=/adm/$udom/$uname/aboutme" />
 3182: 	<a onclick="document.newaboutme.submit()">$lt{'mypi'}</a>
 3183: 	$help{'My Personal Information Page'}
 3184: 	</form>
 3185: NAMFORM
 3186: 
 3187: 	my $newaboutsomeoneform=(<<NASOFORM);
 3188: 	<form action="/adm/coursedocs" method="post" name="newaboutsomeone">
 3189: 	<input type="hidden" name="active" value="cc" />
 3190: 	$uploadtag
 3191: 	<input type="hidden" name="importdetail" value="" />
 3192: 	<a onclick="javascript:makeabout();">$lt{'abou'}</a>
 3193: 	</form>
 3194: NASOFORM
 3195: 
 3196: 
 3197: 	my $newrosterform=(<<NROSTFORM);
 3198: 	<form action="/adm/coursedocs" method="post" name="newroster">
 3199: 	<input type="hidden" name="active" value="cc" />
 3200: 	$uploadtag
 3201: 	<input type="hidden" name="importdetail" 
 3202: 	value="$lt{'rost'}=/adm/viewclasslist" />
 3203: 	<a onclick="document.newroster.submit()">$lt{'rost'}</a>
 3204: 	$help{'Course Roster'}
 3205: 	</form>
 3206: NROSTFORM
 3207: 
 3208: my $specialdocumentsform;
 3209: my @specialdocumentsforma;
 3210: my $newfolderform;
 3211: my $newfolderb;
 3212: 
 3213:        unless ($env{'form.pagepath'}) {
 3214: 	   my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
 3215: 	
 3216: 	my $newpageform=(<<NPFORM);
 3217: 	<form action="/adm/coursedocs" method="post" name="newpage">
 3218: 	<input type="hidden" name="folderpath" value="$path" />
 3219: 	<input type="hidden" name="importdetail" value="" />
 3220: 	<input type="hidden" name="active" value="cc" />
 3221: 	<a onclick="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
 3222: 	$help{'Adding_Pages'}
 3223: 	</form>
 3224: NPFORM
 3225: 
 3226: 
 3227: 	$newfolderform=(<<NFFORM);
 3228: 	<form action="/adm/coursedocs" method="post" name="newfolder">
 3229: 	<input type="hidden" name="folderpath" value="$path" />
 3230: 	<input type="hidden" name="importdetail" value="" />
 3231: 	<input type="hidden" name="active" value="aa" />
 3232: 	<a onclick="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
 3233: 	</form>
 3234: NFFORM
 3235: 
 3236: 	my $newsylform=(<<NSYLFORM);
 3237: 	<form action="/adm/coursedocs" method="post" name="newsyl">
 3238: 	<input type="hidden" name="active" value="cc" />
 3239: 	$uploadtag
 3240: 	<input type="hidden" name="importdetail" 
 3241: 	value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
 3242: 	<a onclick="document.newsyl.submit()">$lt{'syll'}</a>
 3243: 	$help{'Syllabus'}
 3244: 
 3245: 	</form>
 3246: NSYLFORM
 3247: 
 3248: 	my $newgroupfileform=(<<NGFFORM);
 3249: 	<form action="/adm/coursedocs" method="post" name="newgroupfiles">
 3250: 	<input type="hidden" name="active" value="cc" />
 3251: 	$uploadtag
 3252: 	<input type="hidden" name="importdetail"
 3253: 	value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
 3254: 	<a onclick="document.newgroupfiles.submit()">$lt{'grpo'}</a>
 3255: 	$help{'Group Portfolio'}
 3256: 	</form>
 3257: NGFFORM
 3258: 	@specialdocumentsforma=(
 3259: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'"  onclick="javascript:makenewpage(document.newpage,"'.$pageseq.'");" />'=>$newpageform},
 3260: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
 3261: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
 3262: 	); 
 3263: 	
 3264:       }
 3265: 	push @specialdocumentsforma, ({'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
 3266: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
 3267: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
 3268: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
 3269: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
 3270: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
 3271: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
 3272: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
 3273: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/chrt.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},);
 3274: 
 3275: 	$specialdocumentsform = create_form_ul(create_list_elements(@specialdocumentsforma));
 3276: 
 3277: if($env{'form.pagepath'}) {
 3278: 	
 3279: 	@specialdocumentsforma=(
 3280: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.&mt('Simple Problem').'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
 3281: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.&mt('Score Upload Form').'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
 3282: 	);
 3283: 	$specialdocumentsform= create_form_ul(create_list_elements(@specialdocumentsforma));
 3284: }
 3285: 
 3286: my @tools = (
 3287: #	{'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" />'=>$extresourcesform},
 3288: #	{'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" />'=>$imspform},
 3289: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/recover.png" alt="'.$lt{reco}.'" onclick="javascript:groupopen(\''.$readfile.'\',1,0)" />'=>$recoverform},
 3290: 	);
 3291: 
 3292: my @importdoc = (
 3293:     {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'newext\');" />'=>$extresourcesform},
 3294:     {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:makeims();" />'=>$imspform}, 
 3295: );
 3296: $fileuploadform =  create_form_ul(create_list_elements(@importdoc)) . '<hr/>' . $fileuploadform;
 3297: my %orderhash = (
 3298: 		'00' => ['Newfolder',$newfolderform],
 3299:                 'aa' => ['Import Documents',$fileuploadform],
 3300:                 'bb' => ['Published Resources',$simpleeditdefaultform],
 3301:                 'cc' => ['Special Documents',$specialdocumentsform],
 3302: 		'dd' => ['Tools', create_form_ul(create_list_elements(@tools)).&generate_admin_options($containertag,$uploadtag,\%help,\%env)],
 3303:                 );
 3304: my $tid='1';
 3305:  $hadchanges=0;
 3306:         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
 3307:        if ($error) {
 3308:            $r->print('<p><span class="LC_error">'.$error.'</span></p>');
 3309:        }
 3310:        if ($hadchanges) {
 3311:            &mark_hash_old();
 3312:        }
 3313: 
 3314:        &changewarning($r,'');
 3315: $r->print(&generate_edit_table($tid,\%orderhash));
 3316: 
 3317: $r->print('</div>');
 3318: 	}
 3319:        if ($env{'form.pagepath'}) {
 3320:        }
 3321: # ----------------------------------------------------- Supplemental documents
 3322:        $active = 'style="display: none;"';
 3323:        if($activeClass == 1){
 3324:           $active = 'style="display: block;"';
 3325:        }
 3326:        $r->print('<div class="LC_ContentBox" id="supplCourseDocuments" '.$active.'>');
 3327:        my $folder=$env{'form.folder'};
 3328:        unless ($folder=~/^supplemental/) {
 3329: 	   $folder='supplemental';
 3330:        }
 3331:        if ($folder =~ /^supplemental$/ &&
 3332: 	   (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
 3333:           $env{'form.folderpath'} = 'supplemental&'.
 3334:                                     &escape(&mt('Supplemental '.$crstype.' Documents'));
 3335:        } elsif ($allowed) {
 3336: 	  $env{'form.folderpath'} = $savefolderpath;
 3337:        }
 3338:        $env{'form.pagepath'} = '';
 3339:        if ($allowed) {
 3340: 	   my $folderseq=
 3341: 	       '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
 3342: 	       '.sequence';
 3343: 
 3344: 	   my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
 3345: 
 3346: 	my $supupdocformbtn = "<input type='submit' value='".$lt{'upld'}."' />$help{'Uploading_From_Harddrive'}";
 3347: 	my $supupdocform=(<<SUPDOCFORM);
 3348: 	<form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
 3349: 	<input type="hidden" name="active" value="ee" />	
 3350: 	$fileupload
 3351: 	<br />
 3352: 	<br />
 3353: 	<span class="LC_nobreak">
 3354: 	$checkbox
 3355: 	</span>
 3356: 	<br /><br />
 3357: 	$lt{'comment'}:<br />
 3358: 	<textarea cols="50" rows="4" name="comment"></textarea>
 3359: 	<br />
 3360: 	<input type="hidden" name="folderpath" value="$path" />
 3361: 	<input type="hidden" name="cmd" value="upload_supplemental" />
 3362: SUPDOCFORM
 3363: 	$supupdocform .=  create_form_ul(Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."</form>";
 3364: 
 3365: 	my $supnewfolderform=(<<SNFFORM);
 3366: 	<form action="/adm/coursedocs" method="post" name="supnewfolder">
 3367: 	<input type="hidden" name="active" value="ee" />
 3368: 	<input type="hidden" name="folderpath" value="$path" />
 3369: 	<input type="hidden" name="importdetail" value="" />
 3370: 	<a onclick="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a> 
 3371: 	$help{'Adding_Folders'}
 3372: 	</form>
 3373: SNFFORM
 3374: 	
 3375: 
 3376: 	my $supnewextform=(<<SNEFORM);
 3377: 	<form action="/adm/coursedocs" method="post" name="supnewext">
 3378: 	<input type="hidden" name="active" value="ff" />
 3379: 	<input type="hidden" name="folderpath" value="$path" />
 3380: 	<input type="hidden" name="importdetail" value="" />
 3381: 	<a onclick="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
 3382: 	</form>
 3383: SNEFORM
 3384: 
 3385: 	my $supnewsylform=(<<SNSFORM);
 3386: 	<form action="/adm/coursedocs" method="post" name="supnewsyl">
 3387: 	<input type="hidden" name="active" value="ff" />
 3388: 	<input type="hidden" name="folderpath" value="$path" />
 3389: 	<input type="hidden" name="importdetail" 
 3390: 	value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
 3391: 	<a onclick="document.supnewsyl.submit()">$lt{'syll'}</a>
 3392: 	$help{'Syllabus'}
 3393: 	</form>
 3394: SNSFORM
 3395: 
 3396: 	my $supnewaboutmeform=(<<SNAMFORM);
 3397: 	<form action="/adm/coursedocs" method="post" name="supnewaboutme">
 3398: 	<input type="hidden" name="active" value="ff" />
 3399: 	<input type="hidden" name="folderpath" value="$path" />
 3400: 	<input type="hidden" name="importdetail" 
 3401: 	value="$plainname=/adm/$udom/$uname/aboutme" />
 3402: 	<a onclick="document.supnewaboutme.submit()">$lt{'mypi'}</a>
 3403: 	$help{'My Personal Information Page'}
 3404: 	</form>
 3405: SNAMFORM
 3406: 
 3407: 
 3408: my @specialdocs = (
 3409: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
 3410:             =>$supnewsylform},
 3411: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
 3412:             =>$supnewaboutmeform},
 3413: 		);
 3414: my @supimportdoc = (
 3415: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'supnewext\');" />'
 3416:             =>$supnewextform},
 3417:         );
 3418: $supupdocform =  create_form_ul(create_list_elements(@supimportdoc)) . '<hr/>' . $supupdocform;
 3419: my %suporderhash = (
 3420: 		'00' => ['Supnewfolder', $supnewfolderform],
 3421:                 'ee' => ['Import Documents',$supupdocform],
 3422:                 'ff' => ['Special Documents',create_form_ul(create_list_elements(@specialdocs))]
 3423:                 );
 3424: 
 3425:         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
 3426:         if ($error) {
 3427:             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
 3428:         }
 3429:         my $tid='2';
 3430:         $r->print(&generate_edit_table($tid,\%suporderhash));
 3431:     } else {
 3432:         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
 3433:         if ($error) {
 3434:             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
 3435:         }
 3436:     }
 3437: 
 3438: 
 3439: $r->print('</div>');
 3440: $r->print('</div></div>');
 3441: 
 3442: 
 3443:     if ($allowed) {
 3444: 	$r->print('
 3445: <form method="post" name="extimport" action="/adm/coursedocs">
 3446:   <input type="hidden" name="title" />
 3447:   <input type="hidden" name="url" />
 3448:   <input type="hidden" name="useform" />
 3449:   <input type="hidden" name="residx" />
 3450: </form>');
 3451:     }
 3452:   } else {
 3453:       unless ($upload_result eq 'phasetwo') {
 3454: # -------------------------------------------------------- This is showdoc mode
 3455:           $r->print("<h1>".&mt('Uploaded Document').' - '.
 3456: 		&Apache::lonnet::gettitle($r->uri).'</h1><p>'.
 3457: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
 3458:           &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
 3459:       }
 3460:   }
 3461:  }
 3462:  $r->print(&Apache::loncommon::end_page());
 3463:  return OK;
 3464: }
 3465: 
 3466: sub generate_admin_options {
 3467:   my ($containertag,$uploadtag,$help_ref,$env_ref) = @_;
 3468:  my %lt=&Apache::lonlocal::texthash(
 3469:                                          'vc' => 'Verify Content',
 3470:                                          'cv' => 'Check/Set Resource Versions',
 3471:                                          'ls' => 'List Symbs',
 3472:                                          'sl' => 'Show Log',
 3473:                                          'imse' => 'IMS Export',
 3474:                                          'dcd' => 'Dump Course DOCS to Construction Space: available on other servers'
 3475:                                           );
 3476:   my %help = %{$help_ref};
 3477:   my %env = %{$env_ref};
 3478:   my $dumpbut=&dumpbutton();
 3479:   my $exportbut=&exportbutton();
 3480:   my @list = (
 3481: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/verify.png" alt="'.$lt{vc}.'"  onclick=\'javascript:injectData(document.courseverify, "dummy", "verify", "'.$lt{'vc'}.'")\' />' 
 3482:         => "<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"verify\", \"$lt{'vc'}\")'>$lt{'vc'}</a>$help{'Verify_Content'}"},
 3483: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/resversion.png" alt="'.$lt{cv}.'"  onclick=\'javascript:injectData(document.courseverify, "dummy", "versions", "'.$lt{'cv'}.'")\' />'
 3484:         =>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"versions\", \"$lt{'cv'}\")'>$lt{'cv'}</a>$help{'Check_Resource_Versions'}"},
 3485: 	);
 3486:   if($dumpbut ne ''){
 3487:   push @list, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dump.png" alt="'.$lt{dcd}.'" />'=>$dumpbut};
 3488:   }
 3489:   push @list, ({'<img class="LC_noBorder LC_middle" src="/res/adm/pages/imsexport.png" alt="'.$lt{imse}.'" onclick=\'javascript:injectData(document.courseverify, "dummy", "exportcourse", "'.&mt('IMS Export').'")\' />'
 3490:           =>$exportbut},
 3491: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/symbs.png" alt="'.$lt{ls}.'"  onclick=\'javascript:injectData(document.courseverify, "dummy", "listsymbs", "'.$lt{'ls'}.'")\'  />'
 3492:         =>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"listsymbs\", \"$lt{'ls'}\")'>$lt{'ls'}</a><input type='hidden' name='folder' value='$env{'form.folder'}' />"},
 3493: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/log.png" alt="'.$lt{sl}.'"  onclick=\'javascript:injectData(document.courseverify, "dummy", "docslog", "'.$lt{'sl'}.'")\'  />'
 3494:         =>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"docslog\", \"$lt{'sl'}\")'>$lt{'sl'}</a>"},
 3495: 	);
 3496:   return '<form action="/adm/coursedocs" method="post" name="courseverify"><input type="hidden" id="dummy" />'.create_form_ul(create_list_elements(@list)).'</form>';
 3497: 
 3498: }
 3499: 
 3500: 
 3501: sub generate_edit_table {
 3502:     my ($tid,$orderhash_ref) = @_;
 3503:     return unless(ref($orderhash_ref) eq 'HASH');
 3504:     my %orderhash = %{$orderhash_ref};
 3505:     my $form;
 3506:     my $activetab;
 3507:     my $active;
 3508:     if($env{'form.active'} ne ''){
 3509:         $activetab = $env{'form.active'};
 3510:     }
 3511:     $form = '<div class="LC_Box" style="margin-right:0">';
 3512:     $form .= '<ul id="navigation'.$tid.'" class="LC_TabContent">';
 3513:     foreach my $name (sort(keys(%orderhash))){
 3514:         if($name ne '00'){
 3515:             if($activetab eq '' || $activetab ne $name){
 3516:                $active = '';
 3517:             }elsif($activetab eq $name){
 3518:                $active = 'class="active"';
 3519:             }
 3520:             $form .= '<li '.$active.' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');">'.&mt(${$orderhash{$name}}[0]).'</li>';
 3521:         } else {
 3522: 	    $form .= '<li '.$active.'>'.${$orderhash{$name}}[1].'</li>';
 3523: 
 3524: 	}
 3525:     }
 3526:     $form .= '</ul>';
 3527:     $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; clear: both;">';
 3528:     foreach my $field (keys(%orderhash)){
 3529: 	if($field ne '00'){
 3530:         if($activetab eq '' || $activetab ne $field){
 3531:                 $active = 'style="display: none;"';
 3532:         }elsif($activetab eq $field){
 3533:                 $active = 'style="display:block;"';
 3534:         }
 3535:            $form .= '<div id="'.$field.$tid.'"'
 3536:                    .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
 3537:                    .'</div>';
 3538:         }
 3539:     }
 3540:     $form .= '</div></div>';
 3541: 
 3542:     return $form;
 3543: }
 3544: 
 3545: sub editing_js {
 3546:     my ($udom,$uname) = @_;
 3547:     my $now = time();
 3548:     my %lt = &Apache::lonlocal::texthash(
 3549:                                           p_mnf => 'Name of New Folder',
 3550:                                           t_mnf => 'New Folder',
 3551:                                           p_mnp => 'Name of New Page',
 3552:                                           t_mnp => 'New Page',
 3553:                                           p_mxu => 'Title for the Uploaded Score',
 3554:                                           p_msp => 'Name of Simple Course Page',
 3555:                                           p_msb => 'Title for the Problem',
 3556:                                           p_mdb => 'Title for the Drop Box',
 3557:                                           p_mbb => 'Title for the Discussion Board',
 3558:                                           p_mab => "Enter user:domain for User's Personal Information Page",
 3559:                                           p_mab2 => 'Personal Information Page of ',
 3560:                                           p_mab_alrt1 => 'Not a valid user:domain',
 3561:                                           p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
 3562:                                           p_chn => 'New Title',
 3563:                                           p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
 3564:                                           p_rmr2a => 'Remove[_99]',
 3565:                                           p_rmr2b => '?[_99]',
 3566:                                           p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
 3567:                                           p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
 3568:                                           p_ctr2a => 'Cut[_98]',
 3569:                                           p_ctr2b => '?[_98]'
 3570:                                         );
 3571: 
 3572:     return <<ENDNEWSCRIPT;
 3573: function makenewfolder(targetform,folderseq) {
 3574:     var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
 3575:     if (foldername) {
 3576:        targetform.importdetail.value=escape(foldername)+"="+folderseq;
 3577:         targetform.submit();
 3578:     }
 3579: }
 3580: 
 3581: function makenewpage(targetform,folderseq) {
 3582:     var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
 3583:     if (pagename) {
 3584:         targetform.importdetail.value=escape(pagename)+"="+folderseq;
 3585:         targetform.submit();
 3586:     }
 3587: }
 3588: 
 3589: function makenewext(targetname) {
 3590:     this.document.forms.extimport.useform.value=targetname;
 3591:     this.document.forms.extimport.title.value='';
 3592:     this.document.forms.extimport.url.value='';
 3593:     this.document.forms.extimport.residx.value='';
 3594:     window.open('/adm/rat/extpickframe.html');
 3595: }
 3596: 
 3597: function edittext(targetname,residx,title,url) {
 3598:     this.document.forms.extimport.useform.value=targetname;
 3599:     this.document.forms.extimport.residx.value=residx;
 3600:     this.document.forms.extimport.url.value=url;
 3601:     this.document.forms.extimport.title.value=title;
 3602:     window.open('/adm/rat/extpickframe.html');
 3603: }
 3604: 
 3605: function makeexamupload() {
 3606:    var title=prompt('$lt{"p_mxu"}');
 3607:    if (title) {
 3608:     this.document.forms.newexamupload.importdetail.value=
 3609: 	escape(title)+'=/res/lib/templates/examupload.problem';
 3610:     this.document.forms.newexamupload.submit();
 3611:    }
 3612: }
 3613: 
 3614: function makesmppage() {
 3615:    var title=prompt('$lt{"p_msp"}');
 3616:    if (title) {
 3617:     this.document.forms.newsmppg.importdetail.value=
 3618: 	escape(title)+'=/adm/$udom/$uname/$now/smppg';
 3619:     this.document.forms.newsmppg.submit();
 3620:    }
 3621: }
 3622: 
 3623: function makesmpproblem() {
 3624:    var title=prompt('$lt{"p_msb"}');
 3625:    if (title) {
 3626:     this.document.forms.newsmpproblem.importdetail.value=
 3627: 	escape(title)+'=/res/lib/templates/simpleproblem.problem';
 3628:     this.document.forms.newsmpproblem.submit();
 3629:    }
 3630: }
 3631: 
 3632: function makedropbox() {
 3633:    var title=prompt('$lt{"p_mdb"}');
 3634:    if (title) {
 3635:     this.document.forms.newdropbox.importdetail.value=
 3636:         escape(title)+'=/res/lib/templates/DropBox.problem';
 3637:     this.document.forms.newdropbox.submit();
 3638:    }
 3639: }
 3640: 
 3641: function makebulboard() {
 3642:    var title=prompt('$lt{"p_mbb"}');
 3643:    if (title) {
 3644:     this.document.forms.newbul.importdetail.value=
 3645: 	escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
 3646:     this.document.forms.newbul.submit();
 3647:    }
 3648: }
 3649: 
 3650: function makeabout() {
 3651:    var user=prompt("$lt{'p_mab'}");
 3652:    if (user) {
 3653:        var comp=new Array();
 3654:        comp=user.split(':');
 3655:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
 3656: 	   if ((comp[0]) && (comp[1])) {
 3657: 	       this.document.forms.newaboutsomeone.importdetail.value=
 3658: 		   '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
 3659:        this.document.forms.newaboutsomeone.submit();
 3660:    } else {
 3661:        alert("$lt{'p_mab_alrt1'}");
 3662:    }
 3663: } else {
 3664:    alert("$lt{'p_mab_alrt2'}");
 3665: }
 3666: }
 3667: }
 3668: 
 3669: function makeims() {
 3670: var caller = document.forms.ims.folder.value;
 3671: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
 3672: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
 3673: newWindow.location.href = newlocation;
 3674: }
 3675: 
 3676: 
 3677: function finishpick() {
 3678: var title=this.document.forms.extimport.title.value;
 3679: var url=this.document.forms.extimport.url.value;
 3680: var form=this.document.forms.extimport.useform.value;
 3681: var residx=this.document.forms.extimport.residx.value;
 3682: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
 3683: }
 3684: 
 3685: function changename(folderpath,index,oldtitle,container,pagesymb) {
 3686: var title=prompt('$lt{"p_chn"}',oldtitle);
 3687: if (title) {
 3688: this.document.forms.renameform.markcopy.value=-1;
 3689: this.document.forms.renameform.title.value=title;
 3690: this.document.forms.renameform.cmd.value='rename_'+index;
 3691: if (container == 'sequence') {
 3692:     this.document.forms.renameform.folderpath.value=folderpath;
 3693: }
 3694: if (container == 'page') {
 3695:     this.document.forms.renameform.pagepath.value=folderpath;
 3696:     this.document.forms.renameform.pagesymb.value=pagesymb;
 3697: }
 3698: this.document.forms.renameform.submit();
 3699: }
 3700: }
 3701: 
 3702: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
 3703: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
 3704: this.document.forms.renameform.markcopy.value=-1;
 3705: this.document.forms.renameform.cmd.value='del_'+index;
 3706: if (container == 'sequence') {
 3707:     this.document.forms.renameform.folderpath.value=folderpath;
 3708: }
 3709: if (container == 'page') {
 3710:     this.document.forms.renameform.pagepath.value=folderpath;
 3711:     this.document.forms.renameform.pagesymb.value=pagesymb;
 3712: }
 3713: this.document.forms.renameform.submit();
 3714: }
 3715: }
 3716: 
 3717: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
 3718: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
 3719: this.document.forms.renameform.cmd.value='cut_'+index;
 3720: this.document.forms.renameform.markcopy.value=index;
 3721: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
 3722: if (container == 'sequence') {
 3723:     this.document.forms.renameform.folderpath.value=folderpath;
 3724: }
 3725: if (container == 'page') {
 3726:     this.document.forms.renameform.pagepath.value=folderpath;
 3727:     this.document.forms.renameform.pagesymb.value=pagesymb;
 3728: }
 3729: this.document.forms.renameform.submit();
 3730: }
 3731: }
 3732: 
 3733: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
 3734: this.document.forms.renameform.markcopy.value=index;
 3735: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
 3736: if (container == 'sequence') {
 3737: this.document.forms.renameform.folderpath.value=folderpath;
 3738: }
 3739: if (container == 'page') {
 3740: this.document.forms.renameform.pagepath.value=folderpath;
 3741: this.document.forms.renameform.pagesymb.value=pagesymb;
 3742: }
 3743: this.document.forms.renameform.submit();
 3744: }
 3745: 
 3746: function unselectInactive(nav) {
 3747: currentNav = document.getElementById(nav);
 3748: currentLis = currentNav.getElementsByTagName('LI');
 3749: for (i = 0; i < currentLis.length; i++) {
 3750: 	if(currentLis[i].className == 'right active' || currentLis[i].className == 'right'){
 3751: 		currentLis[i].className = 'right';
 3752: 	}else{
 3753: 		currentLis[i].className = 'i';
 3754: 	}
 3755: }
 3756: }
 3757: 
 3758: function hideAll(current, nav, data) {
 3759: unselectInactive(nav);
 3760: if(current.className == 'right'){
 3761: 	current.className = 'right active'
 3762: 	}else{
 3763: 	current.className = 'active';
 3764: }
 3765: currentData = document.getElementById(data);
 3766: currentDivs = currentData.getElementsByTagName('DIV');
 3767: for (i = 0; i < currentDivs.length; i++) {
 3768: 	if(currentDivs[i].className == 'LC_ContentBox'){
 3769: 		currentDivs[i].style.display = 'none';
 3770: 	}
 3771: }
 3772: }
 3773: 
 3774: function openTabs(pageId) {
 3775: 	tabnav = document.getElementById(pageId).getElementsByTagName('UL');	
 3776: 	if(tabnav.length > 2 ){
 3777: 		currentNav = document.getElementById(tabnav[1].id);
 3778: 		currentLis = currentNav.getElementsByTagName('LI');
 3779: 		for(i = 0; i< currentLis.length; i++){
 3780: 			if(currentLis[i].className == 'active') {
 3781: 				funcString = currentLis[i].onclick.toString();
 3782: 				tab = funcString.split('"');
 3783: 				currentData = document.getElementById(tab[1]);
 3784:         			currentData.style.display = 'block';
 3785: 			}	
 3786: 		}
 3787: 	}
 3788: }
 3789: 
 3790: function showPage(current, pageId, nav, data) {
 3791: 	hideAll(current, nav, data);
 3792: 	openTabs(pageId);
 3793: 	unselectInactive(nav);
 3794: 	current.className = 'active';
 3795: 	currentData = document.getElementById(pageId);
 3796: 	currentData.style.display = 'block';
 3797: 	return false;
 3798: }
 3799: 
 3800: function injectData(current, hiddenField, name, value) {
 3801: 	currentElement = document.getElementById(hiddenField);
 3802: 	currentElement.name = name;
 3803: 	currentElement.value = value;
 3804: 	current.submit();
 3805: }
 3806: 
 3807: ENDNEWSCRIPT
 3808: }
 3809: 1;
 3810: __END__
 3811: 
 3812: 
 3813: =head1 NAME
 3814: 
 3815: Apache::londocs.pm
 3816: 
 3817: =head1 SYNOPSIS
 3818: 
 3819: This is part of the LearningOnline Network with CAPA project
 3820: described at http://www.lon-capa.org.
 3821: 
 3822: =head1 SUBROUTINES
 3823: 
 3824: =over
 3825: 
 3826: =item %help=()
 3827: 
 3828: Available help topics
 3829: 
 3830: =item mapread()
 3831: 
 3832: Mapread read maps into LONCAPA::map:: global arrays
 3833: @order and @resources, determines status
 3834: sets @order - pointer to resources in right order
 3835: sets @resources - array with the resources with correct idx
 3836: 
 3837: =item authorhosts()
 3838: 
 3839: Return hash with valid author names
 3840: 
 3841: =item dumpbutton()
 3842: 
 3843: Generate "dump" button
 3844: 
 3845: =item clean()
 3846: 
 3847: =item dumpcourse()
 3848: 
 3849:     Actually dump course
 3850: 
 3851: 
 3852: =item exportbutton()
 3853: 
 3854:     Generate "export" button
 3855: 
 3856: =item exportcourse()
 3857: 
 3858: =item create_ims_store()
 3859: 
 3860: =item build_package()
 3861: 
 3862: =item get_dependencies()
 3863: 
 3864: =item process_content()
 3865: 
 3866: =item replicate_content()
 3867: 
 3868: =item extract_media()
 3869: 
 3870: =item store_template()
 3871: 
 3872: =item group_import()
 3873: 
 3874:     Imports the given (name, url) resources into the course
 3875:     coursenum, coursedom, and folder must precede the list
 3876: 
 3877: =item breadcrumbs()
 3878: 
 3879: =item log_docs()
 3880: 
 3881: =item docs_change_log()
 3882: 
 3883: =item update_paste_buffer()
 3884: 
 3885: =item print_paste_buffer()
 3886: 
 3887: =item do_paste_from_buffer()
 3888: 
 3889: =item update_parameter()
 3890: 
 3891: =item handle_edit_cmd()
 3892: 
 3893: =item editor()
 3894: 
 3895: =item process_file_upload()
 3896: 
 3897: =item process_secondary_uploads()
 3898: 
 3899: =item is_supplemental_title()
 3900: 
 3901: =item parse_supplemental_title()
 3902: 
 3903: =item entryline()
 3904: 
 3905: =item tiehash()
 3906: 
 3907: =item untiehash()
 3908: 
 3909: =item checkonthis()
 3910: 
 3911: check on this
 3912: 
 3913: =item verifycontent()
 3914: 
 3915: Verify Content
 3916: 
 3917: =item devalidateversioncache() & checkversions()
 3918: 
 3919: Check Versions
 3920: 
 3921: =item mark_hash_old()
 3922: 
 3923: =item is_hash_old()
 3924: 
 3925: =item changewarning()
 3926: 
 3927: =item init_breadcrumbs()
 3928: 
 3929: Breadcrumbs for special functions
 3930: 
 3931: =back
 3932: 
 3933: =cut

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