File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.453: download - view: text, annotated - select for diffs
Fri May 27 19:02:16 2011 UTC (13 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Typo.

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

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