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

1.329     droeschl    1: # The LearningOnline Network
                      2: # Documents
                      3: #
1.477   ! raeburn     4: # $Id: londocs.pm,v 1.476 2012/01/31 23:47:15 raeburn Exp $
1.329     droeschl    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: 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;
1.383     tempelho   36: use Apache::lonhtmlcommon;
1.329     droeschl   37: use LONCAPA::map();
                     38: use Apache::lonratedt();
                     39: use Apache::lonxml;
                     40: use Apache::lonclonecourse;
                     41: use Apache::lonnavmaps;
1.472     raeburn    42: use Apache::lonnavdisplay();
1.329     droeschl   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); }
1.364     bisitz     75: 
1.329     droeschl   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();
1.408     raeburn   119:     my $crstype = &Apache::loncommon::course_type();
1.329     droeschl  120:     if ($home+$other==0) { return ''; }
                    121:     if ($home) {
1.419     bisitz    122:         my $link =
1.423     onken     123:             "<a class='LC_menubuttons_link' href='javascript:injectData(document.courseverify, \"dummy\", \"dumpcourse\", \""
1.419     bisitz    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 />';
1.329     droeschl  132:     } else {
1.419     bisitz    133:         return
                    134:             &mt('Dump '.$crstype.' Documents to Construction Space: available on other servers');
1.329     droeschl  135:     }
                    136: }
                    137: 
                    138: sub clean {
                    139:     my ($title)=@_;
                    140:     $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344     bisitz    141:     return $title;
1.329     droeschl  142: }
                    143: 
                    144: 
                    145: 
                    146: sub dumpcourse {
                    147:     my ($r) = @_;
1.408     raeburn   148:     my $crstype = &Apache::loncommon::course_type();
1.419     bisitz    149:     $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Documents to Construction Space').
1.369     bisitz    150: 	      '<form name="dumpdoc" action="" method="post">');
1.419     bisitz    151:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Documents to Construction Space'));
1.329     droeschl  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);
1.462     raeburn   178: 	    my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
1.329     droeschl  179: 	    my $makepath=$path;
                    180: 	    my $fail=0;
                    181: 	    for (my $i=0;$i<$#dirs;$i++) {
                    182: 		$makepath.='/'.$dirs[$i];
1.344     bisitz    183: 		unless (-e $makepath) {
                    184: 		    unless(mkdir($makepath,0777)) { $fail=1; }
1.329     droeschl  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(
1.419     bisitz    262:   '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype Documents").'" /></p></form>');
1.329     droeschl  263:     }
                    264: }
                    265: 
                    266: sub exportbutton {
1.408     raeburn   267:     my $crstype = &Apache::loncommon::course_type();
1.423     onken     268:     return "<a class='LC_menubuttons_link' href='javascript:injectData(document.courseverify, \"dummy\", \"exportcourse\", \"".&mt('IMS Export')."\")'>".&mt('IMS Export')."</a>".
1.362     ehlerst   269:     &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'<br />';
1.329     droeschl  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) };
1.344     bisitz    277:         if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329     droeschl  278: 	     && ($caller eq 'londocs')
                    279: 	     && (!&Apache::lonnet::stat_file($url))) {
1.364     bisitz    280: 
1.329     droeschl  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) {
1.344     bisitz    300: 	    if (!$residx
1.329     droeschl  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);
1.344     bisitz    309: 	    $LONCAPA::map::resources[$residx] =
1.329     droeschl  310: 		join(':', ($name, $url, $ext, 'normal', 'res'));
                    311: 	}
                    312:     }
                    313:     return &storemap($coursenum, $coursedom, $folder.'.'.$container);
                    314: }
                    315: 
                    316: sub breadcrumbs {
1.408     raeburn   317:     my ($allowed,$crstype)=@_;
1.329     droeschl  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;
1.472     raeburn   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);
1.344     bisitz    345: # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
1.472     raeburn   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(
1.329     droeschl  359: 		      {'href'=>$url.$cpinfo,
                    360: 		       'title'=>$name,
1.367     droeschl  361: 		       'text'=>$name,
1.329     droeschl  362: 		       'no_mt'=>1,
                    363: 		       });
                    364: 	$plain.=$name.' &gt; ';
                    365:     }
                    366:     $plain=~s/\&gt\;\s*$//;
                    367:     return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
1.472     raeburn   368: 					       undef, undef, 1 ),$randompick,$ishidden,
                    369:                                                $isencrypted,$plain,$is_random_order);
1.329     droeschl  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; }
1.452     www       457: # FIXME: internationalization seems wrong here
1.329     droeschl  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: 	    }
1.344     bisitz    483: 	    if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329     droeschl  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: 	    }
1.364     bisitz    534: 	}
1.329     droeschl  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}) {
1.452     www       546: # FIXME: internationalization seems wrong here
1.329     droeschl  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'});
1.364     bisitz    573: 
1.329     droeschl  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'}) {
1.346     raeburn   582:         &Apache::lonnet::delenv('docs.markedcopy_supplemental');
1.329     droeschl  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: 
1.381     bisitz    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:     );
1.329     droeschl  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'));
1.380     bisitz    613: 	    $icon .= '/navmap.folder.closed.gif';
1.329     droeschl  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:     }
1.381     bisitz    628:     $r->print('</form></fieldset>');
1.329     droeschl  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/})) {
1.346     raeburn   687: 	&Apache::lonnet::delenv('docs.markedcopy');
1.329     droeschl  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);
1.344     bisitz    698: 	    $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
1.329     droeschl  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 {
1.344     bisitz    712:             (undef,undef,$title) =
1.329     droeschl  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;
1.344     bisitz    736:             last;
1.329     droeschl  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);
1.364     bisitz    762: 
1.329     droeschl  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/|) &&
1.463     www       778: 	    ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329     droeschl  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: 
1.344     bisitz    789:     } elsif ($cmd eq 'up'
1.329     droeschl  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 {
1.458     raeburn   814:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.472     raeburn   815:         $supplementalflag,$orderhash,$iconpath)=@_;
1.329     droeschl  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:     }
1.364     bisitz    829: 
1.446     www       830:     my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
1.472     raeburn   831:         &breadcrumbs($allowed,$crstype);
                    832:     $r->print($breadcrumbtrail);
                    833: 
                    834:     my $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.446     www       835: 
                    836:     unless ($allowed) {
1.395     raeburn   837:         $randompick = -1;
                    838:     }
1.364     bisitz    839: 
1.329     droeschl  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: 	}
1.364     bisitz    860: 
1.329     droeschl  861: 	if ($env{'form.pastemarked'}) {
1.344     bisitz    862:             my $paste_res =
1.329     droeschl  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>');
1.364     bisitz    906: 
1.329     droeschl  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)) {
1.381     bisitz    916: 	$r->print('<div class="LC_Box">'.
1.432     raeburn   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>':'').
1.431     raeburn   922: 		  '</ol>');
1.381     bisitz    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>');
1.364     bisitz    944:     }
1.381     bisitz    945: 
1.458     raeburn   946:     my ($to_show,$output);
1.424     onken     947: 
                    948:     &Apache::loncommon::start_data_table_count(); #setup a row counter 
1.381     bisitz    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,
1.408     raeburn   956:                               $coursenum,$crstype);
1.381     bisitz    957:         $idx++;
                    958:         $shown++;
1.329     droeschl  959:     }
1.424     onken     960:     &Apache::loncommon::end_data_table_count();
                    961:     
1.381     bisitz    962:     if ($shown) {
1.458     raeburn   963:         $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
                    964:                   .&Apache::loncommon::start_data_table(undef,'contentlist');
1.393     raeburn   965:         if ($allowed) {
1.458     raeburn   966:             $to_show .= &Apache::loncommon::start_data_table_header_row()
1.393     raeburn   967:                      .'<th colspan="2">'.&mt('Move').'</th>'
                    968:                      .'<th>'.&mt('Actions').'</th>'
1.458     raeburn   969:                      .'<th colspan="2">'.&mt('Document').'</th>';
1.393     raeburn   970:             if ($folder !~ /^supplemental/) {
1.458     raeburn   971:                 $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
1.393     raeburn   972:             }
1.458     raeburn   973:             $to_show .= &Apache::loncommon::end_data_table_header_row();
1.393     raeburn   974:         }
1.458     raeburn   975:         $to_show .= $output.' '
1.393     raeburn   976:                  .&Apache::loncommon::end_data_table()
1.458     raeburn   977:                  .'<br style="line-height:2px;" />'
                    978:                  .&Apache::loncommon::end_scrollbox();
1.393     raeburn   979:     } else {
1.458     raeburn   980:         $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
                    981:                  .'<div class="LC_info" id="contentlist">'
1.381     bisitz    982:                  .&mt('Currently no documents.')
1.458     raeburn   983:                  .'</div>'
                    984:                  .&Apache::loncommon::end_scrollbox();
                    985:     }
                    986:     my $tid = 1;
                    987:     if ($supplementalflag) {
                    988:         $tid = 2;
1.329     droeschl  989:     }
                    990:     if ($allowed) {
1.472     raeburn   991:         $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,$jumpto));
1.329     droeschl  992:         &print_paste_buffer($r,$container);
1.460     raeburn   993:     } else {
1.472     raeburn   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:         }
1.460     raeburn  1007:         $r->print($to_show);
1.329     droeschl 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
1.440     raeburn  1015:     my ($parseaction,$showupload,$nextphase,$mimetype);
                   1016:     if ($env{'form.parserflag'}) {
1.329     droeschl 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) {
1.457     raeburn  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>';
1.440     raeburn  1038:             return;
1.329     droeschl 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:         }
1.440     raeburn  1049: # this is for a course, not a user, so set context to coursedoc.
1.329     droeschl 1050:         my $newidx=&LONCAPA::map::getresidx();
                   1051:         $destination .= $newidx;
1.439     raeburn  1052:         my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329     droeschl 1053: 						$parseaction,$allfiles,
1.440     raeburn  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:             
1.457     raeburn  1063:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440     raeburn  1064:             return;
                   1065:         }
1.329     droeschl 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) {
1.457     raeburn  1082:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440     raeburn  1083:             return;
1.329     droeschl 1084:         } else {
1.440     raeburn  1085:             if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
                   1086:                 $$upload_output = $showupload;
1.384     raeburn  1087:                 my $total_embedded = scalar(keys(%{$allfiles}));
1.329     droeschl 1088:                 if ($total_embedded > 0) {
1.440     raeburn  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:                     }
1.329     droeschl 1106:                 } else {
1.440     raeburn  1107:                     $$upload_output .= &mt('No embedded items identified').'<br />';
1.329     droeschl 1108:                 }
1.457     raeburn  1109:                 $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.476     raeburn  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,
1.477   ! raeburn  1122:                     comment    => $comment,
1.476     raeburn  1123:                 ); 
                   1124:                 $$upload_output = $showupload.
                   1125:                                   &Apache::loncommon::decompress_form($mimetype,
                   1126:                                       $archiveurl,'/adm/coursedocs',$noextract,
                   1127:                                       \%archiveitems);
1.329     droeschl 1128:             }
                   1129:         }
                   1130:     }
1.440     raeburn  1131:     return $nextphase;
1.329     droeschl 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,'"<>&\'');
1.418     raeburn  1152:         $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.329     droeschl 1153: 	$title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
                   1154: 	    $name.': <br />'.$foldertitle;
                   1155:     }
                   1156:     if (wantarray) {
                   1157: 	return ($title,$foldertitle,$renametitle);
1.364     bisitz   1158:     }
1.329     droeschl 1159:     return $title;
                   1160: }
                   1161: 
                   1162: # --------------------------------------------------------------- An entry line
                   1163: 
                   1164: sub entryline {
1.408     raeburn  1165:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$crstype)=@_;
1.329     droeschl 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];
1.364     bisitz   1178: 
1.329     droeschl 1179: 
                   1180:     $renametitle=~s/\\/\\\\/g;
                   1181:     $renametitle=~s/\&quot\;/\\\"/g;
                   1182:     $renametitle=~s/ /%20/g;
1.379     bisitz   1183:     my $line=&Apache::loncommon::start_data_table_row();
1.329     droeschl 1184:     my ($form_start,$form_end);
                   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';
