Annotation of loncom/interface/londocs.pm, revision 1.350

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

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