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

1.329     droeschl    1: # The LearningOnline Network
                      2: # Documents
                      3: #
1.727   ! raeburn     4: # $Id: londocs.pm,v 1.726 2025/02/28 01:07:59 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.510     raeburn    43: use Apache::lonextresedit();
1.567     raeburn    44: use Apache::lontemplate();
                     45: use Apache::lonsimplepage();
1.606     raeburn    46: use Apache::lonhomework();
                     47: use Apache::lonpublisher();
1.651     raeburn    48: use Apache::loncourserespicker();
1.329     droeschl   49: use HTML::Entities;
1.488     raeburn    50: use HTML::TokeParser;
1.713     raeburn    51: use HTML::LCParser;
1.329     droeschl   52: use GDBM_File;
1.578     raeburn    53: use File::MMagic;
1.606     raeburn    54: use File::Copy;
1.329     droeschl   55: use Apache::lonlocal;
                     56: use Cwd;
1.643     raeburn    57: use UUID::Tiny ':std';
1.329     droeschl   58: use LONCAPA qw(:DEFAULT :match);
                     59: 
                     60: my $iconpath;
                     61: 
                     62: my %hash;
                     63: 
                     64: my $hashtied;
                     65: my %alreadyseen=();
                     66: 
                     67: my $hadchanges;
1.557     raeburn    68: my $suppchanges;
1.329     droeschl   69: 
                     70: 
                     71: my %help=();
                     72: 
                     73: 
                     74: sub mapread {
                     75:     my ($coursenum,$coursedom,$map)=@_;
                     76:     return
                     77:       &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                     78: 			     $map);
                     79: }
                     80: 
                     81: sub storemap {
1.492     raeburn    82:     my ($coursenum,$coursedom,$map,$contentchg)=@_;
                     83:     my $report;
                     84:     if (($contentchg) && ($map =~ /^default/)) {
                     85:        $report = 1;
                     86:     }
1.329     droeschl   87:     my ($outtext,$errtext)=
                     88:       &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492     raeburn    89: 			      $map,1,$report);
1.329     droeschl   90:     if ($errtext) { return ($errtext,2); }
1.364     bisitz     91: 
1.557     raeburn    92:     if ($map =~ /^default/) {
                     93:         $hadchanges=1;
1.682     raeburn    94:     } elsif ($contentchg) {
1.557     raeburn    95:         $suppchanges=1;
                     96:     }
1.329     droeschl   97:     return ($errtext,0);
                     98: }
                     99: 
                    100: 
                    101: 
                    102: sub authorhosts {
                    103:     my %outhash=();
                    104:     my $home=0;
                    105:     my $other=0;
1.709     raeburn   106:     my @ids=&Apache::lonnet::current_machine_ids();
1.329     droeschl  107:     foreach my $key (keys(%env)) {
                    108: 	if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
                    109: 	    my $role=$1;
                    110: 	    my $realm=$2;
                    111: 	    my ($start,$end)=split(/\./,$env{$key});
                    112: 	    if (($start) && ($start>time)) { next; }
                    113: 	    if (($end) && (time>$end)) { next; }
                    114: 	    my ($ca,$cd);
                    115: 	    if ($1 eq 'au') {
                    116: 		$ca=$env{'user.name'};
                    117: 		$cd=$env{'user.domain'};
                    118: 	    } else {
                    119: 		($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
                    120: 	    }
                    121: 	    my $allowed=0;
                    122: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
1.484     raeburn   123: 	    foreach my $id (@ids) {
                    124:                 if ($id eq $myhome) {
                    125:                     $allowed=1;
                    126:                     last;
                    127:                 }
                    128:             }
1.329     droeschl  129: 	    if ($allowed) {
                    130: 		$home++;
1.484     raeburn   131: 		$outhash{'home_'.$ca.':'.$cd}=1;
1.329     droeschl  132: 	    } else {
1.484     raeburn   133: 		$outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329     droeschl  134: 		$other++;
                    135: 	    }
                    136: 	}
                    137:     }
                    138:     return ($home,$other,%outhash);
                    139: }
                    140: 
                    141: 
                    142: sub clean {
                    143:     my ($title)=@_;
                    144:     $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344     bisitz    145:     return $title;
1.329     droeschl  146: }
                    147: 
1.617     raeburn   148: sub default_folderpath {
                    149:     my ($coursenum,$coursedom,$navmapref) = @_;
                    150:     return unless ($coursenum && $coursedom && ref($navmapref));
                    151: # Check if entire course is hidden and/or encrypted
                    152:     my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
                    153:     my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
                    154:     unless (ref($$navmapref)) {
                    155:         $$navmapref = Apache::lonnavmaps::navmap->new();
                    156:     }
                    157:     if (ref($$navmapref)) {
                    158:         if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
                    159:             my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
                    160:             my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
                    161:             unless (@resources) {
                    162:                 $hiddenmap = 1;
                    163:                 unless ($env{'request.role.adv'}) {
                    164:                     $hiddentop = 1;
                    165:                     if ($env{'form.folder'}) {
                    166:                         undef($env{'form.folder'});
                    167:                     }
                    168:                 }
                    169:             }
                    170:         }
                    171:         if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
                    172:             $encryptmap = 1;
                    173:         }
                    174:     }
                    175:     unless ($hiddentop) {
                    176:         $folderpath='default&'.&escape(&mt('Main Content')).
                    177:                     '::'.$hiddenmap.':'.$encryptmap.'::';
                    178:     }
                    179:     if (wantarray) {
                    180:         return ($folderpath,$hiddentop);
                    181:     } else {
                    182:         return $folderpath;
                    183:     }
                    184: }
1.329     droeschl  185: 
1.685     raeburn   186: sub validate_supppath {
                    187:     my ($coursenum,$coursedom) = @_;
                    188:     my $backto;
1.677     raeburn   189:     if ($env{'form.supppath'} ne '') {
                    190:         my @items = split(/\&/,$env{'form.supppath'});
1.685     raeburn   191:         my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.677     raeburn   192:         for (my $i=0; $i<@items; $i++) {
                    193:             my $odd = $i%2;
                    194:             if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
                    195:                 $badpath = 1;
1.685     raeburn   196:                 last;
                    197:             } elsif ($odd) {
                    198:                 my $suffix;
                    199:                 my $idx = $i-1;
                    200:                 if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
                    201:                     $backto .= '&'.$1;
                    202:                 } elsif ($items[$idx] eq 'supplemental') {
                    203:                     $backto .= '&'.$items[$i];
                    204:                 } else {
                    205:                     $backto .= '&'.$items[$i];
                    206:                     my $is_hidden;
                    207:                     unless ($got_supp) {
1.688     raeburn   208:                         my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn   209:                         if (ref($supplemental) eq 'HASH') {
                    210:                             if (ref($supplemental->{'hidden'}) eq 'HASH') {
                    211:                                 %supphidden = %{$supplemental->{'hidden'}};
                    212:                             }
                    213:                             if (ref($supplemental->{'ids'}) eq 'HASH') {
                    214:                                 %suppids = %{$supplemental->{'ids'}};
                    215:                             }
                    216:                         }
                    217:                         $got_supp = 1;
                    218:                     }
                    219:                     if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
                    220:                         my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
                    221:                         if ($supphidden{$mapid}) {
                    222:                             $is_hidden = 1;
                    223:                         }
                    224:                     }
                    225:                     $suffix = '::'.$is_hidden.':::';
                    226:                 }
                    227:                 $supppath .= '&'.$items[$i].$suffix;
                    228:             } else {
                    229:                 $supppath .= '&'.$items[$i];
                    230:                 $backto .= '&'.$items[$i];
1.677     raeburn   231:             }
                    232:         }
                    233:         if ($badpath) {
                    234:             delete($env{'form.supppath'});
1.685     raeburn   235:         } else {
                    236:             $supppath =~ s/^\&//;
                    237:             $backto =~ s/^\&//;
                    238:             $env{'form.supppath'} = $supppath;
1.677     raeburn   239:         }
                    240:     }
1.685     raeburn   241:     return $backto;
1.677     raeburn   242: }
                    243: 
1.329     droeschl  244: sub dumpcourse {
                    245:     my ($r) = @_;
1.408     raeburn   246:     my $crstype = &Apache::loncommon::course_type();
1.567     raeburn   247:     my ($starthash,$js);
                    248:     unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    249:         $js = <<"ENDJS";
                    250: <script type="text/javascript">
                    251: // <![CDATA[
                    252: 
                    253: function hide_searching() {
                    254:     if (document.getElementById('searching')) {
                    255:         document.getElementById('searching').style.display = 'none';
                    256:     }
                    257:     return;
                    258: }
                    259: 
                    260: // ]]>
                    261: </script>
                    262: ENDJS
                    263:         $starthash = {
                    264:                          add_entries => {'onload' => "hide_searching();"},
                    265:                      };
                    266:     }
1.709     raeburn   267:     $r->print(&Apache::loncommon::start_page('Copy uploaded content to Authoring Space',$js,$starthash)."\n".
                    268:               &Apache::lonhtmlcommon::breadcrumbs('Copy uploaded content to Authoring Space')."\n");
1.484     raeburn   269:     $r->print(&startContentScreen('tools'));
1.329     droeschl  270:     my ($home,$other,%outhash)=&authorhosts();
1.484     raeburn   271:     unless ($home) {
1.712     raeburn   272:         $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>'); 
1.484     raeburn   273:         $r->print(&endContentScreen());
                    274:         return '';
                    275:     }
1.329     droeschl  276:     my $origcrsid=$env{'request.course.id'};
                    277:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    278:     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    279: # Do the dumping
1.484     raeburn   280: 	unless ($outhash{'home_'.$env{'form.authorspace'}}) {
1.712     raeburn   281:             $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
                    282:                       &endContentScreen());
1.484     raeburn   283:             return '';
                    284:         }
1.531     raeburn   285: 	my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329     droeschl  286: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
                    287: 	my $title=$env{'form.authorfolder'};
                    288: 	$title=&clean($title);
1.567     raeburn   289:         my ($navmap,$errormsg) =
                    290:             &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
                    291:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    292:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    293:         my (%maps,%resources,%titles);
                    294:         if (!ref($navmap)) {
                    295:             $r->print($errormsg.
                    296:                       &endContentScreen());
                    297:             return '';
                    298:         } else {
                    299:             &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
                    300:                                                                    'dumpdocs',$cdom,$cnum);
1.329     droeschl  301: 	}
1.567     raeburn   302:         my @todump = &Apache::loncommon::get_env_multiple('form.archive');
                    303:         my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
                    304:             %newcontent,%has_simpleprobs);
                    305:         foreach my $item (sort {$a <=> $b} (@todump)) {
                    306:             my $name = $env{'form.namefor_'.$item};
                    307:             if ($resources{$item}) {
                    308:                 my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
                    309:                 if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
                    310:                     $tocopy{$1} = $name;
                    311:                     $display{$item} = $1;
                    312:                     $lookup{$1} = $item; 
                    313:                 } elsif ($res eq 'lib/templates/simpleproblem.problem') {
                    314:                     $simpleproblems{$item} = {
                    315:                                                 symb => $resources{$item},
                    316:                                                 name => $name,
                    317:                                              };
                    318:                     $display{$item} = 'simpleproblem_'.$name;
                    319:                     if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
                    320:                         $has_simpleprobs{$1}{$id} = $item;
                    321:                     }
                    322:                 } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
                    323:                     my $marker = $1;
                    324:                     my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
                    325:                     $simplepages{$item} = {
                    326:                                             res    => $res,
                    327:                                             title  => $titles{$item},
                    328:                                             db     => $db_name,
                    329:                                             marker => $marker,
                    330:                                             symb   => $resources{$item},
                    331:                                             name   => $name,
                    332:                                           };
                    333:                     $display{$item} = '/'.$res;
                    334:                 }
                    335:             } elsif ($maps{$item}) {
                    336:                 if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
                    337:                     $tocopy{$1} = $name;
                    338:                     $display{$item} = $1;
                    339:                     $lookup{$1} = $item;
                    340:                 }
                    341:             } else {
                    342:                 next;
                    343:             }
                    344:         }
1.329     droeschl  345: 	my $crs='/uploaded/'.$env{'request.course.id'}.'/';
                    346: 	$crs=~s/\_/\//g;
1.567     raeburn   347:         my $mm = new File::MMagic;
                    348:         my $prefix = "/uploaded/$cdom/$cnum/";
                    349:         %replacehash = %tocopy;
                    350:         foreach my $item (sort(keys(%simpleproblems))) {
                    351:             my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
                    352:             $newcontent{$display{$item}} = $content;
                    353:         }
                    354:         my $gateway = Apache::lonhtmlgateway->new('web');
                    355:         foreach my $item (sort(keys(%simplepages))) {
                    356:             if (ref($simplepages{$item}) eq 'HASH') {
                    357:                 my $pagetitle = $simplepages{$item}{'title'};
                    358:                 my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
                    359:                 my %contents;
                    360:                 foreach my $field (keys(%fields)) {
                    361:                     if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
                    362:                         my $name = $1;
                    363:                         my $msg = $fields{$field};
                    364:                         if ($name eq 'webreferences') {
                    365:                             if ($msg =~ m{^https?://}) {
                    366:                                 $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
                    367:                             }
                    368:                         } else {
                    369:                             $msg = &Encode::decode('utf8',$msg);
                    370:                             $msg = $gateway->process_outgoing_html($msg,1);
                    371:                             $contents{$name} = $msg;
                    372:                         }
                    373:                     } elsif ($field eq 'uploaded.photourl') {
                    374:                         my $marker = $simplepages{$item}{marker};
                    375:                         if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
                    376:                             my $filepath = $1;
                    377:                             my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
                    378:                             if ($fname ne '') {
                    379:                                 $fname=~s/\.(\w+)$//;
                    380:                                 my $ext=$1;
                    381:                                 $fname = &clean($fname);
                    382:                                 $fname.='.'.$ext;
                    383:                                 $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
                    384:                                 $replacehash{$filepath} = $relpath.$fname;
                    385:                                 $deps{$item}{$filepath} = 1;
                    386:                             }
                    387:                         }
                    388:                     }
                    389:                 }
                    390:                 $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
                    391:                 $lookup{'/'.$simplepages{$item}{'res'}} = $item;
                    392:                 my $content = '
                    393: <html>
                    394: <head>
                    395: <title>'.$pagetitle.'</title>
                    396: </head>
                    397: <body bgcolor="#ffffff">';
                    398:                 if ($contents{title}) {
                    399:                     $content .= "\n".'<h2>'.$contents{title}.'</h2>';
                    400:                 }
                    401:                 if ($contents{image}) {
                    402:                     $content .= "\n".$contents{image};
                    403:                 }
                    404:                 if ($contents{content}) {
                    405:                     $content .= '
                    406: <div class="LC_Box">
1.577     bisitz    407: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567     raeburn   408: $contents{content}.'
                    409: </div>';
                    410:                 }
                    411:                 if ($contents{webreferences}) {
                    412:                     $content .= ' 
                    413: <div class="LC_Box">
1.577     bisitz    414: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567     raeburn   415: $contents{webreferences}.'
                    416: </div>';
                    417:                 }
                    418:                 $content .= '
                    419: </body>
                    420: </html>
                    421: ';
                    422:                 $newcontent{'/'.$simplepages{$item}{res}} = $content; 
                    423:             }
                    424:         }
                    425: 	foreach my $item (keys(%tocopy)) {
                    426:             unless ($item=~/\.(sequence|page)$/) {
                    427:                 my $currurlpath = $prefix.$item;
                    428:                 my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
                    429:                 &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
                    430:             }
                    431:         }
                    432:         foreach my $num (sort {$a <=> $b} (@todump)) {
                    433:             my $src = $display{$num};
                    434:             next if ($src eq '');
                    435:             my @needcopy = ();
                    436:             if ($replacehash{$src}) {
                    437:                 push(@needcopy,$src);
                    438:                 if (ref($deps{$num}) eq 'HASH') {
                    439:                     foreach my $dep (sort(keys(%{$deps{$num}}))) {
                    440:                         if ($replacehash{$dep}) {
                    441:                             push(@needcopy,$dep);
                    442:                         }
                    443:                     }
                    444:                 }
                    445:             } elsif ($src =~ /^simpleproblem_/) {
                    446:                 push(@needcopy,$src);
                    447:             }
                    448:             next if (@needcopy == 0);
                    449:             my ($result,$depresult);
                    450:             for (my $i=0; $i<@needcopy; $i++) {
                    451:                 my $item = $needcopy[$i];
                    452:                 my $newfilename;
                    453:                 if ($simpleproblems{$num}) {
                    454:                     $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
                    455:                 } else {
                    456: 	            $newfilename=$title.'/'.$replacehash{$item};
                    457:                 }
                    458: 	        $newfilename=~s/\.(\w+)$//;
                    459: 	        my $ext=$1;
                    460: 	        $newfilename=&clean($newfilename);
                    461: 	        $newfilename.='.'.$ext;
                    462:                 my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); 
                    463:                 if ($newrelpath ne $replacehash{$item}) {
                    464:                     $replacehash{$item} = $newrelpath;
                    465:                 }
                    466: 	        my @dirs=split(/\//,$newfilename);
                    467: 	        my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
                    468: 	        my $makepath=$path;
                    469: 	        my $fail;
                    470:                 my $origin;
                    471: 	        for (my $i=0;$i<$#dirs;$i++) {
                    472: 		    $makepath.='/'.$dirs[$i];
                    473: 		    unless (-e $makepath) {
                    474: 		        unless(mkdir($makepath,0755)) { 
                    475:                             $fail = &mt('Directory creation failed.');
                    476:                         }
                    477: 		    }
                    478: 	        }
                    479:                 if ($i == 0) {
                    480: 	            $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
                    481:                 } else {
                    482:                     $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
                    483:                                   '<span class="LC_fontsize_small" style="font-weight: bold;">'.
                    484:                                   &mt('(dependency)').'</span>: ';
                    485:                 }
                    486:                 if (-e $path.'/'.$newfilename) {
                    487:                     $fail = &mt('Destination already exists -- not overwriting.'); 
                    488: 	        } else {
                    489:                     if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
                    490:                         if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
                    491:                             ($item =~ /^simpleproblem_/)) {
                    492:                             print $fh $newcontent{$item};
                    493:                         } else {
                    494:                             my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
                    495:                             if (-e $fileloc) {
                    496:                                 if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
                    497:                                     if ((($1 eq 'sequence') || ($1 eq 'page')) &&
                    498:                                         (ref($has_simpleprobs{$item}) eq 'HASH')) {
                    499:                                         my %changes = %{$has_simpleprobs{$item}};
                    500:                                         my $content = &Apache::lonclonecourse::rewritefile(
                    501:                      &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                    502:                                                       (%replacehash,$crs => '')
                    503:                                                                                           );
                    504:                                         my $updatedcontent = '';
                    505:                                         my $parser = HTML::TokeParser->new(\$content);
                    506:                                         $parser->attr_encoded(1);
                    507:                                         while (my $token = $parser->get_token) {
                    508:                                             if ($token->[0] eq 'S') {
                    509:                                                 if (($token->[1] eq 'resource') &&
                    510:                                                     ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && 
                    511:                                                     ($changes{$token->[2]->{'id'}})) {
                    512:                                                     my $id = $token->[2]->{'id'};
                    513:                                                     $updatedcontent .= '<'.$token->[1];
                    514:                                                     foreach my $attrib (@{$token->[3]}) {
                    515:                                                         next unless ($attrib =~ /^(src|type|title|id)$/);
                    516:                                                         if ($attrib eq 'src') {
                    517:                                                             my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); 
                    518:                                                             if ($file) {
                    519:                                                                 $updatedcontent .= ' '.$attrib.'="'.$file.'"';
                    520:                                                             } else {
                    521:                                                                 $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; 
                    522:                                                             }
                    523:                                                         } else {
                    524:                                                             $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
                    525:                                                         }
                    526:                                                     }
                    527:                                                     $updatedcontent .= ' />'."\n";
                    528:                                                 } else {
                    529:                                                     $updatedcontent .= $token->[4]."\n";
                    530:                                                 }
                    531:                                              } else {
                    532:                                                  $updatedcontent .= $token->[2];
                    533:                                              }
                    534:                                          }
                    535:                                          print $fh $updatedcontent;
                    536:                                     } else {  
                    537: 		                        print $fh &Apache::lonclonecourse::rewritefile(
                    538:                      &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                    539: 		                                      (%replacehash,$crs => '')
                    540: 							                              );
                    541:                                     }
                    542:                                 } else {
                    543: 		                    print $fh
                    544:                                         &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
                    545: 		                }
                    546:                             } else {
                    547:                                 $fail = &mt('Source does not exist.');  
                    548:                             }
                    549:                         }
                    550:                         $fh->close();
                    551: 	            } else {
                    552: 		        $fail = &mt('Could not write to destination.');
                    553:                     }
                    554: 	        }
                    555:                 my $text;
                    556: 	        if ($fail) {
                    557:                     $text = '<span class="LC_error">'.&mt('fail').('&nbsp;'x3).$fail.'</span>';
                    558: 	        } else {
                    559:                     $text = '<span class="LC_success">'.&mt('ok').'</span>';
                    560:                 }
                    561:                 if ($i == 0) {
                    562:                     $result .= $text;
                    563:                 } else {
                    564:                     $depresult .= $text.'</li>';
                    565: 	        }
                    566:             }
                    567:             $r->print($result);
                    568:             if ($depresult) {
                    569:                 $r->print('<ul>'.$depresult.'</ul>');
                    570:             }
                    571:         }
                    572:     } else {
                    573:         my ($navmap,$errormsg) =
                    574:             &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
                    575:         if (!ref($navmap)) {
                    576:             $r->print($errormsg);
                    577:         } else {
                    578: 	    my $title=$origcrsdata{'description'};
                    579: 	    $title=~s/[\/\s]+/\_/gs;
1.329     droeschl  580: 	    $title=&clean($title);
1.712     raeburn   581: 	    my $formname = 'dumpdoc';
1.715     raeburn   582: 	    my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
                    583:                            '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
1.712     raeburn   584: 	    my %uploadedfiles;
1.567     raeburn   585: 	    &tiehash();
                    586: 	    foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
                    587: 	        my ($ext)=($file=~/\.(\w+)$/);
                    588: # FIXME Check supplemental here
                    589: 	        my $title=$hash{'title_'.$hash{
                    590: 		                'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
                    591: 	        if (!$title) {
                    592: 		    $title=$file;
                    593: 	        } else {
                    594: 		    $title=~s|/|_|g;
                    595: 	        }
                    596: 	        $title=~s/\.(\w+)$//;
                    597: 	        $title=&clean($title);
                    598: 	        $title.='.'.$ext;
                    599: #	    $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
                    600:                 $uploadedfiles{$file} = $title;
                    601: 	    }
                    602: 	    &untiehash();
                    603:             $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
                    604:                                                                  undef,undef,$preamble,$home,\%uploadedfiles));
                    605:         }
1.329     droeschl  606:     }
1.484     raeburn   607:     $r->print(&endContentScreen());
1.329     droeschl  608: }
                    609: 
1.712     raeburn   610: sub authorspace_selector {
                    611:     my ($r,$formname,$home,$title,%outhash) = @_;
                    612:     $r->print('<div id="searching">'.&mt('Searching ...').'</div>'."\n");
                    613:     $r->rflush();
                    614:     my $preamble;
                    615:     unless ($home==1) {
                    616:         $preamble = '<div class="LC_left_float">'.
                    617:                     '<fieldset><legend>'.
                    618:                     &mt('Select the Authoring Space').
                    619:                     '</legend><select name="authorspace">';
                    620:     }
                    621:     my @orderspaces = ();
                    622:     foreach my $key (sort(keys(%outhash))) {
                    623:         if ($key=~/^home_(.+)$/) {
                    624:             if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
                    625:                 unshift(@orderspaces,$1);
                    626:             } else {
                    627:                 push(@orderspaces,$1);
                    628:             }
                    629:         }
                    630:     }
                    631:     if ($home>1) {
                    632:         $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
                    633:     }
                    634:     foreach my $user (@orderspaces) {
                    635:         if ($home==1) {
                    636:             $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
                    637:         } else {
                    638:             $preamble .= '<option value="'.$user.'">'.$user.' - '.
                    639:                          &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
                    640:         }
                    641:     }
                    642:     unless ($home==1) {
                    643:         $preamble .= '</select></fieldset></div>'."\n";
                    644:     }
                    645:     $preamble .= '<div class="LC_left_float">'.
                    646:                  '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
1.715     raeburn   647:                  '<input type="text" size="30" name="authorfolder" value="'.$title.'" />'."\n".
                    648:                  '</fieldset></div>'."\n";
1.712     raeburn   649:     return $preamble;
                    650: }
                    651: 
1.567     raeburn   652: sub recurse_html {
                    653:     my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
                    654:     return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
                    655:     my (%allfiles,%codebase);
                    656:     if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
                    657:         if (keys(%allfiles)) {
                    658:             foreach my $dependency (keys(%allfiles)) {
                    659:                 next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
                    660:                 my ($depurl,$relfile,$newcontainer);
                    661:                 if ($dependency =~ m{^/}) {
                    662:                     if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
                    663:                         $relfile = $1;
                    664:                         if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
                    665:                             $newcontainer = $1;
                    666:                             next if ($replacehash->{$newcontainer});
                    667:                         }
                    668:                         $depurl = $dependency;
                    669:                     } else {
                    670:                         next;
                    671:                     }
                    672:                 } else {
                    673:                     $relfile = $dependency;
                    674:                     $depurl = $currurlpath;
1.630     raeburn   675:                     $depurl =~ s{[^/]+$}{};
1.567     raeburn   676:                     $depurl .= $dependency;
1.630     raeburn   677:                     ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567     raeburn   678:                 }
                    679:                 next if ($relfile eq '');
                    680:                 my $newname = $replacehash->{$container};
                    681:                 $newname =~ s{[^/]+$}{};
                    682:                 $replacehash->{$newcontainer} = $newname.$relfile;
                    683:                 $deps->{$item}{$newcontainer} = 1;
                    684:                 my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});  
                    685:                 my $depfile = &Apache::lonnet::filelocation('',$depurl);
                    686:                 my $type = $mm->checktype_filename($depfile);
                    687:                 if ($type eq 'text/html') {
                    688:                     &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
                    689:                 }
                    690:             }
                    691:         }
                    692:     }
                    693:     return;
                    694: }
                    695: 
1.712     raeburn   696: sub copycrsauthored {
                    697:     my ($r,$coursenum,$coursedom,$coursehome,$readonly) = @_;
1.715     raeburn   698:     my ($starthash,$js,$title,$formname);
                    699:     my %origcrsdata=&Apache::lonnet::coursedescription($env{'request.course.id'});
                    700:     $title=$origcrsdata{'description'};
                    701:     $title=~s/[\/\s]+/\_/gs;
                    702:     $title=&clean($title);
                    703:     my ($home,$other,%outhash)=&authorhosts();
1.712     raeburn   704:     unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
1.715     raeburn   705:         my %js_lt;
                    706:         $formname = 'copycrsauthored';
                    707:         if ($home) {
                    708:             %js_lt =
                    709:                 &Apache::lonlocal::texthash(
                    710:                     yomu => 'You must select an Authoring Space',
                    711:                     whco => 'When Copyright set to "custom", URL of a published rights file is needed.',
                    712:             );
                    713:             &js_escape(\%js_lt);
                    714:         }
                    715:         if ($home > 1) {
                    716:             $js = <<"ENDJS";
                    717: <script type="text/javascript">
                    718: // <![CDATA[
                    719: 
                    720: function validCrsCopy() {
                    721:     var dest = document.$formname.authorspace.options[document.$formname.authorspace.selectedIndex].value;
                    722:     if (dest == '') {
                    723:         alert("$js_lt{'yomu'}");
                    724:         return false;
                    725:     }
                    726:     var dist = document.$formname.copyright.options[document.$formname.copyright.selectedIndex].value;
                    727:     if (dist == 'custom') {
                    728:         if (document.$formname.customrights.value == '') {
                    729:             alert("$js_lt{'whco'}");
                    730:             return false;
                    731:         }
1.716     raeburn   732:     }
1.715     raeburn   733:     return true;
                    734: }
                    735: 
                    736: function init_copycrs_form() {
                    737:     document.$formname.authorspace.selectedIndex = "0";
                    738:     document.$formname.authorfolder.value = '$title';
                    739:     document.$formname.copyright.selectedIndex = "0";
                    740: }
                    741: 
                    742: // ]]>
                    743: </script>
                    744: 
                    745: ENDJS
                    746:         } elsif ($home) {
                    747:             $js = <<"ENDJS";
                    748: <script type="text/javascript">
                    749: // <![CDATA[
                    750: 
                    751: function init_copycrs_form() {
                    752:     document.$formname.authorfolder.value = '$title';
                    753:     document.$formname.copyright.selectedIndex = "0";
                    754: }
                    755: 
                    756: // ]]>
                    757: </script>
                    758: 
                    759: ENDJS
                    760:         }
                    761:         $js .= <<"ENDJS";
1.712     raeburn   762: <script type="text/javascript">
                    763: // <![CDATA[
                    764: 
                    765: function hide_searching() {
                    766:     if (document.getElementById('searching')) {
                    767:         document.getElementById('searching').style.display = 'none';
                    768:     }
                    769:     return;
                    770: }
                    771: 
1.715     raeburn   772: function showHideCustom(caller,divid) {
                    773:     if (document.getElementById(divid)) {
                    774:         if (caller.options[caller.selectedIndex].value == 'custom') {
                    775:             document.getElementById(divid).style.display="inline-block";
                    776:         } else {
                    777:             document.getElementById(divid).style.display="none";
                    778:         }
                    779:     }
                    780:     return;
                    781: }
                    782: 
1.712     raeburn   783: // ]]>
                    784: </script>
                    785: ENDJS
1.715     raeburn   786: 
                    787:         $js .= "\n".&Apache::lonhtmlcommon::scripttag(&Apache::loncommon::browser_and_searcher_javascript())."\n";
1.712     raeburn   788:         $starthash = {
1.715     raeburn   789:                          add_entries => {'onload' => "hide_searching(); init_copycrs_form();"},
1.712     raeburn   790:                      };
                    791:     }
                    792:     $r->print(&Apache::loncommon::start_page('Copy from Course Authoring to User Authoring',$js,$starthash)."\n".
                    793:               &Apache::lonhtmlcommon::breadcrumbs('Copy from Course Authoring Space')."\n");
                    794:     $r->print(&startContentScreen('tools'));
                    795:     unless ($home) {
                    796:         $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>');
                    797:         $r->print(&endContentScreen());
                    798:         return '';
                    799:     }
1.715     raeburn   800:     my $docroot = $r->dir_config('lonDocRoot');
1.714     raeburn   801:     my $is_course_home;
                    802:     my @ids=&Apache::lonnet::current_machine_ids();
                    803:     if (($coursehome ne '') && (grep(/^\Q$coursehome\E$/,@ids))) {
                    804:         $is_course_home = 1;
                    805:     }
1.712     raeburn   806:     my $exclude = &Apache::lonnet::priv_exclude();
                    807:     my $srcurl = "/priv/$coursedom/$coursenum";
1.715     raeburn   808:     my $srctop = $docroot.$srcurl;
                    809:     my $resurl = "/res/$coursedom/$coursenum";
                    810:     my $res_exclude = &Apache::lonnet::res_exclude();
1.712     raeburn   811:     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    812:         $r->print('<h3>'.&mt('Copying Files and/or Sub-directories').'</h3>');
                    813:         if ($readonly) {
                    814:             $r->print('<p class="LC_info">'.
                    815:                       &mt('You do not have permission to copy files and/or directories from Course Authoring Space.').
                    816:                       '</p>'.
                    817:                       &endContentScreen());
                    818:             return '';
                    819:         }
                    820:         unless ($outhash{'home_'.$env{'form.authorspace'}}) {
                    821:             $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
                    822:                       &endContentScreen());
                    823:             return '';
                    824:         }
                    825:         my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
                    826:         my $desturl = "/priv/$cd/$ca";
1.715     raeburn   827:         my $destresurl = "/res/$cd/$ca";
                    828:         my $desttop = $docroot.$desturl;
1.712     raeburn   829:         my $subdir = &clean($env{'form.authorfolder'});
                    830:         $subdir = &cleandir($subdir);
                    831:         if ($subdir eq '') {
                    832:             $r->print('<p class="LC_info">'.&mt('After removal of disallowed characters target sub-directory name was blank.').'</p>'.
                    833:                       &endContentScreen());
                    834:             return '';
                    835:         } elsif ($subdir =~/^_+$/) {
                    836:             $r->print('<p class="LC_info">'.&mt('After replacement of non-alphanumeric characters with _ in target sub-directory name, nothing but underscores was left.').'</p>'.
                    837:                       &endContentScreen());
                    838:             return '';
                    839:         }
                    840:         my (%tocopy,%dirs_to_make,%files_to_copy);
                    841:         map { $tocopy{&unescape($_)} = 1; } &Apache::loncommon::get_env_multiple('form.copytouser');
                    842:         if (keys(%tocopy)) {
                    843:             my (%subdirs,%files);
1.714     raeburn   844:             &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files);
1.712     raeburn   845:             foreach my $possible (sort(keys(%tocopy))) {
                    846:                 if ($possible =~ m{/$}) {
                    847:                     my $possdir = $possible;
                    848:                     $possdir =~ s{^/+|/+$}{}g;
                    849:                     if (exists($subdirs{$possdir})) {
                    850:                         $dirs_to_make{$possdir} = 1;
                    851:                     } else {
                    852:                         delete($tocopy{$possible});
                    853:                     }
                    854:                 } else {
                    855:                     my ($path,$fname) = ($possible =~ m{(.*/)([^/]+)$});
                    856:                     my $found = 0;
                    857:                     if ($path eq '/') {
                    858:                         if (ref($files{$path}) eq 'HASH') {
                    859:                             if (exists($files{$path}{$fname})) {
                    860:                                 $found = 1;
                    861:                                 $files_to_copy{$fname} = 1;
                    862:                             }
                    863:                         }
                    864:                     } else {
                    865:                         $path =~ s{^/+|/+$}{}g;
                    866:                         if (ref($files{$path}) eq 'HASH') {
                    867:                             if (exists($files{$path}{$fname})) {
                    868:                                 $dirs_to_make{$path} = 1;
                    869:                                 $files_to_copy{"$path/$fname"} = 1;
                    870:                                 $found = 1;
                    871:                             }
                    872:                         }
                    873:                     }
                    874:                     unless ($found) {
                    875:                         delete($tocopy{$possible});
                    876:                     }
                    877:                 }
                    878:             }
                    879:         } else {
                    880:             $r->print('<p>'.&mt('No files or directories selected for copying').'</p>');
                    881:             $r->print(&endContentScreen());
                    882:             return '';
                    883:         }
                    884:         if (keys(%tocopy)) {
1.714     raeburn   885:             my (%resdirs,%resfiles);
                    886:             &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
1.719     raeburn   887:             my ($notopdir,%newdir,%newfile,%checkdeps,%newresfile);
1.712     raeburn   888:             $r->print('<p>'.&mt('Copy to: [_1]',
                    889:                                 '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
                    890:                       '</p>'."\n");
                    891:             if (keys(%dirs_to_make)) {
1.714     raeburn   892:                 unless (-e $desttop.'/'.$subdir) {
                    893:                     mkdir($desttop.'/'.$subdir,0755);
                    894:                 }
                    895:                 if (-e $desttop.'/'.$subdir) {
                    896:                     foreach my $dir (sort(keys(%dirs_to_make))) {
                    897:                         my @dirs=split(/\//,$dir);
                    898:                         my $path="$desttop/$subdir";
                    899:                         my $makepath=$path;
                    900:                         my $fail;
                    901:                         for (my $i=0;$i<@dirs;$i++) {
                    902:                             $makepath.='/'.$dirs[$i];
                    903:                             unless (-e $makepath) {
                    904:                                 unless (mkdir($makepath,0755)) {
                    905:                                     $fail = 1;
                    906:                                     last;
                    907:                                 }
                    908:                                 if (($i == scalar(@dirs)-1) && (!$fail))  {
                    909:                                     $newdir{$dir} = 1;
1.712     raeburn   910:                                 }
                    911:                             }
                    912:                         }
1.714     raeburn   913:                         if ($fail) {
                    914:                             $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
                    915:                                                                    '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$dir.'</span>').
                    916:                                       '</p>'."\n");
                    917:                         }
1.712     raeburn   918:                     }
1.714     raeburn   919:                 } else {
                    920:                     $notopdir = 1;
1.712     raeburn   921:                 }
                    922:             }
                    923:             if (keys(%files_to_copy)) {
1.714     raeburn   924:                 unless (-e $desttop.'/'.$subdir) {
                    925:                     mkdir($desttop.'/'.$subdir,0755);
                    926:                 }
                    927:                 if (-e $desttop.'/'.$subdir) {
                    928:                     my $num = 0;
1.715     raeburn   929:                     my ($copyright,$customdistfile);
                    930:                     if ($env{'form.copyright'} eq 'default' || $env{'form.copyright'} eq 'domain' || $env{'form.copyright'} eq 'public') {
                    931:                         $copyright = $env{'form.copyright'};
                    932:                     } elsif ($env{'form.copyright'} eq 'custom') {
                    933:                         if ($env{'form.customrights'} =~ m{^/res/$match_domain/$match_username/.+\.rights$}) {
                    934:                             my ($rightsdom,$rightsuname) = ($1,$2);
                    935:                             my $rightshome = &Apache::lonnet::homeserver($rightsdom,$rightsuname);
                    936:                             if (($rightshome eq 'no_host') || ($rightshome eq '')) {
                    937:                                 $copyright = 'default';
                    938:                             } elsif (grep(/^\Q$rightshome\E$/,@ids)) {
                    939:                                 if (-e $docroot.$env{'form.customrights'}) {
                    940:                                     $copyright = 'custom';
                    941:                                     $customdistfile = $env{'form.customrights'};
                    942:                                 } else {
                    943:                                     $copyright = 'default';
                    944:                                 }
                    945:                             } else {
                    946:                                 my $rightsfile = &Apache::lonnet::filelocation('',$env{'form.customrights'});
                    947:                                 unless (&Apache::lonnet::getfile($rightsfile) eq '-1') {
                    948:                                     $customdistfile = $env{'form.customrights'};
                    949:                                 }
                    950:                             }
                    951:                         }
                    952:                     }
                    953:                     my $sourceavail;
                    954:                     if ($env{'form.sourceavail'} =~ /^(open|closed)$/) {
                    955:                         $sourceavail = $env{'form.sourceavail'};
                    956:                     }
                    957:                     my $respublish;
                    958:                     if ($env{'form.respublish'}) {
                    959:                         $respublish = 1;
                    960:                     }
                    961:                     my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
1.714     raeburn   962:                     foreach my $file (keys(%files_to_copy)) {
                    963:                         my ($fail,$dup,$dir_is_file,$src,$dest,$path,$fname);
                    964:                         if ($file =~ m{/}) {
                    965:                             ($path,$fname) = ($file =~ m{^(.+)/([^/]+)$});
                    966:                             if (-d "$desttop/$subdir/$path") {
                    967:                                 if (-e "$desttop/$subdir/$path/$fname") {
                    968:                                     $dup = 1;
1.712     raeburn   969:                                 } else {
1.714     raeburn   970:                                     $src = "$srctop/$path/$fname";
                    971:                                     $dest = "$desttop/$subdir/$path/$fname";
1.712     raeburn   972:                                 }
1.714     raeburn   973:                             } elsif (-f "$desttop/$subdir/$path") {
                    974:                                 $dir_is_file = 1;
1.712     raeburn   975:                             } else {
1.714     raeburn   976:                                 $fail = 1;
                    977:                             }
                    978:                         } elsif (-e "$desttop/$subdir/$file") {
                    979:                             $dup = 1;
                    980:                         } else {
                    981:                             $src = "$srctop/$file";
                    982:                             $dest = "$desttop/$subdir/$file";
                    983:                             $fname = $file;
                    984:                         }
                    985:                         if ($fail) {
                    986:                             $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
                    987:                                                                    '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$path.'</span>').
                    988:                                       '</p>'."\n");
                    989:                         } elsif ($dup) {
                    990:                             $r->print('<p class="LC_warning">'.&mt('Target file: [_1] already exists -- not overwriting.',
                    991:                                                                    '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
                    992:                                       '</p>'."\n");
                    993:                         } elsif ($dir_is_file) {
                    994:                             $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] name is already in a use for a file -- not overwriting.',
                    995:                                                                    '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
                    996:                                       '</p>'."\n");
                    997:                         } elsif (($src ne '') && ($dest ne '')) {
1.717     raeburn   998:                             my $ressrc = $docroot.$resurl.'/'.$file;
                    999:                             my $ressrcmeta = $ressrc.'.meta';
                   1000:                             my ($ext) = ($file =~ /\.(\w+)$/);
                   1001:                             my $embstyle=&Apache::loncommon::fileembstyle($ext);
                   1002:                             my ($getres,$getresmeta);
                   1003:                             if ($respublish) {
                   1004:                                 if ($path eq '') {
                   1005:                                     if ((ref($resfiles{'/'}) eq 'HASH') &&
                   1006:                                         (exists($resfiles{'/'}{$fname}))) {
                   1007:                                         $getres = 1;
                   1008:                                         $getresmeta = 1;
                   1009:                                     }
                   1010:                                 } elsif ((ref($resfiles{$path}) eq 'HASH') &&
                   1011:                                          (exists($resfiles{$path}{$fname}))) {
                   1012:                                     $getres = 1;
                   1013:                                     $getresmeta = 1;
1.714     raeburn  1014:                                 }
                   1015:                             }
1.717     raeburn  1016:                             if ($is_course_home) {
                   1017:                                 my ($needpriv,$needprivmeta);
                   1018:                                 if ($respublish) {
                   1019:                                     if ($getres) {
                   1020:                                         if (&Apache::londiff::are_different_files($src,$ressrc)) {
                   1021:                                             $needpriv = 1;
                   1022:                                             if (&File::Copy::copy($ressrc,$dest)) {
                   1023:                                                 if ($embstyle eq 'ssi') {
                   1024:                                                     &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
                   1025:                                                 }
                   1026:                                             }
                   1027:                                         } else {
                   1028:                                             if (&File::Copy::copy($src,$dest)) {
1.719     raeburn  1029:                                                 $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717     raeburn  1030:                                                 if ($embstyle eq 'ssi') {
                   1031:                                                     &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
                   1032:                                                 }
                   1033:                                             }
1.714     raeburn  1034:                                         }
1.717     raeburn  1035:                                     } else {
                   1036:                                         $needpriv = 1;
1.714     raeburn  1037:                                     }
1.717     raeburn  1038:                                     if ($getresmeta) {
                   1039:                                         if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
                   1040:                                             if (&Apache::londiff::are_different_files($src.'.meta',$ressrc.'.meta')) {
                   1041:                                                 if (&File::Copy::copy($ressrc.'.meta',$dest.'.meta')) {
                   1042:                                                     &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1043:                                                                        $customdistfile,$sourceavail,\%checkdeps);
1.715     raeburn  1044:                                                 }
1.717     raeburn  1045:                                                 $needprivmeta = 1;
                   1046:                                             } else {
                   1047:                                                 if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
                   1048:                                                     &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1049:                                                                        $customdistfile,$sourceavail,\%checkdeps);
1.713     raeburn  1050:                                                 }
                   1051:                                             }
1.712     raeburn  1052:                                         }
1.717     raeburn  1053:                                     }
                   1054:                                     if ($getres) {
                   1055:                                         my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
                   1056:                                         if (-e $dest) {
                   1057:                                             my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
1.719     raeburn  1058:                                             if (-e $destresfile) {
                   1059:                                                 $newresfile{$file} = $destresurl.'/'.$subdir.'/'.$file;
                   1060:                                             }
1.714     raeburn  1061:                                         }
1.712     raeburn  1062:                                     }
1.717     raeburn  1063:                                 } else {
                   1064:                                     $needpriv = 1;
                   1065:                                     if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
                   1066:                                         $needprivmeta = 1;
                   1067:                                     }  
                   1068:                                 }
                   1069:                                 if ($needpriv) {
                   1070:                                     if (&File::Copy::copy($src,$dest)) {
1.719     raeburn  1071:                                         $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717     raeburn  1072:                                         if ($embstyle eq 'ssi') {
                   1073:                                             &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
                   1074:                                         }
                   1075:                                     }
                   1076:                                 }
                   1077:                                 if ($needprivmeta) {
                   1078:                                     if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
                   1079:                                          &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1080:                                                             $customdistfile,$sourceavail,\%checkdeps);
                   1081:                                     }
1.714     raeburn  1082:                                 }
1.717     raeburn  1083:                             } else {
                   1084:                                 my ($needpriv,$needprivmeta);
                   1085:                                 if ($respublish) {
                   1086:                                     if ($getres) {
                   1087:                                         &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file);
                   1088:                                     }
                   1089:                                     if ($getresmeta) {
                   1090:                                         &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file.'.meta');
                   1091:                                     }
                   1092:                                     if (-e $docroot.$resurl.'/'.$file) {
                   1093:                                         if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
                   1094:                                             if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file,$dest)) {
                   1095:                                                 $needpriv = 1;
                   1096:                                                 if (&File::Copy::copy($docroot.$resurl.'/'.$file,$dest)) {
                   1097:                                                     if ($embstyle eq 'ssi') {
                   1098:                                                         &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
1.713     raeburn  1099:                                                     }
1.714     raeburn  1100:                                                 }
1.717     raeburn  1101:                                             } else {
                   1102:                                                 if ($embstyle eq 'ssi') {
                   1103:                                                     &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1.714     raeburn  1104:                                                 }
1.719     raeburn  1105:                                                 $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717     raeburn  1106:                                             }
                   1107:                                         }
                   1108:                                     } else {
                   1109:                                         $needpriv = 1;
                   1110:                                     }
                   1111:                                     if (-e $docroot.$resurl.'/'.$file.'.meta') {
                   1112:                                         if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
                   1113:                                             if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
                   1114:                                                 $needprivmeta = 1;
                   1115:                                                 if (&File::Copy::copy($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
                   1116:                                                     &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1117:                                                                        $customdistfile,$sourceavail,\%checkdeps);
1.713     raeburn  1118:                                                 }
1.714     raeburn  1119:                                             } else {
1.717     raeburn  1120:                                                 &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1121:                                                                    $customdistfile,$sourceavail,\%checkdeps);
1.713     raeburn  1122:                                             }
                   1123:                                         }
1.717     raeburn  1124:                                     } else {
                   1125:                                         if (!-e $dest.'.meta') {
                   1126:                                             $needprivmeta = 1;
                   1127:                                         }
1.714     raeburn  1128:                                     }
1.717     raeburn  1129:                                     if ($getres) {
                   1130:                                         my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
                   1131:                                         if (-e $dest) {
                   1132:                                             my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
1.719     raeburn  1133:                                             if (-e $destresfile) {
                   1134:                                                 $newresfile{$file} = $destresurl.'/'.$subdir.'/'.$file;
                   1135:                                             }
1.713     raeburn  1136:                                         }
1.712     raeburn  1137:                                     }
1.717     raeburn  1138:                                 } else {
                   1139:                                     $needpriv = 1;
                   1140:                                     if (!-e $dest.'.meta') {
                   1141:                                         $needprivmeta = 1;
                   1142:                                     }
1.712     raeburn  1143:                                 }
1.717     raeburn  1144:                                 if ($needpriv) {
                   1145:                                     if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
                   1146:                                         if ($embstyle eq 'ssi') {
                   1147:                                             &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1.715     raeburn  1148:                                         }
1.719     raeburn  1149:                                         $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717     raeburn  1150:                                     }
                   1151:                                 }
                   1152:                                 if ($needprivmeta) {
                   1153:                                     if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
                   1154:                                         &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1155:                                                            $customdistfile,$sourceavail,\%checkdeps);
1.715     raeburn  1156:                                     }
                   1157:                                 }
1.712     raeburn  1158:                             }
                   1159:                         }
                   1160:                     }
1.714     raeburn  1161:                 } else {
                   1162:                     $notopdir = 1;
1.712     raeburn  1163:                 }
                   1164:             }
                   1165:             if ($notopdir) {
                   1166:                 $r->print('<p><span class="LC_info">'.&mt('No files or sub-directories copied').'</span><br />'."\n".
                   1167:                           '<span class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
                   1168:                                                           '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
                   1169:                           '</span></p>'."\n");
                   1170:             }
                   1171:             if (keys(%newdir)) {
                   1172:                  $r->print('<p>'.&mt('Created the following directories in [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
                   1173:                            '</p>'."\n".
                   1174:                            '<ul><li>'.join('</li><li>',sort(keys(%newdir))).'</li></ul></p>'."\n");
                   1175:             }
                   1176:             if (keys(%newfile)) {
                   1177:                 $r->print('<p>'.&mt('Copied the following files to [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
                   1178:                           '</p>'."\n".
                   1179:                           '<ul><li>'.join('</li><li>',sort(keys(%newfile))).'</li></ul></p>'."\n");
1.722     raeburn  1180:                 foreach my $file (keys(%newfile)) {
                   1181:                     my %storehash = (
                   1182:                                       'priv' => $newfile{$file},
1.719     raeburn  1183:                                       'who'  => $env{'user.name'}.':'.$env{'user.domain'},
                   1184:                                     );
                   1185:                     if (exists($newresfile{$file})) {
                   1186:                         $storehash{'res'} = 1;
                   1187:                     }
                   1188:                     &Apache::lonnet::store_userdata(\%storehash,$file,'copycourseauthor',$coursedom,$coursenum);
                   1189:                 }
1.712     raeburn  1190:             }
1.713     raeburn  1191:             if (keys(%checkdeps)) {
                   1192:                 my %missingdep;
                   1193:                 foreach my $depfile (sort(keys(%checkdeps))) {
                   1194:                     unless (-e "$desttop/$depfile") {
                   1195:                         $missingdep{$depfile} = 1;
                   1196:                     }
                   1197:                 }
                   1198:                 if (keys(%missingdep)) {
                   1199:                     $r->print('<p>'.&mt('You may also need to copy the following missing dependencies for files copied to [_1]:',
                   1200:                                         '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
                   1201:                           '</p>'."\n".
                   1202:                           '<ul><li>'.join('</li><li>',sort(keys(%missingdep))).'</li></ul></p>'."\n");
                   1203:                 }
                   1204:             }
1.712     raeburn  1205:         } else {
                   1206:             $r->print('<p>'.&mt('No currently existing files or directories in Course Authoring Space selected for copying').'</p>');
                   1207:             $r->print(&endContentScreen());
                   1208:             return '';
                   1209:         }
                   1210:     } else {
                   1211:         my $chkname = 'copytouser';
                   1212:         my $context = 'crsauthored';
                   1213:         my (%subdirs,%files,@dirs_by_depth,@files_by_depth,%parent,%children,%hierarchy,@checked_maps);
1.714     raeburn  1214:         &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files,1);
1.712     raeburn  1215:         foreach my $key (keys(%subdirs)) {
                   1216:             next if (($key eq '/') || ($key eq ''));
                   1217:             my @items = split(/\//,$key);
                   1218:             my $dir = pop(@items);
                   1219:             my $depth = scalar(@items);
                   1220:             my $path;
                   1221:             if (!$depth) {
                   1222:                 $path = '/';
                   1223:             } else {
                   1224:                 $path = join('/',@items);
                   1225:             }
                   1226:             $dirs_by_depth[$depth]{$path}{$dir} = 1;
                   1227:         }
                   1228:         foreach my $path (keys(%files)) {
                   1229:             next if ($path eq '');
                   1230:             my $depth;
                   1231:             if ($path eq '/') {
                   1232:                 $depth = 0;
                   1233:             } else {
                   1234:                 $depth = scalar(split(/\//,$path));
                   1235:             }
                   1236:             if (ref($files{$path}) eq 'HASH') {
                   1237:                 foreach my $file (keys(%{$files{$path}})) {
1.714     raeburn  1238:                     $files_by_depth[$depth]{$path}{$file} = $files{$path}{$file};
1.712     raeburn  1239:                 }
                   1240:             }
                   1241:         }
                   1242:         my ($info,$display,$onsubmit,$togglebuttons,$disabled);
1.714     raeburn  1243:         my (%resdirs,%resfiles);
1.715     raeburn  1244:         &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
                   1245:         my $numpub = 0;
                   1246:         if (keys(%resfiles)) {
                   1247:             foreach my $dir (keys(%resfiles)) {
                   1248:                 if (ref($resfiles{$dir}) eq 'HASH') {
                   1249:                     foreach my $file (keys(%{$resfiles{$dir}})) {
                   1250:                         if (exists($files{$dir}{$file})) {
                   1251:                             $numpub ++;
                   1252:                         }
                   1253:                     }
                   1254:                 }
                   1255:             }
                   1256:         }
1.712     raeburn  1257:         if ($readonly) {
                   1258:             $disabled = ' disabled="disabled"';
                   1259:         }
                   1260:         if ($disabled) {
                   1261:             $togglebuttons = '<br />';
                   1262:         } else {
                   1263:             $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
                   1264:                              'onclick="javascript:checkAll(document.'.$formname.'.'.$chkname.')" />'.
                   1265:                              '&nbsp;&nbsp;<input type="button" value="'.&mt('uncheck all').'"'.
                   1266:                              ' onclick="javascript:uncheckAll(document.'.$formname.'.'.$chkname.')" />';
                   1267:         }
1.715     raeburn  1268:         my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
                   1269:                        &courseresource_options($formname,$numpub).
                   1270:                        '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
                   1271:         my $display = '<form name="'.$formname.'" action="" method="post" onsubmit="return validCrsCopy();">'."\n".
1.712     raeburn  1272:                       $preamble."\n".
                   1273:                       '<div class="LC_float_left">'."\n".
                   1274:                       '<fieldset>'."\n".
                   1275:                       '<legend>'.&mt('Content to copy').('&nbsp;'x4).$togglebuttons.'</legend>'."\n".
                   1276:                       '<span class="LC_fontsize_medium">'.
                   1277:                       &mt('Choose the files and/or folders to copy from Course Authoring to User Authoring').
                   1278:                       '</span><br /><br />'."\n";
                   1279:         my $count = 0;
1.721     raeburn  1280: #
                   1281: # Warning to developers:
                   1282: #
                   1283: # If you add or remove form elements which precede the table of items to copy
                   1284: # you will need to modify the value for startcount. Form elements include both:
                   1285: # <input> and <fieldset> tags.
                   1286: # $startcount (set to 9) contains the following:
                   1287: # fieldsets with following legends: (a) Folder in Authoring Space, (b) Distribution to set in metadata
                   1288: # (c) Content to copy
                   1289: # inputs: textbox for destination folder; dropdown lists: (a) Copyright, (b) Source
                   1290: # hidden: customrights file;  buttons: (a) check all, (b) uncheck all.
                   1291: # authorspace: if more than 1: a fieldset with legend: Select the Authoring Space,
                   1292: # or if 1: an input (hidden) with available author/coauthor role.
                   1293: # if there are multiple possible author/coauthor roles (i.e., $home > 1),
                   1294: # incerement startcount by 1 for the dropdown list uses to select the target.
                   1295: #
                   1296: # If there are published files, increment startcount by 3:
                   1297: # fieldset (legend: Published Resources), and two radio buttons (Yes/No).
                   1298: #
                   1299:         my $startcount = 9;
                   1300:         if ($home > 1) {
                   1301:             $startcount ++;
                   1302:         }
                   1303:         if ($numpub) {
                   1304:             $startcount += 3;
                   1305:         }
1.712     raeburn  1306:         my $lastcontainer = $startcount;
                   1307:         $display .= &Apache::loncommon::start_data_table()."\n".
                   1308:                     &Apache::loncommon::start_data_table_header_row().
                   1309:                     '<th>'.&mt('Copy?').'</th>'.
1.714     raeburn  1310:                     '<th>'.&mt('Name').'</th>'.
                   1311:                     '<th>'.&mt('Last modified').'</th>'.
                   1312:                     '<th>'.&mt('Published?').'</th>'.
1.712     raeburn  1313:                     &Apache::loncommon::end_data_table_header_row()."\n";
                   1314:         $count = &recurse_crsauthored(0,\@dirs_by_depth,\@files_by_depth,'/',$startcount,
                   1315:                                       $count,\$display,\%parent,\%children,$readonly,
1.714     raeburn  1316:                                       $formname,$chkname,\$lastcontainer,\%resfiles);
1.712     raeburn  1317:         $display .= &Apache::loncommon::end_data_table().'</fieldset>';
                   1318:         unless ($readonly) {
                   1319:             $display .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   1320:                         '<div>'.
                   1321:                         '<input type="submit" name="copyauthored" value="'.&mt("Copy Selected Content").'" />'.
                   1322:                         '</div>';
                   1323:         }
                   1324:         $display .= &Apache::loncourserespicker::respicker_javascript($startcount,$count,$context,$formname,\%children,
                   1325:                                                                       \%hierarchy,\@checked_maps,$home,$chkname);
                   1326:         $r->print($display);
                   1327:     }
                   1328:     $r->print(&endContentScreen());
                   1329: }
                   1330: 
                   1331: sub recurse_crsauthored {
                   1332:     my ($currdepth,$dirs_by_depth,$files_by_depth,$currpath,$startcount,$count,$displayref,
1.714     raeburn  1333:         $parent,$children,$readonly,$formname,$chkname,$lastcontainerref,$resfilesref) = @_;
                   1334:     return $count unless ((ref($dirs_by_depth) eq 'ARRAY') && (ref($files_by_depth) eq 'ARRAY') &&
                   1335:                           (ref($resfilesref) eq 'HASH'));
1.712     raeburn  1336:     my ($disabled,$hasdirs,$hasfiles,%unique,%dirs,%files);
                   1337:     if ((ref($dirs_by_depth->[$currdepth]) eq 'HASH') &&
                   1338:         (ref($dirs_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
                   1339:         $hasdirs = 1;
                   1340:         %dirs = %{$dirs_by_depth->[$currdepth]{$currpath}};
                   1341:         map { $unique{$_} = 1; } keys(%dirs);
                   1342:     }
                   1343:     if ((ref($files_by_depth->[$currdepth]) eq 'HASH') &&
                   1344:         (ref($files_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
                   1345:         $hasfiles = 1;
                   1346:         %files = %{$files_by_depth->[$currdepth]{$currpath}};
                   1347:         map { $unique{$_} = 1; } keys(%files);
                   1348:     }
                   1349:     if ($readonly) {
                   1350:         $disabled = ' disabled="disabled"';
                   1351:     }
                   1352:     my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
                   1353:     my $whitespace =
                   1354:         '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
                   1355:     $parent->{$currdepth} = $$lastcontainerref;
                   1356:     foreach my $item (sort { lc($a) cmp lc($b) } (keys(%unique))) {
                   1357:         next if ($item eq '');
                   1358:         my $currelem;
                   1359:         if ($hasdirs && exists($dirs{$item})) {
                   1360:             $count ++;
                   1361:             my $deeper = $currdepth+1;
                   1362:             my ($newpath,$showpath);
                   1363:             if ($currpath eq '/') {
                   1364:                 $newpath = $item;
                   1365:                 $showpath = $currpath.$item.'/';
                   1366:             } else {
                   1367:                 $newpath = $currpath.'/'.$item;
                   1368:                 $showpath = '/'.$currpath.'/'.$item.'/';
                   1369:             }
                   1370:             $currelem = $count+$startcount;
                   1371:             $$lastcontainerref = $currelem;
                   1372:             $children->{$parent->{$currdepth}} .= $currelem.':';
                   1373:             my $icon = 'src="'.$location.'/navmap.folder.open.gif" alt="'.&mt('Folder').'"';
                   1374:             $$displayref .= &Apache::loncommon::start_data_table_row().
                   1375:                             '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath).'" '.
                   1376:                             'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" '.
                   1377:                             $disabled.' /></td><td>';
                   1378:             for (my $i=0; $i<$currdepth; $i++) {
                   1379:                 $$displayref .= "$whitespace\n";
                   1380:             }
1.714     raeburn  1381:             $$displayref .= '<img '.$icon.' />&nbsp;'.$item.'</td><td>&nbsp;</td><td>&nbsp;</td>'.
1.712     raeburn  1382:                             &Apache::loncommon::end_data_table_row()."\n";
                   1383:             $count = &recurse_crsauthored($deeper,$dirs_by_depth,$files_by_depth,$newpath,
                   1384:                                           $startcount,$count,$displayref,$parent,$children,
1.714     raeburn  1385:                                           $readonly,$formname,$chkname,$lastcontainerref,$resfilesref);
1.712     raeburn  1386:         }
                   1387:         if ($hasfiles && exists($files{$item})) {
                   1388:             $count ++;
                   1389:             $currelem = $count+$startcount;
                   1390:             $children->{$parent->{$currdepth}} .= $currelem.':';
                   1391:             my $icon = 'src="'.&Apache::loncommon::icon($item).'"';
                   1392:             my ($ext) = ($item =~ /\.([^.]+)$/);
                   1393:             my $alttext;
                   1394:             if (lc($ext) eq 'problem') {
                   1395:                 $alttext = ' alt="'.&mt('Problem Icon').'"';
                   1396:             } elsif ($ext =~ /^x?html?$/i) {
                   1397:                 $alttext = ' alt="'.&mt('Web Page Icon').'"';
                   1398:             } elsif ($ext =~ /^(jpg|gif|png|svg|jpeg)$/) {
                   1399:                 $alttext = ' alt="'.&mt('Image Icon').'"';
                   1400:             } else {
                   1401:                 $alttext = ' alt="'.&mt('Resource Icon').'"';
                   1402:             }
                   1403:             my $showpath;
                   1404:             if ($currpath eq '/') {
                   1405:                 $showpath = $currpath;
                   1406:             } else {
                   1407:                 $showpath = "/$currpath/";
                   1408:             }
1.714     raeburn  1409:             my ($published,$lastmod);
                   1410:             if ((ref($resfilesref->{$currpath})) && (exists($resfilesref->{$currpath}{$item}))) {
                   1411:                 $published = '<img src="'.$location.'/navmap.correct.gif" alt="'.&mt('yes').'" />';
                   1412:             } else {
                   1413:                 $published = '<img src="'.$location.'/navmap.wrong.gif" alt="'.&mt('no').'" />';
                   1414:             }
1.712     raeburn  1415:             $$displayref .= &Apache::loncommon::start_data_table_row().
                   1416:                             '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath.$item).'" '.
                   1417:                             'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" '.
                   1418:                             $disabled.' /></td><td>';
                   1419:             for (my $i=0; $i<$currdepth; $i++) {
                   1420:                 $$displayref .= "$whitespace\n";
                   1421:             }
                   1422:             $$displayref .= '<img '.$icon.$alttext.' />&nbsp;'.$item.'</td>'.
1.714     raeburn  1423:                             '<td>'.&Apache::lonlocal::locallocaltime($files{$item}).'</td>'.
                   1424:                             '<td style="text-align: center;">'.$published.'</td>'.
1.712     raeburn  1425:                             &Apache::loncommon::end_data_table_row()."\n";
                   1426:         }
                   1427:     }
                   1428:     $$lastcontainerref = $parent->{$currdepth};
                   1429:     return $count;
                   1430: }
                   1431: 
1.715     raeburn  1432: sub courseresource_options {
                   1433:     my ($formname,$numpub) = @_;
                   1434:     my %lt = &Apache::lonlocal::texthash(
                   1435:                                           'default' => 'System wide - can be used for any courses system wide',
                   1436:                                           'domain'  => 'Domain only - use limited to courses in the domain',
                   1437:                                           'custom'  => 'Customized right of use ...',
                   1438:                                           'public'  => 'Public - no authentication or authorization required for use',
                   1439:                                           'closed'  => 'Closed - XML source is closed to everyone',
                   1440:                                           'open'    => 'Open - XML source is open to people who want to use it',
                   1441:                                           'sel'     => 'Select',
                   1442:                                         );
                   1443:     my $output;
                   1444:     if ($numpub) {
                   1445:         $output .= '<div class="LC_left_float">'.
                   1446:                    '<fieldset><legend>'.&mt('Published Resources').'</legend>'.
                   1447:                    &mt('[quant,_1,file] in Course Authoring Space also exist in Resource Space.',
                   1448:                        $numpub).'</br />'.
                   1449:                    &mt('Publish copied files in selected Authoring Space?').': '."\n".
                   1450:                    '<label><input type="radio" name="respublish" checked="checked" value="1" />'.
                   1451:                    &mt('Yes').'</label>'."\n".
                   1452:                    '<label><input type="radio" name="respublish" value="0" />'.
                   1453:                    &mt('No').'</label>'."\n".
                   1454:                    '</fieldset></div>'."\n";
                   1455:     }
                   1456:     $output .= '<div class="LC_left_float">'.
                   1457:                '<fieldset><legend>'.&mt('Distribution to set in metadata').'</legend>'.
                   1458:                &mt('Copyright').': '.
                   1459:                '<select name="copyright" onchange="showHideCustom(this,'."'LC_customfile'".');">'."\n".
                   1460:                '<option value="default" selected="selected">'.$lt{'default'}.'</option>'."\n".
                   1461:                '<option value="domain">'.$lt{'domain'}.'</option>'."\n".
                   1462:                '<option value="public">'.$lt{'public'}.'</option>'."\n".
                   1463:                '<option value="custom">'.$lt{'custom'}.'</option>'."\n".
                   1464:                '</select><div id="LC_customfile" style="padding:0;clear:both;margin:0;border:0;display:none">'."\n".
                   1465:                '<input type="text" name="customrights" size="60" value="" />'.
                   1466:                '<a href="javascript:openbrowser('."'$formname','customrights','rights'".');">'.
                   1467:                $lt{'sel'}.'</a></div><br />'."\n".
                   1468:                &mt('Source').' :'.
                   1469:                '<select name="sourceavail">'."\n".
                   1470:                '<option value="closed" selected="selected">'.$lt{'closed'}.'</option>'."\n".
                   1471:                '<option value="open">'.$lt{'open'}.'</option>'."\n".
                   1472:                '</select><br />'."\n".
                   1473:                '</fieldset></div>'."\n";
                   1474:     return $output;
                   1475: }
                   1476: 
1.717     raeburn  1477: sub crsres_fixup_meta {
                   1478:     my ($dest,$coursenum,$coursedom,$ca,$cd,$copyright,$customdistfile,$sourceavail,$checkdeps) = @_;
                   1479:     return unless (ref($checkdeps) eq 'HASH');
                   1480:     if (open(my $fh,'<',$dest.'.meta')) {
                   1481:         my ($output,$now,$setsourceavail);
                   1482:         $now = time;
                   1483:         if (($dest =~ /\.(xml|html|htm|xhtml|xhtm)$/i) || ($dest =~ /$LONCAPA::assess_re/)) {
                   1484:             $setsourceavail = 1;
                   1485:         }
                   1486:         while (my $line=<$fh>) {
                   1487:             chomp($line);
                   1488:             if ($line eq "<authorspace>$coursenum:$coursedom</authorspace>") {
                   1489:                 $output .= "<authorspace>$ca:$cd</authorspace>\n";
                   1490:             } elsif ($line eq '<copyright>custom</copyright>') {
                   1491:                 $output .= "<copyright>$copyright</copyright>\n";
                   1492:             } elsif ($line =~ m{^<creationdate>\d+</creationdate>$}) {
                   1493:                 $output .= "<creationdate>$now</creationdate>\n";
                   1494:             } elsif ($line eq "<customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>") {
                   1495:                 $output .= "<customdistributionfile>$customdistfile</customdistributionfile>\n";
                   1496:             } elsif ($line =~ m{^<sourceavail>(open|closed)</sourceavail>$}) {
                   1497:                 if ($setsourceavail) {
                   1498:                     $output .= "<sourceavail>$sourceavail</sourceavail>\n";
                   1499:                 }
                   1500:             } elsif ($line eq "<domain>$coursedom</domain>") {
                   1501:                 $output .= "<domain>$cd</domain>\n";
                   1502:             } elsif ($line =~ m{^<lastrevisiondate>\d+</lastrevisiondate>$}) {
                   1503:                 $output .= "<lastrevisiondate>$now</lastrevisiondate>\n";
                   1504:             } elsif ($line =~ m{^<modifyinguser>$match_username:$match_domain</modifyinguser>$}) {
                   1505:                 $output .= "<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>\n";
                   1506:             } elsif ($line eq "<owner>$coursenum:$coursedom</owner>") {
                   1507:                 $output .= "<owner>$ca:$cd</owner>\n";
                   1508:             } elsif ($line =~ m{^<dependencies>(.+)</dependencies>$}) {
                   1509:                 my @deps = split(/\s*,\s*/,$1);
                   1510:                 my @newdeps;
                   1511:                 my $changed = 0;
                   1512:                 foreach my $dep (@deps) {
                   1513:                     if ($dep =~ m{^/res/$coursedom/$coursenum/(.+)$}) {
                   1514:                         my $rest = $1;
                   1515:                         push(@newdeps,"/res/$cd/$ca/$rest");
                   1516:                         $checkdeps->{$rest} = 1;
                   1517:                         $changed ++;
                   1518:                     } else {
                   1519:                         push(@newdeps,$dep);
                   1520:                     }
                   1521:                 }
                   1522:                 if ($changed) {
                   1523:                     $output .= '<dependencies>'.join(',',@newdeps).'</dependencies>'."\n";
                   1524:                 }
                   1525:             } else {
                   1526:                 $output .= "$line\n";
                   1527:             }
                   1528:         }
                   1529:         close($fh);
                   1530:         if (open(my $fh,'>',$dest.'.meta')) {
                   1531:             print $fh $output;
                   1532:             close($fh);
                   1533:         }
                   1534:     }
                   1535: }
                   1536: 
                   1537: sub crsres_fixup {
                   1538:     my ($dest,$coursenum,$coursedom,$ca,$cd,$subdir) = @_;
                   1539:     my $outstring='';
                   1540:     my $changes = 0;
                   1541:     my @parser;
                   1542:     $parser[0]=HTML::LCParser->new($dest);
                   1543:     $parser[-1]->xml_mode(1);
                   1544:     my $token;
                   1545:     while (@parser) {
                   1546:         while ($token=$parser[-1]->get_token) {
                   1547:             if ($token->[0] eq 'S') {
                   1548:                 my $tag=$token->[1];
                   1549:                 my $lctag=lc($tag);
                   1550:                 my %parms=%{$token->[2]};
                   1551:                 foreach my $type ('src','href','background','bgimg') {
                   1552:                     foreach my $key (keys(%parms)) {
                   1553:                         if ($key =~ /^$type$/i) {
                   1554:                             next if (($lctag eq 'img') && ($type eq 'src') &&
                   1555:                                      ($parms{$key} =~ m{^data\:image/gif;base64,}));
                   1556:                             if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1557:                                 $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
                   1558:                                 $changes ++;
                   1559:                             }
                   1560:                         }
                   1561:                     }
                   1562:                 }
                   1563:                 # probably a <randomlabel> image type <label>
                   1564:                 # or a <image> tag inside <imageresponse> or <drawimage>
                   1565:                 if (($lctag eq 'label' && defined($parms{'description'}))
                   1566:                     || ($lctag eq 'image') || ($lctag eq 'import')) {
                   1567:                     my $next_token=$parser[-1]->get_token();
                   1568:                     if ($next_token->[0] eq 'T') {
                   1569:                         $next_token->[1] =~ s/[\n\r\f]+//g;
                   1570:                         if ($next_token->[1] =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1571:                             $next_token->[1] =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
                   1572:                             $changes ++;
                   1573:                         }
                   1574:                     }
                   1575:                     $parser[-1]->unget_token($next_token);
                   1576:                 }
                   1577:                 if ($lctag eq 'applet') {
                   1578:                     my $havecodebase=0;
                   1579:                     foreach my $key (keys(%parms)) {
                   1580:                         if (lc($key) eq 'codebase') {
                   1581:                             if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1582:                                 $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
                   1583:                                 $changes ++;
                   1584:                             }
                   1585:                             $havecodebase = 1;
                   1586:                         }
                   1587:                     }
                   1588:                     unless ($havecodebase) {
                   1589:                         foreach my $key (keys(%parms)) {
                   1590:                             if ($key =~ /(archive|code|object)/i) {
                   1591:                                 if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1592:                                     $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/si};
                   1593:                                     $changes ++;
                   1594:                                 }
                   1595:                             }
                   1596:                         }
                   1597:                     }
                   1598:                 }
                   1599:                 my $newparmstring='';
                   1600:                 my $endtag='';
                   1601:                 foreach my $parkey (keys(%parms)) {
                   1602:                     if ($parkey eq '/') {
                   1603:                         $endtag=' /';
                   1604:                     } else {
                   1605:                         my $quote=($parms{$parkey}=~/\"/?"'":'"');
                   1606:                         $newparmstring.=' '.$parkey.'='.$quote.$parms{$parkey}.$quote;
                   1607:                     }
                   1608:                 }
                   1609:                 if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
                   1610:                 $outstring.='<'.$tag.$newparmstring.$endtag.'>';
                   1611:                 if ($lctag eq 'm' || $lctag eq 'answer' || $lctag eq 'display' ||
                   1612:                     $lctag eq 'tex') {
                   1613:                     $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
                   1614:                 } elsif ($lctag eq 'script') {
                   1615:                     if ($parms{'type'} eq 'loncapa/perl') {
                   1616:                         $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
                   1617:                     } else {
                   1618:                         my $needsupdate;
                   1619:                         my $script = &Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
                   1620:                         if ($script =~ m{\.addMediaSrc\((["'])((?!\1).+)\1\);}) {
                   1621:                             my $src = $2;
                   1622:                             if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1623:                                 $needsupdate = 1;
                   1624:                             }
                   1625:                         }
                   1626:                         if ($script =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) {
                   1627:                             my $scriptslist = $2;
                   1628:                             my @srcs = split(/\s*,\s*/,$scriptslist);
                   1629:                             foreach my $src (@srcs) {
                   1630:                                 if ($src =~ /(["'])(?:(?!\1).)+\.js\1/) {
                   1631:                                     my $quote = $1;
                   1632:                                     my ($url) = ($src =~ m/\Q$quote\E([^$quote]+)\Q$quote\E/);
                   1633:                                     if ($url =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1634:                                         $needsupdate = 1;
                   1635:                                     }
                   1636:                                 }
                   1637:                             }
                   1638:                         }
                   1639:                         if ($script =~ m{loadScript\(\s*(['"])((?:(?!\1).)+\.js)\1,\s*function}is) {
                   1640:                             my $src = $2;
                   1641:                             if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1642:                                 $needsupdate = 1;
                   1643:                             }
                   1644:                         }
                   1645:                         if ($needsupdate) {
                   1646:                             $script =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/gsi};
                   1647:                             $changes ++;
                   1648:                         }
                   1649:                         $outstring .= $script;
                   1650:                     }
                   1651:                 }
                   1652:             } elsif ($token->[0] eq 'E') {
                   1653:                 if ($token->[2]) {
                   1654:                     unless ($token->[1] eq 'allow') {
                   1655:                         $outstring.='</'.$token->[1].'>';
                   1656:                     }
                   1657:                 }
                   1658:             } else {
                   1659:                 $outstring.=$token->[1];
                   1660:             }
                   1661:         }
                   1662:         pop(@parser);
                   1663:     }
                   1664:     if ($changes) {
                   1665:         if (open(my $fh,'>',$dest)) {
                   1666:             print $fh $outstring;
                   1667:             close($fh);
                   1668:         }
                   1669:     }
                   1670: }
                   1671: 
1.329     droeschl 1672: sub group_import {
1.598     raeburn  1673:     my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529     raeburn  1674:     my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
                   1675:         %removeparam,$importuploaded,$fixuperrors);
                   1676:     $allmaps = {};
1.329     droeschl 1677:     while (@files) {
                   1678: 	my ($name, $url, $residx) = @{ shift(@files) };
1.344     bisitz   1679:         if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329     droeschl 1680: 	     && ($caller eq 'londocs')
                   1681: 	     && (!&Apache::lonnet::stat_file($url))) {
1.364     bisitz   1682: 
1.329     droeschl 1683:             my $errtext = '';
                   1684:             my $fatal = 0;
                   1685:             my $newmapstr = '<map>'."\n".
                   1686:                             '<resource id="1" src="" type="start"></resource>'."\n".
                   1687:                             '<link from="1" to="2" index="1"></link>'."\n".
                   1688:                             '<resource id="2" src="" type="finish"></resource>'."\n".
                   1689:                             '</map>';
                   1690:             $env{'form.output'}=$newmapstr;
                   1691:             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                   1692:                                                 'output',$1.$2);
1.534     raeburn  1693:             if ($result !~ m{^/uploaded/}) {
1.329     droeschl 1694:                 $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
                   1695:                 $fatal = 2;
                   1696:             }
                   1697:             if ($fatal) {
                   1698:                 return ($errtext,$fatal);
                   1699:             }
                   1700:         }
                   1701: 	if ($url) {
1.626     raeburn  1702:             if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598     raeburn  1703:                 $url = $1;
                   1704:                 my $marker = $2;
                   1705:                 my $info = $3;
1.699     raeburn  1706:                 my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.727   ! raeburn  1707:                 my @extras = ('linktext','explanation','crslabel','crstitle','crsappend','returnurl','backtourl');
1.598     raeburn  1708:                 my @toolinfo = split(/:/,$info);
                   1709:                 if ($residx) {
1.604     raeburn  1710:                     %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598     raeburn  1711:                     $toolid = $toolsettings{'id'};
                   1712:                 } else {
1.604     raeburn  1713:                     $toolid = shift(@toolinfo);
1.598     raeburn  1714:                 }
1.699     raeburn  1715:                 if ($toolid =~ /^c/) {
                   1716:                     $tooltype = 'crs';
                   1717:                     $toolprefix = 'c';
                   1718:                 } else {
                   1719:                     $tooltype = 'dom';
                   1720:                 }
1.598     raeburn  1721:                 $toolid =~ s/\D//g;
1.604     raeburn  1722:                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645     raeburn  1723:                  $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
1.727   ! raeburn  1724:                  $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'},
        !          1725:                  $toolhash{'returnurl'},$toolhash{'backtourl'}) = @toolinfo;
1.624     raeburn  1726:                 foreach my $item (@extras) {
                   1727:                     $toolhash{$item} = &unescape($toolhash{$item});
                   1728:                 }
1.645     raeburn  1729:                 if ($folder =~ /^supplemental/) {
1.648     raeburn  1730:                     delete($toolhash{'gradable'});
                   1731:                 } else {
                   1732:                     $toolhash{'gradable'} =~ s/\D+//g;
1.645     raeburn  1733:                 }
1.598     raeburn  1734:                 if (ref($ltitoolsref) eq 'HASH') {
1.699     raeburn  1735:                     if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
                   1736:                         if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
                   1737:                             my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
                   1738:                             my @deleted;
                   1739:                             $toolhash{'id'} = $toolprefix.$toolid;
                   1740:                             if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
                   1741:                                 ($toolhash{'target'} eq 'window')) {
                   1742:                                 if ($toolhash{'target'} eq 'window') {
                   1743:                                     foreach my $item ('width','height') {
                   1744:                                         $toolhash{$item} =~ s/^\s+//;
                   1745:                                         $toolhash{$item} =~ s/\s+$//;
                   1746:                                         if ($toolhash{$item} =~ /\D/) {
                   1747:                                             delete($toolhash{$item});
                   1748:                                             if ($residx) {
                   1749:                                                 if ($toolsettings{$item}) {
                   1750:                                                     push(@deleted,$item);
                   1751:                                                 }
1.624     raeburn  1752:                                             }
                   1753:                                         }
                   1754:                                     }
1.604     raeburn  1755:                                 }
1.699     raeburn  1756:                             } elsif ($residx) {
                   1757:                                 $toolhash{'target'} = $toolsettings{'target'};
                   1758:                                 if ($toolhash{'target'} eq 'window') {
                   1759:                                     foreach my $item ('width','height') {
                   1760:                                         $toolhash{$item} = $toolsettings{$item};
                   1761:                                     }
                   1762:                                 }
                   1763:                             } elsif (ref($tools{'display'}) eq 'HASH') {
                   1764:                                 $toolhash{'target'} = $tools{'display'}{'target'};
                   1765:                                 if ($toolhash{'target'} eq 'window') {
                   1766:                                     $toolhash{'width'} = $tools{'display'}{'width'};
                   1767:                                     $toolhash{'height'} = $tools{'display'}{'height'};
1.624     raeburn  1768:                                 }
1.604     raeburn  1769:                             }
1.699     raeburn  1770:                             if ($toolhash{'target'} eq 'iframe') {
                   1771:                                 foreach my $item ('width','height','linktext','explanation') {
                   1772:                                     delete($toolhash{$item});
                   1773:                                     if ($residx) {
                   1774:                                         if ($toolsettings{$item}) {
                   1775:                                             push(@deleted,$item);
                   1776:                                         }
1.624     raeburn  1777:                                     }
1.604     raeburn  1778:                                 }
1.699     raeburn  1779:                             } elsif ($toolhash{'target'} eq 'tab') {
                   1780:                                 foreach my $item ('width','height') {
                   1781:                                     delete($toolhash{$item});
                   1782:                                     if ($residx) {
                   1783:                                         if ($toolsettings{$item}) {
                   1784:                                             push(@deleted,$item);
                   1785:                                         }
1.628     raeburn  1786:                                     }
                   1787:                                 }
                   1788:                             }
1.699     raeburn  1789:                             if (ref($tools{'crsconf'}) eq 'HASH') {
                   1790:                                 foreach my $item ('label','title','linktext','explanation') {
                   1791:                                     my $crsitem;
                   1792:                                     if (($item eq 'label') || ($item eq 'title')) {
                   1793:                                         $crsitem = 'crs'.$item;
                   1794:                                     } else {
                   1795:                                         $crsitem = $item;
                   1796:                                     }
                   1797:                                     if ($tools{'crsconf'}{$item}) {
                   1798:                                         $toolhash{$crsitem} =~ s/^\s+//;
                   1799:                                         $toolhash{$crsitem} =~ s/\s+$//;
                   1800:                                         if ($toolhash{$crsitem} eq '') {
                   1801:                                             delete($toolhash{$crsitem});
                   1802:                                         }
                   1803:                                     } else {
1.624     raeburn  1804:                                         delete($toolhash{$crsitem});
1.604     raeburn  1805:                                     }
1.699     raeburn  1806:                                     if (($residx) && (exists($toolsettings{$crsitem}))) {
                   1807:                                         unless (exists($toolhash{$crsitem})) {
                   1808:                                             push(@deleted,$crsitem);
                   1809:                                         }
                   1810:                                     }
1.604     raeburn  1811:                                 }
1.727   ! raeburn  1812:                                 if ($tools{'crsconf'}{'returnurl'}) {
        !          1813:                                     unless ($toolhash{'returnurl'} eq 'custom') {
        !          1814:                                         delete($toolhash{'backtourl'});
        !          1815:                                     }
        !          1816:                                 } else {
        !          1817:                                     delete($toolhash{'returnurl'});
        !          1818:                                     delete($toolhash{'backtourl'});
        !          1819:                                 }
1.699     raeburn  1820:                             }
                   1821:                             if ($toolhash{'passback'}) {
                   1822:                                 my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                   1823:                                 $toolhash{'gradesecret'} = $gradesecret;
                   1824:                                 $toolhash{'gradesecretdate'} = time;
                   1825:                             }
                   1826:                             if ($toolhash{'roster'}) {
                   1827:                                 my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                   1828:                                 $toolhash{'rostersecret'} = $rostersecret;
                   1829:                                 $toolhash{'rostersecretdate'} = time;
                   1830:                             }
                   1831:                             my $changegradable;
                   1832:                             if (($residx) && ($folder =~ /^default/)) {
                   1833:                                 if ($toolsettings{'gradable'}) {
                   1834:                                     unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
                   1835:                                         push(@deleted,'gradable');
                   1836:                                         $changegradable = 1;
1.604     raeburn  1837:                                     }
1.699     raeburn  1838:                                 } elsif ($toolhash{'gradable'}) {
                   1839:                                     $changegradable = 1;
1.604     raeburn  1840:                                 }
1.699     raeburn  1841:                                 if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645     raeburn  1842:                                     $changegradable = 1;
1.699     raeburn  1843:                                     if ($toolsettings{'gradable'}) {
                   1844:                                         $toolhash{'gradable'} = 1;
                   1845:                                     }
1.645     raeburn  1846:                                 }
1.648     raeburn  1847:                             }
1.727   ! raeburn  1848:                             if ($residx) {
        !          1849:                                 if (($toolsettings{'backtourl'} ne '') && (!exists($toolhash{'backtourl'}))) {
        !          1850:                                     push(@deleted,'backtourl');
        !          1851:                                 }
        !          1852:                                 if (($toolsettings{'returnurl'} ne '') && (!exists($toolhash{'returnurl'}))) {
        !          1853:                                     push(@deleted,'returnurl');
        !          1854:                                 }
        !          1855:                             }
1.699     raeburn  1856:                             my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
                   1857:                             if ($putres eq 'ok') {
                   1858:                                 if (@deleted) {
                   1859:                                     &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648     raeburn  1860:                                 }
1.699     raeburn  1861:                                 if (($changegradable) && ($folder =~ /^default/)) {
                   1862:                                     my $val;
                   1863:                                     if ($toolhash{'gradable'}) {
                   1864:                                         $val = 'yes';
                   1865:                                     } else {
                   1866:                                         $val = 'no';
                   1867:                                     }
                   1868:                                     &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
                   1869:                                                                   'string_yesno');
                   1870:                                     &remember_parms($residx,'gradable','set',$val);
1.645     raeburn  1871:                                 }
1.699     raeburn  1872:                             } else {
                   1873:                                 return (&mt('Failed to save update to external tool.'),1);
1.645     raeburn  1874:                             }
1.604     raeburn  1875:                         }
1.598     raeburn  1876:                     }
                   1877:                 }
                   1878:             }
1.529     raeburn  1879:             if (($caller eq 'londocs') &&
                   1880:                 ($folder =~ /^default/)) {
1.534     raeburn  1881:                 if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529     raeburn  1882:                     my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
                   1883:                     my $cid = $coursedom.'_'.$coursenum;
                   1884:                     $allmaps =
                   1885:                         &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                   1886:                                                              $chome,$cid);
                   1887:                     $donechk = 1;
                   1888:                 }
                   1889:                 if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627     raeburn  1890:                     &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
                   1891:                                         \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529     raeburn  1892:                     $importuploaded = 1;
                   1893:                 } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
                   1894:                     next if ($allmaps->{$url});
                   1895:                 }
                   1896:             }
1.344     bisitz   1897: 	    if (!$residx
1.329     droeschl 1898: 		|| defined($LONCAPA::map::zombies[$residx])) {
                   1899: 		$residx = &LONCAPA::map::getresidx($url,$residx);
                   1900: 		push(@LONCAPA::map::order, $residx);
                   1901: 	    }
                   1902: 	    my $ext = 'false';
                   1903: 	    if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534     raeburn  1904:             if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
                   1905:                 my $filepath = $1;
1.675     raeburn  1906:                 my $fname;
                   1907:                 if ($name eq '') {
                   1908:                     $name = &mt('Web Page');
1.534     raeburn  1909:                     $fname = 'web';
                   1910:                 } else {
1.675     raeburn  1911:                     $fname = $name;
                   1912:                     $fname=&Apache::lonnet::clean_filename($fname);
                   1913:                     if ($fname eq '') {
                   1914:                         $fname = 'web';
                   1915:                     } elsif (length($fname) > 15) {
                   1916:                         $fname = substr($fname,0,14);
                   1917:                     }
1.534     raeburn  1918:                 }
1.675     raeburn  1919:                 my $title = &Apache::loncommon::cleanup_html($name);
1.534     raeburn  1920:                 my $initialtext = &mt('Replace with your own content.');
                   1921:                 my $newhtml = <<END;
1.545     raeburn  1922: <html>
1.534     raeburn  1923: <head>
1.675     raeburn  1924: <title>$title</title>
1.534     raeburn  1925: </head>
                   1926: <body bgcolor="#ffffff">
                   1927: $initialtext
                   1928: </body>
                   1929: </html>
                   1930: END
                   1931:                 $env{'form.output'}=$newhtml;
1.630     raeburn  1932:                 my $result =
1.534     raeburn  1933:                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                   1934:                                                           'output',
                   1935:                                                           "$filepath/$residx/$fname.html");
                   1936:                 if ($result =~ m{^/uploaded/}) {
                   1937:                     $url = $result;
                   1938:                     if ($filepath =~ /^supplemental/) {
                   1939:                         $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   1940:                                 $env{'user.domain'}.'___&&&___'.$name;
                   1941:                     }
                   1942:                 } else {
                   1943:                     return (&mt('Failed to save new web page.'),1);
                   1944:                 }
                   1945:             }
1.675     raeburn  1946:             $name = &LONCAPA::map::qtunescape($name);
1.538     raeburn  1947:             $url  = &LONCAPA::map::qtunescape($url);
1.344     bisitz   1948: 	    $LONCAPA::map::resources[$residx] =
1.329     droeschl 1949: 		join(':', ($name, $url, $ext, 'normal', 'res'));
                   1950: 	}
                   1951:     }
1.529     raeburn  1952:     if ($importuploaded) {
                   1953:         my %import_errors;
                   1954:         my %updated = (
                   1955:                           removefrommap => \%removefrommap,
                   1956:                           removeparam   => \%removeparam,
                   1957:                       );
1.533     raeburn  1958:         my ($result,$msgsarray,$lockerror) = 
                   1959:             &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529     raeburn  1960:         if (keys(%import_errors) > 0) {
1.530     raeburn  1961:             $fixuperrors =
1.529     raeburn  1962:                 '<p span class="LC_warning">'."\n".
                   1963:                 &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
                   1964:                 '<ul>'."\n";
                   1965:             foreach my $key (sort(keys(%import_errors))) {
                   1966:                 $fixuperrors .= '<li>'.$key.'</li>'."\n";
                   1967:             }
                   1968:             $fixuperrors .= '</ul></p>'."\n";
                   1969:         }
1.533     raeburn  1970:         if (ref($msgsarray) eq 'ARRAY') {
                   1971:             if (@{$msgsarray} > 0) {
                   1972:                 $fixuperrors .= '<p class="LC_info">'.
                   1973:                                 join('<br />',@{$msgsarray}).
                   1974:                                 '</p>';
                   1975:             }
                   1976:         }
                   1977:         if ($lockerror) {
                   1978:             $fixuperrors .= '<p class="LC_error">'.
                   1979:                             $lockerror.
                   1980:                             '</p>';
                   1981:         }
1.529     raeburn  1982:     }
                   1983:     my ($errtext,$fatal) =
                   1984:         &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557     raeburn  1985:     unless ($fatal) {
                   1986:         if ($folder =~ /^supplemental/) {
1.561     raeburn  1987:             my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   1988:                                             $folder.'.'.$container);
1.557     raeburn  1989:         }
                   1990:     }
1.529     raeburn  1991:     return ($errtext,$fatal,$fixuperrors);
1.329     droeschl 1992: }
                   1993: 
                   1994: sub log_docs {
1.494     raeburn  1995:     return &Apache::lonnet::write_log('course','docslog',@_);
1.329     droeschl 1996: }
                   1997: 
                   1998: {
                   1999:     my @oldresources=();
                   2000:     my @oldorder=();
                   2001:     my $parmidx;
                   2002:     my %parmaction=();
                   2003:     my %parmvalue=();
                   2004:     my $changedflag;
                   2005: 
                   2006:     sub snapshotbefore {
                   2007:         @oldresources=@LONCAPA::map::resources;
                   2008:         @oldorder=@LONCAPA::map::order;
                   2009:         $parmidx=undef;
                   2010:         %parmaction=();
                   2011:         %parmvalue=();
                   2012:         $changedflag=0;
                   2013:     }
                   2014: 
                   2015:     sub remember_parms {
                   2016:         my ($idx,$parameter,$action,$value)=@_;
                   2017:         $parmidx=$idx;
                   2018:         $parmaction{$parameter}=$action;
                   2019:         $parmvalue{$parameter}=$value;
                   2020:         $changedflag=1;
                   2021:     }
                   2022: 
                   2023:     sub log_differences {
                   2024:         my ($plain)=@_;
                   2025:         my %storehash=('folder' => $plain,
                   2026:                        'currentfolder' => $env{'form.folder'});
                   2027:         if ($parmidx) {
                   2028:            $storehash{'parameter_res'}=$oldresources[$parmidx];
                   2029:            foreach my $parm (keys(%parmaction)) {
                   2030:               $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
                   2031:               $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
                   2032:            }
                   2033:         }
                   2034:         my $maxidx=$#oldresources;
                   2035:         if ($#LONCAPA::map::resources>$#oldresources) {
                   2036:            $maxidx=$#LONCAPA::map::resources;
                   2037:         }
                   2038:         for (my $idx=0; $idx<=$maxidx; $idx++) {
                   2039:            if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
                   2040:               $storehash{'before_resources_'.$idx}=$oldresources[$idx];
                   2041:               $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
                   2042:               $changedflag=1;
                   2043:            }
                   2044:            if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
                   2045:               $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
                   2046:               $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                   2047:               $changedflag=1;
                   2048:            }
                   2049:         }
                   2050: 	$storehash{'maxidx'}=$maxidx;
                   2051:         if ($changedflag) { &log_docs(\%storehash); }
                   2052:     }
                   2053: }
                   2054: 
                   2055: sub docs_change_log {
1.611     raeburn  2056:     my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486     raeburn  2057:     my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617     raeburn  2058:     my $navmap; 
1.483     raeburn  2059:     my $js = '<script type="text/javascript">'."\n".
                   2060:              '// <![CDATA['."\n".
                   2061:              &Apache::loncommon::display_filter_js('docslog')."\n".
1.606     raeburn  2062:              &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622     raeburn  2063:                          $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483     raeburn  2064:              &history_tab_js()."\n".
1.484     raeburn  2065:              &Apache::lonratedt::editscript('simple')."\n".
1.483     raeburn  2066:              '// ]]>'."\n".
                   2067:              '</script>'."\n";
1.484     raeburn  2068:     $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
                   2069:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489     raeburn  2070:     $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484     raeburn  2071:     my %orderhash;
                   2072:     my $container='sequence';
                   2073:     my $pathitem;
1.519     raeburn  2074:     if ($env{'form.folderpath'} =~ /\:1$/) {
1.484     raeburn  2075:         $container='page';
                   2076:     }
1.519     raeburn  2077:     my $folderpath=$env{'form.folderpath'};
                   2078:     if ($folderpath eq '') {
1.617     raeburn  2079:         $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519     raeburn  2080:     }
1.617     raeburn  2081:     undef($navmap);
1.519     raeburn  2082:     $pathitem = '<input type="hidden" name="folderpath" value="'.
                   2083:                 &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484     raeburn  2084:     my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
                   2085:     my $jumpto = $readfile;
                   2086:     $jumpto =~ s{^/}{};
                   2087:     my $tid = 1;
1.489     raeburn  2088:     if ($supplementalflag) {
                   2089:         $tid = 2;
                   2090:     }
1.630     raeburn  2091:     my ($breadcrumbtrail) =
1.509     raeburn  2092:         &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484     raeburn  2093:     $r->print($breadcrumbtrail.
                   2094:               &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
                   2095:               $readfile));
1.329     droeschl 2096:     my %docslog=&Apache::lonnet::dump('nohist_docslog',
                   2097:                                       $env{'course.'.$env{'request.course.id'}.'.domain'},
                   2098:                                       $env{'course.'.$env{'request.course.id'}.'.num'});
                   2099: 
                   2100:     if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
                   2101: 
                   2102:     my %saveable_parameters = ('show' => 'scalar',);
                   2103:     &Apache::loncommon::store_course_settings('docs_log',
                   2104:                                               \%saveable_parameters);
                   2105:     &Apache::loncommon::restore_course_settings('docs_log',
                   2106:                                                 \%saveable_parameters);
                   2107:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452     www      2108: # FIXME: internationalization seems wrong here
1.329     droeschl 2109:     my %lt=('hiddenresource' => 'Resources hidden',
                   2110: 	    'encrypturl'     => 'URL hidden',
                   2111: 	    'randompick'     => 'Randomly pick',
                   2112: 	    'randomorder'    => 'Randomly ordered',
1.645     raeburn  2113:             'gradable'       => 'Grade can be assigned to External Tool',
1.329     droeschl 2114: 	    'set'            => 'set to',
                   2115: 	    'del'            => 'deleted');
1.484     raeburn  2116:     my $filter = &Apache::loncommon::display_filter('docslog')."\n".
                   2117:                  $pathitem."\n".
                   2118:                  '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
                   2119:                  ('&nbsp;'x2).'<input type="submit" value="'.&mt('Display').'" />';
                   2120:     $r->print('<div class="LC_left_float">'.
                   2121:               '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
                   2122:               &makedocslogform($filter,1).
                   2123:               '</fieldset></div><br clear="all" />');
1.329     droeschl 2124:     $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
                   2125:               '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
                   2126:               &mt('After').'</th>'.
                   2127:               &Apache::loncommon::end_data_table_header_row());
                   2128:     my $shown=0;
                   2129:     foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
                   2130: 	if ($env{'form.displayfilter'} eq 'currentfolder') {
                   2131: 	    if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
                   2132: 	}
                   2133:         my @changes=keys(%{$docslog{$id}{'logentry'}});
                   2134:         if ($env{'form.displayfilter'} eq 'containing') {
                   2135: 	    my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
                   2136: 		&Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
                   2137: 	    foreach my $key (@changes) {
                   2138: 		$wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
                   2139: 	    }
1.344     bisitz   2140: 	    if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329     droeschl 2141: 	}
                   2142:         my $count = 0;
                   2143:         my $time =
                   2144:             &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
                   2145:         my $plainname =
                   2146:             &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
                   2147:                                           $docslog{$id}{'exe_udom'});
                   2148:         my $about_me_link =
                   2149:             &Apache::loncommon::aboutmewrapper($plainname,
                   2150:                                                $docslog{$id}{'exe_uname'},
                   2151:                                                $docslog{$id}{'exe_udom'});
                   2152:         my $send_msg_link='';
                   2153:         if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
                   2154:              || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
                   2155:             $send_msg_link ='<br />'.
                   2156:                 &Apache::loncommon::messagewrapper(&mt('Send message'),
                   2157:                                                    $docslog{$id}{'exe_uname'},
                   2158:                                                    $docslog{$id}{'exe_udom'});
                   2159:         }
                   2160:         $r->print(&Apache::loncommon::start_data_table_row());
                   2161:         $r->print('<td>'.$time.'</td>
                   2162:                        <td>'.$about_me_link.
                   2163:                   '<br /><tt>'.$docslog{$id}{'exe_uname'}.
                   2164:                                   ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
                   2165:                   $send_msg_link.'</td><td>'.
                   2166:                   $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488     raeburn  2167:         my $is_supp = 0; 
                   2168:         if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
                   2169:             $is_supp = 1;
                   2170:         }
1.329     droeschl 2171: # Before
                   2172: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   2173: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                   2174: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                   2175: 	    if ($oldname ne $newname) {
1.488     raeburn  2176:                 my $shown = &LONCAPA::map::qtescape($oldname);
                   2177:                 if ($is_supp) {
                   2178:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   2179:                 }
                   2180:                 $r->print($shown);
1.329     droeschl 2181: 	    }
                   2182: 	}
                   2183: 	$r->print('<ul>');
                   2184: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   2185:             if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488     raeburn  2186:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
                   2187:                 if ($is_supp) {
                   2188:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   2189:                 }
                   2190: 		$r->print('<li>'.$shown.'</li>');
1.329     droeschl 2191: 	    }
                   2192: 	}
                   2193: 	$r->print('</ul>');
                   2194: # After
                   2195:         $r->print('</td><td>');
                   2196: 
                   2197: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   2198: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                   2199: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                   2200: 	    if ($oldname ne '' && $oldname ne $newname) {
1.488     raeburn  2201:                 my $shown = &LONCAPA::map::qtescape($newname);
                   2202:                 if ($is_supp) {
                   2203:                     $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
                   2204:                 }
                   2205:                 $r->print($shown);
1.329     droeschl 2206: 	    }
1.364     bisitz   2207: 	}
1.329     droeschl 2208: 	$r->print('<ul>');
                   2209: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   2210:             if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488     raeburn  2211:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
                   2212:                 if ($is_supp) {
                   2213:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   2214:                 }
                   2215:                 $r->print('<li>'.$shown.'</li>');
1.329     droeschl 2216: 	    }
                   2217: 	}
                   2218: 	$r->print('</ul>');
                   2219: 	if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693     raeburn  2220:             my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
                   2221:             if ($title eq '') {
                   2222:                 ($title) = ($url =~ m{/([^/]+)$});
1.695     raeburn  2223:             } elsif ($is_supp) {
                   2224:                 $title = &Apache::loncommon::parse_supplemental_title($title);
1.693     raeburn  2225:             }
                   2226:             $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645     raeburn  2227: 	    foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329     droeschl 2228: 		if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452     www      2229: # FIXME: internationalization seems wrong here
1.329     droeschl 2230: 		    $r->print('<li>'.
                   2231: 			      &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
                   2232: 				  $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
                   2233: 			      .'</li>');
                   2234: 		}
                   2235: 	    }
                   2236: 	    $r->print('</ul>');
                   2237: 	}
                   2238: # End
                   2239:         $r->print('</td>'.&Apache::loncommon::end_data_table_row());
                   2240:         $shown++;
                   2241:         if (!($env{'form.show'} eq &mt('all')
                   2242:               || $shown<=$env{'form.show'})) { last; }
                   2243:     }
1.484     raeburn  2244:     $r->print(&Apache::loncommon::end_data_table()."\n".
                   2245:               &makesimpleeditform($pathitem)."\n".
                   2246:               '</div></div>');
                   2247:     $r->print(&endContentScreen());
1.329     droeschl 2248: }
                   2249: 
                   2250: sub update_paste_buffer {
1.492     raeburn  2251:     my ($coursenum,$coursedom,$folder) = @_;
1.591     raeburn  2252:     my (@possibles,%removals,%cuts,$output);
1.538     raeburn  2253:     if ($env{'form.multiremove'}) {
                   2254:         $env{'form.multiremove'} =~ s/,$//;
                   2255:         map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
                   2256:     }
                   2257:     if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
                   2258:         if ($env{'form.multicut'}) {
                   2259:             $env{'form.multicut'} =~ s/,$//;
                   2260:             foreach my $item (split(/,/,$env{'form.multicut'})) {
                   2261:                 unless ($removals{$item}) {
                   2262:                     $cuts{$item} = 1;
                   2263:                     push(@possibles,$item.':cut');
                   2264:                 }
                   2265:             }
                   2266:         }
                   2267:         if ($env{'form.multicopy'}) {
                   2268:             $env{'form.multicopy'} =~ s/,$//;
                   2269:             foreach my $item (split(/,/,$env{'form.multicopy'})) {
                   2270:                 unless ($removals{$item} || $cuts{$item}) {
                   2271:                     push(@possibles,$item.':copy'); 
                   2272:                 }
                   2273:             }
                   2274:         }
                   2275:     } elsif ($env{'form.markcopy'}) {
                   2276:         @possibles = split(/,/,$env{'form.markcopy'});
                   2277:     }
1.329     droeschl 2278: 
1.538     raeburn  2279:     return if (@possibles == 0);
1.329     droeschl 2280:     return if (!defined($env{'form.copyfolder'}));
                   2281: 
                   2282:     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   2283: 				    $env{'form.copyfolder'});
1.538     raeburn  2284:     return if ($fatal);
                   2285: 
                   2286:     my %curr_groups = &Apache::longroup::coursegroups();
1.364     bisitz   2287: 
1.538     raeburn  2288: # Retrieve current paste buffer suffixes.
                   2289:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   2290:     my (%pasteurls,@newpaste);
                   2291: 
                   2292: # Construct identifiers for current contents of user's paste buffer
                   2293:     if (@currpaste) {
                   2294:         foreach my $suffix (@currpaste) {
1.667     raeburn  2295:             my $cid = $env{'docs.markedcopy_crs_'.$suffix};
                   2296:             my $url = $env{'docs.markedcopy_url_'.$suffix};
                   2297:             my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
                   2298:             if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
                   2299:                 ($url ne '')) {
                   2300:                 if ($url eq '/res/lib/templates/simpleproblem.problem') {
                   2301:                     $pasteurls{$cid.'_'.$mapidx} = 1;
                   2302:                 } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
                   2303:                     $pasteurls{$url} = 1;
                   2304:                 } else {
1.669     raeburn  2305:                     $pasteurls{$cid.'_'.$url} = 1;
1.667     raeburn  2306:                 }
                   2307:             }
1.538     raeburn  2308:         }
                   2309:     }
                   2310: 
                   2311: # Mark items for copying (skip any items already in user's paste buffer)
                   2312:     my %addtoenv;
1.597     raeburn  2313: 
                   2314:     my @pathitems = split(/\&/,$env{'form.folderpath'});
                   2315:     my @folderconf = split(/\:/,$pathitems[-1]);
1.666     raeburn  2316:     my $ispage = $folderconf[5];
1.597     raeburn  2317: 
1.538     raeburn  2318:     foreach my $item (@possibles) {
                   2319:         my ($orderidx,$cmd) = split(/:/,$item);
                   2320:         next if ($orderidx =~ /\D/);
                   2321:         next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597     raeburn  2322:         my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538     raeburn  2323:         my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
                   2324:         my %denied = &action_restrictions($coursenum,$coursedom,
                   2325:                                           &LONCAPA::map::qtescape($url),
                   2326:                                           $env{'form.folderpath'},\%curr_groups);
                   2327:         next if ($denied{'copy'});
                   2328:         $url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.667     raeburn  2329:         if ($url eq '/res/lib/templates/simpleproblem.problem') {
                   2330:             next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
                   2331:         } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
                   2332:             next if (exists($pasteurls{$url}));
                   2333:         } else {
                   2334:             next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
                   2335:         }
1.538     raeburn  2336:         my ($suffix,$errortxt,$locknotfreed) =
                   2337:             &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591     raeburn  2338:         if ($suffix ne '') {
                   2339:             push(@newpaste,$suffix);
                   2340:         } else {
                   2341:             if ($locknotfreed) {
                   2342:                 return $locknotfreed;
                   2343:             }
1.538     raeburn  2344:         }
                   2345:         if (&is_supplemental_title($title)) {
                   2346:             &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
                   2347: 	    ($title) = &Apache::loncommon::parse_supplemental_title($title);
                   2348:         }
1.329     droeschl 2349: 
1.538     raeburn  2350:         $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
                   2351:         $addtoenv{'docs.markedcopy_url_'.$suffix}   = $url,
                   2352:         $addtoenv{'docs.markedcopy_cmd_'.$suffix}   = $cmd,
                   2353:         $addtoenv{'docs.markedcopy_crs_'.$suffix}   = $env{'request.course.id'};
1.597     raeburn  2354:         $addtoenv{'docs.markedcopy_map_'.$suffix}   = $mapidx;
1.538     raeburn  2355:         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
                   2356:             my $prefix = $1;
                   2357:             my $subdir =$2;
                   2358:             if ($subdir eq '') {
                   2359:                 $subdir = $prefix;
1.492     raeburn  2360:             }
1.538     raeburn  2361:             my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627     raeburn  2362:             &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
                   2363:                                  \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538     raeburn  2364:             if (ref($hierarchy{$url}) eq 'HASH') {
                   2365:                 my ($nested,$nestednames);
                   2366:                 &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
                   2367:                 $nested =~ s/\&$//;
                   2368:                 $nestednames =~ s/\Q___&&&___\E$//;
                   2369:                 if ($nested ne '') {
                   2370:                     $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
                   2371:                 }
                   2372:                 if ($nestednames ne '') {
                   2373:                     $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
                   2374:                 }
1.492     raeburn  2375:             }
                   2376:         }
1.591     raeburn  2377:         if ($locknotfreed) {
                   2378:             $output = $locknotfreed;
                   2379:             last;
                   2380:         }
1.492     raeburn  2381:     }
1.538     raeburn  2382:     if (@newpaste) {
                   2383:         $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
                   2384:     }
1.492     raeburn  2385:     &Apache::lonnet::appenv(\%addtoenv);
1.329     droeschl 2386:     delete($env{'form.markcopy'});
1.591     raeburn  2387:     return $output;
1.329     droeschl 2388: }
                   2389: 
1.492     raeburn  2390: sub recurse_uploaded_maps {
                   2391:     my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
                   2392:     if (ref($hierarchy->{$url}) eq 'HASH') {
                   2393:         my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
                   2394:         my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
                   2395:         my (@uploaded,@names,%shorter);
                   2396:         for (my $i=0; $i<@maps; $i++) {
                   2397:             my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
                   2398:             if ($inner ne '') {
                   2399:                 push(@uploaded,$inner);
                   2400:                 push(@names,&escape($titles[$i]));
                   2401:                 $shorter{$maps[$i]} = $inner;
                   2402:             }
                   2403:         }
                   2404:         $$nestref .= "$dir:".join(',',@uploaded).'&';
                   2405:         $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
                   2406:         foreach my $map (@maps) {
                   2407:             if ($shorter{$map} ne '') {
                   2408:                 &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
                   2409:             }
                   2410:         }
                   2411:     }
                   2412:     return;
                   2413: }
                   2414: 
1.329     droeschl 2415: sub print_paste_buffer {
1.492     raeburn  2416:     my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538     raeburn  2417:     return if (!defined($env{'docs.markedcopies'}));
1.329     droeschl 2418: 
1.538     raeburn  2419:     unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
                   2420:         return if ($env{'docs.markedcopies'} eq '');
1.488     raeburn  2421:     }
                   2422: 
1.538     raeburn  2423:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.704     raeburn  2424:     my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.575     raeburn  2425:     my $clipboardcount = 0;
1.488     raeburn  2426: 
1.538     raeburn  2427: # Construct identifiers for current contents of user's paste buffer
                   2428:     foreach my $suffix (@currpaste) {
                   2429:         next if ($suffix =~ /\D/);
                   2430:         my $cid = $env{'docs.markedcopy_crs_'.$suffix};
                   2431:         my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597     raeburn  2432:         my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538     raeburn  2433:         if (($cid =~ /^$match_domain\_$match_courseid$/) &&
                   2434:             ($url ne '')) {
1.575     raeburn  2435:             $clipboardcount ++;
1.538     raeburn  2436:             my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.704     raeburn  2437:                 $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
                   2438:                 $toolcnum,$marker);
1.538     raeburn  2439:             my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
                   2440:             if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
                   2441:                 $is_external = 1;
1.704     raeburn  2442:             } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                   2443:                 ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598     raeburn  2444:                 $is_exttool = 1;
1.538     raeburn  2445:             }
                   2446:             if ($folder =~ /^supplemental/) {
                   2447:                 $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
                   2448:                 unless ($canpaste) {
                   2449:                     $nopaste = &mt('Paste into Supplemental Content unavailable.');
                   2450:                 }
                   2451:             } else {
                   2452:                 $canpaste = 1;
                   2453:             }
                   2454:             if ($canpaste) {
                   2455:                 if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
                   2456:                     my $srcdom = $1;
                   2457:                     my $srcnum = $2;
                   2458:                     my $rem = $3;
                   2459:                     if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
                   2460:                         $othercourse = 1;
                   2461:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596     raeburn  2462:                             $othercrs = '<br />'.&mt('(from another course)');
1.538     raeburn  2463:                         } else {
                   2464:                             $canpaste = 0;
                   2465:                             $nopaste = &mt('Paste from another course unavailable.'); 
                   2466:                         }
                   2467:                     }
                   2468:                     if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
                   2469:                         my $prefix = $1;
                   2470:                         $parent = $2;
                   2471:                         if ($folder !~ /^\Q$prefix\E/) {
                   2472:                             $areachange = 1;
                   2473:                         }
                   2474:                         $is_uploaded_map = 1;
1.492     raeburn  2475:                     }
1.597     raeburn  2476:                 } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627     raeburn  2477:                          ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596     raeburn  2478:                     if ($cid ne $env{'request.course.id'}) {
                   2479:                         my ($srcdom,$srcnum) = split(/_/,$cid);
                   2480:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704     raeburn  2481:                             if ($is_exttool) {
                   2482:                                 if ($toolcdom ne $coursedom) {
                   2483:                                     $canpaste = 0;
                   2484:                                     $nopaste = &mt('Paste from another domain unavailable.');
                   2485:                                 } elsif ($toolcnum ne $coursenum) {
                   2486:                                     my %toolsettings =
                   2487:                                         &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
                   2488:                                     my %tooltypes = &Apache::loncommon::usable_exttools();
                   2489:                                     if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                   2490:                                         (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                   2491:                                         $canpaste = 0;
                   2492:                                         $nopaste = &mt('Paste from another course unavailable.');
                   2493:                                     } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
                   2494:                                         unless ($checkedsameinst) {
                   2495:                                             my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
                   2496:                                             my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   2497:                                             if ($intdom ne '') {
                   2498:                                                 my $internet_names =
                   2499:                                                     &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   2500:                                                 if (ref($internet_names) eq 'ARRAY') {
                   2501:                                                     if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   2502:                                                         $same_institution = 1;
                   2503:                                                     }
                   2504:                                                 }
                   2505:                                             }
                   2506:                                             $checkedsameinst = 1;
                   2507:                                         }
                   2508:                                         if ($same_institution) {
                   2509:                                             $othercrs = '<br />'.&mt('(from another course)');
                   2510:                                         } else {
                   2511:                                             $nopaste = &mt('Paste from another course unavailable.');
                   2512:                                         }
                   2513:                                     } else {
                   2514:                                         $othercrs = '<br />'.&mt('(from another course)');
                   2515:                                     }
                   2516:                                 }
1.627     raeburn  2517:                             }
1.596     raeburn  2518:                         } else {
                   2519:                             $canpaste = 0;
                   2520:                             $nopaste = &mt('Paste from another course unavailable.');
1.629     raeburn  2521:                         }
1.596     raeburn  2522:                     }
1.703     raeburn  2523:                 } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
                   2524:                     my ($audom,$auname) = ($1,$2);
                   2525:                     unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
                   2526:                         if (&Apache::lonnet::is_course($audom,$auname)) {
                   2527:                             $canpaste = 0;
                   2528:                             $nopaste = &mt('Paste from another course unavailable.');
                   2529:                         }
                   2530:                     }
1.492     raeburn  2531:                 }
1.596     raeburn  2532:                 if ($canpaste) {
                   2533:                     push(@pasteable,$suffix);
1.629     raeburn  2534:                 }
1.538     raeburn  2535:             }
                   2536:             my $buffer;
1.627     raeburn  2537:             if ($is_external) {
1.538     raeburn  2538:                 $buffer = &mt('External Resource').': '.
                   2539:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
                   2540:                     &LONCAPA::map::qtescape($url).')';
1.627     raeburn  2541:             } elsif ($is_exttool) {
                   2542:                 $buffer = &mt('External Tool').': '.
                   2543:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538     raeburn  2544:             } else {
                   2545:                 my $icon = &Apache::loncommon::icon($extension);
1.723     raeburn  2546:                 my $icontext;
                   2547:                 if ($extension eq 'sequence') {
                   2548:                     $icontext = &mt('folder icon');
                   2549:                 } elsif ($extension eq 'page') {
                   2550:                     $icontext = &mt('composite page icon');
                   2551:                 } else {
                   2552:                     $icontext = &mt('file icon');
                   2553:                 }
                   2554:                 $icontext = &HTML::Entities::encode($icontext);
1.538     raeburn  2555:                 if ($extension eq 'sequence' &&
                   2556:                     $url =~ m{/default_\d+\.sequence$}x) {
                   2557:                     $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
                   2558:                     $icon .= '/navmap.folder.closed.gif';
                   2559:                 }
1.589     raeburn  2560:                 my $title = $env{'docs.markedcopy_title_'.$suffix};
                   2561:                 if ($title eq '') {
                   2562:                     ($title) = ($url =~ m{/([^/]+)$});
                   2563:                 }
1.723     raeburn  2564:                 $buffer = '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />'.
1.538     raeburn  2565:                           ': '.
                   2566:                           &Apache::loncommon::parse_supplemental_title(
1.589     raeburn  2567:                              &LONCAPA::map::qtescape($title));
1.538     raeburn  2568:             }
                   2569:             $pasteitems .= '<div class="LC_left_float">';
                   2570:             my ($options,$onclick);
                   2571:             if (($canpaste) && (!$areachange) && (!$othercourse) &&
                   2572:                 ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
                   2573:                 if (($is_uploaded_map) ||
                   2574:                     ($url =~ /(bulletinboard|smppg)$/) ||
                   2575:                     ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
                   2576:                     $options = &paste_options($suffix,$is_uploaded_map,$parent);
                   2577:                     $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
                   2578:                 }
                   2579:             }
                   2580:             $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
                   2581:             if ($nopaste) {
1.681     raeburn  2582:                  $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';   
1.538     raeburn  2583:             } else {
                   2584:                 if ($othercrs) {
                   2585:                     $pasteitems .= $othercrs;
                   2586:                 }
                   2587:                 if ($options) {
                   2588:                     $pasteitems .= $options;
1.492     raeburn  2589:                 }
                   2590:             }
1.538     raeburn  2591:             $pasteitems .= '</div>';
                   2592:         }
                   2593:     }
                   2594:     if ($pasteitems eq '') {
                   2595:         &Apache::lonnet::delenv('docs.markedcopies');
                   2596:     }
                   2597:     my ($pasteform,$form_start,$buttons,$form_end);
                   2598:     if ($pasteitems) {
                   2599:         $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541     raeburn  2600:         $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538     raeburn  2601:         if (@pasteable) {
1.575     raeburn  2602:             my $value = &mt('Paste to current folder');
                   2603:             if ($container eq 'page') {
                   2604:                 $value = &mt('Paste to current page');
                   2605:             } 
                   2606:             $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.('&nbsp;'x2);
                   2607:         }
                   2608:         $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.('&nbsp;'x2);
                   2609:         if ($clipboardcount > 1) {
                   2610:             $buttons .=
                   2611:                 '<span style="text-decoration:line-through">'.('&nbsp;'x20).'</span>'.('&nbsp;'x2).
                   2612:                 '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
                   2613:                 ('&nbsp;'x2).
                   2614:                 '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
                   2615:                 ('&nbsp;'x2);
1.492     raeburn  2616:         }
1.575     raeburn  2617:         $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
                   2618:                     '</form>';
1.538     raeburn  2619:     } else {
                   2620:         $pasteitems = &mt('Clipboard is empty');
1.488     raeburn  2621:     }
1.538     raeburn  2622:     $r->print($form_start
                   2623:              .'<fieldset>'
                   2624:              .'<legend>'.&mt('Clipboard').('&nbsp;' x2).$buttons.'</legend>'
                   2625:              .$pasteitems
                   2626:              .'</fieldset>'
                   2627:              .$form_end);
                   2628: }
                   2629: 
                   2630: sub paste_options {
                   2631:     my ($suffix,$is_uploaded_map,$parent) = @_;
                   2632:     my ($copytext,$movetext);
                   2633:     if ($is_uploaded_map) {
                   2634:         $copytext = &mt('Copy to new folder');
                   2635:         $movetext = &mt('Move old');
                   2636:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
                   2637:         $copytext = &mt('Copy to new board');
                   2638:         $movetext = &mt('Move (not posts)');
                   2639:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
                   2640:         $copytext = &mt('Copy to new page');
                   2641:         $movetext = &mt('Move');
1.533     raeburn  2642:     } else {
1.538     raeburn  2643:         $copytext = &mt('Copy to new file');
                   2644:         $movetext = &mt('Move');
                   2645:     }
                   2646:     my $output = '<br />'.
                   2647:                  '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
                   2648:                  '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.('&nbsp;'x 4).
                   2649:                  '<label>'.
                   2650:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
                   2651:                  $copytext.'</label></span>'.('&nbsp;'x2).' '.
                   2652:                  '<span class="LC_nobreak"><label>'.
                   2653:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
                   2654:                  $movetext.'</label></span>';
                   2655:     if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
                   2656:         $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
                   2657:                    '</legend><table border="0">';
                   2658:         my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   2659:         my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
                   2660:         my $lastdir = $parent;
                   2661:         my %depths = (
                   2662:                        $lastdir => 0,
                   2663:                      );
                   2664:         my (%display,%deps);
                   2665:         for (my $i=0; $i<@pastemaps; $i++) {
                   2666:             ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
                   2667:             my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
                   2668:             my @subfolders = split(/,/,$subfolderstr);
                   2669:             $deps{$lastdir} = \@subfolders;
                   2670:             my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
                   2671:             my $depth = $depths{$lastdir} + 1;
                   2672:             my $offset = int($depth * 4);
                   2673:             my $indent = ('&nbsp;' x $offset);
                   2674:             for (my $j=0; $j<@subfolders; $j++) {
                   2675:                 $depths{$subfolders[$j]} = $depth;
                   2676:                 $display{$subfolders[$j]} =
                   2677:                     '<tr><td>'.$indent.$subfoldertitles[$j].'&nbsp;</td>'.
                   2678:                     '<td><label>'.
                   2679:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.('&nbsp;' x2).
                   2680:                     '<label>'.
                   2681:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
                   2682:                     &mt('Move old').'</label>'.
                   2683:                     '</td></tr>';
                   2684:              }
1.492     raeburn  2685:         }
1.538     raeburn  2686:         &recurse_print(\$output,$parent,\%deps,\%display);
                   2687:         $output .= '</table></fieldset>';
1.329     droeschl 2688:     }
1.538     raeburn  2689:     $output .= '</div>';
                   2690:     return $output;
1.488     raeburn  2691: }
                   2692: 
1.492     raeburn  2693: sub recurse_print {
1.538     raeburn  2694:     my ($outputref,$dir,$deps,$display) = @_;
                   2695:     $$outputref .= $display->{$dir}."\n";
1.492     raeburn  2696:     if (ref($deps->{$dir}) eq 'ARRAY') {
                   2697:         foreach my $subdir (@{$deps->{$dir}}) {
1.538     raeburn  2698:             &recurse_print($outputref,$subdir,$deps,$display);
1.492     raeburn  2699:         }
                   2700:     }
                   2701: }
                   2702: 
1.488     raeburn  2703: sub supp_pasteable {
                   2704:     my ($url) = @_;
                   2705:     if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//}) ||
                   2706:         (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
                   2707:         ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
                   2708:         ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598     raeburn  2709:         ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626     raeburn  2710:         ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488     raeburn  2711:         return 1;
                   2712:     }
                   2713:     return;
1.329     droeschl 2714: }
                   2715: 
1.492     raeburn  2716: sub paste_popup_js {
1.594     damieng  2717:     my %html_js_lt = &Apache::lonlocal::texthash(
1.538     raeburn  2718:                                           show => 'Show Options',
                   2719:                                           hide => 'Hide Options',
1.594     damieng  2720:                                         );
                   2721:     my %js_lt = &Apache::lonlocal::texthash(
1.541     raeburn  2722:                                           none => 'No items selected from clipboard.',
1.492     raeburn  2723:                                         );
1.594     damieng  2724:     &html_escape(\%html_js_lt);
                   2725:     &js_escape(\%html_js_lt);
                   2726:     &js_escape(\%js_lt);
1.492     raeburn  2727:     return <<"END";
                   2728: 
1.538     raeburn  2729: function showPasteOptions(suffix) {
                   2730:     document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594     damieng  2731:     document.getElementById('pasteoptionstext_'+suffix).innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492     raeburn  2732:     return;
                   2733: }
                   2734: 
1.538     raeburn  2735: function hidePasteOptions(suffix) {
                   2736:     document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594     damieng  2737:     document.getElementById('pasteoptionstext_'+suffix).innerHTML ='&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538     raeburn  2738:     return;
                   2739: }
                   2740: 
                   2741: function showOptions(caller,suffix) {
                   2742:     if (document.getElementById('pasteoptionstext_'+suffix)) {
                   2743:         if (caller.checked) {
1.594     damieng  2744:             document.getElementById('pasteoptionstext_'+suffix).innerHTML ='&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538     raeburn  2745:         } else {
                   2746:             document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
                   2747:         }
                   2748:         if (document.getElementById('pasteoptions_'+suffix)) {
                   2749:             document.getElementById('pasteoptions_'+suffix).style.display='none';
                   2750:         }
                   2751:     }
1.492     raeburn  2752:     return;
                   2753: }
                   2754: 
1.541     raeburn  2755: function validateClipboard() {
                   2756:     var numchk = 0;
                   2757:     if (document.pasteform.pasting.length > 1) {
                   2758:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   2759:             if (document.pasteform.pasting[i].checked) {
                   2760:                 numchk ++;
                   2761:             }
                   2762:         }
                   2763:     } else {
                   2764:         if (document.pasteform.pasting.type == 'checkbox') {
                   2765:             if (document.pasteform.pasting.checked) {
                   2766:                 numchk ++; 
                   2767:             } 
                   2768:         }
                   2769:     }
                   2770:     if (numchk > 0) { 
                   2771:         return true;
                   2772:     } else {
1.594     damieng  2773:         alert("$js_lt{'none'}");
1.541     raeburn  2774:         return false;
                   2775:     }
                   2776: }
                   2777: 
1.575     raeburn  2778: function checkClipboard() {
                   2779:     if (document.pasteform.pasting.length > 1) {
                   2780:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   2781:             document.pasteform.pasting[i].checked = true;
                   2782:         } 
                   2783:     }
                   2784:     return;
                   2785: }
                   2786: 
                   2787: function uncheckClipboard() {
                   2788:     if (document.pasteform.pasting.length >1) {
                   2789:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   2790:             document.pasteform.pasting[i].checked = false;
                   2791:         }
                   2792:     }
                   2793:     return;
                   2794: }
                   2795: 
1.492     raeburn  2796: END
                   2797: 
                   2798: }
                   2799: 
1.329     droeschl 2800: sub do_paste_from_buffer {
1.492     raeburn  2801:     my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329     droeschl 2802: 
1.538     raeburn  2803: # Array of items in paste buffer
                   2804:     my (@currpaste,%pastebuffer,%allerrors);
                   2805:     @currpaste = split(/,/,$env{'docs.markedcopies'});
                   2806: 
1.492     raeburn  2807: # Early out if paste buffer is empty
1.538     raeburn  2808:     if (@currpaste == 0) {
1.492     raeburn  2809:         return ();
1.538     raeburn  2810:     } 
                   2811:     map { $pastebuffer{$_} = 1; } @currpaste;
                   2812: 
                   2813: # Array of items selected items to paste
                   2814:     my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
                   2815: 
                   2816: # Early out if nothing selected to paste
                   2817:     if (@reqpaste == 0) {
                   2818:         return();
                   2819:     }
                   2820:     my @topaste;
                   2821:     foreach my $suffix (@reqpaste) {
                   2822:         next if ($suffix =~ /\D/);
                   2823:         next unless (exists($pastebuffer{$suffix}));
                   2824:         push(@topaste,$suffix);
                   2825:     }
                   2826: 
                   2827: # Early out if nothing available to paste
                   2828:     if (@topaste == 0) {
                   2829:         return();
1.329     droeschl 2830:     }
                   2831: 
1.704     raeburn  2832:     my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
                   2833:         %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
                   2834:         %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
                   2835:         %currltititles,$currltimax,$gotcrsltitools);
                   2836:     $currltimax = 0;
                   2837:     $gotcrsltitools = 0;
1.538     raeburn  2838:     foreach my $suffix (@topaste) {
                   2839:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596     raeburn  2840:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597     raeburn  2841:         my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix}); 
1.492     raeburn  2842: # Supplemental content may only include certain types of content
                   2843: # Early out if pasted content is not supported in Supplemental area
1.538     raeburn  2844:         if ($folder =~ /^supplemental/) {
                   2845:             unless (&supp_pasteable($url)) {
                   2846:                 $notinsupp{$suffix} = 1;
                   2847:                 next;
                   2848:             }
1.492     raeburn  2849:         }
1.538     raeburn  2850:         if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
                   2851:             my $srcd = $1;
                   2852:             my $srcn = $2;
1.492     raeburn  2853: # When paste buffer was populated using an active role in a different course
1.538     raeburn  2854: # check for mdc privilege in the course from which the resource was pasted
                   2855:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   2856:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   2857:                     $notincrs{$suffix} = 1;
                   2858:                     next;
                   2859:                 }
1.491     raeburn  2860:             }
1.538     raeburn  2861:             $srcdom{$suffix} = $srcd;
                   2862:             $srcnum{$suffix} = $srcn;
1.597     raeburn  2863:         } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632     raeburn  2864:                  ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
                   2865:                  ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596     raeburn  2866:             my ($srcd,$srcn) = split(/_/,$cid);
                   2867: # When paste buffer was populated using an active role in a different course
                   2868: # check for mdc privilege in the course from which the resource was pasted
                   2869:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   2870:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   2871:                     $notincrs{$suffix} = 1;
                   2872:                     next;
                   2873:                 }
                   2874:             }
1.632     raeburn  2875: # When buffer was populated using an active role in a different course
1.704     raeburn  2876: # disallow pasting of External Tool if course is in a different domain,
                   2877: # or if External Tool use is not permitted in this course.
                   2878:             if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                   2879:                 my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
                   2880:                 if ($toolcdom ne $coursedom) {
                   2881:                     $notindom{$suffix} = 1;
                   2882:                     next;
                   2883:                 } elsif ($toolcnum ne $coursenum) {
                   2884:                     my %toolsettings =
                   2885:                         &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
                   2886:                     my %tooltypes = &Apache::loncommon::usable_exttools();
                   2887:                     if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                   2888:                         (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                   2889:                         $othcrstool{$suffix} = 1;
                   2890:                         next;
                   2891:                     }
                   2892:                     if ($toolsettings{'id'} =~ /^c\d+$/) {
                   2893:                         unless ($gotcrsltitools) {
                   2894:                             %currcrsltitools =
                   2895:                                 &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
                   2896:                             foreach my $item (sort(keys(%currcrsltitools))) {
                   2897:                                 if (ref($currcrsltitools{$item}) eq 'HASH') {
                   2898:                                     $currltimax ++;
                   2899:                                     if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
                   2900:                                         push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
                   2901:                                     } else {
                   2902:                                         $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
                   2903:                                     }
                   2904:                                 }
                   2905:                             }
                   2906:                             $gotcrsltitools = 1;
                   2907:                         }
                   2908:                     }
                   2909:                 }
1.627     raeburn  2910:             }
1.596     raeburn  2911:             $srcdom{$suffix} = $srcd;
                   2912:             $srcnum{$suffix} = $srcn;
1.703     raeburn  2913:         } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
                   2914:             my ($audom,$auname) = ($1,$2);
                   2915: # When buffer was populated using an active role in a different course
                   2916: # disallow pasting of published resources from Course Authoring Space
                   2917:             unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
                   2918:                 if (&Apache::lonnet::is_course($audom,$auname)) {
                   2919:                     $othcrsres{$suffix} = 1;
                   2920:                     next;
                   2921:                 }
                   2922:             }
1.491     raeburn  2923:         }
1.597     raeburn  2924:         $srcmapidx{$suffix} = $mapidx;
1.538     raeburn  2925:         push(@dopaste,$suffix);
                   2926:         if ($url=~/\.(page|sequence)$/) {
                   2927:             $is_map{$suffix} = 1; 
                   2928:         }
                   2929:         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
                   2930:             my $oldprefix = $1;
1.492     raeburn  2931: # When pasting content from Main Content to Supplemental Content and vice versa 
                   2932: # URLs will contain different paths (which depend on whether pasted item is
1.597     raeburn  2933: # a folder/page or a document).
1.538     raeburn  2934:             if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
                   2935:                 $prefixchg{$suffix} = 'docstosupp';
                   2936:             } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
                   2937:                 $prefixchg{$suffix} = 'supptodocs';
                   2938:             }
1.491     raeburn  2939: 
1.492     raeburn  2940: # If pasting an uploaded map, get list of contained uploaded maps.
1.538     raeburn  2941:             if ($env{'docs.markedcopy_nested_'.$suffix}) {
                   2942:                 my @nested;
                   2943:                 my ($type) = ($oldprefix =~ /^(default|supplemental)/);
                   2944:                 my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   2945:                 my @deps = map { /\d+:([\d,]+$)/ } @items;
                   2946:                 foreach my $dep (@deps) {
                   2947:                     if ($dep =~ /,/) {
                   2948:                         push(@nested,split(/,/,$dep));
                   2949:                     } else {
                   2950:                         push(@nested,$dep);
                   2951:                     }
1.492     raeburn  2952:                 }
1.538     raeburn  2953:                 foreach my $item (@nested) {
                   2954:                     if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
                   2955:                         push(@{$marktomove{$suffix}},$type.'_'.$item);
                   2956:                     }
1.492     raeburn  2957:                 }
                   2958:             }
1.488     raeburn  2959:         }
                   2960:     }
                   2961: 
1.538     raeburn  2962: # Early out if nothing available to paste
                   2963:     if (@dopaste == 0) {
                   2964:         return ();
                   2965:     }
                   2966: 
                   2967: # Populate message hash and hashes used for main content <=> supplemental content
                   2968: # changes    
                   2969: 
                   2970:     %msgs = &Apache::lonlocal::texthash (
                   2971:                 notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
                   2972:                 notincrs  => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661     raeburn  2973:                 notindom  => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704     raeburn  2974:                 othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703     raeburn  2975:                 othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538     raeburn  2976:                 duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
                   2977:             );
                   2978: 
                   2979:     %before = (
                   2980:                  docstosupp => {
                   2981:                                    map => 'default',
                   2982:                                    doc => 'docs',
                   2983:                                },
                   2984:                  supptodocs => {
                   2985:                                    map => 'supplemental',
                   2986:                                    doc => 'supplemental',
                   2987:                                },
                   2988:               );
                   2989: 
                   2990:     %after = (
                   2991:                  docstosupp => {
                   2992:                                    map => 'supplemental',
                   2993:                                    doc => 'supplemental'
                   2994:                                },
                   2995:                  supptodocs => {
                   2996:                                    map => 'default',
                   2997:                                    doc => 'docs',
                   2998:                                },
                   2999:              );
                   3000: 
                   3001: # Retrieve information about all course maps in main content area 
                   3002: 
                   3003:     my $allmaps = {};
1.704     raeburn  3004:     my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
                   3005:         @updatetoolsenc,$updatetoolscache,$checkedsameinst,
                   3006:         $same_institution);
1.538     raeburn  3007: 
                   3008: # Loop over the items to paste
                   3009:     foreach my $suffix (@dopaste) {
1.329     droeschl 3010: # Maps need to be copied first
1.538     raeburn  3011:         my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
                   3012:             %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597     raeburn  3013:             %newurls,%tomove,%resdatacopy);
1.538     raeburn  3014:         if (ref($marktomove{$suffix}) eq 'ARRAY') {
                   3015:             map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
                   3016:         }
                   3017:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
                   3018:         my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596     raeburn  3019:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); 
1.538     raeburn  3020:         my $oldurl = $url;
                   3021:         if ($is_map{$suffix}) {
1.491     raeburn  3022: # If pasting a map, check if map contains other maps
1.538     raeburn  3023:             my (%hierarchy,%titles);
1.660     raeburn  3024:             if (($folder =~ /^default/) && (!$donechk)) {
                   3025:                 $allmaps =
                   3026:                     &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                   3027:                                                          $env{"course.$env{'request.course.id'}.home"},
                   3028:                                                          $env{'request.course.id'});
                   3029:                 $donechk = 1;
                   3030:             }
1.627     raeburn  3031:             &contained_map_check($url,$folder,$coursenum,$coursedom,
                   3032:                                  \%removefrommap,\%removeparam,\%addedmaps,
                   3033:                                  \%hierarchy,\%titles,$allmaps);
1.538     raeburn  3034:             if ($url=~ m{^/uploaded/}) {
                   3035:                 my $newurl;
                   3036:                 unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   3037:                     ($newurl,my $error) = 
                   3038:                         &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
                   3039:                                         $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   3040:                                         \$title,$allmaps,\%newurls);
                   3041:                     if ($error) {
                   3042:                         $allerrors{$suffix} = $error;
                   3043:                         next;
                   3044:                     }
                   3045:                     if ($newurl ne '') {
                   3046:                         if ($newurl ne $url) {
                   3047:                             if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
                   3048:                                 $newsubdir{$url} = $1;
                   3049:                             }
                   3050:                             $mapchanges{$url} = 1;
1.492     raeburn  3051:                         }
1.538     raeburn  3052:                     }
                   3053:                 }
                   3054:                 if (($srcdom{$suffix} ne $coursedom) ||
                   3055:                     ($srcnum{$suffix} ne $coursenum) ||
                   3056:                     ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
                   3057:                     unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
                   3058:                                               $coursedom,$coursenum,$srcdom{$suffix},
                   3059:                                               $srcnum{$suffix},$allmaps,\%rewrites,
                   3060:                                               \%retitles,\%copies,\%dbcopies,
                   3061:                                               \%zombies,\%params,\%mapmoves,
                   3062:                                               \%mapchanges,\%tomove,\%newsubdir,
1.597     raeburn  3063:                                               \%newurls,\%resdatacopy)) {
1.538     raeburn  3064:                         $mapmoves{$url} = 1;
                   3065:                     }
                   3066:                     $url = $newurl;
                   3067:                 } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
                   3068:                     &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
                   3069:                                       $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   3070:                                       $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
                   3071:                                       \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597     raeburn  3072:                                       \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538     raeburn  3073:                 }
                   3074:             } elsif ($url=~m {^/res/}) {
1.597     raeburn  3075: # published map can only exist once, so remove from paste buffer when done
1.538     raeburn  3076:                 push(@toclear,$suffix);
                   3077: # if pasting published map (main content area only) check map not already in course
                   3078:                 if ($folder =~ /^default/) {
                   3079:                     if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
                   3080:                         $duplicate{$suffix} = 1; 
                   3081:                         next;
1.492     raeburn  3082:                     }
1.491     raeburn  3083:                 }
                   3084:             }
1.538     raeburn  3085:         }
1.627     raeburn  3086:         if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538     raeburn  3087:             my $prefix = $1;
1.648     raeburn  3088:             my $fromothercrs;
1.538     raeburn  3089:             #need to copy the db contents to a new one, unless this is a move.
                   3090:             my %info = (
                   3091:                          src  => $url,
                   3092:                          cdom => $coursedom,
                   3093:                          cnum => $coursenum,
1.596     raeburn  3094:                        );
1.649     raeburn  3095:             if ($prefix eq 'ext.tool') {
1.655     raeburn  3096:                 if ($prefixchg{$suffix} eq 'docstosupp') {
1.649     raeburn  3097:                     $info{'delgradable'} = 1;
                   3098:                 }
                   3099:             }
1.596     raeburn  3100:             if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
                   3101:                 unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
                   3102:                     $fromothercrs = 1;
                   3103:                     $info{'cdom'} = $srcdom{$suffix};
                   3104:                     $info{'cnum'} = $srcnum{$suffix};
1.704     raeburn  3105:                     unless ($checkedsameinst) {
                   3106:                         my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
                   3107:                         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   3108:                         if ($intdom ne '') {
                   3109:                             my $internet_names =
                   3110:                                 &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   3111:                             if (ref($internet_names) eq 'ARRAY') {
                   3112:                                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   3113:                                     $same_institution = 1;
                   3114:                                 }
                   3115:                             }
                   3116:                         }
                   3117:                         $checkedsameinst = 1;
                   3118:                     }
1.596     raeburn  3119:                 }
                   3120:             }
                   3121:             unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630     raeburn  3122:                 my (%lockerr,$msg);
1.538     raeburn  3123:                 my ($newurl,$result,$errtext) =
1.704     raeburn  3124:                     &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
                   3125:                             \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538     raeburn  3126:                 if ($result eq 'ok') {
                   3127:                     $url = $newurl;
                   3128:                     $title=&mt('Copy of').' '.$title;
                   3129:                 } else {
                   3130:                     if ($prefix eq 'smppg') {
                   3131:                         $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
                   3132:                     } elsif ($prefix eq 'bulletinboard') {
1.565     bisitz   3133:                         $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627     raeburn  3134:                     } elsif ($prefix eq 'ext.tool') {
                   3135:                         $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538     raeburn  3136:                     }
                   3137:                     $results{$suffix} = $result;
                   3138:                     $msgerrs{$suffix} = $msg;
                   3139:                     $lockerrs{$suffix} = $lockerr{$prefix}; 
                   3140:                     next;
                   3141: 	        }
                   3142:                 if ($lockerr{$prefix}) {
                   3143:                     $lockerrs{$suffix} = $lockerr{$prefix};  
1.491     raeburn  3144:                 }
1.489     raeburn  3145:             }
                   3146:         }
1.538     raeburn  3147:         $title = &LONCAPA::map::qtunescape($title);
                   3148:         my $ext='false';
                   3149:         if ($url=~m{^http(|s)://}) { $ext='true'; }
                   3150:         if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
                   3151:             if ($folder !~ /^supplemental/) {
                   3152:                 (undef,undef,$title) =
                   3153:                     &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
                   3154:             }
                   3155:         } else {
                   3156:             if ($folder=~/^supplemental/) {
                   3157:                 $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   3158:                        $env{'user.domain'}.'___&&&___'.$title;
1.491     raeburn  3159:             }
1.533     raeburn  3160:         }
1.491     raeburn  3161: 
                   3162: # For uploaded files (excluding pages/sequences) path in copied file is changed
                   3163: # if paste is from Main to Supplemental (or vice versa), or if pasting between
                   3164: # courses.
                   3165: 
1.538     raeburn  3166:         unless ($is_map{$suffix}) {
                   3167:             my $newidx;
1.492     raeburn  3168: # Now insert the URL at the bottom
1.538     raeburn  3169:             $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   3170:             if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
                   3171:                 my $relpath = $1;
                   3172:                 if ($relpath ne '') {
                   3173:                     my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
                   3174:                     my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
                   3175:                     my $newprefix = $newloc;
                   3176:                     if ($newloc eq 'default') {
                   3177:                         $newprefix = 'docs';
                   3178:                     }
                   3179:                     if ($newdocsdir eq '') {
                   3180:                         $newdocsdir = 'default';
                   3181:                     }
1.630     raeburn  3182:                     if (($prefixchg{$suffix}) ||
                   3183:                         ($srcdom{$suffix} ne $coursedom) ||
1.538     raeburn  3184:                         ($srcnum{$suffix} ne $coursenum) ||
                   3185:                         ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
                   3186:                         my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
                   3187:                         $url =
                   3188:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
                   3189:                                                                &Apache::lonnet::getfile($oldurl));
                   3190:                         if ($url eq '/adm/notfound.html') {
                   3191:                             $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
                   3192:                             next;
                   3193:                         } else {
                   3194:                             my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
                   3195:                             $newsubpath =~ s{/+$}{/};
                   3196:                             $docmoves{$oldurl} = $newsubpath;
                   3197:                         }
1.491     raeburn  3198:                     }
                   3199:                 }
1.597     raeburn  3200:             } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   3201:                 my $template = $1;
                   3202:                 if ($newidx) {
                   3203:                     &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
                   3204:                                           $coursedom,$coursenum,$template,$newidx,"$folder.$container");
                   3205:                 }
1.649     raeburn  3206:             } elsif ($url =~ /ext\.tool$/) {
1.655     raeburn  3207:                 if (($newidx) && ($folder=~/^default/)) {
1.649     raeburn  3208:                     my $marker = (split(m{/},$url))[4];
                   3209:                     my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
                   3210:                     my $val = 'no';
                   3211:                     if ($toolsettings{'gradable'}) {
                   3212:                         $val = 'yes';
                   3213:                     }
                   3214:                     &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
                   3215:                                                   'string_yesno');
                   3216:                     &remember_parms($newidx,'gradable','set',$val);
                   3217:                 }
1.491     raeburn  3218:             }
1.538     raeburn  3219:             $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   3220:                                               ':'.$ext.':normal:res';
                   3221:             push(@LONCAPA::map::order,$newidx);
                   3222: # Store the result
                   3223:             my ($errtext,$fatal) =
                   3224:                 &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   3225:             if ($fatal) {
                   3226:                 $save_err .= $errtext;
                   3227:                 $allresult = 'fail';
                   3228:             }
1.488     raeburn  3229:         }
1.538     raeburn  3230: 
1.597     raeburn  3231: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
                   3232: # resourcedata for simpleproblems copied from another course 
1.538     raeburn  3233:         unless ($allresult eq 'fail') {
                   3234:             my %updated = (
                   3235:                             rewrites      => \%rewrites,
                   3236:                             zombies       => \%zombies,
                   3237:                             removefrommap => \%removefrommap,
                   3238:                             removeparam   => \%removeparam,
                   3239:                             dbcopies      => \%dbcopies,
1.597     raeburn  3240:                             resdatacopy   => \%resdatacopy,
1.538     raeburn  3241:                             retitles      => \%retitles,
                   3242:                           );
                   3243:             my %info = (
                   3244:                            newsubdir => \%newsubdir,
                   3245:                            params    => \%params,
                   3246:                        );
                   3247:             if ($prefixchg{$suffix}) {
                   3248:                 $info{'before'} = $before{$prefixchg{$suffix}};
                   3249:                 $info{'after'} = $after{$prefixchg{$suffix}};
                   3250:             }
                   3251:             my %moves = (
                   3252:                            copies   => \%copies,
                   3253:                            docmoves => \%docmoves,
                   3254:                            mapmoves => \%mapmoves,
                   3255:                         );
                   3256:             (my $result,$msgs{$suffix},my $lockerror) =
                   3257:                 &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
                   3258:                               \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
                   3259:                               $url,'paste');
                   3260:             $lockerrors .= $lockerror;
                   3261:             if ($result eq 'ok') {
                   3262:                 if ($is_map{$suffix}) {
                   3263:                     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   3264:                                                     $folder.'.'.$container);
                   3265:                     if ($fatal) {
                   3266:                         $allresult = 'failread';
                   3267:                     } else {
                   3268:                         if ($#LONCAPA::map::order<1) {
                   3269:                             my $idx=&LONCAPA::map::getresidx();
                   3270:                             if ($idx<=0) { $idx=1; }
                   3271:                             $LONCAPA::map::order[0]=$idx;
                   3272:                             $LONCAPA::map::resources[$idx]='';
                   3273:                         }
                   3274:                         my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   3275:                         $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   3276:                                                           ':'.$ext.':normal:res';
                   3277:                         push(@LONCAPA::map::order,$newidx);
1.492     raeburn  3278: 
                   3279: # Store the result
1.538     raeburn  3280:                         my ($errtext,$fatal) = 
                   3281:                             &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   3282:                         if ($fatal) {
                   3283:                             $save_err .= $errtext;
                   3284:                             $allresult = 'failstore';
                   3285:                         }
                   3286:                     } 
                   3287:                 }
                   3288:                 if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   3289:                      push(@toclear,$suffix);
                   3290:                 }
                   3291:             }
1.492     raeburn  3292:         }
                   3293:     }
1.704     raeburn  3294:     if (($updatetoolscache) || (@updatetoolsenc)) {
                   3295:         &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
                   3296:                                 \@updatetoolsenc);
                   3297:     }
1.538     raeburn  3298:     &clear_from_buffer(\@toclear,\@currpaste);
                   3299:     my $msgsarray;
                   3300:     foreach my $suffix (keys(%msgs)) {
                   3301:          if (ref($msgs{$suffix}) eq 'ARRAY') {
                   3302:              $msgsarray .= join(',',@{$msgs{$suffix}});
                   3303:          }
                   3304:     }
                   3305:     return ($allresult,$save_err,$msgsarray,$lockerrors);
                   3306: }
1.533     raeburn  3307: 
1.538     raeburn  3308: sub do_buffer_empty {
                   3309:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   3310:     if (@currpaste == 0) {
                   3311:         return &mt('Clipboard is already empty');
                   3312:     }
                   3313:     my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
                   3314:     if (@toclear == 0) {
                   3315:         return &mt('Nothing selected to clear from clipboard');
                   3316:     }
                   3317:     my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
                   3318:     if ($numdel) {
                   3319:         return &mt('[quant,_1,item] cleared from clipboard',$numdel);
                   3320:     } else {
                   3321:         return &mt('Clipboard unchanged');
1.492     raeburn  3322:     }
1.538     raeburn  3323:     return;
                   3324: }
                   3325: 
                   3326: sub clear_from_buffer {
                   3327:     my ($toclear,$currpaste) = @_;
                   3328:     return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
                   3329:     my %pastebuffer;
                   3330:     map { $pastebuffer{$_} = 1; } @{$currpaste};
                   3331:     my $numdel = 0;
                   3332:     foreach my $suffix (@{$toclear}) {
                   3333:         next if ($suffix =~ /\D/);
                   3334:         next unless (exists($pastebuffer{$suffix}));
                   3335:         my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
                   3336:         if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
                   3337:             delete($pastebuffer{$suffix});
                   3338:             $numdel ++;
                   3339:         }
                   3340:     }
                   3341:     my $newbuffer = join(',',sort(keys(%pastebuffer)));
                   3342:     &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
                   3343:     return $numdel;
1.492     raeburn  3344: }
                   3345: 
1.704     raeburn  3346: sub update_ltitools_caches {
                   3347:     my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
                   3348:     my $hashid=$coursedom.'_'.$coursenum;
                   3349:     if ($updatetoolscache) {
                   3350:         &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
                   3351:     }
                   3352:     if ((ref($updatetoolsenc) eq 'ARRAY') &&
                   3353:         (@{$updatetoolsenc})) {
                   3354:         my @ids=&Apache::lonnet::current_machine_ids();
                   3355:         my $updatedone;
                   3356:         foreach my $lonhost (@{$updatetoolsenc}) {
                   3357:             if (grep(/^\Q$lonhost\E$/,@ids)) {
                   3358:                 unless ($updatedone) {
                   3359:                     &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
                   3360:                 }
                   3361:                 $updatedone = 1;
                   3362:             } else {
                   3363:                 &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
                   3364:             }
                   3365:         }
                   3366:     }
                   3367:     return;
                   3368: }
                   3369: 
1.492     raeburn  3370: sub get_newmap_url {
                   3371:     my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
                   3372:         $titleref,$allmaps,$newurls) = @_;
                   3373:     my $newurl;
                   3374:     if ($url=~ m{^/uploaded/}) {
                   3375:         $$titleref=&mt('Copy of').' '.$$titleref;
                   3376:     }
                   3377:     my $now = time;
                   3378:     my $suffix=$$.int(rand(100)).$now;
                   3379:     my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
                   3380:     if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
                   3381:         my $path = $1;
                   3382:         my $prefix = $2;
                   3383:         my $ancestor = $3;
                   3384:         if (length($ancestor) > 10) {
                   3385:             $ancestor = substr($ancestor,-10,10);
                   3386:         }
                   3387:         my $newid;
                   3388:         if ($prefixchg) {
                   3389:             if ($folder =~ /^supplemental/) {
                   3390:                 $prefix =~ s/^default/supplemental/;
                   3391:             } else {
                   3392:                 $prefix =~ s/^supplemental/default/;
                   3393:             }
                   3394:         }
                   3395:         if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   3396:             $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   3397:         } else {
                   3398:             $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
                   3399:         }
                   3400:         my $counter = 0;
                   3401:         my $is_unique = &uniqueness_check($newurl);
                   3402:         if ($folder =~ /^default/) {
                   3403:             if ($allmaps->{$newurl}) {
                   3404:                 $is_unique = 0;
                   3405:             }
                   3406:         }
                   3407:         while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
                   3408:             $counter ++;
                   3409:             $suffix ++;
                   3410:             if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   3411:                 $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   3412:             } else {
                   3413:                 $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
                   3414:             }
                   3415:             $is_unique = &uniqueness_check($newurl);
                   3416:         }
                   3417:         if ($is_unique) {
                   3418:             $newurls->{$newurl} = 1;
                   3419:         } else {
                   3420:             if ($url=~/\.page$/) {
                   3421:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
                   3422:             } else {
                   3423:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
                   3424:             }
                   3425:         }
1.329     droeschl 3426:     }
1.492     raeburn  3427:     return ($newurl);
1.329     droeschl 3428: }
                   3429: 
1.488     raeburn  3430: sub dbcopy {
1.704     raeburn  3431:     my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
                   3432:         $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533     raeburn  3433:     my ($url,$result,$errtext);
                   3434:     if (ref($dbref) eq 'HASH') {
1.596     raeburn  3435:         $url = $dbref->{'src'};
1.627     raeburn  3436:         if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533     raeburn  3437:             my $prefix = $1;
1.627     raeburn  3438:             if ($prefix eq 'ext.tool') {
                   3439:                 $prefix = 'exttool';
                   3440:             }
1.533     raeburn  3441:             if (($dbref->{'cdom'} =~ /^$match_domain$/) && 
                   3442:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   3443:                 my $db_name;
                   3444:                 my $marker = (split(m{/},$url))[4];
                   3445:                 $marker=~s/\D//g;
                   3446:                 if ($dbref->{'src'} =~ m{/smppg$}) {
                   3447:                     $db_name =
                   3448:                         &Apache::lonsimplepage::get_db_name($url,$marker,
                   3449:                                                             $dbref->{'cdom'},
                   3450:                                                             $dbref->{'cnum'});
1.627     raeburn  3451:                 } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
                   3452:                     $db_name = 'exttool_'.$marker;
1.533     raeburn  3453:                 } else {
                   3454:                     $db_name = 'bulletinpage_'.$marker;
                   3455:                 }
                   3456:                 my ($suffix,$freedlock,$error) =
                   3457:                     &Apache::lonnet::get_timebased_id($prefix,'num','templated',
                   3458:                                                       $coursedom,$coursenum,
                   3459:                                                       'concat');
                   3460:                 if (!$suffix) {
                   3461:                     if ($prefix eq 'smppg') {
                   3462:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631     raeburn  3463:                     } elsif ($prefix eq 'exttool') {
                   3464:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533     raeburn  3465:                     } else {
1.565     bisitz   3466:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533     raeburn  3467:                     }
                   3468:                     if ($error) {
                   3469:                         $errtext .= '<br />'.$error;
                   3470:                     }
                   3471:                 } else {
                   3472:                     #need to copy the db contents to a new one.
                   3473:                     my %contents=&Apache::lonnet::dump($db_name,
                   3474:                                                        $dbref->{'cdom'},
                   3475:                                                        $dbref->{'cnum'});
1.704     raeburn  3476:                     my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
                   3477:                     if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
                   3478:                         if ($contents{'id'} =~ /^(|c)(\d+)$/) {
                   3479:                             $oldtoolid = $2;
                   3480:                             if ($1 eq 'c') {
                   3481:                                 $defincrs = 1;
                   3482:                                 %toolinfo =
                   3483:                                     &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
                   3484:                             } else {
                   3485:                                 %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
                   3486:                             }
                   3487:                             if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
                   3488:                                 if ($toolinfo{$oldtoolid}{'passback'}) {
                   3489:                                     $toolpassback = 1;
                   3490:                                 }
                   3491:                                 if ($toolinfo{$oldtoolid}{'roster'}) {
                   3492:                                     $toolroster = 1;
                   3493:                                 }
                   3494:                             } else {
                   3495:                                 $toolcopyerror = 1;
                   3496:                                 $errtext = &mt('Could not retrieve original settings for pasted external tool.');
                   3497:                             }
                   3498:                         }
                   3499:                         unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
                   3500:                             $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
                   3501:                             if ($contents{'crstitle'} ne '') {
                   3502:                                 $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
                   3503:                             }
                   3504:                             if (($defincrs) && (!$toolcopyerror)) {
                   3505:                                 my %newtool;
                   3506:                                 my $oldcdom = $dbref->{'cdom'};
                   3507:                                 my $oldcnum = $dbref->{'cnum'};
                   3508:                                 my $title = $toolinfo{$oldtoolid}{'title'};
                   3509:                                 if (ref($currltititles) eq 'HASH') {
                   3510:                                     if (exists($currltititles->{$title})) {
                   3511:                                         $title .= ' (copied from another course)';
                   3512:                                     }
                   3513:                                 }
                   3514:                                 my ($newid,$iderror) =
                   3515:                                     &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
                   3516:                                 if ($newid =~ /^\d+$/) {
                   3517:                                     %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
                   3518:                                     $newtool{$newid}{'title'} = $title;
                   3519:                                     if (ref($currltimax)) {
                   3520:                                         $newtool{$newid}{'order'} = $$currltimax;
                   3521:                                     }
                   3522:                                     if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
                   3523:                                         my $fname = $1;
                   3524:                                         my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
                   3525:                                         if ($content eq '-1') {
                   3526:                                             delete($newtool{$newid}{'image'});
                   3527:                                         } else {
                   3528:                                             $env{'form.'.$suffix.'.image'} = $content;
                   3529:                                             my $newlogo =
                   3530:                                                 &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
                   3531:                                             delete($env{'form.'.$suffix.'.image'});
                   3532:                                             if ($newlogo =~ m{^/uploaded/}) {
                   3533:                                                 $newtool{$newid}{'image'} = $newlogo;
                   3534:                                             } else {
                   3535:                                                 delete($newtool{$newid}{'image'});
                   3536:                                             }
                   3537:                                         }
                   3538:                                     }
                   3539:                                     my $newusable;
                   3540:                                     if ($same_institution) {
                   3541:                                         my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
                   3542:                                         if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
                   3543:                                             my %newtoolsenc;
                   3544:                                             %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
                   3545:                                             my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
                   3546:                                             if ($putres eq 'ok') {
                   3547:                                                 if (ref($updatetoolsenc) eq 'ARRAY') {
                   3548:                                                     my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
                   3549:                                                     unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
                   3550:                                                         push(@{$updatetoolsenc},$newhome);
                   3551:                                                     }
                   3552:                                                 }
                   3553:                                                 $newusable = 1;
                   3554:                                             }
                   3555:                                         }
                   3556:                                     }
                   3557:                                     if ($newtool{$newid}{'usable'}) {
                   3558:                                         unless ($newusable) {
                   3559:                                             delete($newtool{$newid}{'usable'});
                   3560:                                         }
                   3561:                                     }
                   3562:                                     my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
                   3563:                                     if ($putres eq 'ok') {
                   3564:                                         $contents{'id'} = "c$newid";
                   3565:                                         if (ref($updatetoolscache)) {
                   3566:                                             $$updatetoolscache ++;
                   3567:                                         }
                   3568:                                         if (ref($currltititles->{$title}) eq 'ARRAY') {
                   3569:                                             push(@{$currltititles->{$title}},$newid);
                   3570:                                         } else {
                   3571:                                             $currltititles->{$title} = [$newid];
                   3572:                                         }
                   3573:                                         if (ref($currltimax)) {
                   3574:                                             $$currltimax ++;
                   3575:                                         }
                   3576:                                     } else {
                   3577:                                         $toolcopyerror = 1;
                   3578:                                         $errtext = &mt('Unable to save external tool definition in Course Settings.');
                   3579:                                     }
                   3580:                                 } else {
                   3581:                                     $toolcopyerror = 1;
                   3582:                                     $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
                   3583:                                 }
                   3584:                             }
                   3585:                         }
                   3586:                     }
1.533     raeburn  3587:                     if (exists($contents{'uploaded.photourl'})) {
                   3588:                         my $photo = $contents{'uploaded.photourl'};
                   3589:                         my ($subdir,$fname) =
                   3590:                             ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596     raeburn  3591:                         my $newphoto;
1.533     raeburn  3592:                         if ($fname ne '') {
                   3593:                             my $content = &Apache::lonnet::getfile($photo);
                   3594:                             unless ($content eq '-1') {
                   3595:                                 $env{'form.'.$suffix.'.photourl'} = $content;
                   3596:                                 $newphoto = 
                   3597:                                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
                   3598:                                 delete($env{'form.'.$suffix.'.photourl'});
                   3599:                             }
                   3600:                         }
                   3601:                         if ($newphoto =~ m{^/uploaded/}) {
                   3602:                             $contents{'uploaded.photourl'} = $newphoto;
                   3603:                         }
                   3604:                     }
                   3605:                     $db_name =~ s{_\d*$ }{_$suffix}x;
1.704     raeburn  3606:                     if ($prefix eq 'exttool') {
                   3607:                         unless ($toolcopyerror) {
                   3608:                             foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
                   3609:                                 if (exists($contents{$key})) {
                   3610:                                     delete($contents{$key});
                   3611:                                 }
                   3612:                             }
                   3613:                             if ($dbref->{'delgradable'}) {
                   3614:                                 if (exists($contents{'gradable'})) {
                   3615:                                     delete($contents{'gradable'});
                   3616:                                 }
                   3617:                             }
                   3618:                             if ($toolpassback) {
                   3619:                                 if ($contents{'gradable'}) {
                   3620:                                     my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                   3621:                                     $contents{'gradesecret'} = $gradesecret;
                   3622:                                     $contents{'gradesecretdate'} = time;
                   3623:                                 }
                   3624:                             }
                   3625:                             if ($toolroster) {
                   3626:                                 my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                   3627:                                 $contents{'rostersecret'} = $rostersecret;
                   3628:                                 $contents{'rostersecretdate'} = time;
                   3629:                             }
                   3630:                         }
1.649     raeburn  3631:                     }
1.704     raeburn  3632:                     if (($prefix eq 'exttool') && ($toolcopyerror)) {
                   3633:                         $result = 'error';
                   3634:                     } else {
                   3635:                         $result=&Apache::lonnet::put($db_name,\%contents,
                   3636:                                                      $coursedom,$coursenum);
                   3637:                         if ($result eq 'ok') {
                   3638:                             $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
                   3639:                         }
1.533     raeburn  3640:                     }
                   3641:                 }
                   3642:                 if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559     raeburn  3643:                     $lockerrorsref->{$prefix} =
1.533     raeburn  3644:                         '<div class="LC_error">'.
                   3645:                         &mt('There was a problem removing a lockfile.');
                   3646:                     if ($prefix eq 'smppg') {
1.560     raeburn  3647:                         $lockerrorsref->{$prefix} .=
1.559     raeburn  3648:                             ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627     raeburn  3649:                     } elsif ($prefix eq 'exttool') {
                   3650:                         $lockerrorsref->{$prefix} .=
                   3651:                             ' '.&mt('This will prevent addition of more external tools to this course.');
1.533     raeburn  3652:                     } else {
1.565     bisitz   3653:                         $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  3654:                     }
1.560     raeburn  3655:                     $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   3656:                                                      '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
                   3657:                                                  '</div>';
1.533     raeburn  3658:                 }
                   3659:             }
                   3660:         } elsif ($url =~ m{/syllabus$}) {
                   3661:             if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
                   3662:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   3663:                 if (($dbref->{'cdom'} ne $coursedom) ||
                   3664:                     ($dbref->{'cnum'} ne $coursenum)) {
                   3665:                     my %contents=&Apache::lonnet::dump('syllabus',
                   3666:                                                        $dbref->{'cdom'},
                   3667:                                                        $dbref->{'cnum'});
                   3668:                     $result=&Apache::lonnet::put('syllabus',\%contents,
                   3669:                                                  $coursedom,$coursenum);
                   3670:                 }
                   3671:             }
1.488     raeburn  3672:         }
                   3673:     }
1.533     raeburn  3674:     return ($url,$result,$errtext);
1.488     raeburn  3675: }
                   3676: 
1.597     raeburn  3677: sub copy_templated_files {
                   3678:     my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
                   3679:     my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
                   3680:     my $srccontainer = 'sequence';
                   3681:     if ($srcwaspage) {
                   3682:         $srccontainer = 'page';
                   3683:     }
                   3684:     my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
                   3685:                   '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
                   3686:     my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
                   3687:     my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
                   3688:     my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
                   3689:                   $template.'.problem';
                   3690:     my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
                   3691:     if ($template eq 'simpleproblem') {
                   3692:         $srcprefix .= '.0.';
                   3693:         my $weightprefix = $newprefix;
                   3694:         $newprefix .= '.0.';
                   3695:         my @simpleprobqtypes = qw(radio option string essay numerical);
                   3696:         my $qtype=$srcparms{$srcprefix.'questiontype'};
                   3697:         if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665     raeburn  3698:             my %newdata = (
                   3699:                 $newprefix.'questiontype' => $qtype,
                   3700:             );
1.597     raeburn  3701:             foreach my $type (@simpleprobqtypes) {
                   3702:                 if ($type eq $qtype) {
                   3703:                     $newdata{"$weightprefix.$type.weight"}=1;
                   3704:                 } else {
                   3705:                     $newdata{"$weightprefix.$type.weight"}=0;
                   3706:                 }
                   3707:             }
                   3708:             $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
                   3709:             $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
                   3710:             $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
                   3711:             if ($qtype eq 'numerical') {
                   3712:                 $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
                   3713:                 $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
                   3714:                 $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
                   3715:                 $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
                   3716:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   3717:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   3718:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   3719:                     unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   3720:                         if ($maxfoils<=0) { $maxfoils=10; }
                   3721:                             my $randomize=$srcparms{$srcprefix.'randomize'};
                   3722:                             unless (defined($randomize)) { $randomize='yes'; }
                   3723:                             unless ($randomize eq 'no') { $randomize='yes'; }
                   3724:                             $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   3725:                             $newdata{$newprefix.'randomize'} = $randomize;
                   3726:                             if ($qtype eq 'option') {
                   3727:                                 $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   3728:                             }
                   3729:                             for (my $i=1; $i<=10; $i++) {
                   3730:                                 $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   3731:                                 $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   3732:                                 $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   3733:                             }
                   3734: 
                   3735:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   3736:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   3737:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   3738:                 unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   3739:                 if ($maxfoils<=0) { $maxfoils=10; }
                   3740:                 my $randomize=$srcparms{$srcprefix.'randomize'};
                   3741:                 unless (defined($randomize)) { $randomize='yes'; }
                   3742:                 unless ($randomize eq 'no') { $randomize='yes'; }
                   3743:                 $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   3744:                 $newdata{$newprefix.'randomize'} = $randomize;
                   3745:                 if ($qtype eq 'option') {
                   3746:                     $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   3747:                 }
                   3748:                 for (my $i=1; $i<=10; $i++) {
                   3749:                     $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   3750:                     $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   3751:                     $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   3752:                 }
                   3753:             } elsif ($qtype eq 'string') {
                   3754:                 $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
                   3755:                 $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
                   3756:             }
                   3757:             if (keys(%newdata)) {
                   3758:                 my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
                   3759:                                                    $coursenum);
                   3760:                 if ($putres eq 'ok') {
                   3761:                     &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
                   3762:                 }
                   3763:             }
                   3764:         }
                   3765:     }
                   3766: }
                   3767: 
1.329     droeschl 3768: sub uniqueness_check {
                   3769:     my ($newurl) = @_;
                   3770:     my $unique = 1;
                   3771:     foreach my $res (@LONCAPA::map::order) {
                   3772:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3773:         $url=&LONCAPA::map::qtescape($url);
                   3774:         if ($newurl eq $url) {
                   3775:             $unique = 0;
1.344     bisitz   3776:             last;
1.329     droeschl 3777:         }
                   3778:     }
                   3779:     return $unique;
                   3780: }
                   3781: 
1.488     raeburn  3782: sub contained_map_check {
1.627     raeburn  3783:     my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
                   3784:         $hierarchy,$titles,$allmaps) = @_;
1.488     raeburn  3785:     my $content = &Apache::lonnet::getfile($url);
                   3786:     unless ($content eq '-1') {
                   3787:         my $parser = HTML::TokeParser->new(\$content);
                   3788:         $parser->attr_encoded(1);
                   3789:         while (my $token = $parser->get_token) {
                   3790:             next if ($token->[0] ne 'S');
                   3791:             if ($token->[1] eq 'resource') {
                   3792:                 next if ($token->[2]->{'type'} eq 'zombie');
                   3793:                 my $ressrc = $token->[2]->{'src'};
1.704     raeburn  3794:                 if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                   3795:                     my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627     raeburn  3796:                     unless ($srcdom eq $coursedom) {
                   3797:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   3798:                         next;
                   3799:                     }
1.704     raeburn  3800:                     unless ($srcnum eq $coursenum) {
                   3801:                         my %toolsettings =
                   3802:                             &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
                   3803:                         my %tooltypes = &Apache::loncommon::usable_exttools();
                   3804:                         if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                   3805:                             (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                   3806:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   3807:                             next;
                   3808:                         }
                   3809:                     }
1.627     raeburn  3810:                 } elsif ($folder =~ /^supplemental/) {
1.488     raeburn  3811:                     unless (&supp_pasteable($ressrc)) {
1.492     raeburn  3812:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488     raeburn  3813:                         next;
                   3814:                     }
                   3815:                 }
1.703     raeburn  3816:                 if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
                   3817:                     my ($srcdom,$srcnum) = ($1,$2);
                   3818:                     unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
                   3819:                         if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
                   3820:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   3821:                             next;
                   3822:                         }
                   3823:                     }
                   3824:                 }
1.492     raeburn  3825:                 if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
                   3826:                     if ($1 eq 'uploaded') {
                   3827:                         $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
                   3828:                         $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488     raeburn  3829:                     } else {
1.492     raeburn  3830:                         if ($allmaps->{$ressrc}) {
1.529     raeburn  3831:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492     raeburn  3832:                         } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
                   3833:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   3834:                         } else {
                   3835:                             $addedmaps->{$ressrc} = [$url];
                   3836:                         }
1.488     raeburn  3837:                     }
1.627     raeburn  3838:                     &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
                   3839:                                          $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488     raeburn  3840:                 }
1.492     raeburn  3841:             } elsif ($token->[1] eq 'param') {
1.488     raeburn  3842:                 if ($folder =~ /^supplemental/) {
1.492     raeburn  3843:                     if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
                   3844:                         push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
                   3845:                     } else {
                   3846:                         $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}]; 
                   3847:                     }
1.488     raeburn  3848:                 }
                   3849:             }
                   3850:         }
                   3851:     }
                   3852:     return;
                   3853: }
                   3854: 
                   3855: sub url_paste_fixups {
1.533     raeburn  3856:     my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
                   3857:         $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597     raeburn  3858:         $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491     raeburn  3859:     my $checktitle;
                   3860:     if (($prefixchg) &&
1.492     raeburn  3861:         ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491     raeburn  3862:         $checktitle = 1;
                   3863:     }
1.492     raeburn  3864:     my $skip;
                   3865:     if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
                   3866:         my $mapid = $1.$2;
                   3867:         if ($tomove->{$mapid}) {
                   3868:             $skip = 1;
                   3869:         }
                   3870:     }
1.491     raeburn  3871:     my $file = &Apache::lonnet::getfile($oldurl);
1.488     raeburn  3872:     return if ($file eq '-1');
                   3873:     my $parser = HTML::TokeParser->new(\$file);
                   3874:     $parser->attr_encoded(1);
1.491     raeburn  3875:     my $changed = 0;
1.488     raeburn  3876:     while (my $token = $parser->get_token) {
                   3877:         next if ($token->[0] ne 'S');
                   3878:         if ($token->[1] eq 'resource') {
                   3879:             my $ressrc = $token->[2]->{'src'};
                   3880:             next if ($ressrc eq '');
1.491     raeburn  3881:             my $id = $token->[2]->{'id'};
1.492     raeburn  3882:             my $title = $token->[2]->{'title'};
1.491     raeburn  3883:             if ($checktitle) {
                   3884:                 if ($title =~ m{\d+\Q___&amp;&amp;&amp;___\E$match_username\Q___&amp;&amp;&amp;___\E$match_domain\Q___&amp;&amp;&amp;___\E(.+)$}) {
1.532     raeburn  3885:                     $retitles->{$oldurl}{$id} = $ressrc;
1.491     raeburn  3886:                 }
                   3887:             }
1.488     raeburn  3888:             next if ($token->[2]->{'type'} eq 'external');
                   3889:             if ($token->[2]->{'type'} eq 'zombie') {
1.492     raeburn  3890:                 next if ($skip);  
1.532     raeburn  3891:                 $zombies->{$oldurl}{$id} = $ressrc;
1.491     raeburn  3892:                 $changed = 1;
                   3893:             } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  3894:                 my $srcdom = $1;
                   3895:                 my $srcnum = $2;
1.488     raeburn  3896:                 my $rem = $3;
1.492     raeburn  3897:                 my $newurl;
                   3898:                 my $mapname;
                   3899:                 if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
                   3900:                     my $prefix = $1;
                   3901:                     $mapname = $prefix.$2;
                   3902:                     if ($tomove->{$mapname}) {
1.533     raeburn  3903:                         &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   3904:                                           $srcdom,$srcnum,$allmaps,$rewrites,
                   3905:                                           $retitles,$copies,$dbcopies,$zombies,
                   3906:                                           $params,$mapmoves,$mapchanges,$tomove,
1.597     raeburn  3907:                                           $newsubdir,$newurls,$resdatacopy);
1.492     raeburn  3908:                         next;
                   3909:                     } else {
                   3910:                         ($newurl,my $error) =
                   3911:                             &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   3912:                                             $srcdom,$srcnum,\$title,$allmaps,$newurls);
                   3913:                         if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
                   3914:                             $newsubdir->{$ressrc} = $1;
                   3915:                         }
                   3916:                         if ($error) {
                   3917:                             next;
                   3918:                         }
                   3919:                     }
                   3920:                 }
                   3921:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
                   3922:                     ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
                   3923:                    
1.488     raeburn  3924:                     if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532     raeburn  3925:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.491     raeburn  3926:                         $mapchanges->{$ressrc} = 1;
1.533     raeburn  3927:                         unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
                   3928:                                                   $cnum,$srcdom,$srcnum,$allmaps,
                   3929:                                                   $rewrites,$retitles,$copies,$dbcopies,
                   3930:                                                   $zombies,$params,$mapmoves,$mapchanges,
1.597     raeburn  3931:                                                   $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491     raeburn  3932:                             $mapmoves->{$ressrc} = 1;
                   3933:                         }
                   3934:                         $changed = 1;
1.488     raeburn  3935:                     } else {
1.532     raeburn  3936:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.488     raeburn  3937:                         $copies->{$oldurl}{$ressrc} = $id;
1.491     raeburn  3938:                         $changed = 1;
1.488     raeburn  3939:                     }
                   3940:                 }
1.649     raeburn  3941:             } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533     raeburn  3942:                 next if ($skip);
1.492     raeburn  3943:                 my $srcdom = $1;
                   3944:                 my $srcnum = $2;
1.649     raeburn  3945:                 my $rem = $3;
                   3946:                 my ($is_exttool,$exttoolchg);
                   3947:                 if ($rem =~ m{\d+/ext\.tool$}) {
1.655     raeburn  3948:                     $is_exttool = 1;
1.649     raeburn  3949:                 }
1.492     raeburn  3950:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532     raeburn  3951:                     $rewrites->{$oldurl}{$id} = $ressrc;
1.533     raeburn  3952:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   3953:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   3954:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   3955:                     $changed = 1;
1.649     raeburn  3956:                     if ($is_exttool) {
                   3957:                         $exttoolchg = 1;
                   3958:                     }
1.700     raeburn  3959:                 } elsif (($is_exttool) &&
1.649     raeburn  3960:                          ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   3961:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   3962:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   3963:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   3964:                     $changed = 1;
                   3965:                     $exttoolchg = 1;
                   3966:                 }
                   3967:                 if (($is_exttool) && ($prefixchg)) {
                   3968:                     if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
                   3969:                         if ($exttoolchg) {
                   3970:                             $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
                   3971:                         }
                   3972:                     }
1.533     raeburn  3973:                 }
                   3974:             } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
                   3975:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
                   3976:                     ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   3977:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   3978:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   3979:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491     raeburn  3980:                     $changed = 1;
1.488     raeburn  3981:                 }
1.597     raeburn  3982:             } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
                   3983:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
                   3984:                     $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
                   3985:                     $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   3986:                     $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
                   3987:                 }
1.488     raeburn  3988:             } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  3989:                 next if ($skip);
                   3990:                 my $srcdom = $1;
                   3991:                 my $srcnum = $2;
                   3992:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533     raeburn  3993:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   3994:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   3995:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491     raeburn  3996:                     $changed = 1;
1.488     raeburn  3997:                 }
                   3998:             }
                   3999:         } elsif ($token->[1] eq 'param') {
1.492     raeburn  4000:             next if ($skip);
1.488     raeburn  4001:             my $to = $token->[2]->{'to'}; 
                   4002:             if ($to ne '') {
                   4003:                 if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492     raeburn  4004:                     push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488     raeburn  4005:                 } else {
                   4006:                     @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
                   4007:                 }
                   4008:             }
                   4009:         }
                   4010:     }
1.491     raeburn  4011:     return $changed;
1.488     raeburn  4012: }
                   4013: 
                   4014: sub apply_fixups {
1.529     raeburn  4015:     my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
                   4016:         $oldurl,$url,$caller) = @_;
                   4017:     my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533     raeburn  4018:         %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704     raeburn  4019:         %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
                   4020:         %currltititles,$currltimax);
                   4021:     $currltimax = 0;
1.529     raeburn  4022:     if (ref($updated) eq 'HASH') {
                   4023:         if (ref($updated->{'rewrites'}) eq 'HASH') {
                   4024:             %rewrites = %{$updated->{'rewrites'}};
                   4025:         }
                   4026:         if (ref($updated->{'zombies'}) eq 'HASH') {
                   4027:             %zombies = %{$updated->{'zombies'}};
                   4028:         }
                   4029:         if (ref($updated->{'removefrommap'}) eq 'HASH') {
                   4030:             %removefrommap = %{$updated->{'removefrommap'}};
                   4031:         }
                   4032:         if (ref($updated->{'removeparam'}) eq 'HASH') {
                   4033:             %removeparam = %{$updated->{'removeparam'}};
                   4034:         }
                   4035:         if (ref($updated->{'dbcopies'}) eq 'HASH') {
                   4036:             %dbcopies = %{$updated->{'dbcopies'}};
                   4037:         }
                   4038:         if (ref($updated->{'retitles'}) eq 'HASH') {
                   4039:             %retitles = %{$updated->{'retitles'}};
                   4040:         }
1.597     raeburn  4041:         if (ref($updated->{'resdatacopy'}) eq 'HASH') {
                   4042:             %resdatacopy = %{$updated->{'resdatacopy'}};
                   4043:         }
1.529     raeburn  4044:     }
                   4045:     if (ref($info) eq 'HASH') {
                   4046:         if (ref($info->{'newsubdir'}) eq 'HASH') {
                   4047:             %newsubdir = %{$info->{'newsubdir'}};
                   4048:         }
                   4049:         if (ref($info->{'params'}) eq 'HASH') {
                   4050:             %params = %{$info->{'params'}};
                   4051:         }
                   4052:         if (ref($info->{'before'}) eq 'HASH') {
                   4053:             %before = %{$info->{'before'}};
                   4054:         }
                   4055:         if (ref($info->{'after'}) eq 'HASH') {
                   4056:             %after = %{$info->{'after'}};
                   4057:         }
                   4058:     }
                   4059:     if (ref($moves) eq 'HASH') {
                   4060:         if (ref($moves->{'copies'}) eq 'HASH') {
                   4061:             %copies = %{$moves->{'copies'}};
                   4062:         }
                   4063:         if (ref($moves->{'docmoves'}) eq 'HASH') {
                   4064:             %docmoves = %{$moves->{'docmoves'}};
                   4065:         }
                   4066:         if (ref($moves->{'mapmoves'}) eq 'HASH') {
                   4067:             %mapmoves = %{$moves->{'mapmoves'}};
                   4068:         }
                   4069:     }
                   4070:     foreach my $key (keys(%copies),keys(%docmoves)) {
1.491     raeburn  4071:         my @allcopies;
1.529     raeburn  4072:         if (exists($copies{$key})) {
                   4073:             if (ref($copies{$key}) eq 'HASH') {
                   4074:                 my %added;
                   4075:                 foreach my $innerkey (keys(%{$copies{$key}})) {
                   4076:                     if (($innerkey ne '') && (!$added{$innerkey})) {
                   4077:                         push(@allcopies,$innerkey);
                   4078:                         $added{$innerkey} = 1;
                   4079:                     }
1.491     raeburn  4080:                 }
1.529     raeburn  4081:                 undef(%added);
1.491     raeburn  4082:             }
                   4083:         }
                   4084:         if ($key eq $oldurl) {
1.529     raeburn  4085:             if ((exists($docmoves{$key}))) {
1.532     raeburn  4086:                 unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491     raeburn  4087:                     push(@allcopies,$oldurl);
                   4088:                 }
                   4089:             }
                   4090:         }
                   4091:         if (@allcopies > 0) {
                   4092:             foreach my $item (@allcopies) {
1.492     raeburn  4093:                 my ($relpath,$oldsubdir,$fname) = 
                   4094:                     ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491     raeburn  4095:                 if ($fname ne '') {
                   4096:                     my $content = &Apache::lonnet::getfile($item);
                   4097:                     unless ($content eq '-1') {
                   4098:                         my $storefn;
1.529     raeburn  4099:                         if (($key eq $oldurl) && (exists($docmoves{$key}))) {
                   4100:                             $storefn = $docmoves{$key};
1.491     raeburn  4101:                         } else {
                   4102:                             $storefn = $relpath;
                   4103:                             $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  4104:                             if ($prefixchg && $before{'doc'} && $after{'doc'}) {
                   4105:                                 $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491     raeburn  4106:                             }
1.529     raeburn  4107:                             if ($newsubdir{$key}) {
1.532     raeburn  4108:                                 $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491     raeburn  4109:                             }
                   4110:                         }
                   4111:                         &copy_dependencies($item,$storefn,$relpath,$errors,\$content);
                   4112:                         my $copyurl = 
                   4113:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},
                   4114:                                                                $storefn.$fname,$content);
                   4115:                         if ($copyurl eq '/adm/notfound.html') {
1.529     raeburn  4116:                             if (exists($docmoves{$oldurl})) {
1.491     raeburn  4117:                                 return &mt('Paste failed: an error occurred copying the file.');
                   4118:                             } elsif (ref($errors) eq 'HASH') {
                   4119:                                 $errors->{$item} = 1;
1.489     raeburn  4120:                             }
                   4121:                         }
1.488     raeburn  4122:                     }
                   4123:                 }
1.491     raeburn  4124:             }
                   4125:         }
                   4126:     }
1.529     raeburn  4127:     foreach my $key (keys(%mapmoves)) {
1.491     raeburn  4128:         my $storefn=$key;
                   4129:         $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  4130:         if ($prefixchg && $before{'map'} && $after{'map'}) {
                   4131:             $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  4132:         }
1.529     raeburn  4133:         if ($newsubdir{$key}) {
                   4134:             $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  4135:         }
1.491     raeburn  4136:         my $mapcontent = &Apache::lonnet::getfile($key);
1.681     raeburn  4137:         if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
                   4138:             ($after{'map'} eq 'default') &&
                   4139:             ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
                   4140:             $mapcontent = '<map>'."\n".
                   4141:                           '<resource id="1" src="" type="start" />'."\n".
                   4142:                           '<link from="1" to="2" index="1" />'."\n".
                   4143:                           '<resource id="2" src="" type="finish" />'."\n".
                   4144:                           '</map>';
                   4145:         }
1.491     raeburn  4146:         if ($mapcontent eq '-1') {
                   4147:             if (ref($errors) eq 'HASH') {
                   4148:                 $errors->{$key} = 1;
                   4149:             }
                   4150:         } else {
                   4151:             my $newmap =
                   4152:                 &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
                   4153:                                                    $mapcontent);
                   4154:             if ($newmap eq '/adm/notfound.html') {
                   4155:                 if (ref($errors) eq 'HASH') {
                   4156:                     $errors->{$key} = 1;
1.489     raeburn  4157:                 }
1.488     raeburn  4158:             }
                   4159:         }
                   4160:     }
1.491     raeburn  4161:     my %updates;
                   4162:     if ($is_map) {
1.529     raeburn  4163:         if (ref($updated) eq 'HASH') {
                   4164:             foreach my $type (keys(%{$updated})) {
                   4165:                 if (ref($updated->{$type}) eq 'HASH') {
                   4166:                     foreach my $key (keys(%{$updated->{$type}})) {
                   4167:                         $updates{$key} = 1;
                   4168:                     }
                   4169:                 }
                   4170:             }
1.491     raeburn  4171:         }
1.704     raeburn  4172:         my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491     raeburn  4173:         foreach my $key (keys(%updates)) {
1.492     raeburn  4174:             my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529     raeburn  4175:             if (ref($rewrites{$key}) eq 'HASH') {
                   4176:                 %torewrite = %{$rewrites{$key}};
1.491     raeburn  4177:             }
1.529     raeburn  4178:             if (ref($retitles{$key}) eq 'HASH') {
                   4179:                 %toretitle = %{$retitles{$key}};
1.491     raeburn  4180:             }
1.529     raeburn  4181:             if (ref($removefrommap{$key}) eq 'HASH') {
                   4182:                 %toremove = %{$removefrommap{$key}};
1.491     raeburn  4183:             }
1.529     raeburn  4184:             if (ref($removeparam{$key}) eq 'HASH') {
                   4185:                 %remparam = %{$removeparam{$key}};
1.492     raeburn  4186:             }
1.529     raeburn  4187:             if (ref($zombies{$key}) eq 'HASH') {
                   4188:                 %zombie = %{$zombies{$key}};
1.491     raeburn  4189:             }
1.529     raeburn  4190:             if (ref($dbcopies{$key}) eq 'HASH') {
1.533     raeburn  4191:                 foreach my $idx (keys(%{$dbcopies{$key}})) {
                   4192:                     if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704     raeburn  4193:                         my $oldurl = $dbcopies{$key}{$idx}{'src'};
                   4194:                         my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
                   4195:                         my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
                   4196:                         my $oldmarker;
                   4197:                         if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
                   4198:                             $oldmarker = $1;
                   4199:                             unless (($gotcrsltitools) ||
                   4200:                                     (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
                   4201:                                 my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
                   4202:                                 if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
                   4203:                                     unless ($gotcrsltitools) {
                   4204:                                         %currcrsltitools =
                   4205:                                             &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
                   4206:                                         foreach my $item (sort(keys(%currcrsltitools))) {
                   4207:                                             if (ref($currcrsltitools{$item}) eq 'HASH') {
                   4208:                                                 $currltimax ++;
                   4209:                                                 if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
                   4210:                                                     push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
                   4211:                                                 } else {
                   4212:                                                     $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
                   4213:                                                 }
                   4214:                                             }
                   4215:                                         }
                   4216:                                         $gotcrsltitools = 1;
                   4217:                                     }
                   4218:                                     unless ($checkedsameinst) {
                   4219:                                         my $primary_id = &Apache::lonnet::domain($cdom,'primary');
                   4220:                                         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   4221:                                         if ($intdom ne '') {
                   4222:                                             my $internet_names =
                   4223:                                                 &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   4224:                                             if (ref($internet_names) eq 'ARRAY') {
                   4225:                                                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   4226:                                                     $same_institution = 1;
                   4227:                                                 }
                   4228:                                             }
                   4229:                                         }
                   4230:                                         $checkedsameinst = 1;
                   4231:                                     }
                   4232:                                 }
                   4233:                             }
                   4234:                         }
1.533     raeburn  4235:                         my ($newurl,$result,$errtext) =
1.704     raeburn  4236:                             &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
                   4237:                                     \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533     raeburn  4238:                         if ($result eq 'ok') {
                   4239:                             $newdb{$idx} = $newurl;
1.704     raeburn  4240:                             if ($newurl =~ /ext\.tool$/) {
                   4241:                                 if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
                   4242:                                     if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
                   4243:                                         my $newmarker = $1;
                   4244:                                         unless ($oldmarker eq $newmarker) {
                   4245:                                             $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
                   4246:                                         }
                   4247:                                     }
                   4248:                                 }
                   4249:                             }
1.533     raeburn  4250:                         } elsif (ref($errors) eq 'HASH') {
                   4251:                             $errors->{$key} = 1;
                   4252:                         }
                   4253:                         push(@msgs,$errtext);
                   4254:                     }
1.491     raeburn  4255:                 }
                   4256:             }
1.597     raeburn  4257:             if (ref($resdatacopy{$key}) eq 'HASH') {
1.664     raeburn  4258:                 my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597     raeburn  4259:                 foreach my $idx (keys(%{$resdatacopy{$key}})) {
                   4260:                     if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
                   4261:                         my $srcurl = $resdatacopy{$key}{$idx}{'src'};
                   4262:                         if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   4263:                             my $template = $1;
                   4264:                             if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
                   4265:                                 ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
                   4266:                                 my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
                   4267:                                 my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664     raeburn  4268:                                 unless ($gotnewmapname) {
                   4269:                                     ($newmapname) = ($key =~ m{/([^/]+)$});
                   4270:                                     ($srcfolder,$srccontainer) = split(/\./,$newmapname);
                   4271:                                     if ($newsubdir{$key}) {
                   4272:                                         $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
                   4273:                                     }
                   4274:                                     $gotnewmapname = 1;
                   4275:                                 }
1.597     raeburn  4276:                                 my $srcmapinfo = $srcfolder.':'.$idx;
                   4277:                                 if ($srccontainer eq 'page') {
                   4278:                                     $srcmapinfo .= ':1';
                   4279:                                 }
                   4280:                                 &copy_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
                   4281:                                                       $cnum,$template,$idx,$newmapname);
                   4282:                             }
                   4283:                         }
                   4284:                     }
                   4285:                 }
                   4286:             }
1.529     raeburn  4287:             if (ref($params{$key}) eq 'HASH') {
                   4288:                 %currparam = %{$params{$key}};
1.492     raeburn  4289:             }
                   4290:             my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
                   4291:             if ($fatal) {
1.533     raeburn  4292:                 return ($errtext);
1.492     raeburn  4293:             }
                   4294:             for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
                   4295:                 if (defined($LONCAPA::map::zombies[$i])) {
                   4296:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532     raeburn  4297:                     if ($zombie{$i} eq $src) {
1.492     raeburn  4298:                         undef($LONCAPA::map::zombies[$i]);
                   4299:                     }
                   4300:                 }
                   4301:             }
1.646     raeburn  4302:             my $total = scalar(@LONCAPA::map::order) - 1;
                   4303:             for (my $i=$total; $i>=0; $i--) {
1.529     raeburn  4304:                 my $idx = $LONCAPA::map::order[$i];
                   4305:                 if (defined($LONCAPA::map::resources[$idx])) {
1.492     raeburn  4306:                     my $changed;
1.529     raeburn  4307:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538     raeburn  4308:                     if ((exists($toremove{$idx})) && 
                   4309:                         ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492     raeburn  4310:                         splice(@LONCAPA::map::order,$i,1);
1.529     raeburn  4311:                         if (ref($currparam{$idx}) eq 'ARRAY') {
                   4312:                             foreach my $name (@{$currparam{$idx}}) {
1.647     raeburn  4313:                                 &LONCAPA::map::delparameter($idx,$name);
1.492     raeburn  4314:                             }
                   4315:                         }
                   4316:                         next;
                   4317:                     }
                   4318:                     my $origsrc = $src;
1.532     raeburn  4319:                     if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492     raeburn  4320:                         if ($title =~ m{^\d+\Q___&amp;&amp;&amp;___\E$match_username\Q___&amp;&amp;&amp;___\E$match_domain\Q___&amp;&amp;&amp;___\E(.+)$}) {
                   4321:                             $changed = 1;
1.491     raeburn  4322:                         }
1.492     raeburn  4323:                     }
1.532     raeburn  4324:                     if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492     raeburn  4325:                         $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
                   4326:                         if ($origsrc =~ m{^/uploaded/}) {
1.529     raeburn  4327:                             if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492     raeburn  4328:                                 if ($src =~ /\.(page|sequence)$/) {
1.529     raeburn  4329:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492     raeburn  4330:                                 } else {
1.529     raeburn  4331:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488     raeburn  4332:                                 }
1.491     raeburn  4333:                             }
1.532     raeburn  4334:                             if ($origsrc =~ /\.(page|sequence)$/) {
                   4335:                                 if ($newsubdir{$origsrc}) {
1.529     raeburn  4336:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491     raeburn  4337:                                 }
1.532     raeburn  4338:                             } elsif ($newsubdir{$key}) {
                   4339:                                 $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488     raeburn  4340:                             }
                   4341:                         }
1.492     raeburn  4342:                         $changed = 1;
1.533     raeburn  4343:                     } elsif ($newdb{$idx} ne '') {
                   4344:                         $src = $newdb{$idx};
1.492     raeburn  4345:                         $changed = 1;
                   4346:                     }
                   4347:                     if ($changed) {
1.538     raeburn  4348:                         $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492     raeburn  4349:                     }
                   4350:                 }
                   4351:             }
                   4352:             foreach my $idx (keys(%remparam)) {
                   4353:                 if (ref($remparam{$idx}) eq 'ARRAY') {
                   4354:                     foreach my $name (@{$remparam{$idx}}) {   
1.647     raeburn  4355:                         &LONCAPA::map::delparameter($idx,$name);
1.491     raeburn  4356:                     }
                   4357:                 }
                   4358:             }
1.533     raeburn  4359:             if (values(%lockerrors) > 0) {
                   4360:                 $lockmsg = join('<br />',values(%lockerrors));
                   4361:             }
1.491     raeburn  4362:             my $storefn;
                   4363:             if ($key eq $oldurl) {
                   4364:                 $storefn = $url;
                   4365:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
                   4366:             } else {
                   4367:                 $storefn = $key;
                   4368:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  4369:                 if ($prefixchg && $before{'map'} && $after{'map'}) {
                   4370:                     $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  4371:                 }
1.529     raeburn  4372:                 if ($newsubdir{$key}) {
                   4373:                     $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  4374:                 }
1.491     raeburn  4375:             }
1.492     raeburn  4376:             my $report;
                   4377:             if ($folder !~ /^supplemental/) {
                   4378:                 $report = 1;
                   4379:             }
1.527     raeburn  4380:             (my $outtext,$errtext) =
1.492     raeburn  4381:                 &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
                   4382:             if ($errtext) {
1.529     raeburn  4383:                 if ($caller eq 'paste') {
1.533     raeburn  4384:                     return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529     raeburn  4385:                 }
1.491     raeburn  4386:             }
                   4387:         }
1.704     raeburn  4388:         if (($updatetoolscache) || (@updatetoolsenc)) {
                   4389:             &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
                   4390:                                     \@updatetoolsenc);
                   4391:         }
1.491     raeburn  4392:     }
1.533     raeburn  4393:     return ('ok',\@msgs,$lockmsg);
1.491     raeburn  4394: }
                   4395: 
                   4396: sub copy_dependencies {
                   4397:     my ($item,$storefn,$relpath,$errors,$contentref) = @_;
                   4398:     my $content;
                   4399:     if (ref($contentref)) {
                   4400:         $content = $$contentref;
                   4401:     } else {
                   4402:         $content = &Apache::lonnet::getfile($item);
                   4403:     }
                   4404:     unless ($content eq '-1') {
                   4405:         my $mm = new File::MMagic;
                   4406:         my $mimetype = $mm->checktype_contents($content);
                   4407:         if ($mimetype eq 'text/html') {
                   4408:             my (%allfiles,%codebase,$state);
                   4409:             my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
                   4410:             if ($res eq 'ok') {
                   4411:                 my ($numexisting,$numpathchanges,$existing);
                   4412:                 (undef,$numexisting,$numpathchanges,$existing) =
                   4413:                     &Apache::loncommon::ask_for_embedded_content(
                   4414:                         '/adm/coursedocs',$state,\%allfiles,\%codebase,
                   4415:                         {'error_on_invalid_names'   => 1,
                   4416:                          'ignore_remote_references' => 1,
                   4417:                          'docs_url'                 => $item,
                   4418:                          'context'                  => 'paste'});
                   4419:                 if ($numexisting > 0) {
                   4420:                     if (ref($existing) eq 'HASH') {
                   4421:                         foreach my $dep (keys(%{$existing})) {
                   4422:                             my $depfile = $dep;
                   4423:                             unless ($depfile =~ m{^\Q$relpath\E}) {
                   4424:                                 $depfile = $relpath.$dep;
                   4425:                             }
                   4426:                             my $depcontent = &Apache::lonnet::getfile($depfile);
                   4427:                             unless ($depcontent eq '-1') {
                   4428:                                 my $storedep = $dep;
                   4429:                                 $storedep =~ s{^\Q$relpath\E}{};
                   4430:                                 my $dep_url =
                   4431:                                     &Apache::lonclonecourse::writefile(
                   4432:                                         $env{'request.course.id'},
                   4433:                                         $storefn.$storedep,$depcontent);
                   4434:                                 if ($dep_url eq '/adm/notfound.html') {
                   4435:                                     if (ref($errors) eq 'HASH') {
                   4436:                                         $errors->{$depfile} = 1;
                   4437:                                     }
                   4438:                                 } else {
                   4439:                                     &copy_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
                   4440:                                 }
                   4441:                             }
                   4442:                         }
1.488     raeburn  4443:                     }
                   4444:                 }
                   4445:             }
                   4446:         }
                   4447:     }
                   4448:     return;
                   4449: }
                   4450: 
1.329     droeschl 4451: my %parameter_type = ( 'randompick'     => 'int_pos',
                   4452: 		       'hiddenresource' => 'string_yesno',
                   4453: 		       'encrypturl'     => 'string_yesno',
                   4454: 		       'randomorder'    => 'string_yesno',);
                   4455: my $valid_parameters_re = join('|',keys(%parameter_type));
                   4456: # set parameters
                   4457: sub update_parameter {
1.537     raeburn  4458:     if ($env{'form.changeparms'} eq 'all') {
                   4459:         my (@allidx,@allmapidx,%allchecked,%currchecked);
                   4460:         %allchecked = (
                   4461:                          'hiddenresource' => {},
                   4462:                          'encrypturl'     => {},
                   4463:                          'randompick'     => {},
                   4464:                          'randomorder'    => {},
                   4465:                       );
                   4466:         foreach my $which (keys(%allchecked)) {
1.630     raeburn  4467:             $env{'form.all'.$which} =~ s/,$//;
1.537     raeburn  4468:             if ($which eq 'randompick') {
                   4469:                 foreach my $item (split(/,/,$env{'form.all'.$which})) {
                   4470:                     my ($res,$value) = split(/:/,$item);
                   4471:                     if ($value =~ /^\d+$/) {
                   4472:                         $allchecked{$which}{$res} = $value;
                   4473:                     }
                   4474:                 }
                   4475:             } else {
1.539     raeburn  4476:                 if ($env{'form.all'.$which}) {
                   4477:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
                   4478:                 }
1.537     raeburn  4479:             }
                   4480:         }
                   4481:         my $haschanges = 0;
                   4482:         foreach my $res (@LONCAPA::map::order) {
                   4483:             my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   4484:             $name=&LONCAPA::map::qtescape($name);
                   4485:             $url=&LONCAPA::map::qtescape($url);
1.692     raeburn  4486:             next unless $url;
1.537     raeburn  4487:             my $is_map;
                   4488:             if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   4489:                 $is_map = 1;
                   4490:             }
                   4491:             foreach my $which (keys(%allchecked)) {
                   4492:                 if (($which eq 'randompick' || $which eq 'randomorder')) {
                   4493:                     next if (!$is_map);
                   4494:                 } 
                   4495:                 my $oldvalue = 0;
                   4496:                 my $newvalue = 0;
                   4497:                 if ($allchecked{$which}{$res}) {
                   4498:                     $newvalue = $allchecked{$which}{$res};
                   4499:                 }
                   4500:                 my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
                   4501:                 if ($which eq 'randompick') {
                   4502:                     if ($current =~ /^(\d+)$/) {
                   4503:                         $oldvalue = $1;
                   4504:                     }
                   4505:                 } else {
                   4506:                     if ($current =~ /^yes$/i) {
                   4507:                         $oldvalue = 1;
                   4508:                     }
                   4509:                 }
                   4510:                 if ($oldvalue ne $newvalue) {
                   4511:                     $haschanges = 1;
                   4512:                     if ($newvalue) {
                   4513:                         my $storeval = 'yes';
                   4514:                         if ($which eq 'randompick') {
                   4515:                             $storeval = $newvalue;
                   4516:                         }
                   4517:                         &LONCAPA::map::storeparameter($res,'parameter_'.$which,
                   4518:                                                       $storeval,
                   4519:                                                       $parameter_type{$which});
                   4520:                         &remember_parms($res,$which,'set',$storeval);
                   4521:                     } elsif ($oldvalue) {
                   4522:                         &LONCAPA::map::delparameter($res,'parameter_'.$which);
                   4523:                         &remember_parms($res,$which,'del');
                   4524:                     }
                   4525:                 }
                   4526:             }
                   4527:         }
                   4528:         return $haschanges;
                   4529:     } else {
1.588     raeburn  4530:         my $haschanges = 0;
                   4531:         return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329     droeschl 4532: 
1.537     raeburn  4533:         my $which = $env{'form.changeparms'};
                   4534:         my $idx = $env{'form.setparms'};
1.588     raeburn  4535:         my $oldvalue = 0;
                   4536:         my $newvalue = 0;
                   4537:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
                   4538:         if ($which eq 'randompick') {
                   4539:             if ($current =~ /^(\d+)$/) {
                   4540:                 $oldvalue = $1;
                   4541:             }
                   4542:         } elsif ($current =~ /^yes$/i) {
                   4543:             $oldvalue = 1;
                   4544:         }
1.537     raeburn  4545:         if ($env{'form.'.$which.'_'.$idx}) {
1.588     raeburn  4546: 	    $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
                   4547: 	                                         : 1;
                   4548:         }
                   4549:         if ($oldvalue ne $newvalue) {
                   4550:             $haschanges = 1;
                   4551:             if ($newvalue) {
                   4552:                 my $storeval = 'yes';
                   4553:                 if ($which eq 'randompick') {
                   4554:                     $storeval = $newvalue;
                   4555:                 }
                   4556: 	        &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
                   4557: 				              $parameter_type{$which});
                   4558: 	        &remember_parms($idx,$which,'set',$storeval);
                   4559:             } else {
                   4560: 	        &LONCAPA::map::delparameter($idx,'parameter_'.$which);
                   4561: 	        &remember_parms($idx,$which,'del');
                   4562:             }
1.537     raeburn  4563:         }
1.588     raeburn  4564:         return $haschanges;
1.329     droeschl 4565:     }
                   4566: }
                   4567: 
                   4568: sub handle_edit_cmd {
                   4569:     my ($coursenum,$coursedom) =@_;
1.633     raeburn  4570:     my $haschanges = 0;
1.543     raeburn  4571:     if ($env{'form.cmd'} eq '') {
1.633     raeburn  4572:         return $haschanges; 
1.543     raeburn  4573:     }
1.329     droeschl 4574:     my ($cmd,$idx)=split('_',$env{'form.cmd'});
                   4575: 
                   4576:     my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                   4577:     my ($title, $url, @rrest) = split(':', $ratstr);
                   4578: 
1.538     raeburn  4579:     if ($cmd eq 'remove') {
1.329     droeschl 4580: 	if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463     www      4581: 	    ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329     droeschl 4582: 	    &Apache::lonnet::removeuploadedurl($url);
                   4583: 	} else {
                   4584: 	    &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   4585: 	}
                   4586: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  4587:         $haschanges = 1;
1.329     droeschl 4588:     } elsif ($cmd eq 'cut') {
                   4589: 	&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   4590: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  4591:         $haschanges = 1;
1.344     bisitz   4592:     } elsif ($cmd eq 'up'
1.329     droeschl 4593: 	     && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
                   4594: 	@LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633     raeburn  4595:         $haschanges = 1;
1.329     droeschl 4596:     } elsif ($cmd eq 'down'
                   4597: 	     && defined($LONCAPA::map::order[$idx+1])) {
                   4598: 	@LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633     raeburn  4599:         $haschanges = 1;
1.329     droeschl 4600:     } elsif ($cmd eq 'rename') {
                   4601: 	my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
                   4602: 	if ($comment=~/\S/) {
                   4603: 	    $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
                   4604: 		$comment.':'.join(':', $url, @rrest);
                   4605: 	}
                   4606: # Devalidate title cache
                   4607: 	my $renamed_url=&LONCAPA::map::qtescape($url);
                   4608: 	&Apache::lonnet::devalidate_title_cache($renamed_url);
1.633     raeburn  4609:         $haschanges = 1;
                   4610:     } elsif ($cmd eq 'setalias') {
                   4611:         my $newvalue = $env{'form.alias'};
                   4612:         if ($newvalue ne '') {
                   4613:             unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
                   4614:                 &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
                   4615:                                               'string');
                   4616:                 &remember_parms($idx,'mapalias','set',$newvalue);
                   4617:                 $haschanges = 1;
                   4618:             }
                   4619:         }
                   4620:     } elsif ($cmd eq 'delalias') {
                   4621:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];  
                   4622:         if ($current ne '') {
                   4623:             &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
                   4624:             &remember_parms($idx,'mapalias','del');
                   4625:             $haschanges = 1;
                   4626:         }
1.329     droeschl 4627:     }
1.633     raeburn  4628:     return $haschanges;
1.329     droeschl 4629: }
                   4630: 
                   4631: sub editor {
1.458     raeburn  4632:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615     raeburn  4633:         $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622     raeburn  4634:         $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519     raeburn  4635:     my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510     raeburn  4636:     if ($allowed) {
1.519     raeburn  4637:         (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   4638:          $is_random_order,$container) =
1.510     raeburn  4639:             &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   4640:         $r->print($breadcrumbtrail);
1.519     raeburn  4641:     } elsif ($env{'form.folderpath'} =~ /\:1$/) {
                   4642:         $container = 'page'; 
                   4643:     } else {
                   4644:         $container = 'sequence';
1.510     raeburn  4645:     }
1.484     raeburn  4646: 
1.525     raeburn  4647:     my $jumpto;
                   4648: 
                   4649:     unless ($supplementalflag) {
1.546     raeburn  4650:         $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525     raeburn  4651:     }
1.484     raeburn  4652: 
                   4653:     unless ($allowed) {
                   4654:         $randompick = -1;
                   4655:     }
                   4656: 
1.615     raeburn  4657:     my ($errtext,$fatal);
                   4658:     if (($folder eq '') && (!$supplementalflag)) {
                   4659:         if (@LONCAPA::map::order) {
                   4660:             undef(@LONCAPA::map::order);
                   4661:             undef(@LONCAPA::map::resources);
                   4662:             undef(@LONCAPA::map::resparms);
                   4663:             undef(@LONCAPA::map::zombies);
                   4664:         }
                   4665:         $folder = 'default';
                   4666:         $container = 'sequence'; 
                   4667:     } else {
                   4668:         ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   4669: 				     $folder.'.'.$container);
                   4670:         return $errtext if ($fatal);
                   4671:     }
1.329     droeschl 4672: 
                   4673:     if ($#LONCAPA::map::order<1) {
                   4674: 	my $idx=&LONCAPA::map::getresidx();
                   4675: 	if ($idx<=0) { $idx=1; }
                   4676:        	$LONCAPA::map::order[0]=$idx;
                   4677:         $LONCAPA::map::resources[$idx]='';
                   4678:     }
1.364     bisitz   4679: 
1.329     droeschl 4680: # ------------------------------------------------------------ Process commands
                   4681: 
                   4682: # ---------------- if they are for this folder and user allowed to make changes
1.611     raeburn  4683:     if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329     droeschl 4684: # set parameters and change order
                   4685: 	&snapshotbefore();
                   4686: 
                   4687: 	if (&update_parameter()) {
1.588     raeburn  4688: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329     droeschl 4689: 	    return $errtext if ($fatal);
                   4690: 	}
                   4691: 
                   4692: 	if ($env{'form.newpos'} && $env{'form.currentpos'}) {
                   4693: # change order
                   4694: 	    my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
                   4695: 	    splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
                   4696: 
                   4697: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
                   4698: 	    return $errtext if ($fatal);
                   4699: 	}
1.364     bisitz   4700: 
1.329     droeschl 4701: 	if ($env{'form.pastemarked'}) {
1.491     raeburn  4702:             my %paste_errors;
1.533     raeburn  4703:             my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492     raeburn  4704:                 &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
                   4705:                                       \%paste_errors);
1.541     raeburn  4706:             if (ref($pastemsgarray) eq 'ARRAY') {
                   4707:                 if (@{$pastemsgarray} > 0) {
                   4708:                     $r->print('<p class="LC_info">'.
                   4709:                               join('<br />',@{$pastemsgarray}).
1.533     raeburn  4710:                               '</p>');
                   4711:                 }
1.541     raeburn  4712:             }
                   4713:             if ($lockerror) {
                   4714:                 $r->print('<p class="LC_error">'.
                   4715:                           $lockerror.
                   4716:                           '</p>');
                   4717:             }
                   4718:             if ($save_error ne '') {
                   4719:                 return $save_error; 
                   4720:             }
                   4721:             if ($paste_res) {
                   4722:                 my %errortext = &Apache::lonlocal::texthash (
                   4723:                                     fail      => 'Storage of folder contents failed',
                   4724:                                     failread  => 'Reading folder contents failed',
                   4725:                                     failstore => 'Storage of folder contents failed',
                   4726:                                 );
                   4727:                 if ($errortext{$paste_res}) {
                   4728:                     $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492     raeburn  4729:                 }
1.329     droeschl 4730:             }
1.491     raeburn  4731:             if (keys(%paste_errors) > 0) {
1.538     raeburn  4732:                 $r->print('<p class="LC_warning">'."\n".
1.491     raeburn  4733:                           &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
                   4734:                           '<ul>'."\n");
                   4735:                 foreach my $key (sort(keys(%paste_errors))) {
                   4736:                     $r->print('<li>'.$key.'</li>'."\n");
                   4737:                 }
                   4738:                 $r->print('</ul></p>'."\n");
                   4739:             }
1.538     raeburn  4740: 	} elsif ($env{'form.clearmarked'}) {
                   4741:             my $output = &do_buffer_empty();
                   4742:             if ($output) {
                   4743:                 $r->print('<p class="LC_info">'.$output.'</p>');
                   4744:             }
                   4745:         }
1.329     droeschl 4746: 
                   4747: 	$r->print($upload_output);
                   4748: 
1.538     raeburn  4749: # Rename, cut, copy or remove a single resource
1.602     raeburn  4750: 	if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492     raeburn  4751:             my $contentchg;
1.633     raeburn  4752:             if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492     raeburn  4753:                 $contentchg = 1;
                   4754:             }
                   4755: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329     droeschl 4756: 	    return $errtext if ($fatal);
                   4757: 	}
1.538     raeburn  4758: 
                   4759: # Cut, copy and/or remove multiple resources
                   4760:         if ($env{'form.multichange'}) {
                   4761:             my %allchecked = (
                   4762:                                cut     => {},
                   4763:                                remove  => {},
                   4764:                              );
                   4765:             my $needsupdate;
                   4766:             foreach my $which (keys(%allchecked)) {
                   4767:                 $env{'form.multi'.$which} =~ s/,$//;
                   4768:                 if ($env{'form.multi'.$which}) {
                   4769:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
                   4770:                     if (ref($allchecked{$which}) eq 'HASH') {
                   4771:                         $needsupdate += scalar(keys(%{$allchecked{$which}}));
                   4772:                     }
                   4773:                 }
                   4774:             }
                   4775:             if ($needsupdate) {
                   4776:                 my $haschanges = 0;
                   4777:                 my %curr_groups = &Apache::longroup::coursegroups();
                   4778:                 my $total = scalar(@LONCAPA::map::order) - 1; 
                   4779:                 for (my $i=$total; $i>=0; $i--) {
                   4780:                     my $res = $LONCAPA::map::order[$i];
                   4781:                     my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   4782:                     $name=&LONCAPA::map::qtescape($name);
                   4783:                     $url=&LONCAPA::map::qtescape($url);
1.586     droeschl 4784:                     next unless $url;
1.538     raeburn  4785:                     my %denied =
                   4786:                         &action_restrictions($coursenum,$coursedom,$url,
                   4787:                                              $env{'form.folderpath'},\%curr_groups);
                   4788:                     foreach my $which (keys(%allchecked)) {
                   4789:                         next if ($denied{$which});
                   4790:                         next unless ($allchecked{$which}{$res});
                   4791:                         if ($which eq 'remove') {
                   4792:                             if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   4793:                                 ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   4794:                                 &Apache::lonnet::removeuploadedurl($url);
                   4795:                             } else {
                   4796:                                 &LONCAPA::map::makezombie($res);
                   4797:                             }
                   4798:                             splice(@LONCAPA::map::order,$i,1);
                   4799:                             $haschanges ++;
                   4800:                         } elsif ($which eq 'cut') {
                   4801:                             &LONCAPA::map::makezombie($res);
                   4802:                             splice(@LONCAPA::map::order,$i,1);
                   4803:                             $haschanges ++;
                   4804:                         }
                   4805:                     }
                   4806:                 }
                   4807:                 if ($haschanges) {
                   4808:                     ($errtext,$fatal) = 
                   4809:                         &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   4810:                     return $errtext if ($fatal);
                   4811:                 }
                   4812:             }
                   4813:         }
                   4814: 
1.329     droeschl 4815: # Group import/search
                   4816: 	if ($env{'form.importdetail'}) {
                   4817: 	    my @imports;
                   4818: 	    foreach my $item (split(/\&/,$env{'form.importdetail'})) {
                   4819: 		if (defined($item)) {
                   4820: 		    my ($name,$url,$residx)=
1.533     raeburn  4821: 			map { &unescape($_); } split(/\=/,$item);
                   4822:                     if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
                   4823:                         my ($suffix,$errortxt,$locknotfreed) =
                   4824:                             &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504     raeburn  4825:                         if ($locknotfreed) {
                   4826:                             $r->print($locknotfreed);
                   4827:                         }
                   4828:                         if ($suffix) {
                   4829:                             $url =~ s/_new\./_$suffix./; 
                   4830:                         } else {
                   4831:                             return $errortxt;
                   4832:                         }
1.533     raeburn  4833:                     } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
                   4834:                         my $type = $1;
                   4835:                         my ($suffix,$errortxt,$locknotfreed) =
                   4836:                             &new_timebased_suffix($coursedom,$coursenum,$type);
                   4837:                         if ($locknotfreed) {
                   4838:                             $r->print($locknotfreed);
                   4839:                         }
                   4840:                         if ($suffix) {
                   4841:                             $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
                   4842:                         } else {
                   4843:                             return $errortxt;
                   4844:                         }
1.626     raeburn  4845:                     } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598     raeburn  4846:                         my ($suffix,$errortxt,$locknotfreed) =
                   4847:                             &new_timebased_suffix($coursedom,$coursenum,'exttool');
                   4848:                         if ($locknotfreed) {
                   4849:                             $r->print($locknotfreed);
                   4850:                         }
                   4851:                         if ($suffix) {
                   4852:                             $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
                   4853:                         } else {
                   4854:                             return $errortxt;
                   4855:                         }
1.534     raeburn  4856:                     } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
                   4857:                         if ($supplementalflag) {
                   4858:                             next unless ($1 eq 'supplemental');
                   4859:                             if ($folder eq 'supplemental') {
                   4860:                                 next unless ($2 eq 'default');
                   4861:                             } else {
                   4862:                                 next unless ($folder eq 'supplemental_'.$2);
                   4863:                             }
                   4864:                         } else {
                   4865:                             next unless ($1 eq 'docs');
                   4866:                             if ($folder eq 'default') {
                   4867:                                 next unless ($2 eq 'default');
                   4868:                             } else {
                   4869:                                 next unless ($folder eq 'default_'.$2);
                   4870:                             }
                   4871:                         }
1.504     raeburn  4872:                     }
1.329     droeschl 4873: 		    push(@imports, [$name, $url, $residx]);
                   4874: 		}
                   4875: 	    }
1.530     raeburn  4876:             ($errtext,$fatal,my $fixuperrors) =
1.529     raeburn  4877:                 &group_import($coursenum, $coursedom, $folder,$container,
1.598     raeburn  4878:                               'londocs',$ltitoolsref,@imports);
1.329     droeschl 4879: 	    return $errtext if ($fatal);
1.529     raeburn  4880:             if ($fixuperrors) {
                   4881:                 $r->print($fixuperrors);
                   4882:             }
1.329     droeschl 4883: 	}
                   4884: # Loading a complete map
                   4885: 	if ($env{'form.loadmap'}) {
                   4886: 	    if ($env{'form.importmap'}=~/\w/) {
                   4887: 		foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
                   4888: 		    my ($title,$url,$ext,$type)=split(/\:/,$res);
                   4889: 		    my $idx=&LONCAPA::map::getresidx($url);
                   4890: 		    $LONCAPA::map::resources[$idx]=$res;
                   4891: 		    $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
                   4892: 		}
                   4893: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  4894: 					    $folder.'.'.$container,1);
1.329     droeschl 4895: 		return $errtext if ($fatal);
                   4896: 	    } else {
                   4897: 		$r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364     bisitz   4898: 
1.329     droeschl 4899: 	    }
                   4900: 	}
                   4901: 	&log_differences($plain);
                   4902:     }
                   4903: # ---------------------------------------------------------------- End commands
                   4904: # ---------------------------------------------------------------- Print screen
                   4905:     my $idx=0;
                   4906:     my $shown=0;
                   4907:     if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381     bisitz   4908: 	$r->print('<div class="LC_Box">'.
1.432     raeburn  4909:           '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
                   4910: 		  ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
                   4911: 		  ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
                   4912: 		  ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
                   4913: 		  ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431     raeburn  4914: 		  '</ol>');
1.381     bisitz   4915:         if ($randompick>=0) {
                   4916:             $r->print('<p class="LC_warning">'
                   4917:                  .&mt('Caution: this folder is set to randomly pick a subset'
                   4918:                      .' of resources. Adding or removing resources from this'
                   4919:                      .' folder will change the set of resources that the'
                   4920:                      .' students see, resulting in spurious or missing credit'
                   4921:                      .' for completed problems, not limited to ones you'
                   4922:                      .' modify. Do not modify the contents of this folder if'
                   4923:                      .' it is in active student use.')
                   4924:                  .'</p>'
                   4925:             );
                   4926:         }
                   4927:         if ($is_random_order) {
                   4928:             $r->print('<p class="LC_warning">'
                   4929:                  .&mt('Caution: this folder is set to randomly order its'
                   4930:                      .' contents. Adding or removing resources from this folder'
                   4931:                      .' will change the order of resources shown.')
                   4932:                  .'</p>'
                   4933:             );
                   4934:         }
                   4935:         $r->print('</div>');
1.364     bisitz   4936:     }
1.381     bisitz   4937: 
1.685     raeburn  4938:     if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688     raeburn  4939:         my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn  4940:         if (ref($supplemental) eq 'HASH') {
                   4941:             if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
                   4942:                 (ref($supplemental->{'ids'}) eq 'HASH')) {
                   4943:                 if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
                   4944:                     my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
                   4945:                     if ($supplemental->{'hidden'}->{$mapnum}) {
                   4946:                         $ishidden = 1;
                   4947:                     }
                   4948:                 }
                   4949:             }
                   4950:         }
                   4951:     }
                   4952: 
1.538     raeburn  4953:     my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
                   4954:     %filters =  (
1.543     raeburn  4955:                   canremove      => [],
                   4956:                   cancut         => [],
                   4957:                   cancopy        => [],
                   4958:                   hiddenresource => [],
                   4959:                   encrypturl     => [],
                   4960:                   randomorder    => [],
                   4961:                   randompick     => [],
1.538     raeburn  4962:                 );
                   4963:     %curr_groups = &Apache::longroup::coursegroups();
1.424     onken    4964:     &Apache::loncommon::start_data_table_count(); #setup a row counter 
1.381     bisitz   4965:     foreach my $res (@LONCAPA::map::order) {
                   4966:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   4967:         $name=&LONCAPA::map::qtescape($name);
                   4968:         $url=&LONCAPA::map::qtescape($url);
                   4969:         unless ($name) {  $name=(split(/\//,$url))[-1]; }
                   4970:         unless ($name) { $idx++; next; }
1.537     raeburn  4971:         push(@allidx,$res);
                   4972:         if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   4973:             push(@allmapidx,$res);
                   4974:         }
1.617     raeburn  4975: 
1.682     raeburn  4976:         if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685     raeburn  4977:             if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
                   4978:                 $idx++;
                   4979:                 next;
                   4980:             }
1.682     raeburn  4981:         }
1.381     bisitz   4982:         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501     raeburn  4983:                               $coursenum,$coursedom,$crstype,
1.538     raeburn  4984:                               $pathitem,$supplementalflag,$container,
1.620     raeburn  4985:                               \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685     raeburn  4986:                               $isencrypted,$ishidden,$navmapref,$hostname);
1.381     bisitz   4987:         $idx++;
                   4988:         $shown++;
1.329     droeschl 4989:     }
1.424     onken    4990:     &Apache::loncommon::end_data_table_count();
1.510     raeburn  4991: 
1.538     raeburn  4992:     my $need_save;
1.611     raeburn  4993:     if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544     raeburn  4994:         my $toolslink;
1.682     raeburn  4995:         if ($allowed || $canedit) {
                   4996:             my $helpitem = 'Navigation_Screen';
                   4997:             if (!$allowed) {
                   4998:                 $helpitem = 'Supplemental_Navigation';
                   4999:             }
1.723     raeburn  5000:             $toolslink = '<div class="LC_navtools">'
                   5001:                        .'<div class="LC_navtools">'
1.520     raeburn  5002:                        .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682     raeburn  5003:                                                            $helpitem,undef,'RAT')
1.723     raeburn  5004:                        .'</div><div class="LC_navtools">'.&mt('Tools:').'</div>'
1.724     raeburn  5005:                        .'<div class="LC_navtools">'."\n".'<ul id="LC_toolbar">'
1.525     raeburn  5006:                        .'<li><a href="/adm/coursedocs?forcesupplement=1&amp;command=editsupp" '
1.520     raeburn  5007:                        .'id="LC_content_toolbar_edittoplevel" '
                   5008:                        .'class="LC_toolbarItem" '
                   5009:                        .'title="'.&mt('Supplemental Content Editor').'">'
1.723     raeburn  5010:                        .'</a></li></ul></div></div>'."\n"
                   5011:                        .'<div style="padding:0;clear:both;margin:0;border:0"></div><br />'."\n";
1.544     raeburn  5012:         }
1.510     raeburn  5013:         if ($shown) {
                   5014:             if ($allowed) {
                   5015:                 $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
                   5016:                           .&Apache::loncommon::start_data_table(undef,'contentlist')
                   5017:                           .&Apache::loncommon::start_data_table_header_row()
                   5018:                           .'<th colspan="2">'.&mt('Move').'</th>'
1.633     raeburn  5019:                           .'<th colspan="3">'.&mt('Actions').'</th>'
1.682     raeburn  5020:                           .'<th>'.&mt('Document').'</th>'
                   5021:                           .'<th colspan="2">'.&mt('Settings').'</th>'
                   5022:                           .&Apache::loncommon::end_data_table_header_row();
1.537     raeburn  5023:                 if ($folder !~ /^supplemental/) {
1.538     raeburn  5024:                     $lists{'canhide'} = join(',',@allidx);
                   5025:                     $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543     raeburn  5026:                     my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
                   5027:                                        'randomorder','randompick');
                   5028:                     foreach my $item (@possfilters) {
1.538     raeburn  5029:                         if (ref($filters{$item}) eq 'ARRAY') {
1.543     raeburn  5030:                             if (@{$filters{$item}} > 0) {
                   5031:                                 $lists{$item} = join(',',@{$filters{$item}});
                   5032:                             }
1.538     raeburn  5033:                         }
                   5034:                     }
1.537     raeburn  5035:                     if (@allidx > 0) {
                   5036:                         my $path;
                   5037:                         if ($env{'form.folderpath'}) {
1.630     raeburn  5038:                             $path =
1.537     raeburn  5039:                                 &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   5040:                         }
1.538     raeburn  5041:                         if (@allidx > 1) {
1.630     raeburn  5042:                             $to_show .=
1.538     raeburn  5043:                                 &Apache::loncommon::continue_data_table_row().
                   5044:                                 '<td colspan="2">&nbsp;</td>'.
                   5045:                                 '<td>'.
1.611     raeburn  5046:                                 &multiple_check_form('actions',\%lists,$canedit).
1.538     raeburn  5047:                                 '</td>'.
1.633     raeburn  5048:                                 '<td colspan="3">&nbsp;</td>'.
                   5049:                                 '<td colspan="2">'.
1.611     raeburn  5050:                                 &multiple_check_form('settings',\%lists,$canedit).
1.538     raeburn  5051:                                 '</td>'.
                   5052:                                 &Apache::loncommon::end_data_table_row();
                   5053:                              $need_save = 1;
                   5054:                         }
1.537     raeburn  5055:                     }
                   5056:                 }
                   5057:                 $to_show .= $output.' '
1.510     raeburn  5058:                            .&Apache::loncommon::end_data_table()
                   5059:                            .'<br style="line-height:2px;" />'
                   5060:                            .&Apache::loncommon::end_scrollbox();
                   5061:             } else {
1.520     raeburn  5062:                 $to_show .= $toolslink
1.510     raeburn  5063:                            .&Apache::loncommon::start_data_table('LC_tableOfContent')
1.725     raeburn  5064:                            .&Apache::loncommon::start_data_table_header_row('LC_visually_hidden')
                   5065:                            .'<th>'.&mt('Resource Type (Icon)').'</th><th>'.&mt('Resource or Folder').'</th>'
                   5066:                            .&Apache::loncommon::end_data_table_header_row()
1.510     raeburn  5067:                            .$output.' '
                   5068:                            .&Apache::loncommon::end_data_table();
1.393     raeburn  5069:             }
1.510     raeburn  5070:         } else {
1.520     raeburn  5071:             if (!$allowed) {
                   5072:                 $to_show .= $toolslink;
                   5073:             }
1.615     raeburn  5074:             my $noresmsg;
                   5075:             if ($allowed && $hiddentop && !$supplementalflag) {
                   5076:                 $noresmsg = &mt('Main Content Hidden'); 
                   5077:             } else {
                   5078:                 $noresmsg = &mt('Currently empty');
                   5079:             }
1.510     raeburn  5080:             $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
                   5081:                        .'<div class="LC_info" id="contentlist">'
1.615     raeburn  5082:                        .$noresmsg
1.510     raeburn  5083:                        .'</div>'
                   5084:                        .&Apache::loncommon::end_scrollbox();
1.393     raeburn  5085:         }
                   5086:     } else {
1.510     raeburn  5087:         if ($shown) {
                   5088:             $to_show = '<div>'
                   5089:                       .&Apache::loncommon::start_data_table('LC_tableOfContent')
                   5090:                       .$output
                   5091:                       .&Apache::loncommon::end_data_table()
                   5092:                       .'</div>';
                   5093:         } else {
                   5094:             $to_show = '<div class="LC_info" id="contentlist">'
1.550     raeburn  5095:                       .&mt('Currently empty')
1.510     raeburn  5096:                       .'</div>'
                   5097:         }
1.458     raeburn  5098:     }
                   5099:     my $tid = 1;
                   5100:     if ($supplementalflag) {
                   5101:         $tid = 2;
1.329     droeschl 5102:     }
                   5103:     if ($allowed) {
1.484     raeburn  5104:         my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538     raeburn  5105:         $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611     raeburn  5106:                                        $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
                   5107:         if ($canedit) {
                   5108:             &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
                   5109:         }
1.460     raeburn  5110:     } else {
                   5111:         $r->print($to_show);
1.329     droeschl 5112:     }
                   5113:     return;
                   5114: }
                   5115: 
1.538     raeburn  5116: sub multiple_check_form {
1.611     raeburn  5117:     my ($caller,$listsref,$canedit) = @_;
1.538     raeburn  5118:     return unless (ref($listsref) eq 'HASH');
1.611     raeburn  5119:     my $disabled;
                   5120:     unless ($canedit) {
1.700     raeburn  5121:         $disabled = ' disabled="disabled"';
1.611     raeburn  5122:     }
1.538     raeburn  5123:     my $output =
                   5124:     '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
                   5125:     '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
                   5126:     '<label><input type="radio" name="showmultpick" value="0" onclick="javascript:togglePick('."'$caller','0'".');" checked="checked" />'.&mt('one').'</label>'.('&nbsp;'x2).'<label><input type="radio" name="showmultpick" value="1" onclick="javascript:togglePick('."'$caller','1'".');" />'.&mt('multiple').'</label></span><span id="more'.$caller.'" class="LC_nobreak LC_docs_ext_edit"></span></form>'.
                   5127:     '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
                   5128:     '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
                   5129:     '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
                   5130:     if ($caller eq 'settings') {
                   5131:         $output .= 
                   5132:             '<table><tr>'.
                   5133:             '<td class="LC_docs_entry_parameter">'.
                   5134:             '<span class="LC_nobreak"><label>'.
1.611     raeburn  5135:             '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538     raeburn  5136:             '</label></span></td>'.
                   5137:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  5138:             '<span class="LC_nobreak"><label><input type="checkbox" name="randompickall" id="randompickall" onclick="updatePick(this.form,'."'all','check'".');propagateState(this.form,'."'randompick'".');propagateState(this.form,'."'rpicknum'".');"'.$disabled.' />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
1.538     raeburn  5139:             '</span></td>'.
                   5140:             '</tr>'."\n".
                   5141:             '<tr>'.
                   5142:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  5143:             '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')"'.$disabled.' />'.&mt('URL hidden').'</label></span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><label><input type="checkbox" name="randomorderall" id="randomorderall" onclick="propagateState(this.form,'."'randomorder'".')"'.$disabled.' />'.&mt('Random Order').
1.538     raeburn  5144:             '</label></span>'.
                   5145:             '</td></tr></table>'."\n";
                   5146:     } else {
                   5147:         $output .=
                   5148:             '<table><tr>'.
                   5149:             '<td class="LC_docs_entry_parameter">'.
                   5150:             '<span class="LC_nobreak LC_docs_remove">'.
1.611     raeburn  5151:             '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538     raeburn  5152:             '</label></span></td>'.
                   5153:             '<td class="LC_docs_entry_parameter">'.
                   5154:             '<span class="LC_nobreak LC_docs_cut">'.
1.611     raeburn  5155:             '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538     raeburn  5156:             '</label></span></td>'."\n".
                   5157:             '<td class="LC_docs_entry_parameter">'.
                   5158:             '<span class="LC_nobreak LC_docs_copy">'.
1.700     raeburn  5159:             '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538     raeburn  5160:             '</label></span></td>'.
                   5161:             '</tr></table>'."\n";
                   5162:     }
                   5163:     $output .= 
                   5164:         '</fieldset>'.
                   5165:         '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
                   5166:     if ($caller eq 'settings') {
                   5167:         $output .= 
1.543     raeburn  5168:         '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
                   5169:         '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
                   5170:         '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
                   5171:         '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
                   5172:         '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538     raeburn  5173:     } elsif ($caller eq 'actions') {
                   5174:         $output .=
                   5175:         '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
                   5176:         '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
                   5177:         '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
                   5178:     }
                   5179:     $output .= 
                   5180:         '</form>'.
                   5181:         '</div>';
                   5182:     return $output;
                   5183: }
                   5184: 
1.329     droeschl 5185: sub process_file_upload {
1.552     raeburn  5186:     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329     droeschl 5187: # upload a file, if present
1.552     raeburn  5188:     my $filesize = length($env{'form.uploaddoc'});
                   5189:     if (!$filesize) {
                   5190:         $$upload_output = '<div class="LC_error">'.
                   5191:                            &mt('Unable to upload [_1]. (size = [_2] bytes)',
                   5192:                           '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
                   5193:                           $filesize).'<br />'.
                   5194:                           &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
                   5195:                           '</div>';
                   5196:         return;
                   5197:     }
                   5198:     my $quotatype = 'unofficial';
                   5199:     if ($crstype eq 'Community') {
1.601     raeburn  5200:         $quotatype = 'community';
                   5201:     } elsif ($crstype eq 'Placement') {
                   5202:         $quotatype = 'placement';
1.580     raeburn  5203:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552     raeburn  5204:         $quotatype = 'official';
1.573     raeburn  5205:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   5206:         $quotatype = 'textbook';
1.552     raeburn  5207:     }
                   5208:     if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
                   5209:         $filesize = int($filesize/1000); #expressed in kb
                   5210:         $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579     raeburn  5211:                                                                       $env{'form.uploaddoc.filename'},$filesize,
                   5212:                                                                       'upload',$quotatype);
1.552     raeburn  5213:         return if ($$upload_output);
                   5214:     }
1.440     raeburn  5215:     my ($parseaction,$showupload,$nextphase,$mimetype);
                   5216:     if ($env{'form.parserflag'}) {
1.329     droeschl 5217:         $parseaction = 'parse';
                   5218:     }
                   5219:     my $folder=$env{'form.folder'};
                   5220:     if ($folder eq '') {
                   5221:         $folder='default';
                   5222:     }
                   5223:     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
                   5224:         my $errtext='';
                   5225:         my $fatal=0;
                   5226:         my $container='sequence';
1.519     raeburn  5227:         if ($env{'form.folderpath'} =~ /:1$/) {
1.329     droeschl 5228:             $container='page';
                   5229:         }
                   5230:         ($errtext,$fatal)=
1.534     raeburn  5231:             &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329     droeschl 5232:         if ($#LONCAPA::map::order<1) {
                   5233:             $LONCAPA::map::order[0]=1;
                   5234:             $LONCAPA::map::resources[1]='';
                   5235:         }
                   5236:         my $destination = 'docs/';
                   5237:         if ($folder =~ /^supplemental/) {
                   5238:             $destination = 'supplemental/';
                   5239:         }
                   5240:         if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   5241:             $destination .= 'default/';
                   5242:         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   5243:             $destination .=  $2.'/';
                   5244:         }
1.534     raeburn  5245:         if ($fatal) {
                   5246:             $$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>';
                   5247:             return;
                   5248:         }
1.440     raeburn  5249: # this is for a course, not a user, so set context to coursedoc.
1.329     droeschl 5250:         my $newidx=&LONCAPA::map::getresidx();
                   5251:         $destination .= $newidx;
1.439     raeburn  5252:         my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329     droeschl 5253: 						$parseaction,$allfiles,
1.440     raeburn  5254: 						$codebase,undef,undef,undef,undef,
                   5255:                                                 undef,undef,\$mimetype);
                   5256:         if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
                   5257:             my $stored = $1;
                   5258:             $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   5259:                           $stored.'</span>').'</p>';
                   5260:         } else {
                   5261:             my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
                   5262:             
1.457     raeburn  5263:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440     raeburn  5264:             return;
                   5265:         }
1.329     droeschl 5266:         my $ext='false';
                   5267:         if ($url=~m{^http://}) { $ext='true'; }
                   5268: 	$url     = &LONCAPA::map::qtunescape($url);
                   5269:         my $comment=$env{'form.comment'};
                   5270: 	$comment = &LONCAPA::map::qtunescape($comment);
                   5271:         if ($folder=~/^supplemental/) {
                   5272:               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   5273:                   $env{'user.domain'}.'___&&&___'.$comment;
                   5274:         }
                   5275: 
                   5276:         $LONCAPA::map::resources[$newidx]=
                   5277: 	    $comment.':'.$url.':'.$ext.':normal:res';
                   5278:         $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
                   5279:         ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  5280: 				    $folder.'.'.$container,1);
1.329     droeschl 5281:         if ($fatal) {
1.457     raeburn  5282:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440     raeburn  5283:             return;
1.329     droeschl 5284:         } else {
1.440     raeburn  5285:             if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
                   5286:                 $$upload_output = $showupload;
1.384     raeburn  5287:                 my $total_embedded = scalar(keys(%{$allfiles}));
1.329     droeschl 5288:                 if ($total_embedded > 0) {
1.440     raeburn  5289:                     my $uploadphase = 'upload_embedded';
                   5290:                     my $primaryurl = &HTML::Entities::encode($url,'<>&"');
                   5291: 		    my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx); 
1.630     raeburn  5292:                     my ($embedded,$num) =
1.440     raeburn  5293:                         &Apache::loncommon::ask_for_embedded_content(
                   5294:                             '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
                   5295:                     if ($embedded) {
                   5296:                         if ($num) {
                   5297:                             $$upload_output .=
                   5298: 			         '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
                   5299:                             $nextphase = $uploadphase;
                   5300:                         } else {
                   5301:                             $$upload_output .= $embedded;
                   5302:                         }
                   5303:                     } else {
                   5304:                         $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
                   5305:                     }
1.329     droeschl 5306:                 } else {
1.440     raeburn  5307:                     $$upload_output .= &mt('No embedded items identified').'<br />';
1.329     droeschl 5308:                 }
1.457     raeburn  5309:                 $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578     raeburn  5310:             } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
                   5311:                      ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476     raeburn  5312:                 $nextphase = 'decompress_uploaded';
                   5313:                 my $position = scalar(@LONCAPA::map::order)-1;
                   5314:                 my $noextract = &return_to_editor();
                   5315:                 my $archiveurl = &HTML::Entities::encode($url,'<>&"');
                   5316:                 my %archiveitems = (
                   5317:                     folderpath => $env{'form.folderpath'},
                   5318:                     cmd        => $nextphase,
                   5319:                     newidx     => $newidx,
                   5320:                     position   => $position,
                   5321:                     phase      => $nextphase,
1.477     raeburn  5322:                     comment    => $comment,
1.480     raeburn  5323:                 );
                   5324:                 my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
                   5325:                 my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx); 
1.476     raeburn  5326:                 $$upload_output = $showupload.
                   5327:                                   &Apache::loncommon::decompress_form($mimetype,
                   5328:                                       $archiveurl,'/adm/coursedocs',$noextract,
1.480     raeburn  5329:                                       \%archiveitems,\@current);
1.329     droeschl 5330:             }
                   5331:         }
                   5332:     }
1.440     raeburn  5333:     return $nextphase;
1.329     droeschl 5334: }
                   5335: 
1.480     raeburn  5336: sub get_dir_list {
                   5337:     my ($url,$coursenum,$coursedom,$newidx) = @_;
                   5338:     my ($destination,$dir_root) = &embedded_destination();
                   5339:     my ($dirlistref,$listerror) =  
                   5340:         &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
                   5341:     my @dir_lines;
                   5342:     my $dirptr=16384;
                   5343:     if (ref($dirlistref) eq 'ARRAY') {
                   5344:         foreach my $dir_line (sort
                   5345:                           {
                   5346:                               my ($afile)=split('&',$a,2);
                   5347:                               my ($bfile)=split('&',$b,2);
                   5348:                               return (lc($afile) cmp lc($bfile));
                   5349:                           } (@{$dirlistref})) {
                   5350:             my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
                   5351:             $filename =~ s/\s+$//;
                   5352:             next if ($filename =~ /^\.\.?$/); 
                   5353:             my $isdir = 0;
                   5354:             if ($dirptr&$testdir) {
                   5355:                 $isdir = 1;
                   5356:             }
                   5357:             push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
                   5358:         }
                   5359:     }
                   5360:     return @dir_lines;
                   5361: }
                   5362: 
1.329     droeschl 5363: sub is_supplemental_title {
                   5364:     my ($title) = @_;
                   5365:     return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
                   5366: }
                   5367: 
                   5368: # --------------------------------------------------------------- An entry line
                   5369: 
                   5370: sub entryline {
1.501     raeburn  5371:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598     raeburn  5372:         $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685     raeburn  5373:         $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687     raeburn  5374:     my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329     droeschl 5375:     if (&is_supplemental_title($title)) {
1.488     raeburn  5376: 	($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687     raeburn  5377:         $encodedtitle=$title;
1.329     droeschl 5378:     } else {
                   5379: 	$title=&HTML::Entities::encode($title,'"<>&\'');
1.687     raeburn  5380:         $encodedtitle=$title;
1.329     droeschl 5381: 	$renametitle=$title;
                   5382: 	$foldertitle=$title;
                   5383:     }
                   5384: 
1.611     raeburn  5385:     my ($disabled,$readonly,$js_lt);
                   5386:     unless ($canedit) {
                   5387:         $disabled = 'disabled="disabled"';
                   5388:         $readonly = 1;
                   5389:     }
                   5390: 
1.329     droeschl 5391:     my $orderidx=$LONCAPA::map::order[$index];
1.364     bisitz   5392: 
1.329     droeschl 5393:     $renametitle=~s/\\/\\\\/g;
                   5394:     $renametitle=~s/\&quot\;/\\\"/g;
1.585     raeburn  5395:     $renametitle=~s/"/%22/g;
1.581     raeburn  5396:     $renametitle=~s/ /%20/g;
                   5397:     $oldtitle = $renametitle;
1.576     raeburn  5398:     $renametitle=~s/\&#39;/\\\'/g;
1.379     bisitz   5399:     my $line=&Apache::loncommon::start_data_table_row();
1.538     raeburn  5400:     my ($form_start,$form_end,$form_common,$form_param);
1.329     droeschl 5401: # Edit commands
1.679     raeburn  5402:     my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329     droeschl 5403:     if ($env{'form.folderpath'}) {
                   5404: 	$esc_path=&escape($env{'form.folderpath'});
                   5405: 	$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   5406: 	# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
                   5407:     }
1.505     raeburn  5408:     my $isexternal;
1.510     raeburn  5409:     if ($residx) {
1.501     raeburn  5410:         my $currurl = $url;
                   5411:         $currurl =~ s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
1.505     raeburn  5412:         if ($currurl =~ m{^/adm/wrapper/ext/}) {
                   5413:             $isexternal = 1;
                   5414:         }
1.510     raeburn  5415:         if (!$supplementalflag) {
                   5416:             my $path = 'uploaded/'.
                   5417:                        $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   5418:                        $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
                   5419:             $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
                   5420:                                                  $residx,
                   5421:                                                  &Apache::lonnet::declutter($currurl));
                   5422:         }
1.501     raeburn  5423:     }
1.538     raeburn  5424:     my ($renamelink,%lt,$ishash);
                   5425:     if (ref($filtersref) eq 'HASH') {
                   5426:         $ishash = 1;
                   5427:     }
                   5428: 
1.329     droeschl 5429:     if ($allowed) {
1.538     raeburn  5430:         $form_start = '
                   5431:    <form action="/adm/coursedocs" method="post">
                   5432: ';
                   5433:         $form_common=(<<END);
                   5434:    <input type="hidden" name="folderpath" value="$path" />
                   5435:    <input type="hidden" name="symb" value="$symb" />
                   5436: END
                   5437:         $form_param=(<<END);
                   5438:    <input type="hidden" name="setparms" value="$orderidx" />
                   5439:    <input type="hidden" name="changeparms" value="0" />
                   5440: END
                   5441:         $form_end = '</form>';
                   5442: 
1.329     droeschl 5443: 	my $incindex=$index+1;
                   5444: 	my $selectbox='';
1.471     raeburn  5445: 	if (($#LONCAPA::map::order>0) &&
1.329     droeschl 5446: 	    ((split(/\:/,
1.344     bisitz   5447: 	     $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
                   5448: 	     ne '') &&
1.329     droeschl 5449: 	    ((split(/\:/,
1.344     bisitz   5450: 	     $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329     droeschl 5451: 	     ne '')) {
                   5452: 	    $selectbox=
                   5453: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611     raeburn  5454: 		'<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329     droeschl 5455: 	    for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
                   5456: 		if ($i==$incindex) {
1.358     bisitz   5457: 		    $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329     droeschl 5458: 		} else {
                   5459: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
                   5460: 		}
                   5461: 	    }
                   5462: 	    $selectbox.='</select>';
                   5463: 	}
1.501     raeburn  5464: 	%lt=&Apache::lonlocal::texthash(
1.329     droeschl 5465:                 'up' => 'Move Up',
                   5466: 		'dw' => 'Move Down',
                   5467: 		'rm' => 'Remove',
                   5468:                 'ct' => 'Cut',
                   5469: 		'rn' => 'Rename',
1.501     raeburn  5470: 		'cp' => 'Copy',
1.633     raeburn  5471:                 'da' => 'Unset alias', 
                   5472:                 'sa' => 'Set alias',
1.501     raeburn  5473:                 'ex' => 'External Resource',
1.598     raeburn  5474:                 'et' => 'External Tool',
1.501     raeburn  5475:                 'ed' => 'Edit',
                   5476:                 'pr' => 'Preview',
                   5477:                 'sv' => 'Save',
                   5478:                 'ul' => 'URL',
1.611     raeburn  5479:                 'ti' => 'Title',
1.618     raeburn  5480:                 'er' => 'Editing rights unavailable for your current role.', 
1.501     raeburn  5481:                 );
1.538     raeburn  5482: 	my %denied = &action_restrictions($coursenum,$coursedom,$url,
                   5483:                                           $env{'form.folderpath'},
                   5484:                                           $currgroups);
1.517     raeburn  5485:         my ($copylink,$cutlink,$removelink);
1.329     droeschl 5486: 	my $skip_confirm = 0;
1.603     raeburn  5487:         my $confirm_removal = 0;
1.329     droeschl 5488: 	if ( $folder =~ /^supplemental/
                   5489: 	     || ($url =~ m{( /smppg$
                   5490: 			    |/syllabus$
                   5491: 			    |/aboutme$
                   5492: 			    |/navmaps$
                   5493: 			    |/bulletinboard$
1.626     raeburn  5494:                             |/ext\.tool$
1.505     raeburn  5495: 			    |\.html$)}x)
                   5496:              || $isexternal) {
1.329     droeschl 5497: 	    $skip_confirm = 1;
                   5498: 	}
1.603     raeburn  5499:         if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   5500:             ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   5501:             $confirm_removal = 1;
                   5502:         }
1.633     raeburn  5503:         if ($url =~ /$LONCAPA::assess_re/) {
                   5504:             $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
                   5505:         }
1.329     droeschl 5506: 
1.538     raeburn  5507: 	if ($denied{'copy'}) {
1.543     raeburn  5508:             $copylink=(<<ENDCOPY)
1.507     raeburn  5509: <span style="visibility: hidden;">$lt{'cp'}</span>
                   5510: ENDCOPY
                   5511:         } else {
1.538     raeburn  5512:             my $formname = 'edit_copy_'.$orderidx;
                   5513:             my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 5514: 	    $copylink=(<<ENDCOPY);
1.538     raeburn  5515: <form name="$formname" method="post" action="/adm/coursedocs">
                   5516: $form_common
1.723     raeburn  5517: <label><input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a></label>
1.538     raeburn  5518: $form_end
1.329     droeschl 5519: ENDCOPY
1.538     raeburn  5520:             if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
                   5521:                 push(@{$filtersref->{'cancopy'}},$orderidx);
                   5522:             }
1.329     droeschl 5523:         }
1.538     raeburn  5524: 	if ($denied{'cut'}) {
1.507     raeburn  5525:             $cutlink=(<<ENDCUT);
                   5526: <span style="visibility: hidden;">$lt{'ct'}</span>
                   5527: ENDCUT
                   5528:         } else {
1.538     raeburn  5529:             my $formname = 'edit_cut_'.$orderidx;
                   5530:             my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 5531: 	    $cutlink=(<<ENDCUT);
1.538     raeburn  5532: <form name="$formname" method="post" action="/adm/coursedocs">
                   5533: $form_common
1.542     raeburn  5534: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.723     raeburn  5535: <label><input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a></label>
1.538     raeburn  5536: $form_end
1.329     droeschl 5537: ENDCUT
1.538     raeburn  5538:             if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
                   5539:                 push(@{$filtersref->{'cancut'}},$orderidx);
                   5540:             }
1.329     droeschl 5541:         }
1.538     raeburn  5542:         if ($denied{'remove'}) {
1.507     raeburn  5543:             $removelink=(<<ENDREM);
                   5544: <span style="visibility: hidden;">$lt{'rm'}</a>
                   5545: ENDREM
                   5546:         } else {
1.538     raeburn  5547:             my $formname = 'edit_remove_'.$orderidx;
1.603     raeburn  5548:             my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497     raeburn  5549:             $removelink=(<<ENDREM);
1.538     raeburn  5550: <form name="$formname" method="post" action="/adm/coursedocs">
                   5551: $form_common
1.542     raeburn  5552: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603     raeburn  5553: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.723     raeburn  5554: <label><input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a></label>
1.538     raeburn  5555: $form_end
1.497     raeburn  5556: ENDREM
1.538     raeburn  5557:             if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
                   5558:                 push(@{$filtersref->{'canremove'}},$orderidx);
                   5559:             }
1.497     raeburn  5560:         }
1.551     raeburn  5561:         $renamelink=(<<ENDREN);
1.581     raeburn  5562: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507     raeburn  5563: ENDREN
1.611     raeburn  5564:         my ($uplink,$downlink);
                   5565:         if ($canedit) {
                   5566:             $uplink = "/adm/coursedocs?cmd=up_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   5567:             $downlink = "/adm/coursedocs?cmd=down_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   5568:         } else {
                   5569:             $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
                   5570:             $downlink = $uplink;
                   5571:         }
1.329     droeschl 5572: 	$line.=(<<END);
                   5573: <td>
1.379     bisitz   5574: <div class="LC_docs_entry_move">
1.611     raeburn  5575:   <a href="$uplink">
1.501     raeburn  5576:     <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379     bisitz   5577:   </a>
                   5578: </div>
                   5579: <div class="LC_docs_entry_move">
1.611     raeburn  5580:   <a href="$downlink">
1.501     raeburn  5581:     <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379     bisitz   5582:   </a>
                   5583: </div>
1.329     droeschl 5584: </td>
                   5585: <td>
                   5586:    $form_start
1.538     raeburn  5587:    $form_param
1.478     raeburn  5588:    $form_common
1.329     droeschl 5589:    $selectbox
                   5590:    $form_end
                   5591: </td>
1.540     raeburn  5592: <td class="LC_docs_entry_commands LC_nobreak">
1.497     raeburn  5593: $removelink
1.329     droeschl 5594: $cutlink
                   5595: $copylink
                   5596: </td>
                   5597: END
                   5598:     }
1.723     raeburn  5599:     my $icontext;
1.329     droeschl 5600: # Figure out what kind of a resource this is
                   5601:     my ($extension)=($url=~/\.(\w+)$/);
1.723     raeburn  5602:     if ($extension eq 'sequence') {
                   5603:         $icontext = &mt('folder icon');
                   5604:     } elsif ($extension eq 'page') {
                   5605:         $icontext = &mt('composite page icon');
                   5606:     } else {
                   5607:         $icontext = &mt('file icon');
                   5608:     }
                   5609:     $icontext = &HTML::Entities::encode($icontext);
1.329     droeschl 5610:     my $uploaded=($url=~/^\/*uploaded\//);
                   5611:     my $icon=&Apache::loncommon::icon($url);
1.519     raeburn  5612:     my $isfolder;
                   5613:     my $ispage;
                   5614:     my $containerarg;
1.615     raeburn  5615:     my $folderurl;
1.685     raeburn  5616:     my $plainurl;
1.329     droeschl 5617:     if ($uploaded) {
1.472     raeburn  5618:         if (($extension eq 'sequence') || ($extension eq 'page')) {
                   5619:             $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519     raeburn  5620:             $containerarg = $1;
1.472     raeburn  5621: 	    if ($extension eq 'sequence') {
                   5622: 	        $icon=$iconpath.'navmap.folder.closed.gif';
                   5623:                 $isfolder=1;
                   5624:             } else {
                   5625:                 $icon=$iconpath.'page.gif';
                   5626:                 $ispage=1;
                   5627:             }
1.615     raeburn  5628:             $folderurl = &Apache::lonnet::declutter($url);
1.472     raeburn  5629:             if ($allowed) {
                   5630:                 $url='/adm/coursedocs?';
                   5631:             } else {
                   5632:                 $url='/adm/supplemental?';
                   5633:             }
1.329     droeschl 5634: 	} else {
1.685     raeburn  5635: 	    $plainurl = $url;
1.329     droeschl 5636: 	}
                   5637:     }
1.364     bisitz   5638: 
1.621     raeburn  5639:     my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329     droeschl 5640:     my $orig_url = $url;
1.340     raeburn  5641:     $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.668     raeburn  5642:     if ($container eq 'page') {
                   5643:         $url=~s{^http(|s)(&colon;|:)//}{/ext/};
                   5644:     } else {
                   5645:         $url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
                   5646:     }
1.501     raeburn  5647:     if (!$supplementalflag && $residx && $symb) {
                   5648:         if ((!$isfolder) && (!$ispage)) {
                   5649: 	    (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668     raeburn  5650:             if (($url =~ m{^ext/}) && ($container eq 'page')) {
                   5651:                 $url=&Apache::lonnet::clutter_with_no_wrapper($url);
                   5652:             } else {
                   5653:                 $url=&Apache::lonnet::clutter($url);
                   5654:             } 
1.501     raeburn  5655: 	    if ($url=~/^\/*uploaded\//) {
                   5656: 	        $url=~/\.(\w+)$/;
                   5657: 	        my $embstyle=&Apache::loncommon::fileembstyle($1);
                   5658: 	        if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                   5659: 		    $url='/adm/wrapper'.$url;
                   5660: 	        } elsif ($embstyle eq 'ssi') {
                   5661: 		    #do nothing with these
                   5662: 	        } elsif ($url!~/\.(sequence|page)$/) {
                   5663: 		    $url='/adm/coursedocs/showdoc'.$url;
                   5664: 	        }
1.623     raeburn  5665: 	    } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
                   5666:                 my $wrapped = $1;
                   5667:                 my $exturl = $2;
1.668     raeburn  5668:                 if (($wrapped eq '') && ($container ne 'page')) { 
1.623     raeburn  5669:                     $url='/adm/wrapper'.$url;
                   5670:                 }
                   5671:                 if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
                   5672:                     $nomodal = 1;
                   5673:                 }
1.626     raeburn  5674: 	    } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  5675: 		$url='/adm/wrapper'.$url;
1.621     raeburn  5676:             } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
                   5677:                 if (($ENV{'SERVER_PORT'} == 443) &&
                   5678:                     ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  5679:                     unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  5680:                         $url .= '?usehttp=1';
                   5681:                     }
1.621     raeburn  5682:                     $nomodal = 1;
                   5683:                 }
1.598     raeburn  5684:             }
1.696     raeburn  5685:             my $checkencrypt;
1.680     raeburn  5686:             if (!$env{'request.role.adv'}) {
1.615     raeburn  5687:                 if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680     raeburn  5688:                     ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615     raeburn  5689:                     $checkencrypt = 1;
1.620     raeburn  5690:                 } elsif (ref($navmapref)) {
1.615     raeburn  5691:                     unless (ref($$navmapref)) {
                   5692:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   5693:                     }
                   5694:                     if (ref($$navmapref)) {
                   5695:                         if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680     raeburn  5696:                             $checkencrypt = 1;
1.615     raeburn  5697:                         }
                   5698:                     }
                   5699:                 }
1.680     raeburn  5700:             }
                   5701:             if ($checkencrypt) {
                   5702:                 my $currenc = $env{'request.enc'};
                   5703:                 $env{'request.enc'} = 1;
                   5704:                 $shownsymb = &Apache::lonenc::encrypted($symb);
1.696     raeburn  5705:                 my $shownurl = &Apache::lonenc::encrypted($url);
1.680     raeburn  5706:                 if (&Apache::lonnet::symbverify($symb,$url)) {
                   5707:                     $url = $shownurl;
                   5708:                 } else {
                   5709:                     $url = '';
                   5710:                 }
                   5711:                 $env{'request.enc'} = $currenc;
                   5712:             } elsif (&Apache::lonnet::symbverify($symb,$url)) {
                   5713:                 $shownsymb = $symb;
                   5714:                 if ($isexternal) {
                   5715:                     $url =~ s/\#[^#]+$//;
                   5716:                     if ($container eq 'page') {
                   5717:                         $url = &Apache::lonnet::clutter($url);
1.613     raeburn  5718:                     }
1.612     raeburn  5719:                 }
1.696     raeburn  5720:             } else {
                   5721:                 $url = '';
1.680     raeburn  5722:             }
                   5723:             unless ($env{'request.role.adv'}) {
                   5724:                 if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   5725:                     $url = '';
                   5726:                 }
                   5727:                 if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
                   5728:                     $url = '';
                   5729:                     $hiddenres = 1;
                   5730:                 }
                   5731:             }
1.696     raeburn  5732:             if (($url ne '') && ($shownsymb ne '')) {
                   5733:                 $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501     raeburn  5734:             }
1.329     droeschl 5735: 	}
1.621     raeburn  5736:     } elsif ($supplementalflag) {
1.610     raeburn  5737:         if ($isexternal) {
                   5738:             if ($url =~ /^([^#]+)#([^#]+)$/) {
                   5739:                 $url = $1;
                   5740:                 $anchor = $2;
1.623     raeburn  5741:                 if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678     raeburn  5742:                     unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  5743:                         if ($hostname ne '') {
                   5744:                             $url = 'http://'.$hostname.$url;
                   5745:                         }
                   5746:                         $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.623     raeburn  5747:                     }
                   5748:                     $nomodal = 1;
                   5749:                 }
1.610     raeburn  5750:             }
1.621     raeburn  5751:         } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   5752:             if (($ENV{'SERVER_PORT'} == 443) &&
                   5753:                 ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  5754:                 unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  5755:                     if ($hostname ne '') {
                   5756:                         $url = 'http://'.$hostname.$url;
                   5757:                     }
                   5758:                     $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  5759:                 }
1.621     raeburn  5760:                 $nomodal = 1;
                   5761:             }
1.705     raeburn  5762:         } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686     raeburn  5763:             my $embstyle=&Apache::loncommon::fileembstyle($extension);
                   5764:             unless ($embstyle eq 'ssi') {
                   5765:                 if (($embstyle eq 'img')
                   5766:                  || ($embstyle eq 'emb')
                   5767:                  || ($embstyle eq 'wrp')) {
                   5768:                     $url='/adm/wrapper'.$url;
                   5769:                 } elsif ($url !~ /\.(sequence|page)$/) {
                   5770:                     $url='/adm/coursedocs/showdoc'.$url;
                   5771:                 }
                   5772:             }
1.610     raeburn  5773:         }
1.685     raeburn  5774:         unless ($allowed && $env{'request.role.adv'}) {
                   5775:             if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   5776:                 $hiddenres = 1;
                   5777:             }
                   5778:         }
1.329     droeschl 5779:     }
1.615     raeburn  5780:     my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617     raeburn  5781:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519     raeburn  5782:     if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329     droeschl 5783: 	my $foldername=&escape($foldertitle);
                   5784: 	my $folderpath=$env{'form.folderpath'};
                   5785: 	if ($folderpath) { $folderpath.='&' };
1.510     raeburn  5786:         if (!$allowed && $supplementalflag) {
1.519     raeburn  5787:             $folderpath.=$containerarg.'&'.$foldername;
1.510     raeburn  5788:             $url.='folderpath='.&escape($folderpath);
1.685     raeburn  5789:             if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   5790:                 $hiddenfolder = 1;
1.682     raeburn  5791:             }
1.510     raeburn  5792:         } else {
1.617     raeburn  5793:             my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
                   5794:                                                         'parameter_randompick'))[0];
                   5795:             my $randorder = ((&LONCAPA::map::getparameter($orderidx,
                   5796:                                               'parameter_randomorder'))[0]=~/^yes$/i);
                   5797:             my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
                   5798:                                               'parameter_hiddenresource'))[0]=~/^yes$/i);
                   5799:             my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
                   5800:                                               'parameter_encrypturl'))[0]=~/^yes$/i);
                   5801:             unless ($hiddenmap) {
1.620     raeburn  5802:                 if (ref($navmapref)) {
                   5803:                     unless (ref($$navmapref)) {
                   5804:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   5805:                     }
                   5806:                     if (ref($$navmapref)) {
                   5807:                         if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
                   5808:                             my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
                   5809:                             unless (@resources) {
                   5810:                                 $hiddenmap = 1;
                   5811:                                 unless ($env{'request.role.adv'}) {  
                   5812:                                     $url = '';
                   5813:                                     $hiddenfolder = 1;
                   5814:                                 }
1.617     raeburn  5815:                             }
1.615     raeburn  5816:                         }
                   5817:                     }
                   5818:                 }
                   5819:             }
1.617     raeburn  5820:             unless ($encryptmap) {
1.620     raeburn  5821:                 if ((ref($navmapref)) && (ref($$navmapref))) {
                   5822:                     if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
                   5823:                         $encryptmap = 1;
                   5824:                     }
1.617     raeburn  5825:                 }
                   5826:             }
1.630     raeburn  5827: 
1.617     raeburn  5828: # Append randompick number, hidden, and encrypted with ":" to foldername,
                   5829: # so it gets transferred between levels
                   5830: 	    $folderpath.=$containerarg.'&'.$foldername.
                   5831:                          ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615     raeburn  5832:             unless ($url eq '') {
1.612     raeburn  5833:                 $url.='folderpath='.&escape($folderpath);
                   5834:             }
1.510     raeburn  5835:             my $rpckchk;
                   5836:             if ($rpicknum) {
                   5837:                 $rpckchk = ' checked="checked"';
1.543     raeburn  5838:                 if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
                   5839:                     push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
                   5840:                 }
1.510     raeburn  5841:             }
1.537     raeburn  5842:             my $formname = 'edit_randompick_'.$orderidx;
1.510     raeburn  5843: 	    $rand_pick_text = 
1.478     raeburn  5844: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  5845: $form_param."\n".
1.478     raeburn  5846: $form_common."\n".
1.611     raeburn  5847: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.$disabled.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
1.510     raeburn  5848:             if ($rpicknum ne '') {
                   5849:                 $rand_pick_text .= ':&nbsp;<a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
                   5850:             }
1.537     raeburn  5851:             $rand_pick_text .= '</span></span>'.
                   5852:                                $form_end;
1.543     raeburn  5853:             my $ro_set;
1.617     raeburn  5854:             if ($randorder) {
1.543     raeburn  5855:                 $ro_set = 'checked="checked"';
                   5856:                 if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
                   5857:                     push(@{$filtersref->{'randomorder'}},$orderidx);
                   5858:                 }
                   5859:             }
1.564     raeburn  5860:             $formname = 'edit_rorder_'.$orderidx;
1.510     raeburn  5861: 	    $rand_order_text = 
1.537     raeburn  5862: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  5863: $form_param."\n".
1.537     raeburn  5864: $form_common."\n".
1.611     raeburn  5865: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.$disabled.' /> '.&mt('Random Order').' </label></span>'.
1.537     raeburn  5866: $form_end; 
1.510     raeburn  5867:         }
1.705     raeburn  5868:     } elsif ($supplementalflag) {
1.598     raeburn  5869:         my $isexttool;
1.626     raeburn  5870:         if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  5871:             $url='/adm/wrapper'.$url;
                   5872:             $isexttool = 1;
                   5873:         }
1.510     raeburn  5874:         $url .= ($url =~ /\?/) ? '&amp;':'?';
1.509     raeburn  5875:         $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510     raeburn  5876:         if ($title) {
1.687     raeburn  5877:             $url .= '&amp;title='.$encodedtitle;
1.510     raeburn  5878:         }
1.598     raeburn  5879:         if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510     raeburn  5880:             $url .= '&amp;idx='.$orderidx;
                   5881:         }
1.610     raeburn  5882:         if ($anchor ne '') {
                   5883:             $url .= '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   5884:         }
1.329     droeschl 5885:     }
1.519     raeburn  5886:     my ($tdalign,$tdwidth);
1.501     raeburn  5887:     if ($allowed) {
1.630     raeburn  5888:         my $fileloc =
1.501     raeburn  5889:             &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510     raeburn  5890:         if ($isexternal) {
1.630     raeburn  5891:             ($editlink,$extresform) =
1.611     raeburn  5892:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   5893:                                                      undef,undef,undef,undef,undef,undef,
                   5894:                                                      undef,$disabled);
1.626     raeburn  5895:         } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  5896:             ($editlink,$extresform) =
                   5897:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   5898:                                                      undef,undef,undef,'tool',$coursedom,
1.611     raeburn  5899:                                                      $coursenum,$ltitoolsref,$disabled);
1.511     raeburn  5900:         } elsif (!$isfolder && !$ispage) {
1.503     raeburn  5901:             my ($cfile,$home,$switchserver,$forceedit,$forceview) = 
                   5902:                 &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511     raeburn  5903:             if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610     raeburn  5904:                 my $suppanchor;
                   5905:                 if ($supplementalflag) {
                   5906:                     $suppanchor = $anchor;
                   5907:                 }
1.630     raeburn  5908:                 my $jscall =
1.501     raeburn  5909:                     &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
                   5910:                                                             $switchserver,
1.503     raeburn  5911:                                                             $forceedit,
1.679     raeburn  5912:                                                             undef,$symb,$shownsymb,
1.511     raeburn  5913:                                                             &escape($env{'form.folderpath'}),
1.622     raeburn  5914:                                                             $renametitle,$hostname,
                   5915:                                                             '','',1,$suppanchor);
1.501     raeburn  5916:                 if ($jscall) {
1.518     raeburn  5917:                     $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
                   5918:                                 $jscall.'" >'.&mt('Edit').'</a>&nbsp;'."\n";
1.501     raeburn  5919:                 }
                   5920:             }
                   5921:         }
1.519     raeburn  5922:         $tdalign = ' align="right" valign="top"';
                   5923:         $tdwidth = ' width="80%"';
1.329     droeschl 5924:     }
1.408     raeburn  5925:     my $reinit;
                   5926:     if ($crstype eq 'Community') {
                   5927:         $reinit = &mt('(re-initialize community to access)');
                   5928:     } else {
                   5929:         $reinit = &mt('(re-initialize course to access)');
1.519     raeburn  5930:     }
1.725     raeburn  5931:     if ($allowed) {
                   5932:         $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
                   5933:         if ($orig_url =~ /$LONCAPA::assess_re/) {
                   5934:             $line.= '<br />';
                   5935:             if ($curralias ne '') {
                   5936:                 $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   5937:                        $lt{'da'}.'</a></span>';
                   5938:             } else {
                   5939:                 $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   5940:                        $lt{'sa'}.'</a></span>';
                   5941:             }
1.633     raeburn  5942:         }
1.725     raeburn  5943:         $line.='</td>';
1.633     raeburn  5944:     }
1.725     raeburn  5945:     $line .= '<td><span class="LC_nobreak">';
1.685     raeburn  5946:     my ($link,$nolink);
1.472     raeburn  5947:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685     raeburn  5948:         if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
                   5949:             if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   5950:                 $nolink = 1;
                   5951:             }
                   5952:         }
                   5953:         if ($nolink) {
1.723     raeburn  5954:             $line .= '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" /></a>';
1.685     raeburn  5955:         } else {
1.723     raeburn  5956:             $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" /></a>';
1.685     raeburn  5957:         }
1.469     www      5958:     } elsif ($url) {
1.610     raeburn  5959:        if ($anchor ne '') {
                   5960:            if ($supplementalflag) {
                   5961:                $anchor = '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   5962:            } else {
                   5963:                $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
                   5964:            }
                   5965:        }
1.705     raeburn  5966:        if (($nomodal) && ($hostname ne '')) {
1.622     raeburn  5967:            $link = 'http://'.$hostname.$url;
                   5968:        } else {
                   5969:            $link = $url;
                   5970:        }
1.705     raeburn  5971:        my $inhibitmenu;
                   5972:        if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
                   5973:            (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
                   5974:                            ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
                   5975:            $inhibitmenu = 'only_body=1';
                   5976:        } else {
                   5977:            $inhibitmenu = 'inhibitmenu=yes';
                   5978:        }
                   5979:        $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').$inhibitmenu.$anchor);
1.685     raeburn  5980:        if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
                   5981:            if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   5982:                $nolink = 1;
                   5983:            }
                   5984:        }
                   5985:        if ($nolink) {
1.723     raeburn  5986:            $line.='<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />';
1.685     raeburn  5987:        } elsif ($nomodal) {
1.621     raeburn  5988:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
1.723     raeburn  5989:                   '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" border="0" /></a>';
1.621     raeburn  5990:        } else {
                   5991:            $line.=&Apache::loncommon::modal_link($link,
1.723     raeburn  5992:                                                  '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />',600,500);
1.621     raeburn  5993:        }
1.469     www      5994:     } else {
1.723     raeburn  5995:        $line.='<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />';
1.469     www      5996:     }
1.519     raeburn  5997:     $line.='</span></td><td'.$tdwidth.'>';
1.472     raeburn  5998:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685     raeburn  5999:        if ($nolink) {
                   6000:            $line.=$title;
                   6001:        } else {
                   6002:            $line.='<a href="'.$url.'">'.$title.'</a>';
                   6003:        }
1.682     raeburn  6004:        if (!$allowed && $supplementalflag && $canedit && $isfolder) {
                   6005:            my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
                   6006:            my $editurl = $url;
                   6007:            $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;};
                   6008:            $line .= '&nbsp;'.'<a href="'.$editurl.'">'.
                   6009:                     '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
                   6010:                     '</a>';
                   6011:        }
                   6012:        if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag))  {
                   6013:            $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
                   6014:        }
1.469     www      6015:     } elsif ($url) {
1.685     raeburn  6016:        if ($nolink) {
                   6017:            $line.=$title;
                   6018:        } elsif ($nomodal) {
1.621     raeburn  6019:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   6020:                   $title.'</a>';
                   6021:        } else {
                   6022:            $line.=&Apache::loncommon::modal_link($link,$title,600,500);
                   6023:        }
1.617     raeburn  6024:     } elsif (($hiddenfolder) || ($hiddenres)) {
1.632     raeburn  6025:        $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469     www      6026:     } else {
                   6027:        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
                   6028:     }
1.633     raeburn  6029:     if (($allowed) && ($curralias ne '')) {
                   6030:         $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
                   6031:     } else {
                   6032:         $line .= $extresform;
                   6033:     }
                   6034:     $line .= '</td>';
1.478     raeburn  6035:     $rand_pick_text = '&nbsp;' if ($rand_pick_text eq '');
                   6036:     $rand_order_text = '&nbsp;' if ($rand_order_text eq '');
1.685     raeburn  6037:     if ($uploaded && $url && !$isfolder && !$ispage) {
                   6038:         if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
                   6039:             &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
                   6040:         }
                   6041:     }
1.682     raeburn  6042:     if ($allowed) {
                   6043:         my %lt=&Apache::lonlocal::texthash(
                   6044:                               'hd' => 'Hidden',
                   6045:                               'ec' => 'URL hidden');
                   6046:         my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543     raeburn  6047:         if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   6048:             $hidtext = ' checked="checked"';
1.694     raeburn  6049:             if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543     raeburn  6050:                 push(@{$filtersref->{'hiddenresource'}},$orderidx);
                   6051:             }
                   6052:         }
1.682     raeburn  6053:         $formhidden = 'edit_hiddenresource_'.$orderidx;
                   6054:         $line.=(<<ENDPARMS);
1.329     droeschl 6055:   <td class="LC_docs_entry_parameter">
1.537     raeburn  6056:     <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538     raeburn  6057:     $form_param
1.478     raeburn  6058:     $form_common
1.611     raeburn  6059:     <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329     droeschl 6060:     $form_end
1.682     raeburn  6061: ENDPARMS
                   6062:         if ($folder =~/^supplemental/) {
                   6063:             $line.= "\n    <td>";
                   6064:         } else {
                   6065:             if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
                   6066:                 $enctext = ' checked="checked"';
                   6067:                 if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
                   6068:                     push(@{$filtersref->{'encrypturl'}},$orderidx);
                   6069:                 }
                   6070:             }
                   6071:             $formurlhidden = 'edit_encrypturl_'.$orderidx;
                   6072: 	    $line.=(<<ENDPARMS);
1.458     raeburn  6073:     <br />
1.537     raeburn  6074:     <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538     raeburn  6075:     $form_param
1.478     raeburn  6076:     $form_common
1.611     raeburn  6077:     <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329     droeschl 6078:     $form_end
                   6079:   </td>
1.478     raeburn  6080:   <td class="LC_docs_entry_parameter">$rand_pick_text<br />
                   6081:                                       $rand_order_text</td>
1.329     droeschl 6082: ENDPARMS
1.682     raeburn  6083:         }
1.329     droeschl 6084:     }
1.379     bisitz   6085:     $line.=&Apache::loncommon::end_data_table_row();
1.329     droeschl 6086:     return $line;
                   6087: }
                   6088: 
1.538     raeburn  6089: sub action_restrictions {
                   6090:     my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
                   6091:     my %denied = (
                   6092:                    cut    => 0,
                   6093:                    copy   => 0,
                   6094:                    remove => 0,
                   6095:                  );
                   6096:     if ($url=~ m{^/res/.+\.(page|sequence)$}) {
                   6097:         # no copy for published maps
                   6098:         $denied{'copy'} = 1;
1.597     raeburn  6099:     } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
                   6100:         unless ($1 eq 'simpleproblem') {
                   6101:             $denied{'copy'} = 1;
                   6102:         }
                   6103:         $denied{'cut'} = 1;
1.538     raeburn  6104:     } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
                   6105:         if ($folderpath =~ /^default&[^\&]+$/) {
                   6106:             if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
                   6107:                 $denied{'remove'} = 1;
                   6108:             }
                   6109:             $denied{'cut'} = 1;
                   6110:             $denied{'copy'} = 1;
                   6111:         }
                   6112:     } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
                   6113:         my $group = $1;
                   6114:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
                   6115:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   6116:                 $denied{'remove'} = 1;
                   6117:             }
                   6118:         }
                   6119:         $denied{'cut'} = 1;
                   6120:         $denied{'copy'} = 1;
                   6121:     } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
                   6122:         my $group = $1;
                   6123:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
                   6124:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   6125:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   6126:                 if (keys(%groupsettings) > 0) {
                   6127:                     $denied{'remove'} = 1;
                   6128:                 }
                   6129:                 $denied{'cut'} = 1;
                   6130:                 $denied{'copy'} = 1;
                   6131:             }
                   6132:         }
                   6133:     } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
                   6134:         my $group = $1;
                   6135:         if ($url =~ /group_boards_\Q$group\E/) {
                   6136:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   6137:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   6138:                 if (keys(%groupsettings) > 0) {
                   6139:                     if (ref($groupsettings{'functions'}) eq 'HASH') {
                   6140:                         if ($groupsettings{'functions'}{'discussion'} eq 'on') {
                   6141:                             $denied{'remove'} = 1;
                   6142:                         }
                   6143:                     }
                   6144:                 }
                   6145:                 $denied{'cut'} = 1;
                   6146:                 $denied{'copy'} = 1;
                   6147:             }
                   6148:         }
                   6149:     }
                   6150:     return %denied;
                   6151: }
                   6152: 
1.533     raeburn  6153: sub new_timebased_suffix {
1.538     raeburn  6154:     my ($dom,$num,$type,$area,$container) = @_;
1.533     raeburn  6155:     my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538     raeburn  6156:     if ($type eq 'paste') {
                   6157:         $prefix = $type;
                   6158:         $namespace = 'courseeditor';
1.587     raeburn  6159:         $idtype = 'addcode';
1.538     raeburn  6160:     } elsif ($type eq 'map') {
1.533     raeburn  6161:         $prefix = 'docs';
                   6162:         if ($area eq 'supplemental') {
                   6163:             $prefix = 'supp';
                   6164:         }
                   6165:         $prefix .= $container;
                   6166:         $namespace = 'uploadedmaps';
                   6167:     } else {
                   6168:         $prefix = $type;
                   6169:         $namespace = 'templated';
1.504     raeburn  6170:     }
                   6171:     my ($suffix,$freedlock,$error) =
1.587     raeburn  6172:         &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504     raeburn  6173:     if (!$suffix) {
1.538     raeburn  6174:         if ($type eq 'paste') {
                   6175:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
                   6176:         } elsif ($type eq 'map') {
1.533     raeburn  6177:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
                   6178:         } elsif ($type eq 'smppg') {
                   6179:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626     raeburn  6180:         } elsif ($type eq 'exttool') {
                   6181:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533     raeburn  6182:         } else {
1.565     bisitz   6183:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533     raeburn  6184:         }
1.504     raeburn  6185:         if ($error) {
                   6186:             $errtext .= '<br />'.$error;
                   6187:         }
                   6188:     }
                   6189:     if ($freedlock ne 'ok') {
1.630     raeburn  6190:         $locknotfreed =
1.533     raeburn  6191:             '<div class="LC_error">'.
                   6192:             &mt('There was a problem removing a lockfile.').' ';
1.538     raeburn  6193:         if ($type eq 'paste') {
1.591     raeburn  6194:             if ($freedlock eq 'nolock') {
                   6195:                 $locknotfreed =
                   6196:                     '<div class="LC_error">'.
                   6197:                     &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
                   6198:  
1.593     droeschl 6199:                     &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591     raeburn  6200:             } else { 
                   6201:                 $locknotfreed .=
                   6202:                     &mt('This will prevent addition of items to the clipboard until your next log-in.');
                   6203:             }
1.538     raeburn  6204:         } elsif ($type eq 'map') {
1.591     raeburn  6205:             $locknotfreed .=
                   6206:                 &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533     raeburn  6207:         } elsif ($type eq 'smppg') {
                   6208:             $locknotfreed .=
                   6209:                 &mt('This will prevent creation of additional simple pages in this course.');
1.626     raeburn  6210:         } elsif ($type eq 'exttool') {
                   6211:             $locknotfreed .=
                   6212:                 &mt('This will prevent creation of additional external tools in this course.');
1.533     raeburn  6213:         } else {
                   6214:             $locknotfreed .=
1.565     bisitz   6215:                 &mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  6216:         }
1.538     raeburn  6217:         unless ($type eq 'paste') {
                   6218:             $locknotfreed .=
1.560     raeburn  6219:                 ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   6220:                         '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538     raeburn  6221:         }
                   6222:         $locknotfreed .= '</div>';
1.504     raeburn  6223:     }
                   6224:     return ($suffix,$errtext,$locknotfreed);
                   6225: }
                   6226: 
1.329     droeschl 6227: =pod
                   6228: 
                   6229: =item tiehash()
                   6230: 
                   6231: tie the hash
                   6232: 
                   6233: =cut
                   6234: 
                   6235: sub tiehash {
                   6236:     my ($mode)=@_;
                   6237:     $hashtied=0;
                   6238:     if ($env{'request.course.fn'}) {
                   6239: 	if ($mode eq 'write') {
                   6240: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   6241: 		    &GDBM_WRCREAT(),0640)) {
                   6242:                 $hashtied=2;
                   6243: 	    }
                   6244: 	} else {
                   6245: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   6246: 		    &GDBM_READER(),0640)) {
                   6247:                 $hashtied=1;
                   6248: 	    }
                   6249: 	}
1.364     bisitz   6250:     }
1.329     droeschl 6251: }
                   6252: 
                   6253: sub untiehash {
                   6254:     if ($hashtied) { untie %hash; }
                   6255:     $hashtied=0;
                   6256:     return OK;
                   6257: }
                   6258: 
                   6259: 
                   6260: 
                   6261: 
                   6262: sub checkonthis {
1.637     raeburn  6263:     my ($r,$url,$level,$title,$checkstale)=@_;
1.329     droeschl 6264:     $url=&unescape($url);
                   6265:     $alreadyseen{$url}=1;
                   6266:     $r->rflush();
                   6267:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
                   6268:        $r->print("\n<br />");
                   6269:        if ($level==0) {
                   6270:            $r->print("<br />");
                   6271:        }
                   6272:        for (my $i=0;$i<=$level*5;$i++) {
                   6273:            $r->print('&nbsp;');
                   6274:        }
                   6275:        $r->print('<a href="'.$url.'" target="cat">'.
                   6276: 		 ($title?$title:$url).'</a> ');
                   6277:        if ($url=~/^\/res\//) {
1.637     raeburn  6278:           my $updated;
                   6279:           if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
                   6280:               ($url !~ /\.\d+\.\w+$/)) {
                   6281:               $updated = &Apache::lonnet::remove_stale_resfile($url);
                   6282:           }
1.329     droeschl 6283: 	  my $result=&Apache::lonnet::repcopy(
                   6284:                               &Apache::lonnet::filelocation('',$url));
                   6285:           if ($result eq 'ok') {
                   6286:              $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637     raeburn  6287:              if ($updated) {
                   6288:                  $r->print('<br />');
                   6289:                  for (my $i=0;$i<=$level*5;$i++) {
                   6290:                      $r->print('&nbsp;');
                   6291:                  }
                   6292:                  $r->print('- '.&mt('Outdated copy removed'));
                   6293:              }
1.329     droeschl 6294:              $r->rflush();
                   6295:              &Apache::lonnet::countacc($url);
                   6296:              $url=~/\.(\w+)$/;
                   6297:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                   6298: 		 $r->print('<br />');
                   6299:                  $r->rflush();
                   6300:                  for (my $i=0;$i<=$level*5;$i++) {
                   6301:                      $r->print('&nbsp;');
                   6302:                  }
                   6303:                  $r->print('- '.&mt('Rendering:').' ');
                   6304: 		 my ($errorcount,$warningcount)=split(/:/,
                   6305: 	       &Apache::lonnet::ssi_body($url,
                   6306: 			       ('grade_target'=>'web',
                   6307: 				'return_only_error_and_warning_counts' => 1)));
                   6308:                  if (($errorcount) ||
                   6309:                      ($warningcount)) {
                   6310: 		     if ($errorcount) {
1.369     bisitz   6311:                         $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329     droeschl 6312:                           &mt('[quant,_1,error]',$errorcount).'</span>');
                   6313:                      }
                   6314: 		     if ($warningcount) {
                   6315:                         $r->print('<span class="LC_warning">'.
                   6316:                           &mt('[quant,_1,warning]',$warningcount).'</span>');
                   6317:                      }
                   6318:                  } else {
                   6319:                      $r->print('<span class="LC_success">'.&mt('ok').'</span>');
                   6320:                  }
                   6321:                  $r->rflush();
                   6322:              }
                   6323: 	     my $dependencies=
                   6324:                 &Apache::lonnet::metadata($url,'dependencies');
                   6325:              foreach my $dep (split(/\,/,$dependencies)) {
                   6326: 		 if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637     raeburn  6327:                     &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329     droeschl 6328:                  }
                   6329:              }
                   6330:           } elsif ($result eq 'unavailable') {
                   6331:              $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
                   6332:           } elsif ($result eq 'not_found') {
                   6333: 	      unless ($url=~/\$/) {
1.521     bisitz   6334: 		  $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329     droeschl 6335: 	      } else {
1.366     bisitz   6336: 		  $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329     droeschl 6337: 	      }
                   6338:           } else {
                   6339:              $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
                   6340:           }
1.637     raeburn  6341:           if (($updated) && ($result ne 'ok')) {
                   6342:               $r->print('<br />'.&mt('Outdated copy removed'));
                   6343:           }
1.329     droeschl 6344:        }
                   6345:     }
                   6346: }
                   6347: 
                   6348: 
                   6349: 
                   6350: =pod
                   6351: 
                   6352: =item list_symbs()
                   6353: 
1.485     raeburn  6354: List Content Identifiers
1.329     droeschl 6355: 
                   6356: =cut
                   6357: 
                   6358: sub list_symbs {
                   6359:     my ($r) = @_;
                   6360: 
1.408     raeburn  6361:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  6362:     $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
                   6363:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
                   6364:     $r->print(&startContentScreen('tools'));
1.329     droeschl 6365:     my $navmap = Apache::lonnavmaps::navmap->new();
                   6366:     if (!defined($navmap)) {
                   6367:         $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
                   6368:                   '<div class="LC_error">'.
                   6369:                   &mt('Unable to retrieve information about course contents').
                   6370:                   '</div>');
1.408     raeburn  6371:         &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329     droeschl 6372:     } else {
1.484     raeburn  6373:         $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
                   6374:                   &Apache::loncommon::start_data_table().
                   6375:                   &Apache::loncommon::start_data_table_header_row().
                   6376:                   '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
                   6377:                   &Apache::loncommon::end_data_table_header_row()."\n");
                   6378:         my $count;
1.329     droeschl 6379:         foreach my $res ($navmap->retrieveResources()) {
1.484     raeburn  6380:             $r->print(&Apache::loncommon::start_data_table_row().
                   6381:                       '<td>'.$res->compTitle().'</td>'.
                   6382:                       '<td>'.$res->symb().'</td>'.
1.521     bisitz   6383:                       &Apache::loncommon::end_data_table_row());
1.484     raeburn  6384:             $count ++;
                   6385:         }
                   6386:         if (!$count) {
                   6387:             $r->print(&Apache::loncommon::start_data_table_row().
                   6388:                       '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
                   6389:                       &Apache::loncommon::end_data_table_row()); 
1.329     droeschl 6390:         }
1.484     raeburn  6391:         $r->print(&Apache::loncommon::end_data_table());
1.329     droeschl 6392:     }
1.521     bisitz   6393:     $r->print(&endContentScreen());
1.329     droeschl 6394: }
                   6395: 
1.651     raeburn  6396: sub short_urls {
                   6397:     my ($r,$canedit) = @_;
                   6398:     my $crstype = &Apache::loncommon::course_type();
                   6399:     my $formname = 'shortenurl';
                   6400:     $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
                   6401:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
                   6402:     $r->print(&startContentScreen('tools'));
                   6403:     my ($navmap,$errormsg) =
                   6404:         &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
                   6405:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   6406:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   6407:     my (%maps,%resources,%titles);
                   6408:     if (!ref($navmap)) {
                   6409:         $r->print($errormsg.
                   6410:                   &endContentScreen());
                   6411:         return '';
                   6412:     } else {
1.652     raeburn  6413:         $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651     raeburn  6414:         $r->rflush();
                   6415:         my $readonly;
                   6416:         if ($canedit) {
1.671     raeburn  6417:             my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651     raeburn  6418:             if ($numnew) {
                   6419:                 $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
                   6420:             }
                   6421:             if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
                   6422:                 $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
                   6423:                 foreach my $error (@{$errors}) {
                   6424:                     $r->print('<li>'.$error.'</li>');
                   6425:                 }
                   6426:                 $r->print('</ul><br />');
                   6427:             }
                   6428:         } else {
                   6429:             $readonly = 1;
                   6430:         }
                   6431:         my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
                   6432:         $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
1.711     raeburn  6433:                                                              undef,undef,undef,undef,undef,\%currtiny,undef,$readonly));
1.651     raeburn  6434:     }
                   6435:     $r->print(&endContentScreen());
                   6436: }
                   6437: 
1.637     raeburn  6438: sub contentverifyform {
                   6439:     my ($r) = @_;
                   6440:     my $crstype = &Apache::loncommon::course_type();
                   6441:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   6442:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
                   6443:     $r->print(&startContentScreen('tools'));
                   6444:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
                   6445:     $r->print('<form method="post" action="/adm/coursedocs"><p>'.
                   6446:               &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
                   6447:               '&nbsp;<span class="LC_nobreak">'.
                   6448:               '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
                   6449:               &mt('No').'</label>'.('&nbsp;'x2).
                   6450:               '<label><input type="radio" name="checkstale" value="1" />'.
                   6451:               &mt('Yes').'</label></span></p><p>'.
1.674     raeburn  6452:               '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637     raeburn  6453:               '<input type="hidden" value="1" name="tools" />'.
                   6454:               '<input type="hidden" value="1" name="verify" /></p></form>');
                   6455:     $r->print(&endContentScreen());
                   6456:     return;
                   6457: }
1.329     droeschl 6458: 
                   6459: sub verifycontent {
1.637     raeburn  6460:     my ($r,$checkstale) = @_;
1.408     raeburn  6461:     my $crstype = &Apache::loncommon::course_type();
1.549     raeburn  6462:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   6463:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484     raeburn  6464:     $r->print(&startContentScreen('tools'));
                   6465:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>'); 
1.329     droeschl 6466:    $hashtied=0;
                   6467:    undef %alreadyseen;
                   6468:    %alreadyseen=();
                   6469:    &tiehash();
1.484     raeburn  6470:    
1.329     droeschl 6471:    foreach my $key (keys(%hash)) {
                   6472:        if ($hash{$key}=~/\.(page|sequence)$/) {
                   6473: 	   if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
                   6474: 	       $r->print('<hr /><span class="LC_error">'.
1.419     bisitz   6475: 			 &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329     droeschl 6476: 			 &unescape($hash{$key}).'</span><br />'.
1.419     bisitz   6477: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329     droeschl 6478: 	   }
                   6479:        }
                   6480:        if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637     raeburn  6481:            &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329     droeschl 6482:        }
                   6483:    }
                   6484:    &untiehash();
1.442     www      6485:    $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521     bisitz   6486:     $r->print(&endContentScreen());
1.329     droeschl 6487: }
                   6488: 
                   6489: sub devalidateversioncache {
                   6490:     my $src=shift;
                   6491:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
                   6492: 					  &Apache::lonnet::clutter($src));
                   6493: }
                   6494: 
                   6495: sub checkversions {
1.611     raeburn  6496:     my ($r,$canedit) = @_;
1.408     raeburn  6497:     my $crstype = &Apache::loncommon::course_type();
1.571     raeburn  6498:     $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
                   6499:     $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484     raeburn  6500:     $r->print(&startContentScreen('tools'));
1.442     www      6501: 
1.329     droeschl 6502:     my $header='';
                   6503:     my $startsel='';
                   6504:     my $monthsel='';
                   6505:     my $weeksel='';
                   6506:     my $daysel='';
                   6507:     my $allsel='';
                   6508:     my %changes=();
                   6509:     my $starttime=0;
                   6510:     my $haschanged=0;
                   6511:     my %setversions=&Apache::lonnet::dump('resourceversions',
                   6512: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   6513: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   6514: 
                   6515:     $hashtied=0;
                   6516:     &tiehash();
1.611     raeburn  6517:     if ($canedit) {
                   6518:         my %newsetversions=();
                   6519:         if ($env{'form.setmostrecent'}) {
                   6520: 	    $haschanged=1;
                   6521: 	    foreach my $key (keys(%hash)) {
                   6522: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   6523: 		    $newsetversions{$1}='mostrecent';
                   6524:                     &devalidateversioncache($1);
                   6525: 	        }
                   6526: 	    }
                   6527:         } elsif ($env{'form.setcurrent'}) {
                   6528: 	    $haschanged=1;
                   6529: 	    foreach my $key (keys(%hash)) {
                   6530: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   6531: 		    my $getvers=&Apache::lonnet::getversion($1);
                   6532: 		    if ($getvers>0) {
                   6533: 		        $newsetversions{$1}=$getvers;
                   6534: 		        &devalidateversioncache($1);
                   6535: 		    }
                   6536: 	        }
1.329     droeschl 6537: 	    }
1.611     raeburn  6538:         } elsif ($env{'form.setversions'}) {
                   6539: 	    $haschanged=1;
                   6540: 	    foreach my $key (keys(%env)) {
                   6541: 	        if ($key=~/^form\.set_version_(.+)$/) {
                   6542: 		    my $src=$1;
                   6543: 		    if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
                   6544: 		        $newsetversions{$src}=$env{$key};
                   6545: 		        &devalidateversioncache($src);
                   6546: 		    }
                   6547: 	        }
1.329     droeschl 6548: 	    }
1.611     raeburn  6549:         }
                   6550:         if ($haschanged) {
                   6551:             if (&Apache::lonnet::put('resourceversions',\%newsetversions,
                   6552: 			             $env{'course.'.$env{'request.course.id'}.'.domain'},
                   6553: 			             $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
                   6554: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   6555:                     &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
                   6556: 	    } else {
                   6557: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   6558:                     &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329     droeschl 6559: 	    }
1.611     raeburn  6560: 	    &mark_hash_old();
                   6561:         }
                   6562:         &changewarning($r,'');
1.329     droeschl 6563:     }
                   6564:     if ($env{'form.timerange'} eq 'all') {
                   6565: # show all documents
1.549     raeburn  6566: 	$header=&mt('All content in '.$crstype);
1.521     bisitz   6567: 	$allsel=' selected="selected"';
1.329     droeschl 6568: 	foreach my $key (keys(%hash)) {
                   6569: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   6570: 		my $src=$1;
                   6571: 		$changes{$src}=1;
                   6572: 	    }
                   6573: 	}
                   6574:     } else {
                   6575: # show documents which changed
                   6576: 	%changes=&Apache::lonnet::dump
                   6577: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
                   6578:                      $env{'course.'.$env{'request.course.id'}.'.num'});
                   6579: 	my $firstkey=(keys(%changes))[0];
                   6580: 	unless ($firstkey=~/^error\:/) {
                   6581: 	    unless ($env{'form.timerange'}) {
                   6582: 		$env{'form.timerange'}=604800;
                   6583: 	    }
                   6584: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
                   6585: 		.&mt('seconds');
                   6586: 	    if ($env{'form.timerange'}==-1) {
                   6587: 		$seltext='since start of course';
1.521     bisitz   6588: 		$startsel=' selected="selected"';
1.329     droeschl 6589: 		$env{'form.timerange'}=time;
                   6590: 	    }
                   6591: 	    $starttime=time-$env{'form.timerange'};
                   6592: 	    if ($env{'form.timerange'}==2592000) {
                   6593: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   6594: 		$monthsel=' selected="selected"';
1.329     droeschl 6595: 	    } elsif ($env{'form.timerange'}==604800) {
                   6596: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   6597: 		$weeksel=' selected="selected"';
1.329     droeschl 6598: 	    } elsif ($env{'form.timerange'}==86400) {
                   6599: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   6600: 		$daysel=' selected="selected"';
1.329     droeschl 6601: 	    }
                   6602: 	    $header=&mt('Content changed').' '.$seltext;
                   6603: 	} else {
                   6604: 	    $header=&mt('No content modifications yet.');
                   6605: 	}
                   6606:     }
                   6607:     %setversions=&Apache::lonnet::dump('resourceversions',
                   6608: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   6609: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   6610:     my %lt=&Apache::lonlocal::texthash
1.408     raeburn  6611: 	      ('st' => 'Version changes since start of '.$crstype,
1.329     droeschl 6612: 	       'lm' => 'Version changes since last Month',
                   6613: 	       'lw' => 'Version changes since last Week',
                   6614: 	       'sy' => 'Version changes since Yesterday',
                   6615:                'al' => 'All Resources (possibly large output)',
1.484     raeburn  6616:                'cd' => 'Change display', 
1.329     droeschl 6617: 	       'sd' => 'Display',
                   6618: 	       'fi' => 'File',
                   6619: 	       'md' => 'Modification Date',
                   6620:                'mr' => 'Most recently published Version',
1.408     raeburn  6621: 	       've' => 'Version used in '.$crstype,
                   6622:                'vu' => 'Set Version to be used in '.$crstype,
                   6623: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329     droeschl 6624: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                   6625: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479     golterma 6626: 	       'di' => 'Differences',
1.484     raeburn  6627: 	       'save' => 'Save changes',
                   6628:                'vers' => 'Version choice(s) for specific resources', 
1.479     golterma 6629: 	       'act' => 'Actions');
1.611     raeburn  6630:     my ($disabled,$readonly);
                   6631:     unless ($canedit) {
                   6632:         $disabled = 'disabled="disabled"';
                   6633:         $readonly = 1;
                   6634:     }
1.329     droeschl 6635:     $r->print(<<ENDHEADERS);
1.484     raeburn  6636: <h4 class="LC_info">$header</h4>
1.329     droeschl 6637: <form action="/adm/coursedocs" method="post">
                   6638: <input type="hidden" name="versions" value="1" />
1.484     raeburn  6639: <div class="LC_left_float">
1.479     golterma 6640: <fieldset>
1.484     raeburn  6641: <legend>$lt{'cd'}</legend>
1.329     droeschl 6642: <select name="timerange">
1.521     bisitz   6643: <option value='all'$allsel>$lt{'al'}</option>
                   6644: <option value="-1"$startsel>$lt{'st'}</option>
                   6645: <option value="2592000"$monthsel>$lt{'lm'}</option>
                   6646: <option value="604800"$weeksel>$lt{'lw'}</option>
                   6647: <option value="86400"$daysel>$lt{'sy'}</option>
1.329     droeschl 6648: </select>
                   6649: <input type="submit" name="display" value="$lt{'sd'}" />
1.484     raeburn  6650: </fieldset>
                   6651: </div>
                   6652: <div class="LC_left_float">
                   6653: <fieldset>
                   6654: <legend>$lt{'act'}</legend>
1.611     raeburn  6655: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
                   6656: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484     raeburn  6657: </fieldset>
                   6658: </div>
                   6659: <br clear="all" />
                   6660: <hr />
                   6661: <h4>$lt{'vers'}</h4>
1.329     droeschl 6662: ENDHEADERS
1.479     golterma 6663:     #number of columns for version history
1.571     raeburn  6664:     my %changedbytime;
                   6665:     foreach my $key (keys(%changes)) {
                   6666:         #excludes not versionable problems from resource version history:
                   6667:         next if ($key =~ /^\/res\/lib\/templates/);
                   6668:         my $chg;
                   6669:         if ($env{'form.timerange'} eq 'all') {
                   6670:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   6671:             $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
                   6672:         } else {
                   6673:             $chg = $changes{$key};
                   6674:             next if ($chg < $starttime);
                   6675:         }
                   6676:         push(@{$changedbytime{$chg}},$key);
                   6677:     }
                   6678:     if (keys(%changedbytime) == 0) {
                   6679:         &untiehash();
                   6680:         $r->print(&mt('No content changes in imported content in specified time frame').
                   6681:                   &endContentScreen());
                   6682:         return;
                   6683:     }
1.479     golterma 6684:     $r->print(
1.611     raeburn  6685:        '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   6686:         &Apache::loncommon::start_data_table().
                   6687:         &Apache::loncommon::start_data_table_header_row().
                   6688:         '<th>'.&mt('Resources').'</th>'.
                   6689:         "<th>$lt{'mr'}</th>".
                   6690:         "<th>$lt{'ve'}</th>".
                   6691:         "<th>$lt{'vu'}</th>".
                   6692:         '<th>'.&mt('History').'</th>'.
                   6693:         &Apache::loncommon::end_data_table_header_row()
                   6694:     );
1.571     raeburn  6695:     foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
                   6696:         foreach my $key (sort(@{$changedbytime{$chg}})) {
                   6697:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   6698:             my $currentversion=&Apache::lonnet::getversion($key);
                   6699:             if ($currentversion<0) {
                   6700:                 $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
                   6701:             }
                   6702:             my $linkurl=&Apache::lonnet::clutter($key);
                   6703:             $r->print(
                   6704:                 &Apache::loncommon::start_data_table_row().
                   6705:                 '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
                   6706:                 '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
                   6707:                 '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
                   6708:                 &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
                   6709:                 '<td align="right">'
                   6710:             );
                   6711:             # Used in course
                   6712:             my $usedversion=$hash{'version_'.$linkurl};
                   6713:             if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521     bisitz   6714:                 if ($usedversion != $currentversion) {
1.479     golterma 6715:                     $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521     bisitz   6716:                 } else {
1.479     golterma 6717:                     $r->print($usedversion);
                   6718:                 }
1.329     droeschl 6719:             } else {
1.521     bisitz   6720:                 $r->print($currentversion);
1.329     droeschl 6721:             }
1.571     raeburn  6722:             $r->print('</td><td title="'.$lt{'vu'}.'">');
                   6723:             # Set version
                   6724:             $r->print(&Apache::loncommon::select_form(
                   6725:                       $setversions{$linkurl},
                   6726:                       'set_version_'.$linkurl,
                   6727:                       {'select_form_order' => ['',1..$currentversion,'mostrecent'],
                   6728:                       '' => '',
                   6729:                       'mostrecent' => &mt('most recent'),
1.611     raeburn  6730:                       map {$_,$_} (1..$currentversion)},'',$readonly));
1.571     raeburn  6731:             my $lastold=1;
                   6732:             for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                   6733:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   6734:                 if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
                   6735:                     $lastold=$prevvers;
                   6736:                 }
                   6737:             }
                   6738:             $r->print('</td>');
                   6739:             # List all available versions
                   6740:             $r->print('<td valign="top"><span class="LC_fontsize_medium">');
                   6741:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
                   6742:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   6743:                 $r->print(
                   6744:                     '<span class="LC_nobreak">'
                   6745:                    .'<a href="'.&Apache::lonnet::clutter($url).'">'
                   6746:                    .&mt('Version [_1]',$prevvers).'</a>'
                   6747:                    .' ('.&Apache::lonlocal::locallocaltime(
1.521     bisitz   6748:                          &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571     raeburn  6749:                    .')');
                   6750:                 if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
                   6751:                     $r->print(
                   6752:                         ' <a href="/adm/diff?filename='.
                   6753:                         &Apache::lonnet::clutter($root.'.'.$extension).
                   6754:                         &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
                   6755:                         '" target="diffs">'.&mt('Diffs').'</a>');
                   6756:                 }
                   6757:                 $r->print('</span><br />');
1.329     droeschl 6758:             }
1.571     raeburn  6759:             $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521     bisitz   6760:         }
1.329     droeschl 6761:     }
1.521     bisitz   6762:     $r->print(
                   6763:         &Apache::loncommon::end_data_table().
1.611     raeburn  6764:         '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   6765:         '</form>'
                   6766:     );
1.329     droeschl 6767: 
                   6768:     &untiehash();
1.521     bisitz   6769:     $r->print(&endContentScreen());
1.571     raeburn  6770:     return;
1.329     droeschl 6771: }
                   6772: 
                   6773: sub mark_hash_old {
                   6774:     my $retie_hash=0;
                   6775:     if ($hashtied) {
                   6776: 	$retie_hash=1;
                   6777: 	&untiehash();
                   6778:     }
                   6779:     &tiehash('write');
                   6780:     $hash{'old'}=1;
                   6781:     &untiehash();
                   6782:     if ($retie_hash) { &tiehash(); }
                   6783: }
                   6784: 
                   6785: sub is_hash_old {
                   6786:     my $untie_hash=0;
                   6787:     if (!$hashtied) {
                   6788: 	$untie_hash=1;
                   6789: 	&tiehash();
                   6790:     }
                   6791:     my $return=$hash{'old'};
                   6792:     if ($untie_hash) { &untiehash(); }
                   6793:     return $return;
                   6794: }
                   6795: 
                   6796: sub changewarning {
                   6797:     my ($r,$postexec,$message,$url)=@_;
                   6798:     if (!&is_hash_old()) { return; }
                   6799:     my $pathvar='folderpath';
                   6800:     my $path=&escape($env{'form.folderpath'});
                   6801:     if (!defined($url)) {
                   6802: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
                   6803:     }
                   6804:     my $course_type = &Apache::loncommon::course_type();
                   6805:     if (!defined($message)) {
                   6806: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
                   6807:     }
1.653     raeburn  6808:     my $windowname = 'loncapaclient';
                   6809:     if ($env{'request.lti.login'}) {
                   6810:         $windowname .= 'lti';
                   6811:     }
1.329     droeschl 6812:     $r->print("\n\n".
1.372     bisitz   6813: '<script type="text/javascript">'."\n".
                   6814: '// <![CDATA['."\n".
                   6815: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
                   6816: '// ]]>'."\n".
1.369     bisitz   6817: '</script>'."\n".
1.653     raeburn  6818: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329     droeschl 6819: '<input type="hidden" name="orgurl" value="'.$url.
1.372     bisitz   6820: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329     droeschl 6821: &mt($message,' <input type="hidden" name="'.
                   6822:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369     bisitz   6823:     &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372     bisitz   6824: $help{'Caching'}.'</p></form>'."\n\n");
1.329     droeschl 6825: }
                   6826: 
                   6827: 
                   6828: sub init_breadcrumbs {
1.571     raeburn  6829:     my ($form,$text,$help)=@_;
1.329     droeschl 6830:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484     raeburn  6831:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405     bisitz   6832: 					    text=>&Apache::loncommon::course_type().' Editor',
1.329     droeschl 6833: 					    faq=>273,
                   6834: 					    bug=>'Instructor Interface',
1.571     raeburn  6835:                                             help => $help});
1.329     droeschl 6836:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
                   6837: 					    text=>$text,
                   6838: 					    faq=>273,
                   6839: 					    bug=>'Instructor Interface'});
                   6840: }
                   6841: 
1.441     www      6842: # subroutine to list form elements
                   6843: sub create_list_elements {
                   6844:    my @formarr = @_;
                   6845:    my $list = '';
1.501     raeburn  6846:    foreach my $button (@formarr){
                   6847:         foreach my $picture (keys(%{$button})) {
                   6848:             $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441     www      6849:         }
                   6850:    }
                   6851:    return $list;
                   6852: }
1.329     droeschl 6853: 
1.441     www      6854: # subroutine to create ul from list elements
                   6855: sub create_form_ul {
                   6856:    my $list = shift;
                   6857:    my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
                   6858:    return $ul;
                   6859: }
1.329     droeschl 6860: 
1.442     www      6861: #
                   6862: # Start tabs
                   6863: #
                   6864: 
                   6865: sub startContentScreen {
1.484     raeburn  6866:     my ($mode) = @_;
1.724     raeburn  6867:     my $output = '<div class="LC_landmark" role="main">'.
                   6868:                  '<ul class="LC_TabContentBigger" id="mainnav">';
1.472     raeburn  6869:     if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484     raeburn  6870:         $output .= '<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";
                   6871:         $output .= '<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";
                   6872:         $output .= '<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";
                   6873:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
                   6874:     } else {
1.549     raeburn  6875:         $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Main Content Editor').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>'."\n";
1.484     raeburn  6876:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
                   6877:         $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Content Utilities').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>'."\n";
                   6878:                    '><a href="/adm/coursedocs?tools=1"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Content Utilities').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>';
                   6879:     }
                   6880:     $output .= "\n".'</ul>'."\n";
                   6881:     $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
                   6882:                '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
                   6883:                '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
                   6884:     return $output;
1.442     www      6885: }
                   6886: 
                   6887: #
                   6888: # End tabs
                   6889: #
                   6890: 
                   6891: sub endContentScreen {
1.724     raeburn  6892:     return '</div></div></div></div>';
1.442     www      6893: }
1.329     droeschl 6894: 
1.446     www      6895: sub supplemental_base {
1.548     raeburn  6896:     return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446     www      6897: }
                   6898: 
1.329     droeschl 6899: sub handler {
                   6900:     my $r = shift;
                   6901:     &Apache::loncommon::content_type($r,'text/html');
                   6902:     $r->send_http_header;
                   6903:     return OK if $r->header_only;
1.484     raeburn  6904: 
                   6905: # get course data
1.408     raeburn  6906:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  6907:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   6908:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.712     raeburn  6909:     my $coursehome=$env{'course.'.$env{'request.course.id'}.'.home'};
1.484     raeburn  6910: 
1.606     raeburn  6911: # get docroot
                   6912:     my $londocroot = $r->dir_config('lonDocRoot');
                   6913: 
1.484     raeburn  6914: # graphics settings
                   6915:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329     droeschl 6916: 
1.443     www      6917: #
1.329     droeschl 6918: # --------------------------------------------- Initialize help topics for this
                   6919:     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627     raeburn  6920: 	               'Adding_External_Resource','Adding_External_Tool',
                   6921:                        'Navigate_Content','Adding_Folders','Docs_Overview',
                   6922: 	               'Load_Map','Supplemental','Score_Upload_Form',
                   6923: 	               'Adding_Pages','Importing_LON-CAPA_Resource',
                   6924: 	               'Importing_IMS_Course','Uploading_From_Harddrive',
1.706     raeburn  6925:                        'Course_Roster','Web_Page','Dropbox','Simple_Problem',
                   6926:                        'Standard_Problem','Course_Resources',
                   6927:                        'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329     droeschl 6928: 	$help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
                   6929:     }
                   6930:     # Composite help files
                   6931:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   6932: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   6933:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   6934: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
                   6935:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   6936: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347     weissno  6937:     $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329     droeschl 6938: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353     weissno  6939:     $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329     droeschl 6940:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534     raeburn  6941:  
1.611     raeburn  6942:     my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682     raeburn  6943: # does this user have privileges to modify content.
                   6944:     if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472     raeburn  6945: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682     raeburn  6946:         unless ($r->uri eq '/adm/supplemental') {
1.611     raeburn  6947:             $allowed = 1;
1.682     raeburn  6948:         }
                   6949:         $canedit = 1;
                   6950:         $canview = 1;
                   6951:     } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
                   6952: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
                   6953:         unless ($r->uri eq '/adm/supplemental') {
1.611     raeburn  6954:             $allowed = 1;
                   6955:         }
1.682     raeburn  6956:         $canview = 1;
1.611     raeburn  6957:     }
                   6958:     unless ($canedit) {
                   6959:         $disabled = ' disabled="disabled"';
1.472     raeburn  6960:     }
1.582     raeburn  6961:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635     raeburn  6962:     if ($env{'form.inhibitmenu'}) {
                   6963:         unless ($env{'form.inhibitmenu'} eq 'yes') {
                   6964:             delete($env{'form.inhibitmenu'});
                   6965:         }
                   6966:     }
                   6967: 
1.582     raeburn  6968:   if ($allowed && $env{'form.verify'}) {
1.571     raeburn  6969:       &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637     raeburn  6970:       if (!$canedit) {
                   6971:           &verifycontent($r);
                   6972:       } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
                   6973:           &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
                   6974:                                                   text=>'Results',
                   6975:                                                   faq=>273,
                   6976:                                                   bug=>'Instructor Interface'});
                   6977:           &verifycontent($r,$env{'form.checkstale'});
                   6978:       } else {
                   6979:           &contentverifyform($r);
                   6980:       }
1.329     droeschl 6981:   } elsif ($allowed && $env{'form.listsymbs'}) {
1.484     raeburn  6982:       &init_breadcrumbs('listsymbs','List Content IDs');
1.329     droeschl 6983:       &list_symbs($r);
1.651     raeburn  6984:   } elsif ($allowed && $env{'form.shorturls'}) {
                   6985:       &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
                   6986:       &short_urls($r,$canedit);
1.329     droeschl 6987:   } elsif ($allowed && $env{'form.docslog'}) {
                   6988:       &init_breadcrumbs('docslog','Show Log');
1.484     raeburn  6989:       my $folder = $env{'form.folder'};
                   6990:       if ($folder eq '') {
                   6991:           $folder='default';
                   6992:       }
1.611     raeburn  6993:       &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329     droeschl 6994:   } elsif ($allowed && $env{'form.versions'}) {
1.571     raeburn  6995:       &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611     raeburn  6996:       &checkversions($r,$canedit);
                   6997:   } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709     raeburn  6998:       &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329     droeschl 6999:       &dumpcourse($r);
1.712     raeburn  7000:   } elsif (($canedit || $canview) && ($env{'form.copyauthored'})) {
                   7001:       &init_breadcrumbs('copyauthored','Copy from Course Authoring to User Authoring');
                   7002:       my $readonly;
                   7003:       if (!$canedit) {
                   7004:           $readonly = 1;
                   7005:       }
                   7006:       &copycrsauthored($r,$coursenum,$coursedom,$coursehome,$readonly);
1.611     raeburn  7007:   } elsif ($canedit && $env{'form.exportcourse'}) {
1.377     bisitz   7008:       &init_breadcrumbs('exportcourse','IMS Export');
1.475     raeburn  7009:       &Apache::imsexport::exportcourse($r);
1.329     droeschl 7010:   } else {
1.611     raeburn  7011:       if ($canedit && $env{'form.authorrole'}) {
1.606     raeburn  7012:           $noendpage = 1;
                   7013:           my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
                   7014:           if ($redirect) {
                   7015:               if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
                   7016:                   my $container = 'sequence'; 
                   7017:                   my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   7018:                       $is_random_order,$container) =
                   7019:                       &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   7020:                   my (@folders)=split('&',$env{'form.folderpath'});
                   7021:                   $env{'form.foldername'}=&unescape(pop(@folders));
                   7022:                   my $folder=pop(@folders);
                   7023:                   my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   7024:                                                   $folder.'.'.$container);
                   7025:                   my $warning;
                   7026:                   if ($fatal) {
                   7027:                       if ($container eq 'page') {
                   7028:                           $warning = &mt('An error occurred retrieving the contents of the current page.');
                   7029:                       } else {
                   7030:                           $warning = &mt('An error occurred retrieving the contents of the current folder.');
                   7031:                       }
                   7032:                   } else {
                   7033:                       my $url = $redirect;
                   7034:                       my $srcfile = $londocroot.$url;
                   7035:                       $url =~ s{^/priv/}{/res/};
                   7036:                       my $targetfile = $londocroot.$url;
                   7037:                       my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   7038:                       my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
                   7039:                       $env{'form.folder'} = $folder;
                   7040:                       &snapshotbefore();
                   7041:                       my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
                   7042:                       my $ext = 'false';
                   7043:                       my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   7044:                       $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   7045:                                                         ':'.$ext.':normal:res';
                   7046:                       push(@LONCAPA::map::order,$newidx);
                   7047:                       &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
                   7048:                                                    'string_yesno');
                   7049:                       &remember_parms($newidx,'hiddenresource','set','yes');
                   7050:                       ($errtext,$fatal) =
                   7051:                           &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
                   7052:                       &log_differences($plain);
                   7053:                       &mark_hash_old();
                   7054:                       $r->internal_redirect($redirect);
                   7055:                       return OK;
                   7056:                   }
1.654     raeburn  7057:               } else {
                   7058:                   $r->internal_redirect($redirect);
1.606     raeburn  7059:               }
                   7060:           }
                   7061:       }
1.445     www      7062: #
                   7063: # Done catching special calls
1.484     raeburn  7064: # The whole rest is for course and supplemental documents and utilities menu
1.445     www      7065: # Get the parameters that may be needed
                   7066: #
                   7067:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682     raeburn  7068:                                             ['folderpath','title',
1.519     raeburn  7069:                                              'forcesupplement','forcestandard',
1.510     raeburn  7070:                                              'tools','symb','command','supppath']);
1.445     www      7071: 
1.635     raeburn  7072:     foreach my $item ('forcesupplement','forcestandard','tools') {
                   7073:         next if ($env{'form.'.$item} eq '');
                   7074:         unless ($env{'form.'.$item} eq '1') {
                   7075:             delete($env{'form.'.$item});
                   7076:         }
                   7077:     }
                   7078: 
                   7079:     if ($env{'form.command'}) {
                   7080:         unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
                   7081:             delete($env{'form.command'});
                   7082:         }
                   7083:     }
                   7084: 
                   7085:     if ($env{'form.symb'}) {
                   7086:         my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   7087:         unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { 
                   7088:             delete($env{'form.symb'});
                   7089:         }
                   7090:     }
                   7091: 
1.445     www      7092: # standard=1: this is a "new-style" course with an uploaded map as top level
                   7093: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329     droeschl 7094: 
                   7095:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445     www      7096: 
1.484     raeburn  7097: # Decide whether this should display supplemental or main content or utilities
1.445     www      7098: # supplementalflag=1: show supplemental documents
                   7099: # supplementalflag=0: show standard documents
1.484     raeburn  7100: # toolsflag=1: show utilities
1.445     www      7101: 
1.561     raeburn  7102:     my $unesc_folderpath = &unescape($env{'form.folderpath'});
                   7103:     my $supplementalflag=($unesc_folderpath=~/^supplemental/);
                   7104:     if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445     www      7105:        $supplementalflag=0;
                   7106:     }
                   7107:     if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
                   7108:     if ($env{'form.forcestandard'})   { $supplementalflag=0; }
1.705     raeburn  7109:     unless (($supplementalflag) ||
                   7110:             ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
                   7111:         unless ($allowed) { $supplementalflag=1; }
                   7112:         unless ($standard) { $supplementalflag=1; }
                   7113:     }
1.484     raeburn  7114:     my $toolsflag=0;
                   7115:     if ($env{'form.tools'}) { $toolsflag=1; }
1.445     www      7116: 
1.635     raeburn  7117:     if ($env{'form.folderpath'} ne '') {
1.685     raeburn  7118:         &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635     raeburn  7119:     }
                   7120: 
1.685     raeburn  7121:     my $backto_supppath;
1.635     raeburn  7122:     if ($env{'form.supppath'} ne '') {
1.685     raeburn  7123:         if ($supplementalflag && $allowed) {
                   7124:             $backto_supppath = &validate_supppath($coursenum,$coursedom);
                   7125:         }
1.635     raeburn  7126:     }
                   7127: 
1.329     droeschl 7128:     my $script='';
                   7129:     my $showdoc=0;
1.457     raeburn  7130:     my $addentries = {};
1.475     raeburn  7131:     my $container;
1.329     droeschl 7132:     my $containertag;
1.508     raeburn  7133:     my $pathitem;
1.598     raeburn  7134:     my %ltitools;
1.699     raeburn  7135:     my $posslti;
1.617     raeburn  7136:     my $hiddentop;
1.615     raeburn  7137:     my $navmap;
1.617     raeburn  7138:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329     droeschl 7139: 
1.464     www      7140: # Do we directly jump somewhere?
1.525     raeburn  7141:    if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472     raeburn  7142:        if ($env{'form.symb'} ne '') {
1.522     raeburn  7143:            $env{'form.folderpath'}=
1.617     raeburn  7144:                &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530     raeburn  7145:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525     raeburn  7146:                $env{'form.command'}.'_'.$env{'form.symb'}});
1.685     raeburn  7147:        } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472     raeburn  7148:            $env{'form.folderpath'}=$env{'form.supppath'};
1.530     raeburn  7149:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685     raeburn  7150:                $env{'form.command'}.'_'.$backto_supppath});
1.466     www      7151:        }
1.472     raeburn  7152:    } elsif ($env{'form.command'} eq 'editdocs') {
1.617     raeburn  7153:        $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525     raeburn  7154:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472     raeburn  7155:    } elsif ($env{'form.command'} eq 'editsupp') {
1.617     raeburn  7156:        $env{'form.folderpath'} = &supplemental_base();
1.525     raeburn  7157:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
                   7158:    } elsif ($env{'form.command'} eq 'contents') {
                   7159:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
                   7160:    } elsif ($env{'form.command'} eq 'home') {
                   7161:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464     www      7162:    }
                   7163: 
1.525     raeburn  7164: 
1.445     www      7165: # Where do we store these for when we come back?
                   7166:     my $stored_folderpath='docs_folderpath';
                   7167:     if ($supplementalflag) {
                   7168:        $stored_folderpath='docs_sup_folderpath';
                   7169:     }
1.464     www      7170: 
1.519     raeburn  7171: # No folderpath, and in edit mode, see if we have something stored
                   7172:     if ((!$env{'form.folderpath'}) && $allowed) {
1.445     www      7173:         &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510     raeburn  7174:                                           {'folderpath' => 'scalar'});
1.615     raeburn  7175: 
                   7176:         if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
                   7177:             if ($supplementalflag) {
                   7178:                 undef($env{'form.folderpath'}) if ($1 eq 'default'); 
                   7179:             } else {
                   7180:                 undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
                   7181:             }
                   7182:         } else {
1.523     raeburn  7183:             undef($env{'form.folderpath'});
                   7184:         }
1.677     raeburn  7185:         if ($env{'form.folderpath'} ne '') {
1.685     raeburn  7186:             &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677     raeburn  7187:         }
1.329     droeschl 7188:     }
1.706     raeburn  7189: 
                   7190: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705     raeburn  7191:     if ((!$allowed) && ($supplementalflag)) {
1.446     www      7192:         unless ($env{'form.folderpath'} =~ /^supplemental/) {
                   7193:             $env{'form.folderpath'} = &supplemental_base();
1.409     raeburn  7194:         }
                   7195:     }
1.446     www      7196: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329     droeschl 7197:     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446     www      7198:         $env{'form.folderpath'} = &supplemental_base()
                   7199:                                   .'&'.
1.329     droeschl 7200:                                   $env{'form.folderpath'};
                   7201:     }
1.685     raeburn  7202: # If allowed and user's role is not advanced check folderpath is not hidden
                   7203:     my $hidden_and_empty;
1.687     raeburn  7204:     if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685     raeburn  7205:         my ($folderurl,$foldername,$hiddenfolder);
1.615     raeburn  7206:         my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617     raeburn  7207:         my $folder = $pathitems[-2];
                   7208:         if ($folder eq '') {
                   7209:             undef($env{'form.folderpath'});
                   7210:         } else {
                   7211:             $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666     raeburn  7212:             if ((split(/\:/,$pathitems[-1]))[5]) {
1.615     raeburn  7213:                 $folderurl .= '.page';
                   7214:             } else {
                   7215:                 $folderurl .= '.sequence';
                   7216:             }
1.685     raeburn  7217:             if ($supplementalflag) {
                   7218:                 ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
                   7219:                 $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688     raeburn  7220:                 my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn  7221:                 if (ref($supplemental) eq 'HASH') {
                   7222:                     my ($suppmap,$suppmapnum);
                   7223:                     if ($folder eq 'supplemental') {
                   7224:                         $suppmap = 'default';
                   7225:                         $suppmapnum = 0;
                   7226:                     } elsif ($folder =~ /^supplemental_(\d+)$/) {
                   7227:                         $suppmap = $1;
                   7228:                         $suppmapnum = $suppmap;
                   7229:                     }
                   7230:                     if ($hiddenfolder) {
                   7231:                         my $hascontent;
                   7232:                         foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
                   7233:                             if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
                   7234:                                 $hascontent = 1;
                   7235:                             } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
                   7236:                                 foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
                   7237:                                     if ($id =~ /^$suppmapnum\:/) {
                   7238:                                         $hascontent = 1;
                   7239:                                         last;
                   7240:                                     }
                   7241:                                 }
                   7242:                             }
                   7243:                             last if ($hascontent);
                   7244:                         }
                   7245:                         unless ($hascontent) {
                   7246:                             if ($foldername ne '') {
                   7247:                                 $hidden_and_empty = $foldername;
                   7248:                             } else {
                   7249:                                 $hidden_and_empty = $folder;
                   7250:                             }
                   7251:                         }
                   7252:                     }
                   7253:                 }
                   7254:             } else {
                   7255:                 unless (ref($navmap)) {
                   7256:                     $navmap = Apache::lonnavmaps::navmap->new();
                   7257:                 }
                   7258:                 ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
                   7259:                 $foldername = &HTML::Entities::decode(&unescape($foldername));
                   7260:                 if (ref($navmap)) {
                   7261:                     if ($hiddenfolder ||
                   7262:                         (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
                   7263:                         my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
                   7264:                         unless (@resources) {
                   7265:                             if ($foldername ne '') {
                   7266:                                 $hidden_and_empty = $foldername;
                   7267:                             } else {
                   7268:                                 $hidden_and_empty = $folder;
                   7269:                             }
                   7270:                         }
                   7271:                     }
                   7272:                 }
1.617     raeburn  7273:             }
1.685     raeburn  7274:             if ($hidden_and_empty ne '') {
                   7275:                 splice(@pathitems,-2);
                   7276:                 if (@pathitems) {
                   7277:                     $env{'form.folderpath'} = join('&',@pathitems);
                   7278:                 } else {
                   7279:                     undef($env{'form.folderpath'});
1.615     raeburn  7280:                 }
                   7281:             }
                   7282:         }
                   7283:     }
                   7284: 
1.446     www      7285: # If after all of this, we still don't have any paths, make them
1.519     raeburn  7286:     unless ($env{'form.folderpath'}) {
1.446     www      7287:        if ($supplementalflag) {
                   7288:           $env{'form.folderpath'}=&supplemental_base();
1.617     raeburn  7289:        } elsif ($allowed) {
                   7290:           ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446     www      7291:        }
1.472     raeburn  7292:     }
1.446     www      7293: 
1.445     www      7294: # Store this
1.484     raeburn  7295:     unless ($toolsflag) {
1.615     raeburn  7296:         if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510     raeburn  7297:             &Apache::loncommon::store_course_settings($stored_folderpath,
1.519     raeburn  7298:                                                       {'folderpath' => 'scalar'});
1.510     raeburn  7299:         }
1.519     raeburn  7300:         my $folderpath;
1.484     raeburn  7301:         if ($env{'form.folderpath'}) {
1.519     raeburn  7302:             $folderpath = $env{'form.folderpath'};
                   7303: 	    my (@folders)=split('&',$env{'form.folderpath'});
                   7304: 	    $env{'form.foldername'}=&unescape(pop(@folders));
                   7305:             if ($env{'form.foldername'} =~ /\:1$/) {
                   7306:                 $container = 'page';
                   7307:             } else {
                   7308:                 $container = 'sequence';
                   7309:             }
                   7310: 	    $env{'form.folder'}=pop(@folders);
1.484     raeburn  7311:         } else {
1.519     raeburn  7312:             if ($env{'form.folder'} eq '' ||
                   7313:                 $env{'form.folder'} eq 'supplemental') {
1.617     raeburn  7314:                 if ($env{'form.folder'} eq 'supplemental') {
                   7315:                     $folderpath=&supplemental_base();
                   7316:                 } elsif (!$hiddentop) {
                   7317:                     $folderpath='default&'.
                   7318:                                  &escape(&mt('Main Content').':::::');
                   7319:                 }
1.484     raeburn  7320:             }
                   7321:         }
1.519     raeburn  7322:         $containertag = '<input type="hidden" name="folderpath" value="" />';
                   7323:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484     raeburn  7324:         if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
                   7325:            $showdoc='/'.$1;
                   7326:         }
                   7327:         if ($showdoc) { # got called in sequence from course
                   7328: 	    $allowed=0; 
                   7329:         } else {
1.611     raeburn  7330:             if ($canedit) {
1.484     raeburn  7331:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   7332:                 $script=&Apache::lonratedt::editscript('simple');
1.433     raeburn  7333:             }
                   7334:         }
1.329     droeschl 7335:     }
                   7336: 
1.344     bisitz   7337: # get personal data
1.329     droeschl 7338:     my $uname=$env{'user.name'};
                   7339:     my $udom=$env{'user.domain'};
                   7340:     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
                   7341: 
                   7342:     if ($allowed) {
1.484     raeburn  7343:         if ($toolsflag) {
                   7344:             $script .= &inject_data_js();
                   7345:             my ($home,$other,%outhash)=&authorhosts();
                   7346:             if (!$home && $other) {
                   7347:                 my @hosts;
                   7348:                 foreach my $aurole (keys(%outhash)) {
                   7349:                     unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   7350:                         push(@hosts,$outhash{$aurole});
                   7351:                     }
                   7352:                 }
                   7353:                 $script .= &dump_switchserver_js(@hosts); 
                   7354:             }
1.458     raeburn  7355:         } else {
1.570     raeburn  7356:             my $tid = 1;
1.484     raeburn  7357:             my @tabids;
                   7358:             if ($supplementalflag) {
1.655     raeburn  7359:                 @tabids = ('002','dd2','ee2','ff2');
1.570     raeburn  7360:                 $tid = 2;
1.484     raeburn  7361:             } else {
1.726     raeburn  7362:                 @tabids = ('aa1','bb1','cc1','dd1','ff1');
1.519     raeburn  7363:                 unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484     raeburn  7364:                     unshift(@tabids,'001');
1.726     raeburn  7365:                     push(@tabids,'ee1');
1.484     raeburn  7366:                 }
1.458     raeburn  7367:             }
1.484     raeburn  7368:             my $tabidstr = join("','",@tabids);
1.699     raeburn  7369:             my (%domtools,%crstools);
                   7370:             my %tooltypes = &Apache::loncommon::usable_exttools();
                   7371:             if ($tooltypes{'dom'}) {
                   7372:                 %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
                   7373:             }
                   7374:             if ($tooltypes{'crs'}) {
                   7375:                 %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
                   7376:             }
                   7377:             %ltitools = (
                   7378:                           dom => \%domtools,
                   7379:                           crs => \%crstools,
                   7380:                         );
                   7381:             $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622     raeburn  7382:             my $hostname = $r->hostname();
1.606     raeburn  7383: 	    $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622     raeburn  7384:                                    $londocroot,$canedit,$hostname,\$navmap).
1.484     raeburn  7385:                        &history_tab_js().
                   7386:                        &inject_data_js().
1.570     raeburn  7387:                        &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598     raeburn  7388:                        &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685     raeburn  7389:             my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
                   7390:             if ($hidden_and_empty ne '') {
                   7391:                 my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
                   7392:                                 $hidden_and_empty);
                   7393:                 $onload .= "javascript:alert('".&js_escape($alert)."');";
                   7394:             }
1.484     raeburn  7395:             $addentries = {
1.685     raeburn  7396:                             onload => $onload,
1.484     raeburn  7397:                           };
1.458     raeburn  7398:         }
1.538     raeburn  7399:         $script .= &paste_popup_js(); 
1.501     raeburn  7400:         my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
                   7401:                              &mt('Switch server?');
                   7402:         
                   7403: 
1.329     droeschl 7404:     }
                   7405: # -------------------------------------------------------------------- Body tag
1.369     bisitz   7406:     $script = '<script type="text/javascript">'."\n"
1.372     bisitz   7407:               .'// <![CDATA['."\n"
                   7408:               .$script."\n"
                   7409:               .'// ]]>'."\n"
1.595     musolffc 7410:               .'</script>'."\n"
                   7411:               .'<script type="text/javascript" 
                   7412:                 src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385     bisitz   7413: 
                   7414:     # Breadcrumbs
                   7415:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510     raeburn  7416: 
                   7417:     if ($showdoc) {
1.682     raeburn  7418:         my $args;
                   7419:         if ($supplementalflag) {
1.687     raeburn  7420:             my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
                   7421:             my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705     raeburn  7422:             $args = {'bread_crumbs' => $brcrum,
                   7423:                      'bread_crumbs_nomenu' => 1};
1.682     raeburn  7424:         } else {
                   7425:             $args = {'force_register' => $showdoc};
                   7426:         }
                   7427:         $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571     raeburn  7428:     } elsif ($toolsflag) {
1.611     raeburn  7429:         my ($breadtext,$breadtitle);
1.617     raeburn  7430:         $breadtext = "$crstype Editor";
1.611     raeburn  7431:         if ($canedit) {
                   7432:             $breadtitle = 'Editing '.$crstype.' Contents';
                   7433:         } else {
                   7434:             $breadtext .= ' (View-only mode)';
                   7435:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   7436:         }
1.571     raeburn  7437:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  7438:             href=>"/adm/coursedocs",text=>$breadtext});
1.571     raeburn  7439:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
                   7440:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   7441:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  7442:                      $breadtitle)
1.571     raeburn  7443:                  );
1.510     raeburn  7444:     } elsif ($r->uri eq '/adm/supplemental') {
1.682     raeburn  7445:         unless ($env{'request.role.adv'}) {
                   7446:             unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
                   7447:                 $r->internal_redirect('/adm/navmaps');
                   7448:                 return OK;
                   7449:             }
                   7450:         }
1.510     raeburn  7451:         my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705     raeburn  7452:         my $args = {'bread_crumbs' => $brcrum};
                   7453:         unless (($env{'form.folderpath'} eq '') ||
                   7454:                 ($env{'form.folder'} eq 'supplemental')) {
                   7455:             $args->{'bread_crumbs_nomenu'} = 1;
                   7456:         }
1.510     raeburn  7457:         $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705     raeburn  7458:                                                  $args));
1.510     raeburn  7459:     } else {
1.611     raeburn  7460:         my ($breadtext,$breadtitle,$helpitem);
1.617     raeburn  7461:         $breadtext = "$crstype Editor";
1.611     raeburn  7462:         if ($canedit) {
                   7463:             $breadtitle = 'Editing '.$crstype.' Contents';
                   7464:             $helpitem = 'Docs_Adding_Course_Doc';
                   7465:         } else {
                   7466:             $breadtext .= ' (View-only mode)';
                   7467:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   7468:             $helpitem = 'Docs_Viewing_Course_Doc';
                   7469:         }
1.392     raeburn  7470:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  7471:             href=>"/adm/coursedocs",text=>$breadtext});
1.446     www      7472:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510     raeburn  7473:                                                  {'add_entries'    => $addentries}
                   7474:                                                 )
1.392     raeburn  7475:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   7476:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  7477:                      $breadtitle,
                   7478:                      $helpitem)
1.392     raeburn  7479:         );
                   7480:     }
1.364     bisitz   7481: 
1.329     droeschl 7482:   my %allfiles = ();
                   7483:   my %codebase = ();
1.440     raeburn  7484:   my ($upload_result,$upload_output,$uploadphase);
1.611     raeburn  7485:   if ($canedit) {
1.684     raeburn  7486:       undef($suppchanges);
1.329     droeschl 7487:       if (($env{'form.uploaddoc.filename'}) &&
                   7488: 	  ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440     raeburn  7489:           my $context = $1; 
                   7490:           # Process file upload - phase one - upload and parse primary file.
1.329     droeschl 7491: 	  undef($hadchanges);
1.440     raeburn  7492:           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552     raeburn  7493:                                               \%allfiles,\%codebase,$context,$crstype);
1.638     raeburn  7494:           undef($navmap);
1.329     droeschl 7495: 	  if ($hadchanges) {
                   7496: 	      &mark_hash_old();
                   7497: 	  }
1.684     raeburn  7498:           if ($suppchanges) {
                   7499:               &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
                   7500:               undef($suppchanges);
                   7501:           }
1.440     raeburn  7502:           $r->print($upload_output);
                   7503:       } elsif ($env{'form.phase'} eq 'upload_embedded') {
                   7504:           # Process file upload - phase two - upload embedded objects 
                   7505:           $uploadphase = 'check_embedded';
                   7506:           my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');   
                   7507:           my $state = &embedded_form_elems($uploadphase,$primaryurl,
                   7508:                                            $env{'form.newidx'});
                   7509:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   7510:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   7511:           my ($destination,$dir_root) = &embedded_destination();
                   7512:           my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
                   7513:           my $actionurl = '/adm/coursedocs';
1.630     raeburn  7514:           my ($result,$flag) =
1.440     raeburn  7515:               &Apache::loncommon::upload_embedded('coursedoc',$destination,
                   7516:                   $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
                   7517:                   $actionurl);
                   7518:           $r->print($result.&return_to_editor());
                   7519:       } elsif ($env{'form.phase'} eq 'check_embedded') {
                   7520:           # Process file upload - phase three - modify references in HTML file
                   7521:           $uploadphase = 'modified_orightml';
                   7522:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   7523:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   7524:           my ($destination,$dir_root) = &embedded_destination();
1.630     raeburn  7525:           my $result =
1.482     raeburn  7526:               &Apache::loncommon::modify_html_refs('coursedoc',$destination,
                   7527:                                                    $docuname,$docudom,undef,
                   7528:                                                    $dir_root);
1.630     raeburn  7529:           $r->print($result.&return_to_editor());
1.476     raeburn  7530:       } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
                   7531:           $uploadphase = 'decompress_phase_one';
                   7532:           $r->print(&decompression_phase_one().
                   7533:                     &return_to_editor());
                   7534:       } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
                   7535:           $uploadphase = 'decompress_phase_two';
                   7536:           $r->print(&decompression_phase_two().
                   7537:                     &return_to_editor());
1.329     droeschl 7538:       }
                   7539:   }
                   7540: 
1.484     raeburn  7541:   if ($allowed && $toolsflag) {
                   7542:       $r->print(&startContentScreen('tools'));
1.708     raeburn  7543:       $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484     raeburn  7544:       $r->print(&endContentScreen());
                   7545:   } elsif ((!$showdoc) && (!$uploadphase)) {
1.329     droeschl 7546: # -----------------------------------------------------------------------------
                   7547:        my %lt=&Apache::lonlocal::texthash(
                   7548: 		'copm' => 'All documents out of a published map into this folder',
1.501     raeburn  7549:                 'upfi' => 'Upload File',
1.553     raeburn  7550:                 'upld' => 'Upload Content',
1.706     raeburn  7551:                 'srch' => 'Search Repository',
                   7552:                 'impo' => 'Import from Repository',
1.487     raeburn  7553: 		'lnks' => 'Import from Stored Links',
1.502     raeburn  7554:                 'impm' => 'Import from Assembled Map',
1.630     raeburn  7555:                 'imcr' => 'Import from Course Resources',
1.598     raeburn  7556:                 'extr' => 'External Resource',
                   7557:                 'extt' => 'External Tool',
1.329     droeschl 7558:                 'selm' => 'Select Map',
                   7559:                 'load' => 'Load Map',
                   7560:                 'newf' => 'New Folder',
                   7561:                 'newp' => 'New Composite Page',
                   7562:                 'syll' => 'Syllabus',
1.425     raeburn  7563:                 'navc' => 'Table of Contents',
1.343     biermanm 7564:                 'sipa' => 'Simple Course Page',
1.329     droeschl 7565:                 'sipr' => 'Simple Problem',
1.630     raeburn  7566:                 'webp' => 'Blank Web Page (editable)',
1.606     raeburn  7567:                 'stpr' => 'Standard Problem',
                   7568:                 'news' => 'New sub-directory',
                   7569:                 'crpr' => 'Create Problem',
1.689     raeburn  7570:                 'swit' => 'Switch Server',
1.329     droeschl 7571:                 'drbx' => 'Drop Box',
1.451     www      7572:                 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336     schafran 7573:                 'bull' => 'Discussion Board',
1.347     weissno  7574:                 'mypi' => 'My Personal Information Page',
1.353     weissno  7575:                 'grpo' => 'Group Portfolio',
1.329     droeschl 7576:                 'rost' => 'Course Roster',
1.528     raeburn  7577:                 'abou' => 'Personal Information Page for a User',
1.553     raeburn  7578:                 'imsf' => 'IMS Upload',
                   7579:                 'imsl' => 'Upload IMS package',
1.501     raeburn  7580:                 'cms'  => 'Origin of IMS package',
                   7581:                 'se'   => 'Select',
1.329     droeschl 7582:                 'file' =>  'File',
                   7583:                 'title' => 'Title',
1.606     raeburn  7584:                 'addp' => 'Add Placeholder to course?',
                   7585:                 'uste' => 'Use Template?',
                   7586:                 'fnam' => 'File Name:',
                   7587:                 'loca' => 'Location:',
                   7588:                 'dire' => 'Directory:',
                   7589:                 'cate' => 'Category:',
                   7590:                 'tmpl' => 'Template:',
1.698     raeburn  7591:                 'empd' => 'No resources found',
1.329     droeschl 7592:                 'comment' => 'Comment',
1.403     raeburn  7593:                 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577     bisitz   7594:                 'bb5'      => 'Blackboard 5',
                   7595:                 'bb6'      => 'Blackboard 6',
                   7596:                 'angel5'   => 'ANGEL 5.5',
                   7597:                 'webctce4' => 'WebCT 4 Campus Edition',
1.606     raeburn  7598:                 'yes'      => 'Yes',
                   7599:                 'no'       => 'No',
1.618     raeburn  7600:                 'er' => 'Editing rights unavailable for your current role.',
1.577     bisitz   7601:         );
1.329     droeschl 7602: # -----------------------------------------------------------------------------
1.595     musolffc 7603: 
                   7604:     # Calculate free quota space for a user or course. A javascript function checks
                   7605:     # file size to determine if upload should be allowed.
                   7606:     my $quotatype = 'unofficial';
                   7607:     if ($crstype eq 'Community') {
1.601     raeburn  7608:         $quotatype = 'community';
                   7609:     } elsif ($crstype eq 'Placement') {
                   7610:         $quotatype = 'placement';
1.595     musolffc 7611:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
                   7612:         $quotatype = 'official';
                   7613:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   7614:         $quotatype = 'textbook';
                   7615:     }
                   7616:     my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
                   7617:                      'course',$quotatype); # expressed in MB
                   7618:     my $current_disk_usage = 0;
                   7619:     foreach my $subdir ('docs','supplemental') {
                   7620:         $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
                   7621:                                "userfiles/$subdir",1); # expressed in kB
                   7622:     }
                   7623:     my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605     raeburn  7624:     my $usage = $current_disk_usage/1024; # in MB
                   7625:     my $quota = $disk_quota;
                   7626:     my $percent;
                   7627:     if ($disk_quota == 0) {
                   7628:         $percent = 100.0;
                   7629:     } else {
1.619     raeburn  7630:         $percent = 100*($usage/$disk_quota);
1.605     raeburn  7631:     }
                   7632:     $usage = sprintf("%.2f",$usage);
                   7633:     $quota = sprintf("%.2f",$quota);
                   7634:     $percent = sprintf("%.0f",$percent);
                   7635:     my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
                   7636:                               $percent.'%',$quota.' MB').'</p>';
1.595     musolffc 7637: 
1.329     droeschl 7638: 	my $checkbox=(<<CHBO);
                   7639: 	<!-- <label>$lt{'parse'}?
                   7640: 	<input type="checkbox" name="parserflag" />
                   7641: 	</label> -->
                   7642: 	<label>
1.611     raeburn  7643: 	<input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329     droeschl 7644: 	</label>
                   7645: CHBO
1.501     raeburn  7646:         my $imsfolder = $env{'form.folder'};
                   7647:         if ($imsfolder eq '') {
                   7648:             $imsfolder = 'default';  
                   7649:         }
                   7650:         my $imspform=(<<IMSFORM);
                   7651:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
                   7652:         $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
                   7653:         <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516     raeburn  7654:         <fieldset id="uploadimsform" style="display: none;">
1.501     raeburn  7655:         <legend>$lt{'imsf'}</legend>
1.723     raeburn  7656:         $quotainfo
                   7657:         <label>$lt{'file'}:<br />
                   7658:         <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled /></label>
1.702     raeburn  7659:         <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501     raeburn  7660:         <br />
                   7661:         <p>
                   7662:         $lt{'cms'}:&nbsp; 
1.611     raeburn  7663:         <select name="source" $disabled>
1.501     raeburn  7664:         <option value="-1" selected="selected">$lt{'se'}</option>
1.577     bisitz   7665:         <option value="bb5">$lt{'bb5'}</option>
                   7666:         <option value="bb6">$lt{'bb6'}</option>
                   7667:         <option value="angel5">$lt{'angel5'}</option>
                   7668:         <option value="webctce4">$lt{'webctce4'}</option>
1.501     raeburn  7669:         </select>
                   7670:         <input type="hidden" name="folder" value="$imsfolder" />
                   7671:         </p>
                   7672:         <input type="hidden" name="phase" value="one" />
1.611     raeburn  7673:         <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501     raeburn  7674:         </fieldset>
                   7675:         </form>
                   7676: IMSFORM
1.329     droeschl 7677: 
                   7678: 	my $fileuploadform=(<<FUFORM);
1.501     raeburn  7679:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
                   7680:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
                   7681:         <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516     raeburn  7682:         <fieldset id="uploaddocform" style="display: none;">
1.501     raeburn  7683:         <legend>$lt{'upfi'}</legend>
1.371     tempelho 7684: 	<input type="hidden" name="active" value="aa" />
1.723     raeburn  7685:         $quotainfo
                   7686:         <label>$lt{'file'}:<br />
                   7687:         <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled /></label>
1.702     raeburn  7688:         <input type="hidden" id="LC_free_space" value="$free_space" />
1.329     droeschl 7689: 	<br />
1.723     raeburn  7690:         <label>
1.329     droeschl 7691: 	$lt{'title'}:<br />
1.723     raeburn  7692: 	<input type="text" size="60" name="comment" $disabled /></label>
1.508     raeburn  7693: 	$pathitem
1.329     droeschl 7694: 	<input type="hidden" name="cmd" value="upload_default" />
                   7695: 	<br />
1.458     raeburn  7696: 	<span class="LC_nobreak" style="float:left">
1.329     droeschl 7697: 	$checkbox
                   7698: 	</span>
1.501     raeburn  7699:         <br clear="all" />
1.611     raeburn  7700:         <input type="submit" value="$lt{'upld'}" $disabled />
1.501     raeburn  7701:         </fieldset>
                   7702:         </form>
1.383     tempelho 7703: FUFORM
1.329     droeschl 7704: 
1.611     raeburn  7705:         my $mapimportjs;
                   7706:         if ($canedit) {
                   7707:             $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');"; 
                   7708:         } else {
                   7709:             $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
                   7710:         }
1.502     raeburn  7711: 	my $importpubform=(<<SEDFFORM);
1.514     raeburn  7712:         <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502     raeburn  7713:         $lt{'impm'}</a>$help{'Load_Map'}
                   7714: 	<form action="/adm/coursedocs" method="post" name="mapimportform">
1.516     raeburn  7715:         <fieldset id="importmapform" style="display: none;">
1.502     raeburn  7716:         <legend>$lt{'impm'}</legend>
1.371     tempelho 7717: 	<input type="hidden" name="active" value="bb" />
1.723     raeburn  7718:         <label>$lt{'copm'}<br />
1.502     raeburn  7719:         <span class="LC_nobreak">
                   7720:         <input type="text" name="importmap" size="40" value="" 
1.611     raeburn  7721:         onfocus="this.blur();$mapimportjs" $disabled />
1.723     raeburn  7722:         &nbsp;<a href="$mapimportjs">$lt{'selm'}</a></span></label><br />
1.611     raeburn  7723:         <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502     raeburn  7724:         </fieldset>
                   7725:         </form>
                   7726: 
1.383     tempelho 7727: SEDFFORM
1.706     raeburn  7728:         my ($importcrsresform,$checkcrsres);
                   7729:         if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
                   7730:             $checkcrsres = 1;
                   7731:         } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
                   7732:             my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
1.710     raeburn  7733:             my $type = lc($env{'course.'.$env{'request.course.id'}.'.type'});
                   7734:             unless (($type eq 'community') || ($type eq 'placement')) {
                   7735:                 $type = 'unofficial';
                   7736:                 if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'} ne '') {
                   7737:                     $type = 'official';
                   7738:                 } elsif ($env{'course.'.$env{'request.course.id'}.'internal.textbook'} ne '') {
                   7739:                     $type = 'textbook';
                   7740:                 } else {
                   7741:                     $type = 'unofficial';
                   7742:                 }
                   7743:             }
                   7744:             if ($domdefs{$type.'crsauthor'}) {
1.706     raeburn  7745:                 $checkcrsres = 1;
                   7746:             }
                   7747:         }
                   7748:         if ($checkcrsres) {
                   7749:             my ($numdirs,$pickfile) = 
                   7750:                 &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
                   7751:                                                           "resize_scrollbox('contentscroll','1','0');",
                   7752:                                                           undef,'res');
                   7753:             if ($pickfile) {
                   7754:                 $importcrsresform=(<<CRSFORM);
1.690     raeburn  7755:         <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606     raeburn  7756:         $lt{'imcr'}</a>$help{'Course_Resources'}
                   7757:         <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
                   7758:         <fieldset id="importcrsresform" style="display: none;">
                   7759:         <legend>$lt{'imcr'}</legend>
1.698     raeburn  7760:         <div id="importcrsrescontent" style="display: none;">
1.606     raeburn  7761:         <input type="hidden" name="active" value="bb" />
                   7762:         $pickfile
1.723     raeburn  7763:         <p><label>
1.699     raeburn  7764:         $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.723     raeburn  7765:         </label></p>
1.606     raeburn  7766:         <input type="hidden" name="importdetail" value="" />
1.690     raeburn  7767:         <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698     raeburn  7768:         </div>
                   7769:         <div id="importcrsresempty" style="display: none;">
                   7770:         <p>
                   7771:         $lt{'empd'}
                   7772:         </p>
                   7773:         </div>
1.606     raeburn  7774:         </fieldset>
                   7775:         </form>
                   7776: CRSFORM
1.706     raeburn  7777:             }
1.606     raeburn  7778:         }
                   7779: 
1.611     raeburn  7780:         my $fromstoredjs;
                   7781:         if ($canedit) {
                   7782:             $fromstoredjs = 'open_StoredLinks_Import()'; 
                   7783:         } else {
                   7784:             $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
                   7785:         }
                   7786: 
1.502     raeburn  7787: 	my @importpubforma = (
1.706     raeburn  7788: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'"  onclick="javascript:groupsearch()" />' => $pathitem."<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>$help{'Search_LON-CAPA_Resource'}" },
1.423     onken    7789: 	{ '<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.706     raeburn  7790: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:'.$fromstoredjs.';" />' => '<a class="LC_menubuttons_link" href="javascript:'.$fromstoredjs.';">'.$lt{'lnks'}.'</a>'.$help{'Import_Stored_Links'} },
1.606     raeburn  7791:         { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
                   7792:         );
1.706     raeburn  7793:         if ($importcrsresform) {
                   7794:             push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/impcrsau.png" alt="'.$lt{imcr}.'"  onclick="javascript:toggleImportCrsres(\'res\');" />' => $importcrsresform});
1.606     raeburn  7795: 	}
1.502     raeburn  7796: 	$importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510     raeburn  7797:         my $extresourcesform =
                   7798:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611     raeburn  7799:                                                  $help{'Adding_External_Resource'},
                   7800:                                                  undef,undef,undef,undef,undef,undef,$disabled);
1.598     raeburn  7801:         my $exttoolform =
                   7802:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
                   7803:                                                  $help{'Adding_External_Tool'},undef,
                   7804:                                                  undef,'tool',$coursedom,$coursenum,
1.611     raeburn  7805:                                                  \%ltitools,$disabled);
1.329     droeschl 7806:     if ($allowed) {
1.492     raeburn  7807:         my $folder = $env{'form.folder'};
                   7808:         if ($folder eq '') {
                   7809:             $folder='default';
                   7810:         }
1.615     raeburn  7811:         if ($canedit) {
                   7812: 	    my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
                   7813:             if ($output) {
                   7814:                 $r->print($output);
                   7815:             }
1.538     raeburn  7816:         }
1.337     ehlerst  7817: 	$r->print(<<HIDDENFORM);
                   7818: 	<form name="renameform" method="post" action="/adm/coursedocs">
                   7819:    <input type="hidden" name="title" />
                   7820:    <input type="hidden" name="cmd" />
                   7821:    <input type="hidden" name="markcopy" />
                   7822:    <input type="hidden" name="copyfolder" />
                   7823:    $containertag
                   7824:  </form>
1.633     raeburn  7825:  <form name="aliasform" method="post" action="/adm/coursedocs">
                   7826:    <input type="hidden" name="alias" />
                   7827:    <input type="hidden" name="cmd" />
                   7828:    $containertag
                   7829:  </form>
1.484     raeburn  7830: 
1.337     ehlerst  7831: HIDDENFORM
1.508     raeburn  7832:         $r->print(&makesimpleeditform($pathitem)."\n".
                   7833:                   &makedocslogform($pathitem."\n".
1.484     raeburn  7834:                                    '<input type="hidden" name="folder" value="'.
                   7835:                                    $env{'form.folder'}.'" />'."\n"));
1.329     droeschl 7836:     }
1.442     www      7837: 
                   7838: # Generate the tabs
1.510     raeburn  7839:     my ($mode,$needs_end);
1.472     raeburn  7840:     if (($supplementalflag) && (!$allowed)) {
1.510     raeburn  7841:         my @folders = split('&',$env{'form.folderpath'});
                   7842:         unless (@folders > 2) {
                   7843:             &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
                   7844:             $needs_end = 1;
                   7845:         }
1.472     raeburn  7846:     } else {
1.484     raeburn  7847:         $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510     raeburn  7848:         $needs_end = 1;
1.472     raeburn  7849:     }
1.443     www      7850: 
1.442     www      7851: #
1.622     raeburn  7852:     my $hostname = $r->hostname();
1.442     www      7853:     my $savefolderpath;
                   7854: 
1.395     raeburn  7855:     if ($allowed) {
1.329     droeschl 7856:        my $folder=$env{'form.folder'};
1.615     raeburn  7857:        if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329     droeschl 7858:            $folder='default';
1.356     tempelho 7859: 	   $savefolderpath = $env{'form.folderpath'};
1.548     raeburn  7860: 	   $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508     raeburn  7861:            $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329     droeschl 7862: 	       &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
                   7863:        }
                   7864:        my $postexec='';
                   7865:        if ($folder eq 'default') {
1.653     raeburn  7866:            my $windowname = 'loncapaclient';
                   7867:            if ($env{'request.lti.login'}) {
                   7868:                $windowname .= 'lti';
                   7869:            }
1.372     bisitz   7870:            $r->print('<script type="text/javascript">'."\n"
                   7871:                     .'// <![CDATA['."\n"
1.653     raeburn  7872:                     .'this.window.name="'.$windowname.'";'."\n"
1.372     bisitz   7873:                     .'// ]]>'."\n"
                   7874:                     .'</script>'."\n"
1.369     bisitz   7875:        );
1.329     droeschl 7876:        } else {
                   7877:            #$postexec='self.close();';
                   7878:        }
1.504     raeburn  7879:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
                   7880:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329     droeschl 7881: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
                   7882: 
                   7883: 	my $newnavform=(<<NNFORM);
                   7884: 	<form action="/adm/coursedocs" method="post" name="newnav">
1.655     raeburn  7885: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  7886: 	$pathitem
1.329     droeschl 7887: 	<input type="hidden" name="importdetail" 
                   7888: 	value="$lt{'navc'}=/adm/navmaps" />
1.611     raeburn  7889: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329     droeschl 7890: 	$help{'Navigate_Content'}
                   7891: 	</form>
                   7892: NNFORM
                   7893: 	my $newsmppageform=(<<NSPFORM);
                   7894: 	<form action="/adm/coursedocs" method="post" name="newsmppg">
1.655     raeburn  7895: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  7896: 	$pathitem
1.329     droeschl 7897: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7898: 	<a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383     tempelho 7899: 	$help{'Simple Page'}
1.329     droeschl 7900: 	</form>
                   7901: NSPFORM
                   7902: 
                   7903: 	my $newsmpproblemform=(<<NSPROBFORM);
                   7904: 	<form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655     raeburn  7905: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  7906: 	$pathitem
1.329     droeschl 7907: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7908: 	<a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572     raeburn  7909: 	$help{'Simple_Problem'}
1.329     droeschl 7910: 	</form>
                   7911: 
                   7912: NSPROBFORM
                   7913: 
                   7914: 	my $newdropboxform=(<<NDBFORM);
                   7915: 	<form action="/adm/coursedocs" method="post" name="newdropbox">
1.655     raeburn  7916: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  7917: 	$pathitem
1.329     droeschl 7918: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7919: 	<a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554     raeburn  7920:         $help{'Dropbox'}
1.344     bisitz   7921: 	</form>
1.329     droeschl 7922: NDBFORM
                   7923: 
                   7924: 	my $newexuploadform=(<<NEXUFORM);
                   7925: 	<form action="/adm/coursedocs" method="post" name="newexamupload">
1.655     raeburn  7926: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  7927: 	$pathitem
1.329     droeschl 7928: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7929: 	<a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329     droeschl 7930: 	$help{'Score_Upload_Form'}
                   7931: 	</form>
                   7932: NEXUFORM
                   7933: 
                   7934: 	my $newbulform=(<<NBFORM);
                   7935: 	<form action="/adm/coursedocs" method="post" name="newbul">
1.655     raeburn  7936: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  7937: 	$pathitem
1.329     droeschl 7938: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7939: 	<a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329     droeschl 7940: 	$help{'Bulletin Board'}
                   7941: 	</form>
                   7942: NBFORM
                   7943: 
                   7944: 	my $newaboutmeform=(<<NAMFORM);
                   7945: 	<form action="/adm/coursedocs" method="post" name="newaboutme">
1.655     raeburn  7946: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  7947: 	$pathitem
1.329     droeschl 7948: 	<input type="hidden" name="importdetail" 
                   7949: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  7950: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347     weissno  7951: 	$help{'My Personal Information Page'}
1.329     droeschl 7952: 	</form>
                   7953: NAMFORM
                   7954: 
                   7955: 	my $newaboutsomeoneform=(<<NASOFORM);
                   7956: 	<form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655     raeburn  7957: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  7958: 	$pathitem
1.329     droeschl 7959: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7960: 	<a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329     droeschl 7961: 	</form>
                   7962: NASOFORM
                   7963: 
                   7964: 	my $newrosterform=(<<NROSTFORM);
                   7965: 	<form action="/adm/coursedocs" method="post" name="newroster">
1.655     raeburn  7966: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  7967: 	$pathitem
1.329     droeschl 7968: 	<input type="hidden" name="importdetail" 
                   7969: 	value="$lt{'rost'}=/adm/viewclasslist" />
1.611     raeburn  7970: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556     raeburn  7971: 	$help{'Course_Roster'}
1.329     droeschl 7972: 	</form>
                   7973: NROSTFORM
                   7974: 
1.534     raeburn  7975:         my $newwebpage;
                   7976:         if ($folder =~ /^default_?(\d*)$/) {
                   7977:             $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
                   7978:             if ($1) {
                   7979:                 $newwebpage .= $1;
                   7980:             } else {
                   7981:                 $newwebpage .= 'default';
                   7982:             }
                   7983:             $newwebpage .= '/new.html';
                   7984:         }
                   7985:         my $newwebpageform =(<<NWEBFORM);
                   7986:         <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655     raeburn  7987:         <input type="hidden" name="active" value="ff" />
1.534     raeburn  7988:         $pathitem
                   7989:         <input type="hidden" name="importdetail" value="$newwebpage" />
                   7990:         <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556     raeburn  7991:         $help{'Web_Page'}
1.534     raeburn  7992:         </form>
                   7993: NWEBFORM
1.701     raeburn  7994:         my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606     raeburn  7995:         my @ids=&Apache::lonnet::current_machine_ids();
1.691     raeburn  7996:         my $machines_str = "'".join("','",@ids)."'";
                   7997:         my (%is_home,%toppath,$rolehomes);
1.606     raeburn  7998:         if ($env{'user.author'}) {
                   7999:             if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691     raeburn  8000:                 $is_home{'author'} = 1;
1.606     raeburn  8001:             }
1.691     raeburn  8002:             $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606     raeburn  8003:         }
                   8004:         my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
                   8005:                                                       ['active'],['ca','aa']);
1.691     raeburn  8006:         my %by_roletype;
1.606     raeburn  8007:         if (keys(%roleshash)) {
                   8008:             foreach my $entry (keys(%roleshash)) {
                   8009:                 my ($auname,$audom,$roletype) = split(/:/,$entry);
                   8010:                 my $key = $entry;
                   8011:                 $key =~ s/:/___/g;
1.691     raeburn  8012:                 my $author = $auname.'___'.$audom;
                   8013:                 $by_roletype{$roletype}{$author} = 1;
1.606     raeburn  8014:                 my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691     raeburn  8015:                 $toppath{$author} = "/priv/$audom/$auname";
                   8016:                 if (grep(/^\Q$rolehome\E$/,@ids)) {
                   8017:                     $is_home{$author} = 1;
1.606     raeburn  8018:                 }
1.691     raeburn  8019:                 $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
                   8020:                               'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606     raeburn  8021:             }
1.691     raeburn  8022:         }
                   8023:         my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   8024:         if (grep(/^\Q$crshome\E$/,@ids)) {
                   8025:             $is_home{'course'} = 1;
                   8026:         }
                   8027:         $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
1.723     raeburn  8028:         my $pickdir = '<label>'.$lt{'loca'}.
1.691     raeburn  8029:                    '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
                   8030:                    '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
                   8031:         if ($env{'user.author'}) {
                   8032:             $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
                   8033:         }
                   8034:         if (keys(%by_roletype)) {
                   8035:             foreach my $possrole ('ca','aa') {
                   8036:                 if (ref($by_roletype{$possrole}) eq 'HASH') {
                   8037:                     my $roletitle = &Apache::lonnet::plaintext($possrole);
                   8038:                     foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
                   8039:                         my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
                   8040:                         $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
                   8041:                                      $roletitle." ($audom/$auname)</option>\n";
1.606     raeburn  8042:                     }
                   8043:                 }
                   8044:             }
                   8045:         }
1.706     raeburn  8046:         if ($checkcrsres) {
                   8047:             $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
                   8048:         }
1.723     raeburn  8049:         $pickdir .= '</select></label><br />'."\n".
                   8050:                     '<label>'.$lt{'dire'}.
1.691     raeburn  8051:                     '<select name="authorpath" onchange="toggleCrsResTitle();">'.
                   8052:                     '<option value=""></option>'.
1.723     raeburn  8053:                     '</select></label><br />'."\n";
1.606     raeburn  8054:         my %seltemplate_menus;
                   8055:         my @files = &Apache::lonhomework::get_template_list('problem');
                   8056:         my @noexamplelink = ('blank.problem','blank.library','script.library');
                   8057:         my $currentcategory = '';
                   8058:         my @ordered = ('');
                   8059:         my %templatehelp;
                   8060:         my $defcategory = '';
                   8061:         my @catorder = ($defcategory);
                   8062:         $seltemplate_menus{$defcategory}->{'order'} = [''];
                   8063:         $seltemplate_menus{$defcategory}->{'text'} = '';
                   8064:         foreach my $file (@files) {
                   8065:             if (ref($file) eq 'ARRAY') {
                   8066:                 my ($path,$title,$category,$help) = @{$file};
                   8067:                 next if ($title !~ /\S/);
                   8068:                 if (&js_escape($category) ne $currentcategory) {
                   8069:                     $currentcategory = &js_escape($category);
                   8070:                     push(@catorder,&js_escape($currentcategory));
                   8071:                     $seltemplate_menus{$currentcategory}->{'text'} = $category;
                   8072:                     $seltemplate_menus{$currentcategory}->{'default'} = '';
                   8073:                     $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
                   8074:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
                   8075:                 }
                   8076:                 if ($path) {
                   8077:                     $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
                   8078:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
                   8079:                     if ($help) {
                   8080:                         $templatehelp{$path} = $help;
                   8081:                     }
                   8082:                 }
                   8083:             }
                   8084:         }
                   8085: 
1.723     raeburn  8086:         my ($templates,$haslabel);
                   8087:         if ($lt{'cate'} ne '') {
                   8088:             $templates = '<label>';
                   8089:             $haslabel = 1;
                   8090:         }
                   8091:         $templates .= $lt{'cate'}.' '.
                   8092:                       &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
                   8093:                                                               $defcategory,'tempcategory','template',
                   8094:                                                               \%seltemplate_menus,\@catorder,
                   8095:                                                               "resize_scrollbox('contentscroll','1','0');",
                   8096:                                                               "toggleExampleText();",'template',$haslabel).'<br />';
1.606     raeburn  8097:         my $templatepreview =  '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true);  return false;">'.
1.701     raeburn  8098:                                '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706     raeburn  8099:         my $crsresform;
                   8100:         if (($env{'user.author'}) || ($checkcrsres)) {
                   8101:             $crsresform=(<<RESFORM);
1.691     raeburn  8102:         <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706     raeburn  8103:         $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606     raeburn  8104:         <form action="/adm/coursedocs" method="post" name="courseresform">
                   8105:         <fieldset id="crsresform" style="display:none;">
                   8106:         <legend>$lt{'stpr'}</legend>
1.655     raeburn  8107:         <input type="hidden" name="active" value="bb" />
1.606     raeburn  8108:         <p>
                   8109:         $pickdir
1.701     raeburn  8110:         </p>
1.691     raeburn  8111:         <div id="newstdproblem" style="display:none;">
1.701     raeburn  8112:         <p>
1.606     raeburn  8113:         <span class="LC_nobreak">$lt{'news'}?&nbsp;
1.611     raeburn  8114:         <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606     raeburn  8115:         &nbsp;
1.611     raeburn  8116:         <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.723     raeburn  8117:         </span><label for="newsubdirname"><span id="newsubdir"></span></label>
1.606     raeburn  8118:         <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701     raeburn  8119:         </p>
1.699     raeburn  8120:         </div>
1.723     raeburn  8121:         <label>$lt{'fnam'}
                   8122:         <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled /></label>
1.701     raeburn  8123:         <div id="newresource" style="display:none">
1.606     raeburn  8124:         <p>
                   8125:         $lt{'addp'}
1.611     raeburn  8126:         <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  8127:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  8128:         <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  8129:         $lt{'yes'}</label>
1.723     raeburn  8130:         <label for="newresourcetitle"><span id="newrestitle"></span></label>
1.611     raeburn  8131:         <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701     raeburn  8132:         </p>
1.606     raeburn  8133:         </div>
                   8134:         <p>
                   8135:         $lt{'uste'}
1.611     raeburn  8136:         <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  8137:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  8138:         <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  8139:         $lt{'yes'}</label>
1.701     raeburn  8140:         </p>
1.606     raeburn  8141:         <div id="newrestemplate" style="display:none">
                   8142:         $templates
                   8143:         $templatepreview
                   8144:         </div>
                   8145:         <span class="LC_nobreak">
1.701     raeburn  8146:         <input type="hidden" name="folderpath" value="$showpath" />
1.611     raeburn  8147:         <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606     raeburn  8148:         </span>
1.691     raeburn  8149:         <div id="stdprobswitch" style="display:none;">
1.689     raeburn  8150:         $rolehomes
                   8151:         <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
                   8152:         </div>
1.606     raeburn  8153:         </fieldset>
                   8154:         </form>
                   8155: 
                   8156: RESFORM
1.706     raeburn  8157:         }
1.534     raeburn  8158: 
1.342     ehlerst  8159: my $specialdocumentsform;
1.383     tempelho 8160: my @specialdocumentsforma;
1.451     www      8161: my $gradingform;
                   8162: my @gradingforma;
                   8163: my $communityform;
                   8164: my @communityforma;
1.351     ehlerst  8165: my $newfolderform;
1.390     tempelho 8166: my $newfolderb;
1.342     ehlerst  8167: 
1.451     www      8168: 	my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383     tempelho 8169: 	
1.329     droeschl 8170: 	my $newpageform=(<<NPFORM);
                   8171: 	<form action="/adm/coursedocs" method="post" name="newpage">
                   8172: 	<input type="hidden" name="folderpath" value="$path" />
                   8173: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  8174: 	<input type="hidden" name="active" value="ee" />
1.423     onken    8175: 	<a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383     tempelho 8176: 	$help{'Adding_Pages'}
1.329     droeschl 8177: 	</form>
                   8178: NPFORM
1.390     tempelho 8179: 
                   8180: 
1.351     ehlerst  8181: 	$newfolderform=(<<NFFORM);
1.329     droeschl 8182: 	<form action="/adm/coursedocs" method="post" name="newfolder">
1.508     raeburn  8183: 	$pathitem
1.329     droeschl 8184: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  8185: 	<input type="hidden" name="active" value="" />
1.422     onken    8186: 	<a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329     droeschl 8187: 	</form>
                   8188: NFFORM
                   8189: 
                   8190: 	my $newsylform=(<<NSYLFORM);
                   8191: 	<form action="/adm/coursedocs" method="post" name="newsyl">
1.570     raeburn  8192: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  8193: 	$pathitem
1.329     droeschl 8194: 	<input type="hidden" name="importdetail" 
                   8195: 	value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  8196: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329     droeschl 8197: 	$help{'Syllabus'}
1.383     tempelho 8198: 
1.329     droeschl 8199: 	</form>
                   8200: NSYLFORM
1.364     bisitz   8201: 
1.329     droeschl 8202: 	my $newgroupfileform=(<<NGFFORM);
                   8203: 	<form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655     raeburn  8204: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  8205: 	$pathitem
1.329     droeschl 8206: 	<input type="hidden" name="importdetail"
                   8207: 	value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611     raeburn  8208: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353     weissno  8209: 	$help{'Group Portfolio'}
1.329     droeschl 8210: 	</form>
                   8211: NGFFORM
1.672     raeburn  8212:         if ($container eq 'page') {
                   8213:             @specialdocumentsforma=(
                   8214:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
                   8215:             );
                   8216:         } else {
                   8217: 	    @specialdocumentsforma=(
1.421     onken    8218: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'"  onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.618     raeburn  8219: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611     raeburn  8220: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451     www      8221:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534     raeburn  8222:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672     raeburn  8223:             );
                   8224:         }
1.451     www      8225:         $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
                   8226: 
1.655     raeburn  8227:         my @external = (
                   8228:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519     raeburn  8229:         );
1.699     raeburn  8230:         if ($posslti) {
1.655     raeburn  8231:             push(@external,
                   8232:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
                   8233:             );
1.598     raeburn  8234:         }
1.655     raeburn  8235:         my $externalform = &create_form_ul(&create_list_elements(@external));
                   8236: 
                   8237:         my @importdoc = ();
1.519     raeburn  8238:         unless ($container eq 'page') {
                   8239:             push(@importdoc,
                   8240:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
                   8241:             );
                   8242:         }
                   8243:         push(@importdoc,
1.558     raeburn  8244:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519     raeburn  8245:         );
1.501     raeburn  8246:         $fileuploadform =  &create_form_ul(&create_list_elements(@importdoc));
1.434     raeburn  8247: 
1.451     www      8248:         @gradingforma=(
                   8249:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
                   8250:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706     raeburn  8251:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451     www      8252:         );
1.706     raeburn  8253:         if ($crsresform) {
                   8254:             push(@gradingforma,
                   8255:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
                   8256:             );
                   8257:         }
1.451     www      8258:         $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
                   8259: 
                   8260:         @communityforma=(
                   8261:        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
                   8262:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
                   8263:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611     raeburn  8264:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
                   8265:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451     www      8266:         );
                   8267:         $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383     tempelho 8268: 
1.330     tempelho 8269: my %orderhash = (
1.553     raeburn  8270:                 'aa' => ['Upload',$fileuploadform],
1.707     raeburn  8271:                 'bb' => ['External',$externalform],
                   8272:                 'cc' => ['Import',$importpubform],
1.701     raeburn  8273:                 'dd' => ['Assessment',$gradingform],
1.673     raeburn  8274:                 'ff' => ['Other',$specialdocumentsform],
1.330     tempelho 8275:                 );
1.519     raeburn  8276: unless ($container eq 'page') {
1.434     raeburn  8277:     $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655     raeburn  8278:     $orderhash{'ee'} = ['Collaboration',$communityform];
1.434     raeburn  8279: }
                   8280: 
1.341     ehlerst  8281:  $hadchanges=0;
1.484     raeburn  8282:        unless (($supplementalflag || $toolsflag)) {
1.458     raeburn  8283:           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615     raeburn  8284:                               $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622     raeburn  8285:                               \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617     raeburn  8286:           undef($navmap);
1.443     www      8287:           if ($error) {
                   8288:              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   8289:           }
1.639     raeburn  8290:           if ($hadchanges) {
                   8291:               unless (&is_hash_old()) {
1.638     raeburn  8292:                   &mark_hash_old();
                   8293:               }
                   8294: 	  }
1.341     ehlerst  8295: 
1.443     www      8296:           &changewarning($r,'');
                   8297:         }
1.458     raeburn  8298:     }
1.442     www      8299: 
1.443     www      8300: # Supplemental documents start here
                   8301: 
1.329     droeschl 8302:        my $folder=$env{'form.folder'};
1.443     www      8303:        unless ($supplementalflag) {
1.329     droeschl 8304: 	   $folder='supplemental';
                   8305:        }
1.685     raeburn  8306:        if (($folder eq 'supplemental') &&
1.329     droeschl 8307: 	   (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446     www      8308:           $env{'form.folderpath'} = &supplemental_base();
1.393     raeburn  8309:        } elsif ($allowed) {
1.356     tempelho 8310: 	  $env{'form.folderpath'} = $savefolderpath;
1.329     droeschl 8311:        }
1.508     raeburn  8312:        $pathitem = '<input type="hidden" name="folderpath" value="'.
                   8313:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329     droeschl 8314:        if ($allowed) {
                   8315: 	   my $folderseq=
1.504     raeburn  8316: 	       '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329     droeschl 8317: 
                   8318: 	my $supupdocform=(<<SUPDOCFORM);
1.501     raeburn  8319:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
                   8320:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383     tempelho 8321: 	<form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516     raeburn  8322:         <fieldset id="uploadsuppdocform" style="display: none;">
1.501     raeburn  8323:         <legend>$lt{'upfi'}</legend>
1.630     raeburn  8324: 	<input type="hidden" name="active" value="ee" />
1.723     raeburn  8325: 	$quotainfo
                   8326:         <label>$lt{'file'}:<br />
                   8327:         <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled /></label>
1.702     raeburn  8328:         <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329     droeschl 8329: 	<br />
                   8330: 	<br />
                   8331: 	<span class="LC_nobreak">
                   8332: 	$checkbox
                   8333: 	</span>
                   8334: 	<br /><br />
1.723     raeburn  8335: 	<label>$lt{'comment'}:<br />
                   8336: 	<textarea cols="50" rows="4" name="comment"></textarea></label>
1.329     droeschl 8337: 	<br />
1.508     raeburn  8338: 	$pathitem
1.329     droeschl 8339: 	<input type="hidden" name="cmd" value="upload_supplemental" />
1.501     raeburn  8340:         <input type='submit' value="$lt{'upld'}" />
1.700     raeburn  8341:         </fieldset>
1.501     raeburn  8342:         </form>
1.329     droeschl 8343: SUPDOCFORM
                   8344: 
                   8345: 	my $supnewfolderform=(<<SNFFORM);
                   8346: 	<form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570     raeburn  8347: 	<input type="hidden" name="active" value="" />
1.508     raeburn  8348:         $pathitem
1.329     droeschl 8349: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    8350: 	<a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a> 
1.383     tempelho 8351: 	$help{'Adding_Folders'}
1.329     droeschl 8352: 	</form>
                   8353: SNFFORM
1.383     tempelho 8354: 	
1.510     raeburn  8355:         my $supextform =
                   8356:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611     raeburn  8357:                                                  $help{'Adding_External_Resource'},
                   8358:                                                  undef,undef,undef,undef,undef,undef,
                   8359:                                                  $disabled);
1.329     droeschl 8360: 
1.598     raeburn  8361:         my $supexttoolform =
                   8362:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
                   8363:                                                  $help{'Adding_External_Tool'},
                   8364:                                                  undef,undef,'tool',$coursedom,
1.611     raeburn  8365:                                                  $coursenum,\%ltitools,$disabled);
1.598     raeburn  8366: 
1.329     droeschl 8367: 	my $supnewsylform=(<<SNSFORM);
                   8368: 	<form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371     tempelho 8369: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  8370:         $pathitem
1.329     droeschl 8371: 	<input type="hidden" name="importdetail" 
                   8372: 	value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  8373: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329     droeschl 8374: 	$help{'Syllabus'}
                   8375: 	</form>
                   8376: SNSFORM
                   8377: 
                   8378: 	my $supnewaboutmeform=(<<SNAMFORM);
1.383     tempelho 8379: 	<form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371     tempelho 8380: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  8381:         $pathitem
1.329     droeschl 8382: 	<input type="hidden" name="importdetail" 
                   8383: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  8384: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347     weissno  8385: 	$help{'My Personal Information Page'}
1.329     droeschl 8386: 	</form>
                   8387: SNAMFORM
                   8388: 
1.534     raeburn  8389:         my $supwebpage;
                   8390:         if ($folder =~ /^supplemental_?(\d*)$/) {
                   8391:             $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
                   8392:             if ($1) {
                   8393:                 $supwebpage .= $1;
                   8394:             } else {
                   8395:                 $supwebpage .= 'default';
                   8396:             }
                   8397:             $supwebpage .= '/new.html';
                   8398:         }
                   8399:         my $supwebpageform =(<<SWEBFORM);
                   8400:         <form action="/adm/coursedocs" method="post" name="supwebpage">
                   8401:         <input type="hidden" name="active" value="cc" />
                   8402:         $pathitem
                   8403:         <input type="hidden" name="importdetail" value="$supwebpage" />
                   8404:         <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556     raeburn  8405:         $help{'Web_Page'}
1.534     raeburn  8406:         </form>
                   8407: SWEBFORM
                   8408: 
1.333     muellerd 8409: 
1.383     tempelho 8410: my @specialdocs = (
1.618     raeburn  8411: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417     droeschl 8412:             =>$supnewsylform},
1.611     raeburn  8413: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417     droeschl 8414:             =>$supnewaboutmeform},
1.534     raeburn  8415:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
                   8416: 
1.383     tempelho 8417: 		);
1.655     raeburn  8418:         my @supexternal = (
                   8419:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
                   8420:              =>$supextform});
1.699     raeburn  8421:         if ($posslti) {
1.655     raeburn  8422:             push(@supexternal,
                   8423:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598     raeburn  8424:             =>$supexttoolform});
                   8425:         }
1.655     raeburn  8426:         my @supimportdoc = (
1.598     raeburn  8427:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501     raeburn  8428:             =>$supupdocform},
1.598     raeburn  8429:         );
1.501     raeburn  8430: 
                   8431: $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc));
1.333     muellerd 8432: my %suporderhash = (
1.390     tempelho 8433: 		'00' => ['Supnewfolder', $supnewfolderform],
1.655     raeburn  8434:                 'dd' => ['Upload',$supupdocform],
                   8435:                 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553     raeburn  8436:                 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333     muellerd 8437:                 );
1.443     www      8438:         if ($supplementalflag) {
1.682     raeburn  8439:             $suppchanges = 0;
                   8440:             my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
                   8441:                                 $supplementalflag,\%suporderhash,$iconpath,$pathitem,
                   8442:                                 \%ltitools,$canedit,$hostname);
                   8443:             if ($error) {
                   8444:                 $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   8445:             }
                   8446:             if ($suppchanges) {
1.684     raeburn  8447:                 &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682     raeburn  8448:                 undef($suppchanges);
                   8449:             }
1.393     raeburn  8450:         }
1.443     www      8451:     } elsif ($supplementalflag) {
1.458     raeburn  8452:         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682     raeburn  8453:                             $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
                   8454:                             $hostname);
1.393     raeburn  8455:         if ($error) {
                   8456:             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383     tempelho 8457:         }
1.393     raeburn  8458:     }
1.389     tempelho 8459: 
1.510     raeburn  8460:     if ($needs_end) {
                   8461:         $r->print(&endContentScreen());
                   8462:     }
1.383     tempelho 8463: 
1.329     droeschl 8464:     if ($allowed) {
                   8465: 	$r->print('
                   8466: <form method="post" name="extimport" action="/adm/coursedocs">
                   8467:   <input type="hidden" name="title" />
                   8468:   <input type="hidden" name="url" />
                   8469:   <input type="hidden" name="useform" />
                   8470:   <input type="hidden" name="residx" />
                   8471: </form>');
                   8472:     }
1.484     raeburn  8473:   } elsif ($showdoc) {
1.329     droeschl 8474: # -------------------------------------------------------- This is showdoc mode
1.484     raeburn  8475:       $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498     bisitz   8476: 		&Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329     droeschl 8477: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484     raeburn  8478:                 &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329     droeschl 8479:   }
                   8480:  }
1.630     raeburn  8481:  unless ($noendpage) {
1.606     raeburn  8482:      $r->print(&Apache::loncommon::end_page());
                   8483:  }
1.329     droeschl 8484:  return OK;
1.364     bisitz   8485: }
1.329     droeschl 8486: 
1.440     raeburn  8487: sub embedded_form_elems {
                   8488:     my ($phase,$primaryurl,$newidx) = @_;
                   8489:     my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634     raeburn  8490:     $newidx =~s /\D+//g;
1.440     raeburn  8491:     return <<STATE;
                   8492:     <input type="hidden" name="folderpath" value="$folderpath" />
                   8493:     <input type="hidden" name="cmd" value="upload_embedded" />
                   8494:     <input type="hidden" name="newidx" value="$newidx" />
                   8495:     <input type="hidden" name="phase" value="$phase" />
                   8496:     <input type="hidden" name="primaryurl" value="$primaryurl" />
                   8497: STATE
                   8498: }
                   8499: 
                   8500: sub embedded_destination {
                   8501:     my $folder=$env{'form.folder'};
                   8502:     my $destination = 'docs/';
                   8503:     if ($folder =~ /^supplemental/) {
                   8504:         $destination = 'supplemental/';
                   8505:     }
                   8506:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   8507:         $destination .= 'default/';
                   8508:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   8509:         $destination .=  $2.'/';
                   8510:     }
1.634     raeburn  8511:     my $newidx = $env{'form.newidx'};
                   8512:     $newidx =~s /\D+//g;
                   8513:     if ($newidx) {
                   8514:         $destination .= $newidx;
                   8515:     }
1.440     raeburn  8516:     my $dir_root = '/userfiles';
                   8517:     return ($destination,$dir_root);
                   8518: }
                   8519: 
                   8520: sub return_to_editor {
                   8521:     my $actionurl = '/adm/coursedocs';
                   8522:     return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n". 
                   8523:            '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
                   8524:            '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
                   8525:            '</a></p>';
                   8526: }
                   8527: 
1.476     raeburn  8528: sub decompression_info {
                   8529:     my ($destination,$dir_root) = &embedded_destination();
                   8530:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                   8531:     my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   8532:     my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   8533:     my $container='sequence';
1.480     raeburn  8534:     my ($pathitem,$hiddenelem);
1.583     raeburn  8535:     my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519     raeburn  8536:     if ($env{'form.folderpath'} =~ /\:1$/) {
1.476     raeburn  8537:         $container='page';
                   8538:     }
1.480     raeburn  8539:     unshift(@hiddens,$pathitem);
                   8540:     foreach my $item (@hiddens) {
1.634     raeburn  8541:         if ($item eq 'newidx') {
                   8542:             next if ($env{'form.'.$item} =~ /\D/);
                   8543:         }
1.480     raeburn  8544:         if ($env{'form.'.$item}) {
                   8545:             $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583     raeburn  8546:                            &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480     raeburn  8547:         }
1.477     raeburn  8548:     }
1.476     raeburn  8549:     return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
                   8550:             $hiddenelem);
                   8551: }
                   8552: 
                   8553: sub decompression_phase_one {
                   8554:     my ($dir,$file,$warning,$error,$output);
                   8555:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   8556:         &decompression_info();
1.490     raeburn  8557:     if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476     raeburn  8558:         $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
                   8559:     } else {
                   8560:         my $file = $1;
1.630     raeburn  8561:         $output =
1.481     raeburn  8562:             &Apache::loncommon::process_decompression($docudom,$docuname,$file,
                   8563:                                                       $destination,$dir_root,
                   8564:                                                       $hiddenelem);
                   8565:         if ($env{'form.autoextract_camtasia'}) {
                   8566:             $output .= &remove_archive($docudom,$docuname,$container);
                   8567:         }
1.476     raeburn  8568:     }
                   8569:     if ($error) {
                   8570:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   8571:                    $error.'</p>'."\n";
                   8572:     }
                   8573:     if ($warning) {
                   8574:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   8575:     }
                   8576:     return $output;
                   8577: }
                   8578: 
                   8579: sub decompression_phase_two {
                   8580:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   8581:         &decompression_info();
1.481     raeburn  8582:     my $output;
1.480     raeburn  8583:     if ($env{'form.archivedelete'}) {
1.481     raeburn  8584:         $output = &remove_archive($docudom,$docuname,$container);
1.480     raeburn  8585:     }
                   8586:     $output .= 
1.481     raeburn  8587:         &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476     raeburn  8588:                                                     $destination,$dir_root,$hiddenelem);
                   8589:     return $output;
                   8590: }
                   8591: 
1.480     raeburn  8592: sub remove_archive {
                   8593:     my ($docudom,$docuname,$container) = @_;
                   8594:     my $map = $env{'form.folder'}.'.'.$container;
1.481     raeburn  8595:     my ($output,$delwarning,$delresult,$url);
1.480     raeburn  8596:     my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
                   8597:     if ($fatal) {
                   8598:         if ($container eq 'page') {
                   8599:             $delwarning = &mt('An error occurred retrieving the contents of the current page.');
                   8600:         } else {
                   8601:             $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
                   8602:         }
1.583     raeburn  8603:         $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  8604:     } else {
                   8605:         my $currcmd = $env{'form.cmd'};
                   8606:         my $position = $env{'form.position'};
1.583     raeburn  8607:         my $archiveidx = $position;
1.563     raeburn  8608:         if ($position > 0) {
1.583     raeburn  8609:             if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
                   8610:                 $archiveidx = $position-1;
                   8611:             }
                   8612:             $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584     raeburn  8613:             my ($title,$url,@rrest) =
1.583     raeburn  8614:                 split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
                   8615:             if ($url eq $env{'form.archiveurl'}) {
                   8616:                 if (&handle_edit_cmd($docuname,$docudom)) {
                   8617:                     ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684     raeburn  8618:                     if ($suppchanges) {
                   8619:                         &Apache::lonnet::update_supp_caches($docudom,$docuname);
                   8620:                         undef($suppchanges);
                   8621:                     }
1.583     raeburn  8622:                     if ($fatal) {
                   8623:                         if ($container eq 'page') {
                   8624:                             $delwarning = &mt('An error occurred updating the contents of the current page.');
                   8625:                         } else {
                   8626:                             $delwarning = &mt('An error occurred updating the contents of the current folder.');
                   8627:                         }
1.480     raeburn  8628:                     } else {
1.583     raeburn  8629:                         $delresult = &mt('Archive file removed.');
1.480     raeburn  8630:                     }
                   8631:                 }
1.583     raeburn  8632:             } else {
                   8633:                 $delwarning .=  &mt('Archive file had unexpected item number in folder.').
                   8634:                                 ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  8635:             }
                   8636:         }
                   8637:         $env{'form.cmd'} = $currcmd;
                   8638:     }
                   8639:     if ($delwarning) {
                   8640:         $output = '<p class="LC_warning">'.
                   8641:                    $delwarning.
                   8642:                    '</p>';
                   8643:     }
                   8644:     if ($delresult) {
                   8645:         $output .= '<p class="LC_info">'.
                   8646:                    $delresult.
                   8647:                    '</p>';
                   8648:     }
1.481     raeburn  8649:     return $output;
1.480     raeburn  8650: }
                   8651: 
1.484     raeburn  8652: sub generate_admin_menu {
1.708     raeburn  8653:     my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484     raeburn  8654:     my $lc_crstype = lc($crstype);
                   8655:     my ($home,$other,%outhash)=&authorhosts();
1.562     bisitz   8656:     my %lt= ( # do not translate here
1.484     raeburn  8657:                                          'vc'   => 'Verify Content',
                   8658:                                          'cv'   => 'Check/Set Resource Versions',
                   8659:                                          'ls'   => 'List Resource Identifiers',
1.651     raeburn  8660:                                          'ct'   => 'Display/Set Shortened URLs for Deep-linking',
1.708     raeburn  8661:                                          'ca'   => "Enter $crstype Authoring Space",
1.484     raeburn  8662:                                          'imse' => 'Export contents to IMS Archive',
1.712     raeburn  8663:                                          'dcd'  => 'Copy uploaded content to Authoring Space',
                   8664:                                          'cpc'  => 'Copy from Course Authoring to User Authoring',
1.562     bisitz   8665:             );
1.712     raeburn  8666:     my ($candump,$dumpurl,$exportcrsurl);
1.484     raeburn  8667:     if ($home + $other > 0) {
                   8668:         $candump = 'F';
                   8669:         if ($home) {
                   8670:             $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
1.712     raeburn  8671:             $exportcrsurl = "javascript:injectData(document.courseverify,'dummy','copyauthored','$lt{'cpc'}')";
1.484     raeburn  8672:         } else {
                   8673:             my @hosts;
                   8674:             foreach my $aurole (keys(%outhash)) {
                   8675:                 unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   8676:                     push(@hosts,$outhash{$aurole});
1.538     raeburn  8677:                 }
1.484     raeburn  8678:             }
                   8679:             if (@hosts == 1) {
                   8680:                 my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
                   8681:                                '&amp;role='.
                   8682:                                &HTML::Entities::encode($env{'request.role'},'"<>&').'&amp;origurl='.
                   8683:                                &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
                   8684:                 $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
1.712     raeburn  8685:                 $exportcrsurl = $dumpurl;
1.484     raeburn  8686:             } else {
                   8687:                 $dumpurl = "javascript:choose_switchserver_window()";
1.712     raeburn  8688:                 $exportcrsurl = $dumpurl;
1.484     raeburn  8689:             }
                   8690:         }
                   8691:     }
                   8692:     my @menu=
                   8693:         ({  categorytitle=>'Administration',
                   8694:             items =>[
                   8695:                 {   linktext   => $lt{'vc'},
                   8696:                     url        => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
                   8697:                     permission => 'F',
1.571     raeburn  8698:                     help       => 'Docs_Verify_Content',
1.484     raeburn  8699:                     icon       => 'verify.png',
                   8700:                     linktitle  => 'Verify contents can be retrieved/rendered',
                   8701:                 },
                   8702:                 {   linktext => $lt{'cv'},
                   8703:                     url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
                   8704:                     permission => 'F',
1.571     raeburn  8705:                     help       => 'Docs_Check_Resource_Versions',
1.484     raeburn  8706:                     icon       => 'resversion.png',
                   8707:                     linktitle  => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
                   8708:                 },
                   8709:                 {   linktext   => $lt{'ls'},
                   8710:                     url        => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
                   8711:                     permission => 'F',
                   8712:                     #help => '',
                   8713:                     icon       => 'symbs.png',
                   8714:                     linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"
                   8715:                 },
1.651     raeburn  8716:                 {   linktext   => $lt{'ct'},
                   8717:                     url        => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
                   8718:                     permission => 'F',
                   8719:                     help       => 'Docs_Short_URLs',
                   8720:                     icon       => 'shorturls.png',
                   8721:                     linktitle  => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
                   8722:                 },
1.484     raeburn  8723:                 ]
1.611     raeburn  8724:         });
                   8725:     if ($canedit) {
1.708     raeburn  8726:         my ($crsauname,$crsaudom,$crshome);
                   8727:         if (($coursenum ne '') && ($coursedom ne '')) {
                   8728:             my $crsauthorurl = "/priv/$coursedom/$coursenum/";
                   8729:             ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
                   8730:             if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
                   8731:                 my @ids=&Apache::lonnet::current_machine_ids();
                   8732:                 my $linkurl;
                   8733:                 if (grep(/^\Q$crshome\E$/,@ids)) {
                   8734:                     $linkurl = $crsauthorurl;
                   8735:                 } else {
1.720     raeburn  8736:                     my $jscall = &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
                   8737:                     if ($jscall) {
                   8738:                         $linkurl = 'javascript:'.$jscall;
                   8739:                     }
1.708     raeburn  8740:                 }
1.720     raeburn  8741:                 if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY') && ($linkurl)) {
1.708     raeburn  8742:                      push(@{$menu[0]->{items}},
                   8743:                      {   linktext   => $lt{'ca'},
                   8744:                          url        => $linkurl,
                   8745:                          permission => 'F',
                   8746:                          help       => 'Docs_Course_Authorspace',
                   8747:                          icon       => 'impcrsau.png',
                   8748:                          linktitle  => $lt{'ca'},
                   8749:                      });
                   8750:                 }
                   8751:             }
                   8752:         }
1.611     raeburn  8753:         push(@menu,
1.484     raeburn  8754:         {   categorytitle=>'Export',
                   8755:             items =>[
                   8756:                 {   linktext   => $lt{'imse'},
                   8757:                     url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
                   8758:                     permission => 'F',
                   8759:                     help       => 'Docs_Export_Course_Docs',
                   8760:                     icon       => 'imsexport.png',
                   8761:                     linktitle  => $lt{'imse'},
                   8762:                 },
                   8763:                 {   linktext   => $lt{'dcd'},
                   8764:                     url        => $dumpurl,
                   8765:                     permission => $candump,
1.571     raeburn  8766:                     help       => 'Docs_Dump_Course_Docs',
1.484     raeburn  8767:                     icon       => 'dump.png',
                   8768:                     linktitle  => $lt{'dcd'},
                   8769:                 },
                   8770:                 ]
                   8771:         });
1.712     raeburn  8772:         if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
                   8773:             if ((ref($menu[1]) eq 'HASH') && (ref($menu[1]->{'items'}) eq 'ARRAY')) {
                   8774:                 push(@{$menu[1]->{items}},
                   8775:                      {   linktext   => $lt{'cpc'},
                   8776:                          url        => $exportcrsurl,
                   8777:                          permission => 'F',
                   8778:                          help       => 'Docs_Export_Course_Author',
                   8779:                          icon       => 'res.png',
                   8780:                          linktitle  => $lt{'cpc'},
                   8781:                      });
                   8782:             }
                   8783:         }
1.611     raeburn  8784:     }
1.484     raeburn  8785:     return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
                   8786:            '<input type="hidden" id="dummy" />'."\n".
                   8787:            &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
                   8788:            '</form>';
1.329     droeschl 8789: }
                   8790: 
                   8791: sub generate_edit_table {
1.538     raeburn  8792:     my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611     raeburn  8793:         $need_save,$copyfolder,$canedit) = @_;
1.406     raeburn  8794:     return unless(ref($orderhash_ref) eq 'HASH');
1.342     ehlerst  8795:     my %orderhash = %{$orderhash_ref};
1.611     raeburn  8796:     my ($form, $activetab, $active, $disabled);
1.570     raeburn  8797:     if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371     tempelho 8798:         $activetab = $env{'form.active'};
                   8799:     }
1.611     raeburn  8800:     unless ($canedit) {
                   8801:         $disabled = ' disabled="disabled"';
                   8802:     }
1.472     raeburn  8803:     my $backicon = $iconpath.'clickhere.gif';
1.525     raeburn  8804:     my $backtext = &mt('Exit Editor');
1.458     raeburn  8805:     $form = '<div class="LC_Box" style="margin:0;">'.
1.488     raeburn  8806:             '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
                   8807:             '<li class="goback">'.
1.546     raeburn  8808:             '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488     raeburn  8809:             '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
                   8810:             '  alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
                   8811:             '<li>'.
                   8812:             '<a href="javascript:groupopen('."'$readfile'".',1);">'.
                   8813:             &mt('Undo Delete').'</a></li>'."\n";
                   8814:     if ($env{'form.docslog'}) {
                   8815:         $form .= '<li class="active">';
                   8816:     } else {
                   8817:         $form .= '<li>';
                   8818:     }
                   8819:     $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
                   8820:              &mt('History').'</a></li>'."\n";
                   8821:     if ($env{'form.docslog'}) {
                   8822:         $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
                   8823:                  &mt('Edit').'</a></li>'."\n";
1.484     raeburn  8824:     }
1.458     raeburn  8825:     foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390     tempelho 8826:         if($name ne '00'){
1.371     tempelho 8827:             if($activetab eq '' || $activetab ne $name){
                   8828:                $active = '';
                   8829:             }elsif($activetab eq $name){
                   8830:                $active = 'class="active"';
                   8831:             }
1.458     raeburn  8832:             $form .= '<li style="float:right" '.$active
1.484     raeburn  8833:                 .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
1.390     tempelho 8834:         } else {
1.570     raeburn  8835: 	    $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390     tempelho 8836: 
                   8837: 	}
1.329     droeschl 8838:     }
1.484     raeburn  8839:     $form .= '</ul>'."\n";
                   8840:     $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458     raeburn  8841: 
                   8842:     if ($to_show ne '') {
1.538     raeburn  8843:         my $saveform;
                   8844:         if ($need_save) {
                   8845:             my $button = &mt('Make changes');
                   8846:             my $path;
                   8847:             if ($env{'form.folderpath'}) {
                   8848:                 $path =
                   8849:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   8850:             }
                   8851:             $saveform = <<"END";
                   8852: <div id="multisave" style="display:none; clear:both;" >
                   8853: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
                   8854: <input type="hidden" name="folderpath" value="$path" />
                   8855: <input type="hidden" name="symb" value="$env{'form.symb'}" />
                   8856: <input type="hidden" name="allhiddenresource" value="" />
                   8857: <input type="hidden" name="allencrypturl" value="" />
                   8858: <input type="hidden" name="allrandompick" value="" />
                   8859: <input type="hidden" name="allrandomorder" value="" />
                   8860: <input type="hidden" name="changeparms" value="" />
                   8861: <input type="hidden" name="multiremove" value="" />
                   8862: <input type="hidden" name="multicut" value="" />
                   8863: <input type="hidden" name="multicopy" value="" />
                   8864: <input type="hidden" name="multichange" value="" />
                   8865: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611     raeburn  8866: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538     raeburn  8867: </form>
                   8868: </div>
                   8869: END
                   8870:         }
                   8871:         $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458     raeburn  8872:     }
1.363     ehlerst  8873:     foreach my $field (keys(%orderhash)){
1.390     tempelho 8874: 	if($field ne '00'){
1.422     onken    8875:             if($activetab eq '' || $activetab ne $field){
1.458     raeburn  8876:                 $active = 'style="display: none;float:left"';
1.422     onken    8877:             }elsif($activetab eq $field){
1.458     raeburn  8878:                 $active = 'style="display:block;float:left"';
1.422     onken    8879:             }
                   8880:             $form .= '<div id="'.$field.$tid.'"'
                   8881:                     .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484     raeburn  8882:                     .'</div>'."\n";
1.363     ehlerst  8883:         }
                   8884:     }
1.484     raeburn  8885:     unless ($env{'form.docslog'}) {
                   8886:         $form .= '</div></div>'."\n";
                   8887:     }
1.329     droeschl 8888:     return $form;
                   8889: }
                   8890: 
                   8891: sub editing_js {
1.622     raeburn  8892:     my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
                   8893:         $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594     damieng  8894:     my %js_lt = &Apache::lonlocal::texthash(
1.329     droeschl 8895:                                           p_mnf => 'Name of New Folder',
                   8896:                                           t_mnf => 'New Folder',
                   8897:                                           p_mnp => 'Name of New Page',
                   8898:                                           t_mnp => 'New Page',
1.451     www      8899:                                           p_mxu => 'Title for the External Score',
1.349     biermanm 8900:                                           p_msp => 'Name of Simple Course Page',
1.329     droeschl 8901:                                           p_msb => 'Title for the Problem',
                   8902:                                           p_mdb => 'Title for the Drop Box',
1.336     schafran 8903:                                           p_mbb => 'Title for the Discussion Board',
1.604     raeburn  8904:                                           p_mwp => 'Title for Web Page',
1.606     raeburn  8905:                                           p_mnr => 'Title for the Resource',
1.348     weissno  8906:                                           p_mab => "Enter user:domain for User's Personal Information Page",
1.352     bisitz   8907:                                           p_mab2 => 'Personal Information Page of ',
1.329     droeschl 8908:                                           p_mab_alrt1 => 'Not a valid user:domain',
                   8909:                                           p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
                   8910:                                           p_chn => 'New Title',
                   8911:                                           p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603     raeburn  8912:                                           p_rmr2a => 'Remove',
                   8913:                                           p_rmr2b => '?',
                   8914:                                           p_rmr3a => 'Remove those',
                   8915:                                           p_rmr3b => 'items?',
                   8916:                                           p_rmr4  => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
                   8917:                                           p_rmr5  => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329     droeschl 8918:                                           p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
                   8919:                                           p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603     raeburn  8920:                                           p_ctr2a => 'Cut',
                   8921:                                           p_ctr2b => '?',
                   8922:                                           p_ctr3a => 'Cut those',
                   8923:                                           p_ctr3b => 'items?',
1.633     raeburn  8924:                                           setal   => 'Enter a (unique) alias',
                   8925:                                           delal   => 'Are you sure you want to eliminate the alias?',
1.478     raeburn  8926:                                           rpck    => 'Enter number to pick (e.g., 3)',
1.501     raeburn  8927:                                           imsfile => 'You must choose an IMS package for import',
                   8928:                                           imscms  => 'You must select which Course Management System was the source of the IMS package',
                   8929:                                           invurl  => 'Invalid URL',
                   8930:                                           titbl   => 'Title is blank',
1.538     raeburn  8931:                                           more    => '(More ...)',
                   8932:                                           less    => '(Less ...)',
1.543     raeburn  8933:                                           noor    => 'No actions selected or changes to settings specified.',
                   8934:                                           noch    => 'No changes to settings specified.',
                   8935:                                           noac    => 'No actions selected.',
1.606     raeburn  8936:                                           nofi    => 'No file selected',
                   8937:                                           tinc    => 'Title in course',
                   8938:                                           sunm    => 'Sub-directory name',
1.618     raeburn  8939:                                           edri    => 'Editing rights unavailable for your current role.',
1.691     raeburn  8940:                                           sele    => 'Select',
                   8941:                                           swit    => 'Switch server required',
1.329     droeschl 8942:                                         );
1.594     damieng  8943:     &js_escape(\%js_lt);
1.433     raeburn  8944:     my $crstype = &Apache::loncommon::course_type();
1.434     raeburn  8945:     my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
                   8946:     my $main_container_page;
1.519     raeburn  8947:     if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
                   8948:         $main_container_page = 1;
1.434     raeburn  8949:     }
1.617     raeburn  8950:     my $backtourl;
                   8951:     my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446     www      8952:     my $toplevelsupp = &supplemental_base();
1.690     raeburn  8953:     my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691     raeburn  8954:     my @ids=&Apache::lonnet::current_machine_ids();
                   8955:     my $machines_str = "'".join("','",@ids)."'";
1.530     raeburn  8956:     if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
                   8957:         my $caller = $1;
1.525     raeburn  8958:         if ($caller =~ /^supplemental/) {
                   8959:             $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
                   8960:         } else {
                   8961:             my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
                   8962:             $res = &Apache::lonnet::clutter($res);
                   8963:             if (&Apache::lonnet::is_on_map($res)) {
1.609     raeburn  8964:                 my ($url,$anchor);
                   8965:                 if ($res =~ /^([^#]+)#([^#]+)$/) {
                   8966:                     $url = $1;
                   8967:                     $anchor = $2;
                   8968:                     if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
                   8969:                         $caller = $1.&escape('#').$anchor;
                   8970:                     }
1.614     raeburn  8971:                 } else {
                   8972:                     $url = $res;
1.609     raeburn  8973:                 }
1.640     raeburn  8974:                 $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
                   8975:                 if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
                   8976:                     $backtourl .= '?navmap=1';
                   8977:                 } else {
                   8978:                     $backtourl .= '?symb='.
                   8979:                                   &HTML::Entities::encode($caller,'<>&"');
                   8980:                 }
1.622     raeburn  8981:                 if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   8982:                     if (($ENV{'SERVER_PORT'} == 443) &&
                   8983:                         ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  8984:                         unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  8985:                             if ($hostname ne '') {
                   8986:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   8987:                             }
                   8988:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  8989:                         }
                   8990:                     }
1.623     raeburn  8991:                 } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
                   8992:                     if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678     raeburn  8993:                         unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658     raeburn  8994:                             if ($hostname ne '') {
                   8995:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   8996:                             }
                   8997:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.657     raeburn  8998:                         }
1.623     raeburn  8999:                     }
1.622     raeburn  9000:                 }
1.609     raeburn  9001:                 if ($anchor ne '') {
                   9002:                     $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
                   9003:                 }
1.590     raeburn  9004:                 $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544     raeburn  9005:             } else {
                   9006:                 $backtourl = '/adm/navmaps';
1.525     raeburn  9007:             }
                   9008:         }
                   9009:     } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
                   9010:         $backtourl = '/adm/menu';
                   9011:     } elsif ($supplementalflag) {
1.682     raeburn  9012:         if (($env{'request.role.adv'}) ||
                   9013:             (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
                   9014:             $backtourl = '/adm/supplemental';
                   9015:         } else {
                   9016:             $backtourl = '/adm/navmaps';
                   9017:         }
1.525     raeburn  9018:     } else {
                   9019:         $backtourl = '/adm/navmaps';
1.472     raeburn  9020:     }
                   9021: 
1.655     raeburn  9022:     my $fieldsets = "'doc'";
1.519     raeburn  9023:     unless ($main_container_page) {
                   9024:         $fieldsets .=",'ims'";
                   9025:     }
1.655     raeburn  9026:     my $extfieldsets = "'ext'";
                   9027:     if ($posslti) {
                   9028:         $extfieldsets .= ",'tool'";
                   9029:     }
1.501     raeburn  9030:     if ($supplementalflag) {
1.655     raeburn  9031:         $fieldsets = "'suppdoc'";
                   9032:         $extfieldsets = "'suppext'";
1.600     raeburn  9033:         if ($posslti) {
1.655     raeburn  9034:             $extfieldsets .= ",'supptool'";
1.600     raeburn  9035:         }
1.501     raeburn  9036:     }
1.655     raeburn  9037: 
1.611     raeburn  9038:     my $jsmakefunctions;
                   9039:     if ($canedit) {
                   9040:         $jsmakefunctions = <<ENDNEWSCRIPT;
1.329     droeschl 9041: function makenewfolder(targetform,folderseq) {
1.594     damieng  9042:     var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329     droeschl 9043:     if (foldername) {
1.676     raeburn  9044:        targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329     droeschl 9045:         targetform.submit();
                   9046:     }
                   9047: }
                   9048: 
                   9049: function makenewpage(targetform,folderseq) {
1.594     damieng  9050:     var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329     droeschl 9051:     if (pagename) {
1.676     raeburn  9052:         targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329     droeschl 9053:         targetform.submit();
                   9054:     }
                   9055: }
                   9056: 
                   9057: function makeexamupload() {
1.594     damieng  9058:    var title=prompt('$js_lt{"p_mxu"}');
1.344     bisitz   9059:    if (title) {
1.329     droeschl 9060:     this.document.forms.newexamupload.importdetail.value=
1.676     raeburn  9061: 	encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329     droeschl 9062:     this.document.forms.newexamupload.submit();
                   9063:    }
                   9064: }
                   9065: 
                   9066: function makesmppage() {
1.594     damieng  9067:    var title=prompt('$js_lt{"p_msp"}');
1.344     bisitz   9068:    if (title) {
1.329     droeschl 9069:     this.document.forms.newsmppg.importdetail.value=
1.676     raeburn  9070: 	encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329     droeschl 9071:     this.document.forms.newsmppg.submit();
                   9072:    }
                   9073: }
                   9074: 
1.534     raeburn  9075: function makewebpage(type) {
1.594     damieng  9076:    var title=prompt('$js_lt{"p_mwp"}');
1.534     raeburn  9077:    var formname;
                   9078:    if (type == 'supp') {
                   9079:        formname = this.document.forms.supwebpage;
                   9080:    } else {
                   9081:        formname = this.document.forms.newwebpage;
                   9082:    }
                   9083:    if (title) {
                   9084:        var webpage = formname.importdetail.value; 
1.675     raeburn  9085:        formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534     raeburn  9086:        formname.submit();
                   9087:    }
                   9088: }
                   9089: 
1.329     droeschl 9090: function makesmpproblem() {
1.594     damieng  9091:    var title=prompt('$js_lt{"p_msb"}');
1.344     bisitz   9092:    if (title) {
1.329     droeschl 9093:     this.document.forms.newsmpproblem.importdetail.value=
1.676     raeburn  9094: 	encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329     droeschl 9095:     this.document.forms.newsmpproblem.submit();
                   9096:    }
                   9097: }
                   9098: 
                   9099: function makedropbox() {
1.594     damieng  9100:    var title=prompt('$js_lt{"p_mdb"}');
1.344     bisitz   9101:    if (title) {
1.329     droeschl 9102:     this.document.forms.newdropbox.importdetail.value=
1.676     raeburn  9103:         encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329     droeschl 9104:     this.document.forms.newdropbox.submit();
                   9105:    }
                   9106: }
                   9107: 
                   9108: function makebulboard() {
1.594     damieng  9109:    var title=prompt('$js_lt{"p_mbb"}');
1.329     droeschl 9110:    if (title) {
                   9111:     this.document.forms.newbul.importdetail.value=
1.676     raeburn  9112: 	encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329     droeschl 9113:     this.document.forms.newbul.submit();
                   9114:    }
                   9115: }
                   9116: 
                   9117: function makeabout() {
1.594     damieng  9118:    var user=prompt("$js_lt{'p_mab'}");
1.329     droeschl 9119:    if (user) {
                   9120:        var comp=new Array();
                   9121:        comp=user.split(':');
                   9122:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   9123: 	   if ((comp[0]) && (comp[1])) {
                   9124: 	       this.document.forms.newaboutsomeone.importdetail.value=
1.594     damieng  9125: 		   '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611     raeburn  9126:                this.document.forms.newaboutsomeone.submit();
                   9127:            } else {
                   9128:                alert("$js_lt{'p_mab_alrt1'}");
                   9129:            }
                   9130:        } else {
                   9131:            alert("$js_lt{'p_mab_alrt2'}");
                   9132:        }
                   9133:     }
                   9134: }
                   9135: 
                   9136: function makenew(targetform) {
                   9137:     targetform.submit();
                   9138: }
                   9139: 
                   9140: function changename(folderpath,index,oldtitle) {
                   9141:     var title=prompt('$js_lt{"p_chn"}',oldtitle);
                   9142:     if (title) {
                   9143:         this.document.forms.renameform.markcopy.value='';
                   9144:         this.document.forms.renameform.title.value=title;
                   9145:         this.document.forms.renameform.cmd.value='rename_'+index;
                   9146:         this.document.forms.renameform.folderpath.value=folderpath;
                   9147:         this.document.forms.renameform.submit();
                   9148:     }
                   9149: }
                   9150: 
1.633     raeburn  9151: function setalias(folderpath,index) {
                   9152:     var alias = prompt('$js_lt{"setal"}');
                   9153:     if ((alias != null) && (alias != '')) {
                   9154:         this.document.forms.aliasform.alias.value=alias;
                   9155:         this.document.forms.aliasform.cmd.value='setalias_'+index;
                   9156:         this.document.forms.aliasform.folderpath.value=folderpath;
                   9157:         this.document.forms.aliasform.submit();
                   9158:     }
                   9159: }
                   9160: 
                   9161: function delalias(folderpath,index) {
                   9162:     if (confirm('$js_lt{"delal"}')) {
                   9163:         this.document.forms.aliasform.cmd.value='delalias_'+index;
                   9164:         this.document.forms.aliasform.folderpath.value=folderpath;
                   9165:         this.document.forms.aliasform.submit();
                   9166:     }
                   9167: }
                   9168: 
1.611     raeburn  9169: ENDNEWSCRIPT
                   9170:     } else {
                   9171:         $jsmakefunctions = <<ENDNEWSCRIPT;
                   9172: 
                   9173: function makenewfolder() {
                   9174:     alert("$js_lt{'edri'}");
                   9175: }
                   9176: 
                   9177: function makenewpage() {
                   9178:     alert("$js_lt{'edri'}");
                   9179: }
                   9180: 
                   9181: function makeexamupload() {
                   9182:     alert("$js_lt{'edri'}");
                   9183: }
                   9184: 
                   9185: function makesmppage() {
                   9186:     alert("$js_lt{'edri'}");
                   9187: }
                   9188: 
                   9189: function makewebpage(type) {
                   9190:     alert("$js_lt{'edri'}");
                   9191: }
                   9192: 
                   9193: function makesmpproblem() {
                   9194:     alert("$js_lt{'edri'}");
                   9195: }
                   9196: 
                   9197: function makedropbox() {
                   9198:     alert("$js_lt{'edri'}");
                   9199: }
                   9200: 
                   9201: function makebulboard() {
                   9202:     alert("$js_lt{'edri'}");
                   9203: }
                   9204: 
                   9205: function makeabout() {
                   9206:     alert("$js_lt{'edri'}");
                   9207: }
                   9208: 
                   9209: function changename() {
                   9210:     alert("$js_lt{'edri'}");
                   9211: }
                   9212: 
1.633     raeburn  9213: function setalias() {
                   9214:     alert("$js_lt{'edri'}");
                   9215: }
                   9216: 
                   9217: function delalias() {
                   9218:     alert("$js_lt{'edri'}");
                   9219: }
                   9220: 
1.611     raeburn  9221: function makenew() {
                   9222:     alert("$js_lt{'edri'}");
                   9223: }
                   9224: 
                   9225: function groupimport() {
                   9226:     alert("$js_lt{'edri'}");
1.335     ehlerst  9227: }
1.611     raeburn  9228: 
                   9229: function groupsearch() {
                   9230:     alert("$js_lt{'edri'}");
1.335     ehlerst  9231: }
1.611     raeburn  9232: 
                   9233: function groupopen(url,recover) {
                   9234:    var options="scrollbars=1,resizable=1,menubar=0";
                   9235:    idxflag=1;
                   9236:    idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
                   9237:    idx.focus();
1.329     droeschl 9238: }
                   9239: 
1.611     raeburn  9240: ENDNEWSCRIPT
                   9241: 
                   9242:     }
                   9243:     return <<ENDSCRIPT;
                   9244: 
                   9245: $jsmakefunctions
                   9246: 
1.501     raeburn  9247: function toggleUpload(caller) {
                   9248:     var blocks = Array($fieldsets);
                   9249:     for (var i=0; i<blocks.length; i++) {
                   9250:         var disp = 'none';
                   9251:         if (caller == blocks[i]) {
                   9252:             var curr = document.getElementById('upload'+caller+'form').style.display;
                   9253:             if (curr == 'none') {
                   9254:                 disp='block';
                   9255:             }
                   9256:         }
                   9257:         document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655     raeburn  9258:     }
                   9259:     resize_scrollbox('contentscroll','1','1');
                   9260:     return;
                   9261: }
                   9262: 
                   9263: function toggleExternal(caller) {
                   9264:     var blocks = Array($extfieldsets);
                   9265:     for (var i=0; i<blocks.length; i++) {
                   9266:         var disp = 'none';
                   9267:         if (caller == blocks[i]) {
                   9268:             var curr = document.getElementById('external'+caller+'form').style.display;
                   9269:             if (curr == 'none') {
                   9270:                 disp='block';
                   9271:             }
                   9272:         }
                   9273:         document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598     raeburn  9274:         if ((caller == 'tool') || (caller == 'supptool')) {
                   9275:             if (disp == 'block') {
1.655     raeburn  9276:                 if (document.getElementById('LC_exttoolid')) {
                   9277:                     var toolselector = document.getElementById('LC_exttoolid');
1.598     raeburn  9278:                     var suppflag = 0;
                   9279:                     if (caller == 'supptool') {
                   9280:                         suppflag = 1;
                   9281:                     }
                   9282:                     currForm = document.getElementById('new'+caller);
1.655     raeburn  9283:                     updateExttool(toolselector,currForm,suppflag);
1.598     raeburn  9284:                 }
                   9285:             }
                   9286:         }
1.501     raeburn  9287:     }
1.502     raeburn  9288:     resize_scrollbox('contentscroll','1','1');
                   9289:     return;
                   9290: }
                   9291: 
1.514     raeburn  9292: function toggleMap(caller) {
1.502     raeburn  9293:     var disp = 'none';
1.510     raeburn  9294:     if (document.getElementById('importmapform')) {
1.514     raeburn  9295:         if (caller == 'map') {
                   9296:             var curr = document.getElementById('importmapform').style.display;
                   9297:             if (curr == 'none') {
                   9298:                 disp='block';
                   9299:             }
1.510     raeburn  9300:         }
                   9301:         document.getElementById('importmapform').style.display=disp;
1.706     raeburn  9302:         if (disp == 'block') {
                   9303:             if (document.getElementById('importcrsresform')) {
                   9304:                 if (document.getElementById('importcrsresform').style.display == 'block') {
                   9305:                     document.getElementById('importcrsresform').style.display = 'none';
                   9306:                 }
                   9307:             }
                   9308:         }
1.510     raeburn  9309:         resize_scrollbox('contentscroll','1','1');
1.502     raeburn  9310:     }
1.501     raeburn  9311:     return;
1.329     droeschl 9312: }
                   9313: 
1.691     raeburn  9314: function toggleCrsRes(caller) {
1.606     raeburn  9315:     var disp = 'none';
                   9316:     if (document.getElementById('crsresform')) {
                   9317:         if (caller == 'res') {
1.691     raeburn  9318:             var form = document.getElementById('crsresform');
                   9319:             var curr = form.style.display;
1.606     raeburn  9320:             if (curr == 'none') {
                   9321:                 disp='block';
1.691     raeburn  9322:                 document.courseresform.authorrole.selectedIndex = 0;
                   9323:                 document.courseresform.authorpath.selectedIndex = 0;
                   9324:                 document.courseresform.newresourceadd.selectedIndex = 0;
                   9325:                 populateDirSelects(form,'authorrole','authorpath',1,0,0);
                   9326:                 toggleNewInCourse(document.courseresform);
                   9327:                 if (document.getElementById('newresource')) {
                   9328:                     document.getElementById('newresource').style.display = 'none';
1.606     raeburn  9329:                 }
                   9330:                 if (document.courseresform.newresusetemp.length) {
                   9331:                     document.courseresform.newresusetemp[0].checked = true;
                   9332:                     toggleWithTemplate(document.courseresform);
                   9333:                 }
                   9334:                 document.courseresform.newresourcename.value = ''; 
                   9335:             }
                   9336:         }
                   9337:         if (document.courseresform.newsubdir.length) {
                   9338:             for (var j=0; j<document.courseresform.newsubdir.length; j++) {
                   9339:                 if (document.courseresform.newsubdir[j].value == 0) {
                   9340:                     document.courseresform.newsubdir[j].checked = true;
                   9341:                 }
                   9342:                 break;
                   9343:             }
                   9344:             if (document.getElementById('newsubdirname')) {
                   9345:                 document.getElementById('newsubdirname').type = "hidden";
                   9346:                 document.getElementById('newsubdirname').value = "";
                   9347:             }
                   9348:             if (document.getElementById('newsubdir')) {
                   9349:                 document.getElementById('newsubdir').innerHTML = "";
                   9350:             }
                   9351:         }
                   9352:         document.getElementById('crsresform').style.display=disp;
                   9353:         resize_scrollbox('contentscroll','1','0');
                   9354:     }
                   9355:     return;
                   9356: }
                   9357: 
                   9358: function toggleNewsubdir(form) {
                   9359:     if (form.newsubdir.length) {
                   9360:         for (var j=0; j<form.newsubdir.length; j++) {
                   9361:             if (form.newsubdir[j].checked) {
                   9362:                 if (document.getElementById('newsubdirname')) {
                   9363:                     if (form.newsubdir[j].value == '1') {
                   9364:                         document.getElementById('newsubdirname').type = "text"; 
                   9365:                         if (document.getElementById('newsubdir')) {
                   9366:                             document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
                   9367:                         }
                   9368:                     } else {
                   9369:                         document.getElementById('newsubdirname').type = "hidden";
                   9370:                         document.getElementById('newsubdirname').value = "";
                   9371:                         document.getElementById('newsubdir').innerHTML = "";
                   9372:                     }
                   9373:                 }
                   9374:                 break;
                   9375:             }
                   9376:         }
                   9377:     }
                   9378: }
                   9379: 
                   9380: function toggleCrsResTitle() {
                   9381:     if (document.getElementById('newresource')) {
1.691     raeburn  9382:         var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
                   9383:         if (selloc == 'course') {
1.606     raeburn  9384:             document.getElementById('newresource').style.display = 'inline';
                   9385:             document.courseresform.newresourceadd[0].checked = true;
                   9386:             toggleNewInCourse(document.courseresform);
                   9387:         } else {
                   9388:             document.getElementById('newresource').style.display = 'none';
                   9389:         }
1.689     raeburn  9390:     }
                   9391:     if (document.getElementById('newstdproblem')) {
                   9392:         if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
                   9393:             document.getElementById('newstdproblem').style.display = 'none'; 
                   9394:             if (document.getElementById('stdprobswitch')) {
                   9395:                 document.getElementById('stdprobswitch').style.display = 'block'; 
                   9396:             }
                   9397:         } else {
                   9398:             document.getElementById('newstdproblem').style.display = 'block';
                   9399:             if (document.getElementById('stdprobswitch')) {
                   9400:                 document.getElementById('stdprobswitch').style.display = 'none';
                   9401:             }
                   9402:         }
                   9403:     }
1.606     raeburn  9404: }
                   9405: 
                   9406: function toggleNewInCourse(form) {
                   9407:     if (form.newresourceadd.length) {
                   9408:         for (var i=0; i<form.newresourceadd.length; i++) {
                   9409:             if (form.newresourceadd[i].checked) {
                   9410:                 if (document.getElementById('newresourcetitle')) {
                   9411:                     if (form.newresourceadd[i].value == '1') {
                   9412:                         document.getElementById('newresourcetitle').type = 'text';
                   9413:                         if (document.getElementById('newrestitle')) {
                   9414:                             document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
                   9415:                         }
                   9416:                     } else {
                   9417:                         document.getElementById('newresourcetitle').type = 'hidden';
                   9418:                         document.getElementById('newresourcetitle').value = '';
                   9419:                         if (document.getElementById('newrestitle')) { 
                   9420:                             document.getElementById('newrestitle').innerHTML = '';
                   9421:                         }
                   9422:                     }
                   9423:                 }
                   9424:                 break;
                   9425:             }
                   9426:         }
                   9427:     }
                   9428: }
                   9429: 
                   9430: function toggleWithTemplate(form) {
                   9431:     if (form.newresusetemp.length) {
                   9432:         for (var i=0; i<form.newresusetemp.length; i++) {
                   9433:             if (form.newresusetemp[i].checked) {
                   9434:                 if (document.getElementById('newrestemplate')) { 
                   9435:                     if (form.newresusetemp[i].value == '1') {
                   9436:                         document.getElementById('newrestemplate').style.display = 'inline';
                   9437:                         toggleExampleText();
                   9438:                     } else {
                   9439:                         form.tempcategory.selectedIndex = 0;
                   9440:                         select1template_changed();
                   9441:                         document.getElementById('newrestemplate').style.display = 'none';
                   9442:                     }
                   9443:                 }
                   9444:             }
                   9445:         }
                   9446:     }
                   9447: }
                   9448: 
                   9449: function toggleExampleText() {
                   9450:     if (document.getElementById('newresexample')) {
                   9451:         var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   9452:         if (url == '') {
                   9453:             document.getElementById('newresexample').style.fontWeight = 'normal';
                   9454:         } else {
                   9455:             document.getElementById('newresexample').style.fontWeight = 'bold';
                   9456:         }
                   9457:     }
                   9458: }
                   9459: 
                   9460: function getExample(width,height,scrolling,transparency) {
                   9461:     var url;
                   9462:     if (document.courseresform.newresusetemp.length) {
                   9463:         for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
                   9464:             if (document.courseresform.newresusetemp[i].checked) {
                   9465:                 if (document.courseresform.newresusetemp[i].value == '1') {
                   9466:                     var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   9467:                     if (url == '') {
                   9468:                         alert('Pick a category and template');
                   9469:                     } else {
                   9470:                         url = url.replace("$londocroot",""); 
                   9471:                         url += '?inhibitmenu=yes';
                   9472:                     }
                   9473:                 }
                   9474:                 break;
                   9475:             }
                   9476:         }
                   9477:     }
                   9478:     if (url != '') {
                   9479:         openMyModal(url,width,height,scrolling,transparency,'');
                   9480:     }
                   9481: }
                   9482: 
1.690     raeburn  9483: function toggleImportCrsres(caller) {
1.606     raeburn  9484:     var disp = 'none';
                   9485:     if (document.getElementById('importcrsresform')) {
                   9486:         if (caller == 'res') {
                   9487:             var curr = document.getElementById('importcrsresform').style.display;
                   9488:             if (curr == 'none') {
                   9489:                 disp='block';
1.698     raeburn  9490:                 populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
                   9491:                 if ((document.getElementById('importcrsrescontent')) &&
                   9492:                     (document.getElementById('importcrsresempty'))) {
                   9493:                     var selelem = document.crsresimportform.elements['coursepath'];
                   9494:                     var numdirs = 0;
                   9495:                     if (selelem.options.length) {
                   9496:                         numdirs = selelem.options.length - 1;
                   9497:                     }
                   9498:                     if (numdirs) {
                   9499:                         document.getElementById('importcrsrescontent').style.display='block';
                   9500:                         document.getElementById('importcrsresempty').style.display='none';
                   9501:                     } else {
                   9502:                         document.getElementById('importcrsrescontent').style.display='none';
                   9503:                         document.getElementById('importcrsresempty').style.display='block';
                   9504:                     }
                   9505:                 }
1.606     raeburn  9506:             }
                   9507:         }
                   9508:         document.getElementById('importcrsresform').style.display=disp;
1.706     raeburn  9509:         if (disp == 'block') {
                   9510:             if (document.getElementById('importmapform')) {
                   9511:                 if (document.getElementById('importmapform').style.display == 'block') {
                   9512:                     document.getElementById('importmapform').style.display = 'none';
                   9513:                 }
                   9514:             }
                   9515:         }
1.606     raeburn  9516:         resize_scrollbox('contentscroll','1','0');
                   9517:     }
                   9518:     return;
                   9519: }
                   9520: 
1.690     raeburn  9521: $showfile_js
                   9522: 
1.691     raeburn  9523: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
                   9524:     var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
                   9525:     if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
                   9526:         var selelem = form.elements[dirsel];
                   9527:         var i, numfiles = selelem.options.length -1;
                   9528:         if (numfiles >=0) {
                   9529:             for (i = numfiles; i >= 0; i--) {
                   9530:                 selelem.remove(i);
                   9531:             }
                   9532:         }
                   9533:         if ((location == '') || (location == null) || (location == 'undefined')) {
                   9534:              if (selelem.options.length == 0) {
                   9535:                  selelem.options[selelem.options.length] = new Option('','');
                   9536:                  selelem.selectedIndex = 0;
                   9537:              }
                   9538:              if (document.getElementById('newstdproblem')) {
                   9539:                  document.getElementById('newstdproblem').style.display = 'none';
                   9540:              }
                   9541:              return;
                   9542:         }
                   9543:         var machineIds = new Array($machines_str);
                   9544:         var athome = 0;
                   9545:         var role = location;
                   9546:         if ((location == 'author') || (location == 'course')) {
                   9547:             if (document.getElementById('rolehome_'+location)) {
                   9548:                 var currhome = document.getElementById('rolehome_'+location).value;
                   9549:                 if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
                   9550:                     if (machineIds.includes(currhome)) {
                   9551:                         athome = 1;
                   9552:                     }
                   9553:                 }
                   9554:             }
                   9555:         } else {
                   9556:             const roleinfo = location.split('___');
                   9557:             role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
                   9558:             if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
                   9559:                 var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
                   9560:                 if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
                   9561:                     if (machineIds.includes(currhome)) {
                   9562:                         athome = 1;
                   9563:                     }
                   9564:                 }
                   9565:             }
                   9566:         }
1.706     raeburn  9567:         var templateradio = document.courseresform.elements['newresusetemp'];
1.691     raeburn  9568:         if (athome) {
                   9569:             if (document.getElementById('stdprobswitch')) {
                   9570:                 document.getElementById('stdprobswitch').style.display = 'none';
                   9571:             }
                   9572:             if (document.getElementById('newstdproblem')) {
                   9573:                 document.getElementById('newstdproblem').style.display = 'none';
                   9574:             }
1.706     raeburn  9575:             var canedit = '$canedit';
                   9576:             if (canedit) {
                   9577:                 if (templateradio.length > 1) {
                   9578:                     for (var i=0; i<templateradio.length; i++) {
                   9579:                         templateradio[i].disabled = false;
                   9580:                     }
                   9581:                 }
                   9582:                 document.courseresform.newresourcename.disabled = false;
                   9583:                 document.courseresform.newcrs.disabled = false;
                   9584:             }
1.691     raeburn  9585:             var http = new XMLHttpRequest();
                   9586:             var url = "/adm/courseauthor";
1.698     raeburn  9587:             var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691     raeburn  9588:             http.open("POST", url, true);
                   9589:             http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                   9590:             http.onreadystatechange = function() {
                   9591:                 if (http.readyState == 4 && http.status == 200) {
                   9592:                     var data = JSON.parse(http.responseText);
                   9593:                     if (Array.isArray(data.dirs)) {
                   9594:                         var len = data.dirs.length;
                   9595:                         if (len) {
                   9596:                             if (len > 1) {
                   9597:                                 selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
                   9598:                             }
                   9599:                         }
                   9600:                         if (len) {
                   9601:                             var j;
                   9602:                             for (j = 0; j < len; j++) {
                   9603:                                 selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
                   9604:                             }
                   9605:                             selelem.selectedIndex = 0;
1.697     raeburn  9606:                             if (len == 1) {
                   9607:                                 toggleCrsResTitle();
                   9608:                             }
1.691     raeburn  9609:                         }
                   9610:                     }
                   9611:                 }
                   9612:             }
                   9613:             http.send(params);
                   9614:         } else {
                   9615:             selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
                   9616:             selelem.selectedIndex = 0;
                   9617:             if (document.getElementById('stdprobswitch')) {
                   9618:                 document.getElementById('stdprobswitch').style.display = 'block';
                   9619:             }
                   9620:             if (document.getElementById('newstdproblem')) {
                   9621:                 document.getElementById('newstdproblem').style.display = 'none';
                   9622:             }
1.706     raeburn  9623:             if (templateradio.length > 1) {
                   9624:                 for (var i=0; i<templateradio.length; i++) {
                   9625:                     templateradio[i].disabled = true;
                   9626:                 }
                   9627:             }
                   9628:             document.courseresform.newresourcename.disabled = true;
                   9629:             document.courseresform.newcrs.disabled = true;
1.691     raeburn  9630:         }
                   9631:     }
                   9632:     return;
                   9633: }
                   9634: 
1.689     raeburn  9635: function switchForProb() {
                   9636:     if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
                   9637:         var url = '/adm/switchserver?otherserver=';
                   9638:         var newhostid = '';
                   9639:         var role = '';
                   9640:         var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
                   9641:         if (selloc == 'author') {
                   9642:             newhostid = document.courseresform.rolehome_author.value;
                   9643:             role = "au./&js_escape($env{'user.domain'})/";
                   9644:         } else if (selloc == 'course') {
                   9645:             newhostid = document.courseresform.rolehome_course.value;
                   9646:             role = "&js_escape($env{'request.role'})";
                   9647:         } else {
                   9648:             var items = new Array();
                   9649:             items = selloc.split('___');
                   9650:             var len = document.courseresform.rolehome_coauthor.length;
                   9651:             if (null == len) {
                   9652:                 var currval = document.courseresform.rolehome_coauthor.value;
                   9653:                 if (null != currval) {
                   9654:                     var info = new Array();
                   9655:                     info = currval.split('=');
                   9656:                     newhostid = info[2];
                   9657:                     role = info[0]+'./'+info[1];
                   9658:                 }
                   9659:             } else {
                   9660:                 for (var i=0; i<len; i++) {
                   9661:                     var currval = document.courseresform.rolehome_coauthor[i].value;
                   9662:                     if (null != currval) {
                   9663:                         var info = new Array();
                   9664:                         info = currval.split('=');
                   9665:                         if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
                   9666:                             newhostid = info[2];
                   9667:                             role = info[0]+'./'+info[1];
                   9668:                             break;
                   9669:                         }
                   9670:                     }
                   9671:                 }
                   9672:             }
                   9673:         }
                   9674:         if (newhostid != '') {
                   9675:             url += newhostid;
                   9676:             if (role != '') {
                   9677:                 url += '&role='+role;
                   9678:             }
                   9679:             document.location.href = url;
                   9680:         }
                   9681:     }
                   9682:     return;
                   9683: }
                   9684: 
1.501     raeburn  9685: function makeims(imsform) {
                   9686:     if ((imsform.uploaddoc.value == '')  || (!imsform.uploaddoc.value)) {
1.594     damieng  9687:         alert("$js_lt{'imsfile'}");
1.501     raeburn  9688:         return;
                   9689:     }
                   9690:     if (imsform.source.selectedIndex == 0) {
1.594     damieng  9691:         alert("$js_lt{'imscms'}");
1.501     raeburn  9692:         return;
                   9693:     }
                   9694:     newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
                   9695:     imsform.submit();
                   9696: }
                   9697: 
1.478     raeburn  9698: function updatePick(targetform,index,caller) {
1.537     raeburn  9699:     var pickitem;
                   9700:     var picknumitem;
                   9701:     var picknumtext;
                   9702:     if (index == 'all') {
                   9703:         pickitem = document.getElementById('randompickall');
                   9704:         picknumitem = document.getElementById('rpicknumall');
                   9705:         picknumtext = document.getElementById('rpicktextall');
                   9706:     } else {
                   9707:         pickitem = document.getElementById('randompick_'+index);
                   9708:         picknumitem = document.getElementById('rpicknum_'+index);
                   9709:         picknumtext = document.getElementById('randompicknum_'+index);
                   9710:     }
1.478     raeburn  9711:     if (pickitem.checked) {
1.594     damieng  9712:         var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478     raeburn  9713:         if (picknum == '' || picknum == null) {
                   9714:             if (caller == 'check') {
                   9715:                 pickitem.checked=false;
1.537     raeburn  9716:                 if (index == 'all') {
                   9717:                     picknumtext.innerHTML = '';
                   9718:                     if (caller == 'link') {
                   9719:                         propagateState(targetform,'rpicknum');
                   9720:                     }
                   9721:                 } else {
1.538     raeburn  9722:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  9723:                 }
1.478     raeburn  9724:             }
                   9725:         } else {
                   9726:             picknum.toString();
                   9727:             var regexdigit=/^\\d+\$/;
                   9728:             if (regexdigit.test(picknum)) {
                   9729:                 picknumitem.value = picknum;
1.537     raeburn  9730:                 if (index == 'all') {
1.538     raeburn  9731:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537     raeburn  9732:                     if (caller == 'link') {
                   9733:                         propagateState(targetform,'rpicknum');
                   9734:                     }
                   9735:                 } else {
                   9736:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538     raeburn  9737:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  9738:                 }
1.478     raeburn  9739:             } else {
                   9740:                 if (caller == 'check') {
1.537     raeburn  9741:                     if (index == 'all') {
                   9742:                         picknumtext.innerHTML = '';
                   9743:                         if (caller == 'link') {
                   9744:                             propagateState(targetform,'rpicknum');
                   9745:                         }
                   9746:                     } else {
                   9747:                         pickitem.checked=false;
1.538     raeburn  9748:                         checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  9749:                     }
1.478     raeburn  9750:                 }
                   9751:                 return;
                   9752:             }
                   9753:         }
                   9754:     } else {
1.537     raeburn  9755:         picknumitem.value = '';
                   9756:         picknumtext.innerHTML = '';
                   9757:         if (index == 'all') {
                   9758:             if (caller == 'link') {
                   9759:                 propagateState(targetform,'rpicknum');
                   9760:             }
                   9761:         } else {
1.538     raeburn  9762:             checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  9763:         }
                   9764:     }
                   9765: }
                   9766: 
                   9767: function propagateState(form,param) {
                   9768:     if (document.getElementById(param+'all')) {
                   9769:         var setcheck = 0;
                   9770:         var rpick = 0;
                   9771:         if (param == 'rpicknum') {
                   9772:             if (document.getElementById('randompickall')) {
                   9773:                 if (document.getElementById('randompickall').checked) {
                   9774:                     if (document.getElementById('rpicknumall')) {
                   9775:                         rpick = document.getElementById('rpicknumall').value;
                   9776:                     }
                   9777:                 }
                   9778:             }
                   9779:         } else {
                   9780:             if (document.getElementById(param+'all').checked) {
                   9781:                 setcheck = 1;
                   9782:             }
                   9783:         }
1.538     raeburn  9784:         var allidxlist;
                   9785:         if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   9786:             if (document.getElementById('all'+param+'idx')) {
                   9787:                 allidxlist = document.getElementById('all'+param+'idx').value;
                   9788:             }
                   9789:             var actions = new Array ('remove','cut','copy');
                   9790:             for (var i=0; i<actions.length; i++) {
                   9791:                 if (actions[i] != param) {
                   9792:                     if (document.getElementById(actions[i]+'all')) {
                   9793:                         document.getElementById(actions[i]+'all').checked = false; 
                   9794:                     }
                   9795:                 }
                   9796:             }
                   9797:         }
1.537     raeburn  9798:         if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538     raeburn  9799:             allidxlist = form.allidx.value;
                   9800:         }
                   9801:         if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
                   9802:             allidxlist = form.allmapidx.value;
                   9803:         }
                   9804:         if ((allidxlist != '') && (allidxlist != null)) {
                   9805:             var allidxs = allidxlist.split(',');
                   9806:             if (allidxs.length > 1) {
                   9807:                 for (var i=0; i<allidxs.length; i++) {
                   9808:                     if (document.getElementById(param+'_'+allidxs[i])) {
                   9809:                         if (param == 'rpicknum') {
                   9810:                             if (document.getElementById('randompick_'+allidxs[i])) {
                   9811:                                 if (document.getElementById('randompick_'+allidxs[i]).checked) {
                   9812:                                     document.getElementById(param+'_'+allidxs[i]).value = rpick;
                   9813:                                     if (rpick > 0) {
                   9814:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ':&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
                   9815:                                     } else {
                   9816:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   9817:                                     }
                   9818:                                 }
                   9819:                             }
                   9820:                         } else {
1.537     raeburn  9821:                             if (setcheck == 1) {
                   9822:                                 document.getElementById(param+'_'+allidxs[i]).checked = true;
                   9823:                             } else {
                   9824:                                 document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538     raeburn  9825:                                 if (param == 'randompick') {
                   9826:                                     document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   9827:                                 }
1.537     raeburn  9828:                             }
                   9829:                         }
                   9830:                     }
                   9831:                 }
1.538     raeburn  9832:                 if (setcheck == 1) {
                   9833:                     if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   9834:                         var actions = new Array('copy','cut','remove');
                   9835:                         for (var i=0; i<actions.length; i++) {
                   9836:                             var otheractions;
                   9837:                             var otheridxs;
                   9838:                             if (actions[i] === param) {
                   9839:                                 continue;
                   9840:                             } else {
                   9841:                                 if (document.getElementById('all'+actions[i]+'idx')) {
                   9842:                                     otheractions = document.getElementById('all'+actions[i]+'idx').value;
                   9843:                                     otheridxs = otheractions.split(',');
                   9844:                                     if (otheridxs.length > 1) {
                   9845:                                         for (var j=0; j<otheridxs.length; j++) {
                   9846:                                             if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
                   9847:                                                 document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
                   9848:                                             }
1.537     raeburn  9849:                                         }
                   9850:                                     }
                   9851:                                 }
1.538     raeburn  9852:                             }
                   9853:                         } 
                   9854:                     }
                   9855:                 }
                   9856:             }
                   9857:         }
                   9858:     }
                   9859:     return;
                   9860: }
                   9861: 
1.603     raeburn  9862: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611     raeburn  9863:     var canedit = '$canedit';
                   9864:     if (canedit == '') {
                   9865:         alert("$js_lt{'edri'}");
                   9866:         return;
                   9867:     }
1.539     raeburn  9868:     var dosettings;
                   9869:     var doaction;
1.538     raeburn  9870:     var control = document.togglemultsettings;
                   9871:     if (context == 'actions') {
                   9872:         control = document.togglemultactions;
1.539     raeburn  9873:         doaction = 1; 
                   9874:     } else {
                   9875:         dosettings = 1;
1.538     raeburn  9876:     }
1.539     raeburn  9877:     if (control) {
                   9878:         if (control.showmultpick.length) {
                   9879:             for (var i=0; i<control.showmultpick.length; i++) {
                   9880:                 if (control.showmultpick[i].checked) {
                   9881:                     if (control.showmultpick[i].value == 1) {
                   9882:                         if (context == 'settings') {
                   9883:                             dosettings = 0;
                   9884:                         } else {
                   9885:                             doaction = 0;
1.538     raeburn  9886:                         }
                   9887:                     }
                   9888:                 }
1.537     raeburn  9889:             }
                   9890:         }
1.539     raeburn  9891:     }
                   9892:     if (context == 'settings') {
                   9893:         if (dosettings == 1) {
1.538     raeburn  9894:             targetform.changeparms.value=param;
                   9895:             targetform.submit();
                   9896:         }
1.537     raeburn  9897:     }
1.539     raeburn  9898:     if (context == 'actions') {
                   9899:         if (doaction == 1) {
                   9900:             targetform.cmd.value=param+'_'+index;
                   9901:             targetform.folderpath.value=folderpath;
                   9902:             targetform.markcopy.value=idx+':'+param;
                   9903:             targetform.copyfolder.value=folder+'.'+container;
                   9904:             if (param == 'remove') {
1.603     raeburn  9905:                 var doremove = 0;
                   9906:                 if (skip_confirm) {
                   9907:                     if (confirm_removal) {
                   9908:                         if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
                   9909:                             doremove = 1;
                   9910:                         }
                   9911:                     } else {
                   9912:                         doremove = 1;
                   9913:                     }
                   9914:                 } else {
                   9915:                     if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
                   9916:                         doremove = 1;
                   9917:                     }
                   9918:                 }
                   9919:                 if (doremove) {
1.539     raeburn  9920:                     targetform.markcopy.value='';
                   9921:                     targetform.copyfolder.value='';
                   9922:                     targetform.submit();
                   9923:                 }
                   9924:             }
                   9925:             if (param == 'cut') {
1.594     damieng  9926:                 if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
1.539     raeburn  9927:                     targetform.submit();
                   9928:                     return;
                   9929:                 }
                   9930:             }
                   9931:             if (param == 'copy') {
                   9932:                 targetform.submit();
                   9933:                 return;
                   9934:             }
                   9935:             targetform.markcopy.value='';
                   9936:             targetform.copyfolder.value='';
                   9937:             targetform.cmd.value='';
                   9938:             targetform.folderpath.value='';
                   9939:             return;
                   9940:         } else {
                   9941:             if (document.getElementById(param+'_'+idx)) {
                   9942:                 item = document.getElementById(param+'_'+idx);
                   9943:                 if (item.type == 'checkbox') {
                   9944:                     if (item.checked) {
                   9945:                         item.checked = false;
                   9946:                     } else {
                   9947:                         item.checked = true;
                   9948:                         singleCheck(item,idx,param);
                   9949:                     }
                   9950:                 }
                   9951:             }
                   9952:         }
                   9953:     }
1.537     raeburn  9954:     return;
                   9955: }
                   9956: 
1.538     raeburn  9957: function singleCheck(caller,idx,action) {
                   9958:     actions = new Array('cut','copy','remove');
                   9959:     if (caller.checked) {
                   9960:         for (var i=0; i<actions.length; i++) {
                   9961:             if (actions[i] != action) {
                   9962:                 if (document.getElementById(actions[i]+'_'+idx)) {
                   9963:                     if (document.getElementById(actions[i]+'_'+idx).checked) {
                   9964:                         document.getElementById(actions[i]+'_'+idx).checked = false;
                   9965:                     }
1.537     raeburn  9966:                 }
                   9967:             }
                   9968:         }
1.478     raeburn  9969:     }
1.537     raeburn  9970:     return;
1.478     raeburn  9971: }
                   9972: 
1.334     muellerd 9973: function unselectInactive(nav) {
1.335     ehlerst  9974: currentNav = document.getElementById(nav);
                   9975: currentLis = currentNav.getElementsByTagName('LI');
                   9976: for (i = 0; i < currentLis.length; i++) {
1.472     raeburn  9977:         if (currentLis[i].className == 'goback') {
                   9978:             currentLis[i].className = 'goback';
                   9979:         } else {
                   9980: 	    if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374     tempelho 9981: 		currentLis[i].className = 'right';
1.472     raeburn  9982: 	    } else {
1.374     tempelho 9983: 		currentLis[i].className = 'i';
1.472     raeburn  9984: 	    }
                   9985:         }
1.335     ehlerst  9986: }
1.332     tempelho 9987: }
                   9988: 
1.334     muellerd 9989: function hideAll(current, nav, data) {
1.335     ehlerst  9990: unselectInactive(nav);
1.570     raeburn  9991: if (current) { 
                   9992:     if (current.className == 'right'){
                   9993:         current.className = 'right active'
                   9994:     } else {
                   9995:         current.className = 'active';
                   9996:     }
1.374     tempelho 9997: }
1.335     ehlerst  9998: currentData = document.getElementById(data);
                   9999: currentDivs = currentData.getElementsByTagName('DIV');
                   10000: for (i = 0; i < currentDivs.length; i++) {
                   10001: 	if(currentDivs[i].className == 'LC_ContentBox'){
1.333     muellerd 10002: 		currentDivs[i].style.display = 'none';
1.330     tempelho 10003: 	}
                   10004: }
1.335     ehlerst  10005: }
1.330     tempelho 10006: 
1.374     tempelho 10007: function openTabs(pageId) {
                   10008: 	tabnav = document.getElementById(pageId).getElementsByTagName('UL');	
1.383     tempelho 10009: 	if(tabnav.length > 2 ){
1.389     tempelho 10010: 		currentNav = document.getElementById(tabnav[1].id);
1.374     tempelho 10011: 		currentLis = currentNav.getElementsByTagName('LI');
                   10012: 		for(i = 0; i< currentLis.length; i++){
                   10013: 			if(currentLis[i].className == 'active') {
1.375     tempelho 10014: 				funcString = currentLis[i].onclick.toString();
                   10015: 				tab = funcString.split('"');
1.420     onken    10016:                                 if(tab.length < 2) {
                   10017:                                    tab = funcString.split("'");
                   10018:                                 }
1.375     tempelho 10019: 				currentData = document.getElementById(tab[1]);
                   10020:         			currentData.style.display = 'block';
1.374     tempelho 10021: 			}	
                   10022: 		}
                   10023: 	}
                   10024: }
                   10025: 
1.334     muellerd 10026: function showPage(current, pageId, nav, data) {
1.570     raeburn  10027:         currstate = current.className;
1.334     muellerd 10028: 	hideAll(current, nav, data);
1.375     tempelho 10029: 	openTabs(pageId);
1.334     muellerd 10030: 	unselectInactive(nav);
1.570     raeburn  10031:         if ((currstate == 'active') || (currstate == 'right active')) {
                   10032:             if (currstate == 'active') {
                   10033: 	        current.className = '';
                   10034:             } else {
                   10035:                 current.className = 'right';
                   10036:             }
                   10037:             activeTab = ''; 
1.656     raeburn  10038:             toggleExternal();
1.570     raeburn  10039:             toggleUpload();
                   10040:             toggleMap();
1.606     raeburn  10041:             toggleCrsRes();
                   10042:             toggleImportCrsres();
1.570     raeburn  10043:             resize_scrollbox('contentscroll','1','0');
                   10044:             return;
                   10045:         } else {
                   10046:             current.className = 'active';
                   10047:         }
1.330     tempelho 10048: 	currentData = document.getElementById(pageId);
                   10049: 	currentData.style.display = 'block';
1.458     raeburn  10050:         activeTab = pageId;
1.656     raeburn  10051:         toggleExternal();
1.501     raeburn  10052:         toggleUpload();
1.503     raeburn  10053:         toggleMap();
1.606     raeburn  10054:         toggleCrsRes();
                   10055:         toggleImportCrsres();
1.433     raeburn  10056:         if (nav == 'mainnav') {
                   10057:             var storedpath = "$docs_folderpath";
1.434     raeburn  10058:             var storedpage = "$main_container_page";
1.433     raeburn  10059:             var reg = new RegExp("^supplemental");
                   10060:             if (pageId == 'mainCourseDocuments') {
1.434     raeburn  10061:                 if (storedpage == 1) {
                   10062:                     document.simpleedit.folderpath.value = '';
                   10063:                     document.uploaddocument.folderpath.value = '';
                   10064:                 } else {
                   10065:                     if (reg.test(storedpath)) {
                   10066:                         document.simpleedit.folderpath.value = '$toplevelmain';
                   10067:                         document.uploaddocument.folderpath.value = '$toplevelmain';
                   10068:                         document.newext.folderpath.value = '$toplevelmain';
                   10069:                     } else {
                   10070:                         document.simpleedit.folderpath.value = storedpath;
                   10071:                         document.uploaddocument.folderpath.value = storedpath;
                   10072:                         document.newext.folderpath.value = storedpath;
                   10073:                     }
1.433     raeburn  10074:                 }
                   10075:             } else {
1.434     raeburn  10076:                 if (reg.test(storedpath)) {
                   10077:                     document.simpleedit.folderpath.value = storedpath;
                   10078:                     document.supuploaddocument.folderpath.value = storedpath;
                   10079:                     document.supnewext.folderpath.value = storedpath;
                   10080:                 } else {
1.433     raeburn  10081:                     document.simpleedit.folderpath.value = '$toplevelsupp';
                   10082:                     document.supuploaddocument.folderpath.value = '$toplevelsupp';
                   10083:                     document.supnewext.folderpath.value = '$toplevelsupp';
                   10084:                 }
                   10085:             }
                   10086:         }
1.485     raeburn  10087:         resize_scrollbox('contentscroll','1','0');
1.330     tempelho 10088: 	return false;
                   10089: }
1.329     droeschl 10090: 
1.472     raeburn  10091: function toContents(jumpto) {
                   10092:     var newurl = '$backtourl';
1.525     raeburn  10093:     if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472     raeburn  10094:         newurl = newurl+'?postdata='+jumpto;
                   10095:     }
                   10096:     location.href=newurl;
                   10097: }
                   10098: 
1.538     raeburn  10099: function togglePick(caller,value) {
                   10100:     var disp = 'none';
                   10101:     if (document.getElementById('multi'+caller)) {
                   10102:         var curr = document.getElementById('multi'+caller).style.display;
                   10103:         if (value == 1) {
                   10104:             disp='block';
                   10105:         }
                   10106:         if (curr == disp) {
                   10107:             return; 
                   10108:         }
                   10109:         document.getElementById('multi'+caller).style.display=disp;
                   10110:         if (value == 1) {
1.594     damieng  10111:             document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>'; 
1.538     raeburn  10112:         } else {
                   10113:             document.getElementById('more'+caller).innerHTML = '';
                   10114:         }
                   10115:         if (caller == 'actions') { 
                   10116:             setClass(value);
                   10117:             setBoxes(value);
                   10118:         }
                   10119:     }
                   10120:     var showButton = multiSettings();
                   10121:     if (showButton != 1) {
                   10122:         showButton = multiActions();
                   10123:     }
                   10124:     if (document.getElementById('multisave')) {
                   10125:         if (showButton == 1) {
                   10126:             document.getElementById('multisave').style.display='block';
                   10127:         } else {
                   10128:             document.getElementById('multisave').style.display='none';
                   10129:         }
                   10130:     }
                   10131:     resize_scrollbox('contentscroll','1','1');
                   10132:     return;
                   10133: }
                   10134: 
                   10135: function toggleCheckUncheck(caller,more) {
                   10136:     if (more == 1) {
1.594     damieng  10137:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538     raeburn  10138:         document.getElementById('allfields'+caller).style.display='block';
                   10139:     } else {
1.594     damieng  10140:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538     raeburn  10141:         document.getElementById('allfields'+caller).style.display='none';
                   10142:     }
                   10143:     resize_scrollbox('contentscroll','1','1');
                   10144: }
                   10145: 
                   10146: function multiSettings() {
                   10147:     var inuse = 0;
                   10148:     var settingsform = document.togglemultsettings;
                   10149:     if (settingsform.showmultpick.length > 1) {
                   10150:         for (var i=0; i<settingsform.showmultpick.length; i++) {
                   10151:             if (settingsform.showmultpick[i].checked) {
                   10152:                 if (settingsform.showmultpick[i].value == 1) {
                   10153:                     inuse = 1;  
                   10154:                 }
                   10155:             }
                   10156:         }
                   10157:     }
                   10158:     return inuse;
                   10159: }
                   10160: 
                   10161: function multiActions() {
                   10162:     var inuse = 0;
                   10163:     var actionsform = document.togglemultactions;
                   10164:     if (actionsform.showmultpick.length > 1) {
                   10165:         for (var i=0; i<actionsform.showmultpick.length; i++) {
                   10166:             if (actionsform.showmultpick[i].checked) {
                   10167:                 if (actionsform.showmultpick[i].value == 1) {
                   10168:                     inuse = 1;
                   10169:                 }
                   10170:             }
                   10171:         }
                   10172:     }
                   10173:     return inuse;
                   10174: } 
                   10175: 
                   10176: function checkSubmits() {
                   10177:     var numchanges = 0;
                   10178:     var form = document.saveactions;
                   10179:     var doactions = multiActions();
1.542     raeburn  10180:     var cutwarnings = 0;
                   10181:     var remwarnings = 0;
1.603     raeburn  10182:     var removalinfo = 0;
1.538     raeburn  10183:     if (doactions == 1) {
                   10184:         var remidxlist = document.cumulativeactions.allremoveidx.value;
                   10185:         if ((remidxlist != '') && (remidxlist != null)) {
                   10186:             var remidxs = remidxlist.split(',');
                   10187:             for (var i=0; i<remidxs.length; i++) {
                   10188:                 if (document.getElementById('remove_'+remidxs[i])) {
                   10189:                     if (document.getElementById('remove_'+remidxs[i]).checked) {
                   10190:                         form.multiremove.value += remidxs[i]+',';
                   10191:                         numchanges ++;
1.542     raeburn  10192:                         if (document.getElementById('skip_remove_'+remidxs[i])) {
                   10193:                             if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
                   10194:                                 remwarnings ++;
                   10195:                             }
                   10196:                         }
1.603     raeburn  10197:                         if (document.getElementById('confirm_removal_'+remidxs[i])) {
                   10198:                             if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
                   10199:                                 removalinfo ++;
                   10200:                             }
                   10201:                         }
1.537     raeburn  10202:                     }
                   10203:                 }
1.538     raeburn  10204:             }
                   10205:         }
                   10206:         var cutidxlist = document.cumulativeactions.allcutidx.value;
                   10207:         if ((cutidxlist != '') && (cutidxlist != null)) {
                   10208:             var cutidxs = cutidxlist.split(',');
                   10209:             for (var i=0; i<cutidxs.length; i++) {
                   10210:                 if (document.getElementById('cut_'+cutidxs[i])) {
                   10211:                     if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
                   10212:                         form.multicut.value += cutidxs[i]+',';
                   10213:                         numchanges ++;
1.542     raeburn  10214:                         if (document.getElementById('skip_cut_'+cutidxs[i])) {
                   10215:                             if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
                   10216:                                 cutwarnings ++;
                   10217:                             }
                   10218:                         }
1.537     raeburn  10219:                     }
                   10220:                 }
                   10221:             }
                   10222:         }
1.538     raeburn  10223:         var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   10224:         if ((copyidxlist != '') && (copyidxlist != null)) {
                   10225:             var copyidxs = copyidxlist.split(',');
                   10226:             for (var i=0; i<copyidxs.length; i++) {
                   10227:                 if (document.getElementById('copy_'+copyidxs[i])) {
                   10228:                     if (document.getElementById('copy_'+copyidxs[i]).checked) {
                   10229:                         form.multicopy.value += copyidxs[i]+',';
                   10230:                         numchanges ++;
                   10231:                     }
                   10232:                 }
                   10233:             }
                   10234:         }
                   10235:         if (numchanges > 0) {
                   10236:             form.multichange.value = numchanges;
                   10237:         }
1.537     raeburn  10238:     }
1.538     raeburn  10239:     var dosettings = multiSettings();
1.543     raeburn  10240:     var haschanges = 0;
1.538     raeburn  10241:     if (dosettings == 1) {
                   10242:         form.allencrypturl.value = '';
                   10243:         form.allhiddenresource.value = '';
1.543     raeburn  10244:         form.changeparms.value = 'all';
                   10245:         var patt=new RegExp(",\$");
1.538     raeburn  10246:         var allidxlist = document.cumulativesettings.allidx.value;
                   10247:         if ((allidxlist != '') && (allidxlist != null)) {
                   10248:             var allidxs = allidxlist.split(',');
                   10249:             if (allidxs.length > 1) {
                   10250:                 for (var i=0; i<allidxs.length; i++) {
                   10251:                     if (document.getElementById('hiddenresource_'+allidxs[i])) {
                   10252:                         if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
                   10253:                             form.allhiddenresource.value += allidxs[i]+',';
                   10254:                         }
                   10255:                     }
                   10256:                     if (document.getElementById('encrypturl_'+allidxs[i])) {
                   10257:                         if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
                   10258:                             form.allencrypturl.value += allidxs[i]+',';
                   10259:                         }
                   10260:                     }
                   10261:                 }
1.543     raeburn  10262:                 form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
                   10263:                 form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537     raeburn  10264:             }
1.538     raeburn  10265:         }
                   10266:         form.allrandompick.value = '';
                   10267:         form.allrandomorder.value = '';
                   10268:         var allmapidxlist = document.cumulativesettings.allmapidx.value;
                   10269:         if ((allmapidxlist != '') && (allmapidxlist != null)) {
                   10270:             var allmapidxs = allmapidxlist.split(',');
                   10271:             for (var i=0; i<allmapidxs.length; i++) {
                   10272:                 var randompick = document.getElementById('randompick_'+allmapidxs[i]);
                   10273:                 var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
                   10274:                 var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
                   10275:                 if ((randompick.checked) && (rpicknum.value != '')) {
                   10276:                     form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
                   10277:                 }
                   10278:                 if (randorder.checked) {
                   10279:                     form.allrandomorder.value += allmapidxs[i]+',';
                   10280:                 }
1.537     raeburn  10281:             }
1.543     raeburn  10282:             form.allrandompick.value = form.allrandompick.value.replace(patt,"");
                   10283:             form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
                   10284:         }
                   10285:         if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
                   10286:             haschanges = 1;
                   10287:         }
                   10288:         if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
                   10289:             haschanges = 1;
                   10290:         }
                   10291:         if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
                   10292:             haschanges = 1;
                   10293:         }
                   10294:         if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
                   10295:             haschanges = 1;
1.537     raeburn  10296:         }
                   10297:     }
1.543     raeburn  10298:     if (doactions == 1) {
1.542     raeburn  10299:         if (numchanges > 0) {
1.603     raeburn  10300:             if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542     raeburn  10301:                 if (remwarnings > 0) {
1.594     damieng  10302:                     if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542     raeburn  10303:                         return false;
                   10304:                     }
                   10305:                 }
1.603     raeburn  10306:                 if (removalinfo > 0) {
                   10307:                     if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
                   10308:                         return false;
                   10309:                     }
                   10310:                 }
1.542     raeburn  10311:                 if (cutwarnings > 0) {
1.594     damieng  10312:                     if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
1.542     raeburn  10313:                         return false;
                   10314:                     }
                   10315:                 }
                   10316:             }
                   10317:             form.submit();
                   10318:             return true;
1.543     raeburn  10319:         }
                   10320:     }
                   10321:     if (dosettings == 1) {
                   10322:         if (haschanges == 1) {
1.542     raeburn  10323:             form.submit();
                   10324:             return true;
                   10325:         }
1.543     raeburn  10326:     }
                   10327:     if ((dosettings == 1) && (doactions == 1)) {
1.594     damieng  10328:         alert("$js_lt{'noor'}");
1.543     raeburn  10329:     } else {
                   10330:         if (dosettings == 1) {
1.594     damieng  10331:             alert("$js_lt{'noch'}");
1.543     raeburn  10332:         } else {
1.594     damieng  10333:             alert("$js_lt{'noac'}");
1.543     raeburn  10334:         }
                   10335:     }
1.538     raeburn  10336:     return false;
                   10337: }
                   10338: 
                   10339: function setClass(value) {
                   10340:     var cutclass = 'LC_docs_cut';
                   10341:     var copyclass = 'LC_docs_copy';
                   10342:     var removeclass = 'LC_docs_remove';
                   10343:     var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
                   10344:     var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
                   10345:     var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
                   10346:     var links = document.getElementsByTagName('a');
                   10347:     for (var i=0; i<links.length; i++) {
                   10348:         var classes = links[i].className;
                   10349:         if (cutreg.test(classes)) {
                   10350:             links[i].className = cutclass;
                   10351:             if (value == 1) {
                   10352:                 links[i].className += " LC_menubuttons_link";
                   10353:             }
                   10354:         } else {
                   10355:             if (copyreg.test(classes)) {
                   10356:                 links[i].className = copyclass;
                   10357:                 if (value == 1) {
                   10358:                     links[i].className += " LC_menubuttons_link";
                   10359:                 } 
                   10360:             } else {
                   10361:                 if (removereg.test(classes)) {
                   10362:                     links[i].className = removeclass;
                   10363:                     if (value == 1) {
                   10364:                         links[i].className += " LC_menubuttons_link";
                   10365:                     }
                   10366:                 }
                   10367:             }
                   10368:         }
                   10369:     }
                   10370:     return;
1.537     raeburn  10371: }
                   10372: 
1.538     raeburn  10373: function setBoxes(value) {
                   10374:     var remidxlist = document.cumulativeactions.allremoveidx.value;
                   10375:     if ((remidxlist != '') && (remidxlist != null)) {
                   10376:         var remidxs = remidxlist.split(',');
                   10377:         for (var i=0; i<remidxs.length; i++) {
                   10378:             if (document.getElementById('remove_'+remidxs[i])) {
                   10379:                 var item = document.getElementById('remove_'+remidxs[i]);
                   10380:                 if (value == 1) {
                   10381:                     item.className = 'LC_docs_remove';
                   10382:                 } else {
                   10383:                     item.className = 'LC_hidden';
                   10384:                 }
                   10385:             }
                   10386:         }
                   10387:     }
                   10388:     var cutidxlist = document.cumulativeactions.allcutidx.value;
                   10389:     if ((cutidxlist != '') && (cutidxlist != null)) {
                   10390:         var cutidxs = cutidxlist.split(',');
                   10391:         for (var i=0; i<cutidxs.length; i++) {
                   10392:             if (document.getElementById('cut_'+cutidxs[i])) {
                   10393:                 var item = document.getElementById('cut_'+cutidxs[i]);
                   10394:                 if (value == 1) {
                   10395:                     item.className = 'LC_docs_cut';
                   10396:                 } else {
                   10397:                     item.className = 'LC_hidden';
                   10398:                 }
                   10399:             }
1.537     raeburn  10400:         }
                   10401:     }
1.538     raeburn  10402:     var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   10403:     if ((copyidxlist != '') && (copyidxlist != null)) {
                   10404:         var copyidxs = copyidxlist.split(',');
                   10405:         for (var i=0; i<copyidxs.length; i++) {
                   10406:             if (document.getElementById('copy_'+copyidxs[i])) {
                   10407:                 var item = document.getElementById('copy_'+copyidxs[i]);
                   10408:                 if (value == 1) {
                   10409:                     item.className = 'LC_docs_copy';
                   10410:                 } else {
                   10411:                     item.className = 'LC_hidden';
                   10412:                 }
                   10413:             }
1.537     raeburn  10414:         }
                   10415:     }
                   10416:     return;
                   10417: }
                   10418: 
1.606     raeburn  10419: function validImportCrsRes() {
                   10420:     var path =  document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
                   10421:     var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
                   10422:     if ((fname == '') || (fname == null)) {
                   10423:         alert("$js_lt{'nofi'}");
                   10424:         return false;
                   10425:     }
                   10426:     var url = '/res/$coursedom/$coursenum/';
                   10427:     if (path && path != '/') {
                   10428:         url += path+'/';
                   10429:     }
                   10430:     if (fname != '') {
                   10431:         url += fname;
                   10432:     }
                   10433:     var title = document.crsresimportform.crsrestitle.value;
1.676     raeburn  10434:     document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606     raeburn  10435:     return true;
                   10436: }
                   10437: 
                   10438: function validateNewRes(caller) {
                   10439:     if (caller == 'single') {
                   10440:         var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value; 
                   10441:         var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
                   10442:         var resname = document.courseresform.newresourcename.value;
                   10443:     }
                   10444: }
                   10445: 
1.611     raeburn  10446: ENDSCRIPT
1.329     droeschl 10447: }
1.457     raeburn  10448: 
1.483     raeburn  10449: sub history_tab_js {
                   10450:     return <<"ENDHIST";
                   10451: function toggleHistoryDisp(choice) {
                   10452:     document.docslogform.docslog.value = choice;
                   10453:     document.docslogform.submit();
                   10454:     return;
                   10455: }
                   10456: 
                   10457: ENDHIST
                   10458: }
                   10459: 
1.484     raeburn  10460: sub inject_data_js {
                   10461:     return <<ENDINJECT;
                   10462: 
                   10463: function injectData(current, hiddenField, name, value) {
                   10464:         currentElement = document.getElementById(hiddenField);
                   10465:         currentElement.name = name;
                   10466:         currentElement.value = value;
                   10467:         current.submit();
                   10468: }
                   10469: 
                   10470: ENDINJECT
                   10471: }
                   10472: 
                   10473: sub dump_switchserver_js {
                   10474:     my @hosts = @_;
1.594     damieng  10475:     my %js_lt = &Apache::lonlocal::texthash(
1.574     raeburn  10476:         dump => 'Copying content to Authoring Space requires switching server.',
1.484     raeburn  10477:         swit => 'Switch server?',
1.594     damieng  10478:     );
                   10479:     my %html_js_lt = &Apache::lonlocal::texthash(
                   10480:         swit => 'Switch server?',
1.709     raeburn  10481:         duco => 'Copying uploaded content to Authoring Space',
1.484     raeburn  10482:         yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
                   10483:         chos => 'Choose server',
                   10484:     );
1.594     damieng  10485:     &js_escape(\%js_lt);
                   10486:     &html_escape(\%html_js_lt);
                   10487:     &js_escape(\%html_js_lt);
1.484     raeburn  10488:     my $role = $env{'request.role'};
                   10489:     my $js = <<"ENDSWJS";
                   10490: <script type="text/javascript">
                   10491: function write_switchserver() {
                   10492:     var server;
                   10493:     if (document.setserver.posshosts.length > 0) {
                   10494:         for (var i=0; i<document.setserver.posshosts.length; i++) {
                   10495:             if (document.setserver.posshosts[i].checked) {
                   10496:                 server = document.setserver.posshosts[i].value;
                   10497:             }
                   10498:        }
                   10499:        opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
                   10500:     }
                   10501:     window.close();
                   10502: }
                   10503: </script>
                   10504: 
                   10505: ENDSWJS
                   10506: 
                   10507:     my $startpage = &Apache::loncommon::start_page('Choose server',$js,
                   10508:                                                    {'only_body' => 1,
                   10509:                                                     'js_ready'  => 1,});
                   10510:     my $endpage = &Apache::loncommon::end_page({'js_ready'  => 1});
                   10511: 
                   10512:     my $hostpicker;
                   10513:     my $count = 0;
                   10514:     foreach my $host (sort(@hosts)) {
                   10515:         my $checked;
                   10516:         if ($count == 0) {
                   10517:             $checked = ' checked="checked"';
                   10518:         }
                   10519:         $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
                   10520:                        $host.'"'.$checked.' />'.$host.'</label>&nbsp;&nbsp;';
                   10521:         $count++;
                   10522:     }
                   10523:     
                   10524:     return <<"ENDSWITCHJS";
                   10525: 
                   10526: function dump_needs_switchserver(url) {
                   10527:     if (url!='' && url!= null) {
1.594     damieng  10528:         if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484     raeburn  10529:             go(url);
                   10530:         }
                   10531:     }
                   10532:     return;
                   10533: }
                   10534: 
                   10535: function choose_switchserver_window() {
                   10536:     newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
                   10537:     newWindow.document.open();
                   10538:     newWindow.document.writeln('$startpage');
1.594     damieng  10539:     newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
                   10540:        '<p>$html_js_lt{'yone'}<\\/p>\\n'+
                   10541:        '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484     raeburn  10542:        '<form name="setserver" method="post" action="" \\/>\\n'+
                   10543:        '$hostpicker\\n'+
                   10544:        '<br \\/><br \\/>\\n'+
1.594     damieng  10545:        '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484     raeburn  10546:        'onclick="write_switchserver();" \\/>\\n'+
                   10547:        '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
                   10548:     newWindow.document.writeln('$endpage');
                   10549:     newWindow.document.close();
                   10550:     newWindow.focus();
                   10551: }
                   10552: 
                   10553: ENDSWITCHJS
                   10554: }
                   10555: 
                   10556: sub makedocslogform {
                   10557:     my ($formelems,$docslog) = @_;
                   10558:     return <<"LOGSFORM";
                   10559:  <form action="/adm/coursedocs" method="post" name="docslogform">
                   10560:    <input type="hidden" name="docslog" value="$docslog" />
                   10561:    $formelems
                   10562:  </form>
                   10563: LOGSFORM
                   10564: }
                   10565: 
                   10566: sub makesimpleeditform {
                   10567:     my ($formelems) = @_;
                   10568:     return <<"SIMPFORM";
                   10569:  <form name="simpleedit" method="post" action="/adm/coursedocs">
                   10570:    <input type="hidden" name="importdetail" value="" />
                   10571:    $formelems
                   10572:  </form>
                   10573: SIMPFORM
                   10574: }
                   10575: 
1.606     raeburn  10576: sub makenewproblem {
                   10577:     my ($r,$coursedom,$coursenum) = @_;
                   10578: # Creating a new problem
                   10579:     my ($redirect,$error);
                   10580:     if ($env{'form.authorrole'}) {
                   10581:         my ($newsubdir,$filename);
                   10582:         if ($env{'form.newsubdir'}) {
                   10583:             if ($env{'form.newsubdirname'} ne '') {
                   10584:                 $newsubdir = $env{'form.newsubdirname'};
1.654     raeburn  10585:             }
1.606     raeburn  10586:         }
                   10587:         if ($env{'form.newresourcename'}) {
                   10588:             $filename = $env{'form.newresourcename'};
                   10589:             $filename =~ s/\.(\d+)(\.\w+)$/$2/;
                   10590:             $filename =~ s/`//g;
                   10591:             $filename =~ s{/\.\./}{_}g;
                   10592:             $filename =~ s/\.+/./g;
                   10593:             $filename =~ s{/+}{_}g;
                   10594:             if ($filename ne '') {
                   10595:                 my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
                   10596:                 if (($ext) && ($ext ne '.problem')) {
                   10597:                     $filename = $name.'.problem';
                   10598:                 } elsif ($ext eq '') {
                   10599:                     $filename .= '.problem';
                   10600:                 }
                   10601:                 my $docroot = $r->dir_config('lonDocRoot');
                   10602:                 my @ids=&Apache::lonnet::current_machine_ids();
                   10603:                 if ($env{'form.authorrole'} eq 'author') {
                   10604:                     if ($env{'user.author'}) {
                   10605:                         if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
                   10606:                             my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
                   10607:                             my $path = $docroot.$url;
                   10608:                             my $subdir = $env{'form.authorpath'};
                   10609:                             $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   10610:                         }
                   10611:                     }
                   10612:                 } elsif ($env{'form.authorrole'} eq 'course') {
                   10613:                     my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   10614:                     if ($chome && grep(/^\Q$chome\E$/,@ids)) {
                   10615:                         my $url = "/priv/$coursedom/$coursenum";
                   10616:                         my $path=$docroot.$url;
                   10617:                         my $subdir = $env{'form.authorpath'};
                   10618:                         $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   10619:                         if ($redirect) {
                   10620:                             my $rightsfile = 'default.rights';
                   10621:                             my $sourcerights = "$path/$rightsfile";
1.709     raeburn  10622:                             &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606     raeburn  10623:                             my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654     raeburn  10624:                             if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
                   10625:                                 if (!-e "$docroot/res/$coursedom") {
                   10626:                                     mkdir("$docroot/res/$coursedom",0755);
1.606     raeburn  10627:                                 }
1.654     raeburn  10628:                                 if (!-e "$docroot/res/$coursedom/$coursenum") {
                   10629:                                     mkdir("$docroot/res/$coursedom/$coursenum",0755);
                   10630:                                 }
                   10631:                                 if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
                   10632:                                     my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   10633:                                     my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606     raeburn  10634:                                 }
                   10635:                             }
1.654     raeburn  10636:                             my $source = $docroot.$redirect;
                   10637:                             if (!-e "$source.meta") {
                   10638:                                 my $cid = $coursedom.'_'.$coursenum;
                   10639:                                 my $now = time;
                   10640:                                 if (open(my $fh,">$source.meta")) {
                   10641:                                     my $author=$env{'environment.firstname'}.' '.
                   10642:                                                $env{'environment.middlename'}.' '.
                   10643:                                                $env{'environment.lastname'}.' '.
                   10644:                                                $env{'environment.generation'};
                   10645:                                     $author =~ s/\s+$//;
                   10646:                                     my $title = $env{'form.newresourcetitle'};
                   10647:                                     $title =~ s/^\s+|\s+$//g;
                   10648:                                     print $fh <<END;
1.606     raeburn  10649: 
                   10650: <abstract></abstract>
                   10651: <author>$author</author>
                   10652: <authorspace>$coursenum:$coursedom</authorspace>
                   10653: <copyright>custom</copyright>
                   10654: <creationdate>$now</creationdate>
                   10655: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
                   10656: <dependencies></dependencies>
                   10657: <domain>$coursedom</domain>
                   10658: <highestgradelevel>0</highestgradelevel>
                   10659: <keywords></keywords>
                   10660: <language>notset </language>
                   10661: <lastrevisiondate>$now</lastrevisiondate>
                   10662: <lowestgradelevel>0</lowestgradelevel>
                   10663: <mime>problem</mime>
                   10664: <modifyinguser>$coursenum:$coursedom</modifyinguser>
                   10665: <notes></notes>
                   10666: <obsolete></obsolete>
                   10667: <obsoletereplacement></obsoletereplacement>
                   10668: <owner>$coursenum:$coursedom</owner>
                   10669: <sourceavail></sourceavail>
                   10670: <standards></standards>
                   10671: <subject></subject>
                   10672: <title>$title</title>
                   10673: END
1.654     raeburn  10674:                                     close($fh);
1.606     raeburn  10675:                                 }
                   10676:                             }
                   10677:                         }
                   10678:                     }
                   10679:                 } else {
                   10680:                     my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
                   10681:                     my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
                   10682:                     if (grep(/^\Q$rolehome\E$/,@ids)) {
                   10683:                         my $now = time;
                   10684:                         if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
                   10685:                             my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
                   10686:                             if (($start <= $now) && (($end == 0) || ($end >= $now))) { 
                   10687:                                 my $url = "/priv/$audom/$auname";  
                   10688:                                 my $path = $r->dir_config('lonDocRoot').$url;
                   10689:                                 my $subdir = $env{'form.authorpath'};
                   10690:                                 $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   10691:                             }
                   10692:                         }
                   10693:                     }
                   10694:                 }
                   10695:             }
                   10696:         }
                   10697:     }
                   10698:     return ($redirect,$error);
                   10699: }
                   10700: 
                   10701: sub finishnewprob {
1.654     raeburn  10702:     my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607     raeburn  10703:     unless (-d $path) {
                   10704:         unless (mkdir($path,02770)) {
                   10705:             return;
                   10706:         }
                   10707:     }
1.606     raeburn  10708:     my $redirect;
                   10709:     if ($subdir ne '/') {
                   10710:         $subdir = &cleandir($subdir);
                   10711:         if (($subdir ne '') && (-d "$path/$subdir")) {
                   10712:             $path .= "/$subdir";
                   10713:             $url .= "/$subdir";
                   10714:         }
                   10715:     }
                   10716:     my $dest;
                   10717:     if ($newsubdir ne '') {
                   10718:         $newsubdir = &cleandir($newsubdir);
                   10719:     }
                   10720:     if ($newsubdir ne '') {
                   10721:         if (-d "$path/$newsubdir") {
                   10722:             $dest = "$path/$newsubdir/$filename";
                   10723:         } else {
                   10724:             my $dirok;
                   10725:             unless (-e "$path/$newsubdir") {
                   10726:                 if (mkdir("$path/$newsubdir",02770)) {
                   10727:                     if (chmod(02770,"$path/$newsubdir")) {
                   10728:                         $dirok = 1;
                   10729:                     }
                   10730:                 }
                   10731:             }
                   10732:             if ($dirok) {
                   10733:                 $dest = "$path/$newsubdir/$filename";
                   10734:             }
                   10735:         }
                   10736:         if (($dest ne '') && (!-e $dest)) {
                   10737:             $redirect = "$url/$newsubdir/$filename";
                   10738:         }
                   10739:     } else {
                   10740:         $dest = "$path/$filename";
                   10741:         if (($dest ne '') && (!-e $dest)) {
                   10742:             $redirect = "$url/$filename";
                   10743:         }
                   10744:     }
1.654     raeburn  10745:     if ((!-e $dest) && ($context ne 'upload')) {
                   10746:         my $template = $env{'form.template'};
                   10747:         my $copyfrom;
                   10748:         if ($template ne '') {
                   10749:             my %templates;
                   10750:             my @files = &Apache::lonhomework::get_template_list('problem');
                   10751:             foreach my $poss (@files) {
                   10752:                 if (ref($poss) eq 'ARRAY') {
                   10753:                     if ($template eq $poss->[0]) {
                   10754:                         $templates{$template} = 1;
                   10755:                         last;
                   10756:                     }
                   10757:                 }
                   10758:             }
                   10759:             if ($templates{$template}) {
                   10760:                 $copyfrom = $template;
                   10761:             }
                   10762:         }
                   10763:         if ($filename =~ /\.problem$/) {
                   10764:             unless ($copyfrom) {
                   10765:                 $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
                   10766:             }
                   10767:             &File::Copy::copy($copyfrom,$dest);
                   10768:         }
                   10769:     }
1.606     raeburn  10770:     return $redirect;
                   10771: }
                   10772: 
                   10773: sub cleandir {
                   10774:     my ($dir) = @_;
                   10775:     $dir =~ s/^\s+//;
                   10776:     $dir =~ s/\s+$//;
                   10777:     $dir =~ s/\.+//g;
                   10778:     $dir =~ s/[\#\?&%\":]//g;
                   10779:     return $dir;
                   10780: }
                   10781: 
1.329     droeschl 10782: 1;
                   10783: __END__
                   10784: 
                   10785: 
                   10786: =head1 NAME
                   10787: 
                   10788: Apache::londocs.pm
                   10789: 
                   10790: =head1 SYNOPSIS
                   10791: 
                   10792: This is part of the LearningOnline Network with CAPA project
                   10793: described at http://www.lon-capa.org.
                   10794: 
                   10795: =head1 SUBROUTINES
                   10796: 
                   10797: =over
                   10798: 
                   10799: =item %help=()
                   10800: 
                   10801: Available help topics
                   10802: 
                   10803: =item mapread()
                   10804: 
1.344     bisitz   10805: Mapread read maps into LONCAPA::map:: global arrays
1.329     droeschl 10806: @order and @resources, determines status
                   10807: sets @order - pointer to resources in right order
                   10808: sets @resources - array with the resources with correct idx
                   10809: 
                   10810: =item authorhosts()
                   10811: 
                   10812: Return hash with valid author names
                   10813: 
                   10814: =item clean()
                   10815: 
                   10816: =item dumpcourse()
                   10817: 
                   10818:     Actually dump course
                   10819: 
                   10820: =item group_import()
                   10821: 
                   10822:     Imports the given (name, url) resources into the course
                   10823:     coursenum, coursedom, and folder must precede the list
                   10824: 
                   10825: =item breadcrumbs()
                   10826: 
                   10827: =item log_docs()
                   10828: 
                   10829: =item docs_change_log()
                   10830: 
                   10831: =item update_paste_buffer()
                   10832: 
                   10833: =item print_paste_buffer()
                   10834: 
                   10835: =item do_paste_from_buffer()
                   10836: 
1.538     raeburn  10837: =item do_buffer_empty() 
                   10838: 
                   10839: =item clear_from_buffer()
                   10840: 
1.492     raeburn  10841: =item get_newmap_url()
                   10842: 
                   10843: =item dbcopy()
                   10844: 
                   10845: =item uniqueness_check()
                   10846: 
                   10847: =item contained_map_check()
                   10848: 
                   10849: =item url_paste_fixups()
                   10850: 
                   10851: =item apply_fixups()
                   10852: 
                   10853: =item copy_dependencies()
                   10854: 
1.329     droeschl 10855: =item update_parameter()
                   10856: 
                   10857: =item handle_edit_cmd()
                   10858: 
                   10859: =item editor()
                   10860: 
                   10861: =item process_file_upload()
                   10862: 
                   10863: =item process_secondary_uploads()
                   10864: 
                   10865: =item is_supplemental_title()
                   10866: 
                   10867: =item entryline()
                   10868: 
                   10869: =item tiehash()
                   10870: 
                   10871: =item untiehash()
                   10872: 
                   10873: =item checkonthis()
                   10874: 
                   10875: check on this
                   10876: 
                   10877: =item verifycontent()
                   10878: 
                   10879: Verify Content
                   10880: 
1.636     raeburn  10881: =item devalidateversioncache() 
                   10882: 
                   10883: =item checkversions()
1.329     droeschl 10884: 
                   10885: Check Versions
                   10886: 
                   10887: =item mark_hash_old()
                   10888: 
                   10889: =item is_hash_old()
                   10890: 
                   10891: =item changewarning()
                   10892: 
                   10893: =item init_breadcrumbs()
                   10894: 
                   10895: Breadcrumbs for special functions
                   10896: 
1.484     raeburn  10897: =item create_list_elements()
                   10898: 
                   10899: =item create_form_ul()
                   10900: 
                   10901: =item startContentScreen() 
                   10902: 
                   10903: =item endContentScreen()
                   10904: 
                   10905: =item supplemental_base()
                   10906: 
                   10907: =item embedded_form_elems()
                   10908: 
                   10909: =item embedded_destination()
                   10910: 
                   10911: =item return_to_editor()
                   10912: 
                   10913: =item decompression_info()
                   10914: 
                   10915: =item decompression_phase_one()
                   10916: 
                   10917: =item decompression_phase_two()
                   10918: 
                   10919: =item remove_archive()
                   10920: 
                   10921: =item generate_admin_menu()
                   10922: 
                   10923: =item generate_edit_table()
                   10924: 
                   10925: =item editing_js()
                   10926: 
                   10927: =item history_tab_js()
                   10928: 
                   10929: =item inject_data_js()
                   10930: 
                   10931: =item dump_switchserver_js()
                   10932: 
1.485     raeburn  10933: =item resize_scrollbox_js()
1.484     raeburn  10934: 
                   10935: =item makedocslogform()
                   10936: 
1.485     raeburn  10937: =item makesimpleeditform()
                   10938: 
1.329     droeschl 10939: =back
                   10940: 
                   10941: =cut

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