1.440     raeburn  1196:         $esc_path=&escape($env{'form.pagepath'});
1.329     droeschl 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='';
1.471     raeburn  1204: 	if (($#LONCAPA::map::order>0) &&
1.329     droeschl 1205: 	    ((split(/\:/,
1.344     bisitz   1206: 	     $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
                   1207: 	     ne '') &&
1.329     droeschl 1208: 	    ((split(/\:/,
1.344     bisitz   1209: 	     $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329     droeschl 1210: 	     ne '')) {
                   1211: 	    $selectbox=
                   1212: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373     bisitz   1213: 		'<select name="newpos" onchange="this.form.submit()">';
1.329     droeschl 1214: 	    for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
                   1215: 		if ($i==$incindex) {
1.358     bisitz   1216: 		    $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329     droeschl 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: 	}
1.344     bisitz   1246:         if ($url=~/^\/res\/lib\/templates\//) {
                   1247:            $nocopy=1;
1.329     droeschl 1248:            $nocut=1;
                   1249:         }
                   1250:         my $copylink='&nbsp;';
                   1251:         my $cutlink='&nbsp;';
1.364     bisitz   1252: 
1.329     droeschl 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 = (<<END);
                   1276:    <form  action="/adm/coursedocs" method="post">
                   1277:    <input type="hidden" name="${type}path" value="$path" />
                   1278:    <input type="hidden" name="${type}symb" value="$symb" />
                   1279:    <input type="hidden" name="setparms" value="$orderidx" />
                   1280:    <input type="hidden" name="changeparms" value="0" />
                   1281: END
                   1282:         $form_end = '</form>';
                   1283: 	$line.=(<<END);
                   1284: <td>
1.379     bisitz   1285: <div class="LC_docs_entry_move">
                   1286:   <a href='/adm/coursedocs?cmd=up_$index&amp;${type}path=$esc_path&amp;${type}symb=$symb$cpinfo'>
                   1287:     <img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" />
                   1288:   </a>
                   1289: </div>
                   1290: <div class="LC_docs_entry_move">
                   1291:   <a href='/adm/coursedocs?cmd=down_$index&amp;${type}path=$esc_path&amp;${type}symb=$symb$cpinfo'>
                   1292:     <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" />
                   1293:   </a>
                   1294: </div>
1.329     droeschl 1295: </td>
                   1296: <td>
                   1297:    $form_start
                   1298:    $selectbox
                   1299:    $form_end
                   1300: </td>
                   1301: <td class="LC_docs_entry_commands">
                   1302:    <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
                   1303: $cutlink
                   1304:    <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
                   1305: $copylink
                   1306: </td>
                   1307: END
                   1308: 
                   1309:     }
                   1310: # Figure out what kind of a resource this is
                   1311:     my ($extension)=($url=~/\.(\w+)$/);
                   1312:     my $uploaded=($url=~/^\/*uploaded\//);
                   1313:     my $icon=&Apache::loncommon::icon($url);
                   1314:     my $isfolder=0;
                   1315:     my $ispage=0;
                   1316:     my $folderarg;
                   1317:     my $pagearg;
                   1318:     my $pagefile;
                   1319:     if ($uploaded) {
1.472     raeburn  1320:         if (($extension eq 'sequence') || ($extension eq 'page')) {
                   1321:             $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
                   1322:             my $containerarg = $1;
                   1323: 	    if ($extension eq 'sequence') {
                   1324: 	        $icon=$iconpath.'navmap.folder.closed.gif';
                   1325:                 $folderarg=$containerarg;
                   1326:                 $isfolder=1;
                   1327:             } else {
                   1328:                 $icon=$iconpath.'page.gif';
                   1329:                 $pagearg=$containerarg;
                   1330:                 $ispage=1;
                   1331:             }
                   1332:             if ($allowed) {
                   1333:                 $url='/adm/coursedocs?';
                   1334:             } else {
                   1335:                 $url='/adm/supplemental?';
                   1336:             }
1.329     droeschl 1337: 	} else {
                   1338: 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
                   1339: 	}
                   1340:     }
1.364     bisitz   1341: 
1.329     droeschl 1342:     my $orig_url = $url;
1.340     raeburn  1343:     $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.329     droeschl 1344:     my $external = ($url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/});
                   1345:     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
                   1346: 	my $symb=&Apache::lonnet::symbclean(
                   1347:           &Apache::lonnet::declutter('uploaded/'.
                   1348:            $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   1349:            $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
                   1350:            '.sequence').
                   1351:            '___'.$residx.'___'.
                   1352: 	   &Apache::lonnet::declutter($url));
                   1353: 	(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
                   1354: 	$url=&Apache::lonnet::clutter($url);
                   1355: 	if ($url=~/^\/*uploaded\//) {
                   1356: 	    $url=~/\.(\w+)$/;
                   1357: 	    my $embstyle=&Apache::loncommon::fileembstyle($1);
                   1358: 	    if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                   1359: 		$url='/adm/wrapper'.$url;
                   1360: 	    } elsif ($embstyle eq 'ssi') {
                   1361: 		#do nothing with these
                   1362: 	    } elsif ($url!~/\.(sequence|page)$/) {
                   1363: 		$url='/adm/coursedocs/showdoc'.$url;
                   1364: 	    }
1.344     bisitz   1365: 	} elsif ($url=~m|^/ext/|) {
1.329     droeschl 1366: 	    $url='/adm/wrapper'.$url;
                   1367: 	    $external = 1;
                   1368: 	}
                   1369:         if (&Apache::lonnet::symbverify($symb,$url)) {
                   1370: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
                   1371:         } else {
                   1372:             $url='';
                   1373:         }
                   1374: 	if ($container eq 'page') {
                   1375: 	    my $symb=$env{'form.pagesymb'};
1.364     bisitz   1376: 
1.329     droeschl 1377: 	    $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   1378: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
                   1379: 	}
                   1380:     }
                   1381:     my ($parameterset,$rand_order_text) = ('&nbsp;', '&nbsp;');
                   1382:     if ($isfolder || $extension eq 'sequence') {
                   1383: 	my $foldername=&escape($foldertitle);
                   1384: 	my $folderpath=$env{'form.folderpath'};
                   1385: 	if ($folderpath) { $folderpath.='&' };
1.344     bisitz   1386: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329     droeschl 1387: # so it gets transferred between levels
                   1388: 	$folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
                   1389:                                               'parameter_randompick'))[0]
                   1390:                                                .':'.((&LONCAPA::map::getparameter($orderidx,
                   1391:                                               'parameter_hiddenresource'))[0]=~/^yes$/i)
                   1392:                                                .':'.((&LONCAPA::map::getparameter($orderidx,
                   1393:                                               'parameter_encrypturl'))[0]=~/^yes$/i)
                   1394:                                                .':'.((&LONCAPA::map::getparameter($orderidx,
                   1395:                                               'parameter_randomorder'))[0]=~/^yes$/i);
                   1396: 	$url.='folderpath='.&escape($folderpath).$cpinfo;
                   1397: 	$parameterset='<label>'.&mt('Randomly Pick: ').
1.373     bisitz   1398: 	    '<input type="text" size="4" onchange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randompick_'.$orderidx.'" value="'.
1.329     droeschl 1399: 	    (&LONCAPA::map::getparameter($orderidx,
                   1400:                                               'parameter_randompick'))[0].
                   1401:                                               '" />'.
                   1402: '<a href="javascript:void(0)">'.&mt('Save').'</a></label>';
                   1403:     	my $ro_set=
                   1404: 	    ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
                   1405: 	$rand_order_text ='
1.369     bisitz   1406: <span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onclick="this.form.changeparms.value=\'randomorder\';this.form.submit()" '.$ro_set.' /> '.&mt('Random Order').' </label></span>';
1.329     droeschl 1407:     }
                   1408:     if ($ispage) {
                   1409:         my $pagename=&escape($pagetitle);
                   1410:         my $pagepath;
                   1411:         my $folderpath=$env{'form.folderpath'};
                   1412:         if ($folderpath) { $pagepath = $folderpath.'&' };
                   1413:         $pagepath.=$pagearg.'&'.$pagename;
                   1414: 	my $symb=$env{'form.pagesymb'};
                   1415: 	if (!$symb) {
                   1416: 	    my $path='uploaded/'.
                   1417: 		$env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   1418: 		$env{'course.'.$env{'request.course.id'}.'.num'}.'/';
                   1419: 	    $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
                   1420: 					       $residx,
                   1421: 					       $path.$pagearg.'.page');
                   1422: 	}
                   1423: 	$url.='pagepath='.&escape($pagepath).
                   1424: 	    '&amp;pagesymb='.&escape($symb).$cpinfo;
                   1425:     }
1.396     raeburn  1426:     if (($external) && ($allowed)) {
1.329     droeschl 1427: 	my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
                   1428: 	$external = '&nbsp;<a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
                   1429:     } else {
                   1430: 	undef($external);
                   1431:     }
1.408     raeburn  1432:     my $reinit;
                   1433:     if ($crstype eq 'Community') {
                   1434:         $reinit = &mt('(re-initialize community to access)');
                   1435:     } else {
                   1436:         $reinit = &mt('(re-initialize course to access)');
                   1437:     }  
1.469     www      1438:     $line.='<td>';
1.472     raeburn  1439:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469     www      1440:        $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
                   1441:     } elsif ($url) {
1.470     raeburn  1442:        $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
                   1443:                                              '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469     www      1444:     } else {
                   1445:        $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
                   1446:     }
                   1447:     $line.='</td><td>';
1.472     raeburn  1448:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469     www      1449:        $line.='<a href="'.$url.'">'.$title.'</a>';
                   1450:     } elsif ($url) {
1.470     raeburn  1451:        $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
                   1452:                                              $title,600,500);
1.469     www      1453:     } else {
                   1454:        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
                   1455:     }
                   1456:     $line.=$external."</td>";
1.329     droeschl 1457:     if (($allowed) && ($folder!~/^supplemental/)) {
                   1458:  	my %lt=&Apache::lonlocal::texthash(
                   1459:  			      'hd' => 'Hidden',
                   1460:  			      'ec' => 'URL hidden');
                   1461: 	my $enctext=
1.358     bisitz   1462: 	    ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
1.329     droeschl 1463: 	my $hidtext=
1.358     bisitz   1464: 	    ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
1.329     droeschl 1465: 	$line.=(<<ENDPARMS);
                   1466:   <td class="LC_docs_entry_parameter">
                   1467:     $form_start
1.369     bisitz   1468:     <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
1.329     droeschl 1469:     $form_end
1.458     raeburn  1470:     <br />
1.329     droeschl 1471:     $form_start
1.369     bisitz   1472:     <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
1.329     droeschl 1473:     $form_end
                   1474:   </td>
1.458     raeburn  1475:   <td class="LC_docs_entry_parameter">$form_start $parameterset $form_end<br />
                   1476:                                       $form_start $rand_order_text $form_end</td>
1.329     droeschl 1477: ENDPARMS
                   1478:     }
1.379     bisitz   1479:     $line.=&Apache::loncommon::end_data_table_row();
1.329     droeschl 1480:     return $line;
                   1481: }
                   1482: 
                   1483: =pod
                   1484: 
                   1485: =item tiehash()
                   1486: 
                   1487: tie the hash
                   1488: 
                   1489: =cut
                   1490: 
                   1491: sub tiehash {
                   1492:     my ($mode)=@_;
                   1493:     $hashtied=0;
                   1494:     if ($env{'request.course.fn'}) {
                   1495: 	if ($mode eq 'write') {
                   1496: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   1497: 		    &GDBM_WRCREAT(),0640)) {
                   1498:                 $hashtied=2;
                   1499: 	    }
                   1500: 	} else {
                   1501: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   1502: 		    &GDBM_READER(),0640)) {
                   1503:                 $hashtied=1;
                   1504: 	    }
                   1505: 	}
1.364     bisitz   1506:     }
1.329     droeschl 1507: }
                   1508: 
                   1509: sub untiehash {
                   1510:     if ($hashtied) { untie %hash; }
                   1511:     $hashtied=0;
                   1512:     return OK;
                   1513: }
                   1514: 
                   1515: 
                   1516: 
                   1517: 
                   1518: sub checkonthis {
                   1519:     my ($r,$url,$level,$title)=@_;
                   1520:     $url=&unescape($url);
                   1521:     $alreadyseen{$url}=1;
                   1522:     $r->rflush();
                   1523:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
                   1524:        $r->print("\n<br />");
                   1525:        if ($level==0) {
                   1526:            $r->print("<br />");
                   1527:        }
                   1528:        for (my $i=0;$i<=$level*5;$i++) {
                   1529:            $r->print('&nbsp;');
                   1530:        }
                   1531:        $r->print('<a href="'.$url.'" target="cat">'.
                   1532: 		 ($title?$title:$url).'</a> ');
                   1533:        if ($url=~/^\/res\//) {
                   1534: 	  my $result=&Apache::lonnet::repcopy(
                   1535:                               &Apache::lonnet::filelocation('',$url));
                   1536:           if ($result eq 'ok') {
                   1537:              $r->print('<span class="LC_success">'.&mt('ok').'</span>');
                   1538:              $r->rflush();
                   1539:              &Apache::lonnet::countacc($url);
                   1540:              $url=~/\.(\w+)$/;
                   1541:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                   1542: 		 $r->print('<br />');
                   1543:                  $r->rflush();
                   1544:                  for (my $i=0;$i<=$level*5;$i++) {
                   1545:                      $r->print('&nbsp;');
                   1546:                  }
                   1547:                  $r->print('- '.&mt('Rendering:').' ');
                   1548: 		 my ($errorcount,$warningcount)=split(/:/,
                   1549: 	       &Apache::lonnet::ssi_body($url,
                   1550: 			       ('grade_target'=>'web',
                   1551: 				'return_only_error_and_warning_counts' => 1)));
                   1552:                  if (($errorcount) ||
                   1553:                      ($warningcount)) {
                   1554: 		     if ($errorcount) {
1.369     bisitz   1555:                         $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329     droeschl 1556:                           &mt('[quant,_1,error]',$errorcount).'</span>');
                   1557:                      }
                   1558: 		     if ($warningcount) {
                   1559:                         $r->print('<span class="LC_warning">'.
                   1560:                           &mt('[quant,_1,warning]',$warningcount).'</span>');
                   1561:                      }
                   1562:                  } else {
                   1563:                      $r->print('<span class="LC_success">'.&mt('ok').'</span>');
                   1564:                  }
                   1565:                  $r->rflush();
                   1566:              }
                   1567: 	     my $dependencies=
                   1568:                 &Apache::lonnet::metadata($url,'dependencies');
                   1569:              foreach my $dep (split(/\,/,$dependencies)) {
                   1570: 		 if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
                   1571:                     &checkonthis($r,$dep,$level+1);
                   1572:                  }
                   1573:              }
                   1574:           } elsif ($result eq 'unavailable') {
                   1575:              $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
                   1576:           } elsif ($result eq 'not_found') {
                   1577: 	      unless ($url=~/\$/) {
                   1578: 		  $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
                   1579: 	      } else {
1.366     bisitz   1580: 		  $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329     droeschl 1581: 	      }
                   1582:           } else {
                   1583:              $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
                   1584:           }
                   1585:        }
                   1586:     }
                   1587: }
                   1588: 
                   1589: 
                   1590: 
                   1591: =pod
                   1592: 
                   1593: =item list_symbs()
                   1594: 
                   1595: List Symbs
                   1596: 
                   1597: =cut
                   1598: 
                   1599: sub list_symbs {
                   1600:     my ($r) = @_;
                   1601: 
1.408     raeburn  1602:     my $crstype = &Apache::loncommon::course_type();
1.329     droeschl 1603:     $r->print(&Apache::loncommon::start_page('Symb List'));
                   1604:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
1.442     www      1605:     &startContentScreen($r,'tools');
1.329     droeschl 1606:     my $navmap = Apache::lonnavmaps::navmap->new();
                   1607:     if (!defined($navmap)) {
                   1608:         $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
                   1609:                   '<div class="LC_error">'.
                   1610:                   &mt('Unable to retrieve information about course contents').
                   1611:                   '</div>');
1.408     raeburn  1612:         &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329     droeschl 1613:     } else {
                   1614:         $r->print("<pre>\n");
                   1615:         foreach my $res ($navmap->retrieveResources()) {
1.419     bisitz   1616:             $r->print($res->compTitle()."\t".$res->symb()."\n");
1.329     droeschl 1617:         }
                   1618:         $r->print("\n</pre>\n");
                   1619:     }
                   1620: }
                   1621: 
                   1622: 
                   1623: sub verifycontent {
                   1624:     my ($r) = @_;
1.408     raeburn  1625:     my $crstype = &Apache::loncommon::course_type();
                   1626:    $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
                   1627:    $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
1.442     www      1628:    &startContentScreen($r,'tools');
1.329     droeschl 1629:    $hashtied=0;
                   1630:    undef %alreadyseen;
                   1631:    %alreadyseen=();
                   1632:    &tiehash();
                   1633:    foreach my $key (keys(%hash)) {
                   1634:        if ($hash{$key}=~/\.(page|sequence)$/) {
                   1635: 	   if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
                   1636: 	       $r->print('<hr /><span class="LC_error">'.
1.419     bisitz   1637: 			 &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329     droeschl 1638: 			 &unescape($hash{$key}).'</span><br />'.
1.419     bisitz   1639: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329     droeschl 1640: 	   }
                   1641:        }
                   1642:        if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
                   1643:            &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
                   1644:        }
                   1645:    }
                   1646:    &untiehash();
1.442     www      1647:    $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.329     droeschl 1648: }
                   1649: 
                   1650: 
                   1651: sub devalidateversioncache {
                   1652:     my $src=shift;
                   1653:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
                   1654: 					  &Apache::lonnet::clutter($src));
                   1655: }
                   1656: 
                   1657: sub checkversions {
                   1658:     my ($r) = @_;
1.408     raeburn  1659:     my $crstype = &Apache::loncommon::course_type();
                   1660:     $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
                   1661:     $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
1.442     www      1662:     &startContentScreen($r,'tools');
                   1663: 
1.329     droeschl 1664:     my $header='';
                   1665:     my $startsel='';
                   1666:     my $monthsel='';
                   1667:     my $weeksel='';
                   1668:     my $daysel='';
                   1669:     my $allsel='';
                   1670:     my %changes=();
                   1671:     my $starttime=0;
                   1672:     my $haschanged=0;
                   1673:     my %setversions=&Apache::lonnet::dump('resourceversions',
                   1674: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1675: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   1676: 
                   1677:     $hashtied=0;
                   1678:     &tiehash();
                   1679:     my %newsetversions=();
                   1680:     if ($env{'form.setmostrecent'}) {
                   1681: 	$haschanged=1;
                   1682: 	foreach my $key (keys(%hash)) {
                   1683: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   1684: 		$newsetversions{$1}='mostrecent';
                   1685:                 &devalidateversioncache($1);
                   1686: 	    }
                   1687: 	}
                   1688:     } elsif ($env{'form.setcurrent'}) {
                   1689: 	$haschanged=1;
                   1690: 	foreach my $key (keys(%hash)) {
                   1691: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   1692: 		my $getvers=&Apache::lonnet::getversion($1);
                   1693: 		if ($getvers>0) {
                   1694: 		    $newsetversions{$1}=$getvers;
                   1695: 		    &devalidateversioncache($1);
                   1696: 		}
                   1697: 	    }
                   1698: 	}
                   1699:     } elsif ($env{'form.setversions'}) {
                   1700: 	$haschanged=1;
                   1701: 	foreach my $key (keys(%env)) {
                   1702: 	    if ($key=~/^form\.set_version_(.+)$/) {
                   1703: 		my $src=$1;
                   1704: 		if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
                   1705: 		    $newsetversions{$src}=$env{$key};
                   1706: 		    &devalidateversioncache($src);
                   1707: 		}
                   1708: 	    }
                   1709: 	}
                   1710:     }
                   1711:     if ($haschanged) {
                   1712:         if (&Apache::lonnet::put('resourceversions',\%newsetversions,
                   1713: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344     bisitz   1714: 			  $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.329     droeschl 1715: 	    $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');
                   1716: 	} else {
                   1717: 	    $r->print('<h1><span class="LC_error">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</span></h1>');
                   1718: 	}
                   1719: 	&mark_hash_old();
                   1720:     }
                   1721:     &changewarning($r,'');
                   1722:     if ($env{'form.timerange'} eq 'all') {
                   1723: # show all documents
1.408     raeburn  1724: 	$header=&mt('All Documents in '.$crstype);
1.329     droeschl 1725: 	$allsel=1;
                   1726: 	foreach my $key (keys(%hash)) {
                   1727: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   1728: 		my $src=$1;
                   1729: 		$changes{$src}=1;
                   1730: 	    }
                   1731: 	}
                   1732:     } else {
                   1733: # show documents which changed
                   1734: 	%changes=&Apache::lonnet::dump
                   1735: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
                   1736:                      $env{'course.'.$env{'request.course.id'}.'.num'});
                   1737: 	my $firstkey=(keys(%changes))[0];
                   1738: 	unless ($firstkey=~/^error\:/) {
                   1739: 	    unless ($env{'form.timerange'}) {
                   1740: 		$env{'form.timerange'}=604800;
                   1741: 	    }
                   1742: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
                   1743: 		.&mt('seconds');
                   1744: 	    if ($env{'form.timerange'}==-1) {
                   1745: 		$seltext='since start of course';
                   1746: 		$startsel='selected';
                   1747: 		$env{'form.timerange'}=time;
                   1748: 	    }
                   1749: 	    $starttime=time-$env{'form.timerange'};
                   1750: 	    if ($env{'form.timerange'}==2592000) {
                   1751: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1752: 		$monthsel='selected';
                   1753: 	    } elsif ($env{'form.timerange'}==604800) {
                   1754: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1755: 		$weeksel='selected';
                   1756: 	    } elsif ($env{'form.timerange'}==86400) {
                   1757: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1758: 		$daysel='selected';
                   1759: 	    }
                   1760: 	    $header=&mt('Content changed').' '.$seltext;
                   1761: 	} else {
                   1762: 	    $header=&mt('No content modifications yet.');
                   1763: 	}
                   1764:     }
                   1765:     %setversions=&Apache::lonnet::dump('resourceversions',
                   1766: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1767: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   1768:     my %lt=&Apache::lonlocal::texthash
1.408     raeburn  1769: 	      ('st' => 'Version changes since start of '.$crstype,
1.329     droeschl 1770: 	       'lm' => 'Version changes since last Month',
                   1771: 	       'lw' => 'Version changes since last Week',
                   1772: 	       'sy' => 'Version changes since Yesterday',
                   1773:                'al' => 'All Resources (possibly large output)',
                   1774: 	       'sd' => 'Display',
                   1775: 	       'fi' => 'File',
                   1776: 	       'md' => 'Modification Date',
                   1777:                'mr' => 'Most recently published Version',
1.408     raeburn  1778: 	       've' => 'Version used in '.$crstype,
                   1779:                'vu' => 'Set Version to be used in '.$crstype,
                   1780: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329     droeschl 1781: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                   1782: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
                   1783: 	       'di' => 'Differences');
                   1784:     $r->print(<<ENDHEADERS);
                   1785: <form action="/adm/coursedocs" method="post">
                   1786: <input type="hidden" name="versions" value="1" />
                   1787: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
                   1788: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
                   1789: <select name="timerange">
                   1790: <option value='all' $allsel>$lt{'al'}</option>
                   1791: <option value="-1" $startsel>$lt{'st'}</option>
                   1792: <option value="2592000" $monthsel>$lt{'lm'}</option>
                   1793: <option value="604800" $weeksel>$lt{'lw'}</option>
                   1794: <option value="86400" $daysel>$lt{'sy'}</option>
                   1795: </select>
                   1796: <input type="submit" name="display" value="$lt{'sd'}" />
                   1797: <h3>$header</h3>
                   1798: <input type="submit" name="setversions" value="$lt{'sv'}" />
                   1799: <table border="0">
                   1800: ENDHEADERS
                   1801:     foreach my $key (sort(keys(%changes))) {
                   1802: 	if ($changes{$key}>$starttime) {
                   1803: 	    my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   1804: 	    my $currentversion=&Apache::lonnet::getversion($key);
                   1805: 	    if ($currentversion<0) {
                   1806: 		$currentversion=&mt('Could not be determined.');
                   1807: 	    }
                   1808: 	    my $linkurl=&Apache::lonnet::clutter($key);
                   1809: 	    $r->print(
                   1810: 		      '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
                   1811: 		      &Apache::lonnet::gettitle($linkurl).
                   1812:                       '</b></font></td></tr>'.
                   1813:                       '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
                   1814:                       '<td colspan="4">'.
                   1815:                       '<a href="'.$linkurl.'" target="cat">'.$linkurl.
                   1816: 		      '</a></td></tr>'.
                   1817:                       '<tr><td></td>'.
                   1818:                       '<td title="'.$lt{'md'}.'">'.
                   1819: 		      &Apache::lonlocal::locallocaltime(
                   1820:                            &Apache::lonnet::metadata($root.'.'.$extension,
                   1821:                                                      'lastrevisiondate')
                   1822:                                                         ).
                   1823:                       '</td>'.
                   1824:                       '<td title="'.$lt{'mr'}.'"><span class="LC_nobreak">Most Recent: '.
                   1825:                       '<font size="+1">'.$currentversion.'</font>'.
                   1826:                       '</span></td>'.
1.408     raeburn  1827:                       '<td title="'.$lt{'ve'}.'"><span class="LC_nobreak">In '.$crstype.': '.
1.329     droeschl 1828:                       '<font size="+1">');
                   1829: # Used in course
                   1830: 	    my $usedversion=$hash{'version_'.$linkurl};
                   1831: 	    if (($usedversion) && ($usedversion ne 'mostrecent')) {
                   1832: 		$r->print($usedversion);
                   1833: 	    } else {
                   1834: 		$r->print($currentversion);
                   1835: 	    }
                   1836: 	    $r->print('</font></span></td><td title="'.$lt{'vu'}.'">'.
                   1837:                       '<span class="LC_nobreak">Use: ');
                   1838: # Set version
                   1839: 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
                   1840: 						      'set_version_'.$linkurl,
1.428     raeburn  1841: 						      {'select_form_order' =>
1.329     droeschl 1842: 						       ['',1..$currentversion,'mostrecent'],
                   1843: 						       '' => '',
1.411     bisitz   1844: 						       'mostrecent' => &mt('most recent'),
1.428     raeburn  1845: 						       map {$_,$_} (1..$currentversion)}));
1.329     droeschl 1846: 	    $r->print('</span></td></tr><tr><td></td>');
                   1847: 	    my $lastold=1;
                   1848: 	    for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                   1849: 		my $url=$root.'.'.$prevvers.'.'.$extension;
                   1850: 		if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
                   1851: 		    $starttime) {
                   1852: 		    $lastold=$prevvers;
                   1853: 		}
                   1854: 	    }
1.364     bisitz   1855:             #
1.329     droeschl 1856:             # Code to figure out how many version entries should go in
                   1857:             # each of the four columns
                   1858:             my $entries_per_col = 0;
                   1859:             my $num_entries = ($currentversion-$lastold);
                   1860:             if ($num_entries % 4 == 0) {
                   1861:                 $entries_per_col = $num_entries/4;
                   1862:             } else {
                   1863:                 $entries_per_col = $num_entries/4 + 1;
                   1864:             }
                   1865:             my $entries_count = 0;
1.344     bisitz   1866:             $r->print('<td valign="top"><font size="-2">');
1.329     droeschl 1867:             my $cols_output = 1;
                   1868:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
                   1869: 		my $url=$root.'.'.$prevvers.'.'.$extension;
                   1870: 		$r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
                   1871: 			  '">'.&mt('Version').' '.$prevvers.'</a> ('.
                   1872: 			  &Apache::lonlocal::locallocaltime(
                   1873:                                 &Apache::lonnet::metadata($url,
                   1874:                                                           'lastrevisiondate')
                   1875:                                                             ).
                   1876: 			  ')');
                   1877: 		if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
                   1878:                     $r->print(' <a href="/adm/diff?filename='.
                   1879: 			      &Apache::lonnet::clutter($root.'.'.$extension).
                   1880: 			      '&versionone='.$prevvers.
1.462     raeburn  1881: 			      '" target="diffs">'.&mt('Diffs').'</a>');
1.329     droeschl 1882: 		}
                   1883: 		$r->print('</span><br />');
                   1884:                 if (++$entries_count % $entries_per_col == 0) {
                   1885:                     $r->print('</font></td>');
                   1886:                     if ($cols_output != 4) {
                   1887:                         $r->print('<td valign="top"><font size="-2">');
                   1888:                         $cols_output++;
                   1889:                     }
                   1890:                 }
                   1891: 	    }
                   1892:             while($cols_output++ < 4) {
                   1893:                 $r->print('</font></td><td><font>')
                   1894:             }
                   1895: 	    $r->print('</font></td></tr>'."\n");
                   1896: 	}
                   1897:     }
                   1898:     $r->print('</table></form>');
1.419     bisitz   1899:     $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.329     droeschl 1900: 
                   1901:     &untiehash();
                   1902: }
                   1903: 
                   1904: sub mark_hash_old {
                   1905:     my $retie_hash=0;
                   1906:     if ($hashtied) {
                   1907: 	$retie_hash=1;
                   1908: 	&untiehash();
                   1909:     }
                   1910:     &tiehash('write');
                   1911:     $hash{'old'}=1;
                   1912:     &untiehash();
                   1913:     if ($retie_hash) { &tiehash(); }
                   1914: }
                   1915: 
                   1916: sub is_hash_old {
                   1917:     my $untie_hash=0;
                   1918:     if (!$hashtied) {
                   1919: 	$untie_hash=1;
                   1920: 	&tiehash();
                   1921:     }
                   1922:     my $return=$hash{'old'};
                   1923:     if ($untie_hash) { &untiehash(); }
                   1924:     return $return;
                   1925: }
                   1926: 
                   1927: sub changewarning {
                   1928:     my ($r,$postexec,$message,$url)=@_;
                   1929:     if (!&is_hash_old()) { return; }
                   1930:     my $pathvar='folderpath';
                   1931:     my $path=&escape($env{'form.folderpath'});
                   1932:     if (!defined($url)) {
                   1933: 	if (defined($env{'form.pagepath'})) {
                   1934: 	    $pathvar='pagepath';
                   1935: 	    $path=&escape($env{'form.pagepath'});
                   1936: 	    $path.='&amp;pagesymb='.&escape($env{'form.pagesymb'});
                   1937: 	}
                   1938: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
                   1939:     }
                   1940:     my $course_type = &Apache::loncommon::course_type();
                   1941:     if (!defined($message)) {
                   1942: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
                   1943:     }
                   1944:     $r->print("\n\n".
1.372     bisitz   1945: '<script type="text/javascript">'."\n".
                   1946: '// <![CDATA['."\n".
                   1947: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
                   1948: '// ]]>'."\n".
1.369     bisitz   1949: '</script>'."\n".
1.375     tempelho 1950: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329     droeschl 1951: '<input type="hidden" name="orgurl" value="'.$url.
1.372     bisitz   1952: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329     droeschl 1953: &mt($message,' <input type="hidden" name="'.
                   1954:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369     bisitz   1955:     &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372     bisitz   1956: $help{'Caching'}.'</p></form>'."\n\n");
1.329     droeschl 1957: }
                   1958: 
                   1959: 
                   1960: sub init_breadcrumbs {
                   1961:     my ($form,$text)=@_;
                   1962:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                   1963:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
1.405     bisitz   1964: 					    text=>&Apache::loncommon::course_type().' Editor',
1.329     droeschl 1965: 					    faq=>273,
                   1966: 					    bug=>'Instructor Interface',
                   1967:                                             help => 'Docs_Adding_Course_Doc'});
                   1968:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
                   1969: 					    text=>$text,
                   1970: 					    faq=>273,
                   1971: 					    bug=>'Instructor Interface'});
                   1972: }
                   1973: 
1.441     www      1974: # subroutine to list form elements
                   1975: sub create_list_elements {
                   1976:    my @formarr = @_;
                   1977:    my $list = '';
                   1978:    for my $button (@formarr){
                   1979:         for my $picture(keys %$button) {
                   1980:             $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
                   1981:         }
                   1982:    }
                   1983:    return $list;
                   1984: }
1.329     droeschl 1985: 
1.441     www      1986: # subroutine to create ul from list elements
                   1987: sub create_form_ul {
                   1988:    my $list = shift;
                   1989:    my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
                   1990:    return $ul;
                   1991: }
1.329     droeschl 1992: 
1.442     www      1993: #
                   1994: # Start tabs
                   1995: #
                   1996: 
                   1997: sub startContentScreen {
                   1998:     my ($r,$mode)=@_;
                   1999:     $r->print('<ul class="LC_TabContentBigger" id="mainnav">');
1.472     raeburn  2000:     if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
                   2001:         $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");
                   2002:         $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");
                   2003:         $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");
                   2004:         $r->print('<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>');
                   2005:     } else {
1.444     www      2006:         $r->print('<li '.(($mode eq 'docs')?' class="active"':'').
1.457     raeburn  2007:                ' 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>');
1.472     raeburn  2008:         $r->print('<li '.(($mode eq 'suppdocs')?' class="active"':'').
                   2009:                   '><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>');
1.444     www      2010:     }
1.472     raeburn  2011:     $r->print("\n".'</ul>'."\n");
1.474     raeburn  2012:     $r->print('<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
                   2013:               '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
                   2014:               '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">');
1.442     www      2015: }
                   2016: 
                   2017: #
                   2018: # End tabs
                   2019: #
                   2020: 
                   2021: sub endContentScreen {
                   2022:    my ($r)=@_;
                   2023:    $r->print('</div></div></div>');
                   2024: }
1.329     droeschl 2025: 
1.446     www      2026: sub supplemental_base {
1.472     raeburn  2027:     return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
1.446     www      2028: }
                   2029: 
1.329     droeschl 2030: sub handler {
                   2031:     my $r = shift;
                   2032:     &Apache::loncommon::content_type($r,'text/html');
                   2033:     $r->send_http_header;
                   2034:     return OK if $r->header_only;
1.408     raeburn  2035:     my $crstype = &Apache::loncommon::course_type();
1.329     droeschl 2036: 
1.443     www      2037: #
1.329     droeschl 2038: # --------------------------------------------- Initialize help topics for this
                   2039:     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
                   2040: 	               'Adding_External_Resource','Navigate_Content',
                   2041: 	               'Adding_Folders','Docs_Overview', 'Load_Map',
                   2042: 	               'Supplemental','Score_Upload_Form','Adding_Pages',
                   2043: 	               'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
                   2044: 	               'Check_Resource_Versions','Verify_Content') {
                   2045: 	$help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
                   2046:     }
                   2047:     # Composite help files
                   2048:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   2049: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   2050:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   2051: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
                   2052:     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
                   2053: 		    'Option_Response_Simple');
                   2054:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   2055: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347     weissno  2056:     $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329     droeschl 2057: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353     weissno  2058:     $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329     droeschl 2059:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
                   2060: 
1.472     raeburn  2061:     
                   2062:     my $allowed;
                   2063: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
                   2064:     unless ($r->uri eq '/adm/supplemental') {
                   2065:         # does this user have privileges to modify content.  
                   2066:         $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                   2067:     }
                   2068: 
1.329     droeschl 2069:   if ($allowed && $env{'form.verify'}) {
                   2070:       &init_breadcrumbs('verify','Verify Content');
                   2071:       &verifycontent($r);
                   2072:   } elsif ($allowed && $env{'form.listsymbs'}) {
                   2073:       &init_breadcrumbs('listsymbs','List Symbs');
                   2074:       &list_symbs($r);
                   2075:   } elsif ($allowed && $env{'form.docslog'}) {
                   2076:       &init_breadcrumbs('docslog','Show Log');
                   2077:       &docs_change_log($r);
                   2078:   } elsif ($allowed && $env{'form.versions'}) {
                   2079:       &init_breadcrumbs('versions','Check/Set Resource Versions');
                   2080:       &checkversions($r);
                   2081:   } elsif ($allowed && $env{'form.dumpcourse'}) {
1.419     bisitz   2082:       &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Documents to Construction Space');
1.329     droeschl 2083:       &dumpcourse($r);
                   2084:   } elsif ($allowed && $env{'form.exportcourse'}) {
1.377     bisitz   2085:       &init_breadcrumbs('exportcourse','IMS Export');
1.475     raeburn  2086:       &Apache::imsexport::exportcourse($r);
1.329     droeschl 2087:   } else {
1.445     www      2088: #
                   2089: # Done catching special calls
                   2090: # The whole rest is for course and supplemental documents
                   2091: # Get the parameters that may be needed
                   2092: #
                   2093:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   2094:                                             ['folderpath','pagepath',
1.466     www      2095:                                              'pagesymb','forcesupplement','forcestandard',
                   2096:                                              'symb','command']);
1.445     www      2097: 
                   2098: # standard=1: this is a "new-style" course with an uploaded map as top level
                   2099: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329     droeschl 2100: 
                   2101:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445     www      2102: 
                   2103: # Decide whether this should display supplemental or main content
                   2104: # supplementalflag=1: show supplemental documents
                   2105: # supplementalflag=0: show standard documents
                   2106: 
                   2107: 
                   2108:     my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
                   2109:     if (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'} eq "" || ($env{'form.pagepath'})) {
                   2110:        $supplementalflag=0;
                   2111:     }
                   2112:     if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
                   2113:     if ($env{'form.forcestandard'})   { $supplementalflag=0; }
                   2114:     unless ($allowed) { $supplementalflag=1; }
                   2115:     unless ($standard) { $supplementalflag=1; }
                   2116: 
1.329     droeschl 2117:     my $script='';
                   2118:     my $showdoc=0;
1.457     raeburn  2119:     my $addentries = {};
1.475     raeburn  2120:     my $container;
1.329     droeschl 2121:     my $containertag;
                   2122:     my $uploadtag;
                   2123: 
1.464     www      2124: # Do we directly jump somewhere?
1.466     www      2125: 
1.464     www      2126:    if ($env{'form.command'} eq 'direct') {
1.468     raeburn  2127:        my ($mapurl,$id,$resurl);
1.472     raeburn  2128:        if ($env{'form.symb'} ne '') {
1.468     raeburn  2129:            ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   2130:            if ($resurl=~/\.(sequence|page)$/) {
                   2131:                $mapurl=$resurl;
                   2132:            } elsif ($resurl eq 'adm/navmaps') {
                   2133:                $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
                   2134:            }
1.472     raeburn  2135:            my $mapresobj;
                   2136:            my $navmap = Apache::lonnavmaps::navmap->new();
                   2137:            if (ref($navmap)) {
                   2138:                $mapresobj = $navmap->getResourceByUrl($mapurl);
                   2139:            }
                   2140:            $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
                   2141:            my $type=$2;
                   2142:            my $path;
                   2143:            if (ref($mapresobj)) {
                   2144:                my $pcslist = $mapresobj->map_hierarchy();
                   2145:                if ($pcslist ne '') {
                   2146:                    foreach my $pc (split(/,/,$pcslist)) {
                   2147:                        next if ($pc <= 1);
                   2148:                        my $res = $navmap->getByMapPc($pc);
                   2149:                        if (ref($res)) {
                   2150:                            my $thisurl = $res->src();
                   2151:                            $thisurl=~s{^.*/([^/]+)\.\w+$}{$1}; 
                   2152:                            my $thistitle = $res->title();
                   2153:                            $path .= '&'.
                   2154:                                     &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
                   2155:                                     &Apache::lonhtmlcommon::entity_encode($thistitle).
                   2156:                                     ':'.$res->randompick().
                   2157:                                     ':'.$res->randomout().
                   2158:                                     ':'.$res->encrypted().
                   2159:                                     ':'.$res->randomorder();
                   2160:                        }
1.467     raeburn  2161:                    }
                   2162:                }
1.472     raeburn  2163:                $path .= '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.467     raeburn  2164:                     &Apache::lonhtmlcommon::entity_encode($mapresobj->title()).
                   2165:                     ':'.$mapresobj->randompick().
                   2166:                     ':'.$mapresobj->randomout().
                   2167:                     ':'.$mapresobj->encrypted().
                   2168:                     ':'.$mapresobj->randomorder();
1.472     raeburn  2169:            } else {
                   2170:                my $maptitle = &Apache::lonnet::gettitle($mapurl);
                   2171:                $path = '&default&...::::'.
                   2172:                    '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
                   2173:                    &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
                   2174:            }
                   2175:            $path = 'default&'.
                   2176:                    &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
                   2177:                    $path;
                   2178:            if ($type eq 'sequence') {
                   2179:                $env{'form.folderpath'}=$path;
                   2180:                $env{'form.pagepath'}='';
                   2181:            } else {
                   2182:                $env{'form.pagepath'}=$path;
                   2183:                $env{'form.folderpath'}='';
                   2184:            }
                   2185:        } elsif ($env{'form.supppath'} ne '') {
                   2186:            $env{'form.folderpath'}=$env{'form.supppath'};
1.466     www      2187:        }
1.472     raeburn  2188:    } elsif ($env{'form.command'} eq 'editdocs') {
                   2189:         $env{'form.folderpath'} = 'default&'.
                   2190:                                   &Apache::lonhtmlcommon::entity_encode('Main Course Content');
                   2191:         $env{'form.pagepath'}='';
                   2192:    } elsif ($env{'form.command'} eq 'editsupp') {
                   2193:         $env{'form.folderpath'} = 'default&'.
                   2194:                                   &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
                   2195:         $env{'form.pagepath'}='';
1.464     www      2196:    }
                   2197: 
