File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.416: download - view: text, annotated - select for diffs
Thu Jan 21 23:19:17 2010 UTC (14 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- IMS Export.
  - Eliminate unnecessary computations of:  $count + $startcount + $boards

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

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