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

1.329     droeschl    1: # The LearningOnline Network
                      2: # Documents
                      3: #
1.672   ! raeburn     4: # $Id: londocs.pm,v 1.671 2020/07/01 20:08:53 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.645     raeburn    48: use Apache::lonparmset();
1.651     raeburn    49: use Apache::loncourserespicker();
1.329     droeschl   50: use HTML::Entities;
1.488     raeburn    51: use HTML::TokeParser;
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;
                     94:     } else {
                     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;
                    106:     foreach my $key (keys(%env)) {
                    107: 	if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
                    108: 	    my $role=$1;
                    109: 	    my $realm=$2;
                    110: 	    my ($start,$end)=split(/\./,$env{$key});
                    111: 	    if (($start) && ($start>time)) { next; }
                    112: 	    if (($end) && (time>$end)) { next; }
                    113: 	    my ($ca,$cd);
                    114: 	    if ($1 eq 'au') {
                    115: 		$ca=$env{'user.name'};
                    116: 		$cd=$env{'user.domain'};
                    117: 	    } else {
                    118: 		($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
                    119: 	    }
                    120: 	    my $allowed=0;
                    121: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
                    122: 	    my @ids=&Apache::lonnet::current_machine_ids();
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: 
                    186: sub dumpcourse {
                    187:     my ($r) = @_;
1.408     raeburn   188:     my $crstype = &Apache::loncommon::course_type();
1.567     raeburn   189:     my ($starthash,$js);
                    190:     unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    191:         $js = <<"ENDJS";
                    192: <script type="text/javascript">
                    193: // <![CDATA[
                    194: 
                    195: function hide_searching() {
                    196:     if (document.getElementById('searching')) {
                    197:         document.getElementById('searching').style.display = 'none';
                    198:     }
                    199:     return;
                    200: }
                    201: 
                    202: // ]]>
                    203: </script>
                    204: ENDJS
                    205:         $starthash = {
                    206:                          add_entries => {'onload' => "hide_searching();"},
                    207:                      };
                    208:     }
1.568     raeburn   209:     $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
                    210:               &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484     raeburn   211:     $r->print(&startContentScreen('tools'));
1.329     droeschl  212:     my ($home,$other,%outhash)=&authorhosts();
1.484     raeburn   213:     unless ($home) {
                    214:         $r->print(&endContentScreen());
                    215:         return '';
                    216:     }
1.329     droeschl  217:     my $origcrsid=$env{'request.course.id'};
                    218:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    219:     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    220: # Do the dumping
1.484     raeburn   221: 	unless ($outhash{'home_'.$env{'form.authorspace'}}) {
                    222:             $r->print(&endContentScreen());
                    223:             return '';
                    224:         }
1.531     raeburn   225: 	my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329     droeschl  226: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
                    227: 	my $title=$env{'form.authorfolder'};
                    228: 	$title=&clean($title);
1.567     raeburn   229:         my ($navmap,$errormsg) =
                    230:             &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
                    231:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    232:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    233:         my (%maps,%resources,%titles);
                    234:         if (!ref($navmap)) {
                    235:             $r->print($errormsg.
                    236:                       &endContentScreen());
                    237:             return '';
                    238:         } else {
                    239:             &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
                    240:                                                                    'dumpdocs',$cdom,$cnum);
1.329     droeschl  241: 	}
1.567     raeburn   242:         my @todump = &Apache::loncommon::get_env_multiple('form.archive');
                    243:         my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
                    244:             %newcontent,%has_simpleprobs);
                    245:         foreach my $item (sort {$a <=> $b} (@todump)) {
                    246:             my $name = $env{'form.namefor_'.$item};
                    247:             if ($resources{$item}) {
                    248:                 my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
                    249:                 if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
                    250:                     $tocopy{$1} = $name;
                    251:                     $display{$item} = $1;
                    252:                     $lookup{$1} = $item; 
                    253:                 } elsif ($res eq 'lib/templates/simpleproblem.problem') {
                    254:                     $simpleproblems{$item} = {
                    255:                                                 symb => $resources{$item},
                    256:                                                 name => $name,
                    257:                                              };
                    258:                     $display{$item} = 'simpleproblem_'.$name;
                    259:                     if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
                    260:                         $has_simpleprobs{$1}{$id} = $item;
                    261:                     }
                    262:                 } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
                    263:                     my $marker = $1;
                    264:                     my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
                    265:                     $simplepages{$item} = {
                    266:                                             res    => $res,
                    267:                                             title  => $titles{$item},
                    268:                                             db     => $db_name,
                    269:                                             marker => $marker,
                    270:                                             symb   => $resources{$item},
                    271:                                             name   => $name,
                    272:                                           };
                    273:                     $display{$item} = '/'.$res;
                    274:                 }
                    275:             } elsif ($maps{$item}) {
                    276:                 if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
                    277:                     $tocopy{$1} = $name;
                    278:                     $display{$item} = $1;
                    279:                     $lookup{$1} = $item;
                    280:                 }
                    281:             } else {
                    282:                 next;
                    283:             }
                    284:         }
1.329     droeschl  285: 	my $crs='/uploaded/'.$env{'request.course.id'}.'/';
                    286: 	$crs=~s/\_/\//g;
1.567     raeburn   287:         my $mm = new File::MMagic;
                    288:         my $prefix = "/uploaded/$cdom/$cnum/";
                    289:         %replacehash = %tocopy;
                    290:         foreach my $item (sort(keys(%simpleproblems))) {
                    291:             my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
                    292:             $newcontent{$display{$item}} = $content;
                    293:         }
                    294:         my $gateway = Apache::lonhtmlgateway->new('web');
                    295:         foreach my $item (sort(keys(%simplepages))) {
                    296:             if (ref($simplepages{$item}) eq 'HASH') {
                    297:                 my $pagetitle = $simplepages{$item}{'title'};
                    298:                 my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
                    299:                 my %contents;
                    300:                 foreach my $field (keys(%fields)) {
                    301:                     if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
                    302:                         my $name = $1;
                    303:                         my $msg = $fields{$field};
                    304:                         if ($name eq 'webreferences') {
                    305:                             if ($msg =~ m{^https?://}) {
                    306:                                 $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
                    307:                             }
                    308:                         } else {
                    309:                             $msg = &Encode::decode('utf8',$msg);
                    310:                             $msg = $gateway->process_outgoing_html($msg,1);
                    311:                             $contents{$name} = $msg;
                    312:                         }
                    313:                     } elsif ($field eq 'uploaded.photourl') {
                    314:                         my $marker = $simplepages{$item}{marker};
                    315:                         if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
                    316:                             my $filepath = $1;
                    317:                             my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
                    318:                             if ($fname ne '') {
                    319:                                 $fname=~s/\.(\w+)$//;
                    320:                                 my $ext=$1;
                    321:                                 $fname = &clean($fname);
                    322:                                 $fname.='.'.$ext;
                    323:                                 $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
                    324:                                 $replacehash{$filepath} = $relpath.$fname;
                    325:                                 $deps{$item}{$filepath} = 1;
                    326:                             }
                    327:                         }
                    328:                     }
                    329:                 }
                    330:                 $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
                    331:                 $lookup{'/'.$simplepages{$item}{'res'}} = $item;
                    332:                 my $content = '
                    333: <html>
                    334: <head>
                    335: <title>'.$pagetitle.'</title>
                    336: </head>
                    337: <body bgcolor="#ffffff">';
                    338:                 if ($contents{title}) {
                    339:                     $content .= "\n".'<h2>'.$contents{title}.'</h2>';
                    340:                 }
                    341:                 if ($contents{image}) {
                    342:                     $content .= "\n".$contents{image};
                    343:                 }
                    344:                 if ($contents{content}) {
                    345:                     $content .= '
                    346: <div class="LC_Box">
1.577     bisitz    347: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567     raeburn   348: $contents{content}.'
                    349: </div>';
                    350:                 }
                    351:                 if ($contents{webreferences}) {
                    352:                     $content .= ' 
                    353: <div class="LC_Box">
1.577     bisitz    354: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567     raeburn   355: $contents{webreferences}.'
                    356: </div>';
                    357:                 }
                    358:                 $content .= '
                    359: </body>
                    360: </html>
                    361: ';
                    362:                 $newcontent{'/'.$simplepages{$item}{res}} = $content; 
                    363:             }
                    364:         }
                    365: 	foreach my $item (keys(%tocopy)) {
                    366:             unless ($item=~/\.(sequence|page)$/) {
                    367:                 my $currurlpath = $prefix.$item;
                    368:                 my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
                    369:                 &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
                    370:             }
                    371:         }
                    372:         foreach my $num (sort {$a <=> $b} (@todump)) {
                    373:             my $src = $display{$num};
                    374:             next if ($src eq '');
                    375:             my @needcopy = ();
                    376:             if ($replacehash{$src}) {
                    377:                 push(@needcopy,$src);
                    378:                 if (ref($deps{$num}) eq 'HASH') {
                    379:                     foreach my $dep (sort(keys(%{$deps{$num}}))) {
                    380:                         if ($replacehash{$dep}) {
                    381:                             push(@needcopy,$dep);
                    382:                         }
                    383:                     }
                    384:                 }
                    385:             } elsif ($src =~ /^simpleproblem_/) {
                    386:                 push(@needcopy,$src);
                    387:             }
                    388:             next if (@needcopy == 0);
                    389:             my ($result,$depresult);
                    390:             for (my $i=0; $i<@needcopy; $i++) {
                    391:                 my $item = $needcopy[$i];
                    392:                 my $newfilename;
                    393:                 if ($simpleproblems{$num}) {
                    394:                     $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
                    395:                 } else {
                    396: 	            $newfilename=$title.'/'.$replacehash{$item};
                    397:                 }
                    398: 	        $newfilename=~s/\.(\w+)$//;
                    399: 	        my $ext=$1;
                    400: 	        $newfilename=&clean($newfilename);
                    401: 	        $newfilename.='.'.$ext;
                    402:                 my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); 
                    403:                 if ($newrelpath ne $replacehash{$item}) {
                    404:                     $replacehash{$item} = $newrelpath;
                    405:                 }
                    406: 	        my @dirs=split(/\//,$newfilename);
                    407: 	        my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
                    408: 	        my $makepath=$path;
                    409: 	        my $fail;
                    410:                 my $origin;
                    411: 	        for (my $i=0;$i<$#dirs;$i++) {
                    412: 		    $makepath.='/'.$dirs[$i];
                    413: 		    unless (-e $makepath) {
                    414: 		        unless(mkdir($makepath,0755)) { 
                    415:                             $fail = &mt('Directory creation failed.');
                    416:                         }
                    417: 		    }
                    418: 	        }
                    419:                 if ($i == 0) {
                    420: 	            $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
                    421:                 } else {
                    422:                     $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
                    423:                                   '<span class="LC_fontsize_small" style="font-weight: bold;">'.
                    424:                                   &mt('(dependency)').'</span>: ';
                    425:                 }
                    426:                 if (-e $path.'/'.$newfilename) {
                    427:                     $fail = &mt('Destination already exists -- not overwriting.'); 
                    428: 	        } else {
                    429:                     if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
                    430:                         if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
                    431:                             ($item =~ /^simpleproblem_/)) {
                    432:                             print $fh $newcontent{$item};
                    433:                         } else {
                    434:                             my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
                    435:                             if (-e $fileloc) {
                    436:                                 if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
                    437:                                     if ((($1 eq 'sequence') || ($1 eq 'page')) &&
                    438:                                         (ref($has_simpleprobs{$item}) eq 'HASH')) {
                    439:                                         my %changes = %{$has_simpleprobs{$item}};
                    440:                                         my $content = &Apache::lonclonecourse::rewritefile(
                    441:                      &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                    442:                                                       (%replacehash,$crs => '')
                    443:                                                                                           );
                    444:                                         my $updatedcontent = '';
                    445:                                         my $parser = HTML::TokeParser->new(\$content);
                    446:                                         $parser->attr_encoded(1);
                    447:                                         while (my $token = $parser->get_token) {
                    448:                                             if ($token->[0] eq 'S') {
                    449:                                                 if (($token->[1] eq 'resource') &&
                    450:                                                     ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && 
                    451:                                                     ($changes{$token->[2]->{'id'}})) {
                    452:                                                     my $id = $token->[2]->{'id'};
                    453:                                                     $updatedcontent .= '<'.$token->[1];
                    454:                                                     foreach my $attrib (@{$token->[3]}) {
                    455:                                                         next unless ($attrib =~ /^(src|type|title|id)$/);
                    456:                                                         if ($attrib eq 'src') {
                    457:                                                             my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); 
                    458:                                                             if ($file) {
                    459:                                                                 $updatedcontent .= ' '.$attrib.'="'.$file.'"';
                    460:                                                             } else {
                    461:                                                                 $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; 
                    462:                                                             }
                    463:                                                         } else {
                    464:                                                             $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
                    465:                                                         }
                    466:                                                     }
                    467:                                                     $updatedcontent .= ' />'."\n";
                    468:                                                 } else {
                    469:                                                     $updatedcontent .= $token->[4]."\n";
                    470:                                                 }
                    471:                                              } else {
                    472:                                                  $updatedcontent .= $token->[2];
                    473:                                              }
                    474:                                          }
                    475:                                          print $fh $updatedcontent;
                    476:                                     } else {  
                    477: 		                        print $fh &Apache::lonclonecourse::rewritefile(
                    478:                      &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                    479: 		                                      (%replacehash,$crs => '')
                    480: 							                              );
                    481:                                     }
                    482:                                 } else {
                    483: 		                    print $fh
                    484:                                         &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
                    485: 		                }
                    486:                             } else {
                    487:                                 $fail = &mt('Source does not exist.');  
                    488:                             }
                    489:                         }
                    490:                         $fh->close();
                    491: 	            } else {
                    492: 		        $fail = &mt('Could not write to destination.');
                    493:                     }
                    494: 	        }
                    495:                 my $text;
                    496: 	        if ($fail) {
                    497:                     $text = '<span class="LC_error">'.&mt('fail').('&nbsp;'x3).$fail.'</span>';
                    498: 	        } else {
                    499:                     $text = '<span class="LC_success">'.&mt('ok').'</span>';
                    500:                 }
                    501:                 if ($i == 0) {
                    502:                     $result .= $text;
                    503:                 } else {
                    504:                     $depresult .= $text.'</li>';
                    505: 	        }
                    506:             }
                    507:             $r->print($result);
                    508:             if ($depresult) {
                    509:                 $r->print('<ul>'.$depresult.'</ul>');
                    510:             }
                    511:         }
                    512:     } else {
                    513:         my ($navmap,$errormsg) =
                    514:             &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
                    515:         if (!ref($navmap)) {
                    516:             $r->print($errormsg);
                    517:         } else {
                    518:             $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
                    519:             $r->rflush();
                    520:             my ($preamble,$formname);
                    521:             $formname = 'dumpdoc';
                    522: 	    unless ($home==1) {
                    523: 	        $preamble = '<div class="LC_left_float">'.
                    524: 		            '<fieldset><legend>'.
                    525:                             &mt('Select the Authoring Space').
                    526:                             '</legend><select name="authorspace">';
1.329     droeschl  527: 	    }
1.567     raeburn   528:             my @orderspaces = ();
                    529: 	    foreach my $key (sort(keys(%outhash))) {
                    530:                 if ($key=~/^home_(.+)$/) {
                    531:                     if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
                    532:                         unshift(@orderspaces,$1);
                    533:                     } else {
                    534:                         push(@orderspaces,$1);
                    535:                     }
                    536:                 } 
                    537:             }
1.569     raeburn   538:             if ($home>1) {
                    539:                 $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
                    540:             }
1.567     raeburn   541:             foreach my $user (@orderspaces) {
1.329     droeschl  542: 		if ($home==1) {
1.567     raeburn   543: 		    $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329     droeschl  544: 		} else {
1.567     raeburn   545: 		    $preamble .= '<option value="'.$user.'">'.$user.' - '.
                    546: 			         &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
                    547: 	        }
1.329     droeschl  548: 	    }
1.567     raeburn   549: 	    unless ($home==1) {
                    550: 	        $preamble .= '</select></fieldset></div>'."\n";
1.329     droeschl  551: 	    }
1.567     raeburn   552: 	    my $title=$origcrsdata{'description'};
                    553: 	    $title=~s/[\/\s]+/\_/gs;
1.329     droeschl  554: 	    $title=&clean($title);
1.567     raeburn   555: 	    $preamble .= '<div class="LC_left_float">'.
                    556:                          '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
                    557:                          '<input type="text" size="50" name="authorfolder" value="'.
                    558:                          $title.'" />'.
                    559:                          '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
                    560:             my %uploadedfiles;
                    561: 	    &tiehash();
                    562: 	    foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
                    563: 	        my ($ext)=($file=~/\.(\w+)$/);
                    564: # FIXME Check supplemental here
                    565: 	        my $title=$hash{'title_'.$hash{
                    566: 		                'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
                    567: 	        if (!$title) {
                    568: 		    $title=$file;
                    569: 	        } else {
                    570: 		    $title=~s|/|_|g;
                    571: 	        }
                    572: 	        $title=~s/\.(\w+)$//;
                    573: 	        $title=&clean($title);
                    574: 	        $title.='.'.$ext;
                    575: #	    $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
                    576:                 $uploadedfiles{$file} = $title;
                    577: 	    }
                    578: 	    &untiehash();
                    579:             $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
                    580:                                                                  undef,undef,$preamble,$home,\%uploadedfiles));
                    581:         }
1.329     droeschl  582:     }
1.484     raeburn   583:     $r->print(&endContentScreen());
1.329     droeschl  584: }
                    585: 
1.567     raeburn   586: sub recurse_html {
                    587:     my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
                    588:     return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
                    589:     my (%allfiles,%codebase);
                    590:     if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
                    591:         if (keys(%allfiles)) {
                    592:             foreach my $dependency (keys(%allfiles)) {
                    593:                 next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
                    594:                 my ($depurl,$relfile,$newcontainer);
                    595:                 if ($dependency =~ m{^/}) {
                    596:                     if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
                    597:                         $relfile = $1;
                    598:                         if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
                    599:                             $newcontainer = $1;
                    600:                             next if ($replacehash->{$newcontainer});
                    601:                         }
                    602:                         $depurl = $dependency;
                    603:                     } else {
                    604:                         next;
                    605:                     }
                    606:                 } else {
                    607:                     $relfile = $dependency;
                    608:                     $depurl = $currurlpath;
1.630     raeburn   609:                     $depurl =~ s{[^/]+$}{};
1.567     raeburn   610:                     $depurl .= $dependency;
1.630     raeburn   611:                     ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567     raeburn   612:                 }
                    613:                 next if ($relfile eq '');
                    614:                 my $newname = $replacehash->{$container};
                    615:                 $newname =~ s{[^/]+$}{};
                    616:                 $replacehash->{$newcontainer} = $newname.$relfile;
                    617:                 $deps->{$item}{$newcontainer} = 1;
                    618:                 my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});  
                    619:                 my $depfile = &Apache::lonnet::filelocation('',$depurl);
                    620:                 my $type = $mm->checktype_filename($depfile);
                    621:                 if ($type eq 'text/html') {
                    622:                     &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
                    623:                 }
                    624:             }
                    625:         }
                    626:     }
                    627:     return;
                    628: }
                    629: 
1.329     droeschl  630: sub group_import {
1.598     raeburn   631:     my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529     raeburn   632:     my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
                    633:         %removeparam,$importuploaded,$fixuperrors);
                    634:     $allmaps = {};
1.329     droeschl  635:     while (@files) {
                    636: 	my ($name, $url, $residx) = @{ shift(@files) };
1.344     bisitz    637:         if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329     droeschl  638: 	     && ($caller eq 'londocs')
                    639: 	     && (!&Apache::lonnet::stat_file($url))) {
1.364     bisitz    640: 
1.329     droeschl  641:             my $errtext = '';
                    642:             my $fatal = 0;
                    643:             my $newmapstr = '<map>'."\n".
                    644:                             '<resource id="1" src="" type="start"></resource>'."\n".
                    645:                             '<link from="1" to="2" index="1"></link>'."\n".
                    646:                             '<resource id="2" src="" type="finish"></resource>'."\n".
                    647:                             '</map>';
                    648:             $env{'form.output'}=$newmapstr;
                    649:             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                    650:                                                 'output',$1.$2);
1.534     raeburn   651:             if ($result !~ m{^/uploaded/}) {
1.329     droeschl  652:                 $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
                    653:                 $fatal = 2;
                    654:             }
                    655:             if ($fatal) {
                    656:                 return ($errtext,$fatal);
                    657:             }
                    658:         }
                    659: 	if ($url) {
1.626     raeburn   660:             if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598     raeburn   661:                 $url = $1;
                    662:                 my $marker = $2;
                    663:                 my $info = $3;
1.604     raeburn   664:                 my ($toolid,%toolhash,%toolsettings);
1.642     raeburn   665:                 my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598     raeburn   666:                 my @toolinfo = split(/:/,$info);
                    667:                 if ($residx) {
1.604     raeburn   668:                     %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598     raeburn   669:                     $toolid = $toolsettings{'id'};
                    670:                 } else {
1.604     raeburn   671:                     $toolid = shift(@toolinfo);
1.598     raeburn   672:                 }
                    673:                 $toolid =~ s/\D//g;
1.604     raeburn   674:                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645     raeburn   675:                  $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
                    676:                  $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624     raeburn   677:                 foreach my $item (@extras) {
                    678:                     $toolhash{$item} = &unescape($toolhash{$item});
                    679:                 }
1.645     raeburn   680:                 if ($folder =~ /^supplemental/) {
1.648     raeburn   681:                     delete($toolhash{'gradable'});
                    682:                 } else {
                    683:                     $toolhash{'gradable'} =~ s/\D+//g;
1.645     raeburn   684:                 }
1.598     raeburn   685:                 if (ref($ltitoolsref) eq 'HASH') {
                    686:                     if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
1.643     raeburn   687:                         my @deleted;
1.598     raeburn   688:                         $toolhash{'id'} = $toolid;
1.628     raeburn   689:                         if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
                    690:                             ($toolhash{'target'} eq 'window')) {
1.604     raeburn   691:                             if ($toolhash{'target'} eq 'window') {
                    692:                                 foreach my $item ('width','height') {
                    693:                                     $toolhash{$item} =~ s/^\s+//;
                    694:                                     $toolhash{$item} =~ s/\s+$//;
1.624     raeburn   695:                                     if ($toolhash{$item} =~ /\D/) {
                    696:                                         delete($toolhash{$item});
                    697:                                         if ($residx) {
                    698:                                             if ($toolsettings{$item}) {
                    699:                                                 push(@deleted,$item);
                    700:                                             }
                    701:                                         }
                    702:                                     }
1.604     raeburn   703:                                 }
                    704:                             }
                    705:                         } elsif ($residx) {
                    706:                             $toolhash{'target'} = $toolsettings{'target'};
                    707:                             if ($toolhash{'target'} eq 'window') {
1.630     raeburn   708:                                 foreach my $item ('width','height') {
1.624     raeburn   709:                                     $toolhash{$item} = $toolsettings{$item};
                    710:                                 }
1.604     raeburn   711:                             }
                    712:                         } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
                    713:                             $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
                    714:                             if ($toolhash{'target'} eq 'window') {
                    715:                                 $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
                    716:                                 $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
                    717:                             }
                    718:                         }
1.598     raeburn   719:                         if ($toolhash{'target'} eq 'iframe') {
1.624     raeburn   720:                             foreach my $item ('width','height','linktext','explanation') {
                    721:                                 delete($toolhash{$item});
                    722:                                 if ($residx) {
                    723:                                     if ($toolsettings{$item}) {
                    724:                                         push(@deleted,$item);
                    725:                                     }
1.604     raeburn   726:                                 }
                    727:                             }
1.628     raeburn   728:                         } elsif ($toolhash{'target'} eq 'tab') {
                    729:                             foreach my $item ('width','height') {
                    730:                                 delete($toolhash{$item});
                    731:                                 if ($residx) {
                    732:                                     if ($toolsettings{$item}) {
                    733:                                         push(@deleted,$item);
                    734:                                     }
                    735:                                 }
                    736:                             }
1.604     raeburn   737:                         }
                    738:                         if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624     raeburn   739:                             foreach my $item ('label','title','linktext','explanation') {
                    740:                                 my $crsitem;
                    741:                                 if (($item eq 'label') || ($item eq 'title')) {
                    742:                                     $crsitem = 'crs'.$item;
                    743:                                 } else {
                    744:                                     $crsitem = $item;
                    745:                                 }
1.604     raeburn   746:                                 if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624     raeburn   747:                                     $toolhash{$crsitem} =~ s/^\s+//;
                    748:                                     $toolhash{$crsitem} =~ s/\s+$//;
                    749:                                     if ($toolhash{$crsitem} eq '') {
                    750:                                         delete($toolhash{$crsitem});
1.604     raeburn   751:                                     }
                    752:                                 } else {
1.624     raeburn   753:                                     delete($toolhash{$crsitem});
1.604     raeburn   754:                                 }
1.624     raeburn   755:                                 if (($residx) && (exists($toolsettings{$crsitem}))) {
                    756:                                     unless (exists($toolhash{$crsitem})) {
                    757:                                         push(@deleted,$crsitem);
1.604     raeburn   758:                                     }
                    759:                                 }
1.598     raeburn   760:                             }
                    761:                         }
1.643     raeburn   762:                         if ($toolhash{'passback'}) {
                    763:                             my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                    764:                             $toolhash{'gradesecret'} = $gradesecret;
                    765:                             $toolhash{'gradesecretdate'} = time;
                    766:                         }
                    767:                         if ($toolhash{'roster'}) {
                    768:                             my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                    769:                             $toolhash{'rostersecret'} = $rostersecret;
                    770:                             $toolhash{'rostersecretdate'} = time;
                    771:                         }
1.645     raeburn   772:                         my $changegradable;
                    773:                         if (($residx) && ($folder =~ /^default/)) {
1.648     raeburn   774:                             if ($toolsettings{'gradable'}) {
                    775:                                 unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1.645     raeburn   776:                                     push(@deleted,'gradable');
                    777:                                     $changegradable = 1;
                    778:                                 }
1.648     raeburn   779:                             } elsif ($toolhash{'gradable'}) {
                    780:                                 $changegradable = 1;
                    781:                             }
                    782:                             if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645     raeburn   783:                                 $changegradable = 1;
1.648     raeburn   784:                                 if ($toolsettings{'gradable'}) {
                    785:                                     $toolhash{'gradable'} = 1;
                    786:                                 }
1.645     raeburn   787:                             }
                    788:                         }
1.598     raeburn   789:                         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604     raeburn   790:                         if ($putres eq 'ok') {
                    791:                             if (@deleted) {
                    792:                                 &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.645     raeburn   793:                             }
                    794:                             if (($changegradable) && ($folder =~ /^default/)) {
                    795:                                 my $val;
                    796:                                 if ($toolhash{'gradable'}) {
                    797:                                     $val = 'yes';
                    798:                                 } else {
                    799:                                     $val = 'no';
                    800:                                 }
                    801:                                 &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
                    802:                                                               'string_yesno');
                    803:                                 &remember_parms($residx,'gradable','set',$val);
                    804:                             }
                    805:                         } else {
                    806:                             return (&mt('Failed to save update to external tool.'),1);
1.604     raeburn   807:                         }
1.598     raeburn   808:                     }
                    809:                 }
                    810:             }
1.529     raeburn   811:             if (($caller eq 'londocs') &&
                    812:                 ($folder =~ /^default/)) {
1.534     raeburn   813:                 if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529     raeburn   814:                     my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
                    815:                     my $cid = $coursedom.'_'.$coursenum;
                    816:                     $allmaps =
                    817:                         &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                    818:                                                              $chome,$cid);
                    819:                     $donechk = 1;
                    820:                 }
                    821:                 if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627     raeburn   822:                     &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
                    823:                                         \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529     raeburn   824:                     $importuploaded = 1;
                    825:                 } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
                    826:                     next if ($allmaps->{$url});
                    827:                 }
                    828:             }
1.344     bisitz    829: 	    if (!$residx
1.329     droeschl  830: 		|| defined($LONCAPA::map::zombies[$residx])) {
                    831: 		$residx = &LONCAPA::map::getresidx($url,$residx);
                    832: 		push(@LONCAPA::map::order, $residx);
                    833: 	    }
                    834: 	    my $ext = 'false';
                    835: 	    if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
                    836: 	    $name = &LONCAPA::map::qtunescape($name);
1.534     raeburn   837:             if ($name eq '') {
1.538     raeburn   838:                 $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534     raeburn   839:             }
                    840:             if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
                    841:                 my $filepath = $1;
                    842:                 my $fname = $name;
                    843:                 if ($fname =~ /^\W+$/) {
                    844:                     $fname = 'web';
                    845:                 } else {
                    846:                     $fname =~ s/\W/_/g;
                    847:                 }
1.599     damieng   848:                 if (length($fname) > 15) {
1.534     raeburn   849:                     $fname = substr($fname,0,14);
                    850:                 }
                    851:                 my $initialtext = &mt('Replace with your own content.');
                    852:                 my $newhtml = <<END;
1.545     raeburn   853: <html>
1.534     raeburn   854: <head>
                    855: <title>$name</title>
                    856: </head>
                    857: <body bgcolor="#ffffff">
                    858: $initialtext
                    859: </body>
                    860: </html>
                    861: END
                    862:                 $env{'form.output'}=$newhtml;
1.630     raeburn   863:                 my $result =
1.534     raeburn   864:                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                    865:                                                           'output',
                    866:                                                           "$filepath/$residx/$fname.html");
                    867:                 if ($result =~ m{^/uploaded/}) {
                    868:                     $url = $result;
                    869:                     if ($filepath =~ /^supplemental/) {
                    870:                         $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                    871:                                 $env{'user.domain'}.'___&&&___'.$name;
                    872:                     }
                    873:                 } else {
                    874:                     return (&mt('Failed to save new web page.'),1);
                    875:                 }
                    876:             }
1.538     raeburn   877:             $url  = &LONCAPA::map::qtunescape($url);
1.344     bisitz    878: 	    $LONCAPA::map::resources[$residx] =
1.329     droeschl  879: 		join(':', ($name, $url, $ext, 'normal', 'res'));
                    880: 	}
                    881:     }
1.529     raeburn   882:     if ($importuploaded) {
                    883:         my %import_errors;
                    884:         my %updated = (
                    885:                           removefrommap => \%removefrommap,
                    886:                           removeparam   => \%removeparam,
                    887:                       );
1.533     raeburn   888:         my ($result,$msgsarray,$lockerror) = 
                    889:             &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529     raeburn   890:         if (keys(%import_errors) > 0) {
1.530     raeburn   891:             $fixuperrors =
1.529     raeburn   892:                 '<p span class="LC_warning">'."\n".
                    893:                 &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".
                    894:                 '<ul>'."\n";
                    895:             foreach my $key (sort(keys(%import_errors))) {
                    896:                 $fixuperrors .= '<li>'.$key.'</li>'."\n";
                    897:             }
                    898:             $fixuperrors .= '</ul></p>'."\n";
                    899:         }
1.533     raeburn   900:         if (ref($msgsarray) eq 'ARRAY') {
                    901:             if (@{$msgsarray} > 0) {
                    902:                 $fixuperrors .= '<p class="LC_info">'.
                    903:                                 join('<br />',@{$msgsarray}).
                    904:                                 '</p>';
                    905:             }
                    906:         }
                    907:         if ($lockerror) {
                    908:             $fixuperrors .= '<p class="LC_error">'.
                    909:                             $lockerror.
                    910:                             '</p>';
                    911:         }
1.529     raeburn   912:     }
                    913:     my ($errtext,$fatal) =
                    914:         &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557     raeburn   915:     unless ($fatal) {
                    916:         if ($folder =~ /^supplemental/) {
                    917:             &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561     raeburn   918:             my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                    919:                                             $folder.'.'.$container);
1.557     raeburn   920:         }
                    921:     }
1.529     raeburn   922:     return ($errtext,$fatal,$fixuperrors);
1.329     droeschl  923: }
                    924: 
                    925: sub log_docs {
1.494     raeburn   926:     return &Apache::lonnet::write_log('course','docslog',@_);
1.329     droeschl  927: }
                    928: 
                    929: {
                    930:     my @oldresources=();
                    931:     my @oldorder=();
                    932:     my $parmidx;
                    933:     my %parmaction=();
                    934:     my %parmvalue=();
                    935:     my $changedflag;
                    936: 
                    937:     sub snapshotbefore {
                    938:         @oldresources=@LONCAPA::map::resources;
                    939:         @oldorder=@LONCAPA::map::order;
                    940:         $parmidx=undef;
                    941:         %parmaction=();
                    942:         %parmvalue=();
                    943:         $changedflag=0;
                    944:     }
                    945: 
                    946:     sub remember_parms {
                    947:         my ($idx,$parameter,$action,$value)=@_;
                    948:         $parmidx=$idx;
                    949:         $parmaction{$parameter}=$action;
                    950:         $parmvalue{$parameter}=$value;
                    951:         $changedflag=1;
                    952:     }
                    953: 
                    954:     sub log_differences {
                    955:         my ($plain)=@_;
                    956:         my %storehash=('folder' => $plain,
                    957:                        'currentfolder' => $env{'form.folder'});
                    958:         if ($parmidx) {
                    959:            $storehash{'parameter_res'}=$oldresources[$parmidx];
                    960:            foreach my $parm (keys(%parmaction)) {
                    961:               $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
                    962:               $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
                    963:            }
                    964:         }
                    965:         my $maxidx=$#oldresources;
                    966:         if ($#LONCAPA::map::resources>$#oldresources) {
                    967:            $maxidx=$#LONCAPA::map::resources;
                    968:         }
                    969:         for (my $idx=0; $idx<=$maxidx; $idx++) {
                    970:            if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
                    971:               $storehash{'before_resources_'.$idx}=$oldresources[$idx];
                    972:               $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
                    973:               $changedflag=1;
                    974:            }
                    975:            if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
                    976:               $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
                    977:               $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                    978:               $changedflag=1;
                    979:            }
                    980:         }
                    981: 	$storehash{'maxidx'}=$maxidx;
                    982:         if ($changedflag) { &log_docs(\%storehash); }
                    983:     }
                    984: }
                    985: 
                    986: sub docs_change_log {
1.611     raeburn   987:     my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486     raeburn   988:     my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617     raeburn   989:     my $navmap; 
1.483     raeburn   990:     my $js = '<script type="text/javascript">'."\n".
                    991:              '// <![CDATA['."\n".
                    992:              &Apache::loncommon::display_filter_js('docslog')."\n".
1.606     raeburn   993:              &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622     raeburn   994:                          $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483     raeburn   995:              &history_tab_js()."\n".
1.484     raeburn   996:              &Apache::lonratedt::editscript('simple')."\n".
1.483     raeburn   997:              '// ]]>'."\n".
                    998:              '</script>'."\n";
1.484     raeburn   999:     $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
                   1000:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489     raeburn  1001:     $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484     raeburn  1002:     my %orderhash;
                   1003:     my $container='sequence';
                   1004:     my $pathitem;
1.519     raeburn  1005:     if ($env{'form.folderpath'} =~ /\:1$/) {
1.484     raeburn  1006:         $container='page';
                   1007:     }
1.519     raeburn  1008:     my $folderpath=$env{'form.folderpath'};
                   1009:     if ($folderpath eq '') {
1.617     raeburn  1010:         $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519     raeburn  1011:     }
1.617     raeburn  1012:     undef($navmap);
1.519     raeburn  1013:     $pathitem = '<input type="hidden" name="folderpath" value="'.
                   1014:                 &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484     raeburn  1015:     my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
                   1016:     my $jumpto = $readfile;
                   1017:     $jumpto =~ s{^/}{};
                   1018:     my $tid = 1;
1.489     raeburn  1019:     if ($supplementalflag) {
                   1020:         $tid = 2;
                   1021:     }
1.630     raeburn  1022:     my ($breadcrumbtrail) =
1.509     raeburn  1023:         &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484     raeburn  1024:     $r->print($breadcrumbtrail.
                   1025:               &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
                   1026:               $readfile));
1.329     droeschl 1027:     my %docslog=&Apache::lonnet::dump('nohist_docslog',
                   1028:                                       $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1029:                                       $env{'course.'.$env{'request.course.id'}.'.num'});
                   1030: 
                   1031:     if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
                   1032: 
                   1033:     my %saveable_parameters = ('show' => 'scalar',);
                   1034:     &Apache::loncommon::store_course_settings('docs_log',
                   1035:                                               \%saveable_parameters);
                   1036:     &Apache::loncommon::restore_course_settings('docs_log',
                   1037:                                                 \%saveable_parameters);
                   1038:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452     www      1039: # FIXME: internationalization seems wrong here
1.329     droeschl 1040:     my %lt=('hiddenresource' => 'Resources hidden',
                   1041: 	    'encrypturl'     => 'URL hidden',
                   1042: 	    'randompick'     => 'Randomly pick',
                   1043: 	    'randomorder'    => 'Randomly ordered',
1.645     raeburn  1044:             'gradable'       => 'Grade can be assigned to External Tool',
1.329     droeschl 1045: 	    'set'            => 'set to',
                   1046: 	    'del'            => 'deleted');
1.484     raeburn  1047:     my $filter = &Apache::loncommon::display_filter('docslog')."\n".
                   1048:                  $pathitem."\n".
                   1049:                  '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
                   1050:                  ('&nbsp;'x2).'<input type="submit" value="'.&mt('Display').'" />';
                   1051:     $r->print('<div class="LC_left_float">'.
                   1052:               '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
                   1053:               &makedocslogform($filter,1).
                   1054:               '</fieldset></div><br clear="all" />');
1.329     droeschl 1055:     $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
                   1056:               '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
                   1057:               &mt('After').'</th>'.
                   1058:               &Apache::loncommon::end_data_table_header_row());
                   1059:     my $shown=0;
                   1060:     foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
                   1061: 	if ($env{'form.displayfilter'} eq 'currentfolder') {
                   1062: 	    if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
                   1063: 	}
                   1064:         my @changes=keys(%{$docslog{$id}{'logentry'}});
                   1065:         if ($env{'form.displayfilter'} eq 'containing') {
                   1066: 	    my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
                   1067: 		&Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
                   1068: 	    foreach my $key (@changes) {
                   1069: 		$wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
                   1070: 	    }
1.344     bisitz   1071: 	    if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329     droeschl 1072: 	}
                   1073:         my $count = 0;
                   1074:         my $time =
                   1075:             &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
                   1076:         my $plainname =
                   1077:             &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
                   1078:                                           $docslog{$id}{'exe_udom'});
                   1079:         my $about_me_link =
                   1080:             &Apache::loncommon::aboutmewrapper($plainname,
                   1081:                                                $docslog{$id}{'exe_uname'},
                   1082:                                                $docslog{$id}{'exe_udom'});
                   1083:         my $send_msg_link='';
                   1084:         if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
                   1085:              || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
                   1086:             $send_msg_link ='<br />'.
                   1087:                 &Apache::loncommon::messagewrapper(&mt('Send message'),
                   1088:                                                    $docslog{$id}{'exe_uname'},
                   1089:                                                    $docslog{$id}{'exe_udom'});
                   1090:         }
                   1091:         $r->print(&Apache::loncommon::start_data_table_row());
                   1092:         $r->print('<td>'.$time.'</td>
                   1093:                        <td>'.$about_me_link.
                   1094:                   '<br /><tt>'.$docslog{$id}{'exe_uname'}.
                   1095:                                   ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
                   1096:                   $send_msg_link.'</td><td>'.
                   1097:                   $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488     raeburn  1098:         my $is_supp = 0; 
                   1099:         if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
                   1100:             $is_supp = 1;
                   1101:         }
1.329     droeschl 1102: # Before
                   1103: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1104: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                   1105: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                   1106: 	    if ($oldname ne $newname) {
1.488     raeburn  1107:                 my $shown = &LONCAPA::map::qtescape($oldname);
                   1108:                 if ($is_supp) {
                   1109:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   1110:                 }
                   1111:                 $r->print($shown);
1.329     droeschl 1112: 	    }
                   1113: 	}
                   1114: 	$r->print('<ul>');
                   1115: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1116:             if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488     raeburn  1117:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
                   1118:                 if ($is_supp) {
                   1119:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   1120:                 }
                   1121: 		$r->print('<li>'.$shown.'</li>');
1.329     droeschl 1122: 	    }
                   1123: 	}
                   1124: 	$r->print('</ul>');
                   1125: # After
                   1126:         $r->print('</td><td>');
                   1127: 
                   1128: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1129: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                   1130: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                   1131: 	    if ($oldname ne '' && $oldname ne $newname) {
1.488     raeburn  1132:                 my $shown = &LONCAPA::map::qtescape($newname);
                   1133:                 if ($is_supp) {
                   1134:                     $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
                   1135:                 }
                   1136:                 $r->print($shown);
1.329     droeschl 1137: 	    }
1.364     bisitz   1138: 	}
1.329     droeschl 1139: 	$r->print('<ul>');
                   1140: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1141:             if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488     raeburn  1142:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
                   1143:                 if ($is_supp) {
                   1144:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   1145:                 }
                   1146:                 $r->print('<li>'.$shown.'</li>');
1.329     droeschl 1147: 	    }
                   1148: 	}
                   1149: 	$r->print('</ul>');
                   1150: 	if ($docslog{$id}{'logentry'}{'parameter_res'}) {
                   1151: 	    $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1.645     raeburn  1152: 	    foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329     droeschl 1153: 		if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452     www      1154: # FIXME: internationalization seems wrong here
1.329     droeschl 1155: 		    $r->print('<li>'.
                   1156: 			      &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
                   1157: 				  $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
                   1158: 			      .'</li>');
                   1159: 		}
                   1160: 	    }
                   1161: 	    $r->print('</ul>');
                   1162: 	}
                   1163: # End
                   1164:         $r->print('</td>'.&Apache::loncommon::end_data_table_row());
                   1165:         $shown++;
                   1166:         if (!($env{'form.show'} eq &mt('all')
                   1167:               || $shown<=$env{'form.show'})) { last; }
                   1168:     }
1.484     raeburn  1169:     $r->print(&Apache::loncommon::end_data_table()."\n".
                   1170:               &makesimpleeditform($pathitem)."\n".
                   1171:               '</div></div>');
                   1172:     $r->print(&endContentScreen());
1.329     droeschl 1173: }
                   1174: 
                   1175: sub update_paste_buffer {
1.492     raeburn  1176:     my ($coursenum,$coursedom,$folder) = @_;
1.591     raeburn  1177:     my (@possibles,%removals,%cuts,$output);
1.538     raeburn  1178:     if ($env{'form.multiremove'}) {
                   1179:         $env{'form.multiremove'} =~ s/,$//;
                   1180:         map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
                   1181:     }
                   1182:     if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
                   1183:         if ($env{'form.multicut'}) {
                   1184:             $env{'form.multicut'} =~ s/,$//;
                   1185:             foreach my $item (split(/,/,$env{'form.multicut'})) {
                   1186:                 unless ($removals{$item}) {
                   1187:                     $cuts{$item} = 1;
                   1188:                     push(@possibles,$item.':cut');
                   1189:                 }
                   1190:             }
                   1191:         }
                   1192:         if ($env{'form.multicopy'}) {
                   1193:             $env{'form.multicopy'} =~ s/,$//;
                   1194:             foreach my $item (split(/,/,$env{'form.multicopy'})) {
                   1195:                 unless ($removals{$item} || $cuts{$item}) {
                   1196:                     push(@possibles,$item.':copy'); 
                   1197:                 }
                   1198:             }
                   1199:         }
                   1200:     } elsif ($env{'form.markcopy'}) {
                   1201:         @possibles = split(/,/,$env{'form.markcopy'});
                   1202:     }
1.329     droeschl 1203: 
1.538     raeburn  1204:     return if (@possibles == 0);
1.329     droeschl 1205:     return if (!defined($env{'form.copyfolder'}));
                   1206: 
                   1207:     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   1208: 				    $env{'form.copyfolder'});
1.538     raeburn  1209:     return if ($fatal);
                   1210: 
                   1211:     my %curr_groups = &Apache::longroup::coursegroups();
1.364     bisitz   1212: 
1.538     raeburn  1213: # Retrieve current paste buffer suffixes.
                   1214:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   1215:     my (%pasteurls,@newpaste);
                   1216: 
                   1217: # Construct identifiers for current contents of user's paste buffer
                   1218:     if (@currpaste) {
                   1219:         foreach my $suffix (@currpaste) {
1.667     raeburn  1220:             my $cid = $env{'docs.markedcopy_crs_'.$suffix};
                   1221:             my $url = $env{'docs.markedcopy_url_'.$suffix};
                   1222:             my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
                   1223:             if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
                   1224:                 ($url ne '')) {
                   1225:                 if ($url eq '/res/lib/templates/simpleproblem.problem') {
                   1226:                     $pasteurls{$cid.'_'.$mapidx} = 1;
                   1227:                 } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
                   1228:                     $pasteurls{$url} = 1;
                   1229:                 } else {
1.669     raeburn  1230:                     $pasteurls{$cid.'_'.$url} = 1;
1.667     raeburn  1231:                 }
                   1232:             }
1.538     raeburn  1233:         }
                   1234:     }
                   1235: 
                   1236: # Mark items for copying (skip any items already in user's paste buffer)
                   1237:     my %addtoenv;
1.597     raeburn  1238: 
                   1239:     my @pathitems = split(/\&/,$env{'form.folderpath'});
                   1240:     my @folderconf = split(/\:/,$pathitems[-1]);
1.666     raeburn  1241:     my $ispage = $folderconf[5];
1.597     raeburn  1242: 
1.538     raeburn  1243:     foreach my $item (@possibles) {
                   1244:         my ($orderidx,$cmd) = split(/:/,$item);
                   1245:         next if ($orderidx =~ /\D/);
                   1246:         next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597     raeburn  1247:         my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538     raeburn  1248:         my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
                   1249:         my %denied = &action_restrictions($coursenum,$coursedom,
                   1250:                                           &LONCAPA::map::qtescape($url),
                   1251:                                           $env{'form.folderpath'},\%curr_groups);
                   1252:         next if ($denied{'copy'});
                   1253:         $url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.667     raeburn  1254:         if ($url eq '/res/lib/templates/simpleproblem.problem') {
                   1255:             next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
                   1256:         } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
                   1257:             next if (exists($pasteurls{$url}));
                   1258:         } else {
                   1259:             next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
                   1260:         }
1.538     raeburn  1261:         my ($suffix,$errortxt,$locknotfreed) =
                   1262:             &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591     raeburn  1263:         if ($suffix ne '') {
                   1264:             push(@newpaste,$suffix);
                   1265:         } else {
                   1266:             if ($locknotfreed) {
                   1267:                 return $locknotfreed;
                   1268:             }
1.538     raeburn  1269:         }
                   1270:         if (&is_supplemental_title($title)) {
                   1271:             &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
                   1272: 	    ($title) = &Apache::loncommon::parse_supplemental_title($title);
                   1273:         }
1.329     droeschl 1274: 
1.538     raeburn  1275:         $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
                   1276:         $addtoenv{'docs.markedcopy_url_'.$suffix}   = $url,
                   1277:         $addtoenv{'docs.markedcopy_cmd_'.$suffix}   = $cmd,
                   1278:         $addtoenv{'docs.markedcopy_crs_'.$suffix}   = $env{'request.course.id'};
1.597     raeburn  1279:         $addtoenv{'docs.markedcopy_map_'.$suffix}   = $mapidx;
1.538     raeburn  1280:         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
                   1281:             my $prefix = $1;
                   1282:             my $subdir =$2;
                   1283:             if ($subdir eq '') {
                   1284:                 $subdir = $prefix;
1.492     raeburn  1285:             }
1.538     raeburn  1286:             my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627     raeburn  1287:             &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
                   1288:                                  \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538     raeburn  1289:             if (ref($hierarchy{$url}) eq 'HASH') {
                   1290:                 my ($nested,$nestednames);
                   1291:                 &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
                   1292:                 $nested =~ s/\&$//;
                   1293:                 $nestednames =~ s/\Q___&&&___\E$//;
                   1294:                 if ($nested ne '') {
                   1295:                     $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
                   1296:                 }
                   1297:                 if ($nestednames ne '') {
                   1298:                     $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
                   1299:                 }
1.492     raeburn  1300:             }
                   1301:         }
1.591     raeburn  1302:         if ($locknotfreed) {
                   1303:             $output = $locknotfreed;
                   1304:             last;
                   1305:         }
1.492     raeburn  1306:     }
1.538     raeburn  1307:     if (@newpaste) {
                   1308:         $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
                   1309:     }
1.492     raeburn  1310:     &Apache::lonnet::appenv(\%addtoenv);
1.329     droeschl 1311:     delete($env{'form.markcopy'});
1.591     raeburn  1312:     return $output;
1.329     droeschl 1313: }
                   1314: 
1.492     raeburn  1315: sub recurse_uploaded_maps {
                   1316:     my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
                   1317:     if (ref($hierarchy->{$url}) eq 'HASH') {
                   1318:         my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
                   1319:         my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
                   1320:         my (@uploaded,@names,%shorter);
                   1321:         for (my $i=0; $i<@maps; $i++) {
                   1322:             my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
                   1323:             if ($inner ne '') {
                   1324:                 push(@uploaded,$inner);
                   1325:                 push(@names,&escape($titles[$i]));
                   1326:                 $shorter{$maps[$i]} = $inner;
                   1327:             }
                   1328:         }
                   1329:         $$nestref .= "$dir:".join(',',@uploaded).'&';
                   1330:         $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
                   1331:         foreach my $map (@maps) {
                   1332:             if ($shorter{$map} ne '') {
                   1333:                 &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
                   1334:             }
                   1335:         }
                   1336:     }
                   1337:     return;
                   1338: }
                   1339: 
1.329     droeschl 1340: sub print_paste_buffer {
1.492     raeburn  1341:     my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538     raeburn  1342:     return if (!defined($env{'docs.markedcopies'}));
1.329     droeschl 1343: 
1.538     raeburn  1344:     unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
                   1345:         return if ($env{'docs.markedcopies'} eq '');
1.488     raeburn  1346:     }
                   1347: 
1.538     raeburn  1348:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   1349:     my ($pasteitems,@pasteable);
1.575     raeburn  1350:     my $clipboardcount = 0;
1.488     raeburn  1351: 
1.538     raeburn  1352: # Construct identifiers for current contents of user's paste buffer
                   1353:     foreach my $suffix (@currpaste) {
                   1354:         next if ($suffix =~ /\D/);
                   1355:         my $cid = $env{'docs.markedcopy_crs_'.$suffix};
                   1356:         my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597     raeburn  1357:         my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538     raeburn  1358:         if (($cid =~ /^$match_domain\_$match_courseid$/) &&
                   1359:             ($url ne '')) {
1.575     raeburn  1360:             $clipboardcount ++;
1.538     raeburn  1361:             my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598     raeburn  1362:                 $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538     raeburn  1363:             my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
                   1364:             if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
                   1365:                 $is_external = 1;
1.626     raeburn  1366:             } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598     raeburn  1367:                 $is_exttool = 1;
1.538     raeburn  1368:             }
                   1369:             if ($folder =~ /^supplemental/) {
                   1370:                 $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
                   1371:                 unless ($canpaste) {
                   1372:                     $nopaste = &mt('Paste into Supplemental Content unavailable.');
                   1373:                 }
                   1374:             } else {
                   1375:                 $canpaste = 1;
                   1376:             }
                   1377:             if ($canpaste) {
                   1378:                 if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
                   1379:                     my $srcdom = $1;
                   1380:                     my $srcnum = $2;
                   1381:                     my $rem = $3;
                   1382:                     if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
                   1383:                         $othercourse = 1;
                   1384:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596     raeburn  1385:                             $othercrs = '<br />'.&mt('(from another course)');
1.538     raeburn  1386:                         } else {
                   1387:                             $canpaste = 0;
                   1388:                             $nopaste = &mt('Paste from another course unavailable.'); 
                   1389:                         }
                   1390:                     }
                   1391:                     if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
                   1392:                         my $prefix = $1;
                   1393:                         $parent = $2;
                   1394:                         if ($folder !~ /^\Q$prefix\E/) {
                   1395:                             $areachange = 1;
                   1396:                         }
                   1397:                         $is_uploaded_map = 1;
1.492     raeburn  1398:                     }
1.597     raeburn  1399:                 } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627     raeburn  1400:                          ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596     raeburn  1401:                     if ($cid ne $env{'request.course.id'}) {
                   1402:                         my ($srcdom,$srcnum) = split(/_/,$cid);
                   1403:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627     raeburn  1404:                             if (($is_exttool) && ($srcdom ne $coursedom)) {
                   1405:                                 $canpaste = 0;
                   1406:                                 $nopaste = &mt('Paste from another domain unavailable.');
                   1407:                             } else {
                   1408:                                 $othercrs = '<br />'.&mt('(from another course)');
                   1409:                             }
1.596     raeburn  1410:                         } else {
                   1411:                             $canpaste = 0;
                   1412:                             $nopaste = &mt('Paste from another course unavailable.');
1.629     raeburn  1413:                         }
1.596     raeburn  1414:                     }
1.492     raeburn  1415:                 }
1.596     raeburn  1416:                 if ($canpaste) {
                   1417:                     push(@pasteable,$suffix);
1.629     raeburn  1418:                 }
1.538     raeburn  1419:             }
                   1420:             my $buffer;
1.627     raeburn  1421:             if ($is_external) {
1.538     raeburn  1422:                 $buffer = &mt('External Resource').': '.
                   1423:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
                   1424:                     &LONCAPA::map::qtescape($url).')';
1.627     raeburn  1425:             } elsif ($is_exttool) {
                   1426:                 $buffer = &mt('External Tool').': '.
                   1427:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538     raeburn  1428:             } else {
                   1429:                 my $icon = &Apache::loncommon::icon($extension);
                   1430:                 if ($extension eq 'sequence' &&
                   1431:                     $url =~ m{/default_\d+\.sequence$}x) {
                   1432:                     $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
                   1433:                     $icon .= '/navmap.folder.closed.gif';
                   1434:                 }
1.589     raeburn  1435:                 my $title = $env{'docs.markedcopy_title_'.$suffix};
                   1436:                 if ($title eq '') {
                   1437:                     ($title) = ($url =~ m{/([^/]+)$});
                   1438:                 }
1.538     raeburn  1439:                 $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
                   1440:                           ': '.
                   1441:                           &Apache::loncommon::parse_supplemental_title(
1.589     raeburn  1442:                              &LONCAPA::map::qtescape($title));
1.538     raeburn  1443:             }
                   1444:             $pasteitems .= '<div class="LC_left_float">';
                   1445:             my ($options,$onclick);
                   1446:             if (($canpaste) && (!$areachange) && (!$othercourse) &&
                   1447:                 ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
                   1448:                 if (($is_uploaded_map) ||
                   1449:                     ($url =~ /(bulletinboard|smppg)$/) ||
                   1450:                     ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
                   1451:                     $options = &paste_options($suffix,$is_uploaded_map,$parent);
                   1452:                     $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
                   1453:                 }
                   1454:             }
                   1455:             $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
                   1456:             if ($nopaste) {
                   1457:                  $pasteitems .= $nopaste;   
                   1458:             } else {
                   1459:                 if ($othercrs) {
                   1460:                     $pasteitems .= $othercrs;
                   1461:                 }
                   1462:                 if ($options) {
                   1463:                     $pasteitems .= $options;
1.492     raeburn  1464:                 }
                   1465:             }
1.538     raeburn  1466:             $pasteitems .= '</div>';
                   1467:         }
                   1468:     }
                   1469:     if ($pasteitems eq '') {
                   1470:         &Apache::lonnet::delenv('docs.markedcopies');
                   1471:     }
                   1472:     my ($pasteform,$form_start,$buttons,$form_end);
                   1473:     if ($pasteitems) {
                   1474:         $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541     raeburn  1475:         $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538     raeburn  1476:         if (@pasteable) {
1.575     raeburn  1477:             my $value = &mt('Paste to current folder');
                   1478:             if ($container eq 'page') {
                   1479:                 $value = &mt('Paste to current page');
                   1480:             } 
                   1481:             $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.('&nbsp;'x2);
                   1482:         }
                   1483:         $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.('&nbsp;'x2);
                   1484:         if ($clipboardcount > 1) {
                   1485:             $buttons .=
                   1486:                 '<span style="text-decoration:line-through">'.('&nbsp;'x20).'</span>'.('&nbsp;'x2).
                   1487:                 '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
                   1488:                 ('&nbsp;'x2).
                   1489:                 '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
                   1490:                 ('&nbsp;'x2);
1.492     raeburn  1491:         }
1.575     raeburn  1492:         $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
                   1493:                     '</form>';
1.538     raeburn  1494:     } else {
                   1495:         $pasteitems = &mt('Clipboard is empty');
1.488     raeburn  1496:     }
1.538     raeburn  1497:     $r->print($form_start
                   1498:              .'<fieldset>'
                   1499:              .'<legend>'.&mt('Clipboard').('&nbsp;' x2).$buttons.'</legend>'
                   1500:              .$pasteitems
                   1501:              .'</fieldset>'
                   1502:              .$form_end);
                   1503: }
                   1504: 
                   1505: sub paste_options {
                   1506:     my ($suffix,$is_uploaded_map,$parent) = @_;
                   1507:     my ($copytext,$movetext);
                   1508:     if ($is_uploaded_map) {
                   1509:         $copytext = &mt('Copy to new folder');
                   1510:         $movetext = &mt('Move old');
                   1511:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
                   1512:         $copytext = &mt('Copy to new board');
                   1513:         $movetext = &mt('Move (not posts)');
                   1514:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
                   1515:         $copytext = &mt('Copy to new page');
                   1516:         $movetext = &mt('Move');
1.533     raeburn  1517:     } else {
1.538     raeburn  1518:         $copytext = &mt('Copy to new file');
                   1519:         $movetext = &mt('Move');
                   1520:     }
                   1521:     my $output = '<br />'.
                   1522:                  '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
                   1523:                  '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.('&nbsp;'x 4).
                   1524:                  '<label>'.
                   1525:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
                   1526:                  $copytext.'</label></span>'.('&nbsp;'x2).' '.
                   1527:                  '<span class="LC_nobreak"><label>'.
                   1528:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
                   1529:                  $movetext.'</label></span>';
                   1530:     if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
                   1531:         $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
                   1532:                    '</legend><table border="0">';
                   1533:         my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   1534:         my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
                   1535:         my $lastdir = $parent;
                   1536:         my %depths = (
                   1537:                        $lastdir => 0,
                   1538:                      );
                   1539:         my (%display,%deps);
                   1540:         for (my $i=0; $i<@pastemaps; $i++) {
                   1541:             ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
                   1542:             my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
                   1543:             my @subfolders = split(/,/,$subfolderstr);
                   1544:             $deps{$lastdir} = \@subfolders;
                   1545:             my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
                   1546:             my $depth = $depths{$lastdir} + 1;
                   1547:             my $offset = int($depth * 4);
                   1548:             my $indent = ('&nbsp;' x $offset);
                   1549:             for (my $j=0; $j<@subfolders; $j++) {
                   1550:                 $depths{$subfolders[$j]} = $depth;
                   1551:                 $display{$subfolders[$j]} =
                   1552:                     '<tr><td>'.$indent.$subfoldertitles[$j].'&nbsp;</td>'.
                   1553:                     '<td><label>'.
                   1554:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.('&nbsp;' x2).
                   1555:                     '<label>'.
                   1556:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
                   1557:                     &mt('Move old').'</label>'.
                   1558:                     '</td></tr>';
                   1559:              }
1.492     raeburn  1560:         }
1.538     raeburn  1561:         &recurse_print(\$output,$parent,\%deps,\%display);
                   1562:         $output .= '</table></fieldset>';
1.329     droeschl 1563:     }
1.538     raeburn  1564:     $output .= '</div>';
                   1565:     return $output;
1.488     raeburn  1566: }
                   1567: 
1.492     raeburn  1568: sub recurse_print {
1.538     raeburn  1569:     my ($outputref,$dir,$deps,$display) = @_;
                   1570:     $$outputref .= $display->{$dir}."\n";
1.492     raeburn  1571:     if (ref($deps->{$dir}) eq 'ARRAY') {
                   1572:         foreach my $subdir (@{$deps->{$dir}}) {
1.538     raeburn  1573:             &recurse_print($outputref,$subdir,$deps,$display);
1.492     raeburn  1574:         }
                   1575:     }
                   1576: }
                   1577: 
1.488     raeburn  1578: sub supp_pasteable {
                   1579:     my ($url) = @_;
                   1580:     if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//}) ||
                   1581:         (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
                   1582:         ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
                   1583:         ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598     raeburn  1584:         ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626     raeburn  1585:         ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488     raeburn  1586:         return 1;
                   1587:     }
                   1588:     return;
1.329     droeschl 1589: }
                   1590: 
1.492     raeburn  1591: sub paste_popup_js {
1.594     damieng  1592:     my %html_js_lt = &Apache::lonlocal::texthash(
1.538     raeburn  1593:                                           show => 'Show Options',
                   1594:                                           hide => 'Hide Options',
1.594     damieng  1595:                                         );
                   1596:     my %js_lt = &Apache::lonlocal::texthash(
1.541     raeburn  1597:                                           none => 'No items selected from clipboard.',
1.492     raeburn  1598:                                         );
1.594     damieng  1599:     &html_escape(\%html_js_lt);
                   1600:     &js_escape(\%html_js_lt);
                   1601:     &js_escape(\%js_lt);
1.492     raeburn  1602:     return <<"END";
                   1603: 
1.538     raeburn  1604: function showPasteOptions(suffix) {
                   1605:     document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594     damieng  1606:     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  1607:     return;
                   1608: }
                   1609: 
1.538     raeburn  1610: function hidePasteOptions(suffix) {
                   1611:     document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594     damieng  1612:     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  1613:     return;
                   1614: }
                   1615: 
                   1616: function showOptions(caller,suffix) {
                   1617:     if (document.getElementById('pasteoptionstext_'+suffix)) {
                   1618:         if (caller.checked) {
1.594     damieng  1619:             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  1620:         } else {
                   1621:             document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
                   1622:         }
                   1623:         if (document.getElementById('pasteoptions_'+suffix)) {
                   1624:             document.getElementById('pasteoptions_'+suffix).style.display='none';
                   1625:         }
                   1626:     }
1.492     raeburn  1627:     return;
                   1628: }
                   1629: 
1.541     raeburn  1630: function validateClipboard() {
                   1631:     var numchk = 0;
                   1632:     if (document.pasteform.pasting.length > 1) {
                   1633:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1634:             if (document.pasteform.pasting[i].checked) {
                   1635:                 numchk ++;
                   1636:             }
                   1637:         }
                   1638:     } else {
                   1639:         if (document.pasteform.pasting.type == 'checkbox') {
                   1640:             if (document.pasteform.pasting.checked) {
                   1641:                 numchk ++; 
                   1642:             } 
                   1643:         }
                   1644:     }
                   1645:     if (numchk > 0) { 
                   1646:         return true;
                   1647:     } else {
1.594     damieng  1648:         alert("$js_lt{'none'}");
1.541     raeburn  1649:         return false;
                   1650:     }
                   1651: }
                   1652: 
1.575     raeburn  1653: function checkClipboard() {
                   1654:     if (document.pasteform.pasting.length > 1) {
                   1655:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1656:             document.pasteform.pasting[i].checked = true;
                   1657:         } 
                   1658:     }
                   1659:     return;
                   1660: }
                   1661: 
                   1662: function uncheckClipboard() {
                   1663:     if (document.pasteform.pasting.length >1) {
                   1664:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1665:             document.pasteform.pasting[i].checked = false;
                   1666:         }
                   1667:     }
                   1668:     return;
                   1669: }
                   1670: 
1.492     raeburn  1671: END
                   1672: 
                   1673: }
                   1674: 
1.329     droeschl 1675: sub do_paste_from_buffer {
1.492     raeburn  1676:     my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329     droeschl 1677: 
1.538     raeburn  1678: # Array of items in paste buffer
                   1679:     my (@currpaste,%pastebuffer,%allerrors);
                   1680:     @currpaste = split(/,/,$env{'docs.markedcopies'});
                   1681: 
1.492     raeburn  1682: # Early out if paste buffer is empty
1.538     raeburn  1683:     if (@currpaste == 0) {
1.492     raeburn  1684:         return ();
1.538     raeburn  1685:     } 
                   1686:     map { $pastebuffer{$_} = 1; } @currpaste;
                   1687: 
                   1688: # Array of items selected items to paste
                   1689:     my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
                   1690: 
                   1691: # Early out if nothing selected to paste
                   1692:     if (@reqpaste == 0) {
                   1693:         return();
                   1694:     }
                   1695:     my @topaste;
                   1696:     foreach my $suffix (@reqpaste) {
                   1697:         next if ($suffix =~ /\D/);
                   1698:         next unless (exists($pastebuffer{$suffix}));
                   1699:         push(@topaste,$suffix);
                   1700:     }
                   1701: 
                   1702: # Early out if nothing available to paste
                   1703:     if (@topaste == 0) {
                   1704:         return();
1.329     droeschl 1705:     }
                   1706: 
1.627     raeburn  1707:     my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597     raeburn  1708:         %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538     raeburn  1709: 
                   1710:     foreach my $suffix (@topaste) {
                   1711:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596     raeburn  1712:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597     raeburn  1713:         my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix}); 
1.492     raeburn  1714: # Supplemental content may only include certain types of content
                   1715: # Early out if pasted content is not supported in Supplemental area
1.538     raeburn  1716:         if ($folder =~ /^supplemental/) {
                   1717:             unless (&supp_pasteable($url)) {
                   1718:                 $notinsupp{$suffix} = 1;
                   1719:                 next;
                   1720:             }
1.492     raeburn  1721:         }
1.538     raeburn  1722:         if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
                   1723:             my $srcd = $1;
                   1724:             my $srcn = $2;
1.492     raeburn  1725: # When paste buffer was populated using an active role in a different course
1.538     raeburn  1726: # check for mdc privilege in the course from which the resource was pasted
                   1727:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   1728:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   1729:                     $notincrs{$suffix} = 1;
                   1730:                     next;
                   1731:                 }
1.491     raeburn  1732:             }
1.538     raeburn  1733:             $srcdom{$suffix} = $srcd;
                   1734:             $srcnum{$suffix} = $srcn;
1.597     raeburn  1735:         } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632     raeburn  1736:                  ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
                   1737:                  ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596     raeburn  1738:             my ($srcd,$srcn) = split(/_/,$cid);
                   1739: # When paste buffer was populated using an active role in a different course
                   1740: # check for mdc privilege in the course from which the resource was pasted
                   1741:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   1742:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   1743:                     $notincrs{$suffix} = 1;
                   1744:                     next;
                   1745:                 }
                   1746:             }
1.632     raeburn  1747: # When buffer was populated using an active role in a different course
                   1748: # disallow pasting of External Tool if course is in a different domain.
                   1749:             if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627     raeburn  1750:                 $notindom{$suffix} = 1;
                   1751:                 next;
                   1752:             }
1.596     raeburn  1753:             $srcdom{$suffix} = $srcd;
                   1754:             $srcnum{$suffix} = $srcn;
1.491     raeburn  1755:         }
1.597     raeburn  1756:         $srcmapidx{$suffix} = $mapidx;
1.538     raeburn  1757:         push(@dopaste,$suffix);
                   1758:         if ($url=~/\.(page|sequence)$/) {
                   1759:             $is_map{$suffix} = 1; 
                   1760:         }
                   1761:         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
                   1762:             my $oldprefix = $1;
1.492     raeburn  1763: # When pasting content from Main Content to Supplemental Content and vice versa 
                   1764: # URLs will contain different paths (which depend on whether pasted item is
1.597     raeburn  1765: # a folder/page or a document).
1.538     raeburn  1766:             if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
                   1767:                 $prefixchg{$suffix} = 'docstosupp';
                   1768:             } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
                   1769:                 $prefixchg{$suffix} = 'supptodocs';
                   1770:             }
1.491     raeburn  1771: 
1.492     raeburn  1772: # If pasting an uploaded map, get list of contained uploaded maps.
1.538     raeburn  1773:             if ($env{'docs.markedcopy_nested_'.$suffix}) {
                   1774:                 my @nested;
                   1775:                 my ($type) = ($oldprefix =~ /^(default|supplemental)/);
                   1776:                 my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   1777:                 my @deps = map { /\d+:([\d,]+$)/ } @items;
                   1778:                 foreach my $dep (@deps) {
                   1779:                     if ($dep =~ /,/) {
                   1780:                         push(@nested,split(/,/,$dep));
                   1781:                     } else {
                   1782:                         push(@nested,$dep);
                   1783:                     }
1.492     raeburn  1784:                 }
1.538     raeburn  1785:                 foreach my $item (@nested) {
                   1786:                     if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
                   1787:                         push(@{$marktomove{$suffix}},$type.'_'.$item);
                   1788:                     }
1.492     raeburn  1789:                 }
                   1790:             }
1.488     raeburn  1791:         }
                   1792:     }
                   1793: 
1.538     raeburn  1794: # Early out if nothing available to paste
                   1795:     if (@dopaste == 0) {
                   1796:         return ();
                   1797:     }
                   1798: 
                   1799: # Populate message hash and hashes used for main content <=> supplemental content
                   1800: # changes    
                   1801: 
                   1802:     %msgs = &Apache::lonlocal::texthash (
                   1803:                 notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
                   1804:                 notincrs  => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661     raeburn  1805:                 notindom  => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538     raeburn  1806:                 duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
                   1807:             );
                   1808: 
                   1809:     %before = (
                   1810:                  docstosupp => {
                   1811:                                    map => 'default',
                   1812:                                    doc => 'docs',
                   1813:                                },
                   1814:                  supptodocs => {
                   1815:                                    map => 'supplemental',
                   1816:                                    doc => 'supplemental',
                   1817:                                },
                   1818:               );
                   1819: 
                   1820:     %after = (
                   1821:                  docstosupp => {
                   1822:                                    map => 'supplemental',
                   1823:                                    doc => 'supplemental'
                   1824:                                },
                   1825:                  supptodocs => {
                   1826:                                    map => 'default',
                   1827:                                    doc => 'docs',
                   1828:                                },
                   1829:              );
                   1830: 
                   1831: # Retrieve information about all course maps in main content area 
                   1832: 
                   1833:     my $allmaps = {};
1.660     raeburn  1834:     my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538     raeburn  1835: 
                   1836: # Loop over the items to paste
                   1837:     foreach my $suffix (@dopaste) {
1.329     droeschl 1838: # Maps need to be copied first
1.538     raeburn  1839:         my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
                   1840:             %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597     raeburn  1841:             %newurls,%tomove,%resdatacopy);
1.538     raeburn  1842:         if (ref($marktomove{$suffix}) eq 'ARRAY') {
                   1843:             map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
                   1844:         }
                   1845:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
                   1846:         my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596     raeburn  1847:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); 
1.538     raeburn  1848:         my $oldurl = $url;
                   1849:         if ($is_map{$suffix}) {
1.491     raeburn  1850: # If pasting a map, check if map contains other maps
1.538     raeburn  1851:             my (%hierarchy,%titles);
1.660     raeburn  1852:             if (($folder =~ /^default/) && (!$donechk)) {
                   1853:                 $allmaps =
                   1854:                     &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                   1855:                                                          $env{"course.$env{'request.course.id'}.home"},
                   1856:                                                          $env{'request.course.id'});
                   1857:                 $donechk = 1;
                   1858:             }
1.627     raeburn  1859:             &contained_map_check($url,$folder,$coursenum,$coursedom,
                   1860:                                  \%removefrommap,\%removeparam,\%addedmaps,
                   1861:                                  \%hierarchy,\%titles,$allmaps);
1.538     raeburn  1862:             if ($url=~ m{^/uploaded/}) {
                   1863:                 my $newurl;
                   1864:                 unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   1865:                     ($newurl,my $error) = 
                   1866:                         &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
                   1867:                                         $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   1868:                                         \$title,$allmaps,\%newurls);
                   1869:                     if ($error) {
                   1870:                         $allerrors{$suffix} = $error;
                   1871:                         next;
                   1872:                     }
                   1873:                     if ($newurl ne '') {
                   1874:                         if ($newurl ne $url) {
                   1875:                             if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
                   1876:                                 $newsubdir{$url} = $1;
                   1877:                             }
                   1878:                             $mapchanges{$url} = 1;
1.492     raeburn  1879:                         }
1.538     raeburn  1880:                     }
                   1881:                 }
                   1882:                 if (($srcdom{$suffix} ne $coursedom) ||
                   1883:                     ($srcnum{$suffix} ne $coursenum) ||
                   1884:                     ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
                   1885:                     unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
                   1886:                                               $coursedom,$coursenum,$srcdom{$suffix},
                   1887:                                               $srcnum{$suffix},$allmaps,\%rewrites,
                   1888:                                               \%retitles,\%copies,\%dbcopies,
                   1889:                                               \%zombies,\%params,\%mapmoves,
                   1890:                                               \%mapchanges,\%tomove,\%newsubdir,
1.597     raeburn  1891:                                               \%newurls,\%resdatacopy)) {
1.538     raeburn  1892:                         $mapmoves{$url} = 1;
                   1893:                     }
                   1894:                     $url = $newurl;
                   1895:                 } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
                   1896:                     &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
                   1897:                                       $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   1898:                                       $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
                   1899:                                       \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597     raeburn  1900:                                       \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538     raeburn  1901:                 }
                   1902:             } elsif ($url=~m {^/res/}) {
1.597     raeburn  1903: # published map can only exist once, so remove from paste buffer when done
1.538     raeburn  1904:                 push(@toclear,$suffix);
                   1905: # if pasting published map (main content area only) check map not already in course
                   1906:                 if ($folder =~ /^default/) {
                   1907:                     if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
                   1908:                         $duplicate{$suffix} = 1; 
                   1909:                         next;
1.492     raeburn  1910:                     }
1.491     raeburn  1911:                 }
                   1912:             }
1.538     raeburn  1913:         }
1.627     raeburn  1914:         if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538     raeburn  1915:             my $prefix = $1;
1.648     raeburn  1916:             my $fromothercrs;
1.538     raeburn  1917:             #need to copy the db contents to a new one, unless this is a move.
                   1918:             my %info = (
                   1919:                          src  => $url,
                   1920:                          cdom => $coursedom,
                   1921:                          cnum => $coursenum,
1.596     raeburn  1922:                        );
1.649     raeburn  1923:             if ($prefix eq 'ext.tool') {
1.655     raeburn  1924:                 if ($prefixchg{$suffix} eq 'docstosupp') {
1.649     raeburn  1925:                     $info{'delgradable'} = 1;
                   1926:                 }
                   1927:             }
1.596     raeburn  1928:             if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
                   1929:                 unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
                   1930:                     $fromothercrs = 1;
                   1931:                     $info{'cdom'} = $srcdom{$suffix};
                   1932:                     $info{'cnum'} = $srcnum{$suffix};
                   1933:                 }
                   1934:             }
                   1935:             unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630     raeburn  1936:                 my (%lockerr,$msg);
1.538     raeburn  1937:                 my ($newurl,$result,$errtext) =
                   1938:                     &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
                   1939:                 if ($result eq 'ok') {
                   1940:                     $url = $newurl;
                   1941:                     $title=&mt('Copy of').' '.$title;
                   1942:                 } else {
                   1943:                     if ($prefix eq 'smppg') {
                   1944:                         $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
                   1945:                     } elsif ($prefix eq 'bulletinboard') {
1.565     bisitz   1946:                         $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627     raeburn  1947:                     } elsif ($prefix eq 'ext.tool') {
                   1948:                         $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538     raeburn  1949:                     }
                   1950:                     $results{$suffix} = $result;
                   1951:                     $msgerrs{$suffix} = $msg;
                   1952:                     $lockerrs{$suffix} = $lockerr{$prefix}; 
                   1953:                     next;
                   1954: 	        }
                   1955:                 if ($lockerr{$prefix}) {
                   1956:                     $lockerrs{$suffix} = $lockerr{$prefix};  
1.491     raeburn  1957:                 }
1.489     raeburn  1958:             }
                   1959:         }
1.538     raeburn  1960:         $title = &LONCAPA::map::qtunescape($title);
                   1961:         my $ext='false';
                   1962:         if ($url=~m{^http(|s)://}) { $ext='true'; }
                   1963:         if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
                   1964:             if ($folder !~ /^supplemental/) {
                   1965:                 (undef,undef,$title) =
                   1966:                     &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
                   1967:             }
                   1968:         } else {
                   1969:             if ($folder=~/^supplemental/) {
                   1970:                 $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   1971:                        $env{'user.domain'}.'___&&&___'.$title;
1.491     raeburn  1972:             }
1.533     raeburn  1973:         }
1.491     raeburn  1974: 
                   1975: # For uploaded files (excluding pages/sequences) path in copied file is changed
                   1976: # if paste is from Main to Supplemental (or vice versa), or if pasting between
                   1977: # courses.
                   1978: 
1.538     raeburn  1979:         unless ($is_map{$suffix}) {
                   1980:             my $newidx;
1.492     raeburn  1981: # Now insert the URL at the bottom
1.538     raeburn  1982:             $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   1983:             if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
                   1984:                 my $relpath = $1;
                   1985:                 if ($relpath ne '') {
                   1986:                     my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
                   1987:                     my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
                   1988:                     my $newprefix = $newloc;
                   1989:                     if ($newloc eq 'default') {
                   1990:                         $newprefix = 'docs';
                   1991:                     }
                   1992:                     if ($newdocsdir eq '') {
                   1993:                         $newdocsdir = 'default';
                   1994:                     }
1.630     raeburn  1995:                     if (($prefixchg{$suffix}) ||
                   1996:                         ($srcdom{$suffix} ne $coursedom) ||
1.538     raeburn  1997:                         ($srcnum{$suffix} ne $coursenum) ||
                   1998:                         ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
                   1999:                         my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
                   2000:                         $url =
                   2001:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
                   2002:                                                                &Apache::lonnet::getfile($oldurl));
                   2003:                         if ($url eq '/adm/notfound.html') {
                   2004:                             $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
                   2005:                             next;
                   2006:                         } else {
                   2007:                             my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
                   2008:                             $newsubpath =~ s{/+$}{/};
                   2009:                             $docmoves{$oldurl} = $newsubpath;
                   2010:                         }
1.491     raeburn  2011:                     }
                   2012:                 }
1.597     raeburn  2013:             } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   2014:                 my $template = $1;
                   2015:                 if ($newidx) {
                   2016:                     &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
                   2017:                                           $coursedom,$coursenum,$template,$newidx,"$folder.$container");
                   2018:                 }
1.649     raeburn  2019:             } elsif ($url =~ /ext\.tool$/) {
1.655     raeburn  2020:                 if (($newidx) && ($folder=~/^default/)) {
1.649     raeburn  2021:                     my $marker = (split(m{/},$url))[4];
                   2022:                     my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
                   2023:                     my $val = 'no';
                   2024:                     if ($toolsettings{'gradable'}) {
                   2025:                         $val = 'yes';
                   2026:                     }
                   2027:                     &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
                   2028:                                                   'string_yesno');
                   2029:                     &remember_parms($newidx,'gradable','set',$val);
                   2030:                 }
1.491     raeburn  2031:             }
1.538     raeburn  2032:             $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   2033:                                               ':'.$ext.':normal:res';
                   2034:             push(@LONCAPA::map::order,$newidx);
                   2035: # Store the result
                   2036:             my ($errtext,$fatal) =
                   2037:                 &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   2038:             if ($fatal) {
                   2039:                 $save_err .= $errtext;
                   2040:                 $allresult = 'fail';
                   2041:             }
1.488     raeburn  2042:         }
1.538     raeburn  2043: 
1.597     raeburn  2044: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
                   2045: # resourcedata for simpleproblems copied from another course 
1.538     raeburn  2046:         unless ($allresult eq 'fail') {
                   2047:             my %updated = (
                   2048:                             rewrites      => \%rewrites,
                   2049:                             zombies       => \%zombies,
                   2050:                             removefrommap => \%removefrommap,
                   2051:                             removeparam   => \%removeparam,
                   2052:                             dbcopies      => \%dbcopies,
1.597     raeburn  2053:                             resdatacopy   => \%resdatacopy,
1.538     raeburn  2054:                             retitles      => \%retitles,
                   2055:                           );
                   2056:             my %info = (
                   2057:                            newsubdir => \%newsubdir,
                   2058:                            params    => \%params,
                   2059:                        );
                   2060:             if ($prefixchg{$suffix}) {
                   2061:                 $info{'before'} = $before{$prefixchg{$suffix}};
                   2062:                 $info{'after'} = $after{$prefixchg{$suffix}};
                   2063:             }
                   2064:             my %moves = (
                   2065:                            copies   => \%copies,
                   2066:                            docmoves => \%docmoves,
                   2067:                            mapmoves => \%mapmoves,
                   2068:                         );
                   2069:             (my $result,$msgs{$suffix},my $lockerror) =
                   2070:                 &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
                   2071:                               \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
                   2072:                               $url,'paste');
                   2073:             $lockerrors .= $lockerror;
                   2074:             if ($result eq 'ok') {
                   2075:                 if ($is_map{$suffix}) {
                   2076:                     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   2077:                                                     $folder.'.'.$container);
                   2078:                     if ($fatal) {
                   2079:                         $allresult = 'failread';
                   2080:                     } else {
                   2081:                         if ($#LONCAPA::map::order<1) {
                   2082:                             my $idx=&LONCAPA::map::getresidx();
                   2083:                             if ($idx<=0) { $idx=1; }
                   2084:                             $LONCAPA::map::order[0]=$idx;
                   2085:                             $LONCAPA::map::resources[$idx]='';
                   2086:                         }
                   2087:                         my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   2088:                         $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   2089:                                                           ':'.$ext.':normal:res';
                   2090:                         push(@LONCAPA::map::order,$newidx);
1.492     raeburn  2091: 
                   2092: # Store the result
1.538     raeburn  2093:                         my ($errtext,$fatal) = 
                   2094:                             &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   2095:                         if ($fatal) {
                   2096:                             $save_err .= $errtext;
                   2097:                             $allresult = 'failstore';
                   2098:                         }
                   2099:                     } 
                   2100:                 }
                   2101:                 if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   2102:                      push(@toclear,$suffix);
                   2103:                 }
                   2104:             }
1.492     raeburn  2105:         }
                   2106:     }
1.538     raeburn  2107:     &clear_from_buffer(\@toclear,\@currpaste);
                   2108:     my $msgsarray;
                   2109:     foreach my $suffix (keys(%msgs)) {
                   2110:          if (ref($msgs{$suffix}) eq 'ARRAY') {
                   2111:              $msgsarray .= join(',',@{$msgs{$suffix}});
                   2112:          }
                   2113:     }
                   2114:     return ($allresult,$save_err,$msgsarray,$lockerrors);
                   2115: }
1.533     raeburn  2116: 
1.538     raeburn  2117: sub do_buffer_empty {
                   2118:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   2119:     if (@currpaste == 0) {
                   2120:         return &mt('Clipboard is already empty');
                   2121:     }
                   2122:     my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
                   2123:     if (@toclear == 0) {
                   2124:         return &mt('Nothing selected to clear from clipboard');
                   2125:     }
                   2126:     my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
                   2127:     if ($numdel) {
                   2128:         return &mt('[quant,_1,item] cleared from clipboard',$numdel);
                   2129:     } else {
                   2130:         return &mt('Clipboard unchanged');
1.492     raeburn  2131:     }
1.538     raeburn  2132:     return;
                   2133: }
                   2134: 
                   2135: sub clear_from_buffer {
                   2136:     my ($toclear,$currpaste) = @_;
                   2137:     return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
                   2138:     my %pastebuffer;
                   2139:     map { $pastebuffer{$_} = 1; } @{$currpaste};
                   2140:     my $numdel = 0;
                   2141:     foreach my $suffix (@{$toclear}) {
                   2142:         next if ($suffix =~ /\D/);
                   2143:         next unless (exists($pastebuffer{$suffix}));
                   2144:         my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
                   2145:         if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
                   2146:             delete($pastebuffer{$suffix});
                   2147:             $numdel ++;
                   2148:         }
                   2149:     }
                   2150:     my $newbuffer = join(',',sort(keys(%pastebuffer)));
                   2151:     &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
                   2152:     return $numdel;
1.492     raeburn  2153: }
                   2154: 
                   2155: sub get_newmap_url {
                   2156:     my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
                   2157:         $titleref,$allmaps,$newurls) = @_;
                   2158:     my $newurl;
                   2159:     if ($url=~ m{^/uploaded/}) {
                   2160:         $$titleref=&mt('Copy of').' '.$$titleref;
                   2161:     }
                   2162:     my $now = time;
                   2163:     my $suffix=$$.int(rand(100)).$now;
                   2164:     my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
                   2165:     if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
                   2166:         my $path = $1;
                   2167:         my $prefix = $2;
                   2168:         my $ancestor = $3;
                   2169:         if (length($ancestor) > 10) {
                   2170:             $ancestor = substr($ancestor,-10,10);
                   2171:         }
                   2172:         my $newid;
                   2173:         if ($prefixchg) {
                   2174:             if ($folder =~ /^supplemental/) {
                   2175:                 $prefix =~ s/^default/supplemental/;
                   2176:             } else {
                   2177:                 $prefix =~ s/^supplemental/default/;
                   2178:             }
                   2179:         }
                   2180:         if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   2181:             $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   2182:         } else {
                   2183:             $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
                   2184:         }
                   2185:         my $counter = 0;
                   2186:         my $is_unique = &uniqueness_check($newurl);
                   2187:         if ($folder =~ /^default/) {
                   2188:             if ($allmaps->{$newurl}) {
                   2189:                 $is_unique = 0;
                   2190:             }
                   2191:         }
                   2192:         while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
                   2193:             $counter ++;
                   2194:             $suffix ++;
                   2195:             if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   2196:                 $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   2197:             } else {
                   2198:                 $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
                   2199:             }
                   2200:             $is_unique = &uniqueness_check($newurl);
                   2201:         }
                   2202:         if ($is_unique) {
                   2203:             $newurls->{$newurl} = 1;
                   2204:         } else {
                   2205:             if ($url=~/\.page$/) {
                   2206:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
                   2207:             } else {
                   2208:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
                   2209:             }
                   2210:         }
1.329     droeschl 2211:     }
1.492     raeburn  2212:     return ($newurl);
1.329     droeschl 2213: }
                   2214: 
1.488     raeburn  2215: sub dbcopy {
1.533     raeburn  2216:     my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
                   2217:     my ($url,$result,$errtext);
                   2218:     if (ref($dbref) eq 'HASH') {
1.596     raeburn  2219:         $url = $dbref->{'src'};
1.627     raeburn  2220:         if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533     raeburn  2221:             my $prefix = $1;
1.627     raeburn  2222:             if ($prefix eq 'ext.tool') {
                   2223:                 $prefix = 'exttool';
                   2224:             }
1.533     raeburn  2225:             if (($dbref->{'cdom'} =~ /^$match_domain$/) && 
                   2226:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   2227:                 my $db_name;
                   2228:                 my $marker = (split(m{/},$url))[4];
                   2229:                 $marker=~s/\D//g;
                   2230:                 if ($dbref->{'src'} =~ m{/smppg$}) {
                   2231:                     $db_name =
                   2232:                         &Apache::lonsimplepage::get_db_name($url,$marker,
                   2233:                                                             $dbref->{'cdom'},
                   2234:                                                             $dbref->{'cnum'});
1.627     raeburn  2235:                 } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
                   2236:                     $db_name = 'exttool_'.$marker;
1.533     raeburn  2237:                 } else {
                   2238:                     $db_name = 'bulletinpage_'.$marker;
                   2239:                 }
                   2240:                 my ($suffix,$freedlock,$error) =
                   2241:                     &Apache::lonnet::get_timebased_id($prefix,'num','templated',
                   2242:                                                       $coursedom,$coursenum,
                   2243:                                                       'concat');
                   2244:                 if (!$suffix) {
                   2245:                     if ($prefix eq 'smppg') {
                   2246:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631     raeburn  2247:                     } elsif ($prefix eq 'exttool') {
                   2248:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533     raeburn  2249:                     } else {
1.565     bisitz   2250:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533     raeburn  2251:                     }
                   2252:                     if ($error) {
                   2253:                         $errtext .= '<br />'.$error;
                   2254:                     }
                   2255:                 } else {
                   2256:                     #need to copy the db contents to a new one.
                   2257:                     my %contents=&Apache::lonnet::dump($db_name,
                   2258:                                                        $dbref->{'cdom'},
                   2259:                                                        $dbref->{'cnum'});
                   2260:                     if (exists($contents{'uploaded.photourl'})) {
                   2261:                         my $photo = $contents{'uploaded.photourl'};
                   2262:                         my ($subdir,$fname) =
                   2263:                             ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596     raeburn  2264:                         my $newphoto;
1.533     raeburn  2265:                         if ($fname ne '') {
                   2266:                             my $content = &Apache::lonnet::getfile($photo);
                   2267:                             unless ($content eq '-1') {
                   2268:                                 $env{'form.'.$suffix.'.photourl'} = $content;
                   2269:                                 $newphoto = 
                   2270:                                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
                   2271:                                 delete($env{'form.'.$suffix.'.photourl'});
                   2272:                             }
                   2273:                         }
                   2274:                         if ($newphoto =~ m{^/uploaded/}) {
                   2275:                             $contents{'uploaded.photourl'} = $newphoto;
                   2276:                         }
                   2277:                     }
                   2278:                     $db_name =~ s{_\d*$ }{_$suffix}x;
1.649     raeburn  2279:                     if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
                   2280:                         delete($contents{'gradable'});
                   2281:                     }
1.533     raeburn  2282:                     $result=&Apache::lonnet::put($db_name,\%contents,
                   2283:                                                  $coursedom,$coursenum);
                   2284:                     if ($result eq 'ok') {
1.627     raeburn  2285:                         $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533     raeburn  2286:                     }
                   2287:                 }
                   2288:                 if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559     raeburn  2289:                     $lockerrorsref->{$prefix} =
1.533     raeburn  2290:                         '<div class="LC_error">'.
                   2291:                         &mt('There was a problem removing a lockfile.');
                   2292:                     if ($prefix eq 'smppg') {
1.560     raeburn  2293:                         $lockerrorsref->{$prefix} .=
1.559     raeburn  2294:                             ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627     raeburn  2295:                     } elsif ($prefix eq 'exttool') {
                   2296:                         $lockerrorsref->{$prefix} .=
                   2297:                             ' '.&mt('This will prevent addition of more external tools to this course.');
1.533     raeburn  2298:                     } else {
1.565     bisitz   2299:                         $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  2300:                     }
1.560     raeburn  2301:                     $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   2302:                                                      '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
                   2303:                                                  '</div>';
1.533     raeburn  2304:                 }
                   2305:             }
                   2306:         } elsif ($url =~ m{/syllabus$}) {
                   2307:             if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
                   2308:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   2309:                 if (($dbref->{'cdom'} ne $coursedom) ||
                   2310:                     ($dbref->{'cnum'} ne $coursenum)) {
                   2311:                     my %contents=&Apache::lonnet::dump('syllabus',
                   2312:                                                        $dbref->{'cdom'},
                   2313:                                                        $dbref->{'cnum'});
                   2314:                     $result=&Apache::lonnet::put('syllabus',\%contents,
                   2315:                                                  $coursedom,$coursenum);
                   2316:                 }
                   2317:             }
1.488     raeburn  2318:         }
                   2319:     }
1.533     raeburn  2320:     return ($url,$result,$errtext);
1.488     raeburn  2321: }
                   2322: 
1.597     raeburn  2323: sub copy_templated_files {
                   2324:     my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
                   2325:     my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
                   2326:     my $srccontainer = 'sequence';
                   2327:     if ($srcwaspage) {
                   2328:         $srccontainer = 'page';
                   2329:     }
                   2330:     my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
                   2331:                   '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
                   2332:     my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
                   2333:     my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
                   2334:     my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
                   2335:                   $template.'.problem';
                   2336:     my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
                   2337:     if ($template eq 'simpleproblem') {
                   2338:         $srcprefix .= '.0.';
                   2339:         my $weightprefix = $newprefix;
                   2340:         $newprefix .= '.0.';
                   2341:         my @simpleprobqtypes = qw(radio option string essay numerical);
                   2342:         my $qtype=$srcparms{$srcprefix.'questiontype'};
                   2343:         if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665     raeburn  2344:             my %newdata = (
                   2345:                 $newprefix.'questiontype' => $qtype,
                   2346:             );
1.597     raeburn  2347:             foreach my $type (@simpleprobqtypes) {
                   2348:                 if ($type eq $qtype) {
                   2349:                     $newdata{"$weightprefix.$type.weight"}=1;
                   2350:                 } else {
                   2351:                     $newdata{"$weightprefix.$type.weight"}=0;
                   2352:                 }
                   2353:             }
                   2354:             $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
                   2355:             $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
                   2356:             $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
                   2357:             if ($qtype eq 'numerical') {
                   2358:                 $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
                   2359:                 $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
                   2360:                 $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
                   2361:                 $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
                   2362:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   2363:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   2364:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   2365:                     unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   2366:                         if ($maxfoils<=0) { $maxfoils=10; }
                   2367:                             my $randomize=$srcparms{$srcprefix.'randomize'};
                   2368:                             unless (defined($randomize)) { $randomize='yes'; }
                   2369:                             unless ($randomize eq 'no') { $randomize='yes'; }
                   2370:                             $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   2371:                             $newdata{$newprefix.'randomize'} = $randomize;
                   2372:                             if ($qtype eq 'option') {
                   2373:                                 $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   2374:                             }
                   2375:                             for (my $i=1; $i<=10; $i++) {
                   2376:                                 $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   2377:                                 $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   2378:                                 $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   2379:                             }
                   2380: 
                   2381:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   2382:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   2383:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   2384:                 unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   2385:                 if ($maxfoils<=0) { $maxfoils=10; }
                   2386:                 my $randomize=$srcparms{$srcprefix.'randomize'};
                   2387:                 unless (defined($randomize)) { $randomize='yes'; }
                   2388:                 unless ($randomize eq 'no') { $randomize='yes'; }
                   2389:                 $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   2390:                 $newdata{$newprefix.'randomize'} = $randomize;
                   2391:                 if ($qtype eq 'option') {
                   2392:                     $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   2393:                 }
                   2394:                 for (my $i=1; $i<=10; $i++) {
                   2395:                     $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   2396:                     $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   2397:                     $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   2398:                 }
                   2399:             } elsif ($qtype eq 'string') {
                   2400:                 $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
                   2401:                 $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
                   2402:             }
                   2403:             if (keys(%newdata)) {
                   2404:                 my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
                   2405:                                                    $coursenum);
                   2406:                 if ($putres eq 'ok') {
                   2407:                     &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
                   2408:                 }
                   2409:             }
                   2410:         }
                   2411:     }
                   2412: }
                   2413: 
1.329     droeschl 2414: sub uniqueness_check {
                   2415:     my ($newurl) = @_;
                   2416:     my $unique = 1;
                   2417:     foreach my $res (@LONCAPA::map::order) {
                   2418:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   2419:         $url=&LONCAPA::map::qtescape($url);
                   2420:         if ($newurl eq $url) {
                   2421:             $unique = 0;
1.344     bisitz   2422:             last;
1.329     droeschl 2423:         }
                   2424:     }
                   2425:     return $unique;
                   2426: }
                   2427: 
1.488     raeburn  2428: sub contained_map_check {
1.627     raeburn  2429:     my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
                   2430:         $hierarchy,$titles,$allmaps) = @_;
1.488     raeburn  2431:     my $content = &Apache::lonnet::getfile($url);
                   2432:     unless ($content eq '-1') {
                   2433:         my $parser = HTML::TokeParser->new(\$content);
                   2434:         $parser->attr_encoded(1);
                   2435:         while (my $token = $parser->get_token) {
                   2436:             next if ($token->[0] ne 'S');
                   2437:             if ($token->[1] eq 'resource') {
                   2438:                 next if ($token->[2]->{'type'} eq 'zombie');
                   2439:                 my $ressrc = $token->[2]->{'src'};
1.627     raeburn  2440:                 if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
                   2441:                     my $srcdom = $1;
                   2442:                     unless ($srcdom eq $coursedom) {
                   2443:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2444:                         next;
                   2445:                     }
                   2446:                 } elsif ($folder =~ /^supplemental/) {
1.488     raeburn  2447:                     unless (&supp_pasteable($ressrc)) {
1.492     raeburn  2448:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488     raeburn  2449:                         next;
                   2450:                     }
                   2451:                 }
1.492     raeburn  2452:                 if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
                   2453:                     if ($1 eq 'uploaded') {
                   2454:                         $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2455:                         $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488     raeburn  2456:                     } else {
1.492     raeburn  2457:                         if ($allmaps->{$ressrc}) {
1.529     raeburn  2458:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492     raeburn  2459:                         } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
                   2460:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2461:                         } else {
                   2462:                             $addedmaps->{$ressrc} = [$url];
                   2463:                         }
1.488     raeburn  2464:                     }
1.627     raeburn  2465:                     &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
                   2466:                                          $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488     raeburn  2467:                 }
1.492     raeburn  2468:             } elsif ($token->[1] eq 'param') {
1.488     raeburn  2469:                 if ($folder =~ /^supplemental/) {
1.492     raeburn  2470:                     if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
                   2471:                         push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
                   2472:                     } else {
                   2473:                         $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}]; 
                   2474:                     }
1.488     raeburn  2475:                 }
                   2476:             }
                   2477:         }
                   2478:     }
                   2479:     return;
                   2480: }
                   2481: 
                   2482: sub url_paste_fixups {
1.533     raeburn  2483:     my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
                   2484:         $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597     raeburn  2485:         $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491     raeburn  2486:     my $checktitle;
                   2487:     if (($prefixchg) &&
1.492     raeburn  2488:         ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491     raeburn  2489:         $checktitle = 1;
                   2490:     }
1.492     raeburn  2491:     my $skip;
                   2492:     if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
                   2493:         my $mapid = $1.$2;
                   2494:         if ($tomove->{$mapid}) {
                   2495:             $skip = 1;
                   2496:         }
                   2497:     }
1.491     raeburn  2498:     my $file = &Apache::lonnet::getfile($oldurl);
1.488     raeburn  2499:     return if ($file eq '-1');
                   2500:     my $parser = HTML::TokeParser->new(\$file);
                   2501:     $parser->attr_encoded(1);
1.491     raeburn  2502:     my $changed = 0;
1.488     raeburn  2503:     while (my $token = $parser->get_token) {
                   2504:         next if ($token->[0] ne 'S');
                   2505:         if ($token->[1] eq 'resource') {
                   2506:             my $ressrc = $token->[2]->{'src'};
                   2507:             next if ($ressrc eq '');
1.491     raeburn  2508:             my $id = $token->[2]->{'id'};
1.492     raeburn  2509:             my $title = $token->[2]->{'title'};
1.491     raeburn  2510:             if ($checktitle) {
                   2511:                 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  2512:                     $retitles->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2513:                 }
                   2514:             }
1.488     raeburn  2515:             next if ($token->[2]->{'type'} eq 'external');
                   2516:             if ($token->[2]->{'type'} eq 'zombie') {
1.492     raeburn  2517:                 next if ($skip);  
1.532     raeburn  2518:                 $zombies->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2519:                 $changed = 1;
                   2520:             } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  2521:                 my $srcdom = $1;
                   2522:                 my $srcnum = $2;
1.488     raeburn  2523:                 my $rem = $3;
1.492     raeburn  2524:                 my $newurl;
                   2525:                 my $mapname;
                   2526:                 if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
                   2527:                     my $prefix = $1;
                   2528:                     $mapname = $prefix.$2;
                   2529:                     if ($tomove->{$mapname}) {
1.533     raeburn  2530:                         &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   2531:                                           $srcdom,$srcnum,$allmaps,$rewrites,
                   2532:                                           $retitles,$copies,$dbcopies,$zombies,
                   2533:                                           $params,$mapmoves,$mapchanges,$tomove,
1.597     raeburn  2534:                                           $newsubdir,$newurls,$resdatacopy);
1.492     raeburn  2535:                         next;
                   2536:                     } else {
                   2537:                         ($newurl,my $error) =
                   2538:                             &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   2539:                                             $srcdom,$srcnum,\$title,$allmaps,$newurls);
                   2540:                         if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
                   2541:                             $newsubdir->{$ressrc} = $1;
                   2542:                         }
                   2543:                         if ($error) {
                   2544:                             next;
                   2545:                         }
                   2546:                     }
                   2547:                 }
                   2548:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
                   2549:                     ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
                   2550:                    
1.488     raeburn  2551:                     if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532     raeburn  2552:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2553:                         $mapchanges->{$ressrc} = 1;
1.533     raeburn  2554:                         unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
                   2555:                                                   $cnum,$srcdom,$srcnum,$allmaps,
                   2556:                                                   $rewrites,$retitles,$copies,$dbcopies,
                   2557:                                                   $zombies,$params,$mapmoves,$mapchanges,
1.597     raeburn  2558:                                                   $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491     raeburn  2559:                             $mapmoves->{$ressrc} = 1;
                   2560:                         }
                   2561:                         $changed = 1;
1.488     raeburn  2562:                     } else {
1.532     raeburn  2563:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.488     raeburn  2564:                         $copies->{$oldurl}{$ressrc} = $id;
1.491     raeburn  2565:                         $changed = 1;
1.488     raeburn  2566:                     }
                   2567:                 }
1.649     raeburn  2568:             } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533     raeburn  2569:                 next if ($skip);
1.492     raeburn  2570:                 my $srcdom = $1;
                   2571:                 my $srcnum = $2;
1.649     raeburn  2572:                 my $rem = $3;
                   2573:                 my ($is_exttool,$exttoolchg);
                   2574:                 if ($rem =~ m{\d+/ext\.tool$}) {
1.655     raeburn  2575:                     $is_exttool = 1;
1.649     raeburn  2576:                 }
1.492     raeburn  2577:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532     raeburn  2578:                     $rewrites->{$oldurl}{$id} = $ressrc;
1.533     raeburn  2579:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2580:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2581:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   2582:                     $changed = 1;
1.649     raeburn  2583:                     if ($is_exttool) {
                   2584:                         $exttoolchg = 1;
                   2585:                     }
                   2586:                 } elsif (($rem =~ m{\d+/ext\.tool$}) &&
                   2587:                          ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   2588:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2589:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2590:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   2591:                     $changed = 1;
                   2592:                     $exttoolchg = 1;
                   2593:                 }
                   2594:                 if (($is_exttool) && ($prefixchg)) {
                   2595:                     if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
                   2596:                         if ($exttoolchg) {
                   2597:                             $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
                   2598:                         }
                   2599:                     }
1.533     raeburn  2600:                 }
                   2601:             } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
                   2602:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
                   2603:                     ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   2604:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2605:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   2606:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491     raeburn  2607:                     $changed = 1;
1.488     raeburn  2608:                 }
1.597     raeburn  2609:             } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
                   2610:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
                   2611:                     $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
                   2612:                     $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   2613:                     $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
                   2614:                 }
1.488     raeburn  2615:             } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  2616:                 next if ($skip);
                   2617:                 my $srcdom = $1;
                   2618:                 my $srcnum = $2;
                   2619:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533     raeburn  2620:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2621:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2622:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491     raeburn  2623:                     $changed = 1;
1.488     raeburn  2624:                 }
                   2625:             }
                   2626:         } elsif ($token->[1] eq 'param') {
1.492     raeburn  2627:             next if ($skip);
1.488     raeburn  2628:             my $to = $token->[2]->{'to'}; 
                   2629:             if ($to ne '') {
                   2630:                 if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492     raeburn  2631:                     push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488     raeburn  2632:                 } else {
                   2633:                     @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
                   2634:                 }
                   2635:             }
                   2636:         }
                   2637:     }
1.491     raeburn  2638:     return $changed;
1.488     raeburn  2639: }
                   2640: 
                   2641: sub apply_fixups {
1.529     raeburn  2642:     my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
                   2643:         $oldurl,$url,$caller) = @_;
                   2644:     my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533     raeburn  2645:         %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597     raeburn  2646:         %resdatacopy,%lockerrors,$lockmsg);
1.529     raeburn  2647:     if (ref($updated) eq 'HASH') {
                   2648:         if (ref($updated->{'rewrites'}) eq 'HASH') {
                   2649:             %rewrites = %{$updated->{'rewrites'}};
                   2650:         }
                   2651:         if (ref($updated->{'zombies'}) eq 'HASH') {
                   2652:             %zombies = %{$updated->{'zombies'}};
                   2653:         }
                   2654:         if (ref($updated->{'removefrommap'}) eq 'HASH') {
                   2655:             %removefrommap = %{$updated->{'removefrommap'}};
                   2656:         }
                   2657:         if (ref($updated->{'removeparam'}) eq 'HASH') {
                   2658:             %removeparam = %{$updated->{'removeparam'}};
                   2659:         }
                   2660:         if (ref($updated->{'dbcopies'}) eq 'HASH') {
                   2661:             %dbcopies = %{$updated->{'dbcopies'}};
                   2662:         }
                   2663:         if (ref($updated->{'retitles'}) eq 'HASH') {
                   2664:             %retitles = %{$updated->{'retitles'}};
                   2665:         }
1.597     raeburn  2666:         if (ref($updated->{'resdatacopy'}) eq 'HASH') {
                   2667:             %resdatacopy = %{$updated->{'resdatacopy'}};
                   2668:         }
1.529     raeburn  2669:     }
                   2670:     if (ref($info) eq 'HASH') {
                   2671:         if (ref($info->{'newsubdir'}) eq 'HASH') {
                   2672:             %newsubdir = %{$info->{'newsubdir'}};
                   2673:         }
                   2674:         if (ref($info->{'params'}) eq 'HASH') {
                   2675:             %params = %{$info->{'params'}};
                   2676:         }
                   2677:         if (ref($info->{'before'}) eq 'HASH') {
                   2678:             %before = %{$info->{'before'}};
                   2679:         }
                   2680:         if (ref($info->{'after'}) eq 'HASH') {
                   2681:             %after = %{$info->{'after'}};
                   2682:         }
                   2683:     }
                   2684:     if (ref($moves) eq 'HASH') {
                   2685:         if (ref($moves->{'copies'}) eq 'HASH') {
                   2686:             %copies = %{$moves->{'copies'}};
                   2687:         }
                   2688:         if (ref($moves->{'docmoves'}) eq 'HASH') {
                   2689:             %docmoves = %{$moves->{'docmoves'}};
                   2690:         }
                   2691:         if (ref($moves->{'mapmoves'}) eq 'HASH') {
                   2692:             %mapmoves = %{$moves->{'mapmoves'}};
                   2693:         }
                   2694:     }
                   2695:     foreach my $key (keys(%copies),keys(%docmoves)) {
1.491     raeburn  2696:         my @allcopies;
1.529     raeburn  2697:         if (exists($copies{$key})) {
                   2698:             if (ref($copies{$key}) eq 'HASH') {
                   2699:                 my %added;
                   2700:                 foreach my $innerkey (keys(%{$copies{$key}})) {
                   2701:                     if (($innerkey ne '') && (!$added{$innerkey})) {
                   2702:                         push(@allcopies,$innerkey);
                   2703:                         $added{$innerkey} = 1;
                   2704:                     }
1.491     raeburn  2705:                 }
1.529     raeburn  2706:                 undef(%added);
1.491     raeburn  2707:             }
                   2708:         }
                   2709:         if ($key eq $oldurl) {
1.529     raeburn  2710:             if ((exists($docmoves{$key}))) {
1.532     raeburn  2711:                 unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491     raeburn  2712:                     push(@allcopies,$oldurl);
                   2713:                 }
                   2714:             }
                   2715:         }
                   2716:         if (@allcopies > 0) {
                   2717:             foreach my $item (@allcopies) {
1.492     raeburn  2718:                 my ($relpath,$oldsubdir,$fname) = 
                   2719:                     ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491     raeburn  2720:                 if ($fname ne '') {
                   2721:                     my $content = &Apache::lonnet::getfile($item);
                   2722:                     unless ($content eq '-1') {
                   2723:                         my $storefn;
1.529     raeburn  2724:                         if (($key eq $oldurl) && (exists($docmoves{$key}))) {
                   2725:                             $storefn = $docmoves{$key};
1.491     raeburn  2726:                         } else {
                   2727:                             $storefn = $relpath;
                   2728:                             $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  2729:                             if ($prefixchg && $before{'doc'} && $after{'doc'}) {
                   2730:                                 $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491     raeburn  2731:                             }
1.529     raeburn  2732:                             if ($newsubdir{$key}) {
1.532     raeburn  2733:                                 $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491     raeburn  2734:                             }
                   2735:                         }
                   2736:                         &copy_dependencies($item,$storefn,$relpath,$errors,\$content);
                   2737:                         my $copyurl = 
                   2738:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},
                   2739:                                                                $storefn.$fname,$content);
                   2740:                         if ($copyurl eq '/adm/notfound.html') {
1.529     raeburn  2741:                             if (exists($docmoves{$oldurl})) {
1.491     raeburn  2742:                                 return &mt('Paste failed: an error occurred copying the file.');
                   2743:                             } elsif (ref($errors) eq 'HASH') {
                   2744:                                 $errors->{$item} = 1;
1.489     raeburn  2745:                             }
                   2746:                         }
1.488     raeburn  2747:                     }
                   2748:                 }
1.491     raeburn  2749:             }
                   2750:         }
                   2751:     }
1.529     raeburn  2752:     foreach my $key (keys(%mapmoves)) {
1.491     raeburn  2753:         my $storefn=$key;
                   2754:         $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  2755:         if ($prefixchg && $before{'map'} && $after{'map'}) {
                   2756:             $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  2757:         }
1.529     raeburn  2758:         if ($newsubdir{$key}) {
                   2759:             $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  2760:         }
1.491     raeburn  2761:         my $mapcontent = &Apache::lonnet::getfile($key);
                   2762:         if ($mapcontent eq '-1') {
                   2763:             if (ref($errors) eq 'HASH') {
                   2764:                 $errors->{$key} = 1;
                   2765:             }
                   2766:         } else {
                   2767:             my $newmap =
                   2768:                 &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
                   2769:                                                    $mapcontent);
                   2770:             if ($newmap eq '/adm/notfound.html') {
                   2771:                 if (ref($errors) eq 'HASH') {
                   2772:                     $errors->{$key} = 1;
1.489     raeburn  2773:                 }
1.488     raeburn  2774:             }
                   2775:         }
                   2776:     }
1.491     raeburn  2777:     my %updates;
                   2778:     if ($is_map) {
1.529     raeburn  2779:         if (ref($updated) eq 'HASH') {
                   2780:             foreach my $type (keys(%{$updated})) {
                   2781:                 if (ref($updated->{$type}) eq 'HASH') {
                   2782:                     foreach my $key (keys(%{$updated->{$type}})) {
                   2783:                         $updates{$key} = 1;
                   2784:                     }
                   2785:                 }
                   2786:             }
1.491     raeburn  2787:         }
                   2788:         foreach my $key (keys(%updates)) {
1.492     raeburn  2789:             my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529     raeburn  2790:             if (ref($rewrites{$key}) eq 'HASH') {
                   2791:                 %torewrite = %{$rewrites{$key}};
1.491     raeburn  2792:             }
1.529     raeburn  2793:             if (ref($retitles{$key}) eq 'HASH') {
                   2794:                 %toretitle = %{$retitles{$key}};
1.491     raeburn  2795:             }
1.529     raeburn  2796:             if (ref($removefrommap{$key}) eq 'HASH') {
                   2797:                 %toremove = %{$removefrommap{$key}};
1.491     raeburn  2798:             }
1.529     raeburn  2799:             if (ref($removeparam{$key}) eq 'HASH') {
                   2800:                 %remparam = %{$removeparam{$key}};
1.492     raeburn  2801:             }
1.529     raeburn  2802:             if (ref($zombies{$key}) eq 'HASH') {
                   2803:                 %zombie = %{$zombies{$key}};
1.491     raeburn  2804:             }
1.529     raeburn  2805:             if (ref($dbcopies{$key}) eq 'HASH') {
1.533     raeburn  2806:                 foreach my $idx (keys(%{$dbcopies{$key}})) {
                   2807:                     if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
                   2808:                         my ($newurl,$result,$errtext) =
                   2809:                             &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
                   2810:                         if ($result eq 'ok') {
                   2811:                             $newdb{$idx} = $newurl;
                   2812:                         } elsif (ref($errors) eq 'HASH') {
                   2813:                             $errors->{$key} = 1;
                   2814:                         }
                   2815:                         push(@msgs,$errtext);
                   2816:                     }
1.491     raeburn  2817:                 }
                   2818:             }
1.597     raeburn  2819:             if (ref($resdatacopy{$key}) eq 'HASH') {
1.664     raeburn  2820:                 my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597     raeburn  2821:                 foreach my $idx (keys(%{$resdatacopy{$key}})) {
                   2822:                     if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
                   2823:                         my $srcurl = $resdatacopy{$key}{$idx}{'src'};
                   2824:                         if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   2825:                             my $template = $1;
                   2826:                             if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
                   2827:                                 ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
                   2828:                                 my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
                   2829:                                 my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664     raeburn  2830:                                 unless ($gotnewmapname) {
                   2831:                                     ($newmapname) = ($key =~ m{/([^/]+)$});
                   2832:                                     ($srcfolder,$srccontainer) = split(/\./,$newmapname);
                   2833:                                     if ($newsubdir{$key}) {
                   2834:                                         $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
                   2835:                                     }
                   2836:                                     $gotnewmapname = 1;
                   2837:                                 }
1.597     raeburn  2838:                                 my $srcmapinfo = $srcfolder.':'.$idx;
                   2839:                                 if ($srccontainer eq 'page') {
                   2840:                                     $srcmapinfo .= ':1';
                   2841:                                 }
                   2842:                                 &copy_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
                   2843:                                                       $cnum,$template,$idx,$newmapname);
                   2844:                             }
                   2845:                         }
                   2846:                     }
                   2847:                 }
                   2848:             }
1.529     raeburn  2849:             if (ref($params{$key}) eq 'HASH') {
                   2850:                 %currparam = %{$params{$key}};
1.492     raeburn  2851:             }
                   2852:             my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
                   2853:             if ($fatal) {
1.533     raeburn  2854:                 return ($errtext);
1.492     raeburn  2855:             }
                   2856:             for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
                   2857:                 if (defined($LONCAPA::map::zombies[$i])) {
                   2858:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532     raeburn  2859:                     if ($zombie{$i} eq $src) {
1.492     raeburn  2860:                         undef($LONCAPA::map::zombies[$i]);
                   2861:                     }
                   2862:                 }
                   2863:             }
1.646     raeburn  2864:             my $total = scalar(@LONCAPA::map::order) - 1;
                   2865:             for (my $i=$total; $i>=0; $i--) {
1.529     raeburn  2866:                 my $idx = $LONCAPA::map::order[$i];
                   2867:                 if (defined($LONCAPA::map::resources[$idx])) {
1.492     raeburn  2868:                     my $changed;
1.529     raeburn  2869:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538     raeburn  2870:                     if ((exists($toremove{$idx})) && 
                   2871:                         ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492     raeburn  2872:                         splice(@LONCAPA::map::order,$i,1);
1.529     raeburn  2873:                         if (ref($currparam{$idx}) eq 'ARRAY') {
                   2874:                             foreach my $name (@{$currparam{$idx}}) {
1.647     raeburn  2875:                                 &LONCAPA::map::delparameter($idx,$name);
1.492     raeburn  2876:                             }
                   2877:                         }
                   2878:                         next;
                   2879:                     }
                   2880:                     my $origsrc = $src;
1.532     raeburn  2881:                     if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492     raeburn  2882:                         if ($title =~ m{^\d+\Q___&amp;&amp;&amp;___\E$match_username\Q___&amp;&amp;&amp;___\E$match_domain\Q___&amp;&amp;&amp;___\E(.+)$}) {
                   2883:                             $changed = 1;
1.491     raeburn  2884:                         }
1.492     raeburn  2885:                     }
1.532     raeburn  2886:                     if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492     raeburn  2887:                         $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
                   2888:                         if ($origsrc =~ m{^/uploaded/}) {
1.529     raeburn  2889:                             if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492     raeburn  2890:                                 if ($src =~ /\.(page|sequence)$/) {
1.529     raeburn  2891:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492     raeburn  2892:                                 } else {
1.529     raeburn  2893:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488     raeburn  2894:                                 }
1.491     raeburn  2895:                             }
1.532     raeburn  2896:                             if ($origsrc =~ /\.(page|sequence)$/) {
                   2897:                                 if ($newsubdir{$origsrc}) {
1.529     raeburn  2898:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491     raeburn  2899:                                 }
1.532     raeburn  2900:                             } elsif ($newsubdir{$key}) {
                   2901:                                 $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488     raeburn  2902:                             }
                   2903:                         }
1.492     raeburn  2904:                         $changed = 1;
1.533     raeburn  2905:                     } elsif ($newdb{$idx} ne '') {
                   2906:                         $src = $newdb{$idx};
1.492     raeburn  2907:                         $changed = 1;
                   2908:                     }
                   2909:                     if ($changed) {
1.538     raeburn  2910:                         $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492     raeburn  2911:                     }
                   2912:                 }
                   2913:             }
                   2914:             foreach my $idx (keys(%remparam)) {
                   2915:                 if (ref($remparam{$idx}) eq 'ARRAY') {
                   2916:                     foreach my $name (@{$remparam{$idx}}) {   
1.647     raeburn  2917:                         &LONCAPA::map::delparameter($idx,$name);
1.491     raeburn  2918:                     }
                   2919:                 }
                   2920:             }
1.533     raeburn  2921:             if (values(%lockerrors) > 0) {
                   2922:                 $lockmsg = join('<br />',values(%lockerrors));
                   2923:             }
1.491     raeburn  2924:             my $storefn;
                   2925:             if ($key eq $oldurl) {
                   2926:                 $storefn = $url;
                   2927:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
                   2928:             } else {
                   2929:                 $storefn = $key;
                   2930:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  2931:                 if ($prefixchg && $before{'map'} && $after{'map'}) {
                   2932:                     $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  2933:                 }
1.529     raeburn  2934:                 if ($newsubdir{$key}) {
                   2935:                     $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  2936:                 }
1.491     raeburn  2937:             }
1.492     raeburn  2938:             my $report;
                   2939:             if ($folder !~ /^supplemental/) {
                   2940:                 $report = 1;
                   2941:             }
1.527     raeburn  2942:             (my $outtext,$errtext) =
1.492     raeburn  2943:                 &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
                   2944:             if ($errtext) {
1.529     raeburn  2945:                 if ($caller eq 'paste') {
1.533     raeburn  2946:                     return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529     raeburn  2947:                 }
1.491     raeburn  2948:             }
                   2949:         }
                   2950:     }
1.533     raeburn  2951:     return ('ok',\@msgs,$lockmsg);
1.491     raeburn  2952: }
                   2953: 
                   2954: sub copy_dependencies {
                   2955:     my ($item,$storefn,$relpath,$errors,$contentref) = @_;
                   2956:     my $content;
                   2957:     if (ref($contentref)) {
                   2958:         $content = $$contentref;
                   2959:     } else {
                   2960:         $content = &Apache::lonnet::getfile($item);
                   2961:     }
                   2962:     unless ($content eq '-1') {
                   2963:         my $mm = new File::MMagic;
                   2964:         my $mimetype = $mm->checktype_contents($content);
                   2965:         if ($mimetype eq 'text/html') {
                   2966:             my (%allfiles,%codebase,$state);
                   2967:             my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
                   2968:             if ($res eq 'ok') {
                   2969:                 my ($numexisting,$numpathchanges,$existing);
                   2970:                 (undef,$numexisting,$numpathchanges,$existing) =
                   2971:                     &Apache::loncommon::ask_for_embedded_content(
                   2972:                         '/adm/coursedocs',$state,\%allfiles,\%codebase,
                   2973:                         {'error_on_invalid_names'   => 1,
                   2974:                          'ignore_remote_references' => 1,
                   2975:                          'docs_url'                 => $item,
                   2976:                          'context'                  => 'paste'});
                   2977:                 if ($numexisting > 0) {
                   2978:                     if (ref($existing) eq 'HASH') {
                   2979:                         foreach my $dep (keys(%{$existing})) {
                   2980:                             my $depfile = $dep;
                   2981:                             unless ($depfile =~ m{^\Q$relpath\E}) {
                   2982:                                 $depfile = $relpath.$dep;
                   2983:                             }
                   2984:                             my $depcontent = &Apache::lonnet::getfile($depfile);
                   2985:                             unless ($depcontent eq '-1') {
                   2986:                                 my $storedep = $dep;
                   2987:                                 $storedep =~ s{^\Q$relpath\E}{};
                   2988:                                 my $dep_url =
                   2989:                                     &Apache::lonclonecourse::writefile(
                   2990:                                         $env{'request.course.id'},
                   2991:                                         $storefn.$storedep,$depcontent);
                   2992:                                 if ($dep_url eq '/adm/notfound.html') {
                   2993:                                     if (ref($errors) eq 'HASH') {
                   2994:                                         $errors->{$depfile} = 1;
                   2995:                                     }
                   2996:                                 } else {
                   2997:                                     &copy_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
                   2998:                                 }
                   2999:                             }
                   3000:                         }
1.488     raeburn  3001:                     }
                   3002:                 }
                   3003:             }
                   3004:         }
                   3005:     }
                   3006:     return;
                   3007: }
                   3008: 
1.329     droeschl 3009: my %parameter_type = ( 'randompick'     => 'int_pos',
                   3010: 		       'hiddenresource' => 'string_yesno',
                   3011: 		       'encrypturl'     => 'string_yesno',
                   3012: 		       'randomorder'    => 'string_yesno',);
                   3013: my $valid_parameters_re = join('|',keys(%parameter_type));
                   3014: # set parameters
                   3015: sub update_parameter {
1.537     raeburn  3016:     if ($env{'form.changeparms'} eq 'all') {
                   3017:         my (@allidx,@allmapidx,%allchecked,%currchecked);
                   3018:         %allchecked = (
                   3019:                          'hiddenresource' => {},
                   3020:                          'encrypturl'     => {},
                   3021:                          'randompick'     => {},
                   3022:                          'randomorder'    => {},
                   3023:                       );
                   3024:         foreach my $which (keys(%allchecked)) {
1.630     raeburn  3025:             $env{'form.all'.$which} =~ s/,$//;
1.537     raeburn  3026:             if ($which eq 'randompick') {
                   3027:                 foreach my $item (split(/,/,$env{'form.all'.$which})) {
                   3028:                     my ($res,$value) = split(/:/,$item);
                   3029:                     if ($value =~ /^\d+$/) {
                   3030:                         $allchecked{$which}{$res} = $value;
                   3031:                     }
                   3032:                 }
                   3033:             } else {
1.539     raeburn  3034:                 if ($env{'form.all'.$which}) {
                   3035:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
                   3036:                 }
1.537     raeburn  3037:             }
                   3038:         }
                   3039:         my $haschanges = 0;
                   3040:         foreach my $res (@LONCAPA::map::order) {
                   3041:             my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3042:             $name=&LONCAPA::map::qtescape($name);
                   3043:             $url=&LONCAPA::map::qtescape($url);
                   3044:             next unless ($name && $url);
                   3045:             my $is_map;
                   3046:             if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   3047:                 $is_map = 1;
                   3048:             }
                   3049:             foreach my $which (keys(%allchecked)) {
                   3050:                 if (($which eq 'randompick' || $which eq 'randomorder')) {
                   3051:                     next if (!$is_map);
                   3052:                 } 
                   3053:                 my $oldvalue = 0;
                   3054:                 my $newvalue = 0;
                   3055:                 if ($allchecked{$which}{$res}) {
                   3056:                     $newvalue = $allchecked{$which}{$res};
                   3057:                 }
                   3058:                 my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
                   3059:                 if ($which eq 'randompick') {
                   3060:                     if ($current =~ /^(\d+)$/) {
                   3061:                         $oldvalue = $1;
                   3062:                     }
                   3063:                 } else {
                   3064:                     if ($current =~ /^yes$/i) {
                   3065:                         $oldvalue = 1;
                   3066:                     }
                   3067:                 }
                   3068:                 if ($oldvalue ne $newvalue) {
                   3069:                     $haschanges = 1;
                   3070:                     if ($newvalue) {
                   3071:                         my $storeval = 'yes';
                   3072:                         if ($which eq 'randompick') {
                   3073:                             $storeval = $newvalue;
                   3074:                         }
                   3075:                         &LONCAPA::map::storeparameter($res,'parameter_'.$which,
                   3076:                                                       $storeval,
                   3077:                                                       $parameter_type{$which});
                   3078:                         &remember_parms($res,$which,'set',$storeval);
                   3079:                     } elsif ($oldvalue) {
                   3080:                         &LONCAPA::map::delparameter($res,'parameter_'.$which);
                   3081:                         &remember_parms($res,$which,'del');
                   3082:                     }
                   3083:                 }
                   3084:             }
                   3085:         }
                   3086:         return $haschanges;
                   3087:     } else {
1.588     raeburn  3088:         my $haschanges = 0;
                   3089:         return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329     droeschl 3090: 
1.537     raeburn  3091:         my $which = $env{'form.changeparms'};
                   3092:         my $idx = $env{'form.setparms'};
1.588     raeburn  3093:         my $oldvalue = 0;
                   3094:         my $newvalue = 0;
                   3095:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
                   3096:         if ($which eq 'randompick') {
                   3097:             if ($current =~ /^(\d+)$/) {
                   3098:                 $oldvalue = $1;
                   3099:             }
                   3100:         } elsif ($current =~ /^yes$/i) {
                   3101:             $oldvalue = 1;
                   3102:         }
1.537     raeburn  3103:         if ($env{'form.'.$which.'_'.$idx}) {
1.588     raeburn  3104: 	    $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
                   3105: 	                                         : 1;
                   3106:         }
                   3107:         if ($oldvalue ne $newvalue) {
                   3108:             $haschanges = 1;
                   3109:             if ($newvalue) {
                   3110:                 my $storeval = 'yes';
                   3111:                 if ($which eq 'randompick') {
                   3112:                     $storeval = $newvalue;
                   3113:                 }
                   3114: 	        &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
                   3115: 				              $parameter_type{$which});
                   3116: 	        &remember_parms($idx,$which,'set',$storeval);
                   3117:             } else {
                   3118: 	        &LONCAPA::map::delparameter($idx,'parameter_'.$which);
                   3119: 	        &remember_parms($idx,$which,'del');
                   3120:             }
1.537     raeburn  3121:         }
1.588     raeburn  3122:         return $haschanges;
1.329     droeschl 3123:     }
                   3124: }
                   3125: 
                   3126: sub handle_edit_cmd {
                   3127:     my ($coursenum,$coursedom) =@_;
1.633     raeburn  3128:     my $haschanges = 0;
1.543     raeburn  3129:     if ($env{'form.cmd'} eq '') {
1.633     raeburn  3130:         return $haschanges; 
1.543     raeburn  3131:     }
1.329     droeschl 3132:     my ($cmd,$idx)=split('_',$env{'form.cmd'});
                   3133: 
                   3134:     my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                   3135:     my ($title, $url, @rrest) = split(':', $ratstr);
                   3136: 
1.538     raeburn  3137:     if ($cmd eq 'remove') {
1.329     droeschl 3138: 	if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463     www      3139: 	    ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329     droeschl 3140: 	    &Apache::lonnet::removeuploadedurl($url);
                   3141: 	} else {
                   3142: 	    &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   3143: 	}
                   3144: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  3145:         $haschanges = 1;
1.329     droeschl 3146:     } elsif ($cmd eq 'cut') {
                   3147: 	&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   3148: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  3149:         $haschanges = 1;
1.344     bisitz   3150:     } elsif ($cmd eq 'up'
1.329     droeschl 3151: 	     && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
                   3152: 	@LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633     raeburn  3153:         $haschanges = 1;
1.329     droeschl 3154:     } elsif ($cmd eq 'down'
                   3155: 	     && defined($LONCAPA::map::order[$idx+1])) {
                   3156: 	@LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633     raeburn  3157:         $haschanges = 1;
1.329     droeschl 3158:     } elsif ($cmd eq 'rename') {
                   3159: 	my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
                   3160: 	if ($comment=~/\S/) {
                   3161: 	    $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
                   3162: 		$comment.':'.join(':', $url, @rrest);
                   3163: 	}
                   3164: # Devalidate title cache
                   3165: 	my $renamed_url=&LONCAPA::map::qtescape($url);
                   3166: 	&Apache::lonnet::devalidate_title_cache($renamed_url);
1.633     raeburn  3167:         $haschanges = 1;
                   3168:     } elsif ($cmd eq 'setalias') {
                   3169:         my $newvalue = $env{'form.alias'};
                   3170:         if ($newvalue ne '') {
                   3171:             unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
                   3172:                 &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
                   3173:                                               'string');
                   3174:                 &remember_parms($idx,'mapalias','set',$newvalue);
                   3175:                 $haschanges = 1;
                   3176:             }
                   3177:         }
                   3178:     } elsif ($cmd eq 'delalias') {
                   3179:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];  
                   3180:         if ($current ne '') {
                   3181:             &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
                   3182:             &remember_parms($idx,'mapalias','del');
                   3183:             $haschanges = 1;
                   3184:         }
1.329     droeschl 3185:     }
1.633     raeburn  3186:     return $haschanges;
1.329     droeschl 3187: }
                   3188: 
                   3189: sub editor {
1.458     raeburn  3190:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615     raeburn  3191:         $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622     raeburn  3192:         $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519     raeburn  3193:     my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510     raeburn  3194:     if ($allowed) {
1.519     raeburn  3195:         (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   3196:          $is_random_order,$container) =
1.510     raeburn  3197:             &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   3198:         $r->print($breadcrumbtrail);
1.519     raeburn  3199:     } elsif ($env{'form.folderpath'} =~ /\:1$/) {
                   3200:         $container = 'page'; 
                   3201:     } else {
                   3202:         $container = 'sequence';
1.510     raeburn  3203:     }
1.484     raeburn  3204: 
1.525     raeburn  3205:     my $jumpto;
                   3206: 
                   3207:     unless ($supplementalflag) {
1.546     raeburn  3208:         $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525     raeburn  3209:     }
1.484     raeburn  3210: 
                   3211:     unless ($allowed) {
                   3212:         $randompick = -1;
                   3213:     }
                   3214: 
1.615     raeburn  3215:     my ($errtext,$fatal);
                   3216:     if (($folder eq '') && (!$supplementalflag)) {
                   3217:         if (@LONCAPA::map::order) {
                   3218:             undef(@LONCAPA::map::order);
                   3219:             undef(@LONCAPA::map::resources);
                   3220:             undef(@LONCAPA::map::resparms);
                   3221:             undef(@LONCAPA::map::zombies);
                   3222:         }
                   3223:         $folder = 'default';
                   3224:         $container = 'sequence'; 
                   3225:     } else {
                   3226:         ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   3227: 				     $folder.'.'.$container);
                   3228:         return $errtext if ($fatal);
                   3229:     }
1.329     droeschl 3230: 
                   3231:     if ($#LONCAPA::map::order<1) {
                   3232: 	my $idx=&LONCAPA::map::getresidx();
                   3233: 	if ($idx<=0) { $idx=1; }
                   3234:        	$LONCAPA::map::order[0]=$idx;
                   3235:         $LONCAPA::map::resources[$idx]='';
                   3236:     }
1.364     bisitz   3237: 
1.329     droeschl 3238: # ------------------------------------------------------------ Process commands
                   3239: 
                   3240: # ---------------- if they are for this folder and user allowed to make changes
1.611     raeburn  3241:     if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329     droeschl 3242: # set parameters and change order
                   3243: 	&snapshotbefore();
                   3244: 
                   3245: 	if (&update_parameter()) {
1.588     raeburn  3246: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329     droeschl 3247: 	    return $errtext if ($fatal);
                   3248: 	}
                   3249: 
                   3250: 	if ($env{'form.newpos'} && $env{'form.currentpos'}) {
                   3251: # change order
                   3252: 	    my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
                   3253: 	    splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
                   3254: 
                   3255: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
                   3256: 	    return $errtext if ($fatal);
                   3257: 	}
1.364     bisitz   3258: 
1.329     droeschl 3259: 	if ($env{'form.pastemarked'}) {
1.491     raeburn  3260:             my %paste_errors;
1.533     raeburn  3261:             my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492     raeburn  3262:                 &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
                   3263:                                       \%paste_errors);
1.541     raeburn  3264:             if (ref($pastemsgarray) eq 'ARRAY') {
                   3265:                 if (@{$pastemsgarray} > 0) {
                   3266:                     $r->print('<p class="LC_info">'.
                   3267:                               join('<br />',@{$pastemsgarray}).
1.533     raeburn  3268:                               '</p>');
                   3269:                 }
1.541     raeburn  3270:             }
                   3271:             if ($lockerror) {
                   3272:                 $r->print('<p class="LC_error">'.
                   3273:                           $lockerror.
                   3274:                           '</p>');
                   3275:             }
                   3276:             if ($save_error ne '') {
                   3277:                 return $save_error; 
                   3278:             }
                   3279:             if ($paste_res) {
                   3280:                 my %errortext = &Apache::lonlocal::texthash (
                   3281:                                     fail      => 'Storage of folder contents failed',
                   3282:                                     failread  => 'Reading folder contents failed',
                   3283:                                     failstore => 'Storage of folder contents failed',
                   3284:                                 );
                   3285:                 if ($errortext{$paste_res}) {
                   3286:                     $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492     raeburn  3287:                 }
1.329     droeschl 3288:             }
1.491     raeburn  3289:             if (keys(%paste_errors) > 0) {
1.538     raeburn  3290:                 $r->print('<p class="LC_warning">'."\n".
1.491     raeburn  3291:                           &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".
                   3292:                           '<ul>'."\n");
                   3293:                 foreach my $key (sort(keys(%paste_errors))) {
                   3294:                     $r->print('<li>'.$key.'</li>'."\n");
                   3295:                 }
                   3296:                 $r->print('</ul></p>'."\n");
                   3297:             }
1.538     raeburn  3298: 	} elsif ($env{'form.clearmarked'}) {
                   3299:             my $output = &do_buffer_empty();
                   3300:             if ($output) {
                   3301:                 $r->print('<p class="LC_info">'.$output.'</p>');
                   3302:             }
                   3303:         }
1.329     droeschl 3304: 
                   3305: 	$r->print($upload_output);
                   3306: 
1.538     raeburn  3307: # Rename, cut, copy or remove a single resource
1.602     raeburn  3308: 	if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492     raeburn  3309:             my $contentchg;
1.633     raeburn  3310:             if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492     raeburn  3311:                 $contentchg = 1;
                   3312:             }
                   3313: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329     droeschl 3314: 	    return $errtext if ($fatal);
                   3315: 	}
1.538     raeburn  3316: 
                   3317: # Cut, copy and/or remove multiple resources
                   3318:         if ($env{'form.multichange'}) {
                   3319:             my %allchecked = (
                   3320:                                cut     => {},
                   3321:                                remove  => {},
                   3322:                              );
                   3323:             my $needsupdate;
                   3324:             foreach my $which (keys(%allchecked)) {
                   3325:                 $env{'form.multi'.$which} =~ s/,$//;
                   3326:                 if ($env{'form.multi'.$which}) {
                   3327:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
                   3328:                     if (ref($allchecked{$which}) eq 'HASH') {
                   3329:                         $needsupdate += scalar(keys(%{$allchecked{$which}}));
                   3330:                     }
                   3331:                 }
                   3332:             }
                   3333:             if ($needsupdate) {
                   3334:                 my $haschanges = 0;
                   3335:                 my %curr_groups = &Apache::longroup::coursegroups();
                   3336:                 my $total = scalar(@LONCAPA::map::order) - 1; 
                   3337:                 for (my $i=$total; $i>=0; $i--) {
                   3338:                     my $res = $LONCAPA::map::order[$i];
                   3339:                     my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3340:                     $name=&LONCAPA::map::qtescape($name);
                   3341:                     $url=&LONCAPA::map::qtescape($url);
1.586     droeschl 3342:                     next unless $url;
1.538     raeburn  3343:                     my %denied =
                   3344:                         &action_restrictions($coursenum,$coursedom,$url,
                   3345:                                              $env{'form.folderpath'},\%curr_groups);
                   3346:                     foreach my $which (keys(%allchecked)) {
                   3347:                         next if ($denied{$which});
                   3348:                         next unless ($allchecked{$which}{$res});
                   3349:                         if ($which eq 'remove') {
                   3350:                             if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   3351:                                 ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   3352:                                 &Apache::lonnet::removeuploadedurl($url);
                   3353:                             } else {
                   3354:                                 &LONCAPA::map::makezombie($res);
                   3355:                             }
                   3356:                             splice(@LONCAPA::map::order,$i,1);
                   3357:                             $haschanges ++;
                   3358:                         } elsif ($which eq 'cut') {
                   3359:                             &LONCAPA::map::makezombie($res);
                   3360:                             splice(@LONCAPA::map::order,$i,1);
                   3361:                             $haschanges ++;
                   3362:                         }
                   3363:                     }
                   3364:                 }
                   3365:                 if ($haschanges) {
                   3366:                     ($errtext,$fatal) = 
                   3367:                         &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   3368:                     return $errtext if ($fatal);
                   3369:                 }
                   3370:             }
                   3371:         }
                   3372: 
1.329     droeschl 3373: # Group import/search
                   3374: 	if ($env{'form.importdetail'}) {
                   3375: 	    my @imports;
                   3376: 	    foreach my $item (split(/\&/,$env{'form.importdetail'})) {
                   3377: 		if (defined($item)) {
                   3378: 		    my ($name,$url,$residx)=
1.533     raeburn  3379: 			map { &unescape($_); } split(/\=/,$item);
                   3380:                     if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
                   3381:                         my ($suffix,$errortxt,$locknotfreed) =
                   3382:                             &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504     raeburn  3383:                         if ($locknotfreed) {
                   3384:                             $r->print($locknotfreed);
                   3385:                         }
                   3386:                         if ($suffix) {
                   3387:                             $url =~ s/_new\./_$suffix./; 
                   3388:                         } else {
                   3389:                             return $errortxt;
                   3390:                         }
1.533     raeburn  3391:                     } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
                   3392:                         my $type = $1;
                   3393:                         my ($suffix,$errortxt,$locknotfreed) =
                   3394:                             &new_timebased_suffix($coursedom,$coursenum,$type);
                   3395:                         if ($locknotfreed) {
                   3396:                             $r->print($locknotfreed);
                   3397:                         }
                   3398:                         if ($suffix) {
                   3399:                             $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
                   3400:                         } else {
                   3401:                             return $errortxt;
                   3402:                         }
1.626     raeburn  3403:                     } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598     raeburn  3404:                         my ($suffix,$errortxt,$locknotfreed) =
                   3405:                             &new_timebased_suffix($coursedom,$coursenum,'exttool');
                   3406:                         if ($locknotfreed) {
                   3407:                             $r->print($locknotfreed);
                   3408:                         }
                   3409:                         if ($suffix) {
                   3410:                             $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
                   3411:                         } else {
                   3412:                             return $errortxt;
                   3413:                         }
1.534     raeburn  3414:                     } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
                   3415:                         if ($supplementalflag) {
                   3416:                             next unless ($1 eq 'supplemental');
                   3417:                             if ($folder eq 'supplemental') {
                   3418:                                 next unless ($2 eq 'default');
                   3419:                             } else {
                   3420:                                 next unless ($folder eq 'supplemental_'.$2);
                   3421:                             }
                   3422:                         } else {
                   3423:                             next unless ($1 eq 'docs');
                   3424:                             if ($folder eq 'default') {
                   3425:                                 next unless ($2 eq 'default');
                   3426:                             } else {
                   3427:                                 next unless ($folder eq 'default_'.$2);
                   3428:                             }
                   3429:                         }
1.504     raeburn  3430:                     }
1.329     droeschl 3431: 		    push(@imports, [$name, $url, $residx]);
                   3432: 		}
                   3433: 	    }
1.530     raeburn  3434:             ($errtext,$fatal,my $fixuperrors) =
1.529     raeburn  3435:                 &group_import($coursenum, $coursedom, $folder,$container,
1.598     raeburn  3436:                               'londocs',$ltitoolsref,@imports);
1.329     droeschl 3437: 	    return $errtext if ($fatal);
1.529     raeburn  3438:             if ($fixuperrors) {
                   3439:                 $r->print($fixuperrors);
                   3440:             }
1.329     droeschl 3441: 	}
                   3442: # Loading a complete map
                   3443: 	if ($env{'form.loadmap'}) {
                   3444: 	    if ($env{'form.importmap'}=~/\w/) {
                   3445: 		foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
                   3446: 		    my ($title,$url,$ext,$type)=split(/\:/,$res);
                   3447: 		    my $idx=&LONCAPA::map::getresidx($url);
                   3448: 		    $LONCAPA::map::resources[$idx]=$res;
                   3449: 		    $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
                   3450: 		}
                   3451: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  3452: 					    $folder.'.'.$container,1);
1.329     droeschl 3453: 		return $errtext if ($fatal);
                   3454: 	    } else {
                   3455: 		$r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364     bisitz   3456: 
1.329     droeschl 3457: 	    }
                   3458: 	}
                   3459: 	&log_differences($plain);
                   3460:     }
                   3461: # ---------------------------------------------------------------- End commands
                   3462: # ---------------------------------------------------------------- Print screen
                   3463:     my $idx=0;
                   3464:     my $shown=0;
                   3465:     if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381     bisitz   3466: 	$r->print('<div class="LC_Box">'.
1.432     raeburn  3467:           '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
                   3468: 		  ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
                   3469: 		  ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
                   3470: 		  ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
                   3471: 		  ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431     raeburn  3472: 		  '</ol>');
1.381     bisitz   3473:         if ($randompick>=0) {
                   3474:             $r->print('<p class="LC_warning">'
                   3475:                  .&mt('Caution: this folder is set to randomly pick a subset'
                   3476:                      .' of resources. Adding or removing resources from this'
                   3477:                      .' folder will change the set of resources that the'
                   3478:                      .' students see, resulting in spurious or missing credit'
                   3479:                      .' for completed problems, not limited to ones you'
                   3480:                      .' modify. Do not modify the contents of this folder if'
                   3481:                      .' it is in active student use.')
                   3482:                  .'</p>'
                   3483:             );
                   3484:         }
                   3485:         if ($is_random_order) {
                   3486:             $r->print('<p class="LC_warning">'
                   3487:                  .&mt('Caution: this folder is set to randomly order its'
                   3488:                      .' contents. Adding or removing resources from this folder'
                   3489:                      .' will change the order of resources shown.')
                   3490:                  .'</p>'
                   3491:             );
                   3492:         }
                   3493:         $r->print('</div>');
1.364     bisitz   3494:     }
1.381     bisitz   3495: 
1.538     raeburn  3496:     my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
                   3497:     %filters =  (
1.543     raeburn  3498:                   canremove      => [],
                   3499:                   cancut         => [],
                   3500:                   cancopy        => [],
                   3501:                   hiddenresource => [],
                   3502:                   encrypturl     => [],
                   3503:                   randomorder    => [],
                   3504:                   randompick     => [],
1.538     raeburn  3505:                 );
                   3506:     %curr_groups = &Apache::longroup::coursegroups();
1.424     onken    3507:     &Apache::loncommon::start_data_table_count(); #setup a row counter 
1.381     bisitz   3508:     foreach my $res (@LONCAPA::map::order) {
                   3509:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3510:         $name=&LONCAPA::map::qtescape($name);
                   3511:         $url=&LONCAPA::map::qtescape($url);
                   3512:         unless ($name) {  $name=(split(/\//,$url))[-1]; }
                   3513:         unless ($name) { $idx++; next; }
1.537     raeburn  3514:         push(@allidx,$res);
                   3515:         if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   3516:             push(@allmapidx,$res);
                   3517:         }
1.617     raeburn  3518: 
1.381     bisitz   3519:         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501     raeburn  3520:                               $coursenum,$coursedom,$crstype,
1.538     raeburn  3521:                               $pathitem,$supplementalflag,$container,
1.620     raeburn  3522:                               \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622     raeburn  3523:                               $isencrypted,$navmapref,$hostname);
1.381     bisitz   3524:         $idx++;
                   3525:         $shown++;
1.329     droeschl 3526:     }
1.424     onken    3527:     &Apache::loncommon::end_data_table_count();
1.510     raeburn  3528: 
1.538     raeburn  3529:     my $need_save;
1.611     raeburn  3530:     if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544     raeburn  3531:         my $toolslink;
1.611     raeburn  3532:         if ($allowed) {
1.544     raeburn  3533:             $toolslink = '<table><tr><td>'
1.520     raeburn  3534:                        .&Apache::loncommon::help_open_menu('Navigation Screen',
                   3535:                                                            'Navigation_Screen',undef,'RAT')
                   3536:                        .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
                   3537:                        .'<td align="left"><ul id="LC_toolbar">'
1.525     raeburn  3538:                        .'<li><a href="/adm/coursedocs?forcesupplement=1&amp;command=editsupp" '
1.520     raeburn  3539:                        .'id="LC_content_toolbar_edittoplevel" '
                   3540:                        .'class="LC_toolbarItem" '
                   3541:                        .'title="'.&mt('Supplemental Content Editor').'">'
                   3542:                        .'</a></li></ul></td></tr></table><br />';
1.544     raeburn  3543:         }
1.510     raeburn  3544:         if ($shown) {
                   3545:             if ($allowed) {
                   3546:                 $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
                   3547:                           .&Apache::loncommon::start_data_table(undef,'contentlist')
                   3548:                           .&Apache::loncommon::start_data_table_header_row()
                   3549:                           .'<th colspan="2">'.&mt('Move').'</th>'
1.633     raeburn  3550:                           .'<th colspan="3">'.&mt('Actions').'</th>'
1.538     raeburn  3551:                           .'<th>'.&mt('Document').'</th>';
1.510     raeburn  3552:                 if ($folder !~ /^supplemental/) {
1.633     raeburn  3553:                     $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
1.510     raeburn  3554:                 }
1.537     raeburn  3555:                 $to_show .= &Apache::loncommon::end_data_table_header_row();
                   3556:                 if ($folder !~ /^supplemental/) {
1.538     raeburn  3557:                     $lists{'canhide'} = join(',',@allidx);
                   3558:                     $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543     raeburn  3559:                     my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
                   3560:                                        'randomorder','randompick');
                   3561:                     foreach my $item (@possfilters) {
1.538     raeburn  3562:                         if (ref($filters{$item}) eq 'ARRAY') {
1.543     raeburn  3563:                             if (@{$filters{$item}} > 0) {
                   3564:                                 $lists{$item} = join(',',@{$filters{$item}});
                   3565:                             }
1.538     raeburn  3566:                         }
                   3567:                     }
1.537     raeburn  3568:                     if (@allidx > 0) {
                   3569:                         my $path;
                   3570:                         if ($env{'form.folderpath'}) {
1.630     raeburn  3571:                             $path =
1.537     raeburn  3572:                                 &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   3573:                         }
1.538     raeburn  3574:                         if (@allidx > 1) {
1.630     raeburn  3575:                             $to_show .=
1.538     raeburn  3576:                                 &Apache::loncommon::continue_data_table_row().
                   3577:                                 '<td colspan="2">&nbsp;</td>'.
                   3578:                                 '<td>'.
1.611     raeburn  3579:                                 &multiple_check_form('actions',\%lists,$canedit).
1.538     raeburn  3580:                                 '</td>'.
1.633     raeburn  3581:                                 '<td colspan="3">&nbsp;</td>'.
                   3582:                                 '<td colspan="2">'.
1.611     raeburn  3583:                                 &multiple_check_form('settings',\%lists,$canedit).
1.538     raeburn  3584:                                 '</td>'.
                   3585:                                 &Apache::loncommon::end_data_table_row();
                   3586:                              $need_save = 1;
                   3587:                         }
1.537     raeburn  3588:                     }
                   3589:                 }
                   3590:                 $to_show .= $output.' '
1.510     raeburn  3591:                            .&Apache::loncommon::end_data_table()
                   3592:                            .'<br style="line-height:2px;" />'
                   3593:                            .&Apache::loncommon::end_scrollbox();
                   3594:             } else {
1.520     raeburn  3595:                 $to_show .= $toolslink
1.510     raeburn  3596:                            .&Apache::loncommon::start_data_table('LC_tableOfContent')
                   3597:                            .$output.' '
                   3598:                            .&Apache::loncommon::end_data_table();
1.393     raeburn  3599:             }
1.510     raeburn  3600:         } else {
1.520     raeburn  3601:             if (!$allowed) {
                   3602:                 $to_show .= $toolslink;
                   3603:             }
1.615     raeburn  3604:             my $noresmsg;
                   3605:             if ($allowed && $hiddentop && !$supplementalflag) {
                   3606:                 $noresmsg = &mt('Main Content Hidden'); 
                   3607:             } else {
                   3608:                 $noresmsg = &mt('Currently empty');
                   3609:             }
1.510     raeburn  3610:             $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
                   3611:                        .'<div class="LC_info" id="contentlist">'
1.615     raeburn  3612:                        .$noresmsg
1.510     raeburn  3613:                        .'</div>'
                   3614:                        .&Apache::loncommon::end_scrollbox();
1.393     raeburn  3615:         }
                   3616:     } else {
1.510     raeburn  3617:         if ($shown) {
                   3618:             $to_show = '<div>'
                   3619:                       .&Apache::loncommon::start_data_table('LC_tableOfContent')
                   3620:                       .$output
                   3621:                       .&Apache::loncommon::end_data_table()
                   3622:                       .'</div>';
                   3623:         } else {
                   3624:             $to_show = '<div class="LC_info" id="contentlist">'
1.550     raeburn  3625:                       .&mt('Currently empty')
1.510     raeburn  3626:                       .'</div>'
                   3627:         }
1.458     raeburn  3628:     }
                   3629:     my $tid = 1;
                   3630:     if ($supplementalflag) {
                   3631:         $tid = 2;
1.329     droeschl 3632:     }
                   3633:     if ($allowed) {
1.484     raeburn  3634:         my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538     raeburn  3635:         $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611     raeburn  3636:                                        $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
                   3637:         if ($canedit) {
                   3638:             &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
                   3639:         }
1.460     raeburn  3640:     } else {
                   3641:         $r->print($to_show);
1.329     droeschl 3642:     }
                   3643:     return;
                   3644: }
                   3645: 
1.538     raeburn  3646: sub multiple_check_form {
1.611     raeburn  3647:     my ($caller,$listsref,$canedit) = @_;
1.538     raeburn  3648:     return unless (ref($listsref) eq 'HASH');
1.611     raeburn  3649:     my $disabled;
                   3650:     unless ($canedit) {
                   3651:         $disabled = 'disabled="disabled"'; 
                   3652:     }
1.538     raeburn  3653:     my $output =
                   3654:     '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
                   3655:     '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
                   3656:     '<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>'.
                   3657:     '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
                   3658:     '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
                   3659:     '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
                   3660:     if ($caller eq 'settings') {
                   3661:         $output .= 
                   3662:             '<table><tr>'.
                   3663:             '<td class="LC_docs_entry_parameter">'.
                   3664:             '<span class="LC_nobreak"><label>'.
1.611     raeburn  3665:             '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538     raeburn  3666:             '</label></span></td>'.
                   3667:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  3668:             '<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  3669:             '</span></td>'.
                   3670:             '</tr>'."\n".
                   3671:             '<tr>'.
                   3672:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  3673:             '<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  3674:             '</label></span>'.
                   3675:             '</td></tr></table>'."\n";
                   3676:     } else {
                   3677:         $output .=
                   3678:             '<table><tr>'.
                   3679:             '<td class="LC_docs_entry_parameter">'.
                   3680:             '<span class="LC_nobreak LC_docs_remove">'.
1.611     raeburn  3681:             '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538     raeburn  3682:             '</label></span></td>'.
                   3683:             '<td class="LC_docs_entry_parameter">'.
                   3684:             '<span class="LC_nobreak LC_docs_cut">'.
1.611     raeburn  3685:             '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538     raeburn  3686:             '</label></span></td>'."\n".
                   3687:             '<td class="LC_docs_entry_parameter">'.
                   3688:             '<span class="LC_nobreak LC_docs_copy">'.
1.611     raeburn  3689:             '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538     raeburn  3690:             '</label></span></td>'.
                   3691:             '</tr></table>'."\n";
                   3692:     }
                   3693:     $output .= 
                   3694:         '</fieldset>'.
                   3695:         '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
                   3696:     if ($caller eq 'settings') {
                   3697:         $output .= 
1.543     raeburn  3698:         '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
                   3699:         '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
                   3700:         '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
                   3701:         '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
                   3702:         '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538     raeburn  3703:     } elsif ($caller eq 'actions') {
                   3704:         $output .=
                   3705:         '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
                   3706:         '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
                   3707:         '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
                   3708:     }
                   3709:     $output .= 
                   3710:         '</form>'.
                   3711:         '</div>';
                   3712:     return $output;
                   3713: }
                   3714: 
1.329     droeschl 3715: sub process_file_upload {
1.552     raeburn  3716:     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329     droeschl 3717: # upload a file, if present
1.552     raeburn  3718:     my $filesize = length($env{'form.uploaddoc'});
                   3719:     if (!$filesize) {
                   3720:         $$upload_output = '<div class="LC_error">'.
                   3721:                            &mt('Unable to upload [_1]. (size = [_2] bytes)',
                   3722:                           '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
                   3723:                           $filesize).'<br />'.
                   3724:                           &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
                   3725:                           '</div>';
                   3726:         return;
                   3727:     }
                   3728:     my $quotatype = 'unofficial';
                   3729:     if ($crstype eq 'Community') {
1.601     raeburn  3730:         $quotatype = 'community';
                   3731:     } elsif ($crstype eq 'Placement') {
                   3732:         $quotatype = 'placement';
1.580     raeburn  3733:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552     raeburn  3734:         $quotatype = 'official';
1.573     raeburn  3735:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   3736:         $quotatype = 'textbook';
1.552     raeburn  3737:     }
                   3738:     if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
                   3739:         $filesize = int($filesize/1000); #expressed in kb
                   3740:         $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579     raeburn  3741:                                                                       $env{'form.uploaddoc.filename'},$filesize,
                   3742:                                                                       'upload',$quotatype);
1.552     raeburn  3743:         return if ($$upload_output);
                   3744:     }
1.440     raeburn  3745:     my ($parseaction,$showupload,$nextphase,$mimetype);
                   3746:     if ($env{'form.parserflag'}) {
1.329     droeschl 3747:         $parseaction = 'parse';
                   3748:     }
                   3749:     my $folder=$env{'form.folder'};
                   3750:     if ($folder eq '') {
                   3751:         $folder='default';
                   3752:     }
                   3753:     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
                   3754:         my $errtext='';
                   3755:         my $fatal=0;
                   3756:         my $container='sequence';
1.519     raeburn  3757:         if ($env{'form.folderpath'} =~ /:1$/) {
1.329     droeschl 3758:             $container='page';
                   3759:         }
                   3760:         ($errtext,$fatal)=
1.534     raeburn  3761:             &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329     droeschl 3762:         if ($#LONCAPA::map::order<1) {
                   3763:             $LONCAPA::map::order[0]=1;
                   3764:             $LONCAPA::map::resources[1]='';
                   3765:         }
                   3766:         my $destination = 'docs/';
                   3767:         if ($folder =~ /^supplemental/) {
                   3768:             $destination = 'supplemental/';
                   3769:         }
                   3770:         if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   3771:             $destination .= 'default/';
                   3772:         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   3773:             $destination .=  $2.'/';
                   3774:         }
1.534     raeburn  3775:         if ($fatal) {
                   3776:             $$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>';
                   3777:             return;
                   3778:         }
1.440     raeburn  3779: # this is for a course, not a user, so set context to coursedoc.
1.329     droeschl 3780:         my $newidx=&LONCAPA::map::getresidx();
                   3781:         $destination .= $newidx;
1.439     raeburn  3782:         my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329     droeschl 3783: 						$parseaction,$allfiles,
1.440     raeburn  3784: 						$codebase,undef,undef,undef,undef,
                   3785:                                                 undef,undef,\$mimetype);
                   3786:         if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
                   3787:             my $stored = $1;
                   3788:             $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   3789:                           $stored.'</span>').'</p>';
                   3790:         } else {
                   3791:             my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
                   3792:             
1.457     raeburn  3793:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440     raeburn  3794:             return;
                   3795:         }
1.329     droeschl 3796:         my $ext='false';
                   3797:         if ($url=~m{^http://}) { $ext='true'; }
                   3798: 	$url     = &LONCAPA::map::qtunescape($url);
                   3799:         my $comment=$env{'form.comment'};
                   3800: 	$comment = &LONCAPA::map::qtunescape($comment);
                   3801:         if ($folder=~/^supplemental/) {
                   3802:               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   3803:                   $env{'user.domain'}.'___&&&___'.$comment;
                   3804:         }
                   3805: 
                   3806:         $LONCAPA::map::resources[$newidx]=
                   3807: 	    $comment.':'.$url.':'.$ext.':normal:res';
                   3808:         $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
                   3809:         ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  3810: 				    $folder.'.'.$container,1);
1.329     droeschl 3811:         if ($fatal) {
1.457     raeburn  3812:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440     raeburn  3813:             return;
1.329     droeschl 3814:         } else {
1.440     raeburn  3815:             if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
                   3816:                 $$upload_output = $showupload;
1.384     raeburn  3817:                 my $total_embedded = scalar(keys(%{$allfiles}));
1.329     droeschl 3818:                 if ($total_embedded > 0) {
1.440     raeburn  3819:                     my $uploadphase = 'upload_embedded';
                   3820:                     my $primaryurl = &HTML::Entities::encode($url,'<>&"');
                   3821: 		    my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx); 
1.630     raeburn  3822:                     my ($embedded,$num) =
1.440     raeburn  3823:                         &Apache::loncommon::ask_for_embedded_content(
                   3824:                             '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
                   3825:                     if ($embedded) {
                   3826:                         if ($num) {
                   3827:                             $$upload_output .=
                   3828: 			         '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
                   3829:                             $nextphase = $uploadphase;
                   3830:                         } else {
                   3831:                             $$upload_output .= $embedded;
                   3832:                         }
                   3833:                     } else {
                   3834:                         $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
                   3835:                     }
1.329     droeschl 3836:                 } else {
1.440     raeburn  3837:                     $$upload_output .= &mt('No embedded items identified').'<br />';
1.329     droeschl 3838:                 }
1.457     raeburn  3839:                 $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578     raeburn  3840:             } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
                   3841:                      ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476     raeburn  3842:                 $nextphase = 'decompress_uploaded';
                   3843:                 my $position = scalar(@LONCAPA::map::order)-1;
                   3844:                 my $noextract = &return_to_editor();
                   3845:                 my $archiveurl = &HTML::Entities::encode($url,'<>&"');
                   3846:                 my %archiveitems = (
                   3847:                     folderpath => $env{'form.folderpath'},
                   3848:                     cmd        => $nextphase,
                   3849:                     newidx     => $newidx,
                   3850:                     position   => $position,
                   3851:                     phase      => $nextphase,
1.477     raeburn  3852:                     comment    => $comment,
1.480     raeburn  3853:                 );
                   3854:                 my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
                   3855:                 my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx); 
1.476     raeburn  3856:                 $$upload_output = $showupload.
                   3857:                                   &Apache::loncommon::decompress_form($mimetype,
                   3858:                                       $archiveurl,'/adm/coursedocs',$noextract,
1.480     raeburn  3859:                                       \%archiveitems,\@current);
1.329     droeschl 3860:             }
                   3861:         }
                   3862:     }
1.440     raeburn  3863:     return $nextphase;
1.329     droeschl 3864: }
                   3865: 
1.480     raeburn  3866: sub get_dir_list {
                   3867:     my ($url,$coursenum,$coursedom,$newidx) = @_;
                   3868:     my ($destination,$dir_root) = &embedded_destination();
                   3869:     my ($dirlistref,$listerror) =  
                   3870:         &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
                   3871:     my @dir_lines;
                   3872:     my $dirptr=16384;
                   3873:     if (ref($dirlistref) eq 'ARRAY') {
                   3874:         foreach my $dir_line (sort
                   3875:                           {
                   3876:                               my ($afile)=split('&',$a,2);
                   3877:                               my ($bfile)=split('&',$b,2);
                   3878:                               return (lc($afile) cmp lc($bfile));
                   3879:                           } (@{$dirlistref})) {
                   3880:             my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
                   3881:             $filename =~ s/\s+$//;
                   3882:             next if ($filename =~ /^\.\.?$/); 
                   3883:             my $isdir = 0;
                   3884:             if ($dirptr&$testdir) {
                   3885:                 $isdir = 1;
                   3886:             }
                   3887:             push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
                   3888:         }
                   3889:     }
                   3890:     return @dir_lines;
                   3891: }
                   3892: 
1.329     droeschl 3893: sub is_supplemental_title {
                   3894:     my ($title) = @_;
                   3895:     return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
                   3896: }
                   3897: 
                   3898: # --------------------------------------------------------------- An entry line
                   3899: 
                   3900: sub entryline {
1.501     raeburn  3901:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598     raeburn  3902:         $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622     raeburn  3903:         $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581     raeburn  3904:     my ($foldertitle,$renametitle,$oldtitle);
1.329     droeschl 3905:     if (&is_supplemental_title($title)) {
1.488     raeburn  3906: 	($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329     droeschl 3907:     } else {
                   3908: 	$title=&HTML::Entities::encode($title,'"<>&\'');
                   3909: 	$renametitle=$title;
                   3910: 	$foldertitle=$title;
                   3911:     }
                   3912: 
1.611     raeburn  3913:     my ($disabled,$readonly,$js_lt);
                   3914:     unless ($canedit) {
                   3915:         $disabled = 'disabled="disabled"';
                   3916:         $readonly = 1;
                   3917:     }
                   3918: 
1.329     droeschl 3919:     my $orderidx=$LONCAPA::map::order[$index];
1.364     bisitz   3920: 
1.329     droeschl 3921:     $renametitle=~s/\\/\\\\/g;
                   3922:     $renametitle=~s/\&quot\;/\\\"/g;
1.585     raeburn  3923:     $renametitle=~s/"/%22/g;
1.581     raeburn  3924:     $renametitle=~s/ /%20/g;
                   3925:     $oldtitle = $renametitle;
1.576     raeburn  3926:     $renametitle=~s/\&#39;/\\\'/g;
1.379     bisitz   3927:     my $line=&Apache::loncommon::start_data_table_row();
1.538     raeburn  3928:     my ($form_start,$form_end,$form_common,$form_param);
1.329     droeschl 3929: # Edit commands
1.633     raeburn  3930:     my ($esc_path, $path, $symb, $curralias);
1.329     droeschl 3931:     if ($env{'form.folderpath'}) {
                   3932: 	$esc_path=&escape($env{'form.folderpath'});
                   3933: 	$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   3934: 	# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
                   3935:     }
1.505     raeburn  3936:     my $isexternal;
1.510     raeburn  3937:     if ($residx) {
1.501     raeburn  3938:         my $currurl = $url;
                   3939:         $currurl =~ s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
1.505     raeburn  3940:         if ($currurl =~ m{^/adm/wrapper/ext/}) {
                   3941:             $isexternal = 1;
                   3942:         }
1.510     raeburn  3943:         if (!$supplementalflag) {
                   3944:             my $path = 'uploaded/'.
                   3945:                        $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   3946:                        $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
                   3947:             $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
                   3948:                                                  $residx,
                   3949:                                                  &Apache::lonnet::declutter($currurl));
                   3950:         }
1.501     raeburn  3951:     }
1.538     raeburn  3952:     my ($renamelink,%lt,$ishash);
                   3953:     if (ref($filtersref) eq 'HASH') {
                   3954:         $ishash = 1;
                   3955:     }
                   3956: 
1.329     droeschl 3957:     if ($allowed) {
1.538     raeburn  3958:         $form_start = '
                   3959:    <form action="/adm/coursedocs" method="post">
                   3960: ';
                   3961:         $form_common=(<<END);
                   3962:    <input type="hidden" name="folderpath" value="$path" />
                   3963:    <input type="hidden" name="symb" value="$symb" />
                   3964: END
                   3965:         $form_param=(<<END);
                   3966:    <input type="hidden" name="setparms" value="$orderidx" />
                   3967:    <input type="hidden" name="changeparms" value="0" />
                   3968: END
                   3969:         $form_end = '</form>';
                   3970: 
1.329     droeschl 3971: 	my $incindex=$index+1;
                   3972: 	my $selectbox='';
1.471     raeburn  3973: 	if (($#LONCAPA::map::order>0) &&
1.329     droeschl 3974: 	    ((split(/\:/,
1.344     bisitz   3975: 	     $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
                   3976: 	     ne '') &&
1.329     droeschl 3977: 	    ((split(/\:/,
1.344     bisitz   3978: 	     $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329     droeschl 3979: 	     ne '')) {
                   3980: 	    $selectbox=
                   3981: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611     raeburn  3982: 		'<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329     droeschl 3983: 	    for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
                   3984: 		if ($i==$incindex) {
1.358     bisitz   3985: 		    $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329     droeschl 3986: 		} else {
                   3987: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
                   3988: 		}
                   3989: 	    }
                   3990: 	    $selectbox.='</select>';
                   3991: 	}
1.501     raeburn  3992: 	%lt=&Apache::lonlocal::texthash(
1.329     droeschl 3993:                 'up' => 'Move Up',
                   3994: 		'dw' => 'Move Down',
                   3995: 		'rm' => 'Remove',
                   3996:                 'ct' => 'Cut',
                   3997: 		'rn' => 'Rename',
1.501     raeburn  3998: 		'cp' => 'Copy',
1.633     raeburn  3999:                 'da' => 'Unset alias', 
                   4000:                 'sa' => 'Set alias',
1.501     raeburn  4001:                 'ex' => 'External Resource',
1.598     raeburn  4002:                 'et' => 'External Tool',
1.501     raeburn  4003:                 'ed' => 'Edit',
                   4004:                 'pr' => 'Preview',
                   4005:                 'sv' => 'Save',
                   4006:                 'ul' => 'URL',
1.611     raeburn  4007:                 'ti' => 'Title',
1.618     raeburn  4008:                 'er' => 'Editing rights unavailable for your current role.', 
1.501     raeburn  4009:                 );
1.538     raeburn  4010: 	my %denied = &action_restrictions($coursenum,$coursedom,$url,
                   4011:                                           $env{'form.folderpath'},
                   4012:                                           $currgroups);
1.517     raeburn  4013:         my ($copylink,$cutlink,$removelink);
1.329     droeschl 4014: 	my $skip_confirm = 0;
1.603     raeburn  4015:         my $confirm_removal = 0;
1.329     droeschl 4016: 	if ( $folder =~ /^supplemental/
                   4017: 	     || ($url =~ m{( /smppg$
                   4018: 			    |/syllabus$
                   4019: 			    |/aboutme$
                   4020: 			    |/navmaps$
                   4021: 			    |/bulletinboard$
1.626     raeburn  4022:                             |/ext\.tool$
1.505     raeburn  4023: 			    |\.html$)}x)
                   4024:              || $isexternal) {
1.329     droeschl 4025: 	    $skip_confirm = 1;
                   4026: 	}
1.603     raeburn  4027:         if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   4028:             ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   4029:             $confirm_removal = 1;
                   4030:         }
1.633     raeburn  4031:         if ($url =~ /$LONCAPA::assess_re/) {
                   4032:             $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
                   4033:         }
1.329     droeschl 4034: 
1.538     raeburn  4035: 	if ($denied{'copy'}) {
1.543     raeburn  4036:             $copylink=(<<ENDCOPY)
1.507     raeburn  4037: <span style="visibility: hidden;">$lt{'cp'}</span>
                   4038: ENDCOPY
                   4039:         } else {
1.538     raeburn  4040:             my $formname = 'edit_copy_'.$orderidx;
                   4041:             my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 4042: 	    $copylink=(<<ENDCOPY);
1.538     raeburn  4043: <form name="$formname" method="post" action="/adm/coursedocs">
                   4044: $form_common
1.611     raeburn  4045: <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>
1.538     raeburn  4046: $form_end
1.329     droeschl 4047: ENDCOPY
1.538     raeburn  4048:             if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
                   4049:                 push(@{$filtersref->{'cancopy'}},$orderidx);
                   4050:             }
1.329     droeschl 4051:         }
1.538     raeburn  4052: 	if ($denied{'cut'}) {
1.507     raeburn  4053:             $cutlink=(<<ENDCUT);
                   4054: <span style="visibility: hidden;">$lt{'ct'}</span>
                   4055: ENDCUT
                   4056:         } else {
1.538     raeburn  4057:             my $formname = 'edit_cut_'.$orderidx;
                   4058:             my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 4059: 	    $cutlink=(<<ENDCUT);
1.538     raeburn  4060: <form name="$formname" method="post" action="/adm/coursedocs">
                   4061: $form_common
1.542     raeburn  4062: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611     raeburn  4063: <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>
1.538     raeburn  4064: $form_end
1.329     droeschl 4065: ENDCUT
1.538     raeburn  4066:             if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
                   4067:                 push(@{$filtersref->{'cancut'}},$orderidx);
                   4068:             }
1.329     droeschl 4069:         }
1.538     raeburn  4070:         if ($denied{'remove'}) {
1.507     raeburn  4071:             $removelink=(<<ENDREM);
                   4072: <span style="visibility: hidden;">$lt{'rm'}</a>
                   4073: ENDREM
                   4074:         } else {
1.538     raeburn  4075:             my $formname = 'edit_remove_'.$orderidx;
1.603     raeburn  4076:             my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497     raeburn  4077:             $removelink=(<<ENDREM);
1.538     raeburn  4078: <form name="$formname" method="post" action="/adm/coursedocs">
                   4079: $form_common
1.542     raeburn  4080: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603     raeburn  4081: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611     raeburn  4082: <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>
1.538     raeburn  4083: $form_end
1.497     raeburn  4084: ENDREM
1.538     raeburn  4085:             if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
                   4086:                 push(@{$filtersref->{'canremove'}},$orderidx);
                   4087:             }
1.497     raeburn  4088:         }
1.551     raeburn  4089:         $renamelink=(<<ENDREN);
1.581     raeburn  4090: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507     raeburn  4091: ENDREN
1.611     raeburn  4092:         my ($uplink,$downlink);
                   4093:         if ($canedit) {
                   4094:             $uplink = "/adm/coursedocs?cmd=up_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   4095:             $downlink = "/adm/coursedocs?cmd=down_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   4096:         } else {
                   4097:             $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
                   4098:             $downlink = $uplink;
                   4099:         }
1.329     droeschl 4100: 	$line.=(<<END);
                   4101: <td>
1.379     bisitz   4102: <div class="LC_docs_entry_move">
1.611     raeburn  4103:   <a href="$uplink">
1.501     raeburn  4104:     <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379     bisitz   4105:   </a>
                   4106: </div>
                   4107: <div class="LC_docs_entry_move">
1.611     raeburn  4108:   <a href="$downlink">
1.501     raeburn  4109:     <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379     bisitz   4110:   </a>
                   4111: </div>
1.329     droeschl 4112: </td>
                   4113: <td>
                   4114:    $form_start
1.538     raeburn  4115:    $form_param
1.478     raeburn  4116:    $form_common
1.329     droeschl 4117:    $selectbox
                   4118:    $form_end
                   4119: </td>
1.540     raeburn  4120: <td class="LC_docs_entry_commands LC_nobreak">
1.497     raeburn  4121: $removelink
1.329     droeschl 4122: $cutlink
                   4123: $copylink
                   4124: </td>
                   4125: END
                   4126:     }
                   4127: # Figure out what kind of a resource this is
                   4128:     my ($extension)=($url=~/\.(\w+)$/);
                   4129:     my $uploaded=($url=~/^\/*uploaded\//);
                   4130:     my $icon=&Apache::loncommon::icon($url);
1.519     raeburn  4131:     my $isfolder;
                   4132:     my $ispage;
                   4133:     my $containerarg;
1.615     raeburn  4134:     my $folderurl;
1.329     droeschl 4135:     if ($uploaded) {
1.472     raeburn  4136:         if (($extension eq 'sequence') || ($extension eq 'page')) {
                   4137:             $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519     raeburn  4138:             $containerarg = $1;
1.472     raeburn  4139: 	    if ($extension eq 'sequence') {
                   4140: 	        $icon=$iconpath.'navmap.folder.closed.gif';
                   4141:                 $isfolder=1;
                   4142:             } else {
                   4143:                 $icon=$iconpath.'page.gif';
                   4144:                 $ispage=1;
                   4145:             }
1.615     raeburn  4146:             $folderurl = &Apache::lonnet::declutter($url);
1.472     raeburn  4147:             if ($allowed) {
                   4148:                 $url='/adm/coursedocs?';
                   4149:             } else {
                   4150:                 $url='/adm/supplemental?';
                   4151:             }
1.329     droeschl 4152: 	} else {
                   4153: 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
                   4154: 	}
                   4155:     }
1.364     bisitz   4156: 
1.621     raeburn  4157:     my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329     droeschl 4158:     my $orig_url = $url;
1.340     raeburn  4159:     $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.668     raeburn  4160:     if ($container eq 'page') {
                   4161:         $url=~s{^http(|s)(&colon;|:)//}{/ext/};
                   4162:     } else {
                   4163:         $url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
                   4164:     }
1.501     raeburn  4165:     if (!$supplementalflag && $residx && $symb) {
                   4166:         if ((!$isfolder) && (!$ispage)) {
                   4167: 	    (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668     raeburn  4168:             if (($url =~ m{^ext/}) && ($container eq 'page')) {
                   4169:                 $url=&Apache::lonnet::clutter_with_no_wrapper($url);
                   4170:             } else {
                   4171:                 $url=&Apache::lonnet::clutter($url);
                   4172:             } 
1.501     raeburn  4173: 	    if ($url=~/^\/*uploaded\//) {
                   4174: 	        $url=~/\.(\w+)$/;
                   4175: 	        my $embstyle=&Apache::loncommon::fileembstyle($1);
                   4176: 	        if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                   4177: 		    $url='/adm/wrapper'.$url;
                   4178: 	        } elsif ($embstyle eq 'ssi') {
                   4179: 		    #do nothing with these
                   4180: 	        } elsif ($url!~/\.(sequence|page)$/) {
                   4181: 		    $url='/adm/coursedocs/showdoc'.$url;
                   4182: 	        }
1.623     raeburn  4183: 	    } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
                   4184:                 my $wrapped = $1;
                   4185:                 my $exturl = $2;
1.668     raeburn  4186:                 if (($wrapped eq '') && ($container ne 'page')) { 
1.623     raeburn  4187:                     $url='/adm/wrapper'.$url;
                   4188:                 }
                   4189:                 if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
                   4190:                     $nomodal = 1;
                   4191:                 }
1.626     raeburn  4192: 	    } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4193: 		$url='/adm/wrapper'.$url;
1.621     raeburn  4194:             } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
                   4195:                 if (($ENV{'SERVER_PORT'} == 443) &&
                   4196:                     ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.657     raeburn  4197:                     unless (&Apache::lonnet::uses_sts()) {
                   4198:                         $url .= '?usehttp=1';
                   4199:                     }
1.621     raeburn  4200:                     $nomodal = 1;
                   4201:                 }
1.598     raeburn  4202:             }
1.501     raeburn  4203:             if (&Apache::lonnet::symbverify($symb,$url)) {
1.609     raeburn  4204:                 my $shownsymb = $symb;
                   4205:                 if ($isexternal) {
1.670     raeburn  4206:                     $url =~ s/\#[^#]+$//;
1.668     raeburn  4207:                     if ($container eq 'page') {
                   4208:                         $url = &Apache::lonnet::clutter($url);
                   4209:                     }
1.609     raeburn  4210:                 }
1.617     raeburn  4211:                 unless ($env{'request.role.adv'}) {
                   4212:                     if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4213:                         $url = '';
                   4214:                     }
                   4215:                     if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
                   4216:                         $url = '';
                   4217:                         $hiddenres = 1;
                   4218:                     }
                   4219:                 }
                   4220:                 if ($url ne '') {
1.641     raeburn  4221:                     $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.617     raeburn  4222:                 }
1.615     raeburn  4223:             } elsif (!$env{'request.role.adv'}) {
                   4224:                 my $checkencrypt;
                   4225:                 if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
                   4226:                       $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
                   4227:                     $checkencrypt = 1;
1.620     raeburn  4228:                 } elsif (ref($navmapref)) {
1.615     raeburn  4229:                     unless (ref($$navmapref)) {
                   4230:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   4231:                     }
                   4232:                     if (ref($$navmapref)) {
                   4233:                         if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
                   4234:                             $checkencrypt = 1;       
                   4235:                         }
                   4236:                     }
                   4237:                 }
                   4238:                 if ($checkencrypt) {
                   4239:                     my $shownsymb = &Apache::lonenc::encrypted($symb);
                   4240:                     my $shownurl = &Apache::lonenc::encrypted($url);
                   4241:                     if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.641     raeburn  4242:                         $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.615     raeburn  4243:                         if ($env{'request.enc'} ne '') {
                   4244:                             delete($env{'request.enc'});
                   4245:                         }
                   4246:                     } else {
                   4247:                         $url='';
1.613     raeburn  4248:                     }
1.612     raeburn  4249:                 } else {
                   4250:                     $url='';
                   4251:                 }
1.501     raeburn  4252:             } else {
                   4253:                 $url='';
                   4254:             }
1.329     droeschl 4255: 	}
1.621     raeburn  4256:     } elsif ($supplementalflag) {
1.610     raeburn  4257:         if ($isexternal) {
                   4258:             if ($url =~ /^([^#]+)#([^#]+)$/) {
                   4259:                 $url = $1;
                   4260:                 $anchor = $2;
1.623     raeburn  4261:                 if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.657     raeburn  4262:                     unless (&Apache::lonnet::uses_sts()) {
                   4263:                         if ($hostname ne '') {
                   4264:                             $url = 'http://'.$hostname.$url;
                   4265:                         }
                   4266:                         $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.623     raeburn  4267:                     }
                   4268:                     $nomodal = 1;
                   4269:                 }
1.610     raeburn  4270:             }
1.621     raeburn  4271:         } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   4272:             if (($ENV{'SERVER_PORT'} == 443) &&
                   4273:                 ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.657     raeburn  4274:                 unless (&Apache::lonnet::uses_sts()) {
                   4275:                     if ($hostname ne '') {
                   4276:                         $url = 'http://'.$hostname.$url;
                   4277:                     }
                   4278:                     $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  4279:                 }
1.621     raeburn  4280:                 $nomodal = 1;
                   4281:             }
1.610     raeburn  4282:         }
1.329     droeschl 4283:     }
1.615     raeburn  4284:     my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617     raeburn  4285:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519     raeburn  4286:     if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329     droeschl 4287: 	my $foldername=&escape($foldertitle);
                   4288: 	my $folderpath=$env{'form.folderpath'};
                   4289: 	if ($folderpath) { $folderpath.='&' };
1.510     raeburn  4290:         if (!$allowed && $supplementalflag) {
1.519     raeburn  4291:             $folderpath.=$containerarg.'&'.$foldername;
1.510     raeburn  4292:             $url.='folderpath='.&escape($folderpath);
                   4293:         } else {
1.617     raeburn  4294:             my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
                   4295:                                                         'parameter_randompick'))[0];
                   4296:             my $randorder = ((&LONCAPA::map::getparameter($orderidx,
                   4297:                                               'parameter_randomorder'))[0]=~/^yes$/i);
                   4298:             my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
                   4299:                                               'parameter_hiddenresource'))[0]=~/^yes$/i);
                   4300:             my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
                   4301:                                               'parameter_encrypturl'))[0]=~/^yes$/i);
                   4302:             unless ($hiddenmap) {
1.620     raeburn  4303:                 if (ref($navmapref)) {
                   4304:                     unless (ref($$navmapref)) {
                   4305:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   4306:                     }
                   4307:                     if (ref($$navmapref)) {
                   4308:                         if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
                   4309:                             my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
                   4310:                             unless (@resources) {
                   4311:                                 $hiddenmap = 1;
                   4312:                                 unless ($env{'request.role.adv'}) {  
                   4313:                                     $url = '';
                   4314:                                     $hiddenfolder = 1;
                   4315:                                 }
1.617     raeburn  4316:                             }
1.615     raeburn  4317:                         }
                   4318:                     }
                   4319:                 }
                   4320:             }
1.617     raeburn  4321:             unless ($encryptmap) {
1.620     raeburn  4322:                 if ((ref($navmapref)) && (ref($$navmapref))) {
                   4323:                     if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
                   4324:                         $encryptmap = 1;
                   4325:                     }
1.617     raeburn  4326:                 }
                   4327:             }
1.630     raeburn  4328: 
1.617     raeburn  4329: # Append randompick number, hidden, and encrypted with ":" to foldername,
                   4330: # so it gets transferred between levels
                   4331: 	    $folderpath.=$containerarg.'&'.$foldername.
                   4332:                          ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615     raeburn  4333:             unless ($url eq '') {
1.612     raeburn  4334:                 $url.='folderpath='.&escape($folderpath);
                   4335:             }
1.510     raeburn  4336:             my $rpckchk;
                   4337:             if ($rpicknum) {
                   4338:                 $rpckchk = ' checked="checked"';
1.543     raeburn  4339:                 if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
                   4340:                     push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
                   4341:                 }
1.510     raeburn  4342:             }
1.537     raeburn  4343:             my $formname = 'edit_randompick_'.$orderidx;
1.510     raeburn  4344: 	    $rand_pick_text = 
1.478     raeburn  4345: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  4346: $form_param."\n".
1.478     raeburn  4347: $form_common."\n".
1.611     raeburn  4348: '<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  4349:             if ($rpicknum ne '') {
                   4350:                 $rand_pick_text .= ':&nbsp;<a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
                   4351:             }
1.537     raeburn  4352:             $rand_pick_text .= '</span></span>'.
                   4353:                                $form_end;
1.543     raeburn  4354:             my $ro_set;
1.617     raeburn  4355:             if ($randorder) {
1.543     raeburn  4356:                 $ro_set = 'checked="checked"';
                   4357:                 if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
                   4358:                     push(@{$filtersref->{'randomorder'}},$orderidx);
                   4359:                 }
                   4360:             }
1.564     raeburn  4361:             $formname = 'edit_rorder_'.$orderidx;
1.510     raeburn  4362: 	    $rand_order_text = 
1.537     raeburn  4363: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  4364: $form_param."\n".
1.537     raeburn  4365: $form_common."\n".
1.611     raeburn  4366: '<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  4367: $form_end; 
1.510     raeburn  4368:         }
1.509     raeburn  4369:     } elsif ($supplementalflag && !$allowed) {
1.598     raeburn  4370:         my $isexttool;
1.626     raeburn  4371:         if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4372:             $url='/adm/wrapper'.$url;
                   4373:             $isexttool = 1;
                   4374:         }
1.510     raeburn  4375:         $url .= ($url =~ /\?/) ? '&amp;':'?';
1.509     raeburn  4376:         $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510     raeburn  4377:         if ($title) {
                   4378:             $url .= '&amp;title='.&HTML::Entities::encode($renametitle,'<>&"');
                   4379:         }
1.598     raeburn  4380:         if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510     raeburn  4381:             $url .= '&amp;idx='.$orderidx;
                   4382:         }
1.610     raeburn  4383:         if ($anchor ne '') {
                   4384:             $url .= '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   4385:         }
1.329     droeschl 4386:     }
1.519     raeburn  4387:     my ($tdalign,$tdwidth);
1.501     raeburn  4388:     if ($allowed) {
1.630     raeburn  4389:         my $fileloc =
1.501     raeburn  4390:             &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510     raeburn  4391:         if ($isexternal) {
1.630     raeburn  4392:             ($editlink,$extresform) =
1.611     raeburn  4393:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   4394:                                                      undef,undef,undef,undef,undef,undef,
                   4395:                                                      undef,$disabled);
1.626     raeburn  4396:         } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4397:             ($editlink,$extresform) =
                   4398:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   4399:                                                      undef,undef,undef,'tool',$coursedom,
1.611     raeburn  4400:                                                      $coursenum,$ltitoolsref,$disabled);
1.511     raeburn  4401:         } elsif (!$isfolder && !$ispage) {
1.503     raeburn  4402:             my ($cfile,$home,$switchserver,$forceedit,$forceview) = 
                   4403:                 &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511     raeburn  4404:             if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610     raeburn  4405:                 my $suppanchor;
                   4406:                 if ($supplementalflag) {
                   4407:                     $suppanchor = $anchor;
                   4408:                 }
1.630     raeburn  4409:                 my $jscall =
1.501     raeburn  4410:                     &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
                   4411:                                                             $switchserver,
1.503     raeburn  4412:                                                             $forceedit,
1.511     raeburn  4413:                                                             undef,$symb,
                   4414:                                                             &escape($env{'form.folderpath'}),
1.622     raeburn  4415:                                                             $renametitle,$hostname,
                   4416:                                                             '','',1,$suppanchor);
1.501     raeburn  4417:                 if ($jscall) {
1.518     raeburn  4418:                     $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
                   4419:                                 $jscall.'" >'.&mt('Edit').'</a>&nbsp;'."\n";
1.501     raeburn  4420:                 }
                   4421:             }
                   4422:         }
1.519     raeburn  4423:         $tdalign = ' align="right" valign="top"';
                   4424:         $tdwidth = ' width="80%"';
1.329     droeschl 4425:     }
1.408     raeburn  4426:     my $reinit;
                   4427:     if ($crstype eq 'Community') {
                   4428:         $reinit = &mt('(re-initialize community to access)');
                   4429:     } else {
                   4430:         $reinit = &mt('(re-initialize course to access)');
1.519     raeburn  4431:     }
                   4432:     $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650     raeburn  4433:     if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633     raeburn  4434:         $line.= '<br />';
                   4435:         if ($curralias ne '') {
                   4436:             $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   4437:                    $lt{'da'}.'</a></span>';
                   4438:         } else {
                   4439:             $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   4440:                    $lt{'sa'}.'</a></span>';
                   4441:         }
                   4442:     }
                   4443:     $line.='</td><td>';
1.621     raeburn  4444:     my $link;
1.472     raeburn  4445:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469     www      4446:        $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
                   4447:     } elsif ($url) {
1.610     raeburn  4448:        if ($anchor ne '') {
                   4449:            if ($supplementalflag) {
                   4450:                $anchor = '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   4451:            } else {
                   4452:                $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
                   4453:            }
                   4454:        }
1.622     raeburn  4455:        if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
                   4456:            $link = 'http://'.$hostname.$url;
                   4457:        } else {
                   4458:            $link = $url;
                   4459:        }
1.659     raeburn  4460:        $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.$anchor);
1.621     raeburn  4461:        if ($nomodal) {
                   4462:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   4463:                   '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
                   4464:        } else {
                   4465:            $line.=&Apache::loncommon::modal_link($link,
                   4466:                                                  '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
                   4467:        }
1.469     www      4468:     } else {
                   4469:        $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
                   4470:     }
1.519     raeburn  4471:     $line.='</span></td><td'.$tdwidth.'>';
1.472     raeburn  4472:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469     www      4473:        $line.='<a href="'.$url.'">'.$title.'</a>';
                   4474:     } elsif ($url) {
1.621     raeburn  4475:        if ($nomodal) {
                   4476:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   4477:                   $title.'</a>';
                   4478:        } else {
                   4479:            $line.=&Apache::loncommon::modal_link($link,$title,600,500);
                   4480:        }
1.617     raeburn  4481:     } elsif (($hiddenfolder) || ($hiddenres)) {
1.632     raeburn  4482:        $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469     www      4483:     } else {
                   4484:        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
                   4485:     }
1.633     raeburn  4486:     if (($allowed) && ($curralias ne '')) {
                   4487:         $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
                   4488:     } else {
                   4489:         $line .= $extresform;
                   4490:     }
                   4491:     $line .= '</td>';
1.478     raeburn  4492:     $rand_pick_text = '&nbsp;' if ($rand_pick_text eq '');
                   4493:     $rand_order_text = '&nbsp;' if ($rand_order_text eq '');
1.329     droeschl 4494:     if (($allowed) && ($folder!~/^supplemental/)) {
                   4495:  	my %lt=&Apache::lonlocal::texthash(
                   4496:  			      'hd' => 'Hidden',
                   4497:  			      'ec' => 'URL hidden');
1.543     raeburn  4498:         my ($enctext,$hidtext);
                   4499:         if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
                   4500:             $enctext = ' checked="checked"';
                   4501:             if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
                   4502:                 push(@{$filtersref->{'encrypturl'}},$orderidx);
                   4503:             }
                   4504:         }
                   4505:         if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4506:             $hidtext = ' checked="checked"';
                   4507:             if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
                   4508:                 push(@{$filtersref->{'hiddenresource'}},$orderidx);
                   4509:             }
                   4510:         }
1.537     raeburn  4511:         my $formhidden = 'edit_hiddenresource_'.$orderidx;
                   4512:         my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329     droeschl 4513: 	$line.=(<<ENDPARMS);
                   4514:   <td class="LC_docs_entry_parameter">
1.537     raeburn  4515:     <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538     raeburn  4516:     $form_param
1.478     raeburn  4517:     $form_common
1.611     raeburn  4518:     <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329     droeschl 4519:     $form_end
1.458     raeburn  4520:     <br />
1.537     raeburn  4521:     <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538     raeburn  4522:     $form_param
1.478     raeburn  4523:     $form_common
1.611     raeburn  4524:     <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329     droeschl 4525:     $form_end
                   4526:   </td>
1.478     raeburn  4527:   <td class="LC_docs_entry_parameter">$rand_pick_text<br />
                   4528:                                       $rand_order_text</td>
1.329     droeschl 4529: ENDPARMS
                   4530:     }
1.379     bisitz   4531:     $line.=&Apache::loncommon::end_data_table_row();
1.329     droeschl 4532:     return $line;
                   4533: }
                   4534: 
1.538     raeburn  4535: sub action_restrictions {
                   4536:     my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
                   4537:     my %denied = (
                   4538:                    cut    => 0,
                   4539:                    copy   => 0,
                   4540:                    remove => 0,
                   4541:                  );
                   4542:     if ($url=~ m{^/res/.+\.(page|sequence)$}) {
                   4543:         # no copy for published maps
                   4544:         $denied{'copy'} = 1;
1.597     raeburn  4545:     } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
                   4546:         unless ($1 eq 'simpleproblem') {
                   4547:             $denied{'copy'} = 1;
                   4548:         }
                   4549:         $denied{'cut'} = 1;
1.538     raeburn  4550:     } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
                   4551:         if ($folderpath =~ /^default&[^\&]+$/) {
                   4552:             if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
                   4553:                 $denied{'remove'} = 1;
                   4554:             }
                   4555:             $denied{'cut'} = 1;
                   4556:             $denied{'copy'} = 1;
                   4557:         }
                   4558:     } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
                   4559:         my $group = $1;
                   4560:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
                   4561:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   4562:                 $denied{'remove'} = 1;
                   4563:             }
                   4564:         }
                   4565:         $denied{'cut'} = 1;
                   4566:         $denied{'copy'} = 1;
                   4567:     } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
                   4568:         my $group = $1;
                   4569:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
                   4570:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   4571:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   4572:                 if (keys(%groupsettings) > 0) {
                   4573:                     $denied{'remove'} = 1;
                   4574:                 }
                   4575:                 $denied{'cut'} = 1;
                   4576:                 $denied{'copy'} = 1;
                   4577:             }
                   4578:         }
                   4579:     } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
                   4580:         my $group = $1;
                   4581:         if ($url =~ /group_boards_\Q$group\E/) {
                   4582:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   4583:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   4584:                 if (keys(%groupsettings) > 0) {
                   4585:                     if (ref($groupsettings{'functions'}) eq 'HASH') {
                   4586:                         if ($groupsettings{'functions'}{'discussion'} eq 'on') {
                   4587:                             $denied{'remove'} = 1;
                   4588:                         }
                   4589:                     }
                   4590:                 }
                   4591:                 $denied{'cut'} = 1;
                   4592:                 $denied{'copy'} = 1;
                   4593:             }
                   4594:         }
                   4595:     }
                   4596:     return %denied;
                   4597: }
                   4598: 
1.533     raeburn  4599: sub new_timebased_suffix {
1.538     raeburn  4600:     my ($dom,$num,$type,$area,$container) = @_;
1.533     raeburn  4601:     my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538     raeburn  4602:     if ($type eq 'paste') {
                   4603:         $prefix = $type;
                   4604:         $namespace = 'courseeditor';
1.587     raeburn  4605:         $idtype = 'addcode';
1.538     raeburn  4606:     } elsif ($type eq 'map') {
1.533     raeburn  4607:         $prefix = 'docs';
                   4608:         if ($area eq 'supplemental') {
                   4609:             $prefix = 'supp';
                   4610:         }
                   4611:         $prefix .= $container;
                   4612:         $namespace = 'uploadedmaps';
                   4613:     } else {
                   4614:         $prefix = $type;
                   4615:         $namespace = 'templated';
1.504     raeburn  4616:     }
                   4617:     my ($suffix,$freedlock,$error) =
1.587     raeburn  4618:         &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504     raeburn  4619:     if (!$suffix) {
1.538     raeburn  4620:         if ($type eq 'paste') {
                   4621:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
                   4622:         } elsif ($type eq 'map') {
1.533     raeburn  4623:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
                   4624:         } elsif ($type eq 'smppg') {
                   4625:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626     raeburn  4626:         } elsif ($type eq 'exttool') {
                   4627:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533     raeburn  4628:         } else {
1.565     bisitz   4629:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533     raeburn  4630:         }
1.504     raeburn  4631:         if ($error) {
                   4632:             $errtext .= '<br />'.$error;
                   4633:         }
                   4634:     }
                   4635:     if ($freedlock ne 'ok') {
1.630     raeburn  4636:         $locknotfreed =
1.533     raeburn  4637:             '<div class="LC_error">'.
                   4638:             &mt('There was a problem removing a lockfile.').' ';
1.538     raeburn  4639:         if ($type eq 'paste') {
1.591     raeburn  4640:             if ($freedlock eq 'nolock') {
                   4641:                 $locknotfreed =
                   4642:                     '<div class="LC_error">'.
                   4643:                     &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
                   4644:  
1.593     droeschl 4645:                     &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591     raeburn  4646:             } else { 
                   4647:                 $locknotfreed .=
                   4648:                     &mt('This will prevent addition of items to the clipboard until your next log-in.');
                   4649:             }
1.538     raeburn  4650:         } elsif ($type eq 'map') {
1.591     raeburn  4651:             $locknotfreed .=
                   4652:                 &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533     raeburn  4653:         } elsif ($type eq 'smppg') {
                   4654:             $locknotfreed .=
                   4655:                 &mt('This will prevent creation of additional simple pages in this course.');
1.626     raeburn  4656:         } elsif ($type eq 'exttool') {
                   4657:             $locknotfreed .=
                   4658:                 &mt('This will prevent creation of additional external tools in this course.');
1.533     raeburn  4659:         } else {
                   4660:             $locknotfreed .=
1.565     bisitz   4661:                 &mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  4662:         }
1.538     raeburn  4663:         unless ($type eq 'paste') {
                   4664:             $locknotfreed .=
1.560     raeburn  4665:                 ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   4666:                         '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538     raeburn  4667:         }
                   4668:         $locknotfreed .= '</div>';
1.504     raeburn  4669:     }
                   4670:     return ($suffix,$errtext,$locknotfreed);
                   4671: }
                   4672: 
1.329     droeschl 4673: =pod
                   4674: 
                   4675: =item tiehash()
                   4676: 
                   4677: tie the hash
                   4678: 
                   4679: =cut
                   4680: 
                   4681: sub tiehash {
                   4682:     my ($mode)=@_;
                   4683:     $hashtied=0;
                   4684:     if ($env{'request.course.fn'}) {
                   4685: 	if ($mode eq 'write') {
                   4686: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   4687: 		    &GDBM_WRCREAT(),0640)) {
                   4688:                 $hashtied=2;
                   4689: 	    }
                   4690: 	} else {
                   4691: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   4692: 		    &GDBM_READER(),0640)) {
                   4693:                 $hashtied=1;
                   4694: 	    }
                   4695: 	}
1.364     bisitz   4696:     }
1.329     droeschl 4697: }
                   4698: 
                   4699: sub untiehash {
                   4700:     if ($hashtied) { untie %hash; }
                   4701:     $hashtied=0;
                   4702:     return OK;
                   4703: }
                   4704: 
                   4705: 
                   4706: 
                   4707: 
                   4708: sub checkonthis {
1.637     raeburn  4709:     my ($r,$url,$level,$title,$checkstale)=@_;
1.329     droeschl 4710:     $url=&unescape($url);
                   4711:     $alreadyseen{$url}=1;
                   4712:     $r->rflush();
                   4713:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
                   4714:        $r->print("\n<br />");
                   4715:        if ($level==0) {
                   4716:            $r->print("<br />");
                   4717:        }
                   4718:        for (my $i=0;$i<=$level*5;$i++) {
                   4719:            $r->print('&nbsp;');
                   4720:        }
                   4721:        $r->print('<a href="'.$url.'" target="cat">'.
                   4722: 		 ($title?$title:$url).'</a> ');
                   4723:        if ($url=~/^\/res\//) {
1.637     raeburn  4724:           my $updated;
                   4725:           if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
                   4726:               ($url !~ /\.\d+\.\w+$/)) {
                   4727:               $updated = &Apache::lonnet::remove_stale_resfile($url);
                   4728:           }
1.329     droeschl 4729: 	  my $result=&Apache::lonnet::repcopy(
                   4730:                               &Apache::lonnet::filelocation('',$url));
                   4731:           if ($result eq 'ok') {
                   4732:              $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637     raeburn  4733:              if ($updated) {
                   4734:                  $r->print('<br />');
                   4735:                  for (my $i=0;$i<=$level*5;$i++) {
                   4736:                      $r->print('&nbsp;');
                   4737:                  }
                   4738:                  $r->print('- '.&mt('Outdated copy removed'));
                   4739:              }
1.329     droeschl 4740:              $r->rflush();
                   4741:              &Apache::lonnet::countacc($url);
                   4742:              $url=~/\.(\w+)$/;
                   4743:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                   4744: 		 $r->print('<br />');
                   4745:                  $r->rflush();
                   4746:                  for (my $i=0;$i<=$level*5;$i++) {
                   4747:                      $r->print('&nbsp;');
                   4748:                  }
                   4749:                  $r->print('- '.&mt('Rendering:').' ');
                   4750: 		 my ($errorcount,$warningcount)=split(/:/,
                   4751: 	       &Apache::lonnet::ssi_body($url,
                   4752: 			       ('grade_target'=>'web',
                   4753: 				'return_only_error_and_warning_counts' => 1)));
                   4754:                  if (($errorcount) ||
                   4755:                      ($warningcount)) {
                   4756: 		     if ($errorcount) {
1.369     bisitz   4757:                         $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329     droeschl 4758:                           &mt('[quant,_1,error]',$errorcount).'</span>');
                   4759:                      }
                   4760: 		     if ($warningcount) {
                   4761:                         $r->print('<span class="LC_warning">'.
                   4762:                           &mt('[quant,_1,warning]',$warningcount).'</span>');
                   4763:                      }
                   4764:                  } else {
                   4765:                      $r->print('<span class="LC_success">'.&mt('ok').'</span>');
                   4766:                  }
                   4767:                  $r->rflush();
                   4768:              }
                   4769: 	     my $dependencies=
                   4770:                 &Apache::lonnet::metadata($url,'dependencies');
                   4771:              foreach my $dep (split(/\,/,$dependencies)) {
                   4772: 		 if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637     raeburn  4773:                     &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329     droeschl 4774:                  }
                   4775:              }
                   4776:           } elsif ($result eq 'unavailable') {
                   4777:              $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
                   4778:           } elsif ($result eq 'not_found') {
                   4779: 	      unless ($url=~/\$/) {
1.521     bisitz   4780: 		  $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329     droeschl 4781: 	      } else {
1.366     bisitz   4782: 		  $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329     droeschl 4783: 	      }
                   4784:           } else {
                   4785:              $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
                   4786:           }
1.637     raeburn  4787:           if (($updated) && ($result ne 'ok')) {
                   4788:               $r->print('<br />'.&mt('Outdated copy removed'));
                   4789:           }
1.329     droeschl 4790:        }
                   4791:     }
                   4792: }
                   4793: 
                   4794: 
                   4795: 
                   4796: =pod
                   4797: 
                   4798: =item list_symbs()
                   4799: 
1.485     raeburn  4800: List Content Identifiers
1.329     droeschl 4801: 
                   4802: =cut
                   4803: 
                   4804: sub list_symbs {
                   4805:     my ($r) = @_;
                   4806: 
1.408     raeburn  4807:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  4808:     $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
                   4809:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
                   4810:     $r->print(&startContentScreen('tools'));
1.329     droeschl 4811:     my $navmap = Apache::lonnavmaps::navmap->new();
                   4812:     if (!defined($navmap)) {
                   4813:         $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
                   4814:                   '<div class="LC_error">'.
                   4815:                   &mt('Unable to retrieve information about course contents').
                   4816:                   '</div>');
1.408     raeburn  4817:         &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329     droeschl 4818:     } else {
1.484     raeburn  4819:         $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
                   4820:                   &Apache::loncommon::start_data_table().
                   4821:                   &Apache::loncommon::start_data_table_header_row().
                   4822:                   '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
                   4823:                   &Apache::loncommon::end_data_table_header_row()."\n");
                   4824:         my $count;
1.329     droeschl 4825:         foreach my $res ($navmap->retrieveResources()) {
1.484     raeburn  4826:             $r->print(&Apache::loncommon::start_data_table_row().
                   4827:                       '<td>'.$res->compTitle().'</td>'.
                   4828:                       '<td>'.$res->symb().'</td>'.
1.521     bisitz   4829:                       &Apache::loncommon::end_data_table_row());
1.484     raeburn  4830:             $count ++;
                   4831:         }
                   4832:         if (!$count) {
                   4833:             $r->print(&Apache::loncommon::start_data_table_row().
                   4834:                       '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
                   4835:                       &Apache::loncommon::end_data_table_row()); 
1.329     droeschl 4836:         }
1.484     raeburn  4837:         $r->print(&Apache::loncommon::end_data_table());
1.329     droeschl 4838:     }
1.521     bisitz   4839:     $r->print(&endContentScreen());
1.329     droeschl 4840: }
                   4841: 
1.651     raeburn  4842: sub short_urls {
                   4843:     my ($r,$canedit) = @_;
                   4844:     my $crstype = &Apache::loncommon::course_type();
                   4845:     my $formname = 'shortenurl';
                   4846:     $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
                   4847:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
                   4848:     $r->print(&startContentScreen('tools'));
                   4849:     my ($navmap,$errormsg) =
                   4850:         &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
                   4851:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   4852:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   4853:     my (%maps,%resources,%titles);
                   4854:     if (!ref($navmap)) {
                   4855:         $r->print($errormsg.
                   4856:                   &endContentScreen());
                   4857:         return '';
                   4858:     } else {
1.652     raeburn  4859:         $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651     raeburn  4860:         $r->rflush();
                   4861:         my $readonly;
                   4862:         if ($canedit) {
1.671     raeburn  4863:             my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651     raeburn  4864:             if ($numnew) {
                   4865:                 $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
                   4866:             }
                   4867:             if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
                   4868:                 $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
                   4869:                 foreach my $error (@{$errors}) {
                   4870:                     $r->print('<li>'.$error.'</li>');
                   4871:                 }
                   4872:                 $r->print('</ul><br />');
                   4873:             }
                   4874:         } else {
                   4875:             $readonly = 1;
                   4876:         }
                   4877:         my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
                   4878:         $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
                   4879:                                                              undef,undef,undef,undef,undef,\%currtiny,$readonly));
                   4880:     }
                   4881:     $r->print(&endContentScreen());
                   4882: }
                   4883: 
1.637     raeburn  4884: sub contentverifyform {
                   4885:     my ($r) = @_;
                   4886:     my $crstype = &Apache::loncommon::course_type();
                   4887:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   4888:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
                   4889:     $r->print(&startContentScreen('tools'));
                   4890:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
                   4891:     $r->print('<form method="post" action="/adm/coursedocs"><p>'.
                   4892:               &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
                   4893:               '&nbsp;<span class="LC_nobreak">'.
                   4894:               '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
                   4895:               &mt('No').'</label>'.('&nbsp;'x2).
                   4896:               '<label><input type="radio" name="checkstale" value="1" />'.
                   4897:               &mt('Yes').'</label></span></p><p>'.
                   4898:               '<input type="submit" value="'.&mt('Verify content').' "/>'.
                   4899:               '<input type="hidden" value="1" name="tools" />'.
                   4900:               '<input type="hidden" value="1" name="verify" /></p></form>');
                   4901:     $r->print(&endContentScreen());
                   4902:     return;
                   4903: }
1.329     droeschl 4904: 
                   4905: sub verifycontent {
1.637     raeburn  4906:     my ($r,$checkstale) = @_;
1.408     raeburn  4907:     my $crstype = &Apache::loncommon::course_type();
1.549     raeburn  4908:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   4909:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484     raeburn  4910:     $r->print(&startContentScreen('tools'));
                   4911:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>'); 
1.329     droeschl 4912:    $hashtied=0;
                   4913:    undef %alreadyseen;
                   4914:    %alreadyseen=();
                   4915:    &tiehash();
1.484     raeburn  4916:    
1.329     droeschl 4917:    foreach my $key (keys(%hash)) {
                   4918:        if ($hash{$key}=~/\.(page|sequence)$/) {
                   4919: 	   if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
                   4920: 	       $r->print('<hr /><span class="LC_error">'.
1.419     bisitz   4921: 			 &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329     droeschl 4922: 			 &unescape($hash{$key}).'</span><br />'.
1.419     bisitz   4923: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329     droeschl 4924: 	   }
                   4925:        }
                   4926:        if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637     raeburn  4927:            &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329     droeschl 4928:        }
                   4929:    }
                   4930:    &untiehash();
1.442     www      4931:    $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521     bisitz   4932:     $r->print(&endContentScreen());
1.329     droeschl 4933: }
                   4934: 
                   4935: sub devalidateversioncache {
                   4936:     my $src=shift;
                   4937:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
                   4938: 					  &Apache::lonnet::clutter($src));
                   4939: }
                   4940: 
                   4941: sub checkversions {
1.611     raeburn  4942:     my ($r,$canedit) = @_;
1.408     raeburn  4943:     my $crstype = &Apache::loncommon::course_type();
1.571     raeburn  4944:     $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
                   4945:     $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484     raeburn  4946:     $r->print(&startContentScreen('tools'));
1.442     www      4947: 
1.329     droeschl 4948:     my $header='';
                   4949:     my $startsel='';
                   4950:     my $monthsel='';
                   4951:     my $weeksel='';
                   4952:     my $daysel='';
                   4953:     my $allsel='';
                   4954:     my %changes=();
                   4955:     my $starttime=0;
                   4956:     my $haschanged=0;
                   4957:     my %setversions=&Apache::lonnet::dump('resourceversions',
                   4958: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   4959: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   4960: 
                   4961:     $hashtied=0;
                   4962:     &tiehash();
1.611     raeburn  4963:     if ($canedit) {
                   4964:         my %newsetversions=();
                   4965:         if ($env{'form.setmostrecent'}) {
                   4966: 	    $haschanged=1;
                   4967: 	    foreach my $key (keys(%hash)) {
                   4968: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   4969: 		    $newsetversions{$1}='mostrecent';
                   4970:                     &devalidateversioncache($1);
                   4971: 	        }
                   4972: 	    }
                   4973:         } elsif ($env{'form.setcurrent'}) {
                   4974: 	    $haschanged=1;
                   4975: 	    foreach my $key (keys(%hash)) {
                   4976: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   4977: 		    my $getvers=&Apache::lonnet::getversion($1);
                   4978: 		    if ($getvers>0) {
                   4979: 		        $newsetversions{$1}=$getvers;
                   4980: 		        &devalidateversioncache($1);
                   4981: 		    }
                   4982: 	        }
1.329     droeschl 4983: 	    }
1.611     raeburn  4984:         } elsif ($env{'form.setversions'}) {
                   4985: 	    $haschanged=1;
                   4986: 	    foreach my $key (keys(%env)) {
                   4987: 	        if ($key=~/^form\.set_version_(.+)$/) {
                   4988: 		    my $src=$1;
                   4989: 		    if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
                   4990: 		        $newsetversions{$src}=$env{$key};
                   4991: 		        &devalidateversioncache($src);
                   4992: 		    }
                   4993: 	        }
1.329     droeschl 4994: 	    }
1.611     raeburn  4995:         }
                   4996:         if ($haschanged) {
                   4997:             if (&Apache::lonnet::put('resourceversions',\%newsetversions,
                   4998: 			             $env{'course.'.$env{'request.course.id'}.'.domain'},
                   4999: 			             $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
                   5000: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   5001:                     &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
                   5002: 	    } else {
                   5003: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   5004:                     &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329     droeschl 5005: 	    }
1.611     raeburn  5006: 	    &mark_hash_old();
                   5007:         }
                   5008:         &changewarning($r,'');
1.329     droeschl 5009:     }
                   5010:     if ($env{'form.timerange'} eq 'all') {
                   5011: # show all documents
1.549     raeburn  5012: 	$header=&mt('All content in '.$crstype);
1.521     bisitz   5013: 	$allsel=' selected="selected"';
1.329     droeschl 5014: 	foreach my $key (keys(%hash)) {
                   5015: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   5016: 		my $src=$1;
                   5017: 		$changes{$src}=1;
                   5018: 	    }
                   5019: 	}
                   5020:     } else {
                   5021: # show documents which changed
                   5022: 	%changes=&Apache::lonnet::dump
                   5023: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
                   5024:                      $env{'course.'.$env{'request.course.id'}.'.num'});
                   5025: 	my $firstkey=(keys(%changes))[0];
                   5026: 	unless ($firstkey=~/^error\:/) {
                   5027: 	    unless ($env{'form.timerange'}) {
                   5028: 		$env{'form.timerange'}=604800;
                   5029: 	    }
                   5030: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
                   5031: 		.&mt('seconds');
                   5032: 	    if ($env{'form.timerange'}==-1) {
                   5033: 		$seltext='since start of course';
1.521     bisitz   5034: 		$startsel=' selected="selected"';
1.329     droeschl 5035: 		$env{'form.timerange'}=time;
                   5036: 	    }
                   5037: 	    $starttime=time-$env{'form.timerange'};
                   5038: 	    if ($env{'form.timerange'}==2592000) {
                   5039: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5040: 		$monthsel=' selected="selected"';
1.329     droeschl 5041: 	    } elsif ($env{'form.timerange'}==604800) {
                   5042: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5043: 		$weeksel=' selected="selected"';
1.329     droeschl 5044: 	    } elsif ($env{'form.timerange'}==86400) {
                   5045: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5046: 		$daysel=' selected="selected"';
1.329     droeschl 5047: 	    }
                   5048: 	    $header=&mt('Content changed').' '.$seltext;
                   5049: 	} else {
                   5050: 	    $header=&mt('No content modifications yet.');
                   5051: 	}
                   5052:     }
                   5053:     %setversions=&Apache::lonnet::dump('resourceversions',
                   5054: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   5055: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   5056:     my %lt=&Apache::lonlocal::texthash
1.408     raeburn  5057: 	      ('st' => 'Version changes since start of '.$crstype,
1.329     droeschl 5058: 	       'lm' => 'Version changes since last Month',
                   5059: 	       'lw' => 'Version changes since last Week',
                   5060: 	       'sy' => 'Version changes since Yesterday',
                   5061:                'al' => 'All Resources (possibly large output)',
1.484     raeburn  5062:                'cd' => 'Change display', 
1.329     droeschl 5063: 	       'sd' => 'Display',
                   5064: 	       'fi' => 'File',
                   5065: 	       'md' => 'Modification Date',
                   5066:                'mr' => 'Most recently published Version',
1.408     raeburn  5067: 	       've' => 'Version used in '.$crstype,
                   5068:                'vu' => 'Set Version to be used in '.$crstype,
                   5069: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329     droeschl 5070: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                   5071: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479     golterma 5072: 	       'di' => 'Differences',
1.484     raeburn  5073: 	       'save' => 'Save changes',
                   5074:                'vers' => 'Version choice(s) for specific resources', 
1.479     golterma 5075: 	       'act' => 'Actions');
1.611     raeburn  5076:     my ($disabled,$readonly);
                   5077:     unless ($canedit) {
                   5078:         $disabled = 'disabled="disabled"';
                   5079:         $readonly = 1;
                   5080:     }
1.329     droeschl 5081:     $r->print(<<ENDHEADERS);
1.484     raeburn  5082: <h4 class="LC_info">$header</h4>
1.329     droeschl 5083: <form action="/adm/coursedocs" method="post">
                   5084: <input type="hidden" name="versions" value="1" />
1.484     raeburn  5085: <div class="LC_left_float">
1.479     golterma 5086: <fieldset>
1.484     raeburn  5087: <legend>$lt{'cd'}</legend>
1.329     droeschl 5088: <select name="timerange">
1.521     bisitz   5089: <option value='all'$allsel>$lt{'al'}</option>
                   5090: <option value="-1"$startsel>$lt{'st'}</option>
                   5091: <option value="2592000"$monthsel>$lt{'lm'}</option>
                   5092: <option value="604800"$weeksel>$lt{'lw'}</option>
                   5093: <option value="86400"$daysel>$lt{'sy'}</option>
1.329     droeschl 5094: </select>
                   5095: <input type="submit" name="display" value="$lt{'sd'}" />
1.484     raeburn  5096: </fieldset>
                   5097: </div>
                   5098: <div class="LC_left_float">
                   5099: <fieldset>
                   5100: <legend>$lt{'act'}</legend>
1.611     raeburn  5101: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
                   5102: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484     raeburn  5103: </fieldset>
                   5104: </div>
                   5105: <br clear="all" />
                   5106: <hr />
                   5107: <h4>$lt{'vers'}</h4>
1.329     droeschl 5108: ENDHEADERS
1.479     golterma 5109:     #number of columns for version history
1.571     raeburn  5110:     my %changedbytime;
                   5111:     foreach my $key (keys(%changes)) {
                   5112:         #excludes not versionable problems from resource version history:
                   5113:         next if ($key =~ /^\/res\/lib\/templates/);
                   5114:         my $chg;
                   5115:         if ($env{'form.timerange'} eq 'all') {
                   5116:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   5117:             $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
                   5118:         } else {
                   5119:             $chg = $changes{$key};
                   5120:             next if ($chg < $starttime);
                   5121:         }
                   5122:         push(@{$changedbytime{$chg}},$key);
                   5123:     }
                   5124:     if (keys(%changedbytime) == 0) {
                   5125:         &untiehash();
                   5126:         $r->print(&mt('No content changes in imported content in specified time frame').
                   5127:                   &endContentScreen());
                   5128:         return;
                   5129:     }
1.479     golterma 5130:     $r->print(
1.611     raeburn  5131:        '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   5132:         &Apache::loncommon::start_data_table().
                   5133:         &Apache::loncommon::start_data_table_header_row().
                   5134:         '<th>'.&mt('Resources').'</th>'.
                   5135:         "<th>$lt{'mr'}</th>".
                   5136:         "<th>$lt{'ve'}</th>".
                   5137:         "<th>$lt{'vu'}</th>".
                   5138:         '<th>'.&mt('History').'</th>'.
                   5139:         &Apache::loncommon::end_data_table_header_row()
                   5140:     );
1.571     raeburn  5141:     foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
                   5142:         foreach my $key (sort(@{$changedbytime{$chg}})) {
                   5143:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   5144:             my $currentversion=&Apache::lonnet::getversion($key);
                   5145:             if ($currentversion<0) {
                   5146:                 $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
                   5147:             }
                   5148:             my $linkurl=&Apache::lonnet::clutter($key);
                   5149:             $r->print(
                   5150:                 &Apache::loncommon::start_data_table_row().
                   5151:                 '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
                   5152:                 '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
                   5153:                 '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
                   5154:                 &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
                   5155:                 '<td align="right">'
                   5156:             );
                   5157:             # Used in course
                   5158:             my $usedversion=$hash{'version_'.$linkurl};
                   5159:             if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521     bisitz   5160:                 if ($usedversion != $currentversion) {
1.479     golterma 5161:                     $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521     bisitz   5162:                 } else {
1.479     golterma 5163:                     $r->print($usedversion);
                   5164:                 }
1.329     droeschl 5165:             } else {
1.521     bisitz   5166:                 $r->print($currentversion);
1.329     droeschl 5167:             }
1.571     raeburn  5168:             $r->print('</td><td title="'.$lt{'vu'}.'">');
                   5169:             # Set version
                   5170:             $r->print(&Apache::loncommon::select_form(
                   5171:                       $setversions{$linkurl},
                   5172:                       'set_version_'.$linkurl,
                   5173:                       {'select_form_order' => ['',1..$currentversion,'mostrecent'],
                   5174:                       '' => '',
                   5175:                       'mostrecent' => &mt('most recent'),
1.611     raeburn  5176:                       map {$_,$_} (1..$currentversion)},'',$readonly));
1.571     raeburn  5177:             my $lastold=1;
                   5178:             for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                   5179:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   5180:                 if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
                   5181:                     $lastold=$prevvers;
                   5182:                 }
                   5183:             }
                   5184:             $r->print('</td>');
                   5185:             # List all available versions
                   5186:             $r->print('<td valign="top"><span class="LC_fontsize_medium">');
                   5187:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
                   5188:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   5189:                 $r->print(
                   5190:                     '<span class="LC_nobreak">'
                   5191:                    .'<a href="'.&Apache::lonnet::clutter($url).'">'
                   5192:                    .&mt('Version [_1]',$prevvers).'</a>'
                   5193:                    .' ('.&Apache::lonlocal::locallocaltime(
1.521     bisitz   5194:                          &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571     raeburn  5195:                    .')');
                   5196:                 if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
                   5197:                     $r->print(
                   5198:                         ' <a href="/adm/diff?filename='.
                   5199:                         &Apache::lonnet::clutter($root.'.'.$extension).
                   5200:                         &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
                   5201:                         '" target="diffs">'.&mt('Diffs').'</a>');
                   5202:                 }
                   5203:                 $r->print('</span><br />');
1.329     droeschl 5204:             }
1.571     raeburn  5205:             $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521     bisitz   5206:         }
1.329     droeschl 5207:     }
1.521     bisitz   5208:     $r->print(
                   5209:         &Apache::loncommon::end_data_table().
1.611     raeburn  5210:         '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   5211:         '</form>'
                   5212:     );
1.329     droeschl 5213: 
                   5214:     &untiehash();
1.521     bisitz   5215:     $r->print(&endContentScreen());
1.571     raeburn  5216:     return;
1.329     droeschl 5217: }
                   5218: 
                   5219: sub mark_hash_old {
                   5220:     my $retie_hash=0;
                   5221:     if ($hashtied) {
                   5222: 	$retie_hash=1;
                   5223: 	&untiehash();
                   5224:     }
                   5225:     &tiehash('write');
                   5226:     $hash{'old'}=1;
                   5227:     &untiehash();
                   5228:     if ($retie_hash) { &tiehash(); }
                   5229: }
                   5230: 
                   5231: sub is_hash_old {
                   5232:     my $untie_hash=0;
                   5233:     if (!$hashtied) {
                   5234: 	$untie_hash=1;
                   5235: 	&tiehash();
                   5236:     }
                   5237:     my $return=$hash{'old'};
                   5238:     if ($untie_hash) { &untiehash(); }
                   5239:     return $return;
                   5240: }
                   5241: 
                   5242: sub changewarning {
                   5243:     my ($r,$postexec,$message,$url)=@_;
                   5244:     if (!&is_hash_old()) { return; }
                   5245:     my $pathvar='folderpath';
                   5246:     my $path=&escape($env{'form.folderpath'});
                   5247:     if (!defined($url)) {
                   5248: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
                   5249:     }
                   5250:     my $course_type = &Apache::loncommon::course_type();
                   5251:     if (!defined($message)) {
                   5252: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
                   5253:     }
1.653     raeburn  5254:     my $windowname = 'loncapaclient';
                   5255:     if ($env{'request.lti.login'}) {
                   5256:         $windowname .= 'lti';
                   5257:     }
1.329     droeschl 5258:     $r->print("\n\n".
1.372     bisitz   5259: '<script type="text/javascript">'."\n".
                   5260: '// <![CDATA['."\n".
                   5261: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
                   5262: '// ]]>'."\n".
1.369     bisitz   5263: '</script>'."\n".
1.653     raeburn  5264: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329     droeschl 5265: '<input type="hidden" name="orgurl" value="'.$url.
1.372     bisitz   5266: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329     droeschl 5267: &mt($message,' <input type="hidden" name="'.
                   5268:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369     bisitz   5269:     &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372     bisitz   5270: $help{'Caching'}.'</p></form>'."\n\n");
1.329     droeschl 5271: }
                   5272: 
                   5273: 
                   5274: sub init_breadcrumbs {
1.571     raeburn  5275:     my ($form,$text,$help)=@_;
1.329     droeschl 5276:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484     raeburn  5277:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405     bisitz   5278: 					    text=>&Apache::loncommon::course_type().' Editor',
1.329     droeschl 5279: 					    faq=>273,
                   5280: 					    bug=>'Instructor Interface',
1.571     raeburn  5281:                                             help => $help});
1.329     droeschl 5282:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
                   5283: 					    text=>$text,
                   5284: 					    faq=>273,
                   5285: 					    bug=>'Instructor Interface'});
                   5286: }
                   5287: 
1.441     www      5288: # subroutine to list form elements
                   5289: sub create_list_elements {
                   5290:    my @formarr = @_;
                   5291:    my $list = '';
1.501     raeburn  5292:    foreach my $button (@formarr){
                   5293:         foreach my $picture (keys(%{$button})) {
                   5294:             $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441     www      5295:         }
                   5296:    }
                   5297:    return $list;
                   5298: }
1.329     droeschl 5299: 
1.441     www      5300: # subroutine to create ul from list elements
                   5301: sub create_form_ul {
                   5302:    my $list = shift;
                   5303:    my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
                   5304:    return $ul;
                   5305: }
1.329     droeschl 5306: 
1.442     www      5307: #
                   5308: # Start tabs
                   5309: #
                   5310: 
                   5311: sub startContentScreen {
1.484     raeburn  5312:     my ($mode) = @_;
                   5313:     my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472     raeburn  5314:     if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484     raeburn  5315:         $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";
                   5316:         $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";
                   5317:         $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";
                   5318:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
                   5319:     } else {
1.549     raeburn  5320:         $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  5321:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
                   5322:         $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";
                   5323:                    '><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>';
                   5324:     }
                   5325:     $output .= "\n".'</ul>'."\n";
                   5326:     $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
                   5327:                '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
                   5328:                '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
                   5329:     return $output;
1.442     www      5330: }
                   5331: 
                   5332: #
                   5333: # End tabs
                   5334: #
                   5335: 
                   5336: sub endContentScreen {
1.484     raeburn  5337:     return '</div></div></div>';
1.442     www      5338: }
1.329     droeschl 5339: 
1.446     www      5340: sub supplemental_base {
1.548     raeburn  5341:     return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446     www      5342: }
                   5343: 
1.329     droeschl 5344: sub handler {
                   5345:     my $r = shift;
                   5346:     &Apache::loncommon::content_type($r,'text/html');
                   5347:     $r->send_http_header;
                   5348:     return OK if $r->header_only;
1.484     raeburn  5349: 
                   5350: # get course data
1.408     raeburn  5351:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  5352:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   5353:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   5354: 
1.606     raeburn  5355: # get docroot
                   5356:     my $londocroot = $r->dir_config('lonDocRoot');
                   5357: 
1.484     raeburn  5358: # graphics settings
                   5359:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329     droeschl 5360: 
1.443     www      5361: #
1.329     droeschl 5362: # --------------------------------------------- Initialize help topics for this
                   5363:     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627     raeburn  5364: 	               'Adding_External_Resource','Adding_External_Tool',
                   5365:                        'Navigate_Content','Adding_Folders','Docs_Overview',
                   5366: 	               'Load_Map','Supplemental','Score_Upload_Form',
                   5367: 	               'Adding_Pages','Importing_LON-CAPA_Resource',
                   5368: 	               'Importing_IMS_Course','Uploading_From_Harddrive',
                   5369:                        'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329     droeschl 5370: 	$help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
                   5371:     }
                   5372:     # Composite help files
                   5373:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   5374: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   5375:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   5376: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
                   5377:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   5378: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347     weissno  5379:     $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329     droeschl 5380: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353     weissno  5381:     $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329     droeschl 5382:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534     raeburn  5383:  
1.611     raeburn  5384:     my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472     raeburn  5385: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
                   5386:     unless ($r->uri eq '/adm/supplemental') {
                   5387:         # does this user have privileges to modify content.  
1.611     raeburn  5388:         if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
                   5389:             $allowed = 1;
                   5390:             $canedit = 1;
                   5391:             $canview = 1;
                   5392:         } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
                   5393:             $allowed = 1;
                   5394:             $canview = 1;
                   5395:         }
                   5396:     }
                   5397:     unless ($canedit) {
                   5398:         $disabled = ' disabled="disabled"';
1.472     raeburn  5399:     }
1.582     raeburn  5400:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635     raeburn  5401:     if ($env{'form.inhibitmenu'}) {
                   5402:         unless ($env{'form.inhibitmenu'} eq 'yes') {
                   5403:             delete($env{'form.inhibitmenu'});
                   5404:         }
                   5405:     }
                   5406: 
1.582     raeburn  5407:   if ($allowed && $env{'form.verify'}) {
1.571     raeburn  5408:       &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637     raeburn  5409:       if (!$canedit) {
                   5410:           &verifycontent($r);
                   5411:       } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
                   5412:           &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
                   5413:                                                   text=>'Results',
                   5414:                                                   faq=>273,
                   5415:                                                   bug=>'Instructor Interface'});
                   5416:           &verifycontent($r,$env{'form.checkstale'});
                   5417:       } else {
                   5418:           &contentverifyform($r);
                   5419:       }
1.329     droeschl 5420:   } elsif ($allowed && $env{'form.listsymbs'}) {
1.484     raeburn  5421:       &init_breadcrumbs('listsymbs','List Content IDs');
1.329     droeschl 5422:       &list_symbs($r);
1.651     raeburn  5423:   } elsif ($allowed && $env{'form.shorturls'}) {
                   5424:       &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
                   5425:       &short_urls($r,$canedit);
1.329     droeschl 5426:   } elsif ($allowed && $env{'form.docslog'}) {
                   5427:       &init_breadcrumbs('docslog','Show Log');
1.484     raeburn  5428:       my $folder = $env{'form.folder'};
                   5429:       if ($folder eq '') {
                   5430:           $folder='default';
                   5431:       }
1.611     raeburn  5432:       &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329     droeschl 5433:   } elsif ($allowed && $env{'form.versions'}) {
1.571     raeburn  5434:       &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611     raeburn  5435:       &checkversions($r,$canedit);
                   5436:   } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568     raeburn  5437:       &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329     droeschl 5438:       &dumpcourse($r);
1.611     raeburn  5439:   } elsif ($canedit && $env{'form.exportcourse'}) {
1.377     bisitz   5440:       &init_breadcrumbs('exportcourse','IMS Export');
1.475     raeburn  5441:       &Apache::imsexport::exportcourse($r);
1.329     droeschl 5442:   } else {
1.611     raeburn  5443:       if ($canedit && $env{'form.authorrole'}) {
1.606     raeburn  5444:           $noendpage = 1;
                   5445:           my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
                   5446:           if ($redirect) {
                   5447:               if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
                   5448:                   my $container = 'sequence'; 
                   5449:                   my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   5450:                       $is_random_order,$container) =
                   5451:                       &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   5452:                   my (@folders)=split('&',$env{'form.folderpath'});
                   5453:                   $env{'form.foldername'}=&unescape(pop(@folders));
                   5454:                   my $folder=pop(@folders);
                   5455:                   my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   5456:                                                   $folder.'.'.$container);
                   5457:                   my $warning;
                   5458:                   if ($fatal) {
                   5459:                       if ($container eq 'page') {
                   5460:                           $warning = &mt('An error occurred retrieving the contents of the current page.');
                   5461:                       } else {
                   5462:                           $warning = &mt('An error occurred retrieving the contents of the current folder.');
                   5463:                       }
                   5464:                   } else {
                   5465:                       my $url = $redirect;
                   5466:                       my $srcfile = $londocroot.$url;
                   5467:                       $url =~ s{^/priv/}{/res/};
                   5468:                       my $targetfile = $londocroot.$url;
                   5469:                       my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   5470:                       my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
                   5471:                       $env{'form.folder'} = $folder;
                   5472:                       &snapshotbefore();
                   5473:                       my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
                   5474:                       my $ext = 'false';
                   5475:                       my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   5476:                       $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   5477:                                                         ':'.$ext.':normal:res';
                   5478:                       push(@LONCAPA::map::order,$newidx);
                   5479:                       &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
                   5480:                                                    'string_yesno');
                   5481:                       &remember_parms($newidx,'hiddenresource','set','yes');
                   5482:                       ($errtext,$fatal) =
                   5483:                           &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
                   5484:                       &log_differences($plain);
                   5485:                       &mark_hash_old();
                   5486:                       $r->internal_redirect($redirect);
                   5487:                       return OK;
                   5488:                   }
1.654     raeburn  5489:               } else {
                   5490:                   $r->internal_redirect($redirect);
1.606     raeburn  5491:               }
                   5492:           }
                   5493:       }
1.445     www      5494: #
                   5495: # Done catching special calls
1.484     raeburn  5496: # The whole rest is for course and supplemental documents and utilities menu
1.445     www      5497: # Get the parameters that may be needed
                   5498: #
                   5499:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519     raeburn  5500:                                             ['folderpath',
                   5501:                                              'forcesupplement','forcestandard',
1.510     raeburn  5502:                                              'tools','symb','command','supppath']);
1.445     www      5503: 
1.635     raeburn  5504:     foreach my $item ('forcesupplement','forcestandard','tools') {
                   5505:         next if ($env{'form.'.$item} eq '');
                   5506:         unless ($env{'form.'.$item} eq '1') {
                   5507:             delete($env{'form.'.$item});
                   5508:         }
                   5509:     }
                   5510: 
                   5511:     if ($env{'form.command'}) {
                   5512:         unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
                   5513:             delete($env{'form.command'});
                   5514:         }
                   5515:     }
                   5516: 
                   5517:     if ($env{'form.symb'}) {
                   5518:         my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   5519:         unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { 
                   5520:             delete($env{'form.symb'});
                   5521:         }
                   5522:     }
                   5523: 
1.445     www      5524: # standard=1: this is a "new-style" course with an uploaded map as top level
                   5525: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329     droeschl 5526: 
                   5527:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445     www      5528: 
1.484     raeburn  5529: # Decide whether this should display supplemental or main content or utilities
1.445     www      5530: # supplementalflag=1: show supplemental documents
                   5531: # supplementalflag=0: show standard documents
1.484     raeburn  5532: # toolsflag=1: show utilities
1.445     www      5533: 
1.561     raeburn  5534:     my $unesc_folderpath = &unescape($env{'form.folderpath'});
                   5535:     my $supplementalflag=($unesc_folderpath=~/^supplemental/);
                   5536:     if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445     www      5537:        $supplementalflag=0;
                   5538:     }
                   5539:     if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
                   5540:     if ($env{'form.forcestandard'})   { $supplementalflag=0; }
                   5541:     unless ($allowed) { $supplementalflag=1; }
                   5542:     unless ($standard) { $supplementalflag=1; }
1.484     raeburn  5543:     my $toolsflag=0;
                   5544:     if ($env{'form.tools'}) { $toolsflag=1; }
1.445     www      5545: 
1.635     raeburn  5546:     if ($env{'form.folderpath'} ne '') {
                   5547:         my @items = split(/\&/,$env{'form.folderpath'});
                   5548:         my $badpath;
                   5549:         for (my $i=0; $i<@items; $i++) {
                   5550:             my $odd = $i%2;
                   5551:             if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
                   5552:                 $badpath = 1;
                   5553:             } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
                   5554:                 $badpath = 1;
                   5555:             }
                   5556:             last if ($badpath);
                   5557:         }
                   5558:         if ($badpath) {
                   5559:             delete($env{'form.folderpath'});
                   5560:         }
                   5561:     }
                   5562: 
                   5563:     if ($env{'form.supppath'} ne '') {
                   5564:         my @items = split(/\&/,$env{'form.supppath'});
                   5565:         my $badpath;
                   5566:         for (my $i=0; $i<@items; $i++) {
                   5567:             my $odd = $i%2;
                   5568:             if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
                   5569:                 $badpath = 1; 
                   5570:             }
                   5571:             last if ($badpath);
                   5572:         }
                   5573:         if ($badpath) {
                   5574:             delete($env{'form.supppath'});
                   5575:         }
                   5576:     }
                   5577: 
1.329     droeschl 5578:     my $script='';
                   5579:     my $showdoc=0;
1.457     raeburn  5580:     my $addentries = {};
1.475     raeburn  5581:     my $container;
1.329     droeschl 5582:     my $containertag;
1.508     raeburn  5583:     my $pathitem;
1.598     raeburn  5584:     my %ltitools;
1.617     raeburn  5585:     my $hiddentop;
1.615     raeburn  5586:     my $navmap;
1.617     raeburn  5587:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329     droeschl 5588: 
1.464     www      5589: # Do we directly jump somewhere?
1.525     raeburn  5590:    if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472     raeburn  5591:        if ($env{'form.symb'} ne '') {
1.522     raeburn  5592:            $env{'form.folderpath'}=
1.617     raeburn  5593:                &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530     raeburn  5594:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525     raeburn  5595:                $env{'form.command'}.'_'.$env{'form.symb'}});
1.472     raeburn  5596:        } elsif ($env{'form.supppath'} ne '') {
                   5597:            $env{'form.folderpath'}=$env{'form.supppath'};
1.530     raeburn  5598:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525     raeburn  5599:                $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466     www      5600:        }
1.472     raeburn  5601:    } elsif ($env{'form.command'} eq 'editdocs') {
1.617     raeburn  5602:        $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525     raeburn  5603:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472     raeburn  5604:    } elsif ($env{'form.command'} eq 'editsupp') {
1.617     raeburn  5605:        $env{'form.folderpath'} = &supplemental_base();
1.525     raeburn  5606:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
                   5607:    } elsif ($env{'form.command'} eq 'contents') {
                   5608:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
                   5609:    } elsif ($env{'form.command'} eq 'home') {
                   5610:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464     www      5611:    }
                   5612: 
1.525     raeburn  5613: 
1.445     www      5614: # Where do we store these for when we come back?
                   5615:     my $stored_folderpath='docs_folderpath';
                   5616:     if ($supplementalflag) {
                   5617:        $stored_folderpath='docs_sup_folderpath';
                   5618:     }
1.464     www      5619: 
1.519     raeburn  5620: # No folderpath, and in edit mode, see if we have something stored
                   5621:     if ((!$env{'form.folderpath'}) && $allowed) {
1.445     www      5622:         &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510     raeburn  5623:                                           {'folderpath' => 'scalar'});
1.615     raeburn  5624: 
                   5625:         if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
                   5626:             if ($supplementalflag) {
                   5627:                 undef($env{'form.folderpath'}) if ($1 eq 'default'); 
                   5628:             } else {
                   5629:                 undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
                   5630:             }
                   5631:         } else {
1.523     raeburn  5632:             undef($env{'form.folderpath'});
                   5633:         }
1.329     droeschl 5634:     }
1.446     www      5635:    
                   5636: # If we are not allowed to make changes, all we can see are supplemental docs
1.409     raeburn  5637:     if (!$allowed) {
1.446     www      5638:         unless ($env{'form.folderpath'} =~ /^supplemental/) {
                   5639:             $env{'form.folderpath'} = &supplemental_base();
1.409     raeburn  5640:         }
                   5641:     }
1.446     www      5642: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329     droeschl 5643:     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446     www      5644:         $env{'form.folderpath'} = &supplemental_base()
                   5645:                                   .'&'.
1.329     droeschl 5646:                                   $env{'form.folderpath'};
                   5647:     }
1.615     raeburn  5648: # If allowed and user's role is not advanced check folderpath is not hidden  
                   5649:     if (($allowed) && (!$env{'request.role.adv'}) && 
                   5650:         ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
                   5651:         my $folderurl;
                   5652:         my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617     raeburn  5653:         my $folder = $pathitems[-2];
                   5654:         if ($folder eq '') {
                   5655:             undef($env{'form.folderpath'});
                   5656:         } else {
                   5657:             $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666     raeburn  5658:             if ((split(/\:/,$pathitems[-1]))[5]) {
1.615     raeburn  5659:                 $folderurl .= '.page';
                   5660:             } else {
                   5661:                 $folderurl .= '.sequence';
                   5662:             }
1.617     raeburn  5663:             unless (ref($navmap)) {
                   5664:                 $navmap = Apache::lonnavmaps::navmap->new();
                   5665:             }
1.615     raeburn  5666:             if (ref($navmap)) {
                   5667:                 if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617     raeburn  5668:                     my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
                   5669:                     unless (@resources) {
                   5670:                         undef($env{'form.folderpath'});
                   5671:                     }
1.615     raeburn  5672:                 }
                   5673:             }
                   5674:         }
                   5675:     }
                   5676: 
                   5677: 
1.446     www      5678: # If after all of this, we still don't have any paths, make them
1.519     raeburn  5679:     unless ($env{'form.folderpath'}) {
1.446     www      5680:        if ($supplementalflag) {
                   5681:           $env{'form.folderpath'}=&supplemental_base();
1.617     raeburn  5682:        } elsif ($allowed) {
                   5683:           ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446     www      5684:        }
1.472     raeburn  5685:     }
1.446     www      5686: 
1.445     www      5687: # Store this
1.484     raeburn  5688:     unless ($toolsflag) {
1.615     raeburn  5689:         if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510     raeburn  5690:             &Apache::loncommon::store_course_settings($stored_folderpath,
1.519     raeburn  5691:                                                       {'folderpath' => 'scalar'});
1.510     raeburn  5692:         }
1.519     raeburn  5693:         my $folderpath;
1.484     raeburn  5694:         if ($env{'form.folderpath'}) {
1.519     raeburn  5695:             $folderpath = $env{'form.folderpath'};
                   5696: 	    my (@folders)=split('&',$env{'form.folderpath'});
                   5697: 	    $env{'form.foldername'}=&unescape(pop(@folders));
                   5698:             if ($env{'form.foldername'} =~ /\:1$/) {
                   5699:                 $container = 'page';
                   5700:             } else {
                   5701:                 $container = 'sequence';
                   5702:             }
                   5703: 	    $env{'form.folder'}=pop(@folders);
1.484     raeburn  5704:         } else {
1.519     raeburn  5705:             if ($env{'form.folder'} eq '' ||
                   5706:                 $env{'form.folder'} eq 'supplemental') {
1.617     raeburn  5707:                 if ($env{'form.folder'} eq 'supplemental') {
                   5708:                     $folderpath=&supplemental_base();
                   5709:                 } elsif (!$hiddentop) {
                   5710:                     $folderpath='default&'.
                   5711:                                  &escape(&mt('Main Content').':::::');
                   5712:                 }
1.484     raeburn  5713:             }
                   5714:         }
1.519     raeburn  5715:         $containertag = '<input type="hidden" name="folderpath" value="" />';
                   5716:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484     raeburn  5717:         if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
                   5718:            $showdoc='/'.$1;
                   5719:         }
                   5720:         if ($showdoc) { # got called in sequence from course
                   5721: 	    $allowed=0; 
                   5722:         } else {
1.611     raeburn  5723:             if ($canedit) {
1.484     raeburn  5724:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   5725:                 $script=&Apache::lonratedt::editscript('simple');
1.433     raeburn  5726:             }
                   5727:         }
1.329     droeschl 5728:     }
                   5729: 
1.344     bisitz   5730: # get personal data
1.329     droeschl 5731:     my $uname=$env{'user.name'};
                   5732:     my $udom=$env{'user.domain'};
                   5733:     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
                   5734: 
                   5735:     if ($allowed) {
1.484     raeburn  5736:         if ($toolsflag) {
                   5737:             $script .= &inject_data_js();
                   5738:             my ($home,$other,%outhash)=&authorhosts();
                   5739:             if (!$home && $other) {
                   5740:                 my @hosts;
                   5741:                 foreach my $aurole (keys(%outhash)) {
                   5742:                     unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   5743:                         push(@hosts,$outhash{$aurole});
                   5744:                     }
                   5745:                 }
                   5746:                 $script .= &dump_switchserver_js(@hosts); 
                   5747:             }
1.458     raeburn  5748:         } else {
1.570     raeburn  5749:             my $tid = 1;
1.484     raeburn  5750:             my @tabids;
                   5751:             if ($supplementalflag) {
1.655     raeburn  5752:                 @tabids = ('002','dd2','ee2','ff2');
1.570     raeburn  5753:                 $tid = 2;
1.484     raeburn  5754:             } else {
                   5755:                 @tabids = ('aa1','bb1','cc1','ff1');
1.519     raeburn  5756:                 unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484     raeburn  5757:                     unshift(@tabids,'001');
                   5758:                     push(@tabids,('dd1','ee1'));
                   5759:                 }
1.458     raeburn  5760:             }
1.484     raeburn  5761:             my $tabidstr = join("','",@tabids);
1.644     raeburn  5762:             %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600     raeburn  5763:             my $posslti = keys(%ltitools);
1.622     raeburn  5764:             my $hostname = $r->hostname();
1.606     raeburn  5765: 	    $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622     raeburn  5766:                                    $londocroot,$canedit,$hostname,\$navmap).
1.484     raeburn  5767:                        &history_tab_js().
                   5768:                        &inject_data_js().
1.570     raeburn  5769:                        &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598     raeburn  5770:                        &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484     raeburn  5771:             $addentries = {
1.485     raeburn  5772:                             onload   => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484     raeburn  5773:                           };
1.458     raeburn  5774:         }
1.538     raeburn  5775:         $script .= &paste_popup_js(); 
1.501     raeburn  5776:         my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
                   5777:                              &mt('Switch server?');
                   5778:         
                   5779: 
1.329     droeschl 5780:     }
                   5781: # -------------------------------------------------------------------- Body tag
1.369     bisitz   5782:     $script = '<script type="text/javascript">'."\n"
1.372     bisitz   5783:               .'// <![CDATA['."\n"
                   5784:               .$script."\n"
                   5785:               .'// ]]>'."\n"
1.595     musolffc 5786:               .'</script>'."\n"
                   5787:               .'<script type="text/javascript" 
                   5788:                 src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385     bisitz   5789: 
                   5790:     # Breadcrumbs
                   5791:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510     raeburn  5792: 
                   5793:     if ($showdoc) {
                   5794:         $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
                   5795:                                                 {'force_register' => $showdoc,}));
1.571     raeburn  5796:     } elsif ($toolsflag) {
1.611     raeburn  5797:         my ($breadtext,$breadtitle);
1.617     raeburn  5798:         $breadtext = "$crstype Editor";
1.611     raeburn  5799:         if ($canedit) {
                   5800:             $breadtitle = 'Editing '.$crstype.' Contents';
                   5801:         } else {
                   5802:             $breadtext .= ' (View-only mode)';
                   5803:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   5804:         }
1.571     raeburn  5805:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  5806:             href=>"/adm/coursedocs",text=>$breadtext});
1.571     raeburn  5807:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
                   5808:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   5809:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  5810:                      $breadtitle)
1.571     raeburn  5811:                  );
1.510     raeburn  5812:     } elsif ($r->uri eq '/adm/supplemental') {
                   5813:         my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
                   5814:         $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
                   5815:                                                 {'bread_crumbs' => $brcrum,}));
                   5816:     } else {
1.611     raeburn  5817:         my ($breadtext,$breadtitle,$helpitem);
1.617     raeburn  5818:         $breadtext = "$crstype Editor";
1.611     raeburn  5819:         if ($canedit) {
                   5820:             $breadtitle = 'Editing '.$crstype.' Contents';
                   5821:             $helpitem = 'Docs_Adding_Course_Doc';
                   5822:         } else {
                   5823:             $breadtext .= ' (View-only mode)';
                   5824:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   5825:             $helpitem = 'Docs_Viewing_Course_Doc';
                   5826:         }
1.392     raeburn  5827:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  5828:             href=>"/adm/coursedocs",text=>$breadtext});
1.446     www      5829:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510     raeburn  5830:                                                  {'add_entries'    => $addentries}
                   5831:                                                 )
1.392     raeburn  5832:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   5833:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  5834:                      $breadtitle,
                   5835:                      $helpitem)
1.392     raeburn  5836:         );
                   5837:     }
1.364     bisitz   5838: 
1.329     droeschl 5839:   my %allfiles = ();
                   5840:   my %codebase = ();
1.440     raeburn  5841:   my ($upload_result,$upload_output,$uploadphase);
1.611     raeburn  5842:   if ($canedit) {
1.329     droeschl 5843:       if (($env{'form.uploaddoc.filename'}) &&
                   5844: 	  ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440     raeburn  5845:           my $context = $1; 
                   5846:           # Process file upload - phase one - upload and parse primary file.
1.329     droeschl 5847: 	  undef($hadchanges);
1.440     raeburn  5848:           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552     raeburn  5849:                                               \%allfiles,\%codebase,$context,$crstype);
1.638     raeburn  5850:           undef($navmap);
1.329     droeschl 5851: 	  if ($hadchanges) {
                   5852: 	      &mark_hash_old();
                   5853: 	  }
1.440     raeburn  5854:           $r->print($upload_output);
                   5855:       } elsif ($env{'form.phase'} eq 'upload_embedded') {
                   5856:           # Process file upload - phase two - upload embedded objects 
                   5857:           $uploadphase = 'check_embedded';
                   5858:           my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');   
                   5859:           my $state = &embedded_form_elems($uploadphase,$primaryurl,
                   5860:                                            $env{'form.newidx'});
                   5861:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   5862:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   5863:           my ($destination,$dir_root) = &embedded_destination();
                   5864:           my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
                   5865:           my $actionurl = '/adm/coursedocs';
1.630     raeburn  5866:           my ($result,$flag) =
1.440     raeburn  5867:               &Apache::loncommon::upload_embedded('coursedoc',$destination,
                   5868:                   $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
                   5869:                   $actionurl);
                   5870:           $r->print($result.&return_to_editor());
                   5871:       } elsif ($env{'form.phase'} eq 'check_embedded') {
                   5872:           # Process file upload - phase three - modify references in HTML file
                   5873:           $uploadphase = 'modified_orightml';
                   5874:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   5875:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   5876:           my ($destination,$dir_root) = &embedded_destination();
1.630     raeburn  5877:           my $result =
1.482     raeburn  5878:               &Apache::loncommon::modify_html_refs('coursedoc',$destination,
                   5879:                                                    $docuname,$docudom,undef,
                   5880:                                                    $dir_root);
1.630     raeburn  5881:           $r->print($result.&return_to_editor());
1.476     raeburn  5882:       } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
                   5883:           $uploadphase = 'decompress_phase_one';
                   5884:           $r->print(&decompression_phase_one().
                   5885:                     &return_to_editor());
                   5886:       } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
                   5887:           $uploadphase = 'decompress_phase_two';
                   5888:           $r->print(&decompression_phase_two().
                   5889:                     &return_to_editor());
1.329     droeschl 5890:       }
                   5891:   }
                   5892: 
1.484     raeburn  5893:   if ($allowed && $toolsflag) {
                   5894:       $r->print(&startContentScreen('tools'));
1.611     raeburn  5895:       $r->print(&generate_admin_menu($crstype,$canedit));
1.484     raeburn  5896:       $r->print(&endContentScreen());
                   5897:   } elsif ((!$showdoc) && (!$uploadphase)) {
1.329     droeschl 5898: # -----------------------------------------------------------------------------
                   5899:        my %lt=&Apache::lonlocal::texthash(
                   5900: 		'copm' => 'All documents out of a published map into this folder',
1.501     raeburn  5901:                 'upfi' => 'Upload File',
1.553     raeburn  5902:                 'upld' => 'Upload Content',
1.329     droeschl 5903:                 'srch' => 'Search',
                   5904:                 'impo' => 'Import',
1.487     raeburn  5905: 		'lnks' => 'Import from Stored Links',
1.502     raeburn  5906:                 'impm' => 'Import from Assembled Map',
1.630     raeburn  5907:                 'imcr' => 'Import from Course Resources',
1.598     raeburn  5908:                 'extr' => 'External Resource',
                   5909:                 'extt' => 'External Tool',
1.329     droeschl 5910:                 'selm' => 'Select Map',
                   5911:                 'load' => 'Load Map',
                   5912:                 'newf' => 'New Folder',
                   5913:                 'newp' => 'New Composite Page',
                   5914:                 'syll' => 'Syllabus',
1.425     raeburn  5915:                 'navc' => 'Table of Contents',
1.343     biermanm 5916:                 'sipa' => 'Simple Course Page',
1.329     droeschl 5917:                 'sipr' => 'Simple Problem',
1.630     raeburn  5918:                 'webp' => 'Blank Web Page (editable)',
1.606     raeburn  5919:                 'stpr' => 'Standard Problem',
                   5920:                 'news' => 'New sub-directory',
                   5921:                 'crpr' => 'Create Problem',
1.329     droeschl 5922:                 'drbx' => 'Drop Box',
1.451     www      5923:                 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336     schafran 5924:                 'bull' => 'Discussion Board',
1.347     weissno  5925:                 'mypi' => 'My Personal Information Page',
1.353     weissno  5926:                 'grpo' => 'Group Portfolio',
1.329     droeschl 5927:                 'rost' => 'Course Roster',
1.528     raeburn  5928:                 'abou' => 'Personal Information Page for a User',
1.553     raeburn  5929:                 'imsf' => 'IMS Upload',
                   5930:                 'imsl' => 'Upload IMS package',
1.501     raeburn  5931:                 'cms'  => 'Origin of IMS package',
                   5932:                 'se'   => 'Select',
1.329     droeschl 5933:                 'file' =>  'File',
                   5934:                 'title' => 'Title',
1.606     raeburn  5935:                 'addp' => 'Add Placeholder to course?',
                   5936:                 'uste' => 'Use Template?',
                   5937:                 'fnam' => 'File Name:',
                   5938:                 'loca' => 'Location:',
                   5939:                 'dire' => 'Directory:',
                   5940:                 'cate' => 'Category:',
                   5941:                 'tmpl' => 'Template:',
1.329     droeschl 5942:                 'comment' => 'Comment',
1.403     raeburn  5943:                 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577     bisitz   5944:                 'bb5'      => 'Blackboard 5',
                   5945:                 'bb6'      => 'Blackboard 6',
                   5946:                 'angel5'   => 'ANGEL 5.5',
                   5947:                 'webctce4' => 'WebCT 4 Campus Edition',
1.606     raeburn  5948:                 'yes'      => 'Yes',
                   5949:                 'no'       => 'No',
1.618     raeburn  5950:                 'er' => 'Editing rights unavailable for your current role.',
1.577     bisitz   5951:         );
1.329     droeschl 5952: # -----------------------------------------------------------------------------
1.595     musolffc 5953: 
                   5954:     # Calculate free quota space for a user or course. A javascript function checks
                   5955:     # file size to determine if upload should be allowed.
                   5956:     my $quotatype = 'unofficial';
                   5957:     if ($crstype eq 'Community') {
1.601     raeburn  5958:         $quotatype = 'community';
                   5959:     } elsif ($crstype eq 'Placement') {
                   5960:         $quotatype = 'placement';
1.595     musolffc 5961:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
                   5962:         $quotatype = 'official';
                   5963:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   5964:         $quotatype = 'textbook';
                   5965:     }
                   5966:     my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
                   5967:                      'course',$quotatype); # expressed in MB
                   5968:     my $current_disk_usage = 0;
                   5969:     foreach my $subdir ('docs','supplemental') {
                   5970:         $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
                   5971:                                "userfiles/$subdir",1); # expressed in kB
                   5972:     }
                   5973:     my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605     raeburn  5974:     my $usage = $current_disk_usage/1024; # in MB
                   5975:     my $quota = $disk_quota;
                   5976:     my $percent;
                   5977:     if ($disk_quota == 0) {
                   5978:         $percent = 100.0;
                   5979:     } else {
1.619     raeburn  5980:         $percent = 100*($usage/$disk_quota);
1.605     raeburn  5981:     }
                   5982:     $usage = sprintf("%.2f",$usage);
                   5983:     $quota = sprintf("%.2f",$quota);
                   5984:     $percent = sprintf("%.0f",$percent);
                   5985:     my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
                   5986:                               $percent.'%',$quota.' MB').'</p>';
1.595     musolffc 5987: 
1.329     droeschl 5988: 	my $fileupload=(<<FIUP);
1.605     raeburn  5989:         $quotainfo
1.329     droeschl 5990: 	$lt{'file'}:<br />
1.662     raeburn  5991: 	<input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663     raeburn  5992:         <input type="hidden" id="LC_free_space" value="$free_space" />
1.329     droeschl 5993: FIUP
                   5994: 
                   5995: 	my $checkbox=(<<CHBO);
                   5996: 	<!-- <label>$lt{'parse'}?
                   5997: 	<input type="checkbox" name="parserflag" />
                   5998: 	</label> -->
                   5999: 	<label>
1.611     raeburn  6000: 	<input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329     droeschl 6001: 	</label>
                   6002: CHBO
1.501     raeburn  6003:         my $imsfolder = $env{'form.folder'};
                   6004:         if ($imsfolder eq '') {
                   6005:             $imsfolder = 'default';  
                   6006:         }
                   6007:         my $imspform=(<<IMSFORM);
                   6008:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
                   6009:         $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
                   6010:         <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516     raeburn  6011:         <fieldset id="uploadimsform" style="display: none;">
1.501     raeburn  6012:         <legend>$lt{'imsf'}</legend>
                   6013:         $fileupload
                   6014:         <br />
                   6015:         <p>
                   6016:         $lt{'cms'}:&nbsp; 
1.611     raeburn  6017:         <select name="source" $disabled>
1.501     raeburn  6018:         <option value="-1" selected="selected">$lt{'se'}</option>
1.577     bisitz   6019:         <option value="bb5">$lt{'bb5'}</option>
                   6020:         <option value="bb6">$lt{'bb6'}</option>
                   6021:         <option value="angel5">$lt{'angel5'}</option>
                   6022:         <option value="webctce4">$lt{'webctce4'}</option>
1.501     raeburn  6023:         </select>
                   6024:         <input type="hidden" name="folder" value="$imsfolder" />
                   6025:         </p>
                   6026:         <input type="hidden" name="phase" value="one" />
1.611     raeburn  6027:         <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501     raeburn  6028:         </fieldset>
                   6029:         </form>
                   6030: IMSFORM
1.329     droeschl 6031: 
                   6032: 	my $fileuploadform=(<<FUFORM);
1.501     raeburn  6033:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
                   6034:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
                   6035:         <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516     raeburn  6036:         <fieldset id="uploaddocform" style="display: none;">
1.501     raeburn  6037:         <legend>$lt{'upfi'}</legend>
1.371     tempelho 6038: 	<input type="hidden" name="active" value="aa" />
1.595     musolffc 6039:     $fileupload
1.329     droeschl 6040: 	<br />
                   6041: 	$lt{'title'}:<br />
1.611     raeburn  6042: 	<input type="text" size="60" name="comment" $disabled />
1.508     raeburn  6043: 	$pathitem
1.329     droeschl 6044: 	<input type="hidden" name="cmd" value="upload_default" />
                   6045: 	<br />
1.458     raeburn  6046: 	<span class="LC_nobreak" style="float:left">
1.329     droeschl 6047: 	$checkbox
                   6048: 	</span>
1.501     raeburn  6049:         <br clear="all" />
1.611     raeburn  6050:         <input type="submit" value="$lt{'upld'}" $disabled />
1.501     raeburn  6051:         </fieldset>
                   6052:         </form>
1.383     tempelho 6053: FUFORM
1.329     droeschl 6054: 
1.611     raeburn  6055:         my $mapimportjs;
                   6056:         if ($canedit) {
                   6057:             $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');"; 
                   6058:         } else {
                   6059:             $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
                   6060:         }
1.502     raeburn  6061: 	my $importpubform=(<<SEDFFORM);
1.514     raeburn  6062:         <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502     raeburn  6063:         $lt{'impm'}</a>$help{'Load_Map'}
                   6064: 	<form action="/adm/coursedocs" method="post" name="mapimportform">
1.516     raeburn  6065:         <fieldset id="importmapform" style="display: none;">
1.502     raeburn  6066:         <legend>$lt{'impm'}</legend>
1.371     tempelho 6067: 	<input type="hidden" name="active" value="bb" />
1.502     raeburn  6068:         $lt{'copm'}<br />
                   6069:         <span class="LC_nobreak">
                   6070:         <input type="text" name="importmap" size="40" value="" 
1.611     raeburn  6071:         onfocus="this.blur();$mapimportjs" $disabled />
                   6072:         &nbsp;<a href="$mapimportjs">$lt{'selm'}</a></span><br />
                   6073:         <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502     raeburn  6074:         </fieldset>
                   6075:         </form>
                   6076: 
1.383     tempelho 6077: SEDFFORM
1.606     raeburn  6078:         my $importcrsresform;
1.608     raeburn  6079:         my ($numdirs,$pickfile) = 
                   6080:             &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
                   6081:                                                       "resize_scrollbox('contentscroll','1','0');",
                   6082:                                                       undef,'res');
1.606     raeburn  6083:         if ($pickfile) {
                   6084:             $importcrsresform=(<<CRSFORM);
                   6085:         <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
                   6086:         $lt{'imcr'}</a>$help{'Course_Resources'}
                   6087:         <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
                   6088:         <fieldset id="importcrsresform" style="display: none;">
                   6089:         <legend>$lt{'imcr'}</legend>
                   6090:         <input type="hidden" name="active" value="bb" />
                   6091:         $pickfile
                   6092:         <p>
1.611     raeburn  6093:         $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606     raeburn  6094:         </p>
                   6095:         <input type="hidden" name="importdetail" value="" />
1.611     raeburn  6096:         <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606     raeburn  6097:         </fieldset>
                   6098:         </form>
                   6099: CRSFORM
                   6100:         }
                   6101: 
1.611     raeburn  6102:         my $fromstoredjs;
                   6103:         if ($canedit) {
                   6104:             $fromstoredjs = 'open_StoredLinks_Import()'; 
                   6105:         } else {
                   6106:             $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
                   6107:         }
                   6108: 
1.502     raeburn  6109: 	my @importpubforma = (
1.508     raeburn  6110: 	{ '<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>" },
1.423     onken    6111: 	{ '<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.611     raeburn  6112: 	{ '<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>' },
1.606     raeburn  6113:         { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
                   6114:         );
                   6115:         if ($pickfile) {
                   6116:             push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'"  onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
                   6117: 	}
1.502     raeburn  6118: 	$importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510     raeburn  6119:         my $extresourcesform =
                   6120:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611     raeburn  6121:                                                  $help{'Adding_External_Resource'},
                   6122:                                                  undef,undef,undef,undef,undef,undef,$disabled);
1.598     raeburn  6123:         my $exttoolform =
                   6124:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
                   6125:                                                  $help{'Adding_External_Tool'},undef,
                   6126:                                                  undef,'tool',$coursedom,$coursenum,
1.611     raeburn  6127:                                                  \%ltitools,$disabled);
1.329     droeschl 6128:     if ($allowed) {
1.492     raeburn  6129:         my $folder = $env{'form.folder'};
                   6130:         if ($folder eq '') {
                   6131:             $folder='default';
                   6132:         }
1.615     raeburn  6133:         if ($canedit) {
                   6134: 	    my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
                   6135:             if ($output) {
                   6136:                 $r->print($output);
                   6137:             }
1.538     raeburn  6138:         }
1.337     ehlerst  6139: 	$r->print(<<HIDDENFORM);
                   6140: 	<form name="renameform" method="post" action="/adm/coursedocs">
                   6141:    <input type="hidden" name="title" />
                   6142:    <input type="hidden" name="cmd" />
                   6143:    <input type="hidden" name="markcopy" />
                   6144:    <input type="hidden" name="copyfolder" />
                   6145:    $containertag
                   6146:  </form>
1.633     raeburn  6147:  <form name="aliasform" method="post" action="/adm/coursedocs">
                   6148:    <input type="hidden" name="alias" />
                   6149:    <input type="hidden" name="cmd" />
                   6150:    $containertag
                   6151:  </form>
1.484     raeburn  6152: 
1.337     ehlerst  6153: HIDDENFORM
1.508     raeburn  6154:         $r->print(&makesimpleeditform($pathitem)."\n".
                   6155:                   &makedocslogform($pathitem."\n".
1.484     raeburn  6156:                                    '<input type="hidden" name="folder" value="'.
                   6157:                                    $env{'form.folder'}.'" />'."\n"));
1.329     droeschl 6158:     }
1.442     www      6159: 
                   6160: # Generate the tabs
1.510     raeburn  6161:     my ($mode,$needs_end);
1.472     raeburn  6162:     if (($supplementalflag) && (!$allowed)) {
1.510     raeburn  6163:         my @folders = split('&',$env{'form.folderpath'});
                   6164:         unless (@folders > 2) {
                   6165:             &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
                   6166:             $needs_end = 1;
                   6167:         }
1.472     raeburn  6168:     } else {
1.484     raeburn  6169:         $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510     raeburn  6170:         $needs_end = 1;
1.472     raeburn  6171:     }
1.443     www      6172: 
1.442     www      6173: #
1.622     raeburn  6174:     my $hostname = $r->hostname();
1.442     www      6175:     my $savefolderpath;
                   6176: 
1.395     raeburn  6177:     if ($allowed) {
1.329     droeschl 6178:        my $folder=$env{'form.folder'};
1.615     raeburn  6179:        if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329     droeschl 6180:            $folder='default';
1.356     tempelho 6181: 	   $savefolderpath = $env{'form.folderpath'};
1.548     raeburn  6182: 	   $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508     raeburn  6183:            $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329     droeschl 6184: 	       &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
                   6185:        }
                   6186:        my $postexec='';
                   6187:        if ($folder eq 'default') {
1.653     raeburn  6188:            my $windowname = 'loncapaclient';
                   6189:            if ($env{'request.lti.login'}) {
                   6190:                $windowname .= 'lti';
                   6191:            }
1.372     bisitz   6192:            $r->print('<script type="text/javascript">'."\n"
                   6193:                     .'// <![CDATA['."\n"
1.653     raeburn  6194:                     .'this.window.name="'.$windowname.'";'."\n"
1.372     bisitz   6195:                     .'// ]]>'."\n"
                   6196:                     .'</script>'."\n"
1.369     bisitz   6197:        );
1.329     droeschl 6198:        } else {
                   6199:            #$postexec='self.close();';
                   6200:        }
1.504     raeburn  6201:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
                   6202:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329     droeschl 6203: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
                   6204: 
                   6205: 	my $newnavform=(<<NNFORM);
                   6206: 	<form action="/adm/coursedocs" method="post" name="newnav">
1.655     raeburn  6207: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6208: 	$pathitem
1.329     droeschl 6209: 	<input type="hidden" name="importdetail" 
                   6210: 	value="$lt{'navc'}=/adm/navmaps" />
1.611     raeburn  6211: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329     droeschl 6212: 	$help{'Navigate_Content'}
                   6213: 	</form>
                   6214: NNFORM
                   6215: 	my $newsmppageform=(<<NSPFORM);
                   6216: 	<form action="/adm/coursedocs" method="post" name="newsmppg">
1.655     raeburn  6217: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6218: 	$pathitem
1.329     droeschl 6219: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6220: 	<a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383     tempelho 6221: 	$help{'Simple Page'}
1.329     droeschl 6222: 	</form>
                   6223: NSPFORM
                   6224: 
                   6225: 	my $newsmpproblemform=(<<NSPROBFORM);
                   6226: 	<form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655     raeburn  6227: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6228: 	$pathitem
1.329     droeschl 6229: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6230: 	<a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572     raeburn  6231: 	$help{'Simple_Problem'}
1.329     droeschl 6232: 	</form>
                   6233: 
                   6234: NSPROBFORM
                   6235: 
                   6236: 	my $newdropboxform=(<<NDBFORM);
                   6237: 	<form action="/adm/coursedocs" method="post" name="newdropbox">
1.655     raeburn  6238: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6239: 	$pathitem
1.329     droeschl 6240: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6241: 	<a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554     raeburn  6242:         $help{'Dropbox'}
1.344     bisitz   6243: 	</form>
1.329     droeschl 6244: NDBFORM
                   6245: 
                   6246: 	my $newexuploadform=(<<NEXUFORM);
                   6247: 	<form action="/adm/coursedocs" method="post" name="newexamupload">
1.655     raeburn  6248: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6249: 	$pathitem
1.329     droeschl 6250: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6251: 	<a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329     droeschl 6252: 	$help{'Score_Upload_Form'}
                   6253: 	</form>
                   6254: NEXUFORM
                   6255: 
                   6256: 	my $newbulform=(<<NBFORM);
                   6257: 	<form action="/adm/coursedocs" method="post" name="newbul">
1.655     raeburn  6258: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6259: 	$pathitem
1.329     droeschl 6260: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6261: 	<a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329     droeschl 6262: 	$help{'Bulletin Board'}
                   6263: 	</form>
                   6264: NBFORM
                   6265: 
                   6266: 	my $newaboutmeform=(<<NAMFORM);
                   6267: 	<form action="/adm/coursedocs" method="post" name="newaboutme">
1.655     raeburn  6268: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6269: 	$pathitem
1.329     droeschl 6270: 	<input type="hidden" name="importdetail" 
                   6271: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  6272: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347     weissno  6273: 	$help{'My Personal Information Page'}
1.329     droeschl 6274: 	</form>
                   6275: NAMFORM
                   6276: 
                   6277: 	my $newaboutsomeoneform=(<<NASOFORM);
                   6278: 	<form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655     raeburn  6279: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6280: 	$pathitem
1.329     droeschl 6281: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6282: 	<a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329     droeschl 6283: 	</form>
                   6284: NASOFORM
                   6285: 
                   6286: 	my $newrosterform=(<<NROSTFORM);
                   6287: 	<form action="/adm/coursedocs" method="post" name="newroster">
1.655     raeburn  6288: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6289: 	$pathitem
1.329     droeschl 6290: 	<input type="hidden" name="importdetail" 
                   6291: 	value="$lt{'rost'}=/adm/viewclasslist" />
1.611     raeburn  6292: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556     raeburn  6293: 	$help{'Course_Roster'}
1.329     droeschl 6294: 	</form>
                   6295: NROSTFORM
                   6296: 
1.534     raeburn  6297:         my $newwebpage;
                   6298:         if ($folder =~ /^default_?(\d*)$/) {
                   6299:             $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
                   6300:             if ($1) {
                   6301:                 $newwebpage .= $1;
                   6302:             } else {
                   6303:                 $newwebpage .= 'default';
                   6304:             }
                   6305:             $newwebpage .= '/new.html';
                   6306:         }
                   6307:         my $newwebpageform =(<<NWEBFORM);
                   6308:         <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655     raeburn  6309:         <input type="hidden" name="active" value="ff" />
1.534     raeburn  6310:         $pathitem
                   6311:         <input type="hidden" name="importdetail" value="$newwebpage" />
                   6312:         <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556     raeburn  6313:         $help{'Web_Page'}
1.534     raeburn  6314:         </form>
                   6315: NWEBFORM
1.604     raeburn  6316: 
1.606     raeburn  6317:         my @ids=&Apache::lonnet::current_machine_ids();
                   6318:         my %select_menus;
                   6319:         my $numauthor = 0;
                   6320:         my $numcrsdirs = 0;
                   6321:         my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}"; 
                   6322:         if ($env{'user.author'}) {
                   6323:             $numauthor ++;
                   6324:             $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
                   6325:             if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
                   6326:                 my $is_home = 1;
                   6327:                 my %subdirs;
1.608     raeburn  6328:                 &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606     raeburn  6329:                 $select_menus{'author'}->{'default'} = '/'; 
                   6330:                 $select_menus{'author'}->{'select2'}->{'/'} = '/';
                   6331:                 my @ordered = ('/');
                   6332:                 foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
                   6333:                     $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
                   6334:                     push(@ordered,$relpath);
                   6335:                 }
                   6336:                 $select_menus{'author'}->{'order'} = \@ordered;
                   6337:             } else {
                   6338:                 $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
                   6339:                 $select_menus{'author'}->{'default'} = 'switch';
                   6340:                 $select_menus{'author'}->{'order'} = ['switch'];
                   6341:             }
                   6342:         }
                   6343:         my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
                   6344:                                                       ['active'],['ca','aa']);
                   6345:         my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   6346:         my %by_roletype;
                   6347:         if (keys(%roleshash)) {
                   6348:             foreach my $entry (keys(%roleshash)) {
                   6349:                 my ($auname,$audom,$roletype) = split(/:/,$entry);
                   6350:                 my $key = $entry;
                   6351:                 $key =~ s/:/___/g;
                   6352:                 $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
                   6353:                 $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
                   6354:                 my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
                   6355:                 if (grep(/^\Q$rolehome\E$/,@ids)) {    
                   6356:                     my $is_home = 1;
                   6357:                     my (%subdirs,@ordered);
                   6358:                     my $toppath="/priv/$audom/$auname";
1.608     raeburn  6359:                     &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606     raeburn  6360:                     $select_menus{$key}->{'default'} = '/';
                   6361:                     $select_menus{$key}->{'select2'}->{'/'} = '/';
                   6362:                     my @ordered = ('/');
                   6363:                     foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
                   6364:                         $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
                   6365:                         push(@ordered,$relpath);
                   6366:                     }
                   6367:                     $select_menus{$key}->{'order'} = \@ordered;
                   6368:                 } else {
                   6369:                     $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
                   6370:                     $select_menus{$key}->{'default'} = 'switch';
                   6371:                     $select_menus{$key}->{'order'} = ['switch'];
                   6372:                 }
                   6373:                 $numauthor ++;
                   6374:             }
                   6375:         }
1.631     raeburn  6376:         my ($pickdir,$showtitle);
1.606     raeburn  6377:         if ($numauthor) {
                   6378:             my @order;
                   6379:             my $defrole;
                   6380:             if ($env{'user.author'}) {
                   6381:                 push(@order,'author');
                   6382:                 $defrole = 'author';
                   6383:             }
                   6384:             if (keys(%by_roletype)) {
                   6385:                 foreach my $possrole ('ca','aa') {
                   6386:                     if (ref($by_roletype{$possrole}) eq 'HASH') {
                   6387:                         foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
                   6388:                             unless ($defrole) {
                   6389:                                 $defrole = $author;
                   6390:                             }
                   6391:                             push(@order,$author.'___'.$possrole);
                   6392:                         }
                   6393:                     }
                   6394:                 }
                   6395:             }
                   6396:             $select_menus{'course'}->{'text'} = &mt('Course Resource');
                   6397:             if (grep(/^\Q$crshome\E$/,@ids)) {
                   6398:                 my $is_home = 1;
                   6399:                 my %subdirs;
                   6400:                 my $toppath="/priv/$coursedom/$coursenum";
1.608     raeburn  6401:                 &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606     raeburn  6402:                 $numcrsdirs = keys(%subdirs);
                   6403:                 $select_menus{'course'}->{'default'} = '/';
                   6404:                 $select_menus{'course'}->{'select2'}->{'/'} = '/';
                   6405:                 my @ordered = ('/');
                   6406:                 foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
                   6407:                     $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
                   6408:                     push(@ordered,$relpath);
                   6409:                 }
                   6410:                 $select_menus{'course'}->{'order'} = \@ordered;
                   6411:             } else {
                   6412:                 $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
                   6413:                 $select_menus{'course'}->{'default'} = 'switch';
                   6414:                 $select_menus{'course'}->{'order'} = ['switch'];
                   6415:             }
                   6416:             push(@order,'course');
                   6417:             $pickdir = $lt{'loca'}.
                   6418:                        &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
                   6419:                                                                $defrole,'authorrole','authorpath',
                   6420:                                                                \%select_menus,\@order,'toggleCrsResTitle();',
                   6421:                                                                '','priv').'<br />';
                   6422:             $showtitle = 'none';
                   6423:         } else {
                   6424:             my $is_home;
                   6425:             $showtitle = 'inline';
                   6426:             if (grep(/^\Q$crshome\E$/,@ids)) {
                   6427:                 $is_home = 1;
                   6428:                 $pickdir .= '<input type="hidden" name="authorrole" value="course" />'; 
                   6429:                 my $toppath="/priv/$coursedom/$coursenum'}";
                   6430:                 my %subdirs;
1.608     raeburn  6431:                 &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606     raeburn  6432:                 $numcrsdirs = keys(%subdirs); 
                   6433:                 if ($numcrsdirs) {
                   6434:                     $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
                   6435:                                  '<option value="/">/</option>'."\n";
                   6436:                     foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608     raeburn  6437:                         $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606     raeburn  6438:                     }
                   6439:                     $pickdir .= '</select>';
                   6440:                 } else {
                   6441:                     $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";   
                   6442:                 }
                   6443:             }
                   6444:         }
                   6445: 
                   6446:         my %seltemplate_menus;
                   6447:         my @files = &Apache::lonhomework::get_template_list('problem');
                   6448:         my @noexamplelink = ('blank.problem','blank.library','script.library');
                   6449:         my $currentcategory = '';
                   6450:         my @ordered = ('');
                   6451:         my %templatehelp;
                   6452:         my $defcategory = '';
                   6453:         my @catorder = ($defcategory);
                   6454:         $seltemplate_menus{$defcategory}->{'order'} = [''];
                   6455:         $seltemplate_menus{$defcategory}->{'text'} = '';
                   6456:         foreach my $file (@files) {
                   6457:             if (ref($file) eq 'ARRAY') {
                   6458:                 my ($path,$title,$category,$help) = @{$file};
                   6459:                 next if ($title !~ /\S/);
                   6460:                 if (&js_escape($category) ne $currentcategory) {
                   6461:                     $currentcategory = &js_escape($category);
                   6462:                     push(@catorder,&js_escape($currentcategory));
                   6463:                     $seltemplate_menus{$currentcategory}->{'text'} = $category;
                   6464:                     $seltemplate_menus{$currentcategory}->{'default'} = '';
                   6465:                     $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
                   6466:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
                   6467:                 }
                   6468:                 if ($path) {
                   6469:                     $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
                   6470:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
                   6471:                     if ($help) {
                   6472:                         $templatehelp{$path} = $help;
                   6473:                     }
                   6474:                 }
                   6475:             }
                   6476:         }
                   6477: 
                   6478:         my $templates = $lt{'cate'}.' '.
                   6479:                         &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
                   6480:                                                                 $defcategory,'tempcategory','template',
                   6481:                                                                 \%seltemplate_menus,\@catorder,
                   6482:                                                                 "resize_scrollbox('contentscroll','1','0');",
                   6483:                                                                 "toggleExampleText();",'template').'<br />';
                   6484:         my $templatepreview =  '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true);  return false;">'.
                   6485:                                '<span id="newresexample">'.&mt('Example').'<span></a>';
                   6486:         my $crsresform=(<<RESFORM);
                   6487:         <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
                   6488:         $lt{'stpr'}</a>$help{'Course_Resource'}
                   6489:         <form action="/adm/coursedocs" method="post" name="courseresform">
                   6490:         <fieldset id="crsresform" style="display:none;">
                   6491:         <legend>$lt{'stpr'}</legend>
1.655     raeburn  6492:         <input type="hidden" name="active" value="bb" />
1.606     raeburn  6493:         <p>
                   6494:         $pickdir
                   6495:         <span class="LC_nobreak">$lt{'news'}?&nbsp;
1.611     raeburn  6496:         <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606     raeburn  6497:         &nbsp;
1.611     raeburn  6498:         <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606     raeburn  6499:         </span><span id="newsubdir"></span>
                   6500:         <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
                   6501:         </p>
                   6502:         $lt{'fnam'}
1.611     raeburn  6503:         <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606     raeburn  6504:         <p>
                   6505:         <div id="newresource" style="display:$showtitle">
                   6506:         $lt{'addp'}
1.611     raeburn  6507:         <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  6508:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  6509:         <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  6510:         $lt{'yes'}</label>
                   6511:         <span id="newrestitle"></span>
1.611     raeburn  6512:         <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606     raeburn  6513:         </div>
                   6514:         </p>
                   6515:         <p>
                   6516:         $lt{'uste'}
1.611     raeburn  6517:         <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  6518:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  6519:         <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  6520:         $lt{'yes'}</label>
                   6521:         <div id="newrestemplate" style="display:none">
                   6522:         $templates
                   6523:         $templatepreview
                   6524:         </div>
                   6525:         </p>
                   6526:         <span class="LC_nobreak">
                   6527:         <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611     raeburn  6528:         <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606     raeburn  6529:         </span>
                   6530:         </fieldset>
                   6531:         </form>
                   6532: 
                   6533: RESFORM
1.534     raeburn  6534: 
1.342     ehlerst  6535: my $specialdocumentsform;
1.383     tempelho 6536: my @specialdocumentsforma;
1.451     www      6537: my $gradingform;
                   6538: my @gradingforma;
                   6539: my $communityform;
                   6540: my @communityforma;
1.351     ehlerst  6541: my $newfolderform;
1.390     tempelho 6542: my $newfolderb;
1.342     ehlerst  6543: 
1.451     www      6544: 	my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383     tempelho 6545: 	
1.329     droeschl 6546: 	my $newpageform=(<<NPFORM);
                   6547: 	<form action="/adm/coursedocs" method="post" name="newpage">
                   6548: 	<input type="hidden" name="folderpath" value="$path" />
                   6549: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  6550: 	<input type="hidden" name="active" value="ee" />
1.423     onken    6551: 	<a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383     tempelho 6552: 	$help{'Adding_Pages'}
1.329     droeschl 6553: 	</form>
                   6554: NPFORM
1.390     tempelho 6555: 
                   6556: 
1.351     ehlerst  6557: 	$newfolderform=(<<NFFORM);
1.329     droeschl 6558: 	<form action="/adm/coursedocs" method="post" name="newfolder">
1.508     raeburn  6559: 	$pathitem
1.329     droeschl 6560: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  6561: 	<input type="hidden" name="active" value="" />
1.422     onken    6562: 	<a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329     droeschl 6563: 	</form>
                   6564: NFFORM
                   6565: 
                   6566: 	my $newsylform=(<<NSYLFORM);
                   6567: 	<form action="/adm/coursedocs" method="post" name="newsyl">
1.570     raeburn  6568: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6569: 	$pathitem
1.329     droeschl 6570: 	<input type="hidden" name="importdetail" 
                   6571: 	value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  6572: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329     droeschl 6573: 	$help{'Syllabus'}
1.383     tempelho 6574: 
1.329     droeschl 6575: 	</form>
                   6576: NSYLFORM
1.364     bisitz   6577: 
1.329     droeschl 6578: 	my $newgroupfileform=(<<NGFFORM);
                   6579: 	<form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655     raeburn  6580: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6581: 	$pathitem
1.329     droeschl 6582: 	<input type="hidden" name="importdetail"
                   6583: 	value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611     raeburn  6584: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353     weissno  6585: 	$help{'Group Portfolio'}
1.329     droeschl 6586: 	</form>
                   6587: NGFFORM
1.672   ! raeburn  6588:         if ($container eq 'page') {
        !          6589:             @specialdocumentsforma=(
        !          6590:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
        !          6591:             );
        !          6592:         } else {
        !          6593: 	    @specialdocumentsforma=(
1.421     onken    6594: 	{'<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  6595: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611     raeburn  6596: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451     www      6597:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534     raeburn  6598:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672   ! raeburn  6599:             );
        !          6600:         }
1.451     www      6601:         $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
                   6602: 
1.655     raeburn  6603:         my @external = (
                   6604:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519     raeburn  6605:         );
1.598     raeburn  6606:         if (keys(%ltitools)) {
1.655     raeburn  6607:             push(@external,
                   6608:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
                   6609:             );
1.598     raeburn  6610:         }
1.655     raeburn  6611:         my $externalform = &create_form_ul(&create_list_elements(@external));
                   6612: 
                   6613:         my @importdoc = ();
1.519     raeburn  6614:         unless ($container eq 'page') {
                   6615:             push(@importdoc,
                   6616:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
                   6617:             );
                   6618:         }
                   6619:         push(@importdoc,
1.558     raeburn  6620:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519     raeburn  6621:         );
1.501     raeburn  6622:         $fileuploadform =  &create_form_ul(&create_list_elements(@importdoc));
1.434     raeburn  6623: 
1.451     www      6624:         @gradingforma=(
                   6625:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
                   6626:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
                   6627:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606     raeburn  6628:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
1.451     www      6629:         );
                   6630:         $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
                   6631: 
                   6632:         @communityforma=(
                   6633:        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
                   6634:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
                   6635:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611     raeburn  6636:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
                   6637:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451     www      6638:         );
                   6639:         $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383     tempelho 6640: 
1.330     tempelho 6641: my %orderhash = (
1.553     raeburn  6642:                 'aa' => ['Upload',$fileuploadform],
                   6643:                 'bb' => ['Import',$importpubform],
1.655     raeburn  6644:                 'cc' => ['External',$externalform],
                   6645:                 'dd' => ['Grading',$gradingform],
1.672   ! raeburn  6646:                 'ff' => ['Other',$specialdocumentsform]; 
1.330     tempelho 6647:                 );
1.519     raeburn  6648: unless ($container eq 'page') {
1.434     raeburn  6649:     $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655     raeburn  6650:     $orderhash{'ee'} = ['Collaboration',$communityform];
1.434     raeburn  6651: }
                   6652: 
1.341     ehlerst  6653:  $hadchanges=0;
1.484     raeburn  6654:        unless (($supplementalflag || $toolsflag)) {
1.458     raeburn  6655:           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615     raeburn  6656:                               $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622     raeburn  6657:                               \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617     raeburn  6658:           undef($navmap);
1.443     www      6659:           if ($error) {
                   6660:              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   6661:           }
1.639     raeburn  6662:           if ($hadchanges) {
                   6663:               unless (&is_hash_old()) {
1.638     raeburn  6664:                   &mark_hash_old();
                   6665:               }
                   6666: 	  }
1.341     ehlerst  6667: 
1.443     www      6668:           &changewarning($r,'');
                   6669:         }
1.458     raeburn  6670:     }
1.442     www      6671: 
1.443     www      6672: # Supplemental documents start here
                   6673: 
1.329     droeschl 6674:        my $folder=$env{'form.folder'};
1.443     www      6675:        unless ($supplementalflag) {
1.329     droeschl 6676: 	   $folder='supplemental';
                   6677:        }
                   6678:        if ($folder =~ /^supplemental$/ &&
                   6679: 	   (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446     www      6680:           $env{'form.folderpath'} = &supplemental_base();
1.393     raeburn  6681:        } elsif ($allowed) {
1.356     tempelho 6682: 	  $env{'form.folderpath'} = $savefolderpath;
1.329     droeschl 6683:        }
1.508     raeburn  6684:        $pathitem = '<input type="hidden" name="folderpath" value="'.
                   6685:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329     droeschl 6686:        if ($allowed) {
                   6687: 	   my $folderseq=
1.504     raeburn  6688: 	       '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329     droeschl 6689: 
                   6690: 	my $supupdocform=(<<SUPDOCFORM);
1.501     raeburn  6691:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
                   6692:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383     tempelho 6693: 	<form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516     raeburn  6694:         <fieldset id="uploadsuppdocform" style="display: none;">
1.501     raeburn  6695:         <legend>$lt{'upfi'}</legend>
1.630     raeburn  6696: 	<input type="hidden" name="active" value="ee" />
1.329     droeschl 6697: 	$fileupload
                   6698: 	<br />
                   6699: 	<br />
                   6700: 	<span class="LC_nobreak">
                   6701: 	$checkbox
                   6702: 	</span>
                   6703: 	<br /><br />
                   6704: 	$lt{'comment'}:<br />
1.383     tempelho 6705: 	<textarea cols="50" rows="4" name="comment"></textarea>
1.329     droeschl 6706: 	<br />
1.508     raeburn  6707: 	$pathitem
1.329     droeschl 6708: 	<input type="hidden" name="cmd" value="upload_supplemental" />
1.501     raeburn  6709:         <input type='submit' value="$lt{'upld'}" />
                   6710:         </form>
1.329     droeschl 6711: SUPDOCFORM
                   6712: 
                   6713: 	my $supnewfolderform=(<<SNFFORM);
                   6714: 	<form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570     raeburn  6715: 	<input type="hidden" name="active" value="" />
1.508     raeburn  6716:         $pathitem
1.329     droeschl 6717: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6718: 	<a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a> 
1.383     tempelho 6719: 	$help{'Adding_Folders'}
1.329     droeschl 6720: 	</form>
                   6721: SNFFORM
1.383     tempelho 6722: 	
1.510     raeburn  6723:         my $supextform =
                   6724:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611     raeburn  6725:                                                  $help{'Adding_External_Resource'},
                   6726:                                                  undef,undef,undef,undef,undef,undef,
                   6727:                                                  $disabled);
1.329     droeschl 6728: 
1.598     raeburn  6729:         my $supexttoolform =
                   6730:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
                   6731:                                                  $help{'Adding_External_Tool'},
                   6732:                                                  undef,undef,'tool',$coursedom,
1.611     raeburn  6733:                                                  $coursenum,\%ltitools,$disabled);
1.598     raeburn  6734: 
1.329     droeschl 6735: 	my $supnewsylform=(<<SNSFORM);
                   6736: 	<form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371     tempelho 6737: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6738:         $pathitem
1.329     droeschl 6739: 	<input type="hidden" name="importdetail" 
                   6740: 	value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  6741: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329     droeschl 6742: 	$help{'Syllabus'}
                   6743: 	</form>
                   6744: SNSFORM
                   6745: 
                   6746: 	my $supnewaboutmeform=(<<SNAMFORM);
1.383     tempelho 6747: 	<form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371     tempelho 6748: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6749:         $pathitem
1.329     droeschl 6750: 	<input type="hidden" name="importdetail" 
                   6751: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  6752: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347     weissno  6753: 	$help{'My Personal Information Page'}
1.329     droeschl 6754: 	</form>
                   6755: SNAMFORM
                   6756: 
1.534     raeburn  6757:         my $supwebpage;
                   6758:         if ($folder =~ /^supplemental_?(\d*)$/) {
                   6759:             $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
                   6760:             if ($1) {
                   6761:                 $supwebpage .= $1;
                   6762:             } else {
                   6763:                 $supwebpage .= 'default';
                   6764:             }
                   6765:             $supwebpage .= '/new.html';
                   6766:         }
                   6767:         my $supwebpageform =(<<SWEBFORM);
                   6768:         <form action="/adm/coursedocs" method="post" name="supwebpage">
                   6769:         <input type="hidden" name="active" value="cc" />
                   6770:         $pathitem
                   6771:         <input type="hidden" name="importdetail" value="$supwebpage" />
                   6772:         <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556     raeburn  6773:         $help{'Web_Page'}
1.534     raeburn  6774:         </form>
                   6775: SWEBFORM
                   6776: 
1.333     muellerd 6777: 
1.383     tempelho 6778: my @specialdocs = (
1.618     raeburn  6779: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417     droeschl 6780:             =>$supnewsylform},
1.611     raeburn  6781: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417     droeschl 6782:             =>$supnewaboutmeform},
1.534     raeburn  6783:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
                   6784: 
1.383     tempelho 6785: 		);
1.655     raeburn  6786:         my @supexternal = (
                   6787:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
                   6788:              =>$supextform});
1.598     raeburn  6789:         if (keys(%ltitools)) {
1.655     raeburn  6790:             push(@supexternal,
                   6791:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598     raeburn  6792:             =>$supexttoolform});
                   6793:         }
1.655     raeburn  6794:         my @supimportdoc = (
1.598     raeburn  6795:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501     raeburn  6796:             =>$supupdocform},
1.598     raeburn  6797:         );
1.501     raeburn  6798: 
                   6799: $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc));
1.333     muellerd 6800: my %suporderhash = (
1.390     tempelho 6801: 		'00' => ['Supnewfolder', $supnewfolderform],
1.655     raeburn  6802:                 'dd' => ['Upload',$supupdocform],
                   6803:                 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553     raeburn  6804:                 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333     muellerd 6805:                 );
1.443     www      6806:         if ($supplementalflag) {
1.458     raeburn  6807:            my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615     raeburn  6808:                                $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622     raeburn  6809:                                \%ltitools,$canedit,$hostname);
1.443     www      6810:            if ($error) {
                   6811:               $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557     raeburn  6812:            } else {
                   6813:                if ($suppchanges) {
                   6814:                    my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
                   6815:                    my @ids=&Apache::lonnet::current_machine_ids();
                   6816:                    foreach my $server (keys(%servers)) {
                   6817:                        next if (grep(/^\Q$server\E$/,@ids));
                   6818:                        my $hashid=$coursenum.':'.$coursedom;
1.566     raeburn  6819:                        my $cachekey = &escape('suppcount').':'.&escape($hashid);
                   6820:                        &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557     raeburn  6821:                    }
                   6822:                    &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
                   6823:                    undef($suppchanges);
1.630     raeburn  6824:                }
                   6825:            }
1.393     raeburn  6826:         }
1.443     www      6827:     } elsif ($supplementalflag) {
1.458     raeburn  6828:         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622     raeburn  6829:                             $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393     raeburn  6830:         if ($error) {
                   6831:             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383     tempelho 6832:         }
1.393     raeburn  6833:     }
1.389     tempelho 6834: 
1.510     raeburn  6835:     if ($needs_end) {
                   6836:         $r->print(&endContentScreen());
                   6837:     }
1.383     tempelho 6838: 
1.329     droeschl 6839:     if ($allowed) {
                   6840: 	$r->print('
                   6841: <form method="post" name="extimport" action="/adm/coursedocs">
                   6842:   <input type="hidden" name="title" />
                   6843:   <input type="hidden" name="url" />
                   6844:   <input type="hidden" name="useform" />
                   6845:   <input type="hidden" name="residx" />
                   6846: </form>');
                   6847:     }
1.484     raeburn  6848:   } elsif ($showdoc) {
1.329     droeschl 6849: # -------------------------------------------------------- This is showdoc mode
1.484     raeburn  6850:       $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498     bisitz   6851: 		&Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329     droeschl 6852: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484     raeburn  6853:                 &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329     droeschl 6854:   }
                   6855:  }
1.630     raeburn  6856:  unless ($noendpage) {
1.606     raeburn  6857:      $r->print(&Apache::loncommon::end_page());
                   6858:  }
1.329     droeschl 6859:  return OK;
1.364     bisitz   6860: }
1.329     droeschl 6861: 
1.440     raeburn  6862: sub embedded_form_elems {
                   6863:     my ($phase,$primaryurl,$newidx) = @_;
                   6864:     my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634     raeburn  6865:     $newidx =~s /\D+//g;
1.440     raeburn  6866:     return <<STATE;
                   6867:     <input type="hidden" name="folderpath" value="$folderpath" />
                   6868:     <input type="hidden" name="cmd" value="upload_embedded" />
                   6869:     <input type="hidden" name="newidx" value="$newidx" />
                   6870:     <input type="hidden" name="phase" value="$phase" />
                   6871:     <input type="hidden" name="primaryurl" value="$primaryurl" />
                   6872: STATE
                   6873: }
                   6874: 
                   6875: sub embedded_destination {
                   6876:     my $folder=$env{'form.folder'};
                   6877:     my $destination = 'docs/';
                   6878:     if ($folder =~ /^supplemental/) {
                   6879:         $destination = 'supplemental/';
                   6880:     }
                   6881:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   6882:         $destination .= 'default/';
                   6883:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   6884:         $destination .=  $2.'/';
                   6885:     }
1.634     raeburn  6886:     my $newidx = $env{'form.newidx'};
                   6887:     $newidx =~s /\D+//g;
                   6888:     if ($newidx) {
                   6889:         $destination .= $newidx;
                   6890:     }
1.440     raeburn  6891:     my $dir_root = '/userfiles';
                   6892:     return ($destination,$dir_root);
                   6893: }
                   6894: 
                   6895: sub return_to_editor {
                   6896:     my $actionurl = '/adm/coursedocs';
                   6897:     return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n". 
                   6898:            '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
                   6899:            '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
                   6900:            '</a></p>';
                   6901: }
                   6902: 
1.476     raeburn  6903: sub decompression_info {
                   6904:     my ($destination,$dir_root) = &embedded_destination();
                   6905:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                   6906:     my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   6907:     my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   6908:     my $container='sequence';
1.480     raeburn  6909:     my ($pathitem,$hiddenelem);
1.583     raeburn  6910:     my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519     raeburn  6911:     if ($env{'form.folderpath'} =~ /\:1$/) {
1.476     raeburn  6912:         $container='page';
                   6913:     }
1.480     raeburn  6914:     unshift(@hiddens,$pathitem);
                   6915:     foreach my $item (@hiddens) {
1.634     raeburn  6916:         if ($item eq 'newidx') {
                   6917:             next if ($env{'form.'.$item} =~ /\D/);
                   6918:         }
1.480     raeburn  6919:         if ($env{'form.'.$item}) {
                   6920:             $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583     raeburn  6921:                            &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480     raeburn  6922:         }
1.477     raeburn  6923:     }
1.476     raeburn  6924:     return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
                   6925:             $hiddenelem);
                   6926: }
                   6927: 
                   6928: sub decompression_phase_one {
                   6929:     my ($dir,$file,$warning,$error,$output);
                   6930:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   6931:         &decompression_info();
1.490     raeburn  6932:     if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476     raeburn  6933:         $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
                   6934:     } else {
                   6935:         my $file = $1;
1.630     raeburn  6936:         $output =
1.481     raeburn  6937:             &Apache::loncommon::process_decompression($docudom,$docuname,$file,
                   6938:                                                       $destination,$dir_root,
                   6939:                                                       $hiddenelem);
                   6940:         if ($env{'form.autoextract_camtasia'}) {
                   6941:             $output .= &remove_archive($docudom,$docuname,$container);
                   6942:         }
1.476     raeburn  6943:     }
                   6944:     if ($error) {
                   6945:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   6946:                    $error.'</p>'."\n";
                   6947:     }
                   6948:     if ($warning) {
                   6949:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   6950:     }
                   6951:     return $output;
                   6952: }
                   6953: 
                   6954: sub decompression_phase_two {
                   6955:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   6956:         &decompression_info();
1.481     raeburn  6957:     my $output;
1.480     raeburn  6958:     if ($env{'form.archivedelete'}) {
1.481     raeburn  6959:         $output = &remove_archive($docudom,$docuname,$container);
1.480     raeburn  6960:     }
                   6961:     $output .= 
1.481     raeburn  6962:         &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476     raeburn  6963:                                                     $destination,$dir_root,$hiddenelem);
                   6964:     return $output;
                   6965: }
                   6966: 
1.480     raeburn  6967: sub remove_archive {
                   6968:     my ($docudom,$docuname,$container) = @_;
                   6969:     my $map = $env{'form.folder'}.'.'.$container;
1.481     raeburn  6970:     my ($output,$delwarning,$delresult,$url);
1.480     raeburn  6971:     my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
                   6972:     if ($fatal) {
                   6973:         if ($container eq 'page') {
                   6974:             $delwarning = &mt('An error occurred retrieving the contents of the current page.');
                   6975:         } else {
                   6976:             $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
                   6977:         }
1.583     raeburn  6978:         $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  6979:     } else {
                   6980:         my $currcmd = $env{'form.cmd'};
                   6981:         my $position = $env{'form.position'};
1.583     raeburn  6982:         my $archiveidx = $position;
1.563     raeburn  6983:         if ($position > 0) {
1.583     raeburn  6984:             if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
                   6985:                 $archiveidx = $position-1;
                   6986:             }
                   6987:             $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584     raeburn  6988:             my ($title,$url,@rrest) =
1.583     raeburn  6989:                 split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
                   6990:             if ($url eq $env{'form.archiveurl'}) {
                   6991:                 if (&handle_edit_cmd($docuname,$docudom)) {
                   6992:                     ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
                   6993:                     if ($fatal) {
                   6994:                         if ($container eq 'page') {
                   6995:                             $delwarning = &mt('An error occurred updating the contents of the current page.');
                   6996:                         } else {
                   6997:                             $delwarning = &mt('An error occurred updating the contents of the current folder.');
                   6998:                         }
1.480     raeburn  6999:                     } else {
1.583     raeburn  7000:                         $delresult = &mt('Archive file removed.');
1.480     raeburn  7001:                     }
                   7002:                 }
1.583     raeburn  7003:             } else {
                   7004:                 $delwarning .=  &mt('Archive file had unexpected item number in folder.').
                   7005:                                 ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  7006:             }
                   7007:         }
                   7008:         $env{'form.cmd'} = $currcmd;
                   7009:     }
                   7010:     if ($delwarning) {
                   7011:         $output = '<p class="LC_warning">'.
                   7012:                    $delwarning.
                   7013:                    '</p>';
                   7014:     }
                   7015:     if ($delresult) {
                   7016:         $output .= '<p class="LC_info">'.
                   7017:                    $delresult.
                   7018:                    '</p>';
                   7019:     }
1.481     raeburn  7020:     return $output;
1.480     raeburn  7021: }
                   7022: 
1.484     raeburn  7023: sub generate_admin_menu {
1.611     raeburn  7024:     my ($crstype,$canedit) = @_;
1.484     raeburn  7025:     my $lc_crstype = lc($crstype);
                   7026:     my ($home,$other,%outhash)=&authorhosts();
1.562     bisitz   7027:     my %lt= ( # do not translate here
1.484     raeburn  7028:                                          'vc'   => 'Verify Content',
                   7029:                                          'cv'   => 'Check/Set Resource Versions',
                   7030:                                          'ls'   => 'List Resource Identifiers',
1.651     raeburn  7031:                                          'ct'   => 'Display/Set Shortened URLs for Deep-linking',
1.484     raeburn  7032:                                          'imse' => 'Export contents to IMS Archive',
1.568     raeburn  7033:                                          'dcd'  => "Copy $crstype Content to Authoring Space",
1.562     bisitz   7034:             );
1.484     raeburn  7035:     my ($candump,$dumpurl);
                   7036:     if ($home + $other > 0) {
                   7037:         $candump = 'F';
                   7038:         if ($home) {
                   7039:             $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
                   7040:         } else {
                   7041:             my @hosts;
                   7042:             foreach my $aurole (keys(%outhash)) {
                   7043:                 unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   7044:                     push(@hosts,$outhash{$aurole});
1.538     raeburn  7045:                 }
1.484     raeburn  7046:             }
                   7047:             if (@hosts == 1) {
                   7048:                 my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
                   7049:                                '&amp;role='.
                   7050:                                &HTML::Entities::encode($env{'request.role'},'"<>&').'&amp;origurl='.
                   7051:                                &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
                   7052:                 $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
                   7053:             } else {
                   7054:                 $dumpurl = "javascript:choose_switchserver_window()";
                   7055:             }
                   7056:         }
                   7057:     }
                   7058:     my @menu=
                   7059:         ({  categorytitle=>'Administration',
                   7060:             items =>[
                   7061:                 {   linktext   => $lt{'vc'},
                   7062:                     url        => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
                   7063:                     permission => 'F',
1.571     raeburn  7064:                     help       => 'Docs_Verify_Content',
1.484     raeburn  7065:                     icon       => 'verify.png',
                   7066:                     linktitle  => 'Verify contents can be retrieved/rendered',
                   7067:                 },
                   7068:                 {   linktext => $lt{'cv'},
                   7069:                     url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
                   7070:                     permission => 'F',
1.571     raeburn  7071:                     help       => 'Docs_Check_Resource_Versions',
1.484     raeburn  7072:                     icon       => 'resversion.png',
                   7073:                     linktitle  => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
                   7074:                 },
                   7075:                 {   linktext   => $lt{'ls'},
                   7076:                     url        => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
                   7077:                     permission => 'F',
                   7078:                     #help => '',
                   7079:                     icon       => 'symbs.png',
                   7080:                     linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"
                   7081:                 },
1.651     raeburn  7082:                 {   linktext   => $lt{'ct'},
                   7083:                     url        => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
                   7084:                     permission => 'F',
                   7085:                     help       => 'Docs_Short_URLs',
                   7086:                     icon       => 'shorturls.png',
                   7087:                     linktitle  => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
                   7088:                 },
1.484     raeburn  7089:                 ]
1.611     raeburn  7090:         });
                   7091:     if ($canedit) {
                   7092:         push(@menu,
1.484     raeburn  7093:         {   categorytitle=>'Export',
                   7094:             items =>[
                   7095:                 {   linktext   => $lt{'imse'},
                   7096:                     url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
                   7097:                     permission => 'F',
                   7098:                     help       => 'Docs_Export_Course_Docs',
                   7099:                     icon       => 'imsexport.png',
                   7100:                     linktitle  => $lt{'imse'},
                   7101:                 },
                   7102:                 {   linktext   => $lt{'dcd'},
                   7103:                     url        => $dumpurl,
                   7104:                     permission => $candump,
1.571     raeburn  7105:                     help       => 'Docs_Dump_Course_Docs',
1.484     raeburn  7106:                     icon       => 'dump.png',
                   7107:                     linktitle  => $lt{'dcd'},
                   7108:                 },
                   7109:                 ]
                   7110:         });
1.611     raeburn  7111:     }
1.484     raeburn  7112:     return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
                   7113:            '<input type="hidden" id="dummy" />'."\n".
                   7114:            &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
                   7115:            '</form>';
1.329     droeschl 7116: }
                   7117: 
                   7118: sub generate_edit_table {
1.538     raeburn  7119:     my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611     raeburn  7120:         $need_save,$copyfolder,$canedit) = @_;
1.406     raeburn  7121:     return unless(ref($orderhash_ref) eq 'HASH');
1.342     ehlerst  7122:     my %orderhash = %{$orderhash_ref};
1.611     raeburn  7123:     my ($form, $activetab, $active, $disabled);
1.570     raeburn  7124:     if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371     tempelho 7125:         $activetab = $env{'form.active'};
                   7126:     }
1.611     raeburn  7127:     unless ($canedit) {
                   7128:         $disabled = ' disabled="disabled"';
                   7129:     }
1.472     raeburn  7130:     my $backicon = $iconpath.'clickhere.gif';
1.525     raeburn  7131:     my $backtext = &mt('Exit Editor');
1.458     raeburn  7132:     $form = '<div class="LC_Box" style="margin:0;">'.
1.488     raeburn  7133:             '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
                   7134:             '<li class="goback">'.
1.546     raeburn  7135:             '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488     raeburn  7136:             '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
                   7137:             '  alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
                   7138:             '<li>'.
                   7139:             '<a href="javascript:groupopen('."'$readfile'".',1);">'.
                   7140:             &mt('Undo Delete').'</a></li>'."\n";
                   7141:     if ($env{'form.docslog'}) {
                   7142:         $form .= '<li class="active">';
                   7143:     } else {
                   7144:         $form .= '<li>';
                   7145:     }
                   7146:     $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
                   7147:              &mt('History').'</a></li>'."\n";
                   7148:     if ($env{'form.docslog'}) {
                   7149:         $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
                   7150:                  &mt('Edit').'</a></li>'."\n";
1.484     raeburn  7151:     }
1.458     raeburn  7152:     foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390     tempelho 7153:         if($name ne '00'){
1.371     tempelho 7154:             if($activetab eq '' || $activetab ne $name){
                   7155:                $active = '';
                   7156:             }elsif($activetab eq $name){
                   7157:                $active = 'class="active"';
                   7158:             }
1.458     raeburn  7159:             $form .= '<li style="float:right" '.$active
1.484     raeburn  7160:                 .' 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 7161:         } else {
1.570     raeburn  7162: 	    $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390     tempelho 7163: 
                   7164: 	}
1.329     droeschl 7165:     }
1.484     raeburn  7166:     $form .= '</ul>'."\n";
                   7167:     $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458     raeburn  7168: 
                   7169:     if ($to_show ne '') {
1.538     raeburn  7170:         my $saveform;
                   7171:         if ($need_save) {
                   7172:             my $button = &mt('Make changes');
                   7173:             my $path;
                   7174:             if ($env{'form.folderpath'}) {
                   7175:                 $path =
                   7176:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   7177:             }
                   7178:             $saveform = <<"END";
                   7179: <div id="multisave" style="display:none; clear:both;" >
                   7180: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
                   7181: <input type="hidden" name="folderpath" value="$path" />
                   7182: <input type="hidden" name="symb" value="$env{'form.symb'}" />
                   7183: <input type="hidden" name="allhiddenresource" value="" />
                   7184: <input type="hidden" name="allencrypturl" value="" />
                   7185: <input type="hidden" name="allrandompick" value="" />
                   7186: <input type="hidden" name="allrandomorder" value="" />
                   7187: <input type="hidden" name="changeparms" value="" />
                   7188: <input type="hidden" name="multiremove" value="" />
                   7189: <input type="hidden" name="multicut" value="" />
                   7190: <input type="hidden" name="multicopy" value="" />
                   7191: <input type="hidden" name="multichange" value="" />
                   7192: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611     raeburn  7193: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538     raeburn  7194: </form>
                   7195: </div>
                   7196: END
                   7197:         }
                   7198:         $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458     raeburn  7199:     }
1.363     ehlerst  7200:     foreach my $field (keys(%orderhash)){
1.390     tempelho 7201: 	if($field ne '00'){
1.422     onken    7202:             if($activetab eq '' || $activetab ne $field){
1.458     raeburn  7203:                 $active = 'style="display: none;float:left"';
1.422     onken    7204:             }elsif($activetab eq $field){
1.458     raeburn  7205:                 $active = 'style="display:block;float:left"';
1.422     onken    7206:             }
                   7207:             $form .= '<div id="'.$field.$tid.'"'
                   7208:                     .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484     raeburn  7209:                     .'</div>'."\n";
1.363     ehlerst  7210:         }
                   7211:     }
1.484     raeburn  7212:     unless ($env{'form.docslog'}) {
                   7213:         $form .= '</div></div>'."\n";
                   7214:     }
1.329     droeschl 7215:     return $form;
                   7216: }
                   7217: 
                   7218: sub editing_js {
1.622     raeburn  7219:     my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
                   7220:         $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594     damieng  7221:     my %js_lt = &Apache::lonlocal::texthash(
1.329     droeschl 7222:                                           p_mnf => 'Name of New Folder',
                   7223:                                           t_mnf => 'New Folder',
                   7224:                                           p_mnp => 'Name of New Page',
                   7225:                                           t_mnp => 'New Page',
1.451     www      7226:                                           p_mxu => 'Title for the External Score',
1.349     biermanm 7227:                                           p_msp => 'Name of Simple Course Page',
1.329     droeschl 7228:                                           p_msb => 'Title for the Problem',
                   7229:                                           p_mdb => 'Title for the Drop Box',
1.336     schafran 7230:                                           p_mbb => 'Title for the Discussion Board',
1.604     raeburn  7231:                                           p_mwp => 'Title for Web Page',
1.606     raeburn  7232:                                           p_mnr => 'Title for the Resource',
1.348     weissno  7233:                                           p_mab => "Enter user:domain for User's Personal Information Page",
1.352     bisitz   7234:                                           p_mab2 => 'Personal Information Page of ',
1.329     droeschl 7235:                                           p_mab_alrt1 => 'Not a valid user:domain',
                   7236:                                           p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
                   7237:                                           p_chn => 'New Title',
                   7238:                                           p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603     raeburn  7239:                                           p_rmr2a => 'Remove',
                   7240:                                           p_rmr2b => '?',
                   7241:                                           p_rmr3a => 'Remove those',
                   7242:                                           p_rmr3b => 'items?',
                   7243:                                           p_rmr4  => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
                   7244:                                           p_rmr5  => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329     droeschl 7245:                                           p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
                   7246:                                           p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603     raeburn  7247:                                           p_ctr2a => 'Cut',
                   7248:                                           p_ctr2b => '?',
                   7249:                                           p_ctr3a => 'Cut those',
                   7250:                                           p_ctr3b => 'items?',
1.633     raeburn  7251:                                           setal   => 'Enter a (unique) alias',
                   7252:                                           delal   => 'Are you sure you want to eliminate the alias?',
1.478     raeburn  7253:                                           rpck    => 'Enter number to pick (e.g., 3)',
1.501     raeburn  7254:                                           imsfile => 'You must choose an IMS package for import',
                   7255:                                           imscms  => 'You must select which Course Management System was the source of the IMS package',
                   7256:                                           invurl  => 'Invalid URL',
                   7257:                                           titbl   => 'Title is blank',
1.538     raeburn  7258:                                           more    => '(More ...)',
                   7259:                                           less    => '(Less ...)',
1.543     raeburn  7260:                                           noor    => 'No actions selected or changes to settings specified.',
                   7261:                                           noch    => 'No changes to settings specified.',
                   7262:                                           noac    => 'No actions selected.',
1.606     raeburn  7263:                                           nofi    => 'No file selected',
                   7264:                                           tinc    => 'Title in course',
                   7265:                                           sunm    => 'Sub-directory name',
1.618     raeburn  7266:                                           edri    => 'Editing rights unavailable for your current role.',
1.329     droeschl 7267:                                         );
1.594     damieng  7268:     &js_escape(\%js_lt);
1.433     raeburn  7269:     my $crstype = &Apache::loncommon::course_type();
1.434     raeburn  7270:     my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
                   7271:     my $main_container_page;
1.519     raeburn  7272:     if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
                   7273:         $main_container_page = 1;
1.434     raeburn  7274:     }
1.617     raeburn  7275:     my $backtourl;
                   7276:     my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446     www      7277:     my $toplevelsupp = &supplemental_base();
1.433     raeburn  7278: 
1.530     raeburn  7279:     if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
                   7280:         my $caller = $1;
1.525     raeburn  7281:         if ($caller =~ /^supplemental/) {
                   7282:             $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
                   7283:         } else {
                   7284:             my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
                   7285:             $res = &Apache::lonnet::clutter($res);
                   7286:             if (&Apache::lonnet::is_on_map($res)) {
1.609     raeburn  7287:                 my ($url,$anchor);
                   7288:                 if ($res =~ /^([^#]+)#([^#]+)$/) {
                   7289:                     $url = $1;
                   7290:                     $anchor = $2;
                   7291:                     if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
                   7292:                         $caller = $1.&escape('#').$anchor;
                   7293:                     }
1.614     raeburn  7294:                 } else {
                   7295:                     $url = $res;
1.609     raeburn  7296:                 }
1.640     raeburn  7297:                 $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
                   7298:                 if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
                   7299:                     $backtourl .= '?navmap=1';
                   7300:                 } else {
                   7301:                     $backtourl .= '?symb='.
                   7302:                                   &HTML::Entities::encode($caller,'<>&"');
                   7303:                 }
1.622     raeburn  7304:                 if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   7305:                     if (($ENV{'SERVER_PORT'} == 443) &&
                   7306:                         ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.657     raeburn  7307:                         unless (&Apache::lonnet::uses_sts()) {
                   7308:                             if ($hostname ne '') {
                   7309:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   7310:                             }
                   7311:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  7312:                         }
                   7313:                     }
1.623     raeburn  7314:                 } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
                   7315:                     if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.657     raeburn  7316:                         unless (&Apache::lonnet::uses_sts()) {
1.658     raeburn  7317:                             if ($hostname ne '') {
                   7318:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   7319:                             }
                   7320:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.657     raeburn  7321:                         }
1.623     raeburn  7322:                     }
1.622     raeburn  7323:                 }
1.609     raeburn  7324:                 if ($anchor ne '') {
                   7325:                     $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
                   7326:                 }
1.590     raeburn  7327:                 $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544     raeburn  7328:             } else {
                   7329:                 $backtourl = '/adm/navmaps';
1.525     raeburn  7330:             }
                   7331:         }
                   7332:     } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
                   7333:         $backtourl = '/adm/menu';
                   7334:     } elsif ($supplementalflag) {
1.472     raeburn  7335:         $backtourl = '/adm/supplemental';
1.525     raeburn  7336:     } else {
                   7337:         $backtourl = '/adm/navmaps';
1.472     raeburn  7338:     }
                   7339: 
1.655     raeburn  7340:     my $fieldsets = "'doc'";
1.519     raeburn  7341:     unless ($main_container_page) {
                   7342:         $fieldsets .=",'ims'";
                   7343:     }
1.655     raeburn  7344:     my $extfieldsets = "'ext'";
                   7345:     if ($posslti) {
                   7346:         $extfieldsets .= ",'tool'";
                   7347:     }
1.501     raeburn  7348:     if ($supplementalflag) {
1.655     raeburn  7349:         $fieldsets = "'suppdoc'";
                   7350:         $extfieldsets = "'suppext'";
1.600     raeburn  7351:         if ($posslti) {
1.655     raeburn  7352:             $extfieldsets .= ",'supptool'";
1.600     raeburn  7353:         }
1.501     raeburn  7354:     }
1.655     raeburn  7355: 
1.611     raeburn  7356:     my $jsmakefunctions;
                   7357:     if ($canedit) {
                   7358:         $jsmakefunctions = <<ENDNEWSCRIPT;
1.329     droeschl 7359: function makenewfolder(targetform,folderseq) {
1.594     damieng  7360:     var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329     droeschl 7361:     if (foldername) {
                   7362:        targetform.importdetail.value=escape(foldername)+"="+folderseq;
                   7363:         targetform.submit();
                   7364:     }
                   7365: }
                   7366: 
                   7367: function makenewpage(targetform,folderseq) {
1.594     damieng  7368:     var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329     droeschl 7369:     if (pagename) {
                   7370:         targetform.importdetail.value=escape(pagename)+"="+folderseq;
                   7371:         targetform.submit();
                   7372:     }
                   7373: }
                   7374: 
                   7375: function makeexamupload() {
1.594     damieng  7376:    var title=prompt('$js_lt{"p_mxu"}');
1.344     bisitz   7377:    if (title) {
1.329     droeschl 7378:     this.document.forms.newexamupload.importdetail.value=
                   7379: 	escape(title)+'=/res/lib/templates/examupload.problem';
                   7380:     this.document.forms.newexamupload.submit();
                   7381:    }
                   7382: }
                   7383: 
                   7384: function makesmppage() {
1.594     damieng  7385:    var title=prompt('$js_lt{"p_msp"}');
1.344     bisitz   7386:    if (title) {
1.329     droeschl 7387:     this.document.forms.newsmppg.importdetail.value=
1.533     raeburn  7388: 	escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329     droeschl 7389:     this.document.forms.newsmppg.submit();
                   7390:    }
                   7391: }
                   7392: 
1.534     raeburn  7393: function makewebpage(type) {
1.594     damieng  7394:    var title=prompt('$js_lt{"p_mwp"}');
1.534     raeburn  7395:    var formname;
                   7396:    if (type == 'supp') {
                   7397:        formname = this.document.forms.supwebpage;
                   7398:    } else {
                   7399:        formname = this.document.forms.newwebpage;
                   7400:    }
                   7401:    if (title) {
                   7402:        var webpage = formname.importdetail.value; 
                   7403:        formname.importdetail.value = escape(title)+'='+webpage;
                   7404:        formname.submit();
                   7405:    }
                   7406: }
                   7407: 
1.329     droeschl 7408: function makesmpproblem() {
1.594     damieng  7409:    var title=prompt('$js_lt{"p_msb"}');
1.344     bisitz   7410:    if (title) {
1.329     droeschl 7411:     this.document.forms.newsmpproblem.importdetail.value=
                   7412: 	escape(title)+'=/res/lib/templates/simpleproblem.problem';
                   7413:     this.document.forms.newsmpproblem.submit();
                   7414:    }
                   7415: }
                   7416: 
                   7417: function makedropbox() {
1.594     damieng  7418:    var title=prompt('$js_lt{"p_mdb"}');
1.344     bisitz   7419:    if (title) {
1.329     droeschl 7420:     this.document.forms.newdropbox.importdetail.value=
                   7421:         escape(title)+'=/res/lib/templates/DropBox.problem';
                   7422:     this.document.forms.newdropbox.submit();
                   7423:    }
                   7424: }
                   7425: 
                   7426: function makebulboard() {
1.594     damieng  7427:    var title=prompt('$js_lt{"p_mbb"}');
1.329     droeschl 7428:    if (title) {
                   7429:     this.document.forms.newbul.importdetail.value=
1.533     raeburn  7430: 	escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329     droeschl 7431:     this.document.forms.newbul.submit();
                   7432:    }
                   7433: }
                   7434: 
                   7435: function makeabout() {
1.594     damieng  7436:    var user=prompt("$js_lt{'p_mab'}");
1.329     droeschl 7437:    if (user) {
                   7438:        var comp=new Array();
                   7439:        comp=user.split(':');
                   7440:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   7441: 	   if ((comp[0]) && (comp[1])) {
                   7442: 	       this.document.forms.newaboutsomeone.importdetail.value=
1.594     damieng  7443: 		   '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611     raeburn  7444:                this.document.forms.newaboutsomeone.submit();
                   7445:            } else {
                   7446:                alert("$js_lt{'p_mab_alrt1'}");
                   7447:            }
                   7448:        } else {
                   7449:            alert("$js_lt{'p_mab_alrt2'}");
                   7450:        }
                   7451:     }
                   7452: }
                   7453: 
                   7454: function makenew(targetform) {
                   7455:     targetform.submit();
                   7456: }
                   7457: 
                   7458: function changename(folderpath,index,oldtitle) {
                   7459:     var title=prompt('$js_lt{"p_chn"}',oldtitle);
                   7460:     if (title) {
                   7461:         this.document.forms.renameform.markcopy.value='';
                   7462:         this.document.forms.renameform.title.value=title;
                   7463:         this.document.forms.renameform.cmd.value='rename_'+index;
                   7464:         this.document.forms.renameform.folderpath.value=folderpath;
                   7465:         this.document.forms.renameform.submit();
                   7466:     }
                   7467: }
                   7468: 
1.633     raeburn  7469: function setalias(folderpath,index) {
                   7470:     var alias = prompt('$js_lt{"setal"}');
                   7471:     if ((alias != null) && (alias != '')) {
                   7472:         this.document.forms.aliasform.alias.value=alias;
                   7473:         this.document.forms.aliasform.cmd.value='setalias_'+index;
                   7474:         this.document.forms.aliasform.folderpath.value=folderpath;
                   7475:         this.document.forms.aliasform.submit();
                   7476:     }
                   7477: }
                   7478: 
                   7479: function delalias(folderpath,index) {
                   7480:     if (confirm('$js_lt{"delal"}')) {
                   7481:         this.document.forms.aliasform.cmd.value='delalias_'+index;
                   7482:         this.document.forms.aliasform.folderpath.value=folderpath;
                   7483:         this.document.forms.aliasform.submit();
                   7484:     }
                   7485: }
                   7486: 
1.611     raeburn  7487: ENDNEWSCRIPT
                   7488:     } else {
                   7489:         $jsmakefunctions = <<ENDNEWSCRIPT;
                   7490: 
                   7491: function makenewfolder() {
                   7492:     alert("$js_lt{'edri'}");
                   7493: }
                   7494: 
                   7495: function makenewpage() {
                   7496:     alert("$js_lt{'edri'}");
                   7497: }
                   7498: 
                   7499: function makeexamupload() {
                   7500:     alert("$js_lt{'edri'}");
                   7501: }
                   7502: 
                   7503: function makesmppage() {
                   7504:     alert("$js_lt{'edri'}");
                   7505: }
                   7506: 
                   7507: function makewebpage(type) {
                   7508:     alert("$js_lt{'edri'}");
                   7509: }
                   7510: 
                   7511: function makesmpproblem() {
                   7512:     alert("$js_lt{'edri'}");
                   7513: }
                   7514: 
                   7515: function makedropbox() {
                   7516:     alert("$js_lt{'edri'}");
                   7517: }
                   7518: 
                   7519: function makebulboard() {
                   7520:     alert("$js_lt{'edri'}");
                   7521: }
                   7522: 
                   7523: function makeabout() {
                   7524:     alert("$js_lt{'edri'}");
                   7525: }
                   7526: 
                   7527: function changename() {
                   7528:     alert("$js_lt{'edri'}");
                   7529: }
                   7530: 
1.633     raeburn  7531: function setalias() {
                   7532:     alert("$js_lt{'edri'}");
                   7533: }
                   7534: 
                   7535: function delalias() {
                   7536:     alert("$js_lt{'edri'}");
                   7537: }
                   7538: 
1.611     raeburn  7539: function makenew() {
                   7540:     alert("$js_lt{'edri'}");
                   7541: }
                   7542: 
                   7543: function groupimport() {
                   7544:     alert("$js_lt{'edri'}");
1.335     ehlerst  7545: }
1.611     raeburn  7546: 
                   7547: function groupsearch() {
                   7548:     alert("$js_lt{'edri'}");
1.335     ehlerst  7549: }
1.611     raeburn  7550: 
                   7551: function groupopen(url,recover) {
                   7552:    var options="scrollbars=1,resizable=1,menubar=0";
                   7553:    idxflag=1;
                   7554:    idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
                   7555:    idx.focus();
1.329     droeschl 7556: }
                   7557: 
1.611     raeburn  7558: ENDNEWSCRIPT
                   7559: 
                   7560:     }
                   7561:     return <<ENDSCRIPT;
                   7562: 
                   7563: $jsmakefunctions
                   7564: 
1.501     raeburn  7565: function toggleUpload(caller) {
                   7566:     var blocks = Array($fieldsets);
                   7567:     for (var i=0; i<blocks.length; i++) {
                   7568:         var disp = 'none';
                   7569:         if (caller == blocks[i]) {
                   7570:             var curr = document.getElementById('upload'+caller+'form').style.display;
                   7571:             if (curr == 'none') {
                   7572:                 disp='block';
                   7573:             }
                   7574:         }
                   7575:         document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655     raeburn  7576:     }
                   7577:     resize_scrollbox('contentscroll','1','1');
                   7578:     return;
                   7579: }
                   7580: 
                   7581: function toggleExternal(caller) {
                   7582:     var blocks = Array($extfieldsets);
                   7583:     for (var i=0; i<blocks.length; i++) {
                   7584:         var disp = 'none';
                   7585:         if (caller == blocks[i]) {
                   7586:             var curr = document.getElementById('external'+caller+'form').style.display;
                   7587:             if (curr == 'none') {
                   7588:                 disp='block';
                   7589:             }
                   7590:         }
                   7591:         document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598     raeburn  7592:         if ((caller == 'tool') || (caller == 'supptool')) {
                   7593:             if (disp == 'block') {
1.655     raeburn  7594:                 if (document.getElementById('LC_exttoolid')) {
                   7595:                     var toolselector = document.getElementById('LC_exttoolid');
1.598     raeburn  7596:                     var suppflag = 0;
                   7597:                     if (caller == 'supptool') {
                   7598:                         suppflag = 1;
                   7599:                     }
                   7600:                     currForm = document.getElementById('new'+caller);
1.655     raeburn  7601:                     updateExttool(toolselector,currForm,suppflag);
1.598     raeburn  7602:                 }
                   7603:             }
                   7604:         }
1.501     raeburn  7605:     }
1.502     raeburn  7606:     resize_scrollbox('contentscroll','1','1');
                   7607:     return;
                   7608: }
                   7609: 
1.514     raeburn  7610: function toggleMap(caller) {
1.502     raeburn  7611:     var disp = 'none';
1.510     raeburn  7612:     if (document.getElementById('importmapform')) {
1.514     raeburn  7613:         if (caller == 'map') {
                   7614:             var curr = document.getElementById('importmapform').style.display;
                   7615:             if (curr == 'none') {
                   7616:                 disp='block';
                   7617:             }
1.510     raeburn  7618:         }
                   7619:         document.getElementById('importmapform').style.display=disp;
                   7620:         resize_scrollbox('contentscroll','1','1');
1.502     raeburn  7621:     }
1.501     raeburn  7622:     return;
1.329     droeschl 7623: }
                   7624: 
1.606     raeburn  7625: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
                   7626:     var disp = 'none';
                   7627:     if (document.getElementById('crsresform')) {
                   7628:         if (caller == 'res') {
                   7629:             var curr = document.getElementById('crsresform').style.display;
                   7630:             if (curr == 'none') {
                   7631:                 disp='block';
                   7632:                 numauthor = parseInt(numauthorrole);
                   7633:                 if (numauthor > 0) {
                   7634:                     document.courseresform.authorrole.selectedIndex = 0;
                   7635:                     select1priv_changed();
                   7636:                     document.courseresform.authorpath.selectedIndex = 0;
                   7637:                     document.courseresform.newresourceadd.selectedIndex = 0;
                   7638:                     toggleNewInCourse(document.courseresform);
                   7639:                     if (document.getElementById('newresource')) {
                   7640:                         document.getElementById('newresource').style.display = 'none';
                   7641:                     }
                   7642:                 } else {
                   7643:                     if (numcrsdirs) {
                   7644:                         document.courseresform.authorpath.selectedIndex = 0;
                   7645:                     }
                   7646:                 }
                   7647:                 if (document.courseresform.newresusetemp.length) {
                   7648:                     document.courseresform.newresusetemp[0].checked = true;
                   7649:                     toggleWithTemplate(document.courseresform);
                   7650:                 }
                   7651:                 document.courseresform.newresourcename.value = ''; 
                   7652:             }
                   7653:         }
                   7654:         if (document.courseresform.newsubdir.length) {
                   7655:             for (var j=0; j<document.courseresform.newsubdir.length; j++) {
                   7656:                 if (document.courseresform.newsubdir[j].value == 0) {
                   7657:                     document.courseresform.newsubdir[j].checked = true;
                   7658:                 }
                   7659:                 break;
                   7660:             }
                   7661:             if (document.getElementById('newsubdirname')) {
                   7662:                 document.getElementById('newsubdirname').type = "hidden";
                   7663:                 document.getElementById('newsubdirname').value = "";
                   7664:             }
                   7665:             if (document.getElementById('newsubdir')) {
                   7666:                 document.getElementById('newsubdir').innerHTML = "";
                   7667:             }
                   7668:         }
                   7669:         document.getElementById('crsresform').style.display=disp;
                   7670:         resize_scrollbox('contentscroll','1','0');
                   7671:     }
                   7672:     return;
                   7673: }
                   7674: 
                   7675: function toggleNewsubdir(form) {
                   7676:     if (form.newsubdir.length) {
                   7677:         for (var j=0; j<form.newsubdir.length; j++) {
                   7678:             if (form.newsubdir[j].checked) {
                   7679:                 if (document.getElementById('newsubdirname')) {
                   7680:                     if (form.newsubdir[j].value == '1') {
                   7681:                         document.getElementById('newsubdirname').type = "text"; 
                   7682:                         if (document.getElementById('newsubdir')) {
                   7683:                             document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
                   7684:                         }
                   7685:                     } else {
                   7686:                         document.getElementById('newsubdirname').type = "hidden";
                   7687:                         document.getElementById('newsubdirname').value = "";
                   7688:                         document.getElementById('newsubdir').innerHTML = "";
                   7689:                     }
                   7690:                 }
                   7691:                 break;
                   7692:             }
                   7693:         }
                   7694:     }
                   7695: }
                   7696: 
                   7697: function toggleCrsResTitle() {
                   7698:     if (document.getElementById('newresource')) {
                   7699:         if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
                   7700:             document.getElementById('newresource').style.display = 'inline';
                   7701:             document.courseresform.newresourceadd[0].checked = true;
                   7702:             toggleNewInCourse(document.courseresform);
                   7703:         } else {
                   7704:             document.getElementById('newresource').style.display = 'none';
                   7705:         }
                   7706:     } 
                   7707: }
                   7708: 
                   7709: function toggleNewInCourse(form) {
                   7710:     if (form.newresourceadd.length) {
                   7711:         for (var i=0; i<form.newresourceadd.length; i++) {
                   7712:             if (form.newresourceadd[i].checked) {
                   7713:                 if (document.getElementById('newresourcetitle')) {
                   7714:                     if (form.newresourceadd[i].value == '1') {
                   7715:                         document.getElementById('newresourcetitle').type = 'text';
                   7716:                         if (document.getElementById('newrestitle')) {
                   7717:                             document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
                   7718:                         }
                   7719:                     } else {
                   7720:                         document.getElementById('newresourcetitle').type = 'hidden';
                   7721:                         document.getElementById('newresourcetitle').value = '';
                   7722:                         if (document.getElementById('newrestitle')) { 
                   7723:                             document.getElementById('newrestitle').innerHTML = '';
                   7724:                         }
                   7725:                     }
                   7726:                 }
                   7727:                 break;
                   7728:             }
                   7729:         }
                   7730:     }
                   7731: }
                   7732: 
                   7733: function toggleWithTemplate(form) {
                   7734:     if (form.newresusetemp.length) {
                   7735:         for (var i=0; i<form.newresusetemp.length; i++) {
                   7736:             if (form.newresusetemp[i].checked) {
                   7737:                 if (document.getElementById('newrestemplate')) { 
                   7738:                     if (form.newresusetemp[i].value == '1') {
                   7739:                         document.getElementById('newrestemplate').style.display = 'inline';
                   7740:                         toggleExampleText();
                   7741:                     } else {
                   7742:                         form.tempcategory.selectedIndex = 0;
                   7743:                         select1template_changed();
                   7744:                         document.getElementById('newrestemplate').style.display = 'none';
                   7745:                     }
                   7746:                 }
                   7747:             }
                   7748:         }
                   7749:     }
                   7750: }
                   7751: 
                   7752: function toggleExampleText() {
                   7753:     if (document.getElementById('newresexample')) {
                   7754:         var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   7755:         if (url == '') {
                   7756:             document.getElementById('newresexample').style.fontWeight = 'normal';
                   7757:         } else {
                   7758:             document.getElementById('newresexample').style.fontWeight = 'bold';
                   7759:         }
                   7760:     }
                   7761: }
                   7762: 
                   7763: function getExample(width,height,scrolling,transparency) {
                   7764:     var url;
                   7765:     if (document.courseresform.newresusetemp.length) {
                   7766:         for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
                   7767:             if (document.courseresform.newresusetemp[i].checked) {
                   7768:                 if (document.courseresform.newresusetemp[i].value == '1') {
                   7769:                     var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   7770:                     if (url == '') {
                   7771:                         alert('Pick a category and template');
                   7772:                     } else {
                   7773:                         url = url.replace("$londocroot",""); 
                   7774:                         url += '?inhibitmenu=yes';
                   7775:                     }
                   7776:                 }
                   7777:                 break;
                   7778:             }
                   7779:         }
                   7780:     }
                   7781:     if (url != '') {
                   7782:         openMyModal(url,width,height,scrolling,transparency,'');
                   7783:     }
                   7784: }
                   7785: 
                   7786: function toggleImportCrsres(caller,dircount) {
                   7787:     var disp = 'none';
                   7788:     if (document.getElementById('importcrsresform')) {
                   7789:         if (caller == 'res') {
                   7790:             var numdirs = parseInt(dircount);
                   7791:             var curr = document.getElementById('importcrsresform').style.display;
                   7792:             if (curr == 'none') {
                   7793:                 disp='block';
                   7794:                 if (numdirs > 1) {
                   7795:                     select1res_changed();
                   7796:                 }
                   7797:             }
                   7798:         }
                   7799:         document.getElementById('importcrsresform').style.display=disp;
                   7800:         resize_scrollbox('contentscroll','1','0');
                   7801:     }
                   7802:     return;
                   7803: }
                   7804: 
1.501     raeburn  7805: function makeims(imsform) {
                   7806:     if ((imsform.uploaddoc.value == '')  || (!imsform.uploaddoc.value)) {
1.594     damieng  7807:         alert("$js_lt{'imsfile'}");
1.501     raeburn  7808:         return;
                   7809:     }
                   7810:     if (imsform.source.selectedIndex == 0) {
1.594     damieng  7811:         alert("$js_lt{'imscms'}");
1.501     raeburn  7812:         return;
                   7813:     }
                   7814:     newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
                   7815:     imsform.submit();
                   7816: }
                   7817: 
1.478     raeburn  7818: function updatePick(targetform,index,caller) {
1.537     raeburn  7819:     var pickitem;
                   7820:     var picknumitem;
                   7821:     var picknumtext;
                   7822:     if (index == 'all') {
                   7823:         pickitem = document.getElementById('randompickall');
                   7824:         picknumitem = document.getElementById('rpicknumall');
                   7825:         picknumtext = document.getElementById('rpicktextall');
                   7826:     } else {
                   7827:         pickitem = document.getElementById('randompick_'+index);
                   7828:         picknumitem = document.getElementById('rpicknum_'+index);
                   7829:         picknumtext = document.getElementById('randompicknum_'+index);
                   7830:     }
1.478     raeburn  7831:     if (pickitem.checked) {
1.594     damieng  7832:         var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478     raeburn  7833:         if (picknum == '' || picknum == null) {
                   7834:             if (caller == 'check') {
                   7835:                 pickitem.checked=false;
1.537     raeburn  7836:                 if (index == 'all') {
                   7837:                     picknumtext.innerHTML = '';
                   7838:                     if (caller == 'link') {
                   7839:                         propagateState(targetform,'rpicknum');
                   7840:                     }
                   7841:                 } else {
1.538     raeburn  7842:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  7843:                 }
1.478     raeburn  7844:             }
                   7845:         } else {
                   7846:             picknum.toString();
                   7847:             var regexdigit=/^\\d+\$/;
                   7848:             if (regexdigit.test(picknum)) {
                   7849:                 picknumitem.value = picknum;
1.537     raeburn  7850:                 if (index == 'all') {
1.538     raeburn  7851:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537     raeburn  7852:                     if (caller == 'link') {
                   7853:                         propagateState(targetform,'rpicknum');
                   7854:                     }
                   7855:                 } else {
                   7856:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538     raeburn  7857:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  7858:                 }
1.478     raeburn  7859:             } else {
                   7860:                 if (caller == 'check') {
1.537     raeburn  7861:                     if (index == 'all') {
                   7862:                         picknumtext.innerHTML = '';
                   7863:                         if (caller == 'link') {
                   7864:                             propagateState(targetform,'rpicknum');
                   7865:                         }
                   7866:                     } else {
                   7867:                         pickitem.checked=false;
1.538     raeburn  7868:                         checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  7869:                     }
1.478     raeburn  7870:                 }
                   7871:                 return;
                   7872:             }
                   7873:         }
                   7874:     } else {
1.537     raeburn  7875:         picknumitem.value = '';
                   7876:         picknumtext.innerHTML = '';
                   7877:         if (index == 'all') {
                   7878:             if (caller == 'link') {
                   7879:                 propagateState(targetform,'rpicknum');
                   7880:             }
                   7881:         } else {
1.538     raeburn  7882:             checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  7883:         }
                   7884:     }
                   7885: }
                   7886: 
                   7887: function propagateState(form,param) {
                   7888:     if (document.getElementById(param+'all')) {
                   7889:         var setcheck = 0;
                   7890:         var rpick = 0;
                   7891:         if (param == 'rpicknum') {
                   7892:             if (document.getElementById('randompickall')) {
                   7893:                 if (document.getElementById('randompickall').checked) {
                   7894:                     if (document.getElementById('rpicknumall')) {
                   7895:                         rpick = document.getElementById('rpicknumall').value;
                   7896:                     }
                   7897:                 }
                   7898:             }
                   7899:         } else {
                   7900:             if (document.getElementById(param+'all').checked) {
                   7901:                 setcheck = 1;
                   7902:             }
                   7903:         }
1.538     raeburn  7904:         var allidxlist;
                   7905:         if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   7906:             if (document.getElementById('all'+param+'idx')) {
                   7907:                 allidxlist = document.getElementById('all'+param+'idx').value;
                   7908:             }
                   7909:             var actions = new Array ('remove','cut','copy');
                   7910:             for (var i=0; i<actions.length; i++) {
                   7911:                 if (actions[i] != param) {
                   7912:                     if (document.getElementById(actions[i]+'all')) {
                   7913:                         document.getElementById(actions[i]+'all').checked = false; 
                   7914:                     }
                   7915:                 }
                   7916:             }
                   7917:         }
1.537     raeburn  7918:         if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538     raeburn  7919:             allidxlist = form.allidx.value;
                   7920:         }
                   7921:         if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
                   7922:             allidxlist = form.allmapidx.value;
                   7923:         }
                   7924:         if ((allidxlist != '') && (allidxlist != null)) {
                   7925:             var allidxs = allidxlist.split(',');
                   7926:             if (allidxs.length > 1) {
                   7927:                 for (var i=0; i<allidxs.length; i++) {
                   7928:                     if (document.getElementById(param+'_'+allidxs[i])) {
                   7929:                         if (param == 'rpicknum') {
                   7930:                             if (document.getElementById('randompick_'+allidxs[i])) {
                   7931:                                 if (document.getElementById('randompick_'+allidxs[i]).checked) {
                   7932:                                     document.getElementById(param+'_'+allidxs[i]).value = rpick;
                   7933:                                     if (rpick > 0) {
                   7934:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ':&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
                   7935:                                     } else {
                   7936:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   7937:                                     }
                   7938:                                 }
                   7939:                             }
                   7940:                         } else {
1.537     raeburn  7941:                             if (setcheck == 1) {
                   7942:                                 document.getElementById(param+'_'+allidxs[i]).checked = true;
                   7943:                             } else {
                   7944:                                 document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538     raeburn  7945:                                 if (param == 'randompick') {
                   7946:                                     document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   7947:                                 }
1.537     raeburn  7948:                             }
                   7949:                         }
                   7950:                     }
                   7951:                 }
1.538     raeburn  7952:                 if (setcheck == 1) {
                   7953:                     if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   7954:                         var actions = new Array('copy','cut','remove');
                   7955:                         for (var i=0; i<actions.length; i++) {
                   7956:                             var otheractions;
                   7957:                             var otheridxs;
                   7958:                             if (actions[i] === param) {
                   7959:                                 continue;
                   7960:                             } else {
                   7961:                                 if (document.getElementById('all'+actions[i]+'idx')) {
                   7962:                                     otheractions = document.getElementById('all'+actions[i]+'idx').value;
                   7963:                                     otheridxs = otheractions.split(',');
                   7964:                                     if (otheridxs.length > 1) {
                   7965:                                         for (var j=0; j<otheridxs.length; j++) {
                   7966:                                             if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
                   7967:                                                 document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
                   7968:                                             }
1.537     raeburn  7969:                                         }
                   7970:                                     }
                   7971:                                 }
1.538     raeburn  7972:                             }
                   7973:                         } 
                   7974:                     }
                   7975:                 }
                   7976:             }
                   7977:         }
                   7978:     }
                   7979:     return;
                   7980: }
                   7981: 
1.603     raeburn  7982: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611     raeburn  7983:     var canedit = '$canedit';
                   7984:     if (canedit == '') {
                   7985:         alert("$js_lt{'edri'}");
                   7986:         return;
                   7987:     }
1.539     raeburn  7988:     var dosettings;
                   7989:     var doaction;
1.538     raeburn  7990:     var control = document.togglemultsettings;
                   7991:     if (context == 'actions') {
                   7992:         control = document.togglemultactions;
1.539     raeburn  7993:         doaction = 1; 
                   7994:     } else {
                   7995:         dosettings = 1;
1.538     raeburn  7996:     }
1.539     raeburn  7997:     if (control) {
                   7998:         if (control.showmultpick.length) {
                   7999:             for (var i=0; i<control.showmultpick.length; i++) {
                   8000:                 if (control.showmultpick[i].checked) {
                   8001:                     if (control.showmultpick[i].value == 1) {
                   8002:                         if (context == 'settings') {
                   8003:                             dosettings = 0;
                   8004:                         } else {
                   8005:                             doaction = 0;
1.538     raeburn  8006:                         }
                   8007:                     }
                   8008:                 }
1.537     raeburn  8009:             }
                   8010:         }
1.539     raeburn  8011:     }
                   8012:     if (context == 'settings') {
                   8013:         if (dosettings == 1) {
1.538     raeburn  8014:             targetform.changeparms.value=param;
                   8015:             targetform.submit();
                   8016:         }
1.537     raeburn  8017:     }
1.539     raeburn  8018:     if (context == 'actions') {
                   8019:         if (doaction == 1) {
                   8020:             targetform.cmd.value=param+'_'+index;
                   8021:             targetform.folderpath.value=folderpath;
                   8022:             targetform.markcopy.value=idx+':'+param;
                   8023:             targetform.copyfolder.value=folder+'.'+container;
                   8024:             if (param == 'remove') {
1.603     raeburn  8025:                 var doremove = 0;
                   8026:                 if (skip_confirm) {
                   8027:                     if (confirm_removal) {
                   8028:                         if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
                   8029:                             doremove = 1;
                   8030:                         }
                   8031:                     } else {
                   8032:                         doremove = 1;
                   8033:                     }
                   8034:                 } else {
                   8035:                     if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
                   8036:                         doremove = 1;
                   8037:                     }
                   8038:                 }
                   8039:                 if (doremove) {
1.539     raeburn  8040:                     targetform.markcopy.value='';
                   8041:                     targetform.copyfolder.value='';
                   8042:                     targetform.submit();
                   8043:                 }
                   8044:             }
                   8045:             if (param == 'cut') {
1.594     damieng  8046:                 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  8047:                     targetform.submit();
                   8048:                     return;
                   8049:                 }
                   8050:             }
                   8051:             if (param == 'copy') {
                   8052:                 targetform.submit();
                   8053:                 return;
                   8054:             }
                   8055:             targetform.markcopy.value='';
                   8056:             targetform.copyfolder.value='';
                   8057:             targetform.cmd.value='';
                   8058:             targetform.folderpath.value='';
                   8059:             return;
                   8060:         } else {
                   8061:             if (document.getElementById(param+'_'+idx)) {
                   8062:                 item = document.getElementById(param+'_'+idx);
                   8063:                 if (item.type == 'checkbox') {
                   8064:                     if (item.checked) {
                   8065:                         item.checked = false;
                   8066:                     } else {
                   8067:                         item.checked = true;
                   8068:                         singleCheck(item,idx,param);
                   8069:                     }
                   8070:                 }
                   8071:             }
                   8072:         }
                   8073:     }
1.537     raeburn  8074:     return;
                   8075: }
                   8076: 
1.538     raeburn  8077: function singleCheck(caller,idx,action) {
                   8078:     actions = new Array('cut','copy','remove');
                   8079:     if (caller.checked) {
                   8080:         for (var i=0; i<actions.length; i++) {
                   8081:             if (actions[i] != action) {
                   8082:                 if (document.getElementById(actions[i]+'_'+idx)) {
                   8083:                     if (document.getElementById(actions[i]+'_'+idx).checked) {
                   8084:                         document.getElementById(actions[i]+'_'+idx).checked = false;
                   8085:                     }
1.537     raeburn  8086:                 }
                   8087:             }
                   8088:         }
1.478     raeburn  8089:     }
1.537     raeburn  8090:     return;
1.478     raeburn  8091: }
                   8092: 
1.334     muellerd 8093: function unselectInactive(nav) {
1.335     ehlerst  8094: currentNav = document.getElementById(nav);
                   8095: currentLis = currentNav.getElementsByTagName('LI');
                   8096: for (i = 0; i < currentLis.length; i++) {
1.472     raeburn  8097:         if (currentLis[i].className == 'goback') {
                   8098:             currentLis[i].className = 'goback';
                   8099:         } else {
                   8100: 	    if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374     tempelho 8101: 		currentLis[i].className = 'right';
1.472     raeburn  8102: 	    } else {
1.374     tempelho 8103: 		currentLis[i].className = 'i';
1.472     raeburn  8104: 	    }
                   8105:         }
1.335     ehlerst  8106: }
1.332     tempelho 8107: }
                   8108: 
1.334     muellerd 8109: function hideAll(current, nav, data) {
1.335     ehlerst  8110: unselectInactive(nav);
1.570     raeburn  8111: if (current) { 
                   8112:     if (current.className == 'right'){
                   8113:         current.className = 'right active'
                   8114:     } else {
                   8115:         current.className = 'active';
                   8116:     }
1.374     tempelho 8117: }
1.335     ehlerst  8118: currentData = document.getElementById(data);
                   8119: currentDivs = currentData.getElementsByTagName('DIV');
                   8120: for (i = 0; i < currentDivs.length; i++) {
                   8121: 	if(currentDivs[i].className == 'LC_ContentBox'){
1.333     muellerd 8122: 		currentDivs[i].style.display = 'none';
1.330     tempelho 8123: 	}
                   8124: }
1.335     ehlerst  8125: }
1.330     tempelho 8126: 
1.374     tempelho 8127: function openTabs(pageId) {
                   8128: 	tabnav = document.getElementById(pageId).getElementsByTagName('UL');	
1.383     tempelho 8129: 	if(tabnav.length > 2 ){
1.389     tempelho 8130: 		currentNav = document.getElementById(tabnav[1].id);
1.374     tempelho 8131: 		currentLis = currentNav.getElementsByTagName('LI');
                   8132: 		for(i = 0; i< currentLis.length; i++){
                   8133: 			if(currentLis[i].className == 'active') {
1.375     tempelho 8134: 				funcString = currentLis[i].onclick.toString();
                   8135: 				tab = funcString.split('"');
1.420     onken    8136:                                 if(tab.length < 2) {
                   8137:                                    tab = funcString.split("'");
                   8138:                                 }
1.375     tempelho 8139: 				currentData = document.getElementById(tab[1]);
                   8140:         			currentData.style.display = 'block';
1.374     tempelho 8141: 			}	
                   8142: 		}
                   8143: 	}
                   8144: }
                   8145: 
1.334     muellerd 8146: function showPage(current, pageId, nav, data) {
1.570     raeburn  8147:         currstate = current.className;
1.334     muellerd 8148: 	hideAll(current, nav, data);
1.375     tempelho 8149: 	openTabs(pageId);
1.334     muellerd 8150: 	unselectInactive(nav);
1.570     raeburn  8151:         if ((currstate == 'active') || (currstate == 'right active')) {
                   8152:             if (currstate == 'active') {
                   8153: 	        current.className = '';
                   8154:             } else {
                   8155:                 current.className = 'right';
                   8156:             }
                   8157:             activeTab = ''; 
1.656     raeburn  8158:             toggleExternal();
1.570     raeburn  8159:             toggleUpload();
                   8160:             toggleMap();
1.606     raeburn  8161:             toggleCrsRes();
                   8162:             toggleImportCrsres();
1.570     raeburn  8163:             resize_scrollbox('contentscroll','1','0');
                   8164:             return;
                   8165:         } else {
                   8166:             current.className = 'active';
                   8167:         }
1.330     tempelho 8168: 	currentData = document.getElementById(pageId);
                   8169: 	currentData.style.display = 'block';
1.458     raeburn  8170:         activeTab = pageId;
1.656     raeburn  8171:         toggleExternal();
1.501     raeburn  8172:         toggleUpload();
1.503     raeburn  8173:         toggleMap();
1.606     raeburn  8174:         toggleCrsRes();
                   8175:         toggleImportCrsres();
1.433     raeburn  8176:         if (nav == 'mainnav') {
                   8177:             var storedpath = "$docs_folderpath";
1.434     raeburn  8178:             var storedpage = "$main_container_page";
1.433     raeburn  8179:             var reg = new RegExp("^supplemental");
                   8180:             if (pageId == 'mainCourseDocuments') {
1.434     raeburn  8181:                 if (storedpage == 1) {
                   8182:                     document.simpleedit.folderpath.value = '';
                   8183:                     document.uploaddocument.folderpath.value = '';
                   8184:                 } else {
                   8185:                     if (reg.test(storedpath)) {
                   8186:                         document.simpleedit.folderpath.value = '$toplevelmain';
                   8187:                         document.uploaddocument.folderpath.value = '$toplevelmain';
                   8188:                         document.newext.folderpath.value = '$toplevelmain';
                   8189:                     } else {
                   8190:                         document.simpleedit.folderpath.value = storedpath;
                   8191:                         document.uploaddocument.folderpath.value = storedpath;
                   8192:                         document.newext.folderpath.value = storedpath;
                   8193:                     }
1.433     raeburn  8194:                 }
                   8195:             } else {
1.434     raeburn  8196:                 if (reg.test(storedpath)) {
                   8197:                     document.simpleedit.folderpath.value = storedpath;
                   8198:                     document.supuploaddocument.folderpath.value = storedpath;
                   8199:                     document.supnewext.folderpath.value = storedpath;
                   8200:                 } else {
1.433     raeburn  8201:                     document.simpleedit.folderpath.value = '$toplevelsupp';
                   8202:                     document.supuploaddocument.folderpath.value = '$toplevelsupp';
                   8203:                     document.supnewext.folderpath.value = '$toplevelsupp';
                   8204:                 }
                   8205:             }
                   8206:         }
1.485     raeburn  8207:         resize_scrollbox('contentscroll','1','0');
1.330     tempelho 8208: 	return false;
                   8209: }
1.329     droeschl 8210: 
1.472     raeburn  8211: function toContents(jumpto) {
                   8212:     var newurl = '$backtourl';
1.525     raeburn  8213:     if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472     raeburn  8214:         newurl = newurl+'?postdata='+jumpto;
                   8215:     }
                   8216:     location.href=newurl;
                   8217: }
                   8218: 
1.538     raeburn  8219: function togglePick(caller,value) {
                   8220:     var disp = 'none';
                   8221:     if (document.getElementById('multi'+caller)) {
                   8222:         var curr = document.getElementById('multi'+caller).style.display;
                   8223:         if (value == 1) {
                   8224:             disp='block';
                   8225:         }
                   8226:         if (curr == disp) {
                   8227:             return; 
                   8228:         }
                   8229:         document.getElementById('multi'+caller).style.display=disp;
                   8230:         if (value == 1) {
1.594     damieng  8231:             document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>'; 
1.538     raeburn  8232:         } else {
                   8233:             document.getElementById('more'+caller).innerHTML = '';
                   8234:         }
                   8235:         if (caller == 'actions') { 
                   8236:             setClass(value);
                   8237:             setBoxes(value);
                   8238:         }
                   8239:     }
                   8240:     var showButton = multiSettings();
                   8241:     if (showButton != 1) {
                   8242:         showButton = multiActions();
                   8243:     }
                   8244:     if (document.getElementById('multisave')) {
                   8245:         if (showButton == 1) {
                   8246:             document.getElementById('multisave').style.display='block';
                   8247:         } else {
                   8248:             document.getElementById('multisave').style.display='none';
                   8249:         }
                   8250:     }
                   8251:     resize_scrollbox('contentscroll','1','1');
                   8252:     return;
                   8253: }
                   8254: 
                   8255: function toggleCheckUncheck(caller,more) {
                   8256:     if (more == 1) {
1.594     damieng  8257:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538     raeburn  8258:         document.getElementById('allfields'+caller).style.display='block';
                   8259:     } else {
1.594     damieng  8260:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538     raeburn  8261:         document.getElementById('allfields'+caller).style.display='none';
                   8262:     }
                   8263:     resize_scrollbox('contentscroll','1','1');
                   8264: }
                   8265: 
                   8266: function multiSettings() {
                   8267:     var inuse = 0;
                   8268:     var settingsform = document.togglemultsettings;
                   8269:     if (settingsform.showmultpick.length > 1) {
                   8270:         for (var i=0; i<settingsform.showmultpick.length; i++) {
                   8271:             if (settingsform.showmultpick[i].checked) {
                   8272:                 if (settingsform.showmultpick[i].value == 1) {
                   8273:                     inuse = 1;  
                   8274:                 }
                   8275:             }
                   8276:         }
                   8277:     }
                   8278:     return inuse;
                   8279: }
                   8280: 
                   8281: function multiActions() {
                   8282:     var inuse = 0;
                   8283:     var actionsform = document.togglemultactions;
                   8284:     if (actionsform.showmultpick.length > 1) {
                   8285:         for (var i=0; i<actionsform.showmultpick.length; i++) {
                   8286:             if (actionsform.showmultpick[i].checked) {
                   8287:                 if (actionsform.showmultpick[i].value == 1) {
                   8288:                     inuse = 1;
                   8289:                 }
                   8290:             }
                   8291:         }
                   8292:     }
                   8293:     return inuse;
                   8294: } 
                   8295: 
                   8296: function checkSubmits() {
                   8297:     var numchanges = 0;
                   8298:     var form = document.saveactions;
                   8299:     var doactions = multiActions();
1.542     raeburn  8300:     var cutwarnings = 0;
                   8301:     var remwarnings = 0;
1.603     raeburn  8302:     var removalinfo = 0;
1.538     raeburn  8303:     if (doactions == 1) {
                   8304:         var remidxlist = document.cumulativeactions.allremoveidx.value;
                   8305:         if ((remidxlist != '') && (remidxlist != null)) {
                   8306:             var remidxs = remidxlist.split(',');
                   8307:             for (var i=0; i<remidxs.length; i++) {
                   8308:                 if (document.getElementById('remove_'+remidxs[i])) {
                   8309:                     if (document.getElementById('remove_'+remidxs[i]).checked) {
                   8310:                         form.multiremove.value += remidxs[i]+',';
                   8311:                         numchanges ++;
1.542     raeburn  8312:                         if (document.getElementById('skip_remove_'+remidxs[i])) {
                   8313:                             if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
                   8314:                                 remwarnings ++;
                   8315:                             }
                   8316:                         }
1.603     raeburn  8317:                         if (document.getElementById('confirm_removal_'+remidxs[i])) {
                   8318:                             if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
                   8319:                                 removalinfo ++;
                   8320:                             }
                   8321:                         }
1.537     raeburn  8322:                     }
                   8323:                 }
1.538     raeburn  8324:             }
                   8325:         }
                   8326:         var cutidxlist = document.cumulativeactions.allcutidx.value;
                   8327:         if ((cutidxlist != '') && (cutidxlist != null)) {
                   8328:             var cutidxs = cutidxlist.split(',');
                   8329:             for (var i=0; i<cutidxs.length; i++) {
                   8330:                 if (document.getElementById('cut_'+cutidxs[i])) {
                   8331:                     if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
                   8332:                         form.multicut.value += cutidxs[i]+',';
                   8333:                         numchanges ++;
1.542     raeburn  8334:                         if (document.getElementById('skip_cut_'+cutidxs[i])) {
                   8335:                             if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
                   8336:                                 cutwarnings ++;
                   8337:                             }
                   8338:                         }
1.537     raeburn  8339:                     }
                   8340:                 }
                   8341:             }
                   8342:         }
1.538     raeburn  8343:         var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   8344:         if ((copyidxlist != '') && (copyidxlist != null)) {
                   8345:             var copyidxs = copyidxlist.split(',');
                   8346:             for (var i=0; i<copyidxs.length; i++) {
                   8347:                 if (document.getElementById('copy_'+copyidxs[i])) {
                   8348:                     if (document.getElementById('copy_'+copyidxs[i]).checked) {
                   8349:                         form.multicopy.value += copyidxs[i]+',';
                   8350:                         numchanges ++;
                   8351:                     }
                   8352:                 }
                   8353:             }
                   8354:         }
                   8355:         if (numchanges > 0) {
                   8356:             form.multichange.value = numchanges;
                   8357:         }
1.537     raeburn  8358:     }
1.538     raeburn  8359:     var dosettings = multiSettings();
1.543     raeburn  8360:     var haschanges = 0;
1.538     raeburn  8361:     if (dosettings == 1) {
                   8362:         form.allencrypturl.value = '';
                   8363:         form.allhiddenresource.value = '';
1.543     raeburn  8364:         form.changeparms.value = 'all';
                   8365:         var patt=new RegExp(",\$");
1.538     raeburn  8366:         var allidxlist = document.cumulativesettings.allidx.value;
                   8367:         if ((allidxlist != '') && (allidxlist != null)) {
                   8368:             var allidxs = allidxlist.split(',');
                   8369:             if (allidxs.length > 1) {
                   8370:                 for (var i=0; i<allidxs.length; i++) {
                   8371:                     if (document.getElementById('hiddenresource_'+allidxs[i])) {
                   8372:                         if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
                   8373:                             form.allhiddenresource.value += allidxs[i]+',';
                   8374:                         }
                   8375:                     }
                   8376:                     if (document.getElementById('encrypturl_'+allidxs[i])) {
                   8377:                         if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
                   8378:                             form.allencrypturl.value += allidxs[i]+',';
                   8379:                         }
                   8380:                     }
                   8381:                 }
1.543     raeburn  8382:                 form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
                   8383:                 form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537     raeburn  8384:             }
1.538     raeburn  8385:         }
                   8386:         form.allrandompick.value = '';
                   8387:         form.allrandomorder.value = '';
                   8388:         var allmapidxlist = document.cumulativesettings.allmapidx.value;
                   8389:         if ((allmapidxlist != '') && (allmapidxlist != null)) {
                   8390:             var allmapidxs = allmapidxlist.split(',');
                   8391:             for (var i=0; i<allmapidxs.length; i++) {
                   8392:                 var randompick = document.getElementById('randompick_'+allmapidxs[i]);
                   8393:                 var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
                   8394:                 var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
                   8395:                 if ((randompick.checked) && (rpicknum.value != '')) {
                   8396:                     form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
                   8397:                 }
                   8398:                 if (randorder.checked) {
                   8399:                     form.allrandomorder.value += allmapidxs[i]+',';
                   8400:                 }
1.537     raeburn  8401:             }
1.543     raeburn  8402:             form.allrandompick.value = form.allrandompick.value.replace(patt,"");
                   8403:             form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
                   8404:         }
                   8405:         if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
                   8406:             haschanges = 1;
                   8407:         }
                   8408:         if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
                   8409:             haschanges = 1;
                   8410:         }
                   8411:         if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
                   8412:             haschanges = 1;
                   8413:         }
                   8414:         if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
                   8415:             haschanges = 1;
1.537     raeburn  8416:         }
                   8417:     }
1.543     raeburn  8418:     if (doactions == 1) {
1.542     raeburn  8419:         if (numchanges > 0) {
1.603     raeburn  8420:             if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542     raeburn  8421:                 if (remwarnings > 0) {
1.594     damieng  8422:                     if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542     raeburn  8423:                         return false;
                   8424:                     }
                   8425:                 }
1.603     raeburn  8426:                 if (removalinfo > 0) {
                   8427:                     if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
                   8428:                         return false;
                   8429:                     }
                   8430:                 }
1.542     raeburn  8431:                 if (cutwarnings > 0) {
1.594     damieng  8432:                     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  8433:                         return false;
                   8434:                     }
                   8435:                 }
                   8436:             }
                   8437:             form.submit();
                   8438:             return true;
1.543     raeburn  8439:         }
                   8440:     }
                   8441:     if (dosettings == 1) {
                   8442:         if (haschanges == 1) {
1.542     raeburn  8443:             form.submit();
                   8444:             return true;
                   8445:         }
1.543     raeburn  8446:     }
                   8447:     if ((dosettings == 1) && (doactions == 1)) {
1.594     damieng  8448:         alert("$js_lt{'noor'}");
1.543     raeburn  8449:     } else {
                   8450:         if (dosettings == 1) {
1.594     damieng  8451:             alert("$js_lt{'noch'}");
1.543     raeburn  8452:         } else {
1.594     damieng  8453:             alert("$js_lt{'noac'}");
1.543     raeburn  8454:         }
                   8455:     }
1.538     raeburn  8456:     return false;
                   8457: }
                   8458: 
                   8459: function setClass(value) {
                   8460:     var cutclass = 'LC_docs_cut';
                   8461:     var copyclass = 'LC_docs_copy';
                   8462:     var removeclass = 'LC_docs_remove';
                   8463:     var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
                   8464:     var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
                   8465:     var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
                   8466:     var links = document.getElementsByTagName('a');
                   8467:     for (var i=0; i<links.length; i++) {
                   8468:         var classes = links[i].className;
                   8469:         if (cutreg.test(classes)) {
                   8470:             links[i].className = cutclass;
                   8471:             if (value == 1) {
                   8472:                 links[i].className += " LC_menubuttons_link";
                   8473:             }
                   8474:         } else {
                   8475:             if (copyreg.test(classes)) {
                   8476:                 links[i].className = copyclass;
                   8477:                 if (value == 1) {
                   8478:                     links[i].className += " LC_menubuttons_link";
                   8479:                 } 
                   8480:             } else {
                   8481:                 if (removereg.test(classes)) {
                   8482:                     links[i].className = removeclass;
                   8483:                     if (value == 1) {
                   8484:                         links[i].className += " LC_menubuttons_link";
                   8485:                     }
                   8486:                 }
                   8487:             }
                   8488:         }
                   8489:     }
                   8490:     return;
1.537     raeburn  8491: }
                   8492: 
1.538     raeburn  8493: function setBoxes(value) {
                   8494:     var remidxlist = document.cumulativeactions.allremoveidx.value;
                   8495:     if ((remidxlist != '') && (remidxlist != null)) {
                   8496:         var remidxs = remidxlist.split(',');
                   8497:         for (var i=0; i<remidxs.length; i++) {
                   8498:             if (document.getElementById('remove_'+remidxs[i])) {
                   8499:                 var item = document.getElementById('remove_'+remidxs[i]);
                   8500:                 if (value == 1) {
                   8501:                     item.className = 'LC_docs_remove';
                   8502:                 } else {
                   8503:                     item.className = 'LC_hidden';
                   8504:                 }
                   8505:             }
                   8506:         }
                   8507:     }
                   8508:     var cutidxlist = document.cumulativeactions.allcutidx.value;
                   8509:     if ((cutidxlist != '') && (cutidxlist != null)) {
                   8510:         var cutidxs = cutidxlist.split(',');
                   8511:         for (var i=0; i<cutidxs.length; i++) {
                   8512:             if (document.getElementById('cut_'+cutidxs[i])) {
                   8513:                 var item = document.getElementById('cut_'+cutidxs[i]);
                   8514:                 if (value == 1) {
                   8515:                     item.className = 'LC_docs_cut';
                   8516:                 } else {
                   8517:                     item.className = 'LC_hidden';
                   8518:                 }
                   8519:             }
1.537     raeburn  8520:         }
                   8521:     }
1.538     raeburn  8522:     var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   8523:     if ((copyidxlist != '') && (copyidxlist != null)) {
                   8524:         var copyidxs = copyidxlist.split(',');
                   8525:         for (var i=0; i<copyidxs.length; i++) {
                   8526:             if (document.getElementById('copy_'+copyidxs[i])) {
                   8527:                 var item = document.getElementById('copy_'+copyidxs[i]);
                   8528:                 if (value == 1) {
                   8529:                     item.className = 'LC_docs_copy';
                   8530:                 } else {
                   8531:                     item.className = 'LC_hidden';
                   8532:                 }
                   8533:             }
1.537     raeburn  8534:         }
                   8535:     }
                   8536:     return;
                   8537: }
                   8538: 
1.606     raeburn  8539: function validImportCrsRes() {
                   8540:     var path =  document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
                   8541:     var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
                   8542:     if ((fname == '') || (fname == null)) {
                   8543:         alert("$js_lt{'nofi'}");
                   8544:         return false;
                   8545:     }
                   8546:     var url = '/res/$coursedom/$coursenum/';
                   8547:     if (path && path != '/') {
                   8548:         url += path+'/';
                   8549:     }
                   8550:     if (fname != '') {
                   8551:         url += fname;
                   8552:     }
                   8553:     var title = document.crsresimportform.crsrestitle.value;
                   8554:     document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
                   8555:     return true;
                   8556: }
                   8557: 
                   8558: function validateNewRes(caller) {
                   8559:     if (caller == 'single') {
                   8560:         var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value; 
                   8561:         var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
                   8562:         var resname = document.courseresform.newresourcename.value;
                   8563:     }
                   8564: }
                   8565: 
1.611     raeburn  8566: ENDSCRIPT
1.329     droeschl 8567: }
1.457     raeburn  8568: 
1.483     raeburn  8569: sub history_tab_js {
                   8570:     return <<"ENDHIST";
                   8571: function toggleHistoryDisp(choice) {
                   8572:     document.docslogform.docslog.value = choice;
                   8573:     document.docslogform.submit();
                   8574:     return;
                   8575: }
                   8576: 
                   8577: ENDHIST
                   8578: }
                   8579: 
1.484     raeburn  8580: sub inject_data_js {
                   8581:     return <<ENDINJECT;
                   8582: 
                   8583: function injectData(current, hiddenField, name, value) {
                   8584:         currentElement = document.getElementById(hiddenField);
                   8585:         currentElement.name = name;
                   8586:         currentElement.value = value;
                   8587:         current.submit();
                   8588: }
                   8589: 
                   8590: ENDINJECT
                   8591: }
                   8592: 
                   8593: sub dump_switchserver_js {
                   8594:     my @hosts = @_;
1.594     damieng  8595:     my %js_lt = &Apache::lonlocal::texthash(
1.574     raeburn  8596:         dump => 'Copying content to Authoring Space requires switching server.',
1.484     raeburn  8597:         swit => 'Switch server?',
1.594     damieng  8598:     );
                   8599:     my %html_js_lt = &Apache::lonlocal::texthash(
                   8600:         swit => 'Switch server?',
1.568     raeburn  8601:         duco => 'Copying Content to Authoring Space',
1.484     raeburn  8602:         yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
                   8603:         chos => 'Choose server',
                   8604:     );
1.594     damieng  8605:     &js_escape(\%js_lt);
                   8606:     &html_escape(\%html_js_lt);
                   8607:     &js_escape(\%html_js_lt);
1.484     raeburn  8608:     my $role = $env{'request.role'};
                   8609:     my $js = <<"ENDSWJS";
                   8610: <script type="text/javascript">
                   8611: function write_switchserver() {
                   8612:     var server;
                   8613:     if (document.setserver.posshosts.length > 0) {
                   8614:         for (var i=0; i<document.setserver.posshosts.length; i++) {
                   8615:             if (document.setserver.posshosts[i].checked) {
                   8616:                 server = document.setserver.posshosts[i].value;
                   8617:             }
                   8618:        }
                   8619:        opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
                   8620:     }
                   8621:     window.close();
                   8622: }
                   8623: </script>
                   8624: 
                   8625: ENDSWJS
                   8626: 
                   8627:     my $startpage = &Apache::loncommon::start_page('Choose server',$js,
                   8628:                                                    {'only_body' => 1,
                   8629:                                                     'js_ready'  => 1,});
                   8630:     my $endpage = &Apache::loncommon::end_page({'js_ready'  => 1});
                   8631: 
                   8632:     my $hostpicker;
                   8633:     my $count = 0;
                   8634:     foreach my $host (sort(@hosts)) {
                   8635:         my $checked;
                   8636:         if ($count == 0) {
                   8637:             $checked = ' checked="checked"';
                   8638:         }
                   8639:         $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
                   8640:                        $host.'"'.$checked.' />'.$host.'</label>&nbsp;&nbsp;';
                   8641:         $count++;
                   8642:     }
                   8643:     
                   8644:     return <<"ENDSWITCHJS";
                   8645: 
                   8646: function dump_needs_switchserver(url) {
                   8647:     if (url!='' && url!= null) {
1.594     damieng  8648:         if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484     raeburn  8649:             go(url);
                   8650:         }
                   8651:     }
                   8652:     return;
                   8653: }
                   8654: 
                   8655: function choose_switchserver_window() {
                   8656:     newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
                   8657:     newWindow.document.open();
                   8658:     newWindow.document.writeln('$startpage');
1.594     damieng  8659:     newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
                   8660:        '<p>$html_js_lt{'yone'}<\\/p>\\n'+
                   8661:        '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484     raeburn  8662:        '<form name="setserver" method="post" action="" \\/>\\n'+
                   8663:        '$hostpicker\\n'+
                   8664:        '<br \\/><br \\/>\\n'+
1.594     damieng  8665:        '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484     raeburn  8666:        'onclick="write_switchserver();" \\/>\\n'+
                   8667:        '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
                   8668:     newWindow.document.writeln('$endpage');
                   8669:     newWindow.document.close();
                   8670:     newWindow.focus();
                   8671: }
                   8672: 
                   8673: ENDSWITCHJS
                   8674: }
                   8675: 
                   8676: sub makedocslogform {
                   8677:     my ($formelems,$docslog) = @_;
                   8678:     return <<"LOGSFORM";
                   8679:  <form action="/adm/coursedocs" method="post" name="docslogform">
                   8680:    <input type="hidden" name="docslog" value="$docslog" />
                   8681:    $formelems
                   8682:  </form>
                   8683: LOGSFORM
                   8684: }
                   8685: 
                   8686: sub makesimpleeditform {
                   8687:     my ($formelems) = @_;
                   8688:     return <<"SIMPFORM";
                   8689:  <form name="simpleedit" method="post" action="/adm/coursedocs">
                   8690:    <input type="hidden" name="importdetail" value="" />
                   8691:    $formelems
                   8692:  </form>
                   8693: SIMPFORM
                   8694: }
                   8695: 
1.606     raeburn  8696: sub makenewproblem {
                   8697:     my ($r,$coursedom,$coursenum) = @_;
                   8698: # Creating a new problem
                   8699:     my ($redirect,$error);
                   8700:     if ($env{'form.authorrole'}) {
                   8701:         my ($newsubdir,$filename);
                   8702:         if ($env{'form.newsubdir'}) {
                   8703:             if ($env{'form.newsubdirname'} ne '') {
                   8704:                 $newsubdir = $env{'form.newsubdirname'};
1.654     raeburn  8705:             }
1.606     raeburn  8706:         }
                   8707:         if ($env{'form.newresourcename'}) {
                   8708:             $filename = $env{'form.newresourcename'};
                   8709:             $filename =~ s/\.(\d+)(\.\w+)$/$2/;
                   8710:             $filename =~ s/`//g;
                   8711:             $filename =~ s{/\.\./}{_}g;
                   8712:             $filename =~ s/\.+/./g;
                   8713:             $filename =~ s{/+}{_}g;
                   8714:             if ($filename ne '') {
                   8715:                 my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
                   8716:                 if (($ext) && ($ext ne '.problem')) {
                   8717:                     $filename = $name.'.problem';
                   8718:                 } elsif ($ext eq '') {
                   8719:                     $filename .= '.problem';
                   8720:                 }
                   8721:                 my $docroot = $r->dir_config('lonDocRoot');
                   8722:                 my @ids=&Apache::lonnet::current_machine_ids();
                   8723:                 if ($env{'form.authorrole'} eq 'author') {
                   8724:                     if ($env{'user.author'}) {
                   8725:                         if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
                   8726:                             my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
                   8727:                             my $path = $docroot.$url;
                   8728:                             my $subdir = $env{'form.authorpath'};
                   8729:                             $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   8730:                         }
                   8731:                     }
                   8732:                 } elsif ($env{'form.authorrole'} eq 'course') {
                   8733:                     my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   8734:                     if ($chome && grep(/^\Q$chome\E$/,@ids)) {
                   8735:                         my $url = "/priv/$coursedom/$coursenum";
                   8736:                         my $path=$docroot.$url;
                   8737:                         my $subdir = $env{'form.authorpath'};
                   8738:                         $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   8739:                         if ($redirect) {
                   8740:                             my $rightsfile = 'default.rights';
                   8741:                             my $sourcerights = "$path/$rightsfile";
                   8742:                             my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
                   8743:                             my $now = time;
                   8744:                             if (!-e $sourcerights) {
                   8745:                                 my $cid = $coursedom.'_'.$coursenum;
                   8746:                                 if (open(my $fh,">$sourcerights")) {
                   8747:                                     print $fh <<END;
                   8748: <accessrule effect="deny" realm="" type="course" role="" />
                   8749: <accessrule effect="allow" realm="$cid" type="course" role="" />
                   8750: END
                   8751:                                     close($fh);
                   8752:                                 }
                   8753:                             }
                   8754:                             if (!-e "$sourcerights.meta") {
                   8755:                                 if (open(my $fh,">$sourcerights.meta")) {
                   8756:                                     my $author=$env{'environment.firstname'}.' '.
                   8757:                                                $env{'environment.middlename'}.' '.
                   8758:                                                $env{'environment.lastname'}.' '.
                   8759:                                                $env{'environment.generation'};
                   8760:                                     $author =~ s/\s+$//;
                   8761:                                     print $fh <<"END";
                   8762: 
                   8763: <abstract></abstract>
                   8764: <author>$author</author>
                   8765: <authorspace>$coursenum:$coursedom</authorspace>
                   8766: <copyright>private</copyright>
                   8767: <creationdate>$now</creationdate>
                   8768: <customdistributionfile></customdistributionfile>
                   8769: <dependencies></dependencies>
                   8770: <domain>$coursedom</domain>
                   8771: <highestgradelevel>0</highestgradelevel>
                   8772: <keywords></keywords>
                   8773: <language>notset </language>
                   8774: <lastrevisiondate>$now</lastrevisiondate>
                   8775: <lowestgradelevel>0</lowestgradelevel>
                   8776: <mime>rights</mime>
                   8777: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
                   8778: <notes></notes>
                   8779: <obsolete></obsolete>
                   8780: <obsoletereplacement></obsoletereplacement>
                   8781: <owner>$coursenum:$coursedom</owner>
                   8782: <rule>deny:::course,allow:$cid::course</rule>
                   8783: <sourceavail></sourceavail>
                   8784: <standards></standards>
                   8785: <subject></subject>
                   8786: <title></title>
                   8787: END
1.654     raeburn  8788:                                     close($fh);
                   8789:                                 }
                   8790:                             }
                   8791:                             if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
                   8792:                                 if (!-e "$docroot/res/$coursedom") {
                   8793:                                     mkdir("$docroot/res/$coursedom",0755);
1.606     raeburn  8794:                                 }
1.654     raeburn  8795:                                 if (!-e "$docroot/res/$coursedom/$coursenum") {
                   8796:                                     mkdir("$docroot/res/$coursedom/$coursenum",0755);
                   8797:                                 }
                   8798:                                 if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
                   8799:                                     my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   8800:                                     my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606     raeburn  8801:                                 }
                   8802:                             }
1.654     raeburn  8803:                             my $source = $docroot.$redirect;
                   8804:                             if (!-e "$source.meta") {
                   8805:                                 my $cid = $coursedom.'_'.$coursenum;
                   8806:                                 my $now = time;
                   8807:                                 if (open(my $fh,">$source.meta")) {
                   8808:                                     my $author=$env{'environment.firstname'}.' '.
                   8809:                                                $env{'environment.middlename'}.' '.
                   8810:                                                $env{'environment.lastname'}.' '.
                   8811:                                                $env{'environment.generation'};
                   8812:                                     $author =~ s/\s+$//;
                   8813:                                     my $title = $env{'form.newresourcetitle'};
                   8814:                                     $title =~ s/^\s+|\s+$//g;
                   8815:                                     print $fh <<END;
1.606     raeburn  8816: 
                   8817: <abstract></abstract>
                   8818: <author>$author</author>
                   8819: <authorspace>$coursenum:$coursedom</authorspace>
                   8820: <copyright>custom</copyright>
                   8821: <creationdate>$now</creationdate>
                   8822: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
                   8823: <dependencies></dependencies>
                   8824: <domain>$coursedom</domain>
                   8825: <highestgradelevel>0</highestgradelevel>
                   8826: <keywords></keywords>
                   8827: <language>notset </language>
                   8828: <lastrevisiondate>$now</lastrevisiondate>
                   8829: <lowestgradelevel>0</lowestgradelevel>
                   8830: <mime>problem</mime>
                   8831: <modifyinguser>$coursenum:$coursedom</modifyinguser>
                   8832: <notes></notes>
                   8833: <obsolete></obsolete>
                   8834: <obsoletereplacement></obsoletereplacement>
                   8835: <owner>$coursenum:$coursedom</owner>
                   8836: <sourceavail></sourceavail>
                   8837: <standards></standards>
                   8838: <subject></subject>
                   8839: <title>$title</title>
                   8840: END
1.654     raeburn  8841:                                     close($fh);
1.606     raeburn  8842:                                 }
                   8843:                             }
                   8844:                         }
                   8845:                     }
                   8846:                 } else {
                   8847:                     my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
                   8848:                     my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
                   8849:                     if (grep(/^\Q$rolehome\E$/,@ids)) {
                   8850:                         my $now = time;
                   8851:                         if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
                   8852:                             my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
                   8853:                             if (($start <= $now) && (($end == 0) || ($end >= $now))) { 
                   8854:                                 my $url = "/priv/$audom/$auname";  
                   8855:                                 my $path = $r->dir_config('lonDocRoot').$url;
                   8856:                                 my $subdir = $env{'form.authorpath'};
                   8857:                                 $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   8858:                             }
                   8859:                         }
                   8860:                     }
                   8861:                 }
                   8862:             }
                   8863:         }
                   8864:     }
                   8865:     return ($redirect,$error);
                   8866: }
                   8867: 
                   8868: sub finishnewprob {
1.654     raeburn  8869:     my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607     raeburn  8870:     unless (-d $path) {
                   8871:         unless (mkdir($path,02770)) {
                   8872:             return;
                   8873:         }
                   8874:     }
1.606     raeburn  8875:     my $redirect;
                   8876:     if ($subdir ne '/') {
                   8877:         $subdir = &cleandir($subdir);
                   8878:         if (($subdir ne '') && (-d "$path/$subdir")) {
                   8879:             $path .= "/$subdir";
                   8880:             $url .= "/$subdir";
                   8881:         }
                   8882:     }
                   8883:     my $dest;
                   8884:     if ($newsubdir ne '') {
                   8885:         $newsubdir = &cleandir($newsubdir);
                   8886:     }
                   8887:     if ($newsubdir ne '') {
                   8888:         if (-d "$path/$newsubdir") {
                   8889:             $dest = "$path/$newsubdir/$filename";
                   8890:         } else {
                   8891:             my $dirok;
                   8892:             unless (-e "$path/$newsubdir") {
                   8893:                 if (mkdir("$path/$newsubdir",02770)) {
                   8894:                     if (chmod(02770,"$path/$newsubdir")) {
                   8895:                         $dirok = 1;
                   8896:                     }
                   8897:                 }
                   8898:             }
                   8899:             if ($dirok) {
                   8900:                 $dest = "$path/$newsubdir/$filename";
                   8901:             }
                   8902:         }
                   8903:         if (($dest ne '') && (!-e $dest)) {
                   8904:             $redirect = "$url/$newsubdir/$filename";
                   8905:         }
                   8906:     } else {
                   8907:         $dest = "$path/$filename";
                   8908:         if (($dest ne '') && (!-e $dest)) {
                   8909:             $redirect = "$url/$filename";
                   8910:         }
                   8911:     }
1.654     raeburn  8912:     if ((!-e $dest) && ($context ne 'upload')) {
                   8913:         my $template = $env{'form.template'};
                   8914:         my $copyfrom;
                   8915:         if ($template ne '') {
                   8916:             my %templates;
                   8917:             my @files = &Apache::lonhomework::get_template_list('problem');
                   8918:             foreach my $poss (@files) {
                   8919:                 if (ref($poss) eq 'ARRAY') {
                   8920:                     if ($template eq $poss->[0]) {
                   8921:                         $templates{$template} = 1;
                   8922:                         last;
                   8923:                     }
                   8924:                 }
                   8925:             }
                   8926:             if ($templates{$template}) {
                   8927:                 $copyfrom = $template;
                   8928:             }
                   8929:         }
                   8930:         if ($filename =~ /\.problem$/) {
                   8931:             unless ($copyfrom) {
                   8932:                 $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
                   8933:             }
                   8934:             &File::Copy::copy($copyfrom,$dest);
                   8935:         }
                   8936:     }
1.606     raeburn  8937:     return $redirect;
                   8938: }
                   8939: 
                   8940: sub cleandir {
                   8941:     my ($dir) = @_;
                   8942:     $dir =~ s/^\s+//;
                   8943:     $dir =~ s/\s+$//;
                   8944:     $dir =~ s/\.+//g;
                   8945:     $dir =~ s/[\#\?&%\":]//g;
                   8946:     return $dir;
                   8947: }
                   8948: 
1.329     droeschl 8949: 1;
                   8950: __END__
                   8951: 
                   8952: 
                   8953: =head1 NAME
                   8954: 
                   8955: Apache::londocs.pm
                   8956: 
                   8957: =head1 SYNOPSIS
                   8958: 
                   8959: This is part of the LearningOnline Network with CAPA project
                   8960: described at http://www.lon-capa.org.
                   8961: 
                   8962: =head1 SUBROUTINES
                   8963: 
                   8964: =over
                   8965: 
                   8966: =item %help=()
                   8967: 
                   8968: Available help topics
                   8969: 
                   8970: =item mapread()
                   8971: 
1.344     bisitz   8972: Mapread read maps into LONCAPA::map:: global arrays
1.329     droeschl 8973: @order and @resources, determines status
                   8974: sets @order - pointer to resources in right order
                   8975: sets @resources - array with the resources with correct idx
                   8976: 
                   8977: =item authorhosts()
                   8978: 
                   8979: Return hash with valid author names
                   8980: 
                   8981: =item clean()
                   8982: 
                   8983: =item dumpcourse()
                   8984: 
                   8985:     Actually dump course
                   8986: 
                   8987: =item group_import()
                   8988: 
                   8989:     Imports the given (name, url) resources into the course
                   8990:     coursenum, coursedom, and folder must precede the list
                   8991: 
                   8992: =item breadcrumbs()
                   8993: 
                   8994: =item log_docs()
                   8995: 
                   8996: =item docs_change_log()
                   8997: 
                   8998: =item update_paste_buffer()
                   8999: 
                   9000: =item print_paste_buffer()
                   9001: 
                   9002: =item do_paste_from_buffer()
                   9003: 
1.538     raeburn  9004: =item do_buffer_empty() 
                   9005: 
                   9006: =item clear_from_buffer()
                   9007: 
1.492     raeburn  9008: =item get_newmap_url()
                   9009: 
                   9010: =item dbcopy()
                   9011: 
                   9012: =item uniqueness_check()
                   9013: 
                   9014: =item contained_map_check()
                   9015: 
                   9016: =item url_paste_fixups()
                   9017: 
                   9018: =item apply_fixups()
                   9019: 
                   9020: =item copy_dependencies()
                   9021: 
1.329     droeschl 9022: =item update_parameter()
                   9023: 
                   9024: =item handle_edit_cmd()
                   9025: 
                   9026: =item editor()
                   9027: 
                   9028: =item process_file_upload()
                   9029: 
                   9030: =item process_secondary_uploads()
                   9031: 
                   9032: =item is_supplemental_title()
                   9033: 
                   9034: =item entryline()
                   9035: 
                   9036: =item tiehash()
                   9037: 
                   9038: =item untiehash()
                   9039: 
                   9040: =item checkonthis()
                   9041: 
                   9042: check on this
                   9043: 
                   9044: =item verifycontent()
                   9045: 
                   9046: Verify Content
                   9047: 
1.636     raeburn  9048: =item devalidateversioncache() 
                   9049: 
                   9050: =item checkversions()
1.329     droeschl 9051: 
                   9052: Check Versions
                   9053: 
                   9054: =item mark_hash_old()
                   9055: 
                   9056: =item is_hash_old()
                   9057: 
                   9058: =item changewarning()
                   9059: 
                   9060: =item init_breadcrumbs()
                   9061: 
                   9062: Breadcrumbs for special functions
                   9063: 
1.484     raeburn  9064: =item create_list_elements()
                   9065: 
                   9066: =item create_form_ul()
                   9067: 
                   9068: =item startContentScreen() 
                   9069: 
                   9070: =item endContentScreen()
                   9071: 
                   9072: =item supplemental_base()
                   9073: 
                   9074: =item embedded_form_elems()
                   9075: 
                   9076: =item embedded_destination()
                   9077: 
                   9078: =item return_to_editor()
                   9079: 
                   9080: =item decompression_info()
                   9081: 
                   9082: =item decompression_phase_one()
                   9083: 
                   9084: =item decompression_phase_two()
                   9085: 
                   9086: =item remove_archive()
                   9087: 
                   9088: =item generate_admin_menu()
                   9089: 
                   9090: =item generate_edit_table()
                   9091: 
                   9092: =item editing_js()
                   9093: 
                   9094: =item history_tab_js()
                   9095: 
                   9096: =item inject_data_js()
                   9097: 
                   9098: =item dump_switchserver_js()
                   9099: 
1.485     raeburn  9100: =item resize_scrollbox_js()
1.484     raeburn  9101: 
                   9102: =item makedocslogform()
                   9103: 
1.485     raeburn  9104: =item makesimpleeditform()
                   9105: 
1.329     droeschl 9106: =back
                   9107: 
                   9108: =cut

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