1.445     www      2198: # Where do we store these for when we come back?
                   2199:     my $stored_folderpath='docs_folderpath';
                   2200:     if ($supplementalflag) {
                   2201:        $stored_folderpath='docs_sup_folderpath';
                   2202:     }
1.464     www      2203: 
1.329     droeschl 2204: # No folderpath, no pagepath, see if we have something stored
                   2205:     if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
1.445     www      2206:         &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329     droeschl 2207:                                               {'folderpath' => 'scalar'});
                   2208:     }
1.446     www      2209:    
                   2210: # If we are not allowed to make changes, all we can see are supplemental docs
1.409     raeburn  2211:     if (!$allowed) {
1.446     www      2212:         $env{'form.pagepath'}='';
                   2213:         unless ($env{'form.folderpath'} =~ /^supplemental/) {
                   2214:             $env{'form.folderpath'} = &supplemental_base();
1.409     raeburn  2215:         }
                   2216:     }
1.446     www      2217: # If we still not have a folderpath, see if we can resurrect at pagepath
1.409     raeburn  2218:     if (!$env{'form.folderpath'} && $allowed) {
1.445     www      2219:         &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329     droeschl 2220:                                               {'pagepath' => 'scalar'});
                   2221:     }
1.446     www      2222: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329     droeschl 2223:     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446     www      2224:         $env{'form.folderpath'} = &supplemental_base()
                   2225:                                   .'&'.
