File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.476: download - view: text, annotated - select for diffs
Tue Jan 31 23:47:15 2012 UTC (12 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Work in progress.
- Upload archive files (.zip, .tar, .tar.gz etc.) into a course, and offer the
  option to extract contents, and decide how extracted items should be deployed.
- londocs.pm
  - new routines: &decompression_info(), &decompression_phase_one(),
                  &decompression_phase_two().
- loncomon.pm
  - new routines: &process_decompression(), &get_extracted(),
                  &recurse_extracted_archive(), &archive_hierarchy(),
                  &archive_row(), &archive_options_form, &archive_javascript(),
                  &process_extracted_files()

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

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