File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.478: download - view: text, annotated - select for diffs
Sat Mar 10 21:24:59 2012 UTC (12 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- More compact display for randompick chooser for folders.
- Consistence use/behavior of checkboxes for randompick, randomorder,
  hidden, and encrypturl.

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

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