1.329     droeschl 2226:                                   $env{'form.folderpath'};
                   2227:     }
1.446     www      2228: # If after all of this, we still don't have any paths, make them
                   2229:     unless (($env{'form.pagepath'}) || ($env{'form.folderpath'})) {
                   2230:        if ($supplementalflag) {
                   2231:           $env{'form.folderpath'}=&supplemental_base();
                   2232:        } else {
                   2233:           $env{'form.folderpath'}='default';
                   2234:        }
1.472     raeburn  2235:     }
1.446     www      2236: 
1.445     www      2237: # Store this
1.447     www      2238:     &Apache::loncommon::store_course_settings($stored_folderpath,
1.329     droeschl 2239:                                                 {'pagepath' => 'scalar',
                   2240:                                                  'folderpath' => 'scalar'});
1.446     www      2241: 
1.329     droeschl 2242:     if ($env{'form.folderpath'}) {
                   2243: 	my (@folderpath)=split('&',$env{'form.folderpath'});
                   2244: 	$env{'form.foldername'}=&unescape(pop(@folderpath));
                   2245: 	$env{'form.folder'}=pop(@folderpath);
1.475     raeburn  2246:         $container='sequence';
1.329     droeschl 2247:     }
                   2248:     if ($env{'form.pagepath'}) {
                   2249:         my (@pagepath)=split('&',$env{'form.pagepath'});
                   2250:         $env{'form.pagename'}=&unescape(pop(@pagepath));
                   2251:         $env{'form.folder'}=pop(@pagepath);
1.475     raeburn  2252:         $container='page';
1.329     droeschl 2253:         $containertag = '<input type="hidden" name="pagepath" value="" />'.
1.434     raeburn  2254: 	                '<input type="hidden" name="pagesymb" value="" />';
                   2255:         $uploadtag = 
                   2256:             '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
                   2257: 	    '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />'.
                   2258:             '<input type="hidden" name="folderpath" value="" />';
1.433     raeburn  2259:     } else {
                   2260:         my $folderpath=$env{'form.folderpath'};
                   2261:         if (!$folderpath) {
                   2262:             if ($env{'form.folder'} eq '' ||
                   2263:                 $env{'form.folder'} eq 'supplemental') {
                   2264:                 $folderpath='default&'.
                   2265:                     &escape(&mt('Main '.$crstype.' Documents'));
                   2266:             }
                   2267:         }
                   2268:         $containertag = '<input type="hidden" name="folderpath" value="" />';
                   2269:         $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.329     droeschl 2270:     }
                   2271:     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
                   2272:        $showdoc='/'.$1;
                   2273:     }
1.402     raeburn  2274:     if ($showdoc) { # got called in sequence from course
                   2275: 	$allowed=0; 
                   2276:     } else {
1.344     bisitz   2277:        if ($allowed) {
1.329     droeschl 2278:          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1.344     bisitz   2279:          $script=&Apache::lonratedt::editscript('simple');
1.329     droeschl 2280:        }
                   2281:     }
                   2282: 
                   2283: # get course data
                   2284:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   2285:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   2286: 
1.344     bisitz   2287: # get personal data
1.329     droeschl 2288:     my $uname=$env{'user.name'};
                   2289:     my $udom=$env{'user.domain'};
                   2290:     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
                   2291: 
                   2292: # graphics settings
                   2293: 
                   2294:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
                   2295: 
                   2296:     if ($allowed) {
1.458     raeburn  2297:         my @tabids;
                   2298:         if ($supplementalflag) {
                   2299:             @tabids = ('002','ee2','ff2');
                   2300:         } else {
                   2301:             @tabids = ('aa1','bb1','cc1','ff1');
                   2302:             unless ($env{'form.pagepath'}) {
                   2303:                 unshift(@tabids,'001');
                   2304:                 push(@tabids,('dd1','ee1'));
                   2305:             }
                   2306:         }
                   2307:         my $tabidstr = join("','",@tabids);
1.472     raeburn  2308: 	$script .= &editing_js($udom,$uname,$supplementalflag).
1.458     raeburn  2309:                    &resize_contentdiv_js($tabidstr);
1.457     raeburn  2310:         $addentries = {
1.458     raeburn  2311:                         onload   => "javascript:resize_contentdiv('contentscroll','1','1');",
1.457     raeburn  2312:                       };
1.329     droeschl 2313:     }
                   2314: # -------------------------------------------------------------------- Body tag
1.369     bisitz   2315:     $script = '<script type="text/javascript">'."\n"
1.372     bisitz   2316:               .'// <![CDATA['."\n"
                   2317:               .$script."\n"
                   2318:               .'// ]]>'."\n"
                   2319:               .'</script>'."\n";
1.385     bisitz   2320: 
                   2321:     # Breadcrumbs
                   2322:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.446     www      2323:     unless ($showdoc) {
1.392     raeburn  2324:         &Apache::lonhtmlcommon::add_breadcrumb({
1.446     www      2325:             href=>"/adm/coursedocs",text=>"$crstype Contents"});
1.392     raeburn  2326: 
1.446     www      2327:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.457     raeburn  2328:                                                  {'force_register' => $showdoc,
                   2329:                                                   'add_entries'    => $addentries,
                   2330:                                                  })
1.392     raeburn  2331:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   2332:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.408     raeburn  2333:                      'Editing the Table of Contents for your '.$crstype,
1.392     raeburn  2334:                      'Docs_Adding_Course_Doc')
                   2335:         );
1.446     www      2336:     } else {
1.408     raeburn  2337:         $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
1.402     raeburn  2338:                                                 {'force_register' => $showdoc,}));
1.392     raeburn  2339:     }
1.364     bisitz   2340: 
1.329     droeschl 2341:   my %allfiles = ();
                   2342:   my %codebase = ();
1.440     raeburn  2343:   my ($upload_result,$upload_output,$uploadphase);
1.329     droeschl 2344:   if ($allowed) {
                   2345:       if (($env{'form.uploaddoc.filename'}) &&
                   2346: 	  ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440     raeburn  2347:           my $context = $1; 
                   2348:           # Process file upload - phase one - upload and parse primary file.
1.329     droeschl 2349: 	  undef($hadchanges);
1.440     raeburn  2350:           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
                   2351:                                               \%allfiles,\%codebase,$context);
1.329     droeschl 2352: 	  if ($hadchanges) {
                   2353: 	      &mark_hash_old();
                   2354: 	  }
1.440     raeburn  2355:           $r->print($upload_output);
                   2356:       } elsif ($env{'form.phase'} eq 'upload_embedded') {
                   2357:           # Process file upload - phase two - upload embedded objects 
                   2358:           $uploadphase = 'check_embedded';
                   2359:           my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');   
                   2360:           my $state = &embedded_form_elems($uploadphase,$primaryurl,
                   2361:                                            $env{'form.newidx'});
                   2362:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   2363:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   2364:           my ($destination,$dir_root) = &embedded_destination();
                   2365:           my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
                   2366:           my $actionurl = '/adm/coursedocs';
                   2367:           my ($result,$flag) = 
                   2368:               &Apache::loncommon::upload_embedded('coursedoc',$destination,
                   2369:                   $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
                   2370:                   $actionurl);
                   2371:           $r->print($result.&return_to_editor());
                   2372:       } elsif ($env{'form.phase'} eq 'check_embedded') {
                   2373:           # Process file upload - phase three - modify references in HTML file
                   2374:           $uploadphase = 'modified_orightml';
                   2375:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   2376:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   2377:           my ($destination,$dir_root) = &embedded_destination();
                   2378:           $r->print(&Apache::loncommon::modify_html_refs('coursedoc',$destination,
                   2379:                                                          $docuname,$docudom,undef,
                   2380:                                                          $dir_root).
                   2381:                    &return_to_editor());
1.476     raeburn  2382:       } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
                   2383:           $uploadphase = 'decompress_phase_one';
                   2384:           $r->print(&decompression_phase_one().
                   2385:                     &return_to_editor());
                   2386:       } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
                   2387:           $uploadphase = 'decompress_phase_two';
                   2388:           $r->print(&decompression_phase_two().
                   2389:                     &return_to_editor());
1.329     droeschl 2390:       }
                   2391:   }
                   2392: 
1.440     raeburn  2393:   unless ($showdoc || $uploadphase) {  
1.329     droeschl 2394: # -----------------------------------------------------------------------------
                   2395:        my %lt=&Apache::lonlocal::texthash(
1.408     raeburn  2396:                 'uplm' => 'Upload a new main '.lc($crstype).' document',
                   2397:                 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
1.329     droeschl 2398:                 'impp' => 'Import a document',
                   2399: 		'copm' => 'All documents out of a published map into this folder',
1.417     droeschl 2400:                 'upld' => 'Import Document',
1.329     droeschl 2401:                 'srch' => 'Search',
                   2402:                 'impo' => 'Import',
1.435     wenzelju 2403: 		'wish' => 'Import from Wishlist',
1.329     droeschl 2404:                 'selm' => 'Select Map',
                   2405:                 'load' => 'Load Map',
1.419     bisitz   2406:                 'reco' => 'Recover Deleted Documents',
1.329     droeschl 2407:                 'newf' => 'New Folder',
                   2408:                 'newp' => 'New Composite Page',
                   2409:                 'extr' => 'External Resource',
                   2410:                 'syll' => 'Syllabus',
1.425     raeburn  2411:                 'navc' => 'Table of Contents',
1.343     biermanm 2412:                 'sipa' => 'Simple Course Page',
1.329     droeschl 2413:                 'sipr' => 'Simple Problem',
                   2414:                 'drbx' => 'Drop Box',
1.451     www      2415:                 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336     schafran 2416:                 'bull' => 'Discussion Board',
1.347     weissno  2417:                 'mypi' => 'My Personal Information Page',
1.353     weissno  2418:                 'grpo' => 'Group Portfolio',
1.329     droeschl 2419:                 'rost' => 'Course Roster',
1.348     weissno  2420: 				'abou' => 'Personal Information Page for a User',
1.377     bisitz   2421:                 'imsf' => 'IMS Import',
                   2422:                 'imsl' => 'Import IMS package',
1.329     droeschl 2423:                 'file' =>  'File',
                   2424:                 'title' => 'Title',
                   2425:                 'comment' => 'Comment',
1.403     raeburn  2426:                 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.368     truskell 2427: 		'nd' => 'Upload Document',
1.329     droeschl 2428: 		'pm' => 'Published Map',
                   2429: 		'sd' => 'Special Document',
                   2430: 		'mo' => 'More Options',
                   2431: 					  );
                   2432: # -----------------------------------------------------------------------------
                   2433: 	my $fileupload=(<<FIUP);
                   2434: 	$lt{'file'}:<br />
                   2435: 	<input type="file" name="uploaddoc" size="40" />
                   2436: FIUP
                   2437: 
                   2438: 	my $checkbox=(<<CHBO);
                   2439: 	<!-- <label>$lt{'parse'}?
                   2440: 	<input type="checkbox" name="parserflag" />
                   2441: 	</label> -->
                   2442: 	<label>
                   2443: 	<input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
                   2444: 	</label>
                   2445: CHBO
                   2446: 
1.458     raeburn  2447:     my $fileuploada = "<br clear='all' /><input type='submit' value='".$lt{'upld'}."' /> $help{'Uploading_From_Harddrive'}";
1.329     droeschl 2448: 	my $fileuploadform=(<<FUFORM);
                   2449: 	<form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.371     tempelho 2450: 	<input type="hidden" name="active" value="aa" />
1.329     droeschl 2451: 	$fileupload
                   2452: 	<br />
                   2453: 	$lt{'title'}:<br />
1.458     raeburn  2454: 	<input type="text" size="60" name="comment" />
1.329     droeschl 2455: 	$uploadtag
                   2456: 	<input type="hidden" name="cmd" value="upload_default" />
                   2457: 	<br />
1.458     raeburn  2458: 	<span class="LC_nobreak" style="float:left">
1.329     droeschl 2459: 	$checkbox
                   2460: 	</span>
1.383     tempelho 2461: FUFORM
1.459     raeburn  2462:     $fileuploadform .= $fileuploada.'</form>';
1.329     droeschl 2463: 
                   2464: 	my $simpleeditdefaultform=(<<SEDFFORM);
                   2465: 	<form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.371     tempelho 2466: 	<input type="hidden" name="active" value="bb" />
1.383     tempelho 2467: SEDFFORM
                   2468: 	my @simpleeditdefaultforma = ( 
1.423     onken    2469: 	{ '<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>" },
                   2470: 	{ '<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'}" },
1.435     wenzelju 2471: 	{ '<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>" },
1.383     tempelho 2472: 	);
1.443     www      2473: 	$simpleeditdefaultform .= &create_form_ul(&create_list_elements(@simpleeditdefaultforma));
1.383     tempelho 2474: 	$simpleeditdefaultform .=(<<SEDFFORM);
1.459     raeburn  2475: 	<hr id="bb_hrule" style="width:0px;text-align:left;margin-left:0" />
1.329     droeschl 2476: 	$lt{'copm'}<br />
                   2477: 	<input type="text" size="40" name="importmap" /><br />
1.458     raeburn  2478: 	<span class="LC_nobreak" style="float:left"><input type="button"
1.369     bisitz   2479: 	onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.329     droeschl 2480: 	value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
                   2481: 	$help{'Load_Map'}</span>
                   2482: 	</form>
                   2483: SEDFFORM
                   2484: 
1.442     www      2485:       my $extresourcesform=(<<ERFORM);
                   2486:       <form action="/adm/coursedocs" method="post" name="newext">
                   2487:       $uploadtag
                   2488:       <input type="hidden" name="importdetail" value="" />
                   2489:       <a class="LC_menubuttons_link" href="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
                   2490:       </form>
1.329     droeschl 2491: ERFORM
                   2492: 
1.442     www      2493: 
1.329     droeschl 2494:     if ($allowed) {
                   2495: 	&update_paste_buffer($coursenum,$coursedom);
                   2496:        my %lt=&Apache::lonlocal::texthash(
                   2497: 					 'vc' => 'Verify Content',
                   2498: 					 'cv' => 'Check/Set Resource Versions',
                   2499: 					 'ls' => 'List Symbs',
                   2500:                                          'sl' => 'Show Log'
                   2501: 					  );
                   2502: 
1.337     ehlerst  2503: 	$r->print(<<HIDDENFORM);
                   2504: 	<form name="renameform" method="post" action="/adm/coursedocs">
                   2505:    <input type="hidden" name="title" />
                   2506:    <input type="hidden" name="cmd" />
                   2507:    <input type="hidden" name="markcopy" />
                   2508:    <input type="hidden" name="copyfolder" />
                   2509:    $containertag
                   2510:  </form>
                   2511:  <form name="simpleedit" method="post" action="/adm/coursedocs">
                   2512:    <input type="hidden" name="importdetail" value="" />
                   2513:    $uploadtag
                   2514:  </form>
                   2515: HIDDENFORM
1.329     droeschl 2516:     }
1.442     www      2517: 
                   2518: # Generate the tabs
1.472     raeburn  2519:     my $mode;
                   2520:     if (($supplementalflag) && (!$allowed)) {
                   2521:         &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
                   2522:     } else {
                   2523:         &startContentScreen($r,($supplementalflag?'suppdocs':'docs'));
                   2524:     }
1.443     www      2525: 
1.442     www      2526: #
                   2527: 
                   2528:     my $savefolderpath;
                   2529: 
1.395     raeburn  2530:     if ($allowed) {
1.329     droeschl 2531:        my $folder=$env{'form.folder'};
1.443     www      2532:        if ($folder eq '' || $supplementalflag) {
1.329     droeschl 2533:            $folder='default';
1.356     tempelho 2534: 	   $savefolderpath = $env{'form.folderpath'};
1.442     www      2535: 	   $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
1.329     droeschl 2536:            $uploadtag = '<input type="hidden" name="folderpath" value="'.
                   2537: 	       &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
                   2538:        }
                   2539:        my $postexec='';
                   2540:        if ($folder eq 'default') {
1.372     bisitz   2541:            $r->print('<script type="text/javascript">'."\n"
                   2542:                     .'// <![CDATA['."\n"
                   2543:                     .'this.window.name="loncapaclient";'."\n"
                   2544:                     .'// ]]>'."\n"
                   2545:                     .'</script>'."\n"
1.369     bisitz   2546:        );
1.329     droeschl 2547:        } else {
                   2548:            #$postexec='self.close();';
                   2549:        }
                   2550:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                   2551:                      '.sequence';
                   2552:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                   2553:                      '.page';
                   2554: 	my $container='sequence';
                   2555: 	if ($env{'form.pagepath'}) {
                   2556: 	    $container='page';
                   2557: 	}
                   2558: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
                   2559: 
                   2560: 
                   2561: 
                   2562: 	my $recoverform=(<<RFORM);
                   2563: 	<form action="/adm/groupsort" method="post" name="recover">
1.436     wenzelju 2564: 	<a class="LC_menubuttons_link" href="javascript:groupopen('$readfile',1)">$lt{'reco'}</a>
1.329     droeschl 2565: 	</form>
                   2566: RFORM
                   2567: 
                   2568: 	my $imspform=(<<IMSPFORM);
                   2569: 	<form action="/adm/imsimportdocs" method="post" name="ims">
                   2570: 	<input type="hidden" name="folder" value="$folder" />
1.423     onken    2571: 	<a class="LC_menubuttons_link" href="javascript:makeims();">$lt{'imsf'}</a>
1.329     droeschl 2572: 	</form>
                   2573: IMSPFORM
                   2574: 
                   2575: 	my $newnavform=(<<NNFORM);
                   2576: 	<form action="/adm/coursedocs" method="post" name="newnav">
1.371     tempelho 2577: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 2578: 	$uploadtag
                   2579: 	<input type="hidden" name="importdetail" 
                   2580: 	value="$lt{'navc'}=/adm/navmaps" />
1.423     onken    2581: 	<a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329     droeschl 2582: 	$help{'Navigate_Content'}
                   2583: 	</form>
                   2584: NNFORM
                   2585: 	my $newsmppageform=(<<NSPFORM);
                   2586: 	<form action="/adm/coursedocs" method="post" name="newsmppg">
1.371     tempelho 2587: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 2588: 	$uploadtag
                   2589: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    2590: 	<a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383     tempelho 2591: 	$help{'Simple Page'}
1.329     droeschl 2592: 	</form>
                   2593: NSPFORM
                   2594: 
                   2595: 	my $newsmpproblemform=(<<NSPROBFORM);
                   2596: 	<form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371     tempelho 2597: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 2598: 	$uploadtag
                   2599: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    2600: 	<a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.383     tempelho 2601: 	$help{'Simple Problem'}
1.329     droeschl 2602: 	</form>
                   2603: 
                   2604: NSPROBFORM
                   2605: 
                   2606: 	my $newdropboxform=(<<NDBFORM);
                   2607: 	<form action="/adm/coursedocs" method="post" name="newdropbox">
1.371     tempelho 2608: 	<input type="hidden" name="active" value="cc" />
1.344     bisitz   2609: 	$uploadtag
1.329     droeschl 2610: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    2611: 	<a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.344     bisitz   2612: 	</form>
1.329     droeschl 2613: NDBFORM
                   2614: 
                   2615: 	my $newexuploadform=(<<NEXUFORM);
                   2616: 	<form action="/adm/coursedocs" method="post" name="newexamupload">
1.371     tempelho 2617: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 2618: 	$uploadtag
                   2619: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    2620: 	<a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329     droeschl 2621: 	$help{'Score_Upload_Form'}
                   2622: 	</form>
                   2623: NEXUFORM
                   2624: 
                   2625: 	my $newbulform=(<<NBFORM);
                   2626: 	<form action="/adm/coursedocs" method="post" name="newbul">
1.371     tempelho 2627: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 2628: 	$uploadtag
                   2629: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    2630: 	<a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329     droeschl 2631: 	$help{'Bulletin Board'}
                   2632: 	</form>
                   2633: NBFORM
                   2634: 
                   2635: 	my $newaboutmeform=(<<NAMFORM);
                   2636: 	<form action="/adm/coursedocs" method="post" name="newaboutme">
1.371     tempelho 2637: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 2638: 	$uploadtag
                   2639: 	<input type="hidden" name="importdetail" 
                   2640: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.423     onken    2641: 	<a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347     weissno  2642: 	$help{'My Personal Information Page'}
1.329     droeschl 2643: 	</form>
                   2644: NAMFORM
                   2645: 
                   2646: 	my $newaboutsomeoneform=(<<NASOFORM);
                   2647: 	<form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371     tempelho 2648: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 2649: 	$uploadtag
                   2650: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    2651: 	<a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329     droeschl 2652: 	</form>
                   2653: NASOFORM
                   2654: 
                   2655: 
                   2656: 	my $newrosterform=(<<NROSTFORM);
                   2657: 	<form action="/adm/coursedocs" method="post" name="newroster">
1.371     tempelho 2658: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 2659: 	$uploadtag
                   2660: 	<input type="hidden" name="importdetail" 
                   2661: 	value="$lt{'rost'}=/adm/viewclasslist" />
1.423     onken    2662: 	<a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.329     droeschl 2663: 	$help{'Course Roster'}
                   2664: 	</form>
                   2665: NROSTFORM
                   2666: 
1.342     ehlerst  2667: my $specialdocumentsform;
1.383     tempelho 2668: my @specialdocumentsforma;
1.451     www      2669: my $gradingform;
                   2670: my @gradingforma;
                   2671: my $communityform;
                   2672: my @communityforma;
1.351     ehlerst  2673: my $newfolderform;
1.390     tempelho 2674: my $newfolderb;
1.342     ehlerst  2675: 
1.451     www      2676: 	my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383     tempelho 2677: 	
1.329     droeschl 2678: 	my $newpageform=(<<NPFORM);
                   2679: 	<form action="/adm/coursedocs" method="post" name="newpage">
                   2680: 	<input type="hidden" name="folderpath" value="$path" />
                   2681: 	<input type="hidden" name="importdetail" value="" />
1.371     tempelho 2682: 	<input type="hidden" name="active" value="cc" />
1.423     onken    2683: 	<a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383     tempelho 2684: 	$help{'Adding_Pages'}
1.329     droeschl 2685: 	</form>
                   2686: NPFORM
1.390     tempelho 2687: 
                   2688: 
1.351     ehlerst  2689: 	$newfolderform=(<<NFFORM);
1.329     droeschl 2690: 	<form action="/adm/coursedocs" method="post" name="newfolder">
                   2691: 	<input type="hidden" name="folderpath" value="$path" />
                   2692: 	<input type="hidden" name="importdetail" value="" />
1.371     tempelho 2693: 	<input type="hidden" name="active" value="aa" />
1.422     onken    2694: 	<a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329     droeschl 2695: 	</form>
                   2696: NFFORM
                   2697: 
                   2698: 	my $newsylform=(<<NSYLFORM);
                   2699: 	<form action="/adm/coursedocs" method="post" name="newsyl">
1.371     tempelho 2700: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 2701: 	$uploadtag
                   2702: 	<input type="hidden" name="importdetail" 
                   2703: 	value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423     onken    2704: 	<a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329     droeschl 2705: 	$help{'Syllabus'}
1.383     tempelho 2706: 
1.329     droeschl 2707: 	</form>
                   2708: NSYLFORM
1.364     bisitz   2709: 
1.329     droeschl 2710: 	my $newgroupfileform=(<<NGFFORM);
                   2711: 	<form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371     tempelho 2712: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 2713: 	$uploadtag
                   2714: 	<input type="hidden" name="importdetail"
                   2715: 	value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423     onken    2716: 	<a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353     weissno  2717: 	$help{'Group Portfolio'}
1.329     droeschl 2718: 	</form>
                   2719: NGFFORM
1.383     tempelho 2720: 	@specialdocumentsforma=(
1.421     onken    2721: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'"  onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.417     droeschl 2722: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451     www      2723: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
                   2724:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
                   2725:         );
                   2726:         $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
                   2727: 
1.434     raeburn  2728: 
                   2729:         my @importdoc = (
                   2730:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'newext\');" />'=>$extresourcesform},
                   2731:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:makeims();" />'=>$imspform},);
1.459     raeburn  2732:         $fileuploadform =  &create_form_ul(&create_list_elements(@importdoc)) . '<hr id="cc_hrule" style="width:0px;text-align:left;margin-left:0" />' . $fileuploadform;
1.434     raeburn  2733: 
1.451     www      2734:         @gradingforma=(
                   2735:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
                   2736:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
                   2737:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
                   2738: 
                   2739:         );
                   2740:         $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
                   2741: 
                   2742:         @communityforma=(
                   2743:        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
                   2744:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
                   2745:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
                   2746:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
                   2747:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
                   2748:         );
                   2749:         $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383     tempelho 2750: 
1.329     droeschl 2751: 
1.331     muellerd 2752: 
1.383     tempelho 2753: my @tools = (
1.417     droeschl 2754: #	{'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" />'=>$extresourcesform},
                   2755: #	{'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" />'=>$imspform},
1.436     wenzelju 2756: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/recover.png" alt="'.$lt{reco}.'" onclick="javascript:groupopen(\''.$readfile.'\',1)" />'=>$recoverform},
1.383     tempelho 2757: 	);
                   2758: 
1.330     tempelho 2759: my %orderhash = (
1.417     droeschl 2760:                 'aa' => ['Import Documents',$fileuploadform],
1.377     bisitz   2761:                 'bb' => ['Published Resources',$simpleeditdefaultform],
1.451     www      2762:                 'cc' => ['Grading Resources',$gradingform],
                   2763: 		'ff' => ['Tools', &create_form_ul(&create_list_elements(@tools)).&generate_admin_options(\%help,\%env)],
1.330     tempelho 2764:                 );
1.451     www      2765: unless ($env{'form.pagepath'}) {
1.434     raeburn  2766:     $orderhash{'00'} = ['Newfolder',$newfolderform];
1.451     www      2767:     $orderhash{'dd'} = ['Community Resources',$communityform];
                   2768:     $orderhash{'ee'} = ['Special Documents',$specialdocumentsform];
1.434     raeburn  2769: }
                   2770: 
1.341     ehlerst  2771:  $hadchanges=0;
1.443     www      2772:        unless ($supplementalflag) {
1.458     raeburn  2773:           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472     raeburn  2774:                               $supplementalflag,\%orderhash,$iconpath);
1.443     www      2775:           if ($error) {
                   2776:              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   2777:           }
                   2778:           if ($hadchanges) {
                   2779:              &mark_hash_old();
                   2780:           }
1.341     ehlerst  2781: 
1.443     www      2782:           &changewarning($r,'');
                   2783:         }
1.458     raeburn  2784:     }
1.442     www      2785: 
1.443     www      2786: # Supplemental documents start here
                   2787: 
1.329     droeschl 2788:        my $folder=$env{'form.folder'};
1.443     www      2789:        unless ($supplementalflag) {
1.329     droeschl 2790: 	   $folder='supplemental';
                   2791:        }
                   2792:        if ($folder =~ /^supplemental$/ &&
                   2793: 	   (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446     www      2794:           $env{'form.folderpath'} = &supplemental_base();
1.393     raeburn  2795:        } elsif ($allowed) {
1.356     tempelho 2796: 	  $env{'form.folderpath'} = $savefolderpath;
1.329     droeschl 2797:        }
1.362     ehlerst  2798:        $env{'form.pagepath'} = '';
1.329     droeschl 2799:        if ($allowed) {
                   2800: 	   my $folderseq=
                   2801: 	       '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
                   2802: 	       '.sequence';
                   2803: 
                   2804: 	   my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   2805: 
1.400     droeschl 2806: 	my $supupdocformbtn = "<input type='submit' value='".$lt{'upld'}."' />$help{'Uploading_From_Harddrive'}";
1.329     droeschl 2807: 	my $supupdocform=(<<SUPDOCFORM);
1.383     tempelho 2808: 	<form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.371     tempelho 2809: 	<input type="hidden" name="active" value="ee" />	
1.329     droeschl 2810: 	$fileupload
                   2811: 	<br />
                   2812: 	<br />
                   2813: 	<span class="LC_nobreak">
                   2814: 	$checkbox
                   2815: 	</span>
                   2816: 	<br /><br />
                   2817: 	$lt{'comment'}:<br />
1.383     tempelho 2818: 	<textarea cols="50" rows="4" name="comment"></textarea>
1.329     droeschl 2819: 	<br />
                   2820: 	<input type="hidden" name="folderpath" value="$path" />
                   2821: 	<input type="hidden" name="cmd" value="upload_supplemental" />
                   2822: SUPDOCFORM
1.443     www      2823: 	$supupdocform .=  &create_form_ul(&Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."</form>";
1.329     droeschl 2824: 
                   2825: 	my $supnewfolderform=(<<SNFFORM);
                   2826: 	<form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371     tempelho 2827: 	<input type="hidden" name="active" value="ee" />
1.329     droeschl 2828: 	<input type="hidden" name="folderpath" value="$path" />
                   2829: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    2830: 	<a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a> 
1.383     tempelho 2831: 	$help{'Adding_Folders'}
1.329     droeschl 2832: 	</form>
                   2833: SNFFORM
1.383     tempelho 2834: 	
1.329     droeschl 2835: 
                   2836: 	my $supnewextform=(<<SNEFORM);
                   2837: 	<form action="/adm/coursedocs" method="post" name="supnewext">
1.371     tempelho 2838: 	<input type="hidden" name="active" value="ff" />
1.329     droeschl 2839: 	<input type="hidden" name="folderpath" value="$path" />
                   2840: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    2841: 	<a class="LC_menubuttons_link" href="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
1.329     droeschl 2842: 	</form>
                   2843: SNEFORM
                   2844: 
                   2845: 	my $supnewsylform=(<<SNSFORM);
                   2846: 	<form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371     tempelho 2847: 	<input type="hidden" name="active" value="ff" />
1.329     droeschl 2848: 	<input type="hidden" name="folderpath" value="$path" />
                   2849: 	<input type="hidden" name="importdetail" 
                   2850: 	value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423     onken    2851: 	<a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329     droeschl 2852: 	$help{'Syllabus'}
                   2853: 	</form>
                   2854: SNSFORM
                   2855: 
                   2856: 	my $supnewaboutmeform=(<<SNAMFORM);
1.383     tempelho 2857: 	<form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371     tempelho 2858: 	<input type="hidden" name="active" value="ff" />
1.329     droeschl 2859: 	<input type="hidden" name="folderpath" value="$path" />
                   2860: 	<input type="hidden" name="importdetail" 
                   2861: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.423     onken    2862: 	<a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347     weissno  2863: 	$help{'My Personal Information Page'}
1.329     droeschl 2864: 	</form>
                   2865: SNAMFORM
                   2866: 
1.333     muellerd 2867: 
1.383     tempelho 2868: my @specialdocs = (
1.417     droeschl 2869: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
                   2870:             =>$supnewsylform},
                   2871: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
                   2872:             =>$supnewaboutmeform},
1.383     tempelho 2873: 		);
1.417     droeschl 2874: my @supimportdoc = (
                   2875: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'supnewext\');" />'
                   2876:             =>$supnewextform},
                   2877:         );
1.459     raeburn  2878: $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc)) . '<hr id="ee_hrule" style="width:0px;text-align:left;margin-left:0" />' . $supupdocform;
1.333     muellerd 2879: my %suporderhash = (
1.390     tempelho 2880: 		'00' => ['Supnewfolder', $supnewfolderform],
1.417     droeschl 2881:                 'ee' => ['Import Documents',$supupdocform],
1.443     www      2882:                 'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))]
1.333     muellerd 2883:                 );
1.443     www      2884:         if ($supplementalflag) {
1.458     raeburn  2885:            my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472     raeburn  2886:                                $supplementalflag,\%suporderhash,$iconpath);
1.443     www      2887:            if ($error) {
                   2888:               $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   2889:            }
1.393     raeburn  2890:         }
1.443     www      2891:     } elsif ($supplementalflag) {
1.458     raeburn  2892:         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472     raeburn  2893:                             $supplementalflag,'',$iconpath);
1.393     raeburn  2894:         if ($error) {
                   2895:             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383     tempelho 2896:         }
1.393     raeburn  2897:     }
1.389     tempelho 2898: 
1.442     www      2899:     &endContentScreen($r);
1.383     tempelho 2900: 
1.329     droeschl 2901:     if ($allowed) {
                   2902: 	$r->print('
                   2903: <form method="post" name="extimport" action="/adm/coursedocs">
                   2904:   <input type="hidden" name="title" />
                   2905:   <input type="hidden" name="url" />
                   2906:   <input type="hidden" name="useform" />
                   2907:   <input type="hidden" name="residx" />
                   2908: </form>');
                   2909:     }
                   2910:   } else {
1.440     raeburn  2911:       unless ($uploadphase) {
1.329     droeschl 2912: # -------------------------------------------------------- This is showdoc mode
                   2913:           $r->print("<h1>".&mt('Uploaded Document').' - '.
                   2914: 		&Apache::lonnet::gettitle($r->uri).'</h1><p>'.
                   2915: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
                   2916:           &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
                   2917:       }
                   2918:   }
                   2919:  }
                   2920:  $r->print(&Apache::loncommon::end_page());
                   2921:  return OK;
1.364     bisitz   2922: }
1.329     droeschl 2923: 
1.440     raeburn  2924: sub embedded_form_elems {
                   2925:     my ($phase,$primaryurl,$newidx) = @_;
                   2926:     my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   2927:     return <<STATE;
                   2928:     <input type="hidden" name="folderpath" value="$folderpath" />
                   2929:     <input type="hidden" name="cmd" value="upload_embedded" />
                   2930:     <input type="hidden" name="newidx" value="$newidx" />
                   2931:     <input type="hidden" name="phase" value="$phase" />
                   2932:     <input type="hidden" name="primaryurl" value="$primaryurl" />
                   2933: STATE
                   2934: }
                   2935: 
                   2936: sub embedded_destination {
                   2937:     my $folder=$env{'form.folder'};
                   2938:     my $destination = 'docs/';
                   2939:     if ($folder =~ /^supplemental/) {
                   2940:         $destination = 'supplemental/';
                   2941:     }
                   2942:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   2943:         $destination .= 'default/';
                   2944:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   2945:         $destination .=  $2.'/';
                   2946:     }
                   2947:     $destination .= $env{'form.newidx'};
                   2948:     my $dir_root = '/userfiles';
                   2949:     return ($destination,$dir_root);
                   2950: }
                   2951: 
                   2952: sub return_to_editor {
                   2953:     my $actionurl = '/adm/coursedocs';
                   2954:     return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n". 
                   2955:            '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
                   2956:            '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
                   2957:            '</a></p>';
                   2958: }
                   2959: 
1.476     raeburn  2960: sub decompression_info {
                   2961:     my ($destination,$dir_root) = &embedded_destination();
                   2962:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                   2963:     my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   2964:     my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   2965:     my $container='sequence';
                   2966:     my $hiddenelem;
                   2967:     if ($env{'form.pagepath'}) {
                   2968:         $container='page';
                   2969:         $hiddenelem = '<input type="hidden" name="pagepath" value="'.$env{'form.pagepath'}.'" />'."\n";
                   2970:     } else {
                   2971:         $hiddenelem = '<input type="hidden" name="folderpath" value="'.$env{'form.folderpath'}.'" />'."\n";
                   2972:     }
                   2973:     if ($env{'form.newidx'}) {
                   2974:         $hiddenelem .= '<input type="hidden" name="newidx" value="'.$env{'form.newidx'}.'" />'."\n";
                   2975:     }
1.477   ! raeburn  2976:     if ($env{'form.comment'}) {
        !          2977:         $hiddenelem .= '<input type="hidden" name="comment" value="'.$env{'form.comment'}.'" />'."\n";
        !          2978:     }
1.476     raeburn  2979:     return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
                   2980:             $hiddenelem);
                   2981: }
                   2982: 
                   2983: sub decompression_phase_one {
                   2984:     my ($dir,$file,$warning,$error,$output);
                   2985:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   2986:         &decompression_info();
                   2987:     if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/docs/\E(?:default|supplemental|\d+).*/([^/]+)$}) {
                   2988:         $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
                   2989:     } else {
                   2990:         my $file = $1;
                   2991:         $output = &Apache::loncommon::process_decompression($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem);
                   2992:         if ($env{'form.archivedelete'}) {
                   2993:             my $map = $env{'form.folder'}.'.'.$container;
                   2994:             my ($delwarning,$delresult);
                   2995:             my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
                   2996:             if ($fatal) {
                   2997:                 if ($container eq 'page') {
                   2998:                     $delwarning = &mt('An error occurred retrieving the contents of the current page.');
                   2999:                 } else {
                   3000:                     $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
                   3001:                 }
                   3002:                 $delwarning .= &mt('As a result the archive file has not been removed.');
                   3003:             } else {
                   3004:                 my $currcmd = $env{'form.cmd'};
                   3005:                 $env{'form.cmd'} = 'del_'.$env{'form.position'};
                   3006:                 if (&handle_edit_cmd($docuname,$docudom)) {
                   3007:                     ($errtext,$fatal) = &storemap($docuname,$docudom,$map);
                   3008:                     if ($fatal) {
                   3009:                         if ($container eq 'page') {
                   3010:                             $delwarning = &mt('An error occurred updating the contents of the current page.');
                   3011:                         } else {
                   3012:                             $delwarning = &mt('An error occurred updating the contents of the current folder.');
                   3013:                         }
                   3014:                     }
                   3015:                 }
                   3016:                 $env{'form.cmd'} = $currcmd;
                   3017:                 $delresult = &mt('Archive file removed after extracting files.');
                   3018:             }
                   3019:             if ($delwarning) {
                   3020:                 $output .= '<p class="LC_warning">'.
                   3021:                            $delwarning.
                   3022:                            '</p>';
                   3023:             }
                   3024:             if ($delresult) {
                   3025:                 $output .= '<p class="LC_info">'.
                   3026:                            $delresult.
                   3027:                            '</p>';
                   3028:             }
                   3029:         }
                   3030:     }
                   3031:     if ($error) {
                   3032:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   3033:                    $error.'</p>'."\n";
                   3034:     }
                   3035:     if ($warning) {
                   3036:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   3037:     }
                   3038:     return $output;
                   3039: }
                   3040: 
                   3041: sub decompression_phase_two {
                   3042:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   3043:         &decompression_info();
                   3044:     my $output = 
                   3045:         &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
                   3046:                                                     $destination,$dir_root,$hiddenelem);
                   3047:     return $output;
                   3048: }
                   3049: 
1.329     droeschl 3050: sub generate_admin_options {
1.434     raeburn  3051:   my ($help_ref,$env_ref) = @_;
                   3052:   my %lt=&Apache::lonlocal::texthash(
1.337     ehlerst  3053:                                          'vc' => 'Verify Content',
                   3054:                                          'cv' => 'Check/Set Resource Versions',
                   3055:                                          'ls' => 'List Symbs',
1.412     wenzelju 3056:                                          'sl' => 'Show Log',
                   3057:                                          'imse' => 'IMS Export',
1.419     bisitz   3058:                                          'dcd' => 'Dump Course Documents to Construction Space: available on other servers'
1.337     ehlerst  3059:                                           );
1.329     droeschl 3060:   my %help = %{$help_ref};
                   3061:   my %env = %{$env_ref};
                   3062:   my $dumpbut=&dumpbutton();
                   3063:   my $exportbut=&exportbutton();
1.383     tempelho 3064:   my @list = (
1.417     droeschl 3065: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/verify.png" alt="'.$lt{vc}.'"  onclick=\'javascript:injectData(document.courseverify, "dummy", "verify", "'.$lt{'vc'}.'")\' />' 
1.423     onken    3066:         => "<a class='LC_menubuttons_link' href='javascript:injectData(document.courseverify, \"dummy\", \"verify\", \"$lt{'vc'}\")'>$lt{'vc'}</a>$help{'Verify_Content'}"},
1.417     droeschl 3067: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/resversion.png" alt="'.$lt{cv}.'"  onclick=\'javascript:injectData(document.courseverify, "dummy", "versions", "'.$lt{'cv'}.'")\' />'
1.423     onken    3068:         =>"<a class='LC_menubuttons_link' href='javascript:injectData(document.courseverify, \"dummy\", \"versions\", \"$lt{'cv'}\")'>$lt{'cv'}</a>$help{'Check_Resource_Versions'}"},
1.383     tempelho 3069: 	);
                   3070:   if($dumpbut ne ''){
1.417     droeschl 3071:   push @list, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dump.png" alt="'.$lt{dcd}.'" />'=>$dumpbut};
1.383     tempelho 3072:   }
1.431     raeburn  3073:   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').'\');" />'
1.417     droeschl 3074:           =>$exportbut},
                   3075: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/symbs.png" alt="'.$lt{ls}.'"  onclick=\'javascript:injectData(document.courseverify, "dummy", "listsymbs", "'.$lt{'ls'}.'")\'  />'
1.423     onken    3076:         =>"<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'}' />"},
1.426     wenzelju 3077: 	{'<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'}.'")\'  />'
1.423     onken    3078:         =>"<a class='LC_menubuttons_link' href='javascript:injectData(document.courseverify, \"dummy\", \"docslog\", \"$lt{'sl'}\")'>$lt{'sl'}</a>"},
1.383     tempelho 3079: 	);
1.443     www      3080:   return '<form action="/adm/coursedocs" method="post" name="courseverify"><input type="hidden" id="dummy" />'.&create_form_ul(&create_list_elements(@list)).'</form>';
1.330     tempelho 3081: 
1.329     droeschl 3082: }
                   3083: 
1.330     tempelho 3084: 
1.329     droeschl 3085: sub generate_edit_table {
1.472     raeburn  3086:     my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto) = @_;
1.406     raeburn  3087:     return unless(ref($orderhash_ref) eq 'HASH');
1.342     ehlerst  3088:     my %orderhash = %{$orderhash_ref};
1.344     bisitz   3089:     my $form;
1.371     tempelho 3090:     my $activetab;
                   3091:     my $active;
                   3092:     if($env{'form.active'} ne ''){
                   3093:         $activetab = $env{'form.active'};
                   3094:     }
1.472     raeburn  3095:     my $backicon = $iconpath.'clickhere.gif';
                   3096:     my $backtext = &mt('Back to Overview');
1.458     raeburn  3097:     $form = '<div class="LC_Box" style="margin:0;">'.
1.472     raeburn  3098:              '<ul id="navigation'.$tid.'" class="LC_TabContent">'.
                   3099:              '<li class="goback">'.
                   3100:              '<a href="javascript:toContents('."'$jumpto'".');">'.
1.473     raeburn  3101:              '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
                   3102:              '  alt="'.$backtext.'" />'.$backtext.'</a></li>';
1.458     raeburn  3103:     foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390     tempelho 3104:         if($name ne '00'){
1.371     tempelho 3105:             if($activetab eq '' || $activetab ne $name){
                   3106:                $active = '';
                   3107:             }elsif($activetab eq $name){
                   3108:                $active = 'class="active"';
                   3109:             }
1.458     raeburn  3110:             $form .= '<li style="float:right" '.$active
1.429     droeschl 3111:                 .' onmouseover="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"'
                   3112:                 .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>';
1.390     tempelho 3113:         } else {
1.458     raeburn  3114: 	    $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>';
1.390     tempelho 3115: 
                   3116: 	}
1.329     droeschl 3117:     }
1.339     ehlerst  3118:     $form .= '</ul>';
1.458     raeburn  3119:     $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">';
                   3120: 
                   3121:     if ($to_show ne '') {
                   3122:         $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>';
                   3123:     }
1.363     ehlerst  3124:     foreach my $field (keys(%orderhash)){
1.390     tempelho 3125: 	if($field ne '00'){
1.422     onken    3126:             if($activetab eq '' || $activetab ne $field){
1.458     raeburn  3127:                 $active = 'style="display: none;float:left"';
1.422     onken    3128:             }elsif($activetab eq $field){
1.458     raeburn  3129:                 $active = 'style="display:block;float:left"';
1.422     onken    3130:             }
                   3131:             $form .= '<div id="'.$field.$tid.'"'
                   3132:                     .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
                   3133:                     .'</div>';
1.363     ehlerst  3134:         }
                   3135:     }
1.330     tempelho 3136:     $form .= '</div></div>';
1.364     bisitz   3137: 
1.329     droeschl 3138:     return $form;
                   3139: }
                   3140: 
                   3141: sub editing_js {
1.472     raeburn  3142:     my ($udom,$uname,$supplementalflag) = @_;
1.329     droeschl 3143:     my $now = time();
                   3144:     my %lt = &Apache::lonlocal::texthash(
                   3145:                                           p_mnf => 'Name of New Folder',
                   3146:                                           t_mnf => 'New Folder',
                   3147:                                           p_mnp => 'Name of New Page',
                   3148:                                           t_mnp => 'New Page',
1.451     www      3149:                                           p_mxu => 'Title for the External Score',
1.349     biermanm 3150:                                           p_msp => 'Name of Simple Course Page',
1.329     droeschl 3151:                                           p_msb => 'Title for the Problem',
                   3152:                                           p_mdb => 'Title for the Drop Box',
1.336     schafran 3153:                                           p_mbb => 'Title for the Discussion Board',
1.348     weissno  3154:                                           p_mab => "Enter user:domain for User's Personal Information Page",
1.352     bisitz   3155:                                           p_mab2 => 'Personal Information Page of ',
1.329     droeschl 3156:                                           p_mab_alrt1 => 'Not a valid user:domain',
                   3157:                                           p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
                   3158:                                           p_chn => 'New Title',
                   3159:                                           p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
                   3160:                                           p_rmr2a => 'Remove[_99]',
                   3161:                                           p_rmr2b => '?[_99]',
                   3162:                                           p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
                   3163:                                           p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
                   3164:                                           p_ctr2a => 'Cut[_98]',
                   3165:                                           p_ctr2b => '?[_98]'
                   3166:                                         );
                   3167: 
1.433     raeburn  3168:     my $crstype = &Apache::loncommon::course_type();
1.434     raeburn  3169:     my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
                   3170:     my $docs_pagepath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.pagepath'},'<>&"');
                   3171:     my $main_container_page;
                   3172:     if ($docs_folderpath eq '') {
                   3173:         if ($docs_pagepath ne '') {
                   3174:             $main_container_page = 1;
                   3175:         }
                   3176:     }
1.433     raeburn  3177:     my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
1.446     www      3178:     my $toplevelsupp = &supplemental_base();
1.433     raeburn  3179: 
1.472     raeburn  3180:     my $backtourl = '/adm/navmaps';
                   3181:     if ($supplementalflag) {
                   3182:         $backtourl = '/adm/supplemental';
                   3183:     }
                   3184: 
1.329     droeschl 3185:     return <<ENDNEWSCRIPT;
                   3186: function makenewfolder(targetform,folderseq) {
                   3187:     var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
                   3188:     if (foldername) {
                   3189:        targetform.importdetail.value=escape(foldername)+"="+folderseq;
                   3190:         targetform.submit();
                   3191:     }
                   3192: }
                   3193: 
                   3194: function makenewpage(targetform,folderseq) {
                   3195:     var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
                   3196:     if (pagename) {
                   3197:         targetform.importdetail.value=escape(pagename)+"="+folderseq;
                   3198:         targetform.submit();
                   3199:     }
                   3200: }
                   3201: 
                   3202: function makenewext(targetname) {
                   3203:     this.document.forms.extimport.useform.value=targetname;
                   3204:     this.document.forms.extimport.title.value='';
                   3205:     this.document.forms.extimport.url.value='';
                   3206:     this.document.forms.extimport.residx.value='';
                   3207:     window.open('/adm/rat/extpickframe.html');
                   3208: }
                   3209: 
                   3210: function edittext(targetname,residx,title,url) {
                   3211:     this.document.forms.extimport.useform.value=targetname;
                   3212:     this.document.forms.extimport.residx.value=residx;
                   3213:     this.document.forms.extimport.url.value=url;
                   3214:     this.document.forms.extimport.title.value=title;
                   3215:     window.open('/adm/rat/extpickframe.html');
                   3216: }
                   3217: 
                   3218: function makeexamupload() {
                   3219:    var title=prompt('$lt{"p_mxu"}');
1.344     bisitz   3220:    if (title) {
1.329     droeschl 3221:     this.document.forms.newexamupload.importdetail.value=
                   3222: 	escape(title)+'=/res/lib/templates/examupload.problem';
                   3223:     this.document.forms.newexamupload.submit();
                   3224:    }
                   3225: }
                   3226: 
                   3227: function makesmppage() {
                   3228:    var title=prompt('$lt{"p_msp"}');
1.344     bisitz   3229:    if (title) {
1.329     droeschl 3230:     this.document.forms.newsmppg.importdetail.value=
                   3231: 	escape(title)+'=/adm/$udom/$uname/$now/smppg';
                   3232:     this.document.forms.newsmppg.submit();
                   3233:    }
                   3234: }
                   3235: 
                   3236: function makesmpproblem() {
                   3237:    var title=prompt('$lt{"p_msb"}');
1.344     bisitz   3238:    if (title) {
1.329     droeschl 3239:     this.document.forms.newsmpproblem.importdetail.value=
                   3240: 	escape(title)+'=/res/lib/templates/simpleproblem.problem';
                   3241:     this.document.forms.newsmpproblem.submit();
                   3242:    }
                   3243: }
                   3244: 
                   3245: function makedropbox() {
                   3246:    var title=prompt('$lt{"p_mdb"}');
1.344     bisitz   3247:    if (title) {
1.329     droeschl 3248:     this.document.forms.newdropbox.importdetail.value=
                   3249:         escape(title)+'=/res/lib/templates/DropBox.problem';
                   3250:     this.document.forms.newdropbox.submit();
                   3251:    }
                   3252: }
                   3253: 
                   3254: function makebulboard() {
                   3255:    var title=prompt('$lt{"p_mbb"}');
                   3256:    if (title) {
                   3257:     this.document.forms.newbul.importdetail.value=
                   3258: 	escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
                   3259:     this.document.forms.newbul.submit();
                   3260:    }
                   3261: }
                   3262: 
                   3263: function makeabout() {
                   3264:    var user=prompt("$lt{'p_mab'}");
                   3265:    if (user) {
                   3266:        var comp=new Array();
                   3267:        comp=user.split(':');
                   3268:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   3269: 	   if ((comp[0]) && (comp[1])) {
                   3270: 	       this.document.forms.newaboutsomeone.importdetail.value=
                   3271: 		   '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335     ehlerst  3272:        this.document.forms.newaboutsomeone.submit();
                   3273:    } else {
                   3274:        alert("$lt{'p_mab_alrt1'}");
1.329     droeschl 3275:    }
1.335     ehlerst  3276: } else {
                   3277:    alert("$lt{'p_mab_alrt2'}");
                   3278: }
                   3279: }
1.329     droeschl 3280: }
                   3281: 
                   3282: function makeims() {
1.335     ehlerst  3283: var caller = document.forms.ims.folder.value;
                   3284: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
                   3285: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
                   3286: newWindow.location.href = newlocation;
1.329     droeschl 3287: }
                   3288: 
                   3289: 
                   3290: function finishpick() {
1.335     ehlerst  3291: var title=this.document.forms.extimport.title.value;
                   3292: var url=this.document.forms.extimport.url.value;
                   3293: var form=this.document.forms.extimport.useform.value;
                   3294: var residx=this.document.forms.extimport.residx.value;
                   3295: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
1.329     droeschl 3296: }
                   3297: 
                   3298: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335     ehlerst  3299: var title=prompt('$lt{"p_chn"}',oldtitle);
                   3300: if (title) {
                   3301: this.document.forms.renameform.markcopy.value=-1;
                   3302: this.document.forms.renameform.title.value=title;
                   3303: this.document.forms.renameform.cmd.value='rename_'+index;
                   3304: if (container == 'sequence') {
                   3305:     this.document.forms.renameform.folderpath.value=folderpath;
                   3306: }
                   3307: if (container == 'page') {
                   3308:     this.document.forms.renameform.pagepath.value=folderpath;
                   3309:     this.document.forms.renameform.pagesymb.value=pagesymb;
                   3310: }
                   3311: this.document.forms.renameform.submit();
                   3312: }
1.329     droeschl 3313: }
                   3314: 
                   3315: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335     ehlerst  3316: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
                   3317: this.document.forms.renameform.markcopy.value=-1;
                   3318: this.document.forms.renameform.cmd.value='del_'+index;
                   3319: if (container == 'sequence') {
                   3320:     this.document.forms.renameform.folderpath.value=folderpath;
                   3321: }
                   3322: if (container == 'page') {
                   3323:     this.document.forms.renameform.pagepath.value=folderpath;
                   3324:     this.document.forms.renameform.pagesymb.value=pagesymb;
                   3325: }
                   3326: this.document.forms.renameform.submit();
                   3327: }
1.329     droeschl 3328: }
                   3329: 
                   3330: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335     ehlerst  3331: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
                   3332: this.document.forms.renameform.cmd.value='cut_'+index;
                   3333: this.document.forms.renameform.markcopy.value=index;
                   3334: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
                   3335: if (container == 'sequence') {
                   3336:     this.document.forms.renameform.folderpath.value=folderpath;
                   3337: }
                   3338: if (container == 'page') {
                   3339:     this.document.forms.renameform.pagepath.value=folderpath;
                   3340:     this.document.forms.renameform.pagesymb.value=pagesymb;
                   3341: }
                   3342: this.document.forms.renameform.submit();
                   3343: }
1.329     droeschl 3344: }
                   3345: 
                   3346: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335     ehlerst  3347: this.document.forms.renameform.markcopy.value=index;
                   3348: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
                   3349: if (container == 'sequence') {
                   3350: this.document.forms.renameform.folderpath.value=folderpath;
                   3351: }
                   3352: if (container == 'page') {
                   3353: this.document.forms.renameform.pagepath.value=folderpath;
                   3354: this.document.forms.renameform.pagesymb.value=pagesymb;
                   3355: }
                   3356: this.document.forms.renameform.submit();
1.329     droeschl 3357: }
                   3358: 
1.334     muellerd 3359: function unselectInactive(nav) {
1.335     ehlerst  3360: currentNav = document.getElementById(nav);
                   3361: currentLis = currentNav.getElementsByTagName('LI');
                   3362: for (i = 0; i < currentLis.length; i++) {
1.472     raeburn  3363:         if (currentLis[i].className == 'goback') {
                   3364:             currentLis[i].className = 'goback';
                   3365:         } else {
                   3366: 	    if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374     tempelho 3367: 		currentLis[i].className = 'right';
1.472     raeburn  3368: 	    } else {
1.374     tempelho 3369: 		currentLis[i].className = 'i';
1.472     raeburn  3370: 	    }
                   3371:         }
1.335     ehlerst  3372: }
1.332     tempelho 3373: }
                   3374: 
1.334     muellerd 3375: function hideAll(current, nav, data) {
1.335     ehlerst  3376: unselectInactive(nav);
1.374     tempelho 3377: if(current.className == 'right'){
                   3378: 	current.className = 'right active'
                   3379: 	}else{
                   3380: 	current.className = 'active';
                   3381: }
1.335     ehlerst  3382: currentData = document.getElementById(data);
                   3383: currentDivs = currentData.getElementsByTagName('DIV');
                   3384: for (i = 0; i < currentDivs.length; i++) {
                   3385: 	if(currentDivs[i].className == 'LC_ContentBox'){
1.333     muellerd 3386: 		currentDivs[i].style.display = 'none';
1.330     tempelho 3387: 	}
                   3388: }
1.335     ehlerst  3389: }
1.330     tempelho 3390: 
1.374     tempelho 3391: function openTabs(pageId) {
                   3392: 	tabnav = document.getElementById(pageId).getElementsByTagName('UL');	
1.383     tempelho 3393: 	if(tabnav.length > 2 ){
1.389     tempelho 3394: 		currentNav = document.getElementById(tabnav[1].id);
1.374     tempelho 3395: 		currentLis = currentNav.getElementsByTagName('LI');
                   3396: 		for(i = 0; i< currentLis.length; i++){
                   3397: 			if(currentLis[i].className == 'active') {
1.375     tempelho 3398: 				funcString = currentLis[i].onclick.toString();
                   3399: 				tab = funcString.split('"');
1.420     onken    3400:                                 if(tab.length < 2) {
                   3401:                                    tab = funcString.split("'");
                   3402:                                 }
1.375     tempelho 3403: 				currentData = document.getElementById(tab[1]);
                   3404:         			currentData.style.display = 'block';
1.374     tempelho 3405: 			}	
                   3406: 		}
                   3407: 	}
                   3408: }
                   3409: 
1.334     muellerd 3410: function showPage(current, pageId, nav, data) {
                   3411: 	hideAll(current, nav, data);
1.375     tempelho 3412: 	openTabs(pageId);
1.334     muellerd 3413: 	unselectInactive(nav);
1.330     tempelho 3414: 	current.className = 'active';
                   3415: 	currentData = document.getElementById(pageId);
                   3416: 	currentData.style.display = 'block';
1.458     raeburn  3417:         activeTab = pageId;
1.433     raeburn  3418:         if (nav == 'mainnav') {
                   3419:             var storedpath = "$docs_folderpath";
                   3420:             if (storedpath == '') {
                   3421:                 storedpath = "$docs_pagepath";
                   3422:             }
1.434     raeburn  3423:             var storedpage = "$main_container_page";
1.433     raeburn  3424:             var reg = new RegExp("^supplemental");
                   3425:             if (pageId == 'mainCourseDocuments') {
1.434     raeburn  3426:                 if (storedpage == 1) {
                   3427:                     document.simpleedit.folderpath.value = '';
                   3428:                     document.uploaddocument.folderpath.value = '';
                   3429:                 } else {
                   3430:                     if (reg.test(storedpath)) {
                   3431:                         document.simpleedit.folderpath.value = '$toplevelmain';
                   3432:                         document.uploaddocument.folderpath.value = '$toplevelmain';
                   3433:                         document.newext.folderpath.value = '$toplevelmain';
                   3434:                     } else {
                   3435:                         document.simpleedit.folderpath.value = storedpath;
                   3436:                         document.uploaddocument.folderpath.value = storedpath;
                   3437:                         document.newext.folderpath.value = storedpath;
                   3438:                     }
1.433     raeburn  3439:                 }
                   3440:             } else {
1.434     raeburn  3441:                 if (reg.test(storedpath)) {
                   3442:                     document.simpleedit.folderpath.value = storedpath;
                   3443:                     document.supuploaddocument.folderpath.value = storedpath;
                   3444:                     document.supnewext.folderpath.value = storedpath;
                   3445:                 } else {
1.433     raeburn  3446:                     document.simpleedit.folderpath.value = '$toplevelsupp';
                   3447:                     document.supuploaddocument.folderpath.value = '$toplevelsupp';
                   3448:                     document.supnewext.folderpath.value = '$toplevelsupp';
                   3449:                 }
                   3450:             }
                   3451:         }
1.458     raeburn  3452:         resize_contentdiv('contentscroll','1','0');
1.330     tempelho 3453: 	return false;
                   3454: }
1.329     droeschl 3455: 
1.383     tempelho 3456: function injectData(current, hiddenField, name, value) {
                   3457: 	currentElement = document.getElementById(hiddenField);
                   3458: 	currentElement.name = name;
                   3459: 	currentElement.value = value;
                   3460: 	current.submit();
                   3461: }
                   3462: 
1.472     raeburn  3463: function toContents(jumpto) {
                   3464:     var newurl = '$backtourl';
                   3465:     if (jumpto != '') {
                   3466:         newurl = newurl+'?postdata='+jumpto;
                   3467: ;
                   3468:     }
                   3469:     location.href=newurl;
                   3470: }
                   3471: 
1.329     droeschl 3472: ENDNEWSCRIPT
                   3473: }
1.457     raeburn  3474: 
                   3475: sub resize_contentdiv_js {
1.458     raeburn  3476:     my ($tabidstr) = @_;
1.457     raeburn  3477:     my $viewport_js = &Apache::loncommon::viewport_geometry_js();
                   3478:     return <<ENDRESIZESCRIPT;
                   3479: 
1.458     raeburn  3480: window.onresize=resizeContentEditor;
                   3481: 
                   3482: var activeTab;
                   3483: 
1.457     raeburn  3484: $viewport_js
                   3485: 
1.458     raeburn  3486: function resize_contentdiv(scrollboxname,chkw,chkh) {
                   3487:     var scrollboxid = 'div_'+scrollboxname;
                   3488:     var scrolltableid = 'table_'+scrollboxname;
                   3489:     var scrollbox;
                   3490:     var scrolltable;
                   3491: 
1.457     raeburn  3492:     if (document.getElementById("contenteditor") == null) {
                   3493:         return;
                   3494:     }
1.458     raeburn  3495: 
                   3496:     if (document.getElementById(scrollboxid) == null) {
                   3497:         return;
                   3498:     } else {
                   3499:         scrollbox = document.getElementById(scrollboxid);
                   3500:     }
                   3501: 
                   3502:     if (document.getElementById(scrolltableid) == null) {
                   3503:         return;
                   3504:     } else {
                   3505:         scrolltable = document.getElementById(scrolltableid);
                   3506:     }
                   3507: 
1.457     raeburn  3508:     init_geometry();
                   3509:     var vph = Geometry.getViewportHeight();
1.458     raeburn  3510:     var vpw = Geometry.getViewportWidth();
                   3511: 
                   3512:     var alltabs = ['$tabidstr'];
                   3513:     var listwchange;
                   3514:     if (chkw == 1) {
                   3515:         var contenteditorw = document.getElementById("contenteditor").offsetWidth;
                   3516:         var contentlistw;
                   3517:         var contentlistid = document.getElementById("contentlist");
                   3518:         if (contentlistid != null) {
                   3519:             contentlistw = document.getElementById("contentlist").offsetWidth;
                   3520:         }
                   3521:         var contentlistwstart = contentlistw;
                   3522: 
                   3523:         var scrollboxw = scrollbox.offsetWidth;
                   3524:         var scrollboxscrollw = scrollbox.scrollWidth;
                   3525: 
                   3526:         var offsetw = parseInt(vpw * 0.015);
                   3527:         var paddingw = parseInt(vpw * 0.09);
                   3528: 
                   3529:         var minscrollboxw = 250;
                   3530: 
                   3531:         var maxtabw = 0;
1.459     raeburn  3532:         var actabw = 0;
1.458     raeburn  3533:         for (var i=0; i<alltabs.length; i++) {
                   3534:             if (activeTab == alltabs[i]) {
1.459     raeburn  3535:                 actabw = document.getElementById(alltabs[i]).offsetWidth;
                   3536:                 if (actabw > maxtabw) {
                   3537:                     maxtabw = actabw;
1.458     raeburn  3538:                 }
                   3539:             } else {
                   3540:                 if (document.getElementById(alltabs[i]) != null) {
                   3541:                     var thistab = document.getElementById(alltabs[i]);
                   3542:                     thistab.style.visibility = 'hidden';
                   3543:                     thistab.style.display = 'block';
                   3544:                     var tabw = document.getElementById(alltabs[i]).offsetWidth;
                   3545:                     thistab.style.display = 'none';
                   3546:                     thistab.style.visibility = '';
                   3547:                     if (tabw > maxtabw) {
                   3548:                         maxtabw = tabw;
                   3549:                     }
                   3550:                 }
                   3551:             }
                   3552:         }
1.457     raeburn  3553: 
1.458     raeburn  3554:         if (maxtabw > 0) {
                   3555:             var newscrollboxw;
                   3556:             if (maxtabw+paddingw+scrollboxscrollw<contenteditorw) {
                   3557:                 newscrollboxw = contenteditorw-paddingw-maxtabw;
                   3558:                 if (newscrollboxw < minscrollboxw) {
                   3559:                     newscrollboxw = minscrollboxw;
                   3560:                 }
                   3561:                 scrollbox.style.width = newscrollboxw+"px";
                   3562:                 if (newscrollboxw != scrollboxw) {
                   3563:                     var newcontentlistw = newscrollboxw-offsetw;
                   3564:                     contentlistid.style.width = newcontentlistw+"px";
                   3565:                 }
                   3566:             } else {
                   3567:                 newscrollboxw = contenteditorw-paddingw-maxtabw;
                   3568:                 if (newscrollboxw < minscrollboxw) {
                   3569:                     newscrollboxw = minscrollboxw;
                   3570:                 }
                   3571:                 scrollbox.style.width = newscrollboxw+"px";
                   3572:                 if (newscrollboxw != scrollboxw) {
                   3573:                     var newcontentlistw = newscrollboxw-offsetw;
                   3574:                     contentlistid.style.width = newcontentlistw+"px";
                   3575:                 }
                   3576:             }
                   3577: 
                   3578:             if (newscrollboxw != scrollboxw) {
                   3579:                 var newscrolltablew = newscrollboxw+offsetw;
                   3580:                 scrolltable.style.width = newscrolltablew+"px";
                   3581:             }
                   3582:         }
                   3583: 
                   3584:         if (contentlistid.offsetWidth != contentlistwstart) {
                   3585:             listwchange = 1;
                   3586:         }
                   3587: 
1.459     raeburn  3588:         if (activeTab == 'cc1') {
                   3589:             if (document.getElementById('cc_hrule') != null) {
                   3590:                 document.getElementById('cc_hrule').style.width=actabw+"px";
                   3591:             }
                   3592:         } else {
                   3593:             if (activeTab == 'bb1') {
                   3594:                 if (document.getElementById('bb_hrule') != null) {
                   3595:                     document.getElementById('bb_hrule').style.width=actabw+"px";
                   3596:                 }
                   3597:             } else {
                   3598:                 if (activeTab == 'ee2') {
                   3599:                     if (document.getElementById('ee_hrule') != null) {
                   3600:                         document.getElementById('ee_hrule').style.width=actabw+"px";
                   3601:                     }
                   3602:                 }
                   3603:             }
                   3604:         }
1.458     raeburn  3605:     }
                   3606:     if ((chkh == 1) || (listwchange)) {
                   3607:         var primaryheight = document.getElementById("LC_nav_bar").offsetHeight;
                   3608:         var secondaryheight = document.getElementById("LC_secondary_menu").offsetHeight;
                   3609:         var crumbsheight = document.getElementById("LC_breadcrumbs").offsetHeight;
                   3610:         var dccidheight = document.getElementById("dccid").offsetHeight;
                   3611: 
                   3612:         var uploadresultheight = 0;
                   3613:         if (document.getElementById("uploadfileresult") != null) {
                   3614:             uploadresultheight = document.getElementById("uploadfileresult").offsetHeight;
                   3615:         }
                   3616:         var tabbedheight = document.getElementById("tabbededitor").offsetHeight;
                   3617:         var contenteditorheight = document.getElementById("contenteditor").offsetHeight;
1.457     raeburn  3618:         var scrollboxheight = scrollbox.offsetHeight;
                   3619:         var scrollboxscrollheight = scrollbox.scrollHeight;
1.458     raeburn  3620:         var freevspace = vph-(primaryheight+secondaryheight+crumbsheight+dccidheight+uploadresultheight+tabbedheight+contenteditorheight);
1.457     raeburn  3621: 
1.458     raeburn  3622:         var minvscrollbox = 200;
                   3623:         var offsetv = 20;
1.457     raeburn  3624:         var newscrollboxheight;
1.458     raeburn  3625:         if (freevspace < 0) {
                   3626:             newscrollboxheight = scrollboxheight+freevspace-offsetv;
                   3627:             if (newscrollboxheight < minvscrollbox) {
                   3628:                 newscrollboxheight = minvscrollbox;
1.457     raeburn  3629:             }
                   3630:             scrollbox.style.height = newscrollboxheight + "px";
                   3631:         } else {
                   3632:             if (scrollboxscrollheight > scrollboxheight) {
1.458     raeburn  3633:                 if (freevspace > offsetv) {
                   3634:                     newscrollboxheight = scrollboxheight+freevspace-offsetv;
                   3635:                     if (newscrollboxheight < minvscrollbox) {
                   3636:                         newscrollboxheight = minvscrollbox;
1.457     raeburn  3637:                     }
                   3638:                     scrollbox.style.height = newscrollboxheight+"px";
                   3639:                 }
                   3640:             }
                   3641:         }
                   3642:         scrollboxheight = scrollbox.offsetHeight;
1.458     raeburn  3643:         var contentlistheight = document.getElementById("contentlist").offsetHeight;
1.457     raeburn  3644: 
                   3645:         if (scrollboxscrollheight <= scrollboxheight) {
1.458     raeburn  3646:             if ((contentlistheight+offsetv)<scrollboxheight) {
                   3647:                 newscrollheight = contentlistheight+offsetv;
1.457     raeburn  3648:                 scrollbox.style.height = newscrollheight+"px";
                   3649:             }
                   3650:         }
                   3651:     }
1.458     raeburn  3652:     return;
                   3653: }
                   3654: 
                   3655: function resizeContentEditor() {
                   3656:     var timer;
                   3657:     clearTimeout(timer)
                   3658:     timer=setTimeout('resize_contentdiv("contentscroll","1","1")',500);
1.457     raeburn  3659: }
                   3660: 
                   3661: ENDRESIZESCRIPT
                   3662:     return;
                   3663: }
                   3664: 
1.329     droeschl 3665: 1;
                   3666: __END__
                   3667: 
                   3668: 
                   3669: =head1 NAME
                   3670: 
                   3671: Apache::londocs.pm
                   3672: 
                   3673: =head1 SYNOPSIS
                   3674: 
                   3675: This is part of the LearningOnline Network with CAPA project
                   3676: described at http://www.lon-capa.org.
                   3677: 
                   3678: =head1 SUBROUTINES
                   3679: 
                   3680: =over
                   3681: 
                   3682: =item %help=()
                   3683: 
                   3684: Available help topics
                   3685: 
                   3686: =item mapread()
                   3687: 
1.344     bisitz   3688: Mapread read maps into LONCAPA::map:: global arrays
1.329     droeschl 3689: @order and @resources, determines status
                   3690: sets @order - pointer to resources in right order
                   3691: sets @resources - array with the resources with correct idx
                   3692: 
                   3693: =item authorhosts()
                   3694: 
                   3695: Return hash with valid author names
                   3696: 
                   3697: =item dumpbutton()
                   3698: 
                   3699: Generate "dump" button
                   3700: 
                   3701: =item clean()
                   3702: 
                   3703: =item dumpcourse()
                   3704: 
                   3705:     Actually dump course
                   3706: 
                   3707: 
                   3708: =item exportbutton()
                   3709: 
                   3710:     Generate "export" button
                   3711: 
                   3712: =item group_import()
                   3713: 
                   3714:     Imports the given (name, url) resources into the course
                   3715:     coursenum, coursedom, and folder must precede the list
                   3716: 
                   3717: =item breadcrumbs()
                   3718: 
                   3719: =item log_docs()
                   3720: 
                   3721: =item docs_change_log()
                   3722: 
                   3723: =item update_paste_buffer()
                   3724: 
                   3725: =item print_paste_buffer()
                   3726: 
                   3727: =item do_paste_from_buffer()
                   3728: 
                   3729: =item update_parameter()
                   3730: 
                   3731: =item handle_edit_cmd()
                   3732: 
                   3733: =item editor()
                   3734: 
                   3735: =item process_file_upload()
                   3736: 
                   3737: =item process_secondary_uploads()
                   3738: 
                   3739: =item is_supplemental_title()
                   3740: 
                   3741: =item parse_supplemental_title()
                   3742: 
                   3743: =item entryline()
                   3744: 
                   3745: =item tiehash()
                   3746: 
                   3747: =item untiehash()
                   3748: 
                   3749: =item checkonthis()
                   3750: 
                   3751: check on this
                   3752: 
                   3753: =item verifycontent()
                   3754: 
                   3755: Verify Content
                   3756: 
                   3757: =item devalidateversioncache() & checkversions()
                   3758: 
                   3759: Check Versions
                   3760: 
                   3761: =item mark_hash_old()
                   3762: 
                   3763: =item is_hash_old()
                   3764: 
                   3765: =item changewarning()
                   3766: 
                   3767: =item init_breadcrumbs()
                   3768: 
                   3769: Breadcrumbs for special functions
                   3770: 
                   3771: =back
                   3772: 
                   3773: =cut

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