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

1.329     droeschl    1: # The LearningOnline Network
                      2: # Documents
                      3: #
1.723   ! raeburn     4: # $Id: londocs.pm,v 1.722 2025/01/07 21:01:37 raeburn Exp $
1.329     droeschl    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: package Apache::londocs;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common :http);
                     33: use Apache::imsexport;
                     34: use Apache::lonnet;
                     35: use Apache::loncommon;
1.383     tempelho   36: use Apache::lonhtmlcommon;
1.329     droeschl   37: use LONCAPA::map();
                     38: use Apache::lonratedt();
                     39: use Apache::lonxml;
                     40: use Apache::lonclonecourse;
                     41: use Apache::lonnavmaps;
1.472     raeburn    42: use Apache::lonnavdisplay();
1.510     raeburn    43: use Apache::lonextresedit();
1.567     raeburn    44: use Apache::lontemplate();
                     45: use Apache::lonsimplepage();
1.606     raeburn    46: use Apache::lonhomework();
                     47: use Apache::lonpublisher();
1.651     raeburn    48: use Apache::loncourserespicker();
1.329     droeschl   49: use HTML::Entities;
1.488     raeburn    50: use HTML::TokeParser;
1.713     raeburn    51: use HTML::LCParser;
1.329     droeschl   52: use GDBM_File;
1.578     raeburn    53: use File::MMagic;
1.606     raeburn    54: use File::Copy;
1.329     droeschl   55: use Apache::lonlocal;
                     56: use Cwd;
1.643     raeburn    57: use UUID::Tiny ':std';
1.329     droeschl   58: use LONCAPA qw(:DEFAULT :match);
                     59: 
                     60: my $iconpath;
                     61: 
                     62: my %hash;
                     63: 
                     64: my $hashtied;
                     65: my %alreadyseen=();
                     66: 
                     67: my $hadchanges;
1.557     raeburn    68: my $suppchanges;
1.329     droeschl   69: 
                     70: 
                     71: my %help=();
                     72: 
                     73: 
                     74: sub mapread {
                     75:     my ($coursenum,$coursedom,$map)=@_;
                     76:     return
                     77:       &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                     78: 			     $map);
                     79: }
                     80: 
                     81: sub storemap {
1.492     raeburn    82:     my ($coursenum,$coursedom,$map,$contentchg)=@_;
                     83:     my $report;
                     84:     if (($contentchg) && ($map =~ /^default/)) {
                     85:        $report = 1;
                     86:     }
1.329     droeschl   87:     my ($outtext,$errtext)=
                     88:       &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492     raeburn    89: 			      $map,1,$report);
1.329     droeschl   90:     if ($errtext) { return ($errtext,2); }
1.364     bisitz     91: 
1.557     raeburn    92:     if ($map =~ /^default/) {
                     93:         $hadchanges=1;
1.682     raeburn    94:     } elsif ($contentchg) {
1.557     raeburn    95:         $suppchanges=1;
                     96:     }
1.329     droeschl   97:     return ($errtext,0);
                     98: }
                     99: 
                    100: 
                    101: 
                    102: sub authorhosts {
                    103:     my %outhash=();
                    104:     my $home=0;
                    105:     my $other=0;
1.709     raeburn   106:     my @ids=&Apache::lonnet::current_machine_ids();
1.329     droeschl  107:     foreach my $key (keys(%env)) {
                    108: 	if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
                    109: 	    my $role=$1;
                    110: 	    my $realm=$2;
                    111: 	    my ($start,$end)=split(/\./,$env{$key});
                    112: 	    if (($start) && ($start>time)) { next; }
                    113: 	    if (($end) && (time>$end)) { next; }
                    114: 	    my ($ca,$cd);
                    115: 	    if ($1 eq 'au') {
                    116: 		$ca=$env{'user.name'};
                    117: 		$cd=$env{'user.domain'};
                    118: 	    } else {
                    119: 		($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
                    120: 	    }
                    121: 	    my $allowed=0;
                    122: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
1.484     raeburn   123: 	    foreach my $id (@ids) {
                    124:                 if ($id eq $myhome) {
                    125:                     $allowed=1;
                    126:                     last;
                    127:                 }
                    128:             }
1.329     droeschl  129: 	    if ($allowed) {
                    130: 		$home++;
1.484     raeburn   131: 		$outhash{'home_'.$ca.':'.$cd}=1;
1.329     droeschl  132: 	    } else {
1.484     raeburn   133: 		$outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329     droeschl  134: 		$other++;
                    135: 	    }
                    136: 	}
                    137:     }
                    138:     return ($home,$other,%outhash);
                    139: }
                    140: 
                    141: 
                    142: sub clean {
                    143:     my ($title)=@_;
                    144:     $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344     bisitz    145:     return $title;
1.329     droeschl  146: }
                    147: 
1.617     raeburn   148: sub default_folderpath {
                    149:     my ($coursenum,$coursedom,$navmapref) = @_;
                    150:     return unless ($coursenum && $coursedom && ref($navmapref));
                    151: # Check if entire course is hidden and/or encrypted
                    152:     my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
                    153:     my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
                    154:     unless (ref($$navmapref)) {
                    155:         $$navmapref = Apache::lonnavmaps::navmap->new();
                    156:     }
                    157:     if (ref($$navmapref)) {
                    158:         if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
                    159:             my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
                    160:             my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
                    161:             unless (@resources) {
                    162:                 $hiddenmap = 1;
                    163:                 unless ($env{'request.role.adv'}) {
                    164:                     $hiddentop = 1;
                    165:                     if ($env{'form.folder'}) {
                    166:                         undef($env{'form.folder'});
                    167:                     }
                    168:                 }
                    169:             }
                    170:         }
                    171:         if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
                    172:             $encryptmap = 1;
                    173:         }
                    174:     }
                    175:     unless ($hiddentop) {
                    176:         $folderpath='default&'.&escape(&mt('Main Content')).
                    177:                     '::'.$hiddenmap.':'.$encryptmap.'::';
                    178:     }
                    179:     if (wantarray) {
                    180:         return ($folderpath,$hiddentop);
                    181:     } else {
                    182:         return $folderpath;
                    183:     }
                    184: }
1.329     droeschl  185: 
1.685     raeburn   186: sub validate_supppath {
                    187:     my ($coursenum,$coursedom) = @_;
                    188:     my $backto;
1.677     raeburn   189:     if ($env{'form.supppath'} ne '') {
                    190:         my @items = split(/\&/,$env{'form.supppath'});
1.685     raeburn   191:         my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.677     raeburn   192:         for (my $i=0; $i<@items; $i++) {
                    193:             my $odd = $i%2;
                    194:             if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
                    195:                 $badpath = 1;
1.685     raeburn   196:                 last;
                    197:             } elsif ($odd) {
                    198:                 my $suffix;
                    199:                 my $idx = $i-1;
                    200:                 if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
                    201:                     $backto .= '&'.$1;
                    202:                 } elsif ($items[$idx] eq 'supplemental') {
                    203:                     $backto .= '&'.$items[$i];
                    204:                 } else {
                    205:                     $backto .= '&'.$items[$i];
                    206:                     my $is_hidden;
                    207:                     unless ($got_supp) {
1.688     raeburn   208:                         my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn   209:                         if (ref($supplemental) eq 'HASH') {
                    210:                             if (ref($supplemental->{'hidden'}) eq 'HASH') {
                    211:                                 %supphidden = %{$supplemental->{'hidden'}};
                    212:                             }
                    213:                             if (ref($supplemental->{'ids'}) eq 'HASH') {
                    214:                                 %suppids = %{$supplemental->{'ids'}};
                    215:                             }
                    216:                         }
                    217:                         $got_supp = 1;
                    218:                     }
                    219:                     if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
                    220:                         my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
                    221:                         if ($supphidden{$mapid}) {
                    222:                             $is_hidden = 1;
                    223:                         }
                    224:                     }
                    225:                     $suffix = '::'.$is_hidden.':::';
                    226:                 }
                    227:                 $supppath .= '&'.$items[$i].$suffix;
                    228:             } else {
                    229:                 $supppath .= '&'.$items[$i];
                    230:                 $backto .= '&'.$items[$i];
1.677     raeburn   231:             }
                    232:         }
                    233:         if ($badpath) {
                    234:             delete($env{'form.supppath'});
1.685     raeburn   235:         } else {
                    236:             $supppath =~ s/^\&//;
                    237:             $backto =~ s/^\&//;
                    238:             $env{'form.supppath'} = $supppath;
1.677     raeburn   239:         }
                    240:     }
1.685     raeburn   241:     return $backto;
1.677     raeburn   242: }
                    243: 
1.329     droeschl  244: sub dumpcourse {
                    245:     my ($r) = @_;
1.408     raeburn   246:     my $crstype = &Apache::loncommon::course_type();
1.567     raeburn   247:     my ($starthash,$js);
                    248:     unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    249:         $js = <<"ENDJS";
                    250: <script type="text/javascript">
                    251: // <![CDATA[
                    252: 
                    253: function hide_searching() {
                    254:     if (document.getElementById('searching')) {
                    255:         document.getElementById('searching').style.display = 'none';
                    256:     }
                    257:     return;
                    258: }
                    259: 
                    260: // ]]>
                    261: </script>
                    262: ENDJS
                    263:         $starthash = {
                    264:                          add_entries => {'onload' => "hide_searching();"},
                    265:                      };
                    266:     }
1.709     raeburn   267:     $r->print(&Apache::loncommon::start_page('Copy uploaded content to Authoring Space',$js,$starthash)."\n".
                    268:               &Apache::lonhtmlcommon::breadcrumbs('Copy uploaded content to Authoring Space')."\n");
1.484     raeburn   269:     $r->print(&startContentScreen('tools'));
1.329     droeschl  270:     my ($home,$other,%outhash)=&authorhosts();
1.484     raeburn   271:     unless ($home) {
1.712     raeburn   272:         $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>'); 
1.484     raeburn   273:         $r->print(&endContentScreen());
                    274:         return '';
                    275:     }
1.329     droeschl  276:     my $origcrsid=$env{'request.course.id'};
                    277:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    278:     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    279: # Do the dumping
1.484     raeburn   280: 	unless ($outhash{'home_'.$env{'form.authorspace'}}) {
1.712     raeburn   281:             $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
                    282:                       &endContentScreen());
1.484     raeburn   283:             return '';
                    284:         }
1.531     raeburn   285: 	my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329     droeschl  286: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
                    287: 	my $title=$env{'form.authorfolder'};
                    288: 	$title=&clean($title);
1.567     raeburn   289:         my ($navmap,$errormsg) =
                    290:             &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
                    291:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    292:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    293:         my (%maps,%resources,%titles);
                    294:         if (!ref($navmap)) {
                    295:             $r->print($errormsg.
                    296:                       &endContentScreen());
                    297:             return '';
                    298:         } else {
                    299:             &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
                    300:                                                                    'dumpdocs',$cdom,$cnum);
1.329     droeschl  301: 	}
1.567     raeburn   302:         my @todump = &Apache::loncommon::get_env_multiple('form.archive');
                    303:         my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
                    304:             %newcontent,%has_simpleprobs);
                    305:         foreach my $item (sort {$a <=> $b} (@todump)) {
                    306:             my $name = $env{'form.namefor_'.$item};
                    307:             if ($resources{$item}) {
                    308:                 my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
                    309:                 if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
                    310:                     $tocopy{$1} = $name;
                    311:                     $display{$item} = $1;
                    312:                     $lookup{$1} = $item; 
                    313:                 } elsif ($res eq 'lib/templates/simpleproblem.problem') {
                    314:                     $simpleproblems{$item} = {
                    315:                                                 symb => $resources{$item},
                    316:                                                 name => $name,
                    317:                                              };
                    318:                     $display{$item} = 'simpleproblem_'.$name;
                    319:                     if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
                    320:                         $has_simpleprobs{$1}{$id} = $item;
                    321:                     }
                    322:                 } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
                    323:                     my $marker = $1;
                    324:                     my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
                    325:                     $simplepages{$item} = {
                    326:                                             res    => $res,
                    327:                                             title  => $titles{$item},
                    328:                                             db     => $db_name,
                    329:                                             marker => $marker,
                    330:                                             symb   => $resources{$item},
                    331:                                             name   => $name,
                    332:                                           };
                    333:                     $display{$item} = '/'.$res;
                    334:                 }
                    335:             } elsif ($maps{$item}) {
                    336:                 if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
                    337:                     $tocopy{$1} = $name;
                    338:                     $display{$item} = $1;
                    339:                     $lookup{$1} = $item;
                    340:                 }
                    341:             } else {
                    342:                 next;
                    343:             }
                    344:         }
1.329     droeschl  345: 	my $crs='/uploaded/'.$env{'request.course.id'}.'/';
                    346: 	$crs=~s/\_/\//g;
1.567     raeburn   347:         my $mm = new File::MMagic;
                    348:         my $prefix = "/uploaded/$cdom/$cnum/";
                    349:         %replacehash = %tocopy;
                    350:         foreach my $item (sort(keys(%simpleproblems))) {
                    351:             my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
                    352:             $newcontent{$display{$item}} = $content;
                    353:         }
                    354:         my $gateway = Apache::lonhtmlgateway->new('web');
                    355:         foreach my $item (sort(keys(%simplepages))) {
                    356:             if (ref($simplepages{$item}) eq 'HASH') {
                    357:                 my $pagetitle = $simplepages{$item}{'title'};
                    358:                 my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
                    359:                 my %contents;
                    360:                 foreach my $field (keys(%fields)) {
                    361:                     if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
                    362:                         my $name = $1;
                    363:                         my $msg = $fields{$field};
                    364:                         if ($name eq 'webreferences') {
                    365:                             if ($msg =~ m{^https?://}) {
                    366:                                 $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
                    367:                             }
                    368:                         } else {
                    369:                             $msg = &Encode::decode('utf8',$msg);
                    370:                             $msg = $gateway->process_outgoing_html($msg,1);
                    371:                             $contents{$name} = $msg;
                    372:                         }
                    373:                     } elsif ($field eq 'uploaded.photourl') {
                    374:                         my $marker = $simplepages{$item}{marker};
                    375:                         if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
                    376:                             my $filepath = $1;
                    377:                             my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
                    378:                             if ($fname ne '') {
                    379:                                 $fname=~s/\.(\w+)$//;
                    380:                                 my $ext=$1;
                    381:                                 $fname = &clean($fname);
                    382:                                 $fname.='.'.$ext;
                    383:                                 $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
                    384:                                 $replacehash{$filepath} = $relpath.$fname;
                    385:                                 $deps{$item}{$filepath} = 1;
                    386:                             }
                    387:                         }
                    388:                     }
                    389:                 }
                    390:                 $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
                    391:                 $lookup{'/'.$simplepages{$item}{'res'}} = $item;
                    392:                 my $content = '
                    393: <html>
                    394: <head>
                    395: <title>'.$pagetitle.'</title>
                    396: </head>
                    397: <body bgcolor="#ffffff">';
                    398:                 if ($contents{title}) {
                    399:                     $content .= "\n".'<h2>'.$contents{title}.'</h2>';
                    400:                 }
                    401:                 if ($contents{image}) {
                    402:                     $content .= "\n".$contents{image};
                    403:                 }
                    404:                 if ($contents{content}) {
                    405:                     $content .= '
                    406: <div class="LC_Box">
1.577     bisitz    407: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567     raeburn   408: $contents{content}.'
                    409: </div>';
                    410:                 }
                    411:                 if ($contents{webreferences}) {
                    412:                     $content .= ' 
                    413: <div class="LC_Box">
1.577     bisitz    414: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567     raeburn   415: $contents{webreferences}.'
                    416: </div>';
                    417:                 }
                    418:                 $content .= '
                    419: </body>
                    420: </html>
                    421: ';
                    422:                 $newcontent{'/'.$simplepages{$item}{res}} = $content; 
                    423:             }
                    424:         }
                    425: 	foreach my $item (keys(%tocopy)) {
                    426:             unless ($item=~/\.(sequence|page)$/) {
                    427:                 my $currurlpath = $prefix.$item;
                    428:                 my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
                    429:                 &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
                    430:             }
                    431:         }
                    432:         foreach my $num (sort {$a <=> $b} (@todump)) {
                    433:             my $src = $display{$num};
                    434:             next if ($src eq '');
                    435:             my @needcopy = ();
                    436:             if ($replacehash{$src}) {
                    437:                 push(@needcopy,$src);
                    438:                 if (ref($deps{$num}) eq 'HASH') {
                    439:                     foreach my $dep (sort(keys(%{$deps{$num}}))) {
                    440:                         if ($replacehash{$dep}) {
                    441:                             push(@needcopy,$dep);
                    442:                         }
                    443:                     }
                    444:                 }
                    445:             } elsif ($src =~ /^simpleproblem_/) {
                    446:                 push(@needcopy,$src);
                    447:             }
                    448:             next if (@needcopy == 0);
                    449:             my ($result,$depresult);
                    450:             for (my $i=0; $i<@needcopy; $i++) {
                    451:                 my $item = $needcopy[$i];
                    452:                 my $newfilename;
                    453:                 if ($simpleproblems{$num}) {
                    454:                     $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
                    455:                 } else {
                    456: 	            $newfilename=$title.'/'.$replacehash{$item};
                    457:                 }
                    458: 	        $newfilename=~s/\.(\w+)$//;
                    459: 	        my $ext=$1;
                    460: 	        $newfilename=&clean($newfilename);
                    461: 	        $newfilename.='.'.$ext;
                    462:                 my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); 
                    463:                 if ($newrelpath ne $replacehash{$item}) {
                    464:                     $replacehash{$item} = $newrelpath;
                    465:                 }
                    466: 	        my @dirs=split(/\//,$newfilename);
                    467: 	        my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
                    468: 	        my $makepath=$path;
                    469: 	        my $fail;
                    470:                 my $origin;
                    471: 	        for (my $i=0;$i<$#dirs;$i++) {
                    472: 		    $makepath.='/'.$dirs[$i];
                    473: 		    unless (-e $makepath) {
                    474: 		        unless(mkdir($makepath,0755)) { 
                    475:                             $fail = &mt('Directory creation failed.');
                    476:                         }
                    477: 		    }
                    478: 	        }
                    479:                 if ($i == 0) {
                    480: 	            $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
                    481:                 } else {
                    482:                     $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
                    483:                                   '<span class="LC_fontsize_small" style="font-weight: bold;">'.
                    484:                                   &mt('(dependency)').'</span>: ';
                    485:                 }
                    486:                 if (-e $path.'/'.$newfilename) {
                    487:                     $fail = &mt('Destination already exists -- not overwriting.'); 
                    488: 	        } else {
                    489:                     if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
                    490:                         if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
                    491:                             ($item =~ /^simpleproblem_/)) {
                    492:                             print $fh $newcontent{$item};
                    493:                         } else {
                    494:                             my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
                    495:                             if (-e $fileloc) {
                    496:                                 if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
                    497:                                     if ((($1 eq 'sequence') || ($1 eq 'page')) &&
                    498:                                         (ref($has_simpleprobs{$item}) eq 'HASH')) {
                    499:                                         my %changes = %{$has_simpleprobs{$item}};
                    500:                                         my $content = &Apache::lonclonecourse::rewritefile(
                    501:                      &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                    502:                                                       (%replacehash,$crs => '')
                    503:                                                                                           );
                    504:                                         my $updatedcontent = '';
                    505:                                         my $parser = HTML::TokeParser->new(\$content);
                    506:                                         $parser->attr_encoded(1);
                    507:                                         while (my $token = $parser->get_token) {
                    508:                                             if ($token->[0] eq 'S') {
                    509:                                                 if (($token->[1] eq 'resource') &&
                    510:                                                     ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && 
                    511:                                                     ($changes{$token->[2]->{'id'}})) {
                    512:                                                     my $id = $token->[2]->{'id'};
                    513:                                                     $updatedcontent .= '<'.$token->[1];
                    514:                                                     foreach my $attrib (@{$token->[3]}) {
                    515:                                                         next unless ($attrib =~ /^(src|type|title|id)$/);
                    516:                                                         if ($attrib eq 'src') {
                    517:                                                             my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); 
                    518:                                                             if ($file) {
                    519:                                                                 $updatedcontent .= ' '.$attrib.'="'.$file.'"';
                    520:                                                             } else {
                    521:                                                                 $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; 
                    522:                                                             }
                    523:                                                         } else {
                    524:                                                             $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
                    525:                                                         }
                    526:                                                     }
                    527:                                                     $updatedcontent .= ' />'."\n";
                    528:                                                 } else {
                    529:                                                     $updatedcontent .= $token->[4]."\n";
                    530:                                                 }
                    531:                                              } else {
                    532:                                                  $updatedcontent .= $token->[2];
                    533:                                              }
                    534:                                          }
                    535:                                          print $fh $updatedcontent;
                    536:                                     } else {  
                    537: 		                        print $fh &Apache::lonclonecourse::rewritefile(
                    538:                      &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                    539: 		                                      (%replacehash,$crs => '')
                    540: 							                              );
                    541:                                     }
                    542:                                 } else {
                    543: 		                    print $fh
                    544:                                         &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
                    545: 		                }
                    546:                             } else {
                    547:                                 $fail = &mt('Source does not exist.');  
                    548:                             }
                    549:                         }
                    550:                         $fh->close();
                    551: 	            } else {
                    552: 		        $fail = &mt('Could not write to destination.');
                    553:                     }
                    554: 	        }
                    555:                 my $text;
                    556: 	        if ($fail) {
                    557:                     $text = '<span class="LC_error">'.&mt('fail').('&nbsp;'x3).$fail.'</span>';
                    558: 	        } else {
                    559:                     $text = '<span class="LC_success">'.&mt('ok').'</span>';
                    560:                 }
                    561:                 if ($i == 0) {
                    562:                     $result .= $text;
                    563:                 } else {
                    564:                     $depresult .= $text.'</li>';
                    565: 	        }
                    566:             }
                    567:             $r->print($result);
                    568:             if ($depresult) {
                    569:                 $r->print('<ul>'.$depresult.'</ul>');
                    570:             }
                    571:         }
                    572:     } else {
                    573:         my ($navmap,$errormsg) =
                    574:             &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
                    575:         if (!ref($navmap)) {
                    576:             $r->print($errormsg);
                    577:         } else {
                    578: 	    my $title=$origcrsdata{'description'};
                    579: 	    $title=~s/[\/\s]+/\_/gs;
1.329     droeschl  580: 	    $title=&clean($title);
1.712     raeburn   581: 	    my $formname = 'dumpdoc';
1.715     raeburn   582: 	    my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
                    583:                            '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
1.712     raeburn   584: 	    my %uploadedfiles;
1.567     raeburn   585: 	    &tiehash();
                    586: 	    foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
                    587: 	        my ($ext)=($file=~/\.(\w+)$/);
                    588: # FIXME Check supplemental here
                    589: 	        my $title=$hash{'title_'.$hash{
                    590: 		                'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
                    591: 	        if (!$title) {
                    592: 		    $title=$file;
                    593: 	        } else {
                    594: 		    $title=~s|/|_|g;
                    595: 	        }
                    596: 	        $title=~s/\.(\w+)$//;
                    597: 	        $title=&clean($title);
                    598: 	        $title.='.'.$ext;
                    599: #	    $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
                    600:                 $uploadedfiles{$file} = $title;
                    601: 	    }
                    602: 	    &untiehash();
                    603:             $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
                    604:                                                                  undef,undef,$preamble,$home,\%uploadedfiles));
                    605:         }
1.329     droeschl  606:     }
1.484     raeburn   607:     $r->print(&endContentScreen());
1.329     droeschl  608: }
                    609: 
1.712     raeburn   610: sub authorspace_selector {
                    611:     my ($r,$formname,$home,$title,%outhash) = @_;
                    612:     $r->print('<div id="searching">'.&mt('Searching ...').'</div>'."\n");
                    613:     $r->rflush();
                    614:     my $preamble;
                    615:     unless ($home==1) {
                    616:         $preamble = '<div class="LC_left_float">'.
                    617:                     '<fieldset><legend>'.
                    618:                     &mt('Select the Authoring Space').
                    619:                     '</legend><select name="authorspace">';
                    620:     }
                    621:     my @orderspaces = ();
                    622:     foreach my $key (sort(keys(%outhash))) {
                    623:         if ($key=~/^home_(.+)$/) {
                    624:             if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
                    625:                 unshift(@orderspaces,$1);
                    626:             } else {
                    627:                 push(@orderspaces,$1);
                    628:             }
                    629:         }
                    630:     }
                    631:     if ($home>1) {
                    632:         $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
                    633:     }
                    634:     foreach my $user (@orderspaces) {
                    635:         if ($home==1) {
                    636:             $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
                    637:         } else {
                    638:             $preamble .= '<option value="'.$user.'">'.$user.' - '.
                    639:                          &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
                    640:         }
                    641:     }
                    642:     unless ($home==1) {
                    643:         $preamble .= '</select></fieldset></div>'."\n";
                    644:     }
                    645:     $preamble .= '<div class="LC_left_float">'.
                    646:                  '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
1.715     raeburn   647:                  '<input type="text" size="30" name="authorfolder" value="'.$title.'" />'."\n".
                    648:                  '</fieldset></div>'."\n";
1.712     raeburn   649:     return $preamble;
                    650: }
                    651: 
1.567     raeburn   652: sub recurse_html {
                    653:     my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
                    654:     return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
                    655:     my (%allfiles,%codebase);
                    656:     if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
                    657:         if (keys(%allfiles)) {
                    658:             foreach my $dependency (keys(%allfiles)) {
                    659:                 next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
                    660:                 my ($depurl,$relfile,$newcontainer);
                    661:                 if ($dependency =~ m{^/}) {
                    662:                     if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
                    663:                         $relfile = $1;
                    664:                         if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
                    665:                             $newcontainer = $1;
                    666:                             next if ($replacehash->{$newcontainer});
                    667:                         }
                    668:                         $depurl = $dependency;
                    669:                     } else {
                    670:                         next;
                    671:                     }
                    672:                 } else {
                    673:                     $relfile = $dependency;
                    674:                     $depurl = $currurlpath;
1.630     raeburn   675:                     $depurl =~ s{[^/]+$}{};
1.567     raeburn   676:                     $depurl .= $dependency;
1.630     raeburn   677:                     ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567     raeburn   678:                 }
                    679:                 next if ($relfile eq '');
                    680:                 my $newname = $replacehash->{$container};
                    681:                 $newname =~ s{[^/]+$}{};
                    682:                 $replacehash->{$newcontainer} = $newname.$relfile;
                    683:                 $deps->{$item}{$newcontainer} = 1;
                    684:                 my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});  
                    685:                 my $depfile = &Apache::lonnet::filelocation('',$depurl);
                    686:                 my $type = $mm->checktype_filename($depfile);
                    687:                 if ($type eq 'text/html') {
                    688:                     &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
                    689:                 }
                    690:             }
                    691:         }
                    692:     }
                    693:     return;
                    694: }
                    695: 
1.712     raeburn   696: sub copycrsauthored {
                    697:     my ($r,$coursenum,$coursedom,$coursehome,$readonly) = @_;
1.715     raeburn   698:     my ($starthash,$js,$title,$formname);
                    699:     my %origcrsdata=&Apache::lonnet::coursedescription($env{'request.course.id'});
                    700:     $title=$origcrsdata{'description'};
                    701:     $title=~s/[\/\s]+/\_/gs;
                    702:     $title=&clean($title);
                    703:     my ($home,$other,%outhash)=&authorhosts();
1.712     raeburn   704:     unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
1.715     raeburn   705:         my %js_lt;
                    706:         $formname = 'copycrsauthored';
                    707:         if ($home) {
                    708:             %js_lt =
                    709:                 &Apache::lonlocal::texthash(
                    710:                     yomu => 'You must select an Authoring Space',
                    711:                     whco => 'When Copyright set to "custom", URL of a published rights file is needed.',
                    712:             );
                    713:             &js_escape(\%js_lt);
                    714:         }
                    715:         if ($home > 1) {
                    716:             $js = <<"ENDJS";
                    717: <script type="text/javascript">
                    718: // <![CDATA[
                    719: 
                    720: function validCrsCopy() {
                    721:     var dest = document.$formname.authorspace.options[document.$formname.authorspace.selectedIndex].value;
                    722:     if (dest == '') {
                    723:         alert("$js_lt{'yomu'}");
                    724:         return false;
                    725:     }
                    726:     var dist = document.$formname.copyright.options[document.$formname.copyright.selectedIndex].value;
                    727:     if (dist == 'custom') {
                    728:         if (document.$formname.customrights.value == '') {
                    729:             alert("$js_lt{'whco'}");
                    730:             return false;
                    731:         }
1.716     raeburn   732:     }
1.715     raeburn   733:     return true;
                    734: }
                    735: 
                    736: function init_copycrs_form() {
                    737:     document.$formname.authorspace.selectedIndex = "0";
                    738:     document.$formname.authorfolder.value = '$title';
                    739:     document.$formname.copyright.selectedIndex = "0";
                    740: }
                    741: 
                    742: // ]]>
                    743: </script>
                    744: 
                    745: ENDJS
                    746:         } elsif ($home) {
                    747:             $js = <<"ENDJS";
                    748: <script type="text/javascript">
                    749: // <![CDATA[
                    750: 
                    751: function init_copycrs_form() {
                    752:     document.$formname.authorfolder.value = '$title';
                    753:     document.$formname.copyright.selectedIndex = "0";
                    754: }
                    755: 
                    756: // ]]>
                    757: </script>
                    758: 
                    759: ENDJS
                    760:         }
                    761:         $js .= <<"ENDJS";
1.712     raeburn   762: <script type="text/javascript">
                    763: // <![CDATA[
                    764: 
                    765: function hide_searching() {
                    766:     if (document.getElementById('searching')) {
                    767:         document.getElementById('searching').style.display = 'none';
                    768:     }
                    769:     return;
                    770: }
                    771: 
1.715     raeburn   772: function showHideCustom(caller,divid) {
                    773:     if (document.getElementById(divid)) {
                    774:         if (caller.options[caller.selectedIndex].value == 'custom') {
                    775:             document.getElementById(divid).style.display="inline-block";
                    776:         } else {
                    777:             document.getElementById(divid).style.display="none";
                    778:         }
                    779:     }
                    780:     return;
                    781: }
                    782: 
1.712     raeburn   783: // ]]>
                    784: </script>
                    785: ENDJS
1.715     raeburn   786: 
                    787:         $js .= "\n".&Apache::lonhtmlcommon::scripttag(&Apache::loncommon::browser_and_searcher_javascript())."\n";
1.712     raeburn   788:         $starthash = {
1.715     raeburn   789:                          add_entries => {'onload' => "hide_searching(); init_copycrs_form();"},
1.712     raeburn   790:                      };
                    791:     }
                    792:     $r->print(&Apache::loncommon::start_page('Copy from Course Authoring to User Authoring',$js,$starthash)."\n".
                    793:               &Apache::lonhtmlcommon::breadcrumbs('Copy from Course Authoring Space')."\n");
                    794:     $r->print(&startContentScreen('tools'));
                    795:     unless ($home) {
                    796:         $r->print('<p class="LC_info">'.&mt('No author or co-author roles on this server.').'</p>');
                    797:         $r->print(&endContentScreen());
                    798:         return '';
                    799:     }
1.715     raeburn   800:     my $docroot = $r->dir_config('lonDocRoot');
1.714     raeburn   801:     my $is_course_home;
                    802:     my @ids=&Apache::lonnet::current_machine_ids();
                    803:     if (($coursehome ne '') && (grep(/^\Q$coursehome\E$/,@ids))) {
                    804:         $is_course_home = 1;
                    805:     }
1.712     raeburn   806:     my $exclude = &Apache::lonnet::priv_exclude();
                    807:     my $srcurl = "/priv/$coursedom/$coursenum";
1.715     raeburn   808:     my $srctop = $docroot.$srcurl;
                    809:     my $resurl = "/res/$coursedom/$coursenum";
                    810:     my $res_exclude = &Apache::lonnet::res_exclude();
1.712     raeburn   811:     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    812:         $r->print('<h3>'.&mt('Copying Files and/or Sub-directories').'</h3>');
                    813:         if ($readonly) {
                    814:             $r->print('<p class="LC_info">'.
                    815:                       &mt('You do not have permission to copy files and/or directories from Course Authoring Space.').
                    816:                       '</p>'.
                    817:                       &endContentScreen());
                    818:             return '';
                    819:         }
                    820:         unless ($outhash{'home_'.$env{'form.authorspace'}}) {
                    821:             $r->print('<p class="LC_info">'.&mt('Selected Authoring Space is not on this server.').'</p>'.
                    822:                       &endContentScreen());
                    823:             return '';
                    824:         }
                    825:         my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
                    826:         my $desturl = "/priv/$cd/$ca";
1.715     raeburn   827:         my $destresurl = "/res/$cd/$ca";
                    828:         my $desttop = $docroot.$desturl;
1.712     raeburn   829:         my $subdir = &clean($env{'form.authorfolder'});
                    830:         $subdir = &cleandir($subdir);
                    831:         if ($subdir eq '') {
                    832:             $r->print('<p class="LC_info">'.&mt('After removal of disallowed characters target sub-directory name was blank.').'</p>'.
                    833:                       &endContentScreen());
                    834:             return '';
                    835:         } elsif ($subdir =~/^_+$/) {
                    836:             $r->print('<p class="LC_info">'.&mt('After replacement of non-alphanumeric characters with _ in target sub-directory name, nothing but underscores was left.').'</p>'.
                    837:                       &endContentScreen());
                    838:             return '';
                    839:         }
                    840:         my (%tocopy,%dirs_to_make,%files_to_copy);
                    841:         map { $tocopy{&unescape($_)} = 1; } &Apache::loncommon::get_env_multiple('form.copytouser');
                    842:         if (keys(%tocopy)) {
                    843:             my (%subdirs,%files);
1.714     raeburn   844:             &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files);
1.712     raeburn   845:             foreach my $possible (sort(keys(%tocopy))) {
                    846:                 if ($possible =~ m{/$}) {
                    847:                     my $possdir = $possible;
                    848:                     $possdir =~ s{^/+|/+$}{}g;
                    849:                     if (exists($subdirs{$possdir})) {
                    850:                         $dirs_to_make{$possdir} = 1;
                    851:                     } else {
                    852:                         delete($tocopy{$possible});
                    853:                     }
                    854:                 } else {
                    855:                     my ($path,$fname) = ($possible =~ m{(.*/)([^/]+)$});
                    856:                     my $found = 0;
                    857:                     if ($path eq '/') {
                    858:                         if (ref($files{$path}) eq 'HASH') {
                    859:                             if (exists($files{$path}{$fname})) {
                    860:                                 $found = 1;
                    861:                                 $files_to_copy{$fname} = 1;
                    862:                             }
                    863:                         }
                    864:                     } else {
                    865:                         $path =~ s{^/+|/+$}{}g;
                    866:                         if (ref($files{$path}) eq 'HASH') {
                    867:                             if (exists($files{$path}{$fname})) {
                    868:                                 $dirs_to_make{$path} = 1;
                    869:                                 $files_to_copy{"$path/$fname"} = 1;
                    870:                                 $found = 1;
                    871:                             }
                    872:                         }
                    873:                     }
                    874:                     unless ($found) {
                    875:                         delete($tocopy{$possible});
                    876:                     }
                    877:                 }
                    878:             }
                    879:         } else {
                    880:             $r->print('<p>'.&mt('No files or directories selected for copying').'</p>');
                    881:             $r->print(&endContentScreen());
                    882:             return '';
                    883:         }
                    884:         if (keys(%tocopy)) {
1.714     raeburn   885:             my (%resdirs,%resfiles);
                    886:             &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
1.719     raeburn   887:             my ($notopdir,%newdir,%newfile,%checkdeps,%newresfile);
1.712     raeburn   888:             $r->print('<p>'.&mt('Copy to: [_1]',
                    889:                                 '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
                    890:                       '</p>'."\n");
                    891:             if (keys(%dirs_to_make)) {
1.714     raeburn   892:                 unless (-e $desttop.'/'.$subdir) {
                    893:                     mkdir($desttop.'/'.$subdir,0755);
                    894:                 }
                    895:                 if (-e $desttop.'/'.$subdir) {
                    896:                     foreach my $dir (sort(keys(%dirs_to_make))) {
                    897:                         my @dirs=split(/\//,$dir);
                    898:                         my $path="$desttop/$subdir";
                    899:                         my $makepath=$path;
                    900:                         my $fail;
                    901:                         for (my $i=0;$i<@dirs;$i++) {
                    902:                             $makepath.='/'.$dirs[$i];
                    903:                             unless (-e $makepath) {
                    904:                                 unless (mkdir($makepath,0755)) {
                    905:                                     $fail = 1;
                    906:                                     last;
                    907:                                 }
                    908:                                 if (($i == scalar(@dirs)-1) && (!$fail))  {
                    909:                                     $newdir{$dir} = 1;
1.712     raeburn   910:                                 }
                    911:                             }
                    912:                         }
1.714     raeburn   913:                         if ($fail) {
                    914:                             $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
                    915:                                                                    '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$dir.'</span>').
                    916:                                       '</p>'."\n");
                    917:                         }
1.712     raeburn   918:                     }
1.714     raeburn   919:                 } else {
                    920:                     $notopdir = 1;
1.712     raeburn   921:                 }
                    922:             }
                    923:             if (keys(%files_to_copy)) {
1.714     raeburn   924:                 unless (-e $desttop.'/'.$subdir) {
                    925:                     mkdir($desttop.'/'.$subdir,0755);
                    926:                 }
                    927:                 if (-e $desttop.'/'.$subdir) {
                    928:                     my $num = 0;
1.715     raeburn   929:                     my ($copyright,$customdistfile);
                    930:                     if ($env{'form.copyright'} eq 'default' || $env{'form.copyright'} eq 'domain' || $env{'form.copyright'} eq 'public') {
                    931:                         $copyright = $env{'form.copyright'};
                    932:                     } elsif ($env{'form.copyright'} eq 'custom') {
                    933:                         if ($env{'form.customrights'} =~ m{^/res/$match_domain/$match_username/.+\.rights$}) {
                    934:                             my ($rightsdom,$rightsuname) = ($1,$2);
                    935:                             my $rightshome = &Apache::lonnet::homeserver($rightsdom,$rightsuname);
                    936:                             if (($rightshome eq 'no_host') || ($rightshome eq '')) {
                    937:                                 $copyright = 'default';
                    938:                             } elsif (grep(/^\Q$rightshome\E$/,@ids)) {
                    939:                                 if (-e $docroot.$env{'form.customrights'}) {
                    940:                                     $copyright = 'custom';
                    941:                                     $customdistfile = $env{'form.customrights'};
                    942:                                 } else {
                    943:                                     $copyright = 'default';
                    944:                                 }
                    945:                             } else {
                    946:                                 my $rightsfile = &Apache::lonnet::filelocation('',$env{'form.customrights'});
                    947:                                 unless (&Apache::lonnet::getfile($rightsfile) eq '-1') {
                    948:                                     $customdistfile = $env{'form.customrights'};
                    949:                                 }
                    950:                             }
                    951:                         }
                    952:                     }
                    953:                     my $sourceavail;
                    954:                     if ($env{'form.sourceavail'} =~ /^(open|closed)$/) {
                    955:                         $sourceavail = $env{'form.sourceavail'};
                    956:                     }
                    957:                     my $respublish;
                    958:                     if ($env{'form.respublish'}) {
                    959:                         $respublish = 1;
                    960:                     }
                    961:                     my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
1.714     raeburn   962:                     foreach my $file (keys(%files_to_copy)) {
                    963:                         my ($fail,$dup,$dir_is_file,$src,$dest,$path,$fname);
                    964:                         if ($file =~ m{/}) {
                    965:                             ($path,$fname) = ($file =~ m{^(.+)/([^/]+)$});
                    966:                             if (-d "$desttop/$subdir/$path") {
                    967:                                 if (-e "$desttop/$subdir/$path/$fname") {
                    968:                                     $dup = 1;
1.712     raeburn   969:                                 } else {
1.714     raeburn   970:                                     $src = "$srctop/$path/$fname";
                    971:                                     $dest = "$desttop/$subdir/$path/$fname";
1.712     raeburn   972:                                 }
1.714     raeburn   973:                             } elsif (-f "$desttop/$subdir/$path") {
                    974:                                 $dir_is_file = 1;
1.712     raeburn   975:                             } else {
1.714     raeburn   976:                                 $fail = 1;
                    977:                             }
                    978:                         } elsif (-e "$desttop/$subdir/$file") {
                    979:                             $dup = 1;
                    980:                         } else {
                    981:                             $src = "$srctop/$file";
                    982:                             $dest = "$desttop/$subdir/$file";
                    983:                             $fname = $file;
                    984:                         }
                    985:                         if ($fail) {
                    986:                             $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
                    987:                                                                    '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$path.'</span>').
                    988:                                       '</p>'."\n");
                    989:                         } elsif ($dup) {
                    990:                             $r->print('<p class="LC_warning">'.&mt('Target file: [_1] already exists -- not overwriting.',
                    991:                                                                    '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
                    992:                                       '</p>'."\n");
                    993:                         } elsif ($dir_is_file) {
                    994:                             $r->print('<p class="LC_warning">'.&mt('Target directory: [_1] name is already in a use for a file -- not overwriting.',
                    995:                                                                    '<span class="LC_filename">'.$desturl.'/'.$subdir.'/'.$file.'</span>').
                    996:                                       '</p>'."\n");
                    997:                         } elsif (($src ne '') && ($dest ne '')) {
1.717     raeburn   998:                             my $ressrc = $docroot.$resurl.'/'.$file;
                    999:                             my $ressrcmeta = $ressrc.'.meta';
                   1000:                             my ($ext) = ($file =~ /\.(\w+)$/);
                   1001:                             my $embstyle=&Apache::loncommon::fileembstyle($ext);
                   1002:                             my ($getres,$getresmeta);
                   1003:                             if ($respublish) {
                   1004:                                 if ($path eq '') {
                   1005:                                     if ((ref($resfiles{'/'}) eq 'HASH') &&
                   1006:                                         (exists($resfiles{'/'}{$fname}))) {
                   1007:                                         $getres = 1;
                   1008:                                         $getresmeta = 1;
                   1009:                                     }
                   1010:                                 } elsif ((ref($resfiles{$path}) eq 'HASH') &&
                   1011:                                          (exists($resfiles{$path}{$fname}))) {
                   1012:                                     $getres = 1;
                   1013:                                     $getresmeta = 1;
1.714     raeburn  1014:                                 }
                   1015:                             }
1.717     raeburn  1016:                             if ($is_course_home) {
                   1017:                                 my ($needpriv,$needprivmeta);
                   1018:                                 if ($respublish) {
                   1019:                                     if ($getres) {
                   1020:                                         if (&Apache::londiff::are_different_files($src,$ressrc)) {
                   1021:                                             $needpriv = 1;
                   1022:                                             if (&File::Copy::copy($ressrc,$dest)) {
                   1023:                                                 if ($embstyle eq 'ssi') {
                   1024:                                                     &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
                   1025:                                                 }
                   1026:                                             }
                   1027:                                         } else {
                   1028:                                             if (&File::Copy::copy($src,$dest)) {
1.719     raeburn  1029:                                                 $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717     raeburn  1030:                                                 if ($embstyle eq 'ssi') {
                   1031:                                                     &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
                   1032:                                                 }
                   1033:                                             }
1.714     raeburn  1034:                                         }
1.717     raeburn  1035:                                     } else {
                   1036:                                         $needpriv = 1;
1.714     raeburn  1037:                                     }
1.717     raeburn  1038:                                     if ($getresmeta) {
                   1039:                                         if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
                   1040:                                             if (&Apache::londiff::are_different_files($src.'.meta',$ressrc.'.meta')) {
                   1041:                                                 if (&File::Copy::copy($ressrc.'.meta',$dest.'.meta')) {
                   1042:                                                     &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1043:                                                                        $customdistfile,$sourceavail,\%checkdeps);
1.715     raeburn  1044:                                                 }
1.717     raeburn  1045:                                                 $needprivmeta = 1;
                   1046:                                             } else {
                   1047:                                                 if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
                   1048:                                                     &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1049:                                                                        $customdistfile,$sourceavail,\%checkdeps);
1.713     raeburn  1050:                                                 }
                   1051:                                             }
1.712     raeburn  1052:                                         }
1.717     raeburn  1053:                                     }
                   1054:                                     if ($getres) {
                   1055:                                         my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
                   1056:                                         if (-e $dest) {
                   1057:                                             my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
1.719     raeburn  1058:                                             if (-e $destresfile) {
                   1059:                                                 $newresfile{$file} = $destresurl.'/'.$subdir.'/'.$file;
                   1060:                                             }
1.714     raeburn  1061:                                         }
1.712     raeburn  1062:                                     }
1.717     raeburn  1063:                                 } else {
                   1064:                                     $needpriv = 1;
                   1065:                                     if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
                   1066:                                         $needprivmeta = 1;
                   1067:                                     }  
                   1068:                                 }
                   1069:                                 if ($needpriv) {
                   1070:                                     if (&File::Copy::copy($src,$dest)) {
1.719     raeburn  1071:                                         $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717     raeburn  1072:                                         if ($embstyle eq 'ssi') {
                   1073:                                             &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
                   1074:                                         }
                   1075:                                     }
                   1076:                                 }
                   1077:                                 if ($needprivmeta) {
                   1078:                                     if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
                   1079:                                          &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1080:                                                             $customdistfile,$sourceavail,\%checkdeps);
                   1081:                                     }
1.714     raeburn  1082:                                 }
1.717     raeburn  1083:                             } else {
                   1084:                                 my ($needpriv,$needprivmeta);
                   1085:                                 if ($respublish) {
                   1086:                                     if ($getres) {
                   1087:                                         &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file);
                   1088:                                     }
                   1089:                                     if ($getresmeta) {
                   1090:                                         &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file.'.meta');
                   1091:                                     }
                   1092:                                     if (-e $docroot.$resurl.'/'.$file) {
                   1093:                                         if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
                   1094:                                             if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file,$dest)) {
                   1095:                                                 $needpriv = 1;
                   1096:                                                 if (&File::Copy::copy($docroot.$resurl.'/'.$file,$dest)) {
                   1097:                                                     if ($embstyle eq 'ssi') {
                   1098:                                                         &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
1.713     raeburn  1099:                                                     }
1.714     raeburn  1100:                                                 }
1.717     raeburn  1101:                                             } else {
                   1102:                                                 if ($embstyle eq 'ssi') {
                   1103:                                                     &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1.714     raeburn  1104:                                                 }
1.719     raeburn  1105:                                                 $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717     raeburn  1106:                                             }
                   1107:                                         }
                   1108:                                     } else {
                   1109:                                         $needpriv = 1;
                   1110:                                     }
                   1111:                                     if (-e $docroot.$resurl.'/'.$file.'.meta') {
                   1112:                                         if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
                   1113:                                             if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
                   1114:                                                 $needprivmeta = 1;
                   1115:                                                 if (&File::Copy::copy($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
                   1116:                                                     &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1117:                                                                        $customdistfile,$sourceavail,\%checkdeps);
1.713     raeburn  1118:                                                 }
1.714     raeburn  1119:                                             } else {
1.717     raeburn  1120:                                                 &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1121:                                                                    $customdistfile,$sourceavail,\%checkdeps);
1.713     raeburn  1122:                                             }
                   1123:                                         }
1.717     raeburn  1124:                                     } else {
                   1125:                                         if (!-e $dest.'.meta') {
                   1126:                                             $needprivmeta = 1;
                   1127:                                         }
1.714     raeburn  1128:                                     }
1.717     raeburn  1129:                                     if ($getres) {
                   1130:                                         my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
                   1131:                                         if (-e $dest) {
                   1132:                                             my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
1.719     raeburn  1133:                                             if (-e $destresfile) {
                   1134:                                                 $newresfile{$file} = $destresurl.'/'.$subdir.'/'.$file;
                   1135:                                             }
1.713     raeburn  1136:                                         }
1.712     raeburn  1137:                                     }
1.717     raeburn  1138:                                 } else {
                   1139:                                     $needpriv = 1;
                   1140:                                     if (!-e $dest.'.meta') {
                   1141:                                         $needprivmeta = 1;
                   1142:                                     }
1.712     raeburn  1143:                                 }
1.717     raeburn  1144:                                 if ($needpriv) {
                   1145:                                     if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
                   1146:                                         if ($embstyle eq 'ssi') {
                   1147:                                             &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
1.715     raeburn  1148:                                         }
1.719     raeburn  1149:                                         $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
1.717     raeburn  1150:                                     }
                   1151:                                 }
                   1152:                                 if ($needprivmeta) {
                   1153:                                     if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
                   1154:                                         &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
                   1155:                                                            $customdistfile,$sourceavail,\%checkdeps);
1.715     raeburn  1156:                                     }
                   1157:                                 }
1.712     raeburn  1158:                             }
                   1159:                         }
                   1160:                     }
1.714     raeburn  1161:                 } else {
                   1162:                     $notopdir = 1;
1.712     raeburn  1163:                 }
                   1164:             }
                   1165:             if ($notopdir) {
                   1166:                 $r->print('<p><span class="LC_info">'.&mt('No files or sub-directories copied').'</span><br />'."\n".
                   1167:                           '<span class="LC_warning">'.&mt('Target directory: [_1] does not exist, and could not be created.',
                   1168:                                                           '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
                   1169:                           '</span></p>'."\n");
                   1170:             }
                   1171:             if (keys(%newdir)) {
                   1172:                  $r->print('<p>'.&mt('Created the following directories in [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
                   1173:                            '</p>'."\n".
                   1174:                            '<ul><li>'.join('</li><li>',sort(keys(%newdir))).'</li></ul></p>'."\n");
                   1175:             }
                   1176:             if (keys(%newfile)) {
                   1177:                 $r->print('<p>'.&mt('Copied the following files to [_1]:','<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
                   1178:                           '</p>'."\n".
                   1179:                           '<ul><li>'.join('</li><li>',sort(keys(%newfile))).'</li></ul></p>'."\n");
1.722     raeburn  1180:                 foreach my $file (keys(%newfile)) {
                   1181:                     my %storehash = (
                   1182:                                       'priv' => $newfile{$file},
1.719     raeburn  1183:                                       'who'  => $env{'user.name'}.':'.$env{'user.domain'},
                   1184:                                     );
                   1185:                     if (exists($newresfile{$file})) {
                   1186:                         $storehash{'res'} = 1;
                   1187:                     }
                   1188:                     &Apache::lonnet::store_userdata(\%storehash,$file,'copycourseauthor',$coursedom,$coursenum);
                   1189:                 }
1.712     raeburn  1190:             }
1.713     raeburn  1191:             if (keys(%checkdeps)) {
                   1192:                 my %missingdep;
                   1193:                 foreach my $depfile (sort(keys(%checkdeps))) {
                   1194:                     unless (-e "$desttop/$depfile") {
                   1195:                         $missingdep{$depfile} = 1;
                   1196:                     }
                   1197:                 }
                   1198:                 if (keys(%missingdep)) {
                   1199:                     $r->print('<p>'.&mt('You may also need to copy the following missing dependencies for files copied to [_1]:',
                   1200:                                         '<span class="LC_filename">'.$desturl.'/'.$subdir.'</span>').
                   1201:                           '</p>'."\n".
                   1202:                           '<ul><li>'.join('</li><li>',sort(keys(%missingdep))).'</li></ul></p>'."\n");
                   1203:                 }
                   1204:             }
1.712     raeburn  1205:         } else {
                   1206:             $r->print('<p>'.&mt('No currently existing files or directories in Course Authoring Space selected for copying').'</p>');
                   1207:             $r->print(&endContentScreen());
                   1208:             return '';
                   1209:         }
                   1210:     } else {
                   1211:         my $chkname = 'copytouser';
                   1212:         my $context = 'crsauthored';
                   1213:         my (%subdirs,%files,@dirs_by_depth,@files_by_depth,%parent,%children,%hierarchy,@checked_maps);
1.714     raeburn  1214:         &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files,1);
1.712     raeburn  1215:         foreach my $key (keys(%subdirs)) {
                   1216:             next if (($key eq '/') || ($key eq ''));
                   1217:             my @items = split(/\//,$key);
                   1218:             my $dir = pop(@items);
                   1219:             my $depth = scalar(@items);
                   1220:             my $path;
                   1221:             if (!$depth) {
                   1222:                 $path = '/';
                   1223:             } else {
                   1224:                 $path = join('/',@items);
                   1225:             }
                   1226:             $dirs_by_depth[$depth]{$path}{$dir} = 1;
                   1227:         }
                   1228:         foreach my $path (keys(%files)) {
                   1229:             next if ($path eq '');
                   1230:             my $depth;
                   1231:             if ($path eq '/') {
                   1232:                 $depth = 0;
                   1233:             } else {
                   1234:                 $depth = scalar(split(/\//,$path));
                   1235:             }
                   1236:             if (ref($files{$path}) eq 'HASH') {
                   1237:                 foreach my $file (keys(%{$files{$path}})) {
1.714     raeburn  1238:                     $files_by_depth[$depth]{$path}{$file} = $files{$path}{$file};
1.712     raeburn  1239:                 }
                   1240:             }
                   1241:         }
                   1242:         my ($info,$display,$onsubmit,$togglebuttons,$disabled);
1.714     raeburn  1243:         my (%resdirs,%resfiles);
1.715     raeburn  1244:         &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
                   1245:         my $numpub = 0;
                   1246:         if (keys(%resfiles)) {
                   1247:             foreach my $dir (keys(%resfiles)) {
                   1248:                 if (ref($resfiles{$dir}) eq 'HASH') {
                   1249:                     foreach my $file (keys(%{$resfiles{$dir}})) {
                   1250:                         if (exists($files{$dir}{$file})) {
                   1251:                             $numpub ++;
                   1252:                         }
                   1253:                     }
                   1254:                 }
                   1255:             }
                   1256:         }
1.712     raeburn  1257:         if ($readonly) {
                   1258:             $disabled = ' disabled="disabled"';
                   1259:         }
                   1260:         if ($disabled) {
                   1261:             $togglebuttons = '<br />';
                   1262:         } else {
                   1263:             $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
                   1264:                              'onclick="javascript:checkAll(document.'.$formname.'.'.$chkname.')" />'.
                   1265:                              '&nbsp;&nbsp;<input type="button" value="'.&mt('uncheck all').'"'.
                   1266:                              ' onclick="javascript:uncheckAll(document.'.$formname.'.'.$chkname.')" />';
                   1267:         }
1.715     raeburn  1268:         my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
                   1269:                        &courseresource_options($formname,$numpub).
                   1270:                        '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
                   1271:         my $display = '<form name="'.$formname.'" action="" method="post" onsubmit="return validCrsCopy();">'."\n".
1.712     raeburn  1272:                       $preamble."\n".
                   1273:                       '<div class="LC_float_left">'."\n".
                   1274:                       '<fieldset>'."\n".
                   1275:                       '<legend>'.&mt('Content to copy').('&nbsp;'x4).$togglebuttons.'</legend>'."\n".
                   1276:                       '<span class="LC_fontsize_medium">'.
                   1277:                       &mt('Choose the files and/or folders to copy from Course Authoring to User Authoring').
                   1278:                       '</span><br /><br />'."\n";
                   1279:         my $count = 0;
1.721     raeburn  1280: #
                   1281: # Warning to developers:
                   1282: #
                   1283: # If you add or remove form elements which precede the table of items to copy
                   1284: # you will need to modify the value for startcount. Form elements include both:
                   1285: # <input> and <fieldset> tags.
                   1286: # $startcount (set to 9) contains the following:
                   1287: # fieldsets with following legends: (a) Folder in Authoring Space, (b) Distribution to set in metadata
                   1288: # (c) Content to copy
                   1289: # inputs: textbox for destination folder; dropdown lists: (a) Copyright, (b) Source
                   1290: # hidden: customrights file;  buttons: (a) check all, (b) uncheck all.
                   1291: # authorspace: if more than 1: a fieldset with legend: Select the Authoring Space,
                   1292: # or if 1: an input (hidden) with available author/coauthor role.
                   1293: # if there are multiple possible author/coauthor roles (i.e., $home > 1),
                   1294: # incerement startcount by 1 for the dropdown list uses to select the target.
                   1295: #
                   1296: # If there are published files, increment startcount by 3:
                   1297: # fieldset (legend: Published Resources), and two radio buttons (Yes/No).
                   1298: #
                   1299:         my $startcount = 9;
                   1300:         if ($home > 1) {
                   1301:             $startcount ++;
                   1302:         }
                   1303:         if ($numpub) {
                   1304:             $startcount += 3;
                   1305:         }
1.712     raeburn  1306:         my $lastcontainer = $startcount;
                   1307:         $display .= &Apache::loncommon::start_data_table()."\n".
                   1308:                     &Apache::loncommon::start_data_table_header_row().
                   1309:                     '<th>'.&mt('Copy?').'</th>'.
1.714     raeburn  1310:                     '<th>'.&mt('Name').'</th>'.
                   1311:                     '<th>'.&mt('Last modified').'</th>'.
                   1312:                     '<th>'.&mt('Published?').'</th>'.
1.712     raeburn  1313:                     &Apache::loncommon::end_data_table_header_row()."\n";
                   1314:         $count = &recurse_crsauthored(0,\@dirs_by_depth,\@files_by_depth,'/',$startcount,
                   1315:                                       $count,\$display,\%parent,\%children,$readonly,
1.714     raeburn  1316:                                       $formname,$chkname,\$lastcontainer,\%resfiles);
1.712     raeburn  1317:         $display .= &Apache::loncommon::end_data_table().'</fieldset>';
                   1318:         unless ($readonly) {
                   1319:             $display .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   1320:                         '<div>'.
                   1321:                         '<input type="submit" name="copyauthored" value="'.&mt("Copy Selected Content").'" />'.
                   1322:                         '</div>';
                   1323:         }
                   1324:         $display .= &Apache::loncourserespicker::respicker_javascript($startcount,$count,$context,$formname,\%children,
                   1325:                                                                       \%hierarchy,\@checked_maps,$home,$chkname);
                   1326:         $r->print($display);
                   1327:     }
                   1328:     $r->print(&endContentScreen());
                   1329: }
                   1330: 
                   1331: sub recurse_crsauthored {
                   1332:     my ($currdepth,$dirs_by_depth,$files_by_depth,$currpath,$startcount,$count,$displayref,
1.714     raeburn  1333:         $parent,$children,$readonly,$formname,$chkname,$lastcontainerref,$resfilesref) = @_;
                   1334:     return $count unless ((ref($dirs_by_depth) eq 'ARRAY') && (ref($files_by_depth) eq 'ARRAY') &&
                   1335:                           (ref($resfilesref) eq 'HASH'));
1.712     raeburn  1336:     my ($disabled,$hasdirs,$hasfiles,%unique,%dirs,%files);
                   1337:     if ((ref($dirs_by_depth->[$currdepth]) eq 'HASH') &&
                   1338:         (ref($dirs_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
                   1339:         $hasdirs = 1;
                   1340:         %dirs = %{$dirs_by_depth->[$currdepth]{$currpath}};
                   1341:         map { $unique{$_} = 1; } keys(%dirs);
                   1342:     }
                   1343:     if ((ref($files_by_depth->[$currdepth]) eq 'HASH') &&
                   1344:         (ref($files_by_depth->[$currdepth]{$currpath}) eq 'HASH')) {
                   1345:         $hasfiles = 1;
                   1346:         %files = %{$files_by_depth->[$currdepth]{$currpath}};
                   1347:         map { $unique{$_} = 1; } keys(%files);
                   1348:     }
                   1349:     if ($readonly) {
                   1350:         $disabled = ' disabled="disabled"';
                   1351:     }
                   1352:     my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
                   1353:     my $whitespace =
                   1354:         '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
                   1355:     $parent->{$currdepth} = $$lastcontainerref;
                   1356:     foreach my $item (sort { lc($a) cmp lc($b) } (keys(%unique))) {
                   1357:         next if ($item eq '');
                   1358:         my $currelem;
                   1359:         if ($hasdirs && exists($dirs{$item})) {
                   1360:             $count ++;
                   1361:             my $deeper = $currdepth+1;
                   1362:             my ($newpath,$showpath);
                   1363:             if ($currpath eq '/') {
                   1364:                 $newpath = $item;
                   1365:                 $showpath = $currpath.$item.'/';
                   1366:             } else {
                   1367:                 $newpath = $currpath.'/'.$item;
                   1368:                 $showpath = '/'.$currpath.'/'.$item.'/';
                   1369:             }
                   1370:             $currelem = $count+$startcount;
                   1371:             $$lastcontainerref = $currelem;
                   1372:             $children->{$parent->{$currdepth}} .= $currelem.':';
                   1373:             my $icon = 'src="'.$location.'/navmap.folder.open.gif" alt="'.&mt('Folder').'"';
                   1374:             $$displayref .= &Apache::loncommon::start_data_table_row().
                   1375:                             '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath).'" '.
                   1376:                             'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" '.
                   1377:                             $disabled.' /></td><td>';
                   1378:             for (my $i=0; $i<$currdepth; $i++) {
                   1379:                 $$displayref .= "$whitespace\n";
                   1380:             }
1.714     raeburn  1381:             $$displayref .= '<img '.$icon.' />&nbsp;'.$item.'</td><td>&nbsp;</td><td>&nbsp;</td>'.
1.712     raeburn  1382:                             &Apache::loncommon::end_data_table_row()."\n";
                   1383:             $count = &recurse_crsauthored($deeper,$dirs_by_depth,$files_by_depth,$newpath,
                   1384:                                           $startcount,$count,$displayref,$parent,$children,
1.714     raeburn  1385:                                           $readonly,$formname,$chkname,$lastcontainerref,$resfilesref);
1.712     raeburn  1386:         }
                   1387:         if ($hasfiles && exists($files{$item})) {
                   1388:             $count ++;
                   1389:             $currelem = $count+$startcount;
                   1390:             $children->{$parent->{$currdepth}} .= $currelem.':';
                   1391:             my $icon = 'src="'.&Apache::loncommon::icon($item).'"';
                   1392:             my ($ext) = ($item =~ /\.([^.]+)$/);
                   1393:             my $alttext;
                   1394:             if (lc($ext) eq 'problem') {
                   1395:                 $alttext = ' alt="'.&mt('Problem Icon').'"';
                   1396:             } elsif ($ext =~ /^x?html?$/i) {
                   1397:                 $alttext = ' alt="'.&mt('Web Page Icon').'"';
                   1398:             } elsif ($ext =~ /^(jpg|gif|png|svg|jpeg)$/) {
                   1399:                 $alttext = ' alt="'.&mt('Image Icon').'"';
                   1400:             } else {
                   1401:                 $alttext = ' alt="'.&mt('Resource Icon').'"';
                   1402:             }
                   1403:             my $showpath;
                   1404:             if ($currpath eq '/') {
                   1405:                 $showpath = $currpath;
                   1406:             } else {
                   1407:                 $showpath = "/$currpath/";
                   1408:             }
1.714     raeburn  1409:             my ($published,$lastmod);
                   1410:             if ((ref($resfilesref->{$currpath})) && (exists($resfilesref->{$currpath}{$item}))) {
                   1411:                 $published = '<img src="'.$location.'/navmap.correct.gif" alt="'.&mt('yes').'" />';
                   1412:             } else {
                   1413:                 $published = '<img src="'.$location.'/navmap.wrong.gif" alt="'.&mt('no').'" />';
                   1414:             }
1.712     raeburn  1415:             $$displayref .= &Apache::loncommon::start_data_table_row().
                   1416:                             '<td><input type="checkbox" name="'.$chkname.'" value="'.&escape($showpath.$item).'" '.
                   1417:                             'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" '.
                   1418:                             $disabled.' /></td><td>';
                   1419:             for (my $i=0; $i<$currdepth; $i++) {
                   1420:                 $$displayref .= "$whitespace\n";
                   1421:             }
                   1422:             $$displayref .= '<img '.$icon.$alttext.' />&nbsp;'.$item.'</td>'.
1.714     raeburn  1423:                             '<td>'.&Apache::lonlocal::locallocaltime($files{$item}).'</td>'.
                   1424:                             '<td style="text-align: center;">'.$published.'</td>'.
1.712     raeburn  1425:                             &Apache::loncommon::end_data_table_row()."\n";
                   1426:         }
                   1427:     }
                   1428:     $$lastcontainerref = $parent->{$currdepth};
                   1429:     return $count;
                   1430: }
                   1431: 
1.715     raeburn  1432: sub courseresource_options {
                   1433:     my ($formname,$numpub) = @_;
                   1434:     my %lt = &Apache::lonlocal::texthash(
                   1435:                                           'default' => 'System wide - can be used for any courses system wide',
                   1436:                                           'domain'  => 'Domain only - use limited to courses in the domain',
                   1437:                                           'custom'  => 'Customized right of use ...',
                   1438:                                           'public'  => 'Public - no authentication or authorization required for use',
                   1439:                                           'closed'  => 'Closed - XML source is closed to everyone',
                   1440:                                           'open'    => 'Open - XML source is open to people who want to use it',
                   1441:                                           'sel'     => 'Select',
                   1442:                                         );
                   1443:     my $output;
                   1444:     if ($numpub) {
                   1445:         $output .= '<div class="LC_left_float">'.
                   1446:                    '<fieldset><legend>'.&mt('Published Resources').'</legend>'.
                   1447:                    &mt('[quant,_1,file] in Course Authoring Space also exist in Resource Space.',
                   1448:                        $numpub).'</br />'.
                   1449:                    &mt('Publish copied files in selected Authoring Space?').': '."\n".
                   1450:                    '<label><input type="radio" name="respublish" checked="checked" value="1" />'.
                   1451:                    &mt('Yes').'</label>'."\n".
                   1452:                    '<label><input type="radio" name="respublish" value="0" />'.
                   1453:                    &mt('No').'</label>'."\n".
                   1454:                    '</fieldset></div>'."\n";
                   1455:     }
                   1456:     $output .= '<div class="LC_left_float">'.
                   1457:                '<fieldset><legend>'.&mt('Distribution to set in metadata').'</legend>'.
                   1458:                &mt('Copyright').': '.
                   1459:                '<select name="copyright" onchange="showHideCustom(this,'."'LC_customfile'".');">'."\n".
                   1460:                '<option value="default" selected="selected">'.$lt{'default'}.'</option>'."\n".
                   1461:                '<option value="domain">'.$lt{'domain'}.'</option>'."\n".
                   1462:                '<option value="public">'.$lt{'public'}.'</option>'."\n".
                   1463:                '<option value="custom">'.$lt{'custom'}.'</option>'."\n".
                   1464:                '</select><div id="LC_customfile" style="padding:0;clear:both;margin:0;border:0;display:none">'."\n".
                   1465:                '<input type="text" name="customrights" size="60" value="" />'.
                   1466:                '<a href="javascript:openbrowser('."'$formname','customrights','rights'".');">'.
                   1467:                $lt{'sel'}.'</a></div><br />'."\n".
                   1468:                &mt('Source').' :'.
                   1469:                '<select name="sourceavail">'."\n".
                   1470:                '<option value="closed" selected="selected">'.$lt{'closed'}.'</option>'."\n".
                   1471:                '<option value="open">'.$lt{'open'}.'</option>'."\n".
                   1472:                '</select><br />'."\n".
                   1473:                '</fieldset></div>'."\n";
                   1474:     return $output;
                   1475: }
                   1476: 
1.717     raeburn  1477: sub crsres_fixup_meta {
                   1478:     my ($dest,$coursenum,$coursedom,$ca,$cd,$copyright,$customdistfile,$sourceavail,$checkdeps) = @_;
                   1479:     return unless (ref($checkdeps) eq 'HASH');
                   1480:     if (open(my $fh,'<',$dest.'.meta')) {
                   1481:         my ($output,$now,$setsourceavail);
                   1482:         $now = time;
                   1483:         if (($dest =~ /\.(xml|html|htm|xhtml|xhtm)$/i) || ($dest =~ /$LONCAPA::assess_re/)) {
                   1484:             $setsourceavail = 1;
                   1485:         }
                   1486:         while (my $line=<$fh>) {
                   1487:             chomp($line);
                   1488:             if ($line eq "<authorspace>$coursenum:$coursedom</authorspace>") {
                   1489:                 $output .= "<authorspace>$ca:$cd</authorspace>\n";
                   1490:             } elsif ($line eq '<copyright>custom</copyright>') {
                   1491:                 $output .= "<copyright>$copyright</copyright>\n";
                   1492:             } elsif ($line =~ m{^<creationdate>\d+</creationdate>$}) {
                   1493:                 $output .= "<creationdate>$now</creationdate>\n";
                   1494:             } elsif ($line eq "<customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>") {
                   1495:                 $output .= "<customdistributionfile>$customdistfile</customdistributionfile>\n";
                   1496:             } elsif ($line =~ m{^<sourceavail>(open|closed)</sourceavail>$}) {
                   1497:                 if ($setsourceavail) {
                   1498:                     $output .= "<sourceavail>$sourceavail</sourceavail>\n";
                   1499:                 }
                   1500:             } elsif ($line eq "<domain>$coursedom</domain>") {
                   1501:                 $output .= "<domain>$cd</domain>\n";
                   1502:             } elsif ($line =~ m{^<lastrevisiondate>\d+</lastrevisiondate>$}) {
                   1503:                 $output .= "<lastrevisiondate>$now</lastrevisiondate>\n";
                   1504:             } elsif ($line =~ m{^<modifyinguser>$match_username:$match_domain</modifyinguser>$}) {
                   1505:                 $output .= "<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>\n";
                   1506:             } elsif ($line eq "<owner>$coursenum:$coursedom</owner>") {
                   1507:                 $output .= "<owner>$ca:$cd</owner>\n";
                   1508:             } elsif ($line =~ m{^<dependencies>(.+)</dependencies>$}) {
                   1509:                 my @deps = split(/\s*,\s*/,$1);
                   1510:                 my @newdeps;
                   1511:                 my $changed = 0;
                   1512:                 foreach my $dep (@deps) {
                   1513:                     if ($dep =~ m{^/res/$coursedom/$coursenum/(.+)$}) {
                   1514:                         my $rest = $1;
                   1515:                         push(@newdeps,"/res/$cd/$ca/$rest");
                   1516:                         $checkdeps->{$rest} = 1;
                   1517:                         $changed ++;
                   1518:                     } else {
                   1519:                         push(@newdeps,$dep);
                   1520:                     }
                   1521:                 }
                   1522:                 if ($changed) {
                   1523:                     $output .= '<dependencies>'.join(',',@newdeps).'</dependencies>'."\n";
                   1524:                 }
                   1525:             } else {
                   1526:                 $output .= "$line\n";
                   1527:             }
                   1528:         }
                   1529:         close($fh);
                   1530:         if (open(my $fh,'>',$dest.'.meta')) {
                   1531:             print $fh $output;
                   1532:             close($fh);
                   1533:         }
                   1534:     }
                   1535: }
                   1536: 
                   1537: sub crsres_fixup {
                   1538:     my ($dest,$coursenum,$coursedom,$ca,$cd,$subdir) = @_;
                   1539:     my $outstring='';
                   1540:     my $changes = 0;
                   1541:     my @parser;
                   1542:     $parser[0]=HTML::LCParser->new($dest);
                   1543:     $parser[-1]->xml_mode(1);
                   1544:     my $token;
                   1545:     while (@parser) {
                   1546:         while ($token=$parser[-1]->get_token) {
                   1547:             if ($token->[0] eq 'S') {
                   1548:                 my $tag=$token->[1];
                   1549:                 my $lctag=lc($tag);
                   1550:                 my %parms=%{$token->[2]};
                   1551:                 foreach my $type ('src','href','background','bgimg') {
                   1552:                     foreach my $key (keys(%parms)) {
                   1553:                         if ($key =~ /^$type$/i) {
                   1554:                             next if (($lctag eq 'img') && ($type eq 'src') &&
                   1555:                                      ($parms{$key} =~ m{^data\:image/gif;base64,}));
                   1556:                             if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1557:                                 $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
                   1558:                                 $changes ++;
                   1559:                             }
                   1560:                         }
                   1561:                     }
                   1562:                 }
                   1563:                 # probably a <randomlabel> image type <label>
                   1564:                 # or a <image> tag inside <imageresponse> or <drawimage>
                   1565:                 if (($lctag eq 'label' && defined($parms{'description'}))
                   1566:                     || ($lctag eq 'image') || ($lctag eq 'import')) {
                   1567:                     my $next_token=$parser[-1]->get_token();
                   1568:                     if ($next_token->[0] eq 'T') {
                   1569:                         $next_token->[1] =~ s/[\n\r\f]+//g;
                   1570:                         if ($next_token->[1] =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1571:                             $next_token->[1] =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
                   1572:                             $changes ++;
                   1573:                         }
                   1574:                     }
                   1575:                     $parser[-1]->unget_token($next_token);
                   1576:                 }
                   1577:                 if ($lctag eq 'applet') {
                   1578:                     my $havecodebase=0;
                   1579:                     foreach my $key (keys(%parms)) {
                   1580:                         if (lc($key) eq 'codebase') {
                   1581:                             if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1582:                                 $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/}si;
                   1583:                                 $changes ++;
                   1584:                             }
                   1585:                             $havecodebase = 1;
                   1586:                         }
                   1587:                     }
                   1588:                     unless ($havecodebase) {
                   1589:                         foreach my $key (keys(%parms)) {
                   1590:                             if ($key =~ /(archive|code|object)/i) {
                   1591:                                 if ($parms{$key} =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1592:                                     $parms{$key} =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/si};
                   1593:                                     $changes ++;
                   1594:                                 }
                   1595:                             }
                   1596:                         }
                   1597:                     }
                   1598:                 }
                   1599:                 my $newparmstring='';
                   1600:                 my $endtag='';
                   1601:                 foreach my $parkey (keys(%parms)) {
                   1602:                     if ($parkey eq '/') {
                   1603:                         $endtag=' /';
                   1604:                     } else {
                   1605:                         my $quote=($parms{$parkey}=~/\"/?"'":'"');
                   1606:                         $newparmstring.=' '.$parkey.'='.$quote.$parms{$parkey}.$quote;
                   1607:                     }
                   1608:                 }
                   1609:                 if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
                   1610:                 $outstring.='<'.$tag.$newparmstring.$endtag.'>';
                   1611:                 if ($lctag eq 'm' || $lctag eq 'answer' || $lctag eq 'display' ||
                   1612:                     $lctag eq 'tex') {
                   1613:                     $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
                   1614:                 } elsif ($lctag eq 'script') {
                   1615:                     if ($parms{'type'} eq 'loncapa/perl') {
                   1616:                         $outstring.=&Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
                   1617:                     } else {
                   1618:                         my $needsupdate;
                   1619:                         my $script = &Apache::lonxml::get_all_text_unbalanced('/'.$lctag,\@parser);
                   1620:                         if ($script =~ m{\.addMediaSrc\((["'])((?!\1).+)\1\);}) {
                   1621:                             my $src = $2;
                   1622:                             if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1623:                                 $needsupdate = 1;
                   1624:                             }
                   1625:                         }
                   1626:                         if ($script =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) {
                   1627:                             my $scriptslist = $2;
                   1628:                             my @srcs = split(/\s*,\s*/,$scriptslist);
                   1629:                             foreach my $src (@srcs) {
                   1630:                                 if ($src =~ /(["'])(?:(?!\1).)+\.js\1/) {
                   1631:                                     my $quote = $1;
                   1632:                                     my ($url) = ($src =~ m/\Q$quote\E([^$quote]+)\Q$quote\E/);
                   1633:                                     if ($url =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1634:                                         $needsupdate = 1;
                   1635:                                     }
                   1636:                                 }
                   1637:                             }
                   1638:                         }
                   1639:                         if ($script =~ m{loadScript\(\s*(['"])((?:(?!\1).)+\.js)\1,\s*function}is) {
                   1640:                             my $src = $2;
                   1641:                             if ($src =~ m{^\Q/res/$coursedom/$coursenum/\E}si) {
                   1642:                                 $needsupdate = 1;
                   1643:                             }
                   1644:                         }
                   1645:                         if ($needsupdate) {
                   1646:                             $script =~ s{^\Q/res/$coursedom/$coursenum/\E}{/res/$cd/$ca/$subdir/gsi};
                   1647:                             $changes ++;
                   1648:                         }
                   1649:                         $outstring .= $script;
                   1650:                     }
                   1651:                 }
                   1652:             } elsif ($token->[0] eq 'E') {
                   1653:                 if ($token->[2]) {
                   1654:                     unless ($token->[1] eq 'allow') {
                   1655:                         $outstring.='</'.$token->[1].'>';
                   1656:                     }
                   1657:                 }
                   1658:             } else {
                   1659:                 $outstring.=$token->[1];
                   1660:             }
                   1661:         }
                   1662:         pop(@parser);
                   1663:     }
                   1664:     if ($changes) {
                   1665:         if (open(my $fh,'>',$dest)) {
                   1666:             print $fh $outstring;
                   1667:             close($fh);
                   1668:         }
                   1669:     }
                   1670: }
                   1671: 
1.329     droeschl 1672: sub group_import {
1.598     raeburn  1673:     my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529     raeburn  1674:     my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
                   1675:         %removeparam,$importuploaded,$fixuperrors);
                   1676:     $allmaps = {};
1.329     droeschl 1677:     while (@files) {
                   1678: 	my ($name, $url, $residx) = @{ shift(@files) };
1.344     bisitz   1679:         if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329     droeschl 1680: 	     && ($caller eq 'londocs')
                   1681: 	     && (!&Apache::lonnet::stat_file($url))) {
1.364     bisitz   1682: 
1.329     droeschl 1683:             my $errtext = '';
                   1684:             my $fatal = 0;
                   1685:             my $newmapstr = '<map>'."\n".
                   1686:                             '<resource id="1" src="" type="start"></resource>'."\n".
                   1687:                             '<link from="1" to="2" index="1"></link>'."\n".
                   1688:                             '<resource id="2" src="" type="finish"></resource>'."\n".
                   1689:                             '</map>';
                   1690:             $env{'form.output'}=$newmapstr;
                   1691:             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                   1692:                                                 'output',$1.$2);
1.534     raeburn  1693:             if ($result !~ m{^/uploaded/}) {
1.329     droeschl 1694:                 $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
                   1695:                 $fatal = 2;
                   1696:             }
                   1697:             if ($fatal) {
                   1698:                 return ($errtext,$fatal);
                   1699:             }
                   1700:         }
                   1701: 	if ($url) {
1.626     raeburn  1702:             if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598     raeburn  1703:                 $url = $1;
                   1704:                 my $marker = $2;
                   1705:                 my $info = $3;
1.699     raeburn  1706:                 my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642     raeburn  1707:                 my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598     raeburn  1708:                 my @toolinfo = split(/:/,$info);
                   1709:                 if ($residx) {
1.604     raeburn  1710:                     %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598     raeburn  1711:                     $toolid = $toolsettings{'id'};
                   1712:                 } else {
1.604     raeburn  1713:                     $toolid = shift(@toolinfo);
1.598     raeburn  1714:                 }
1.699     raeburn  1715:                 if ($toolid =~ /^c/) {
                   1716:                     $tooltype = 'crs';
                   1717:                     $toolprefix = 'c';
                   1718:                 } else {
                   1719:                     $tooltype = 'dom';
                   1720:                 }
1.598     raeburn  1721:                 $toolid =~ s/\D//g;
1.604     raeburn  1722:                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645     raeburn  1723:                  $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
                   1724:                  $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624     raeburn  1725:                 foreach my $item (@extras) {
                   1726:                     $toolhash{$item} = &unescape($toolhash{$item});
                   1727:                 }
1.645     raeburn  1728:                 if ($folder =~ /^supplemental/) {
1.648     raeburn  1729:                     delete($toolhash{'gradable'});
                   1730:                 } else {
                   1731:                     $toolhash{'gradable'} =~ s/\D+//g;
1.645     raeburn  1732:                 }
1.598     raeburn  1733:                 if (ref($ltitoolsref) eq 'HASH') {
1.699     raeburn  1734:                     if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
                   1735:                         if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
                   1736:                             my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
                   1737:                             my @deleted;
                   1738:                             $toolhash{'id'} = $toolprefix.$toolid;
                   1739:                             if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
                   1740:                                 ($toolhash{'target'} eq 'window')) {
                   1741:                                 if ($toolhash{'target'} eq 'window') {
                   1742:                                     foreach my $item ('width','height') {
                   1743:                                         $toolhash{$item} =~ s/^\s+//;
                   1744:                                         $toolhash{$item} =~ s/\s+$//;
                   1745:                                         if ($toolhash{$item} =~ /\D/) {
                   1746:                                             delete($toolhash{$item});
                   1747:                                             if ($residx) {
                   1748:                                                 if ($toolsettings{$item}) {
                   1749:                                                     push(@deleted,$item);
                   1750:                                                 }
1.624     raeburn  1751:                                             }
                   1752:                                         }
                   1753:                                     }
1.604     raeburn  1754:                                 }
1.699     raeburn  1755:                             } elsif ($residx) {
                   1756:                                 $toolhash{'target'} = $toolsettings{'target'};
                   1757:                                 if ($toolhash{'target'} eq 'window') {
                   1758:                                     foreach my $item ('width','height') {
                   1759:                                         $toolhash{$item} = $toolsettings{$item};
                   1760:                                     }
                   1761:                                 }
                   1762:                             } elsif (ref($tools{'display'}) eq 'HASH') {
                   1763:                                 $toolhash{'target'} = $tools{'display'}{'target'};
                   1764:                                 if ($toolhash{'target'} eq 'window') {
                   1765:                                     $toolhash{'width'} = $tools{'display'}{'width'};
                   1766:                                     $toolhash{'height'} = $tools{'display'}{'height'};
1.624     raeburn  1767:                                 }
1.604     raeburn  1768:                             }
1.699     raeburn  1769:                             if ($toolhash{'target'} eq 'iframe') {
                   1770:                                 foreach my $item ('width','height','linktext','explanation') {
                   1771:                                     delete($toolhash{$item});
                   1772:                                     if ($residx) {
                   1773:                                         if ($toolsettings{$item}) {
                   1774:                                             push(@deleted,$item);
                   1775:                                         }
1.624     raeburn  1776:                                     }
1.604     raeburn  1777:                                 }
1.699     raeburn  1778:                             } elsif ($toolhash{'target'} eq 'tab') {
                   1779:                                 foreach my $item ('width','height') {
                   1780:                                     delete($toolhash{$item});
                   1781:                                     if ($residx) {
                   1782:                                         if ($toolsettings{$item}) {
                   1783:                                             push(@deleted,$item);
                   1784:                                         }
1.628     raeburn  1785:                                     }
                   1786:                                 }
                   1787:                             }
1.699     raeburn  1788:                             if (ref($tools{'crsconf'}) eq 'HASH') {
                   1789:                                 foreach my $item ('label','title','linktext','explanation') {
                   1790:                                     my $crsitem;
                   1791:                                     if (($item eq 'label') || ($item eq 'title')) {
                   1792:                                         $crsitem = 'crs'.$item;
                   1793:                                     } else {
                   1794:                                         $crsitem = $item;
                   1795:                                     }
                   1796:                                     if ($tools{'crsconf'}{$item}) {
                   1797:                                         $toolhash{$crsitem} =~ s/^\s+//;
                   1798:                                         $toolhash{$crsitem} =~ s/\s+$//;
                   1799:                                         if ($toolhash{$crsitem} eq '') {
                   1800:                                             delete($toolhash{$crsitem});
                   1801:                                         }
                   1802:                                     } else {
1.624     raeburn  1803:                                         delete($toolhash{$crsitem});
1.604     raeburn  1804:                                     }
1.699     raeburn  1805:                                     if (($residx) && (exists($toolsettings{$crsitem}))) {
                   1806:                                         unless (exists($toolhash{$crsitem})) {
                   1807:                                             push(@deleted,$crsitem);
                   1808:                                         }
                   1809:                                     }
1.604     raeburn  1810:                                 }
1.699     raeburn  1811:                             }
                   1812:                             if ($toolhash{'passback'}) {
                   1813:                                 my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                   1814:                                 $toolhash{'gradesecret'} = $gradesecret;
                   1815:                                 $toolhash{'gradesecretdate'} = time;
                   1816:                             }
                   1817:                             if ($toolhash{'roster'}) {
                   1818:                                 my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                   1819:                                 $toolhash{'rostersecret'} = $rostersecret;
                   1820:                                 $toolhash{'rostersecretdate'} = time;
                   1821:                             }
                   1822:                             my $changegradable;
                   1823:                             if (($residx) && ($folder =~ /^default/)) {
                   1824:                                 if ($toolsettings{'gradable'}) {
                   1825:                                     unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
                   1826:                                         push(@deleted,'gradable');
                   1827:                                         $changegradable = 1;
1.604     raeburn  1828:                                     }
1.699     raeburn  1829:                                 } elsif ($toolhash{'gradable'}) {
                   1830:                                     $changegradable = 1;
1.604     raeburn  1831:                                 }
1.699     raeburn  1832:                                 if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645     raeburn  1833:                                     $changegradable = 1;
1.699     raeburn  1834:                                     if ($toolsettings{'gradable'}) {
                   1835:                                         $toolhash{'gradable'} = 1;
                   1836:                                     }
1.645     raeburn  1837:                                 }
1.648     raeburn  1838:                             }
1.699     raeburn  1839:                             my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
                   1840:                             if ($putres eq 'ok') {
                   1841:                                 if (@deleted) {
                   1842:                                     &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648     raeburn  1843:                                 }
1.699     raeburn  1844:                                 if (($changegradable) && ($folder =~ /^default/)) {
                   1845:                                     my $val;
                   1846:                                     if ($toolhash{'gradable'}) {
                   1847:                                         $val = 'yes';
                   1848:                                     } else {
                   1849:                                         $val = 'no';
                   1850:                                     }
                   1851:                                     &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
                   1852:                                                                   'string_yesno');
                   1853:                                     &remember_parms($residx,'gradable','set',$val);
1.645     raeburn  1854:                                 }
1.699     raeburn  1855:                             } else {
                   1856:                                 return (&mt('Failed to save update to external tool.'),1);
1.645     raeburn  1857:                             }
1.604     raeburn  1858:                         }
1.598     raeburn  1859:                     }
                   1860:                 }
                   1861:             }
1.529     raeburn  1862:             if (($caller eq 'londocs') &&
                   1863:                 ($folder =~ /^default/)) {
1.534     raeburn  1864:                 if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529     raeburn  1865:                     my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
                   1866:                     my $cid = $coursedom.'_'.$coursenum;
                   1867:                     $allmaps =
                   1868:                         &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                   1869:                                                              $chome,$cid);
                   1870:                     $donechk = 1;
                   1871:                 }
                   1872:                 if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627     raeburn  1873:                     &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
                   1874:                                         \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529     raeburn  1875:                     $importuploaded = 1;
                   1876:                 } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
                   1877:                     next if ($allmaps->{$url});
                   1878:                 }
                   1879:             }
1.344     bisitz   1880: 	    if (!$residx
1.329     droeschl 1881: 		|| defined($LONCAPA::map::zombies[$residx])) {
                   1882: 		$residx = &LONCAPA::map::getresidx($url,$residx);
                   1883: 		push(@LONCAPA::map::order, $residx);
                   1884: 	    }
                   1885: 	    my $ext = 'false';
                   1886: 	    if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534     raeburn  1887:             if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
                   1888:                 my $filepath = $1;
1.675     raeburn  1889:                 my $fname;
                   1890:                 if ($name eq '') {
                   1891:                     $name = &mt('Web Page');
1.534     raeburn  1892:                     $fname = 'web';
                   1893:                 } else {
1.675     raeburn  1894:                     $fname = $name;
                   1895:                     $fname=&Apache::lonnet::clean_filename($fname);
                   1896:                     if ($fname eq '') {
                   1897:                         $fname = 'web';
                   1898:                     } elsif (length($fname) > 15) {
                   1899:                         $fname = substr($fname,0,14);
                   1900:                     }
1.534     raeburn  1901:                 }
1.675     raeburn  1902:                 my $title = &Apache::loncommon::cleanup_html($name);
1.534     raeburn  1903:                 my $initialtext = &mt('Replace with your own content.');
                   1904:                 my $newhtml = <<END;
1.545     raeburn  1905: <html>
1.534     raeburn  1906: <head>
1.675     raeburn  1907: <title>$title</title>
1.534     raeburn  1908: </head>
                   1909: <body bgcolor="#ffffff">
                   1910: $initialtext
                   1911: </body>
                   1912: </html>
                   1913: END
                   1914:                 $env{'form.output'}=$newhtml;
1.630     raeburn  1915:                 my $result =
1.534     raeburn  1916:                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                   1917:                                                           'output',
                   1918:                                                           "$filepath/$residx/$fname.html");
                   1919:                 if ($result =~ m{^/uploaded/}) {
                   1920:                     $url = $result;
                   1921:                     if ($filepath =~ /^supplemental/) {
                   1922:                         $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   1923:                                 $env{'user.domain'}.'___&&&___'.$name;
                   1924:                     }
                   1925:                 } else {
                   1926:                     return (&mt('Failed to save new web page.'),1);
                   1927:                 }
                   1928:             }
1.675     raeburn  1929:             $name = &LONCAPA::map::qtunescape($name);
1.538     raeburn  1930:             $url  = &LONCAPA::map::qtunescape($url);
1.344     bisitz   1931: 	    $LONCAPA::map::resources[$residx] =
1.329     droeschl 1932: 		join(':', ($name, $url, $ext, 'normal', 'res'));
                   1933: 	}
                   1934:     }
1.529     raeburn  1935:     if ($importuploaded) {
                   1936:         my %import_errors;
                   1937:         my %updated = (
                   1938:                           removefrommap => \%removefrommap,
                   1939:                           removeparam   => \%removeparam,
                   1940:                       );
1.533     raeburn  1941:         my ($result,$msgsarray,$lockerror) = 
                   1942:             &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529     raeburn  1943:         if (keys(%import_errors) > 0) {
1.530     raeburn  1944:             $fixuperrors =
1.529     raeburn  1945:                 '<p span class="LC_warning">'."\n".
                   1946:                 &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".
                   1947:                 '<ul>'."\n";
                   1948:             foreach my $key (sort(keys(%import_errors))) {
                   1949:                 $fixuperrors .= '<li>'.$key.'</li>'."\n";
                   1950:             }
                   1951:             $fixuperrors .= '</ul></p>'."\n";
                   1952:         }
1.533     raeburn  1953:         if (ref($msgsarray) eq 'ARRAY') {
                   1954:             if (@{$msgsarray} > 0) {
                   1955:                 $fixuperrors .= '<p class="LC_info">'.
                   1956:                                 join('<br />',@{$msgsarray}).
                   1957:                                 '</p>';
                   1958:             }
                   1959:         }
                   1960:         if ($lockerror) {
                   1961:             $fixuperrors .= '<p class="LC_error">'.
                   1962:                             $lockerror.
                   1963:                             '</p>';
                   1964:         }
1.529     raeburn  1965:     }
                   1966:     my ($errtext,$fatal) =
                   1967:         &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557     raeburn  1968:     unless ($fatal) {
                   1969:         if ($folder =~ /^supplemental/) {
1.561     raeburn  1970:             my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   1971:                                             $folder.'.'.$container);
1.557     raeburn  1972:         }
                   1973:     }
1.529     raeburn  1974:     return ($errtext,$fatal,$fixuperrors);
1.329     droeschl 1975: }
                   1976: 
                   1977: sub log_docs {
1.494     raeburn  1978:     return &Apache::lonnet::write_log('course','docslog',@_);
1.329     droeschl 1979: }
                   1980: 
                   1981: {
                   1982:     my @oldresources=();
                   1983:     my @oldorder=();
                   1984:     my $parmidx;
                   1985:     my %parmaction=();
                   1986:     my %parmvalue=();
                   1987:     my $changedflag;
                   1988: 
                   1989:     sub snapshotbefore {
                   1990:         @oldresources=@LONCAPA::map::resources;
                   1991:         @oldorder=@LONCAPA::map::order;
                   1992:         $parmidx=undef;
                   1993:         %parmaction=();
                   1994:         %parmvalue=();
                   1995:         $changedflag=0;
                   1996:     }
                   1997: 
                   1998:     sub remember_parms {
                   1999:         my ($idx,$parameter,$action,$value)=@_;
                   2000:         $parmidx=$idx;
                   2001:         $parmaction{$parameter}=$action;
                   2002:         $parmvalue{$parameter}=$value;
                   2003:         $changedflag=1;
                   2004:     }
                   2005: 
                   2006:     sub log_differences {
                   2007:         my ($plain)=@_;
                   2008:         my %storehash=('folder' => $plain,
                   2009:                        'currentfolder' => $env{'form.folder'});
                   2010:         if ($parmidx) {
                   2011:            $storehash{'parameter_res'}=$oldresources[$parmidx];
                   2012:            foreach my $parm (keys(%parmaction)) {
                   2013:               $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
                   2014:               $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
                   2015:            }
                   2016:         }
                   2017:         my $maxidx=$#oldresources;
                   2018:         if ($#LONCAPA::map::resources>$#oldresources) {
                   2019:            $maxidx=$#LONCAPA::map::resources;
                   2020:         }
                   2021:         for (my $idx=0; $idx<=$maxidx; $idx++) {
                   2022:            if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
                   2023:               $storehash{'before_resources_'.$idx}=$oldresources[$idx];
                   2024:               $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
                   2025:               $changedflag=1;
                   2026:            }
                   2027:            if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
                   2028:               $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
                   2029:               $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                   2030:               $changedflag=1;
                   2031:            }
                   2032:         }
                   2033: 	$storehash{'maxidx'}=$maxidx;
                   2034:         if ($changedflag) { &log_docs(\%storehash); }
                   2035:     }
                   2036: }
                   2037: 
                   2038: sub docs_change_log {
1.611     raeburn  2039:     my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486     raeburn  2040:     my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617     raeburn  2041:     my $navmap; 
1.483     raeburn  2042:     my $js = '<script type="text/javascript">'."\n".
                   2043:              '// <![CDATA['."\n".
                   2044:              &Apache::loncommon::display_filter_js('docslog')."\n".
1.606     raeburn  2045:              &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622     raeburn  2046:                          $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483     raeburn  2047:              &history_tab_js()."\n".
1.484     raeburn  2048:              &Apache::lonratedt::editscript('simple')."\n".
1.483     raeburn  2049:              '// ]]>'."\n".
                   2050:              '</script>'."\n";
1.484     raeburn  2051:     $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
                   2052:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489     raeburn  2053:     $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484     raeburn  2054:     my %orderhash;
                   2055:     my $container='sequence';
                   2056:     my $pathitem;
1.519     raeburn  2057:     if ($env{'form.folderpath'} =~ /\:1$/) {
1.484     raeburn  2058:         $container='page';
                   2059:     }
1.519     raeburn  2060:     my $folderpath=$env{'form.folderpath'};
                   2061:     if ($folderpath eq '') {
1.617     raeburn  2062:         $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519     raeburn  2063:     }
1.617     raeburn  2064:     undef($navmap);
1.519     raeburn  2065:     $pathitem = '<input type="hidden" name="folderpath" value="'.
                   2066:                 &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484     raeburn  2067:     my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
                   2068:     my $jumpto = $readfile;
                   2069:     $jumpto =~ s{^/}{};
                   2070:     my $tid = 1;
1.489     raeburn  2071:     if ($supplementalflag) {
                   2072:         $tid = 2;
                   2073:     }
1.630     raeburn  2074:     my ($breadcrumbtrail) =
1.509     raeburn  2075:         &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484     raeburn  2076:     $r->print($breadcrumbtrail.
                   2077:               &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
                   2078:               $readfile));
1.329     droeschl 2079:     my %docslog=&Apache::lonnet::dump('nohist_docslog',
                   2080:                                       $env{'course.'.$env{'request.course.id'}.'.domain'},
                   2081:                                       $env{'course.'.$env{'request.course.id'}.'.num'});
                   2082: 
                   2083:     if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
                   2084: 
                   2085:     my %saveable_parameters = ('show' => 'scalar',);
                   2086:     &Apache::loncommon::store_course_settings('docs_log',
                   2087:                                               \%saveable_parameters);
                   2088:     &Apache::loncommon::restore_course_settings('docs_log',
                   2089:                                                 \%saveable_parameters);
                   2090:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452     www      2091: # FIXME: internationalization seems wrong here
1.329     droeschl 2092:     my %lt=('hiddenresource' => 'Resources hidden',
                   2093: 	    'encrypturl'     => 'URL hidden',
                   2094: 	    'randompick'     => 'Randomly pick',
                   2095: 	    'randomorder'    => 'Randomly ordered',
1.645     raeburn  2096:             'gradable'       => 'Grade can be assigned to External Tool',
1.329     droeschl 2097: 	    'set'            => 'set to',
                   2098: 	    'del'            => 'deleted');
1.484     raeburn  2099:     my $filter = &Apache::loncommon::display_filter('docslog')."\n".
                   2100:                  $pathitem."\n".
                   2101:                  '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
                   2102:                  ('&nbsp;'x2).'<input type="submit" value="'.&mt('Display').'" />';
                   2103:     $r->print('<div class="LC_left_float">'.
                   2104:               '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
                   2105:               &makedocslogform($filter,1).
                   2106:               '</fieldset></div><br clear="all" />');
1.329     droeschl 2107:     $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
                   2108:               '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
                   2109:               &mt('After').'</th>'.
                   2110:               &Apache::loncommon::end_data_table_header_row());
                   2111:     my $shown=0;
                   2112:     foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
                   2113: 	if ($env{'form.displayfilter'} eq 'currentfolder') {
                   2114: 	    if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
                   2115: 	}
                   2116:         my @changes=keys(%{$docslog{$id}{'logentry'}});
                   2117:         if ($env{'form.displayfilter'} eq 'containing') {
                   2118: 	    my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
                   2119: 		&Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
                   2120: 	    foreach my $key (@changes) {
                   2121: 		$wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
                   2122: 	    }
1.344     bisitz   2123: 	    if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329     droeschl 2124: 	}
                   2125:         my $count = 0;
                   2126:         my $time =
                   2127:             &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
                   2128:         my $plainname =
                   2129:             &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
                   2130:                                           $docslog{$id}{'exe_udom'});
                   2131:         my $about_me_link =
                   2132:             &Apache::loncommon::aboutmewrapper($plainname,
                   2133:                                                $docslog{$id}{'exe_uname'},
                   2134:                                                $docslog{$id}{'exe_udom'});
                   2135:         my $send_msg_link='';
                   2136:         if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
                   2137:              || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
                   2138:             $send_msg_link ='<br />'.
                   2139:                 &Apache::loncommon::messagewrapper(&mt('Send message'),
                   2140:                                                    $docslog{$id}{'exe_uname'},
                   2141:                                                    $docslog{$id}{'exe_udom'});
                   2142:         }
                   2143:         $r->print(&Apache::loncommon::start_data_table_row());
                   2144:         $r->print('<td>'.$time.'</td>
                   2145:                        <td>'.$about_me_link.
                   2146:                   '<br /><tt>'.$docslog{$id}{'exe_uname'}.
                   2147:                                   ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
                   2148:                   $send_msg_link.'</td><td>'.
                   2149:                   $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488     raeburn  2150:         my $is_supp = 0; 
                   2151:         if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
                   2152:             $is_supp = 1;
                   2153:         }
1.329     droeschl 2154: # Before
                   2155: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   2156: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                   2157: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                   2158: 	    if ($oldname ne $newname) {
1.488     raeburn  2159:                 my $shown = &LONCAPA::map::qtescape($oldname);
                   2160:                 if ($is_supp) {
                   2161:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   2162:                 }
                   2163:                 $r->print($shown);
1.329     droeschl 2164: 	    }
                   2165: 	}
                   2166: 	$r->print('<ul>');
                   2167: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   2168:             if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488     raeburn  2169:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
                   2170:                 if ($is_supp) {
                   2171:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   2172:                 }
                   2173: 		$r->print('<li>'.$shown.'</li>');
1.329     droeschl 2174: 	    }
                   2175: 	}
                   2176: 	$r->print('</ul>');
                   2177: # After
                   2178:         $r->print('</td><td>');
                   2179: 
                   2180: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   2181: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                   2182: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                   2183: 	    if ($oldname ne '' && $oldname ne $newname) {
1.488     raeburn  2184:                 my $shown = &LONCAPA::map::qtescape($newname);
                   2185:                 if ($is_supp) {
                   2186:                     $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
                   2187:                 }
                   2188:                 $r->print($shown);
1.329     droeschl 2189: 	    }
1.364     bisitz   2190: 	}
1.329     droeschl 2191: 	$r->print('<ul>');
                   2192: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   2193:             if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488     raeburn  2194:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
                   2195:                 if ($is_supp) {
                   2196:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   2197:                 }
                   2198:                 $r->print('<li>'.$shown.'</li>');
1.329     droeschl 2199: 	    }
                   2200: 	}
                   2201: 	$r->print('</ul>');
                   2202: 	if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693     raeburn  2203:             my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
                   2204:             if ($title eq '') {
                   2205:                 ($title) = ($url =~ m{/([^/]+)$});
1.695     raeburn  2206:             } elsif ($is_supp) {
                   2207:                 $title = &Apache::loncommon::parse_supplemental_title($title);
1.693     raeburn  2208:             }
                   2209:             $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645     raeburn  2210: 	    foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329     droeschl 2211: 		if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452     www      2212: # FIXME: internationalization seems wrong here
1.329     droeschl 2213: 		    $r->print('<li>'.
                   2214: 			      &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
                   2215: 				  $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
                   2216: 			      .'</li>');
                   2217: 		}
                   2218: 	    }
                   2219: 	    $r->print('</ul>');
                   2220: 	}
                   2221: # End
                   2222:         $r->print('</td>'.&Apache::loncommon::end_data_table_row());
                   2223:         $shown++;
                   2224:         if (!($env{'form.show'} eq &mt('all')
                   2225:               || $shown<=$env{'form.show'})) { last; }
                   2226:     }
1.484     raeburn  2227:     $r->print(&Apache::loncommon::end_data_table()."\n".
                   2228:               &makesimpleeditform($pathitem)."\n".
                   2229:               '</div></div>');
                   2230:     $r->print(&endContentScreen());
1.329     droeschl 2231: }
                   2232: 
                   2233: sub update_paste_buffer {
1.492     raeburn  2234:     my ($coursenum,$coursedom,$folder) = @_;
1.591     raeburn  2235:     my (@possibles,%removals,%cuts,$output);
1.538     raeburn  2236:     if ($env{'form.multiremove'}) {
                   2237:         $env{'form.multiremove'} =~ s/,$//;
                   2238:         map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
                   2239:     }
                   2240:     if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
                   2241:         if ($env{'form.multicut'}) {
                   2242:             $env{'form.multicut'} =~ s/,$//;
                   2243:             foreach my $item (split(/,/,$env{'form.multicut'})) {
                   2244:                 unless ($removals{$item}) {
                   2245:                     $cuts{$item} = 1;
                   2246:                     push(@possibles,$item.':cut');
                   2247:                 }
                   2248:             }
                   2249:         }
                   2250:         if ($env{'form.multicopy'}) {
                   2251:             $env{'form.multicopy'} =~ s/,$//;
                   2252:             foreach my $item (split(/,/,$env{'form.multicopy'})) {
                   2253:                 unless ($removals{$item} || $cuts{$item}) {
                   2254:                     push(@possibles,$item.':copy'); 
                   2255:                 }
                   2256:             }
                   2257:         }
                   2258:     } elsif ($env{'form.markcopy'}) {
                   2259:         @possibles = split(/,/,$env{'form.markcopy'});
                   2260:     }
1.329     droeschl 2261: 
1.538     raeburn  2262:     return if (@possibles == 0);
1.329     droeschl 2263:     return if (!defined($env{'form.copyfolder'}));
                   2264: 
                   2265:     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   2266: 				    $env{'form.copyfolder'});
1.538     raeburn  2267:     return if ($fatal);
                   2268: 
                   2269:     my %curr_groups = &Apache::longroup::coursegroups();
1.364     bisitz   2270: 
1.538     raeburn  2271: # Retrieve current paste buffer suffixes.
                   2272:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   2273:     my (%pasteurls,@newpaste);
                   2274: 
                   2275: # Construct identifiers for current contents of user's paste buffer
                   2276:     if (@currpaste) {
                   2277:         foreach my $suffix (@currpaste) {
1.667     raeburn  2278:             my $cid = $env{'docs.markedcopy_crs_'.$suffix};
                   2279:             my $url = $env{'docs.markedcopy_url_'.$suffix};
                   2280:             my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
                   2281:             if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
                   2282:                 ($url ne '')) {
                   2283:                 if ($url eq '/res/lib/templates/simpleproblem.problem') {
                   2284:                     $pasteurls{$cid.'_'.$mapidx} = 1;
                   2285:                 } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
                   2286:                     $pasteurls{$url} = 1;
                   2287:                 } else {
1.669     raeburn  2288:                     $pasteurls{$cid.'_'.$url} = 1;
1.667     raeburn  2289:                 }
                   2290:             }
1.538     raeburn  2291:         }
                   2292:     }
                   2293: 
                   2294: # Mark items for copying (skip any items already in user's paste buffer)
                   2295:     my %addtoenv;
1.597     raeburn  2296: 
                   2297:     my @pathitems = split(/\&/,$env{'form.folderpath'});
                   2298:     my @folderconf = split(/\:/,$pathitems[-1]);
1.666     raeburn  2299:     my $ispage = $folderconf[5];
1.597     raeburn  2300: 
1.538     raeburn  2301:     foreach my $item (@possibles) {
                   2302:         my ($orderidx,$cmd) = split(/:/,$item);
                   2303:         next if ($orderidx =~ /\D/);
                   2304:         next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597     raeburn  2305:         my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538     raeburn  2306:         my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
                   2307:         my %denied = &action_restrictions($coursenum,$coursedom,
                   2308:                                           &LONCAPA::map::qtescape($url),
                   2309:                                           $env{'form.folderpath'},\%curr_groups);
                   2310:         next if ($denied{'copy'});
                   2311:         $url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.667     raeburn  2312:         if ($url eq '/res/lib/templates/simpleproblem.problem') {
                   2313:             next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
                   2314:         } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
                   2315:             next if (exists($pasteurls{$url}));
                   2316:         } else {
                   2317:             next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
                   2318:         }
1.538     raeburn  2319:         my ($suffix,$errortxt,$locknotfreed) =
                   2320:             &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591     raeburn  2321:         if ($suffix ne '') {
                   2322:             push(@newpaste,$suffix);
                   2323:         } else {
                   2324:             if ($locknotfreed) {
                   2325:                 return $locknotfreed;
                   2326:             }
1.538     raeburn  2327:         }
                   2328:         if (&is_supplemental_title($title)) {
                   2329:             &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
                   2330: 	    ($title) = &Apache::loncommon::parse_supplemental_title($title);
                   2331:         }
1.329     droeschl 2332: 
1.538     raeburn  2333:         $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
                   2334:         $addtoenv{'docs.markedcopy_url_'.$suffix}   = $url,
                   2335:         $addtoenv{'docs.markedcopy_cmd_'.$suffix}   = $cmd,
                   2336:         $addtoenv{'docs.markedcopy_crs_'.$suffix}   = $env{'request.course.id'};
1.597     raeburn  2337:         $addtoenv{'docs.markedcopy_map_'.$suffix}   = $mapidx;
1.538     raeburn  2338:         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
                   2339:             my $prefix = $1;
                   2340:             my $subdir =$2;
                   2341:             if ($subdir eq '') {
                   2342:                 $subdir = $prefix;
1.492     raeburn  2343:             }
1.538     raeburn  2344:             my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627     raeburn  2345:             &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
                   2346:                                  \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538     raeburn  2347:             if (ref($hierarchy{$url}) eq 'HASH') {
                   2348:                 my ($nested,$nestednames);
                   2349:                 &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
                   2350:                 $nested =~ s/\&$//;
                   2351:                 $nestednames =~ s/\Q___&&&___\E$//;
                   2352:                 if ($nested ne '') {
                   2353:                     $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
                   2354:                 }
                   2355:                 if ($nestednames ne '') {
                   2356:                     $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
                   2357:                 }
1.492     raeburn  2358:             }
                   2359:         }
1.591     raeburn  2360:         if ($locknotfreed) {
                   2361:             $output = $locknotfreed;
                   2362:             last;
                   2363:         }
1.492     raeburn  2364:     }
1.538     raeburn  2365:     if (@newpaste) {
                   2366:         $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
                   2367:     }
1.492     raeburn  2368:     &Apache::lonnet::appenv(\%addtoenv);
1.329     droeschl 2369:     delete($env{'form.markcopy'});
1.591     raeburn  2370:     return $output;
1.329     droeschl 2371: }
                   2372: 
1.492     raeburn  2373: sub recurse_uploaded_maps {
                   2374:     my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
                   2375:     if (ref($hierarchy->{$url}) eq 'HASH') {
                   2376:         my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
                   2377:         my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
                   2378:         my (@uploaded,@names,%shorter);
                   2379:         for (my $i=0; $i<@maps; $i++) {
                   2380:             my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
                   2381:             if ($inner ne '') {
                   2382:                 push(@uploaded,$inner);
                   2383:                 push(@names,&escape($titles[$i]));
                   2384:                 $shorter{$maps[$i]} = $inner;
                   2385:             }
                   2386:         }
                   2387:         $$nestref .= "$dir:".join(',',@uploaded).'&';
                   2388:         $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
                   2389:         foreach my $map (@maps) {
                   2390:             if ($shorter{$map} ne '') {
                   2391:                 &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
                   2392:             }
                   2393:         }
                   2394:     }
                   2395:     return;
                   2396: }
                   2397: 
1.329     droeschl 2398: sub print_paste_buffer {
1.492     raeburn  2399:     my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538     raeburn  2400:     return if (!defined($env{'docs.markedcopies'}));
1.329     droeschl 2401: 
1.538     raeburn  2402:     unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
                   2403:         return if ($env{'docs.markedcopies'} eq '');
1.488     raeburn  2404:     }
                   2405: 
1.538     raeburn  2406:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
1.704     raeburn  2407:     my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
1.575     raeburn  2408:     my $clipboardcount = 0;
1.488     raeburn  2409: 
1.538     raeburn  2410: # Construct identifiers for current contents of user's paste buffer
                   2411:     foreach my $suffix (@currpaste) {
                   2412:         next if ($suffix =~ /\D/);
                   2413:         my $cid = $env{'docs.markedcopy_crs_'.$suffix};
                   2414:         my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597     raeburn  2415:         my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538     raeburn  2416:         if (($cid =~ /^$match_domain\_$match_courseid$/) &&
                   2417:             ($url ne '')) {
1.575     raeburn  2418:             $clipboardcount ++;
1.538     raeburn  2419:             my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.704     raeburn  2420:                 $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
                   2421:                 $toolcnum,$marker);
1.538     raeburn  2422:             my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
                   2423:             if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
                   2424:                 $is_external = 1;
1.704     raeburn  2425:             } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                   2426:                 ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598     raeburn  2427:                 $is_exttool = 1;
1.538     raeburn  2428:             }
                   2429:             if ($folder =~ /^supplemental/) {
                   2430:                 $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
                   2431:                 unless ($canpaste) {
                   2432:                     $nopaste = &mt('Paste into Supplemental Content unavailable.');
                   2433:                 }
                   2434:             } else {
                   2435:                 $canpaste = 1;
                   2436:             }
                   2437:             if ($canpaste) {
                   2438:                 if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
                   2439:                     my $srcdom = $1;
                   2440:                     my $srcnum = $2;
                   2441:                     my $rem = $3;
                   2442:                     if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
                   2443:                         $othercourse = 1;
                   2444:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596     raeburn  2445:                             $othercrs = '<br />'.&mt('(from another course)');
1.538     raeburn  2446:                         } else {
                   2447:                             $canpaste = 0;
                   2448:                             $nopaste = &mt('Paste from another course unavailable.'); 
                   2449:                         }
                   2450:                     }
                   2451:                     if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
                   2452:                         my $prefix = $1;
                   2453:                         $parent = $2;
                   2454:                         if ($folder !~ /^\Q$prefix\E/) {
                   2455:                             $areachange = 1;
                   2456:                         }
                   2457:                         $is_uploaded_map = 1;
1.492     raeburn  2458:                     }
1.597     raeburn  2459:                 } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627     raeburn  2460:                          ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596     raeburn  2461:                     if ($cid ne $env{'request.course.id'}) {
                   2462:                         my ($srcdom,$srcnum) = split(/_/,$cid);
                   2463:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704     raeburn  2464:                             if ($is_exttool) {
                   2465:                                 if ($toolcdom ne $coursedom) {
                   2466:                                     $canpaste = 0;
                   2467:                                     $nopaste = &mt('Paste from another domain unavailable.');
                   2468:                                 } elsif ($toolcnum ne $coursenum) {
                   2469:                                     my %toolsettings =
                   2470:                                         &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
                   2471:                                     my %tooltypes = &Apache::loncommon::usable_exttools();
                   2472:                                     if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                   2473:                                         (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                   2474:                                         $canpaste = 0;
                   2475:                                         $nopaste = &mt('Paste from another course unavailable.');
                   2476:                                     } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
                   2477:                                         unless ($checkedsameinst) {
                   2478:                                             my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
                   2479:                                             my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   2480:                                             if ($intdom ne '') {
                   2481:                                                 my $internet_names =
                   2482:                                                     &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   2483:                                                 if (ref($internet_names) eq 'ARRAY') {
                   2484:                                                     if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   2485:                                                         $same_institution = 1;
                   2486:                                                     }
                   2487:                                                 }
                   2488:                                             }
                   2489:                                             $checkedsameinst = 1;
                   2490:                                         }
                   2491:                                         if ($same_institution) {
                   2492:                                             $othercrs = '<br />'.&mt('(from another course)');
                   2493:                                         } else {
                   2494:                                             $nopaste = &mt('Paste from another course unavailable.');
                   2495:                                         }
                   2496:                                     } else {
                   2497:                                         $othercrs = '<br />'.&mt('(from another course)');
                   2498:                                     }
                   2499:                                 }
1.627     raeburn  2500:                             }
1.596     raeburn  2501:                         } else {
                   2502:                             $canpaste = 0;
                   2503:                             $nopaste = &mt('Paste from another course unavailable.');
1.629     raeburn  2504:                         }
1.596     raeburn  2505:                     }
1.703     raeburn  2506:                 } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
                   2507:                     my ($audom,$auname) = ($1,$2);
                   2508:                     unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
                   2509:                         if (&Apache::lonnet::is_course($audom,$auname)) {
                   2510:                             $canpaste = 0;
                   2511:                             $nopaste = &mt('Paste from another course unavailable.');
                   2512:                         }
                   2513:                     }
1.492     raeburn  2514:                 }
1.596     raeburn  2515:                 if ($canpaste) {
                   2516:                     push(@pasteable,$suffix);
1.629     raeburn  2517:                 }
1.538     raeburn  2518:             }
                   2519:             my $buffer;
1.627     raeburn  2520:             if ($is_external) {
1.538     raeburn  2521:                 $buffer = &mt('External Resource').': '.
                   2522:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
                   2523:                     &LONCAPA::map::qtescape($url).')';
1.627     raeburn  2524:             } elsif ($is_exttool) {
                   2525:                 $buffer = &mt('External Tool').': '.
                   2526:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538     raeburn  2527:             } else {
                   2528:                 my $icon = &Apache::loncommon::icon($extension);
1.723   ! raeburn  2529:                 my $icontext;
        !          2530:                 if ($extension eq 'sequence') {
        !          2531:                     $icontext = &mt('folder icon');
        !          2532:                 } elsif ($extension eq 'page') {
        !          2533:                     $icontext = &mt('composite page icon');
        !          2534:                 } else {
        !          2535:                     $icontext = &mt('file icon');
        !          2536:                 }
        !          2537:                 $icontext = &HTML::Entities::encode($icontext);
1.538     raeburn  2538:                 if ($extension eq 'sequence' &&
                   2539:                     $url =~ m{/default_\d+\.sequence$}x) {
                   2540:                     $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
                   2541:                     $icon .= '/navmap.folder.closed.gif';
                   2542:                 }
1.589     raeburn  2543:                 my $title = $env{'docs.markedcopy_title_'.$suffix};
                   2544:                 if ($title eq '') {
                   2545:                     ($title) = ($url =~ m{/([^/]+)$});
                   2546:                 }
1.723   ! raeburn  2547:                 $buffer = '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />'.
1.538     raeburn  2548:                           ': '.
                   2549:                           &Apache::loncommon::parse_supplemental_title(
1.589     raeburn  2550:                              &LONCAPA::map::qtescape($title));
1.538     raeburn  2551:             }
                   2552:             $pasteitems .= '<div class="LC_left_float">';
                   2553:             my ($options,$onclick);
                   2554:             if (($canpaste) && (!$areachange) && (!$othercourse) &&
                   2555:                 ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
                   2556:                 if (($is_uploaded_map) ||
                   2557:                     ($url =~ /(bulletinboard|smppg)$/) ||
                   2558:                     ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
                   2559:                     $options = &paste_options($suffix,$is_uploaded_map,$parent);
                   2560:                     $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
                   2561:                 }
                   2562:             }
                   2563:             $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
                   2564:             if ($nopaste) {
1.681     raeburn  2565:                  $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';   
1.538     raeburn  2566:             } else {
                   2567:                 if ($othercrs) {
                   2568:                     $pasteitems .= $othercrs;
                   2569:                 }
                   2570:                 if ($options) {
                   2571:                     $pasteitems .= $options;
1.492     raeburn  2572:                 }
                   2573:             }
1.538     raeburn  2574:             $pasteitems .= '</div>';
                   2575:         }
                   2576:     }
                   2577:     if ($pasteitems eq '') {
                   2578:         &Apache::lonnet::delenv('docs.markedcopies');
                   2579:     }
                   2580:     my ($pasteform,$form_start,$buttons,$form_end);
                   2581:     if ($pasteitems) {
                   2582:         $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541     raeburn  2583:         $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538     raeburn  2584:         if (@pasteable) {
1.575     raeburn  2585:             my $value = &mt('Paste to current folder');
                   2586:             if ($container eq 'page') {
                   2587:                 $value = &mt('Paste to current page');
                   2588:             } 
                   2589:             $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.('&nbsp;'x2);
                   2590:         }
                   2591:         $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.('&nbsp;'x2);
                   2592:         if ($clipboardcount > 1) {
                   2593:             $buttons .=
                   2594:                 '<span style="text-decoration:line-through">'.('&nbsp;'x20).'</span>'.('&nbsp;'x2).
                   2595:                 '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
                   2596:                 ('&nbsp;'x2).
                   2597:                 '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
                   2598:                 ('&nbsp;'x2);
1.492     raeburn  2599:         }
1.575     raeburn  2600:         $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
                   2601:                     '</form>';
1.538     raeburn  2602:     } else {
                   2603:         $pasteitems = &mt('Clipboard is empty');
1.488     raeburn  2604:     }
1.538     raeburn  2605:     $r->print($form_start
                   2606:              .'<fieldset>'
                   2607:              .'<legend>'.&mt('Clipboard').('&nbsp;' x2).$buttons.'</legend>'
                   2608:              .$pasteitems
                   2609:              .'</fieldset>'
                   2610:              .$form_end);
                   2611: }
                   2612: 
                   2613: sub paste_options {
                   2614:     my ($suffix,$is_uploaded_map,$parent) = @_;
                   2615:     my ($copytext,$movetext);
                   2616:     if ($is_uploaded_map) {
                   2617:         $copytext = &mt('Copy to new folder');
                   2618:         $movetext = &mt('Move old');
                   2619:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
                   2620:         $copytext = &mt('Copy to new board');
                   2621:         $movetext = &mt('Move (not posts)');
                   2622:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
                   2623:         $copytext = &mt('Copy to new page');
                   2624:         $movetext = &mt('Move');
1.533     raeburn  2625:     } else {
1.538     raeburn  2626:         $copytext = &mt('Copy to new file');
                   2627:         $movetext = &mt('Move');
                   2628:     }
                   2629:     my $output = '<br />'.
                   2630:                  '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
                   2631:                  '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.('&nbsp;'x 4).
                   2632:                  '<label>'.
                   2633:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
                   2634:                  $copytext.'</label></span>'.('&nbsp;'x2).' '.
                   2635:                  '<span class="LC_nobreak"><label>'.
                   2636:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
                   2637:                  $movetext.'</label></span>';
                   2638:     if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
                   2639:         $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
                   2640:                    '</legend><table border="0">';
                   2641:         my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   2642:         my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
                   2643:         my $lastdir = $parent;
                   2644:         my %depths = (
                   2645:                        $lastdir => 0,
                   2646:                      );
                   2647:         my (%display,%deps);
                   2648:         for (my $i=0; $i<@pastemaps; $i++) {
                   2649:             ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
                   2650:             my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
                   2651:             my @subfolders = split(/,/,$subfolderstr);
                   2652:             $deps{$lastdir} = \@subfolders;
                   2653:             my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
                   2654:             my $depth = $depths{$lastdir} + 1;
                   2655:             my $offset = int($depth * 4);
                   2656:             my $indent = ('&nbsp;' x $offset);
                   2657:             for (my $j=0; $j<@subfolders; $j++) {
                   2658:                 $depths{$subfolders[$j]} = $depth;
                   2659:                 $display{$subfolders[$j]} =
                   2660:                     '<tr><td>'.$indent.$subfoldertitles[$j].'&nbsp;</td>'.
                   2661:                     '<td><label>'.
                   2662:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.('&nbsp;' x2).
                   2663:                     '<label>'.
                   2664:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
                   2665:                     &mt('Move old').'</label>'.
                   2666:                     '</td></tr>';
                   2667:              }
1.492     raeburn  2668:         }
1.538     raeburn  2669:         &recurse_print(\$output,$parent,\%deps,\%display);
                   2670:         $output .= '</table></fieldset>';
1.329     droeschl 2671:     }
1.538     raeburn  2672:     $output .= '</div>';
                   2673:     return $output;
1.488     raeburn  2674: }
                   2675: 
1.492     raeburn  2676: sub recurse_print {
1.538     raeburn  2677:     my ($outputref,$dir,$deps,$display) = @_;
                   2678:     $$outputref .= $display->{$dir}."\n";
1.492     raeburn  2679:     if (ref($deps->{$dir}) eq 'ARRAY') {
                   2680:         foreach my $subdir (@{$deps->{$dir}}) {
1.538     raeburn  2681:             &recurse_print($outputref,$subdir,$deps,$display);
1.492     raeburn  2682:         }
                   2683:     }
                   2684: }
                   2685: 
1.488     raeburn  2686: sub supp_pasteable {
                   2687:     my ($url) = @_;
                   2688:     if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//}) ||
                   2689:         (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
                   2690:         ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
                   2691:         ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598     raeburn  2692:         ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626     raeburn  2693:         ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488     raeburn  2694:         return 1;
                   2695:     }
                   2696:     return;
1.329     droeschl 2697: }
                   2698: 
1.492     raeburn  2699: sub paste_popup_js {
1.594     damieng  2700:     my %html_js_lt = &Apache::lonlocal::texthash(
1.538     raeburn  2701:                                           show => 'Show Options',
                   2702:                                           hide => 'Hide Options',
1.594     damieng  2703:                                         );
                   2704:     my %js_lt = &Apache::lonlocal::texthash(
1.541     raeburn  2705:                                           none => 'No items selected from clipboard.',
1.492     raeburn  2706:                                         );
1.594     damieng  2707:     &html_escape(\%html_js_lt);
                   2708:     &js_escape(\%html_js_lt);
                   2709:     &js_escape(\%js_lt);
1.492     raeburn  2710:     return <<"END";
                   2711: 
1.538     raeburn  2712: function showPasteOptions(suffix) {
                   2713:     document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594     damieng  2714:     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  2715:     return;
                   2716: }
                   2717: 
1.538     raeburn  2718: function hidePasteOptions(suffix) {
                   2719:     document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594     damieng  2720:     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  2721:     return;
                   2722: }
                   2723: 
                   2724: function showOptions(caller,suffix) {
                   2725:     if (document.getElementById('pasteoptionstext_'+suffix)) {
                   2726:         if (caller.checked) {
1.594     damieng  2727:             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  2728:         } else {
                   2729:             document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
                   2730:         }
                   2731:         if (document.getElementById('pasteoptions_'+suffix)) {
                   2732:             document.getElementById('pasteoptions_'+suffix).style.display='none';
                   2733:         }
                   2734:     }
1.492     raeburn  2735:     return;
                   2736: }
                   2737: 
1.541     raeburn  2738: function validateClipboard() {
                   2739:     var numchk = 0;
                   2740:     if (document.pasteform.pasting.length > 1) {
                   2741:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   2742:             if (document.pasteform.pasting[i].checked) {
                   2743:                 numchk ++;
                   2744:             }
                   2745:         }
                   2746:     } else {
                   2747:         if (document.pasteform.pasting.type == 'checkbox') {
                   2748:             if (document.pasteform.pasting.checked) {
                   2749:                 numchk ++; 
                   2750:             } 
                   2751:         }
                   2752:     }
                   2753:     if (numchk > 0) { 
                   2754:         return true;
                   2755:     } else {
1.594     damieng  2756:         alert("$js_lt{'none'}");
1.541     raeburn  2757:         return false;
                   2758:     }
                   2759: }
                   2760: 
1.575     raeburn  2761: function checkClipboard() {
                   2762:     if (document.pasteform.pasting.length > 1) {
                   2763:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   2764:             document.pasteform.pasting[i].checked = true;
                   2765:         } 
                   2766:     }
                   2767:     return;
                   2768: }
                   2769: 
                   2770: function uncheckClipboard() {
                   2771:     if (document.pasteform.pasting.length >1) {
                   2772:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   2773:             document.pasteform.pasting[i].checked = false;
                   2774:         }
                   2775:     }
                   2776:     return;
                   2777: }
                   2778: 
1.492     raeburn  2779: END
                   2780: 
                   2781: }
                   2782: 
1.329     droeschl 2783: sub do_paste_from_buffer {
1.492     raeburn  2784:     my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329     droeschl 2785: 
1.538     raeburn  2786: # Array of items in paste buffer
                   2787:     my (@currpaste,%pastebuffer,%allerrors);
                   2788:     @currpaste = split(/,/,$env{'docs.markedcopies'});
                   2789: 
1.492     raeburn  2790: # Early out if paste buffer is empty
1.538     raeburn  2791:     if (@currpaste == 0) {
1.492     raeburn  2792:         return ();
1.538     raeburn  2793:     } 
                   2794:     map { $pastebuffer{$_} = 1; } @currpaste;
                   2795: 
                   2796: # Array of items selected items to paste
                   2797:     my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
                   2798: 
                   2799: # Early out if nothing selected to paste
                   2800:     if (@reqpaste == 0) {
                   2801:         return();
                   2802:     }
                   2803:     my @topaste;
                   2804:     foreach my $suffix (@reqpaste) {
                   2805:         next if ($suffix =~ /\D/);
                   2806:         next unless (exists($pastebuffer{$suffix}));
                   2807:         push(@topaste,$suffix);
                   2808:     }
                   2809: 
                   2810: # Early out if nothing available to paste
                   2811:     if (@topaste == 0) {
                   2812:         return();
1.329     droeschl 2813:     }
                   2814: 
1.704     raeburn  2815:     my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
                   2816:         %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
                   2817:         %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
                   2818:         %currltititles,$currltimax,$gotcrsltitools);
                   2819:     $currltimax = 0;
                   2820:     $gotcrsltitools = 0;
1.538     raeburn  2821:     foreach my $suffix (@topaste) {
                   2822:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596     raeburn  2823:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597     raeburn  2824:         my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix}); 
1.492     raeburn  2825: # Supplemental content may only include certain types of content
                   2826: # Early out if pasted content is not supported in Supplemental area
1.538     raeburn  2827:         if ($folder =~ /^supplemental/) {
                   2828:             unless (&supp_pasteable($url)) {
                   2829:                 $notinsupp{$suffix} = 1;
                   2830:                 next;
                   2831:             }
1.492     raeburn  2832:         }
1.538     raeburn  2833:         if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
                   2834:             my $srcd = $1;
                   2835:             my $srcn = $2;
1.492     raeburn  2836: # When paste buffer was populated using an active role in a different course
1.538     raeburn  2837: # check for mdc privilege in the course from which the resource was pasted
                   2838:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   2839:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   2840:                     $notincrs{$suffix} = 1;
                   2841:                     next;
                   2842:                 }
1.491     raeburn  2843:             }
1.538     raeburn  2844:             $srcdom{$suffix} = $srcd;
                   2845:             $srcnum{$suffix} = $srcn;
1.597     raeburn  2846:         } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632     raeburn  2847:                  ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
                   2848:                  ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596     raeburn  2849:             my ($srcd,$srcn) = split(/_/,$cid);
                   2850: # When paste buffer was populated using an active role in a different course
                   2851: # check for mdc privilege in the course from which the resource was pasted
                   2852:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   2853:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   2854:                     $notincrs{$suffix} = 1;
                   2855:                     next;
                   2856:                 }
                   2857:             }
1.632     raeburn  2858: # When buffer was populated using an active role in a different course
1.704     raeburn  2859: # disallow pasting of External Tool if course is in a different domain,
                   2860: # or if External Tool use is not permitted in this course.
                   2861:             if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                   2862:                 my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
                   2863:                 if ($toolcdom ne $coursedom) {
                   2864:                     $notindom{$suffix} = 1;
                   2865:                     next;
                   2866:                 } elsif ($toolcnum ne $coursenum) {
                   2867:                     my %toolsettings =
                   2868:                         &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
                   2869:                     my %tooltypes = &Apache::loncommon::usable_exttools();
                   2870:                     if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                   2871:                         (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                   2872:                         $othcrstool{$suffix} = 1;
                   2873:                         next;
                   2874:                     }
                   2875:                     if ($toolsettings{'id'} =~ /^c\d+$/) {
                   2876:                         unless ($gotcrsltitools) {
                   2877:                             %currcrsltitools =
                   2878:                                 &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
                   2879:                             foreach my $item (sort(keys(%currcrsltitools))) {
                   2880:                                 if (ref($currcrsltitools{$item}) eq 'HASH') {
                   2881:                                     $currltimax ++;
                   2882:                                     if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
                   2883:                                         push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
                   2884:                                     } else {
                   2885:                                         $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
                   2886:                                     }
                   2887:                                 }
                   2888:                             }
                   2889:                             $gotcrsltitools = 1;
                   2890:                         }
                   2891:                     }
                   2892:                 }
1.627     raeburn  2893:             }
1.596     raeburn  2894:             $srcdom{$suffix} = $srcd;
                   2895:             $srcnum{$suffix} = $srcn;
1.703     raeburn  2896:         } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
                   2897:             my ($audom,$auname) = ($1,$2);
                   2898: # When buffer was populated using an active role in a different course
                   2899: # disallow pasting of published resources from Course Authoring Space
                   2900:             unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
                   2901:                 if (&Apache::lonnet::is_course($audom,$auname)) {
                   2902:                     $othcrsres{$suffix} = 1;
                   2903:                     next;
                   2904:                 }
                   2905:             }
1.491     raeburn  2906:         }
1.597     raeburn  2907:         $srcmapidx{$suffix} = $mapidx;
1.538     raeburn  2908:         push(@dopaste,$suffix);
                   2909:         if ($url=~/\.(page|sequence)$/) {
                   2910:             $is_map{$suffix} = 1; 
                   2911:         }
                   2912:         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
                   2913:             my $oldprefix = $1;
1.492     raeburn  2914: # When pasting content from Main Content to Supplemental Content and vice versa 
                   2915: # URLs will contain different paths (which depend on whether pasted item is
1.597     raeburn  2916: # a folder/page or a document).
1.538     raeburn  2917:             if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
                   2918:                 $prefixchg{$suffix} = 'docstosupp';
                   2919:             } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
                   2920:                 $prefixchg{$suffix} = 'supptodocs';
                   2921:             }
1.491     raeburn  2922: 
1.492     raeburn  2923: # If pasting an uploaded map, get list of contained uploaded maps.
1.538     raeburn  2924:             if ($env{'docs.markedcopy_nested_'.$suffix}) {
                   2925:                 my @nested;
                   2926:                 my ($type) = ($oldprefix =~ /^(default|supplemental)/);
                   2927:                 my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   2928:                 my @deps = map { /\d+:([\d,]+$)/ } @items;
                   2929:                 foreach my $dep (@deps) {
                   2930:                     if ($dep =~ /,/) {
                   2931:                         push(@nested,split(/,/,$dep));
                   2932:                     } else {
                   2933:                         push(@nested,$dep);
                   2934:                     }
1.492     raeburn  2935:                 }
1.538     raeburn  2936:                 foreach my $item (@nested) {
                   2937:                     if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
                   2938:                         push(@{$marktomove{$suffix}},$type.'_'.$item);
                   2939:                     }
1.492     raeburn  2940:                 }
                   2941:             }
1.488     raeburn  2942:         }
                   2943:     }
                   2944: 
1.538     raeburn  2945: # Early out if nothing available to paste
                   2946:     if (@dopaste == 0) {
                   2947:         return ();
                   2948:     }
                   2949: 
                   2950: # Populate message hash and hashes used for main content <=> supplemental content
                   2951: # changes    
                   2952: 
                   2953:     %msgs = &Apache::lonlocal::texthash (
                   2954:                 notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
                   2955:                 notincrs  => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661     raeburn  2956:                 notindom  => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704     raeburn  2957:                 othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703     raeburn  2958:                 othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538     raeburn  2959:                 duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
                   2960:             );
                   2961: 
                   2962:     %before = (
                   2963:                  docstosupp => {
                   2964:                                    map => 'default',
                   2965:                                    doc => 'docs',
                   2966:                                },
                   2967:                  supptodocs => {
                   2968:                                    map => 'supplemental',
                   2969:                                    doc => 'supplemental',
                   2970:                                },
                   2971:               );
                   2972: 
                   2973:     %after = (
                   2974:                  docstosupp => {
                   2975:                                    map => 'supplemental',
                   2976:                                    doc => 'supplemental'
                   2977:                                },
                   2978:                  supptodocs => {
                   2979:                                    map => 'default',
                   2980:                                    doc => 'docs',
                   2981:                                },
                   2982:              );
                   2983: 
                   2984: # Retrieve information about all course maps in main content area 
                   2985: 
                   2986:     my $allmaps = {};
1.704     raeburn  2987:     my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
                   2988:         @updatetoolsenc,$updatetoolscache,$checkedsameinst,
                   2989:         $same_institution);
1.538     raeburn  2990: 
                   2991: # Loop over the items to paste
                   2992:     foreach my $suffix (@dopaste) {
1.329     droeschl 2993: # Maps need to be copied first
1.538     raeburn  2994:         my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
                   2995:             %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597     raeburn  2996:             %newurls,%tomove,%resdatacopy);
1.538     raeburn  2997:         if (ref($marktomove{$suffix}) eq 'ARRAY') {
                   2998:             map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
                   2999:         }
                   3000:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
                   3001:         my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596     raeburn  3002:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); 
1.538     raeburn  3003:         my $oldurl = $url;
                   3004:         if ($is_map{$suffix}) {
1.491     raeburn  3005: # If pasting a map, check if map contains other maps
1.538     raeburn  3006:             my (%hierarchy,%titles);
1.660     raeburn  3007:             if (($folder =~ /^default/) && (!$donechk)) {
                   3008:                 $allmaps =
                   3009:                     &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                   3010:                                                          $env{"course.$env{'request.course.id'}.home"},
                   3011:                                                          $env{'request.course.id'});
                   3012:                 $donechk = 1;
                   3013:             }
1.627     raeburn  3014:             &contained_map_check($url,$folder,$coursenum,$coursedom,
                   3015:                                  \%removefrommap,\%removeparam,\%addedmaps,
                   3016:                                  \%hierarchy,\%titles,$allmaps);
1.538     raeburn  3017:             if ($url=~ m{^/uploaded/}) {
                   3018:                 my $newurl;
                   3019:                 unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   3020:                     ($newurl,my $error) = 
                   3021:                         &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
                   3022:                                         $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   3023:                                         \$title,$allmaps,\%newurls);
                   3024:                     if ($error) {
                   3025:                         $allerrors{$suffix} = $error;
                   3026:                         next;
                   3027:                     }
                   3028:                     if ($newurl ne '') {
                   3029:                         if ($newurl ne $url) {
                   3030:                             if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
                   3031:                                 $newsubdir{$url} = $1;
                   3032:                             }
                   3033:                             $mapchanges{$url} = 1;
1.492     raeburn  3034:                         }
1.538     raeburn  3035:                     }
                   3036:                 }
                   3037:                 if (($srcdom{$suffix} ne $coursedom) ||
                   3038:                     ($srcnum{$suffix} ne $coursenum) ||
                   3039:                     ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
                   3040:                     unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
                   3041:                                               $coursedom,$coursenum,$srcdom{$suffix},
                   3042:                                               $srcnum{$suffix},$allmaps,\%rewrites,
                   3043:                                               \%retitles,\%copies,\%dbcopies,
                   3044:                                               \%zombies,\%params,\%mapmoves,
                   3045:                                               \%mapchanges,\%tomove,\%newsubdir,
1.597     raeburn  3046:                                               \%newurls,\%resdatacopy)) {
1.538     raeburn  3047:                         $mapmoves{$url} = 1;
                   3048:                     }
                   3049:                     $url = $newurl;
                   3050:                 } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
                   3051:                     &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
                   3052:                                       $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   3053:                                       $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
                   3054:                                       \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597     raeburn  3055:                                       \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538     raeburn  3056:                 }
                   3057:             } elsif ($url=~m {^/res/}) {
1.597     raeburn  3058: # published map can only exist once, so remove from paste buffer when done
1.538     raeburn  3059:                 push(@toclear,$suffix);
                   3060: # if pasting published map (main content area only) check map not already in course
                   3061:                 if ($folder =~ /^default/) {
                   3062:                     if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
                   3063:                         $duplicate{$suffix} = 1; 
                   3064:                         next;
1.492     raeburn  3065:                     }
1.491     raeburn  3066:                 }
                   3067:             }
1.538     raeburn  3068:         }
1.627     raeburn  3069:         if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538     raeburn  3070:             my $prefix = $1;
1.648     raeburn  3071:             my $fromothercrs;
1.538     raeburn  3072:             #need to copy the db contents to a new one, unless this is a move.
                   3073:             my %info = (
                   3074:                          src  => $url,
                   3075:                          cdom => $coursedom,
                   3076:                          cnum => $coursenum,
1.596     raeburn  3077:                        );
1.649     raeburn  3078:             if ($prefix eq 'ext.tool') {
1.655     raeburn  3079:                 if ($prefixchg{$suffix} eq 'docstosupp') {
1.649     raeburn  3080:                     $info{'delgradable'} = 1;
                   3081:                 }
                   3082:             }
1.596     raeburn  3083:             if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
                   3084:                 unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
                   3085:                     $fromothercrs = 1;
                   3086:                     $info{'cdom'} = $srcdom{$suffix};
                   3087:                     $info{'cnum'} = $srcnum{$suffix};
1.704     raeburn  3088:                     unless ($checkedsameinst) {
                   3089:                         my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
                   3090:                         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   3091:                         if ($intdom ne '') {
                   3092:                             my $internet_names =
                   3093:                                 &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   3094:                             if (ref($internet_names) eq 'ARRAY') {
                   3095:                                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   3096:                                     $same_institution = 1;
                   3097:                                 }
                   3098:                             }
                   3099:                         }
                   3100:                         $checkedsameinst = 1;
                   3101:                     }
1.596     raeburn  3102:                 }
                   3103:             }
                   3104:             unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630     raeburn  3105:                 my (%lockerr,$msg);
1.538     raeburn  3106:                 my ($newurl,$result,$errtext) =
1.704     raeburn  3107:                     &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
                   3108:                             \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538     raeburn  3109:                 if ($result eq 'ok') {
                   3110:                     $url = $newurl;
                   3111:                     $title=&mt('Copy of').' '.$title;
                   3112:                 } else {
                   3113:                     if ($prefix eq 'smppg') {
                   3114:                         $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
                   3115:                     } elsif ($prefix eq 'bulletinboard') {
1.565     bisitz   3116:                         $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627     raeburn  3117:                     } elsif ($prefix eq 'ext.tool') {
                   3118:                         $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538     raeburn  3119:                     }
                   3120:                     $results{$suffix} = $result;
                   3121:                     $msgerrs{$suffix} = $msg;
                   3122:                     $lockerrs{$suffix} = $lockerr{$prefix}; 
                   3123:                     next;
                   3124: 	        }
                   3125:                 if ($lockerr{$prefix}) {
                   3126:                     $lockerrs{$suffix} = $lockerr{$prefix};  
1.491     raeburn  3127:                 }
1.489     raeburn  3128:             }
                   3129:         }
1.538     raeburn  3130:         $title = &LONCAPA::map::qtunescape($title);
                   3131:         my $ext='false';
                   3132:         if ($url=~m{^http(|s)://}) { $ext='true'; }
                   3133:         if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
                   3134:             if ($folder !~ /^supplemental/) {
                   3135:                 (undef,undef,$title) =
                   3136:                     &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
                   3137:             }
                   3138:         } else {
                   3139:             if ($folder=~/^supplemental/) {
                   3140:                 $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   3141:                        $env{'user.domain'}.'___&&&___'.$title;
1.491     raeburn  3142:             }
1.533     raeburn  3143:         }
1.491     raeburn  3144: 
                   3145: # For uploaded files (excluding pages/sequences) path in copied file is changed
                   3146: # if paste is from Main to Supplemental (or vice versa), or if pasting between
                   3147: # courses.
                   3148: 
1.538     raeburn  3149:         unless ($is_map{$suffix}) {
                   3150:             my $newidx;
1.492     raeburn  3151: # Now insert the URL at the bottom
1.538     raeburn  3152:             $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   3153:             if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
                   3154:                 my $relpath = $1;
                   3155:                 if ($relpath ne '') {
                   3156:                     my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
                   3157:                     my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
                   3158:                     my $newprefix = $newloc;
                   3159:                     if ($newloc eq 'default') {
                   3160:                         $newprefix = 'docs';
                   3161:                     }
                   3162:                     if ($newdocsdir eq '') {
                   3163:                         $newdocsdir = 'default';
                   3164:                     }
1.630     raeburn  3165:                     if (($prefixchg{$suffix}) ||
                   3166:                         ($srcdom{$suffix} ne $coursedom) ||
1.538     raeburn  3167:                         ($srcnum{$suffix} ne $coursenum) ||
                   3168:                         ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
                   3169:                         my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
                   3170:                         $url =
                   3171:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
                   3172:                                                                &Apache::lonnet::getfile($oldurl));
                   3173:                         if ($url eq '/adm/notfound.html') {
                   3174:                             $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
                   3175:                             next;
                   3176:                         } else {
                   3177:                             my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
                   3178:                             $newsubpath =~ s{/+$}{/};
                   3179:                             $docmoves{$oldurl} = $newsubpath;
                   3180:                         }
1.491     raeburn  3181:                     }
                   3182:                 }
1.597     raeburn  3183:             } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   3184:                 my $template = $1;
                   3185:                 if ($newidx) {
                   3186:                     &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
                   3187:                                           $coursedom,$coursenum,$template,$newidx,"$folder.$container");
                   3188:                 }
1.649     raeburn  3189:             } elsif ($url =~ /ext\.tool$/) {
1.655     raeburn  3190:                 if (($newidx) && ($folder=~/^default/)) {
1.649     raeburn  3191:                     my $marker = (split(m{/},$url))[4];
                   3192:                     my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
                   3193:                     my $val = 'no';
                   3194:                     if ($toolsettings{'gradable'}) {
                   3195:                         $val = 'yes';
                   3196:                     }
                   3197:                     &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
                   3198:                                                   'string_yesno');
                   3199:                     &remember_parms($newidx,'gradable','set',$val);
                   3200:                 }
1.491     raeburn  3201:             }
1.538     raeburn  3202:             $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   3203:                                               ':'.$ext.':normal:res';
                   3204:             push(@LONCAPA::map::order,$newidx);
                   3205: # Store the result
                   3206:             my ($errtext,$fatal) =
                   3207:                 &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   3208:             if ($fatal) {
                   3209:                 $save_err .= $errtext;
                   3210:                 $allresult = 'fail';
                   3211:             }
1.488     raeburn  3212:         }
1.538     raeburn  3213: 
1.597     raeburn  3214: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
                   3215: # resourcedata for simpleproblems copied from another course 
1.538     raeburn  3216:         unless ($allresult eq 'fail') {
                   3217:             my %updated = (
                   3218:                             rewrites      => \%rewrites,
                   3219:                             zombies       => \%zombies,
                   3220:                             removefrommap => \%removefrommap,
                   3221:                             removeparam   => \%removeparam,
                   3222:                             dbcopies      => \%dbcopies,
1.597     raeburn  3223:                             resdatacopy   => \%resdatacopy,
1.538     raeburn  3224:                             retitles      => \%retitles,
                   3225:                           );
                   3226:             my %info = (
                   3227:                            newsubdir => \%newsubdir,
                   3228:                            params    => \%params,
                   3229:                        );
                   3230:             if ($prefixchg{$suffix}) {
                   3231:                 $info{'before'} = $before{$prefixchg{$suffix}};
                   3232:                 $info{'after'} = $after{$prefixchg{$suffix}};
                   3233:             }
                   3234:             my %moves = (
                   3235:                            copies   => \%copies,
                   3236:                            docmoves => \%docmoves,
                   3237:                            mapmoves => \%mapmoves,
                   3238:                         );
                   3239:             (my $result,$msgs{$suffix},my $lockerror) =
                   3240:                 &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
                   3241:                               \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
                   3242:                               $url,'paste');
                   3243:             $lockerrors .= $lockerror;
                   3244:             if ($result eq 'ok') {
                   3245:                 if ($is_map{$suffix}) {
                   3246:                     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   3247:                                                     $folder.'.'.$container);
                   3248:                     if ($fatal) {
                   3249:                         $allresult = 'failread';
                   3250:                     } else {
                   3251:                         if ($#LONCAPA::map::order<1) {
                   3252:                             my $idx=&LONCAPA::map::getresidx();
                   3253:                             if ($idx<=0) { $idx=1; }
                   3254:                             $LONCAPA::map::order[0]=$idx;
                   3255:                             $LONCAPA::map::resources[$idx]='';
                   3256:                         }
                   3257:                         my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   3258:                         $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   3259:                                                           ':'.$ext.':normal:res';
                   3260:                         push(@LONCAPA::map::order,$newidx);
1.492     raeburn  3261: 
                   3262: # Store the result
1.538     raeburn  3263:                         my ($errtext,$fatal) = 
                   3264:                             &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   3265:                         if ($fatal) {
                   3266:                             $save_err .= $errtext;
                   3267:                             $allresult = 'failstore';
                   3268:                         }
                   3269:                     } 
                   3270:                 }
                   3271:                 if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   3272:                      push(@toclear,$suffix);
                   3273:                 }
                   3274:             }
1.492     raeburn  3275:         }
                   3276:     }
1.704     raeburn  3277:     if (($updatetoolscache) || (@updatetoolsenc)) {
                   3278:         &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
                   3279:                                 \@updatetoolsenc);
                   3280:     }
1.538     raeburn  3281:     &clear_from_buffer(\@toclear,\@currpaste);
                   3282:     my $msgsarray;
                   3283:     foreach my $suffix (keys(%msgs)) {
                   3284:          if (ref($msgs{$suffix}) eq 'ARRAY') {
                   3285:              $msgsarray .= join(',',@{$msgs{$suffix}});
                   3286:          }
                   3287:     }
                   3288:     return ($allresult,$save_err,$msgsarray,$lockerrors);
                   3289: }
1.533     raeburn  3290: 
1.538     raeburn  3291: sub do_buffer_empty {
                   3292:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   3293:     if (@currpaste == 0) {
                   3294:         return &mt('Clipboard is already empty');
                   3295:     }
                   3296:     my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
                   3297:     if (@toclear == 0) {
                   3298:         return &mt('Nothing selected to clear from clipboard');
                   3299:     }
                   3300:     my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
                   3301:     if ($numdel) {
                   3302:         return &mt('[quant,_1,item] cleared from clipboard',$numdel);
                   3303:     } else {
                   3304:         return &mt('Clipboard unchanged');
1.492     raeburn  3305:     }
1.538     raeburn  3306:     return;
                   3307: }
                   3308: 
                   3309: sub clear_from_buffer {
                   3310:     my ($toclear,$currpaste) = @_;
                   3311:     return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
                   3312:     my %pastebuffer;
                   3313:     map { $pastebuffer{$_} = 1; } @{$currpaste};
                   3314:     my $numdel = 0;
                   3315:     foreach my $suffix (@{$toclear}) {
                   3316:         next if ($suffix =~ /\D/);
                   3317:         next unless (exists($pastebuffer{$suffix}));
                   3318:         my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
                   3319:         if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
                   3320:             delete($pastebuffer{$suffix});
                   3321:             $numdel ++;
                   3322:         }
                   3323:     }
                   3324:     my $newbuffer = join(',',sort(keys(%pastebuffer)));
                   3325:     &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
                   3326:     return $numdel;
1.492     raeburn  3327: }
                   3328: 
1.704     raeburn  3329: sub update_ltitools_caches {
                   3330:     my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
                   3331:     my $hashid=$coursedom.'_'.$coursenum;
                   3332:     if ($updatetoolscache) {
                   3333:         &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
                   3334:     }
                   3335:     if ((ref($updatetoolsenc) eq 'ARRAY') &&
                   3336:         (@{$updatetoolsenc})) {
                   3337:         my @ids=&Apache::lonnet::current_machine_ids();
                   3338:         my $updatedone;
                   3339:         foreach my $lonhost (@{$updatetoolsenc}) {
                   3340:             if (grep(/^\Q$lonhost\E$/,@ids)) {
                   3341:                 unless ($updatedone) {
                   3342:                     &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
                   3343:                 }
                   3344:                 $updatedone = 1;
                   3345:             } else {
                   3346:                 &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
                   3347:             }
                   3348:         }
                   3349:     }
                   3350:     return;
                   3351: }
                   3352: 
1.492     raeburn  3353: sub get_newmap_url {
                   3354:     my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
                   3355:         $titleref,$allmaps,$newurls) = @_;
                   3356:     my $newurl;
                   3357:     if ($url=~ m{^/uploaded/}) {
                   3358:         $$titleref=&mt('Copy of').' '.$$titleref;
                   3359:     }
                   3360:     my $now = time;
                   3361:     my $suffix=$$.int(rand(100)).$now;
                   3362:     my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
                   3363:     if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
                   3364:         my $path = $1;
                   3365:         my $prefix = $2;
                   3366:         my $ancestor = $3;
                   3367:         if (length($ancestor) > 10) {
                   3368:             $ancestor = substr($ancestor,-10,10);
                   3369:         }
                   3370:         my $newid;
                   3371:         if ($prefixchg) {
                   3372:             if ($folder =~ /^supplemental/) {
                   3373:                 $prefix =~ s/^default/supplemental/;
                   3374:             } else {
                   3375:                 $prefix =~ s/^supplemental/default/;
                   3376:             }
                   3377:         }
                   3378:         if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   3379:             $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   3380:         } else {
                   3381:             $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
                   3382:         }
                   3383:         my $counter = 0;
                   3384:         my $is_unique = &uniqueness_check($newurl);
                   3385:         if ($folder =~ /^default/) {
                   3386:             if ($allmaps->{$newurl}) {
                   3387:                 $is_unique = 0;
                   3388:             }
                   3389:         }
                   3390:         while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
                   3391:             $counter ++;
                   3392:             $suffix ++;
                   3393:             if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   3394:                 $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   3395:             } else {
                   3396:                 $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
                   3397:             }
                   3398:             $is_unique = &uniqueness_check($newurl);
                   3399:         }
                   3400:         if ($is_unique) {
                   3401:             $newurls->{$newurl} = 1;
                   3402:         } else {
                   3403:             if ($url=~/\.page$/) {
                   3404:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
                   3405:             } else {
                   3406:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
                   3407:             }
                   3408:         }
1.329     droeschl 3409:     }
1.492     raeburn  3410:     return ($newurl);
1.329     droeschl 3411: }
                   3412: 
1.488     raeburn  3413: sub dbcopy {
1.704     raeburn  3414:     my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
                   3415:         $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533     raeburn  3416:     my ($url,$result,$errtext);
                   3417:     if (ref($dbref) eq 'HASH') {
1.596     raeburn  3418:         $url = $dbref->{'src'};
1.627     raeburn  3419:         if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533     raeburn  3420:             my $prefix = $1;
1.627     raeburn  3421:             if ($prefix eq 'ext.tool') {
                   3422:                 $prefix = 'exttool';
                   3423:             }
1.533     raeburn  3424:             if (($dbref->{'cdom'} =~ /^$match_domain$/) && 
                   3425:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   3426:                 my $db_name;
                   3427:                 my $marker = (split(m{/},$url))[4];
                   3428:                 $marker=~s/\D//g;
                   3429:                 if ($dbref->{'src'} =~ m{/smppg$}) {
                   3430:                     $db_name =
                   3431:                         &Apache::lonsimplepage::get_db_name($url,$marker,
                   3432:                                                             $dbref->{'cdom'},
                   3433:                                                             $dbref->{'cnum'});
1.627     raeburn  3434:                 } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
                   3435:                     $db_name = 'exttool_'.$marker;
1.533     raeburn  3436:                 } else {
                   3437:                     $db_name = 'bulletinpage_'.$marker;
                   3438:                 }
                   3439:                 my ($suffix,$freedlock,$error) =
                   3440:                     &Apache::lonnet::get_timebased_id($prefix,'num','templated',
                   3441:                                                       $coursedom,$coursenum,
                   3442:                                                       'concat');
                   3443:                 if (!$suffix) {
                   3444:                     if ($prefix eq 'smppg') {
                   3445:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631     raeburn  3446:                     } elsif ($prefix eq 'exttool') {
                   3447:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533     raeburn  3448:                     } else {
1.565     bisitz   3449:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533     raeburn  3450:                     }
                   3451:                     if ($error) {
                   3452:                         $errtext .= '<br />'.$error;
                   3453:                     }
                   3454:                 } else {
                   3455:                     #need to copy the db contents to a new one.
                   3456:                     my %contents=&Apache::lonnet::dump($db_name,
                   3457:                                                        $dbref->{'cdom'},
                   3458:                                                        $dbref->{'cnum'});
1.704     raeburn  3459:                     my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
                   3460:                     if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
                   3461:                         if ($contents{'id'} =~ /^(|c)(\d+)$/) {
                   3462:                             $oldtoolid = $2;
                   3463:                             if ($1 eq 'c') {
                   3464:                                 $defincrs = 1;
                   3465:                                 %toolinfo =
                   3466:                                     &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
                   3467:                             } else {
                   3468:                                 %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
                   3469:                             }
                   3470:                             if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
                   3471:                                 if ($toolinfo{$oldtoolid}{'passback'}) {
                   3472:                                     $toolpassback = 1;
                   3473:                                 }
                   3474:                                 if ($toolinfo{$oldtoolid}{'roster'}) {
                   3475:                                     $toolroster = 1;
                   3476:                                 }
                   3477:                             } else {
                   3478:                                 $toolcopyerror = 1;
                   3479:                                 $errtext = &mt('Could not retrieve original settings for pasted external tool.');
                   3480:                             }
                   3481:                         }
                   3482:                         unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
                   3483:                             $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
                   3484:                             if ($contents{'crstitle'} ne '') {
                   3485:                                 $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
                   3486:                             }
                   3487:                             if (($defincrs) && (!$toolcopyerror)) {
                   3488:                                 my %newtool;
                   3489:                                 my $oldcdom = $dbref->{'cdom'};
                   3490:                                 my $oldcnum = $dbref->{'cnum'};
                   3491:                                 my $title = $toolinfo{$oldtoolid}{'title'};
                   3492:                                 if (ref($currltititles) eq 'HASH') {
                   3493:                                     if (exists($currltititles->{$title})) {
                   3494:                                         $title .= ' (copied from another course)';
                   3495:                                     }
                   3496:                                 }
                   3497:                                 my ($newid,$iderror) =
                   3498:                                     &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
                   3499:                                 if ($newid =~ /^\d+$/) {
                   3500:                                     %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
                   3501:                                     $newtool{$newid}{'title'} = $title;
                   3502:                                     if (ref($currltimax)) {
                   3503:                                         $newtool{$newid}{'order'} = $$currltimax;
                   3504:                                     }
                   3505:                                     if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
                   3506:                                         my $fname = $1;
                   3507:                                         my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
                   3508:                                         if ($content eq '-1') {
                   3509:                                             delete($newtool{$newid}{'image'});
                   3510:                                         } else {
                   3511:                                             $env{'form.'.$suffix.'.image'} = $content;
                   3512:                                             my $newlogo =
                   3513:                                                 &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
                   3514:                                             delete($env{'form.'.$suffix.'.image'});
                   3515:                                             if ($newlogo =~ m{^/uploaded/}) {
                   3516:                                                 $newtool{$newid}{'image'} = $newlogo;
                   3517:                                             } else {
                   3518:                                                 delete($newtool{$newid}{'image'});
                   3519:                                             }
                   3520:                                         }
                   3521:                                     }
                   3522:                                     my $newusable;
                   3523:                                     if ($same_institution) {
                   3524:                                         my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
                   3525:                                         if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
                   3526:                                             my %newtoolsenc;
                   3527:                                             %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
                   3528:                                             my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
                   3529:                                             if ($putres eq 'ok') {
                   3530:                                                 if (ref($updatetoolsenc) eq 'ARRAY') {
                   3531:                                                     my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
                   3532:                                                     unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
                   3533:                                                         push(@{$updatetoolsenc},$newhome);
                   3534:                                                     }
                   3535:                                                 }
                   3536:                                                 $newusable = 1;
                   3537:                                             }
                   3538:                                         }
                   3539:                                     }
                   3540:                                     if ($newtool{$newid}{'usable'}) {
                   3541:                                         unless ($newusable) {
                   3542:                                             delete($newtool{$newid}{'usable'});
                   3543:                                         }
                   3544:                                     }
                   3545:                                     my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
                   3546:                                     if ($putres eq 'ok') {
                   3547:                                         $contents{'id'} = "c$newid";
                   3548:                                         if (ref($updatetoolscache)) {
                   3549:                                             $$updatetoolscache ++;
                   3550:                                         }
                   3551:                                         if (ref($currltititles->{$title}) eq 'ARRAY') {
                   3552:                                             push(@{$currltititles->{$title}},$newid);
                   3553:                                         } else {
                   3554:                                             $currltititles->{$title} = [$newid];
                   3555:                                         }
                   3556:                                         if (ref($currltimax)) {
                   3557:                                             $$currltimax ++;
                   3558:                                         }
                   3559:                                     } else {
                   3560:                                         $toolcopyerror = 1;
                   3561:                                         $errtext = &mt('Unable to save external tool definition in Course Settings.');
                   3562:                                     }
                   3563:                                 } else {
                   3564:                                     $toolcopyerror = 1;
                   3565:                                     $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
                   3566:                                 }
                   3567:                             }
                   3568:                         }
                   3569:                     }
1.533     raeburn  3570:                     if (exists($contents{'uploaded.photourl'})) {
                   3571:                         my $photo = $contents{'uploaded.photourl'};
                   3572:                         my ($subdir,$fname) =
                   3573:                             ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596     raeburn  3574:                         my $newphoto;
1.533     raeburn  3575:                         if ($fname ne '') {
                   3576:                             my $content = &Apache::lonnet::getfile($photo);
                   3577:                             unless ($content eq '-1') {
                   3578:                                 $env{'form.'.$suffix.'.photourl'} = $content;
                   3579:                                 $newphoto = 
                   3580:                                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
                   3581:                                 delete($env{'form.'.$suffix.'.photourl'});
                   3582:                             }
                   3583:                         }
                   3584:                         if ($newphoto =~ m{^/uploaded/}) {
                   3585:                             $contents{'uploaded.photourl'} = $newphoto;
                   3586:                         }
                   3587:                     }
                   3588:                     $db_name =~ s{_\d*$ }{_$suffix}x;
1.704     raeburn  3589:                     if ($prefix eq 'exttool') {
                   3590:                         unless ($toolcopyerror) {
                   3591:                             foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
                   3592:                                 if (exists($contents{$key})) {
                   3593:                                     delete($contents{$key});
                   3594:                                 }
                   3595:                             }
                   3596:                             if ($dbref->{'delgradable'}) {
                   3597:                                 if (exists($contents{'gradable'})) {
                   3598:                                     delete($contents{'gradable'});
                   3599:                                 }
                   3600:                             }
                   3601:                             if ($toolpassback) {
                   3602:                                 if ($contents{'gradable'}) {
                   3603:                                     my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                   3604:                                     $contents{'gradesecret'} = $gradesecret;
                   3605:                                     $contents{'gradesecretdate'} = time;
                   3606:                                 }
                   3607:                             }
                   3608:                             if ($toolroster) {
                   3609:                                 my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                   3610:                                 $contents{'rostersecret'} = $rostersecret;
                   3611:                                 $contents{'rostersecretdate'} = time;
                   3612:                             }
                   3613:                         }
1.649     raeburn  3614:                     }
1.704     raeburn  3615:                     if (($prefix eq 'exttool') && ($toolcopyerror)) {
                   3616:                         $result = 'error';
                   3617:                     } else {
                   3618:                         $result=&Apache::lonnet::put($db_name,\%contents,
                   3619:                                                      $coursedom,$coursenum);
                   3620:                         if ($result eq 'ok') {
                   3621:                             $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
                   3622:                         }
1.533     raeburn  3623:                     }
                   3624:                 }
                   3625:                 if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559     raeburn  3626:                     $lockerrorsref->{$prefix} =
1.533     raeburn  3627:                         '<div class="LC_error">'.
                   3628:                         &mt('There was a problem removing a lockfile.');
                   3629:                     if ($prefix eq 'smppg') {
1.560     raeburn  3630:                         $lockerrorsref->{$prefix} .=
1.559     raeburn  3631:                             ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627     raeburn  3632:                     } elsif ($prefix eq 'exttool') {
                   3633:                         $lockerrorsref->{$prefix} .=
                   3634:                             ' '.&mt('This will prevent addition of more external tools to this course.');
1.533     raeburn  3635:                     } else {
1.565     bisitz   3636:                         $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  3637:                     }
1.560     raeburn  3638:                     $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   3639:                                                      '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
                   3640:                                                  '</div>';
1.533     raeburn  3641:                 }
                   3642:             }
                   3643:         } elsif ($url =~ m{/syllabus$}) {
                   3644:             if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
                   3645:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   3646:                 if (($dbref->{'cdom'} ne $coursedom) ||
                   3647:                     ($dbref->{'cnum'} ne $coursenum)) {
                   3648:                     my %contents=&Apache::lonnet::dump('syllabus',
                   3649:                                                        $dbref->{'cdom'},
                   3650:                                                        $dbref->{'cnum'});
                   3651:                     $result=&Apache::lonnet::put('syllabus',\%contents,
                   3652:                                                  $coursedom,$coursenum);
                   3653:                 }
                   3654:             }
1.488     raeburn  3655:         }
                   3656:     }
1.533     raeburn  3657:     return ($url,$result,$errtext);
1.488     raeburn  3658: }
                   3659: 
1.597     raeburn  3660: sub copy_templated_files {
                   3661:     my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
                   3662:     my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
                   3663:     my $srccontainer = 'sequence';
                   3664:     if ($srcwaspage) {
                   3665:         $srccontainer = 'page';
                   3666:     }
                   3667:     my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
                   3668:                   '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
                   3669:     my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
                   3670:     my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
                   3671:     my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
                   3672:                   $template.'.problem';
                   3673:     my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
                   3674:     if ($template eq 'simpleproblem') {
                   3675:         $srcprefix .= '.0.';
                   3676:         my $weightprefix = $newprefix;
                   3677:         $newprefix .= '.0.';
                   3678:         my @simpleprobqtypes = qw(radio option string essay numerical);
                   3679:         my $qtype=$srcparms{$srcprefix.'questiontype'};
                   3680:         if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665     raeburn  3681:             my %newdata = (
                   3682:                 $newprefix.'questiontype' => $qtype,
                   3683:             );
1.597     raeburn  3684:             foreach my $type (@simpleprobqtypes) {
                   3685:                 if ($type eq $qtype) {
                   3686:                     $newdata{"$weightprefix.$type.weight"}=1;
                   3687:                 } else {
                   3688:                     $newdata{"$weightprefix.$type.weight"}=0;
                   3689:                 }
                   3690:             }
                   3691:             $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
                   3692:             $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
                   3693:             $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
                   3694:             if ($qtype eq 'numerical') {
                   3695:                 $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
                   3696:                 $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
                   3697:                 $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
                   3698:                 $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
                   3699:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   3700:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   3701:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   3702:                     unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   3703:                         if ($maxfoils<=0) { $maxfoils=10; }
                   3704:                             my $randomize=$srcparms{$srcprefix.'randomize'};
                   3705:                             unless (defined($randomize)) { $randomize='yes'; }
                   3706:                             unless ($randomize eq 'no') { $randomize='yes'; }
                   3707:                             $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   3708:                             $newdata{$newprefix.'randomize'} = $randomize;
                   3709:                             if ($qtype eq 'option') {
                   3710:                                 $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   3711:                             }
                   3712:                             for (my $i=1; $i<=10; $i++) {
                   3713:                                 $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   3714:                                 $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   3715:                                 $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   3716:                             }
                   3717: 
                   3718:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   3719:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   3720:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   3721:                 unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   3722:                 if ($maxfoils<=0) { $maxfoils=10; }
                   3723:                 my $randomize=$srcparms{$srcprefix.'randomize'};
                   3724:                 unless (defined($randomize)) { $randomize='yes'; }
                   3725:                 unless ($randomize eq 'no') { $randomize='yes'; }
                   3726:                 $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   3727:                 $newdata{$newprefix.'randomize'} = $randomize;
                   3728:                 if ($qtype eq 'option') {
                   3729:                     $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   3730:                 }
                   3731:                 for (my $i=1; $i<=10; $i++) {
                   3732:                     $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   3733:                     $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   3734:                     $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   3735:                 }
                   3736:             } elsif ($qtype eq 'string') {
                   3737:                 $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
                   3738:                 $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
                   3739:             }
                   3740:             if (keys(%newdata)) {
                   3741:                 my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
                   3742:                                                    $coursenum);
                   3743:                 if ($putres eq 'ok') {
                   3744:                     &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
                   3745:                 }
                   3746:             }
                   3747:         }
                   3748:     }
                   3749: }
                   3750: 
1.329     droeschl 3751: sub uniqueness_check {
                   3752:     my ($newurl) = @_;
                   3753:     my $unique = 1;
                   3754:     foreach my $res (@LONCAPA::map::order) {
                   3755:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3756:         $url=&LONCAPA::map::qtescape($url);
                   3757:         if ($newurl eq $url) {
                   3758:             $unique = 0;
1.344     bisitz   3759:             last;
1.329     droeschl 3760:         }
                   3761:     }
                   3762:     return $unique;
                   3763: }
                   3764: 
1.488     raeburn  3765: sub contained_map_check {
1.627     raeburn  3766:     my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
                   3767:         $hierarchy,$titles,$allmaps) = @_;
1.488     raeburn  3768:     my $content = &Apache::lonnet::getfile($url);
                   3769:     unless ($content eq '-1') {
                   3770:         my $parser = HTML::TokeParser->new(\$content);
                   3771:         $parser->attr_encoded(1);
                   3772:         while (my $token = $parser->get_token) {
                   3773:             next if ($token->[0] ne 'S');
                   3774:             if ($token->[1] eq 'resource') {
                   3775:                 next if ($token->[2]->{'type'} eq 'zombie');
                   3776:                 my $ressrc = $token->[2]->{'src'};
1.704     raeburn  3777:                 if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                   3778:                     my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627     raeburn  3779:                     unless ($srcdom eq $coursedom) {
                   3780:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   3781:                         next;
                   3782:                     }
1.704     raeburn  3783:                     unless ($srcnum eq $coursenum) {
                   3784:                         my %toolsettings =
                   3785:                             &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
                   3786:                         my %tooltypes = &Apache::loncommon::usable_exttools();
                   3787:                         if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                   3788:                             (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                   3789:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   3790:                             next;
                   3791:                         }
                   3792:                     }
1.627     raeburn  3793:                 } elsif ($folder =~ /^supplemental/) {
1.488     raeburn  3794:                     unless (&supp_pasteable($ressrc)) {
1.492     raeburn  3795:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488     raeburn  3796:                         next;
                   3797:                     }
                   3798:                 }
1.703     raeburn  3799:                 if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
                   3800:                     my ($srcdom,$srcnum) = ($1,$2);
                   3801:                     unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
                   3802:                         if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
                   3803:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   3804:                             next;
                   3805:                         }
                   3806:                     }
                   3807:                 }
1.492     raeburn  3808:                 if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
                   3809:                     if ($1 eq 'uploaded') {
                   3810:                         $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
                   3811:                         $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488     raeburn  3812:                     } else {
1.492     raeburn  3813:                         if ($allmaps->{$ressrc}) {
1.529     raeburn  3814:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492     raeburn  3815:                         } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
                   3816:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   3817:                         } else {
                   3818:                             $addedmaps->{$ressrc} = [$url];
                   3819:                         }
1.488     raeburn  3820:                     }
1.627     raeburn  3821:                     &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
                   3822:                                          $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488     raeburn  3823:                 }
1.492     raeburn  3824:             } elsif ($token->[1] eq 'param') {
1.488     raeburn  3825:                 if ($folder =~ /^supplemental/) {
1.492     raeburn  3826:                     if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
                   3827:                         push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
                   3828:                     } else {
                   3829:                         $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}]; 
                   3830:                     }
1.488     raeburn  3831:                 }
                   3832:             }
                   3833:         }
                   3834:     }
                   3835:     return;
                   3836: }
                   3837: 
                   3838: sub url_paste_fixups {
1.533     raeburn  3839:     my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
                   3840:         $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597     raeburn  3841:         $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491     raeburn  3842:     my $checktitle;
                   3843:     if (($prefixchg) &&
1.492     raeburn  3844:         ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491     raeburn  3845:         $checktitle = 1;
                   3846:     }
1.492     raeburn  3847:     my $skip;
                   3848:     if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
                   3849:         my $mapid = $1.$2;
                   3850:         if ($tomove->{$mapid}) {
                   3851:             $skip = 1;
                   3852:         }
                   3853:     }
1.491     raeburn  3854:     my $file = &Apache::lonnet::getfile($oldurl);
1.488     raeburn  3855:     return if ($file eq '-1');
                   3856:     my $parser = HTML::TokeParser->new(\$file);
                   3857:     $parser->attr_encoded(1);
1.491     raeburn  3858:     my $changed = 0;
1.488     raeburn  3859:     while (my $token = $parser->get_token) {
                   3860:         next if ($token->[0] ne 'S');
                   3861:         if ($token->[1] eq 'resource') {
                   3862:             my $ressrc = $token->[2]->{'src'};
                   3863:             next if ($ressrc eq '');
1.491     raeburn  3864:             my $id = $token->[2]->{'id'};
1.492     raeburn  3865:             my $title = $token->[2]->{'title'};
1.491     raeburn  3866:             if ($checktitle) {
                   3867:                 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  3868:                     $retitles->{$oldurl}{$id} = $ressrc;
1.491     raeburn  3869:                 }
                   3870:             }
1.488     raeburn  3871:             next if ($token->[2]->{'type'} eq 'external');
                   3872:             if ($token->[2]->{'type'} eq 'zombie') {
1.492     raeburn  3873:                 next if ($skip);  
1.532     raeburn  3874:                 $zombies->{$oldurl}{$id} = $ressrc;
1.491     raeburn  3875:                 $changed = 1;
                   3876:             } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  3877:                 my $srcdom = $1;
                   3878:                 my $srcnum = $2;
1.488     raeburn  3879:                 my $rem = $3;
1.492     raeburn  3880:                 my $newurl;
                   3881:                 my $mapname;
                   3882:                 if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
                   3883:                     my $prefix = $1;
                   3884:                     $mapname = $prefix.$2;
                   3885:                     if ($tomove->{$mapname}) {
1.533     raeburn  3886:                         &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   3887:                                           $srcdom,$srcnum,$allmaps,$rewrites,
                   3888:                                           $retitles,$copies,$dbcopies,$zombies,
                   3889:                                           $params,$mapmoves,$mapchanges,$tomove,
1.597     raeburn  3890:                                           $newsubdir,$newurls,$resdatacopy);
1.492     raeburn  3891:                         next;
                   3892:                     } else {
                   3893:                         ($newurl,my $error) =
                   3894:                             &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   3895:                                             $srcdom,$srcnum,\$title,$allmaps,$newurls);
                   3896:                         if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
                   3897:                             $newsubdir->{$ressrc} = $1;
                   3898:                         }
                   3899:                         if ($error) {
                   3900:                             next;
                   3901:                         }
                   3902:                     }
                   3903:                 }
                   3904:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
                   3905:                     ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
                   3906:                    
1.488     raeburn  3907:                     if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532     raeburn  3908:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.491     raeburn  3909:                         $mapchanges->{$ressrc} = 1;
1.533     raeburn  3910:                         unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
                   3911:                                                   $cnum,$srcdom,$srcnum,$allmaps,
                   3912:                                                   $rewrites,$retitles,$copies,$dbcopies,
                   3913:                                                   $zombies,$params,$mapmoves,$mapchanges,
1.597     raeburn  3914:                                                   $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491     raeburn  3915:                             $mapmoves->{$ressrc} = 1;
                   3916:                         }
                   3917:                         $changed = 1;
1.488     raeburn  3918:                     } else {
1.532     raeburn  3919:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.488     raeburn  3920:                         $copies->{$oldurl}{$ressrc} = $id;
1.491     raeburn  3921:                         $changed = 1;
1.488     raeburn  3922:                     }
                   3923:                 }
1.649     raeburn  3924:             } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533     raeburn  3925:                 next if ($skip);
1.492     raeburn  3926:                 my $srcdom = $1;
                   3927:                 my $srcnum = $2;
1.649     raeburn  3928:                 my $rem = $3;
                   3929:                 my ($is_exttool,$exttoolchg);
                   3930:                 if ($rem =~ m{\d+/ext\.tool$}) {
1.655     raeburn  3931:                     $is_exttool = 1;
1.649     raeburn  3932:                 }
1.492     raeburn  3933:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532     raeburn  3934:                     $rewrites->{$oldurl}{$id} = $ressrc;
1.533     raeburn  3935:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   3936:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   3937:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   3938:                     $changed = 1;
1.649     raeburn  3939:                     if ($is_exttool) {
                   3940:                         $exttoolchg = 1;
                   3941:                     }
1.700     raeburn  3942:                 } elsif (($is_exttool) &&
1.649     raeburn  3943:                          ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   3944:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   3945:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   3946:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   3947:                     $changed = 1;
                   3948:                     $exttoolchg = 1;
                   3949:                 }
                   3950:                 if (($is_exttool) && ($prefixchg)) {
                   3951:                     if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
                   3952:                         if ($exttoolchg) {
                   3953:                             $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
                   3954:                         }
                   3955:                     }
1.533     raeburn  3956:                 }
                   3957:             } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
                   3958:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
                   3959:                     ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   3960:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   3961:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   3962:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491     raeburn  3963:                     $changed = 1;
1.488     raeburn  3964:                 }
1.597     raeburn  3965:             } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
                   3966:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
                   3967:                     $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
                   3968:                     $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   3969:                     $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
                   3970:                 }
1.488     raeburn  3971:             } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  3972:                 next if ($skip);
                   3973:                 my $srcdom = $1;
                   3974:                 my $srcnum = $2;
                   3975:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533     raeburn  3976:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   3977:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   3978:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491     raeburn  3979:                     $changed = 1;
1.488     raeburn  3980:                 }
                   3981:             }
                   3982:         } elsif ($token->[1] eq 'param') {
1.492     raeburn  3983:             next if ($skip);
1.488     raeburn  3984:             my $to = $token->[2]->{'to'}; 
                   3985:             if ($to ne '') {
                   3986:                 if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492     raeburn  3987:                     push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488     raeburn  3988:                 } else {
                   3989:                     @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
                   3990:                 }
                   3991:             }
                   3992:         }
                   3993:     }
1.491     raeburn  3994:     return $changed;
1.488     raeburn  3995: }
                   3996: 
                   3997: sub apply_fixups {
1.529     raeburn  3998:     my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
                   3999:         $oldurl,$url,$caller) = @_;
                   4000:     my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533     raeburn  4001:         %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704     raeburn  4002:         %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
                   4003:         %currltititles,$currltimax);
                   4004:     $currltimax = 0;
1.529     raeburn  4005:     if (ref($updated) eq 'HASH') {
                   4006:         if (ref($updated->{'rewrites'}) eq 'HASH') {
                   4007:             %rewrites = %{$updated->{'rewrites'}};
                   4008:         }
                   4009:         if (ref($updated->{'zombies'}) eq 'HASH') {
                   4010:             %zombies = %{$updated->{'zombies'}};
                   4011:         }
                   4012:         if (ref($updated->{'removefrommap'}) eq 'HASH') {
                   4013:             %removefrommap = %{$updated->{'removefrommap'}};
                   4014:         }
                   4015:         if (ref($updated->{'removeparam'}) eq 'HASH') {
                   4016:             %removeparam = %{$updated->{'removeparam'}};
                   4017:         }
                   4018:         if (ref($updated->{'dbcopies'}) eq 'HASH') {
                   4019:             %dbcopies = %{$updated->{'dbcopies'}};
                   4020:         }
                   4021:         if (ref($updated->{'retitles'}) eq 'HASH') {
                   4022:             %retitles = %{$updated->{'retitles'}};
                   4023:         }
1.597     raeburn  4024:         if (ref($updated->{'resdatacopy'}) eq 'HASH') {
                   4025:             %resdatacopy = %{$updated->{'resdatacopy'}};
                   4026:         }
1.529     raeburn  4027:     }
                   4028:     if (ref($info) eq 'HASH') {
                   4029:         if (ref($info->{'newsubdir'}) eq 'HASH') {
                   4030:             %newsubdir = %{$info->{'newsubdir'}};
                   4031:         }
                   4032:         if (ref($info->{'params'}) eq 'HASH') {
                   4033:             %params = %{$info->{'params'}};
                   4034:         }
                   4035:         if (ref($info->{'before'}) eq 'HASH') {
                   4036:             %before = %{$info->{'before'}};
                   4037:         }
                   4038:         if (ref($info->{'after'}) eq 'HASH') {
                   4039:             %after = %{$info->{'after'}};
                   4040:         }
                   4041:     }
                   4042:     if (ref($moves) eq 'HASH') {
                   4043:         if (ref($moves->{'copies'}) eq 'HASH') {
                   4044:             %copies = %{$moves->{'copies'}};
                   4045:         }
                   4046:         if (ref($moves->{'docmoves'}) eq 'HASH') {
                   4047:             %docmoves = %{$moves->{'docmoves'}};
                   4048:         }
                   4049:         if (ref($moves->{'mapmoves'}) eq 'HASH') {
                   4050:             %mapmoves = %{$moves->{'mapmoves'}};
                   4051:         }
                   4052:     }
                   4053:     foreach my $key (keys(%copies),keys(%docmoves)) {
1.491     raeburn  4054:         my @allcopies;
1.529     raeburn  4055:         if (exists($copies{$key})) {
                   4056:             if (ref($copies{$key}) eq 'HASH') {
                   4057:                 my %added;
                   4058:                 foreach my $innerkey (keys(%{$copies{$key}})) {
                   4059:                     if (($innerkey ne '') && (!$added{$innerkey})) {
                   4060:                         push(@allcopies,$innerkey);
                   4061:                         $added{$innerkey} = 1;
                   4062:                     }
1.491     raeburn  4063:                 }
1.529     raeburn  4064:                 undef(%added);
1.491     raeburn  4065:             }
                   4066:         }
                   4067:         if ($key eq $oldurl) {
1.529     raeburn  4068:             if ((exists($docmoves{$key}))) {
1.532     raeburn  4069:                 unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491     raeburn  4070:                     push(@allcopies,$oldurl);
                   4071:                 }
                   4072:             }
                   4073:         }
                   4074:         if (@allcopies > 0) {
                   4075:             foreach my $item (@allcopies) {
1.492     raeburn  4076:                 my ($relpath,$oldsubdir,$fname) = 
                   4077:                     ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491     raeburn  4078:                 if ($fname ne '') {
                   4079:                     my $content = &Apache::lonnet::getfile($item);
                   4080:                     unless ($content eq '-1') {
                   4081:                         my $storefn;
1.529     raeburn  4082:                         if (($key eq $oldurl) && (exists($docmoves{$key}))) {
                   4083:                             $storefn = $docmoves{$key};
1.491     raeburn  4084:                         } else {
                   4085:                             $storefn = $relpath;
                   4086:                             $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  4087:                             if ($prefixchg && $before{'doc'} && $after{'doc'}) {
                   4088:                                 $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491     raeburn  4089:                             }
1.529     raeburn  4090:                             if ($newsubdir{$key}) {
1.532     raeburn  4091:                                 $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491     raeburn  4092:                             }
                   4093:                         }
                   4094:                         &copy_dependencies($item,$storefn,$relpath,$errors,\$content);
                   4095:                         my $copyurl = 
                   4096:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},
                   4097:                                                                $storefn.$fname,$content);
                   4098:                         if ($copyurl eq '/adm/notfound.html') {
1.529     raeburn  4099:                             if (exists($docmoves{$oldurl})) {
1.491     raeburn  4100:                                 return &mt('Paste failed: an error occurred copying the file.');
                   4101:                             } elsif (ref($errors) eq 'HASH') {
                   4102:                                 $errors->{$item} = 1;
1.489     raeburn  4103:                             }
                   4104:                         }
1.488     raeburn  4105:                     }
                   4106:                 }
1.491     raeburn  4107:             }
                   4108:         }
                   4109:     }
1.529     raeburn  4110:     foreach my $key (keys(%mapmoves)) {
1.491     raeburn  4111:         my $storefn=$key;
                   4112:         $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  4113:         if ($prefixchg && $before{'map'} && $after{'map'}) {
                   4114:             $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  4115:         }
1.529     raeburn  4116:         if ($newsubdir{$key}) {
                   4117:             $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  4118:         }
1.491     raeburn  4119:         my $mapcontent = &Apache::lonnet::getfile($key);
1.681     raeburn  4120:         if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
                   4121:             ($after{'map'} eq 'default') &&
                   4122:             ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
                   4123:             $mapcontent = '<map>'."\n".
                   4124:                           '<resource id="1" src="" type="start" />'."\n".
                   4125:                           '<link from="1" to="2" index="1" />'."\n".
                   4126:                           '<resource id="2" src="" type="finish" />'."\n".
                   4127:                           '</map>';
                   4128:         }
1.491     raeburn  4129:         if ($mapcontent eq '-1') {
                   4130:             if (ref($errors) eq 'HASH') {
                   4131:                 $errors->{$key} = 1;
                   4132:             }
                   4133:         } else {
                   4134:             my $newmap =
                   4135:                 &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
                   4136:                                                    $mapcontent);
                   4137:             if ($newmap eq '/adm/notfound.html') {
                   4138:                 if (ref($errors) eq 'HASH') {
                   4139:                     $errors->{$key} = 1;
1.489     raeburn  4140:                 }
1.488     raeburn  4141:             }
                   4142:         }
                   4143:     }
1.491     raeburn  4144:     my %updates;
                   4145:     if ($is_map) {
1.529     raeburn  4146:         if (ref($updated) eq 'HASH') {
                   4147:             foreach my $type (keys(%{$updated})) {
                   4148:                 if (ref($updated->{$type}) eq 'HASH') {
                   4149:                     foreach my $key (keys(%{$updated->{$type}})) {
                   4150:                         $updates{$key} = 1;
                   4151:                     }
                   4152:                 }
                   4153:             }
1.491     raeburn  4154:         }
1.704     raeburn  4155:         my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491     raeburn  4156:         foreach my $key (keys(%updates)) {
1.492     raeburn  4157:             my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529     raeburn  4158:             if (ref($rewrites{$key}) eq 'HASH') {
                   4159:                 %torewrite = %{$rewrites{$key}};
1.491     raeburn  4160:             }
1.529     raeburn  4161:             if (ref($retitles{$key}) eq 'HASH') {
                   4162:                 %toretitle = %{$retitles{$key}};
1.491     raeburn  4163:             }
1.529     raeburn  4164:             if (ref($removefrommap{$key}) eq 'HASH') {
                   4165:                 %toremove = %{$removefrommap{$key}};
1.491     raeburn  4166:             }
1.529     raeburn  4167:             if (ref($removeparam{$key}) eq 'HASH') {
                   4168:                 %remparam = %{$removeparam{$key}};
1.492     raeburn  4169:             }
1.529     raeburn  4170:             if (ref($zombies{$key}) eq 'HASH') {
                   4171:                 %zombie = %{$zombies{$key}};
1.491     raeburn  4172:             }
1.529     raeburn  4173:             if (ref($dbcopies{$key}) eq 'HASH') {
1.533     raeburn  4174:                 foreach my $idx (keys(%{$dbcopies{$key}})) {
                   4175:                     if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704     raeburn  4176:                         my $oldurl = $dbcopies{$key}{$idx}{'src'};
                   4177:                         my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
                   4178:                         my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
                   4179:                         my $oldmarker;
                   4180:                         if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
                   4181:                             $oldmarker = $1;
                   4182:                             unless (($gotcrsltitools) ||
                   4183:                                     (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
                   4184:                                 my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
                   4185:                                 if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
                   4186:                                     unless ($gotcrsltitools) {
                   4187:                                         %currcrsltitools =
                   4188:                                             &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
                   4189:                                         foreach my $item (sort(keys(%currcrsltitools))) {
                   4190:                                             if (ref($currcrsltitools{$item}) eq 'HASH') {
                   4191:                                                 $currltimax ++;
                   4192:                                                 if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
                   4193:                                                     push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
                   4194:                                                 } else {
                   4195:                                                     $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
                   4196:                                                 }
                   4197:                                             }
                   4198:                                         }
                   4199:                                         $gotcrsltitools = 1;
                   4200:                                     }
                   4201:                                     unless ($checkedsameinst) {
                   4202:                                         my $primary_id = &Apache::lonnet::domain($cdom,'primary');
                   4203:                                         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   4204:                                         if ($intdom ne '') {
                   4205:                                             my $internet_names =
                   4206:                                                 &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   4207:                                             if (ref($internet_names) eq 'ARRAY') {
                   4208:                                                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   4209:                                                     $same_institution = 1;
                   4210:                                                 }
                   4211:                                             }
                   4212:                                         }
                   4213:                                         $checkedsameinst = 1;
                   4214:                                     }
                   4215:                                 }
                   4216:                             }
                   4217:                         }
1.533     raeburn  4218:                         my ($newurl,$result,$errtext) =
1.704     raeburn  4219:                             &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
                   4220:                                     \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533     raeburn  4221:                         if ($result eq 'ok') {
                   4222:                             $newdb{$idx} = $newurl;
1.704     raeburn  4223:                             if ($newurl =~ /ext\.tool$/) {
                   4224:                                 if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
                   4225:                                     if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
                   4226:                                         my $newmarker = $1;
                   4227:                                         unless ($oldmarker eq $newmarker) {
                   4228:                                             $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
                   4229:                                         }
                   4230:                                     }
                   4231:                                 }
                   4232:                             }
1.533     raeburn  4233:                         } elsif (ref($errors) eq 'HASH') {
                   4234:                             $errors->{$key} = 1;
                   4235:                         }
                   4236:                         push(@msgs,$errtext);
                   4237:                     }
1.491     raeburn  4238:                 }
                   4239:             }
1.597     raeburn  4240:             if (ref($resdatacopy{$key}) eq 'HASH') {
1.664     raeburn  4241:                 my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597     raeburn  4242:                 foreach my $idx (keys(%{$resdatacopy{$key}})) {
                   4243:                     if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
                   4244:                         my $srcurl = $resdatacopy{$key}{$idx}{'src'};
                   4245:                         if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   4246:                             my $template = $1;
                   4247:                             if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
                   4248:                                 ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
                   4249:                                 my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
                   4250:                                 my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664     raeburn  4251:                                 unless ($gotnewmapname) {
                   4252:                                     ($newmapname) = ($key =~ m{/([^/]+)$});
                   4253:                                     ($srcfolder,$srccontainer) = split(/\./,$newmapname);
                   4254:                                     if ($newsubdir{$key}) {
                   4255:                                         $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
                   4256:                                     }
                   4257:                                     $gotnewmapname = 1;
                   4258:                                 }
1.597     raeburn  4259:                                 my $srcmapinfo = $srcfolder.':'.$idx;
                   4260:                                 if ($srccontainer eq 'page') {
                   4261:                                     $srcmapinfo .= ':1';
                   4262:                                 }
                   4263:                                 &copy_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
                   4264:                                                       $cnum,$template,$idx,$newmapname);
                   4265:                             }
                   4266:                         }
                   4267:                     }
                   4268:                 }
                   4269:             }
1.529     raeburn  4270:             if (ref($params{$key}) eq 'HASH') {
                   4271:                 %currparam = %{$params{$key}};
1.492     raeburn  4272:             }
                   4273:             my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
                   4274:             if ($fatal) {
1.533     raeburn  4275:                 return ($errtext);
1.492     raeburn  4276:             }
                   4277:             for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
                   4278:                 if (defined($LONCAPA::map::zombies[$i])) {
                   4279:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532     raeburn  4280:                     if ($zombie{$i} eq $src) {
1.492     raeburn  4281:                         undef($LONCAPA::map::zombies[$i]);
                   4282:                     }
                   4283:                 }
                   4284:             }
1.646     raeburn  4285:             my $total = scalar(@LONCAPA::map::order) - 1;
                   4286:             for (my $i=$total; $i>=0; $i--) {
1.529     raeburn  4287:                 my $idx = $LONCAPA::map::order[$i];
                   4288:                 if (defined($LONCAPA::map::resources[$idx])) {
1.492     raeburn  4289:                     my $changed;
1.529     raeburn  4290:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538     raeburn  4291:                     if ((exists($toremove{$idx})) && 
                   4292:                         ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492     raeburn  4293:                         splice(@LONCAPA::map::order,$i,1);
1.529     raeburn  4294:                         if (ref($currparam{$idx}) eq 'ARRAY') {
                   4295:                             foreach my $name (@{$currparam{$idx}}) {
1.647     raeburn  4296:                                 &LONCAPA::map::delparameter($idx,$name);
1.492     raeburn  4297:                             }
                   4298:                         }
                   4299:                         next;
                   4300:                     }
                   4301:                     my $origsrc = $src;
1.532     raeburn  4302:                     if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492     raeburn  4303:                         if ($title =~ m{^\d+\Q___&amp;&amp;&amp;___\E$match_username\Q___&amp;&amp;&amp;___\E$match_domain\Q___&amp;&amp;&amp;___\E(.+)$}) {
                   4304:                             $changed = 1;
1.491     raeburn  4305:                         }
1.492     raeburn  4306:                     }
1.532     raeburn  4307:                     if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492     raeburn  4308:                         $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
                   4309:                         if ($origsrc =~ m{^/uploaded/}) {
1.529     raeburn  4310:                             if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492     raeburn  4311:                                 if ($src =~ /\.(page|sequence)$/) {
1.529     raeburn  4312:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492     raeburn  4313:                                 } else {
1.529     raeburn  4314:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488     raeburn  4315:                                 }
1.491     raeburn  4316:                             }
1.532     raeburn  4317:                             if ($origsrc =~ /\.(page|sequence)$/) {
                   4318:                                 if ($newsubdir{$origsrc}) {
1.529     raeburn  4319:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491     raeburn  4320:                                 }
1.532     raeburn  4321:                             } elsif ($newsubdir{$key}) {
                   4322:                                 $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488     raeburn  4323:                             }
                   4324:                         }
1.492     raeburn  4325:                         $changed = 1;
1.533     raeburn  4326:                     } elsif ($newdb{$idx} ne '') {
                   4327:                         $src = $newdb{$idx};
1.492     raeburn  4328:                         $changed = 1;
                   4329:                     }
                   4330:                     if ($changed) {
1.538     raeburn  4331:                         $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492     raeburn  4332:                     }
                   4333:                 }
                   4334:             }
                   4335:             foreach my $idx (keys(%remparam)) {
                   4336:                 if (ref($remparam{$idx}) eq 'ARRAY') {
                   4337:                     foreach my $name (@{$remparam{$idx}}) {   
1.647     raeburn  4338:                         &LONCAPA::map::delparameter($idx,$name);
1.491     raeburn  4339:                     }
                   4340:                 }
                   4341:             }
1.533     raeburn  4342:             if (values(%lockerrors) > 0) {
                   4343:                 $lockmsg = join('<br />',values(%lockerrors));
                   4344:             }
1.491     raeburn  4345:             my $storefn;
                   4346:             if ($key eq $oldurl) {
                   4347:                 $storefn = $url;
                   4348:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
                   4349:             } else {
                   4350:                 $storefn = $key;
                   4351:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  4352:                 if ($prefixchg && $before{'map'} && $after{'map'}) {
                   4353:                     $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  4354:                 }
1.529     raeburn  4355:                 if ($newsubdir{$key}) {
                   4356:                     $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  4357:                 }
1.491     raeburn  4358:             }
1.492     raeburn  4359:             my $report;
                   4360:             if ($folder !~ /^supplemental/) {
                   4361:                 $report = 1;
                   4362:             }
1.527     raeburn  4363:             (my $outtext,$errtext) =
1.492     raeburn  4364:                 &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
                   4365:             if ($errtext) {
1.529     raeburn  4366:                 if ($caller eq 'paste') {
1.533     raeburn  4367:                     return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529     raeburn  4368:                 }
1.491     raeburn  4369:             }
                   4370:         }
1.704     raeburn  4371:         if (($updatetoolscache) || (@updatetoolsenc)) {
                   4372:             &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
                   4373:                                     \@updatetoolsenc);
                   4374:         }
1.491     raeburn  4375:     }
1.533     raeburn  4376:     return ('ok',\@msgs,$lockmsg);
1.491     raeburn  4377: }
                   4378: 
                   4379: sub copy_dependencies {
                   4380:     my ($item,$storefn,$relpath,$errors,$contentref) = @_;
                   4381:     my $content;
                   4382:     if (ref($contentref)) {
                   4383:         $content = $$contentref;
                   4384:     } else {
                   4385:         $content = &Apache::lonnet::getfile($item);
                   4386:     }
                   4387:     unless ($content eq '-1') {
                   4388:         my $mm = new File::MMagic;
                   4389:         my $mimetype = $mm->checktype_contents($content);
                   4390:         if ($mimetype eq 'text/html') {
                   4391:             my (%allfiles,%codebase,$state);
                   4392:             my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
                   4393:             if ($res eq 'ok') {
                   4394:                 my ($numexisting,$numpathchanges,$existing);
                   4395:                 (undef,$numexisting,$numpathchanges,$existing) =
                   4396:                     &Apache::loncommon::ask_for_embedded_content(
                   4397:                         '/adm/coursedocs',$state,\%allfiles,\%codebase,
                   4398:                         {'error_on_invalid_names'   => 1,
                   4399:                          'ignore_remote_references' => 1,
                   4400:                          'docs_url'                 => $item,
                   4401:                          'context'                  => 'paste'});
                   4402:                 if ($numexisting > 0) {
                   4403:                     if (ref($existing) eq 'HASH') {
                   4404:                         foreach my $dep (keys(%{$existing})) {
                   4405:                             my $depfile = $dep;
                   4406:                             unless ($depfile =~ m{^\Q$relpath\E}) {
                   4407:                                 $depfile = $relpath.$dep;
                   4408:                             }
                   4409:                             my $depcontent = &Apache::lonnet::getfile($depfile);
                   4410:                             unless ($depcontent eq '-1') {
                   4411:                                 my $storedep = $dep;
                   4412:                                 $storedep =~ s{^\Q$relpath\E}{};
                   4413:                                 my $dep_url =
                   4414:                                     &Apache::lonclonecourse::writefile(
                   4415:                                         $env{'request.course.id'},
                   4416:                                         $storefn.$storedep,$depcontent);
                   4417:                                 if ($dep_url eq '/adm/notfound.html') {
                   4418:                                     if (ref($errors) eq 'HASH') {
                   4419:                                         $errors->{$depfile} = 1;
                   4420:                                     }
                   4421:                                 } else {
                   4422:                                     &copy_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
                   4423:                                 }
                   4424:                             }
                   4425:                         }
1.488     raeburn  4426:                     }
                   4427:                 }
                   4428:             }
                   4429:         }
                   4430:     }
                   4431:     return;
                   4432: }
                   4433: 
1.329     droeschl 4434: my %parameter_type = ( 'randompick'     => 'int_pos',
                   4435: 		       'hiddenresource' => 'string_yesno',
                   4436: 		       'encrypturl'     => 'string_yesno',
                   4437: 		       'randomorder'    => 'string_yesno',);
                   4438: my $valid_parameters_re = join('|',keys(%parameter_type));
                   4439: # set parameters
                   4440: sub update_parameter {
1.537     raeburn  4441:     if ($env{'form.changeparms'} eq 'all') {
                   4442:         my (@allidx,@allmapidx,%allchecked,%currchecked);
                   4443:         %allchecked = (
                   4444:                          'hiddenresource' => {},
                   4445:                          'encrypturl'     => {},
                   4446:                          'randompick'     => {},
                   4447:                          'randomorder'    => {},
                   4448:                       );
                   4449:         foreach my $which (keys(%allchecked)) {
1.630     raeburn  4450:             $env{'form.all'.$which} =~ s/,$//;
1.537     raeburn  4451:             if ($which eq 'randompick') {
                   4452:                 foreach my $item (split(/,/,$env{'form.all'.$which})) {
                   4453:                     my ($res,$value) = split(/:/,$item);
                   4454:                     if ($value =~ /^\d+$/) {
                   4455:                         $allchecked{$which}{$res} = $value;
                   4456:                     }
                   4457:                 }
                   4458:             } else {
1.539     raeburn  4459:                 if ($env{'form.all'.$which}) {
                   4460:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
                   4461:                 }
1.537     raeburn  4462:             }
                   4463:         }
                   4464:         my $haschanges = 0;
                   4465:         foreach my $res (@LONCAPA::map::order) {
                   4466:             my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   4467:             $name=&LONCAPA::map::qtescape($name);
                   4468:             $url=&LONCAPA::map::qtescape($url);
1.692     raeburn  4469:             next unless $url;
1.537     raeburn  4470:             my $is_map;
                   4471:             if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   4472:                 $is_map = 1;
                   4473:             }
                   4474:             foreach my $which (keys(%allchecked)) {
                   4475:                 if (($which eq 'randompick' || $which eq 'randomorder')) {
                   4476:                     next if (!$is_map);
                   4477:                 } 
                   4478:                 my $oldvalue = 0;
                   4479:                 my $newvalue = 0;
                   4480:                 if ($allchecked{$which}{$res}) {
                   4481:                     $newvalue = $allchecked{$which}{$res};
                   4482:                 }
                   4483:                 my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
                   4484:                 if ($which eq 'randompick') {
                   4485:                     if ($current =~ /^(\d+)$/) {
                   4486:                         $oldvalue = $1;
                   4487:                     }
                   4488:                 } else {
                   4489:                     if ($current =~ /^yes$/i) {
                   4490:                         $oldvalue = 1;
                   4491:                     }
                   4492:                 }
                   4493:                 if ($oldvalue ne $newvalue) {
                   4494:                     $haschanges = 1;
                   4495:                     if ($newvalue) {
                   4496:                         my $storeval = 'yes';
                   4497:                         if ($which eq 'randompick') {
                   4498:                             $storeval = $newvalue;
                   4499:                         }
                   4500:                         &LONCAPA::map::storeparameter($res,'parameter_'.$which,
                   4501:                                                       $storeval,
                   4502:                                                       $parameter_type{$which});
                   4503:                         &remember_parms($res,$which,'set',$storeval);
                   4504:                     } elsif ($oldvalue) {
                   4505:                         &LONCAPA::map::delparameter($res,'parameter_'.$which);
                   4506:                         &remember_parms($res,$which,'del');
                   4507:                     }
                   4508:                 }
                   4509:             }
                   4510:         }
                   4511:         return $haschanges;
                   4512:     } else {
1.588     raeburn  4513:         my $haschanges = 0;
                   4514:         return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329     droeschl 4515: 
1.537     raeburn  4516:         my $which = $env{'form.changeparms'};
                   4517:         my $idx = $env{'form.setparms'};
1.588     raeburn  4518:         my $oldvalue = 0;
                   4519:         my $newvalue = 0;
                   4520:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
                   4521:         if ($which eq 'randompick') {
                   4522:             if ($current =~ /^(\d+)$/) {
                   4523:                 $oldvalue = $1;
                   4524:             }
                   4525:         } elsif ($current =~ /^yes$/i) {
                   4526:             $oldvalue = 1;
                   4527:         }
1.537     raeburn  4528:         if ($env{'form.'.$which.'_'.$idx}) {
1.588     raeburn  4529: 	    $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
                   4530: 	                                         : 1;
                   4531:         }
                   4532:         if ($oldvalue ne $newvalue) {
                   4533:             $haschanges = 1;
                   4534:             if ($newvalue) {
                   4535:                 my $storeval = 'yes';
                   4536:                 if ($which eq 'randompick') {
                   4537:                     $storeval = $newvalue;
                   4538:                 }
                   4539: 	        &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
                   4540: 				              $parameter_type{$which});
                   4541: 	        &remember_parms($idx,$which,'set',$storeval);
                   4542:             } else {
                   4543: 	        &LONCAPA::map::delparameter($idx,'parameter_'.$which);
                   4544: 	        &remember_parms($idx,$which,'del');
                   4545:             }
1.537     raeburn  4546:         }
1.588     raeburn  4547:         return $haschanges;
1.329     droeschl 4548:     }
                   4549: }
                   4550: 
                   4551: sub handle_edit_cmd {
                   4552:     my ($coursenum,$coursedom) =@_;
1.633     raeburn  4553:     my $haschanges = 0;
1.543     raeburn  4554:     if ($env{'form.cmd'} eq '') {
1.633     raeburn  4555:         return $haschanges; 
1.543     raeburn  4556:     }
1.329     droeschl 4557:     my ($cmd,$idx)=split('_',$env{'form.cmd'});
                   4558: 
                   4559:     my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                   4560:     my ($title, $url, @rrest) = split(':', $ratstr);
                   4561: 
1.538     raeburn  4562:     if ($cmd eq 'remove') {
1.329     droeschl 4563: 	if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463     www      4564: 	    ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329     droeschl 4565: 	    &Apache::lonnet::removeuploadedurl($url);
                   4566: 	} else {
                   4567: 	    &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   4568: 	}
                   4569: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  4570:         $haschanges = 1;
1.329     droeschl 4571:     } elsif ($cmd eq 'cut') {
                   4572: 	&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   4573: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  4574:         $haschanges = 1;
1.344     bisitz   4575:     } elsif ($cmd eq 'up'
1.329     droeschl 4576: 	     && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
                   4577: 	@LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633     raeburn  4578:         $haschanges = 1;
1.329     droeschl 4579:     } elsif ($cmd eq 'down'
                   4580: 	     && defined($LONCAPA::map::order[$idx+1])) {
                   4581: 	@LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633     raeburn  4582:         $haschanges = 1;
1.329     droeschl 4583:     } elsif ($cmd eq 'rename') {
                   4584: 	my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
                   4585: 	if ($comment=~/\S/) {
                   4586: 	    $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
                   4587: 		$comment.':'.join(':', $url, @rrest);
                   4588: 	}
                   4589: # Devalidate title cache
                   4590: 	my $renamed_url=&LONCAPA::map::qtescape($url);
                   4591: 	&Apache::lonnet::devalidate_title_cache($renamed_url);
1.633     raeburn  4592:         $haschanges = 1;
                   4593:     } elsif ($cmd eq 'setalias') {
                   4594:         my $newvalue = $env{'form.alias'};
                   4595:         if ($newvalue ne '') {
                   4596:             unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
                   4597:                 &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
                   4598:                                               'string');
                   4599:                 &remember_parms($idx,'mapalias','set',$newvalue);
                   4600:                 $haschanges = 1;
                   4601:             }
                   4602:         }
                   4603:     } elsif ($cmd eq 'delalias') {
                   4604:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];  
                   4605:         if ($current ne '') {
                   4606:             &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
                   4607:             &remember_parms($idx,'mapalias','del');
                   4608:             $haschanges = 1;
                   4609:         }
1.329     droeschl 4610:     }
1.633     raeburn  4611:     return $haschanges;
1.329     droeschl 4612: }
                   4613: 
                   4614: sub editor {
1.458     raeburn  4615:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615     raeburn  4616:         $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622     raeburn  4617:         $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519     raeburn  4618:     my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510     raeburn  4619:     if ($allowed) {
1.519     raeburn  4620:         (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   4621:          $is_random_order,$container) =
1.510     raeburn  4622:             &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   4623:         $r->print($breadcrumbtrail);
1.519     raeburn  4624:     } elsif ($env{'form.folderpath'} =~ /\:1$/) {
                   4625:         $container = 'page'; 
                   4626:     } else {
                   4627:         $container = 'sequence';
1.510     raeburn  4628:     }
1.484     raeburn  4629: 
1.525     raeburn  4630:     my $jumpto;
                   4631: 
                   4632:     unless ($supplementalflag) {
1.546     raeburn  4633:         $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525     raeburn  4634:     }
1.484     raeburn  4635: 
                   4636:     unless ($allowed) {
                   4637:         $randompick = -1;
                   4638:     }
                   4639: 
1.615     raeburn  4640:     my ($errtext,$fatal);
                   4641:     if (($folder eq '') && (!$supplementalflag)) {
                   4642:         if (@LONCAPA::map::order) {
                   4643:             undef(@LONCAPA::map::order);
                   4644:             undef(@LONCAPA::map::resources);
                   4645:             undef(@LONCAPA::map::resparms);
                   4646:             undef(@LONCAPA::map::zombies);
                   4647:         }
                   4648:         $folder = 'default';
                   4649:         $container = 'sequence'; 
                   4650:     } else {
                   4651:         ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   4652: 				     $folder.'.'.$container);
                   4653:         return $errtext if ($fatal);
                   4654:     }
1.329     droeschl 4655: 
                   4656:     if ($#LONCAPA::map::order<1) {
                   4657: 	my $idx=&LONCAPA::map::getresidx();
                   4658: 	if ($idx<=0) { $idx=1; }
                   4659:        	$LONCAPA::map::order[0]=$idx;
                   4660:         $LONCAPA::map::resources[$idx]='';
                   4661:     }
1.364     bisitz   4662: 
1.329     droeschl 4663: # ------------------------------------------------------------ Process commands
                   4664: 
                   4665: # ---------------- if they are for this folder and user allowed to make changes
1.611     raeburn  4666:     if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329     droeschl 4667: # set parameters and change order
                   4668: 	&snapshotbefore();
                   4669: 
                   4670: 	if (&update_parameter()) {
1.588     raeburn  4671: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329     droeschl 4672: 	    return $errtext if ($fatal);
                   4673: 	}
                   4674: 
                   4675: 	if ($env{'form.newpos'} && $env{'form.currentpos'}) {
                   4676: # change order
                   4677: 	    my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
                   4678: 	    splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
                   4679: 
                   4680: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
                   4681: 	    return $errtext if ($fatal);
                   4682: 	}
1.364     bisitz   4683: 
1.329     droeschl 4684: 	if ($env{'form.pastemarked'}) {
1.491     raeburn  4685:             my %paste_errors;
1.533     raeburn  4686:             my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492     raeburn  4687:                 &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
                   4688:                                       \%paste_errors);
1.541     raeburn  4689:             if (ref($pastemsgarray) eq 'ARRAY') {
                   4690:                 if (@{$pastemsgarray} > 0) {
                   4691:                     $r->print('<p class="LC_info">'.
                   4692:                               join('<br />',@{$pastemsgarray}).
1.533     raeburn  4693:                               '</p>');
                   4694:                 }
1.541     raeburn  4695:             }
                   4696:             if ($lockerror) {
                   4697:                 $r->print('<p class="LC_error">'.
                   4698:                           $lockerror.
                   4699:                           '</p>');
                   4700:             }
                   4701:             if ($save_error ne '') {
                   4702:                 return $save_error; 
                   4703:             }
                   4704:             if ($paste_res) {
                   4705:                 my %errortext = &Apache::lonlocal::texthash (
                   4706:                                     fail      => 'Storage of folder contents failed',
                   4707:                                     failread  => 'Reading folder contents failed',
                   4708:                                     failstore => 'Storage of folder contents failed',
                   4709:                                 );
                   4710:                 if ($errortext{$paste_res}) {
                   4711:                     $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492     raeburn  4712:                 }
1.329     droeschl 4713:             }
1.491     raeburn  4714:             if (keys(%paste_errors) > 0) {
1.538     raeburn  4715:                 $r->print('<p class="LC_warning">'."\n".
1.491     raeburn  4716:                           &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".
                   4717:                           '<ul>'."\n");
                   4718:                 foreach my $key (sort(keys(%paste_errors))) {
                   4719:                     $r->print('<li>'.$key.'</li>'."\n");
                   4720:                 }
                   4721:                 $r->print('</ul></p>'."\n");
                   4722:             }
1.538     raeburn  4723: 	} elsif ($env{'form.clearmarked'}) {
                   4724:             my $output = &do_buffer_empty();
                   4725:             if ($output) {
                   4726:                 $r->print('<p class="LC_info">'.$output.'</p>');
                   4727:             }
                   4728:         }
1.329     droeschl 4729: 
                   4730: 	$r->print($upload_output);
                   4731: 
1.538     raeburn  4732: # Rename, cut, copy or remove a single resource
1.602     raeburn  4733: 	if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492     raeburn  4734:             my $contentchg;
1.633     raeburn  4735:             if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492     raeburn  4736:                 $contentchg = 1;
                   4737:             }
                   4738: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329     droeschl 4739: 	    return $errtext if ($fatal);
                   4740: 	}
1.538     raeburn  4741: 
                   4742: # Cut, copy and/or remove multiple resources
                   4743:         if ($env{'form.multichange'}) {
                   4744:             my %allchecked = (
                   4745:                                cut     => {},
                   4746:                                remove  => {},
                   4747:                              );
                   4748:             my $needsupdate;
                   4749:             foreach my $which (keys(%allchecked)) {
                   4750:                 $env{'form.multi'.$which} =~ s/,$//;
                   4751:                 if ($env{'form.multi'.$which}) {
                   4752:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
                   4753:                     if (ref($allchecked{$which}) eq 'HASH') {
                   4754:                         $needsupdate += scalar(keys(%{$allchecked{$which}}));
                   4755:                     }
                   4756:                 }
                   4757:             }
                   4758:             if ($needsupdate) {
                   4759:                 my $haschanges = 0;
                   4760:                 my %curr_groups = &Apache::longroup::coursegroups();
                   4761:                 my $total = scalar(@LONCAPA::map::order) - 1; 
                   4762:                 for (my $i=$total; $i>=0; $i--) {
                   4763:                     my $res = $LONCAPA::map::order[$i];
                   4764:                     my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   4765:                     $name=&LONCAPA::map::qtescape($name);
                   4766:                     $url=&LONCAPA::map::qtescape($url);
1.586     droeschl 4767:                     next unless $url;
1.538     raeburn  4768:                     my %denied =
                   4769:                         &action_restrictions($coursenum,$coursedom,$url,
                   4770:                                              $env{'form.folderpath'},\%curr_groups);
                   4771:                     foreach my $which (keys(%allchecked)) {
                   4772:                         next if ($denied{$which});
                   4773:                         next unless ($allchecked{$which}{$res});
                   4774:                         if ($which eq 'remove') {
                   4775:                             if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   4776:                                 ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   4777:                                 &Apache::lonnet::removeuploadedurl($url);
                   4778:                             } else {
                   4779:                                 &LONCAPA::map::makezombie($res);
                   4780:                             }
                   4781:                             splice(@LONCAPA::map::order,$i,1);
                   4782:                             $haschanges ++;
                   4783:                         } elsif ($which eq 'cut') {
                   4784:                             &LONCAPA::map::makezombie($res);
                   4785:                             splice(@LONCAPA::map::order,$i,1);
                   4786:                             $haschanges ++;
                   4787:                         }
                   4788:                     }
                   4789:                 }
                   4790:                 if ($haschanges) {
                   4791:                     ($errtext,$fatal) = 
                   4792:                         &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   4793:                     return $errtext if ($fatal);
                   4794:                 }
                   4795:             }
                   4796:         }
                   4797: 
1.329     droeschl 4798: # Group import/search
                   4799: 	if ($env{'form.importdetail'}) {
                   4800: 	    my @imports;
                   4801: 	    foreach my $item (split(/\&/,$env{'form.importdetail'})) {
                   4802: 		if (defined($item)) {
                   4803: 		    my ($name,$url,$residx)=
1.533     raeburn  4804: 			map { &unescape($_); } split(/\=/,$item);
                   4805:                     if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
                   4806:                         my ($suffix,$errortxt,$locknotfreed) =
                   4807:                             &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504     raeburn  4808:                         if ($locknotfreed) {
                   4809:                             $r->print($locknotfreed);
                   4810:                         }
                   4811:                         if ($suffix) {
                   4812:                             $url =~ s/_new\./_$suffix./; 
                   4813:                         } else {
                   4814:                             return $errortxt;
                   4815:                         }
1.533     raeburn  4816:                     } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
                   4817:                         my $type = $1;
                   4818:                         my ($suffix,$errortxt,$locknotfreed) =
                   4819:                             &new_timebased_suffix($coursedom,$coursenum,$type);
                   4820:                         if ($locknotfreed) {
                   4821:                             $r->print($locknotfreed);
                   4822:                         }
                   4823:                         if ($suffix) {
                   4824:                             $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
                   4825:                         } else {
                   4826:                             return $errortxt;
                   4827:                         }
1.626     raeburn  4828:                     } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598     raeburn  4829:                         my ($suffix,$errortxt,$locknotfreed) =
                   4830:                             &new_timebased_suffix($coursedom,$coursenum,'exttool');
                   4831:                         if ($locknotfreed) {
                   4832:                             $r->print($locknotfreed);
                   4833:                         }
                   4834:                         if ($suffix) {
                   4835:                             $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
                   4836:                         } else {
                   4837:                             return $errortxt;
                   4838:                         }
1.534     raeburn  4839:                     } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
                   4840:                         if ($supplementalflag) {
                   4841:                             next unless ($1 eq 'supplemental');
                   4842:                             if ($folder eq 'supplemental') {
                   4843:                                 next unless ($2 eq 'default');
                   4844:                             } else {
                   4845:                                 next unless ($folder eq 'supplemental_'.$2);
                   4846:                             }
                   4847:                         } else {
                   4848:                             next unless ($1 eq 'docs');
                   4849:                             if ($folder eq 'default') {
                   4850:                                 next unless ($2 eq 'default');
                   4851:                             } else {
                   4852:                                 next unless ($folder eq 'default_'.$2);
                   4853:                             }
                   4854:                         }
1.504     raeburn  4855:                     }
1.329     droeschl 4856: 		    push(@imports, [$name, $url, $residx]);
                   4857: 		}
                   4858: 	    }
1.530     raeburn  4859:             ($errtext,$fatal,my $fixuperrors) =
1.529     raeburn  4860:                 &group_import($coursenum, $coursedom, $folder,$container,
1.598     raeburn  4861:                               'londocs',$ltitoolsref,@imports);
1.329     droeschl 4862: 	    return $errtext if ($fatal);
1.529     raeburn  4863:             if ($fixuperrors) {
                   4864:                 $r->print($fixuperrors);
                   4865:             }
1.329     droeschl 4866: 	}
                   4867: # Loading a complete map
                   4868: 	if ($env{'form.loadmap'}) {
                   4869: 	    if ($env{'form.importmap'}=~/\w/) {
                   4870: 		foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
                   4871: 		    my ($title,$url,$ext,$type)=split(/\:/,$res);
                   4872: 		    my $idx=&LONCAPA::map::getresidx($url);
                   4873: 		    $LONCAPA::map::resources[$idx]=$res;
                   4874: 		    $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
                   4875: 		}
                   4876: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  4877: 					    $folder.'.'.$container,1);
1.329     droeschl 4878: 		return $errtext if ($fatal);
                   4879: 	    } else {
                   4880: 		$r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364     bisitz   4881: 
1.329     droeschl 4882: 	    }
                   4883: 	}
                   4884: 	&log_differences($plain);
                   4885:     }
                   4886: # ---------------------------------------------------------------- End commands
                   4887: # ---------------------------------------------------------------- Print screen
                   4888:     my $idx=0;
                   4889:     my $shown=0;
                   4890:     if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381     bisitz   4891: 	$r->print('<div class="LC_Box">'.
1.432     raeburn  4892:           '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
                   4893: 		  ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
                   4894: 		  ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
                   4895: 		  ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
                   4896: 		  ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431     raeburn  4897: 		  '</ol>');
1.381     bisitz   4898:         if ($randompick>=0) {
                   4899:             $r->print('<p class="LC_warning">'
                   4900:                  .&mt('Caution: this folder is set to randomly pick a subset'
                   4901:                      .' of resources. Adding or removing resources from this'
                   4902:                      .' folder will change the set of resources that the'
                   4903:                      .' students see, resulting in spurious or missing credit'
                   4904:                      .' for completed problems, not limited to ones you'
                   4905:                      .' modify. Do not modify the contents of this folder if'
                   4906:                      .' it is in active student use.')
                   4907:                  .'</p>'
                   4908:             );
                   4909:         }
                   4910:         if ($is_random_order) {
                   4911:             $r->print('<p class="LC_warning">'
                   4912:                  .&mt('Caution: this folder is set to randomly order its'
                   4913:                      .' contents. Adding or removing resources from this folder'
                   4914:                      .' will change the order of resources shown.')
                   4915:                  .'</p>'
                   4916:             );
                   4917:         }
                   4918:         $r->print('</div>');
1.364     bisitz   4919:     }
1.381     bisitz   4920: 
1.685     raeburn  4921:     if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688     raeburn  4922:         my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn  4923:         if (ref($supplemental) eq 'HASH') {
                   4924:             if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
                   4925:                 (ref($supplemental->{'ids'}) eq 'HASH')) {
                   4926:                 if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
                   4927:                     my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
                   4928:                     if ($supplemental->{'hidden'}->{$mapnum}) {
                   4929:                         $ishidden = 1;
                   4930:                     }
                   4931:                 }
                   4932:             }
                   4933:         }
                   4934:     }
                   4935: 
1.538     raeburn  4936:     my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
                   4937:     %filters =  (
1.543     raeburn  4938:                   canremove      => [],
                   4939:                   cancut         => [],
                   4940:                   cancopy        => [],
                   4941:                   hiddenresource => [],
                   4942:                   encrypturl     => [],
                   4943:                   randomorder    => [],
                   4944:                   randompick     => [],
1.538     raeburn  4945:                 );
                   4946:     %curr_groups = &Apache::longroup::coursegroups();
1.424     onken    4947:     &Apache::loncommon::start_data_table_count(); #setup a row counter 
1.381     bisitz   4948:     foreach my $res (@LONCAPA::map::order) {
                   4949:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   4950:         $name=&LONCAPA::map::qtescape($name);
                   4951:         $url=&LONCAPA::map::qtescape($url);
                   4952:         unless ($name) {  $name=(split(/\//,$url))[-1]; }
                   4953:         unless ($name) { $idx++; next; }
1.537     raeburn  4954:         push(@allidx,$res);
                   4955:         if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   4956:             push(@allmapidx,$res);
                   4957:         }
1.617     raeburn  4958: 
1.682     raeburn  4959:         if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685     raeburn  4960:             if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
                   4961:                 $idx++;
                   4962:                 next;
                   4963:             }
1.682     raeburn  4964:         }
1.381     bisitz   4965:         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501     raeburn  4966:                               $coursenum,$coursedom,$crstype,
1.538     raeburn  4967:                               $pathitem,$supplementalflag,$container,
1.620     raeburn  4968:                               \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685     raeburn  4969:                               $isencrypted,$ishidden,$navmapref,$hostname);
1.381     bisitz   4970:         $idx++;
                   4971:         $shown++;
1.329     droeschl 4972:     }
1.424     onken    4973:     &Apache::loncommon::end_data_table_count();
1.510     raeburn  4974: 
1.538     raeburn  4975:     my $need_save;
1.611     raeburn  4976:     if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544     raeburn  4977:         my $toolslink;
1.682     raeburn  4978:         if ($allowed || $canedit) {
                   4979:             my $helpitem = 'Navigation_Screen';
                   4980:             if (!$allowed) {
                   4981:                 $helpitem = 'Supplemental_Navigation';
                   4982:             }
1.723   ! raeburn  4983:             $toolslink = '<div class="LC_navtools">'
        !          4984:                        .'<div class="LC_navtools">'
1.520     raeburn  4985:                        .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682     raeburn  4986:                                                            $helpitem,undef,'RAT')
1.723   ! raeburn  4987:                        .'</div><div class="LC_navtools">'.&mt('Tools:').'</div>'
        !          4988:                        .'<div class="LC_navtools">'."\n".'<ul id="LC_toolbar">' 
1.525     raeburn  4989:                        .'<li><a href="/adm/coursedocs?forcesupplement=1&amp;command=editsupp" '
1.520     raeburn  4990:                        .'id="LC_content_toolbar_edittoplevel" '
                   4991:                        .'class="LC_toolbarItem" '
                   4992:                        .'title="'.&mt('Supplemental Content Editor').'">'
1.723   ! raeburn  4993:                        .'</a></li></ul></div></div>'."\n"
        !          4994:                        .'<div style="padding:0;clear:both;margin:0;border:0"></div><br />'."\n";
1.544     raeburn  4995:         }
1.510     raeburn  4996:         if ($shown) {
                   4997:             if ($allowed) {
                   4998:                 $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
                   4999:                           .&Apache::loncommon::start_data_table(undef,'contentlist')
                   5000:                           .&Apache::loncommon::start_data_table_header_row()
                   5001:                           .'<th colspan="2">'.&mt('Move').'</th>'
1.633     raeburn  5002:                           .'<th colspan="3">'.&mt('Actions').'</th>'
1.682     raeburn  5003:                           .'<th>'.&mt('Document').'</th>'
                   5004:                           .'<th colspan="2">'.&mt('Settings').'</th>'
                   5005:                           .&Apache::loncommon::end_data_table_header_row();
1.537     raeburn  5006:                 if ($folder !~ /^supplemental/) {
1.538     raeburn  5007:                     $lists{'canhide'} = join(',',@allidx);
                   5008:                     $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543     raeburn  5009:                     my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
                   5010:                                        'randomorder','randompick');
                   5011:                     foreach my $item (@possfilters) {
1.538     raeburn  5012:                         if (ref($filters{$item}) eq 'ARRAY') {
1.543     raeburn  5013:                             if (@{$filters{$item}} > 0) {
                   5014:                                 $lists{$item} = join(',',@{$filters{$item}});
                   5015:                             }
1.538     raeburn  5016:                         }
                   5017:                     }
1.537     raeburn  5018:                     if (@allidx > 0) {
                   5019:                         my $path;
                   5020:                         if ($env{'form.folderpath'}) {
1.630     raeburn  5021:                             $path =
1.537     raeburn  5022:                                 &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   5023:                         }
1.538     raeburn  5024:                         if (@allidx > 1) {
1.630     raeburn  5025:                             $to_show .=
1.538     raeburn  5026:                                 &Apache::loncommon::continue_data_table_row().
                   5027:                                 '<td colspan="2">&nbsp;</td>'.
                   5028:                                 '<td>'.
1.611     raeburn  5029:                                 &multiple_check_form('actions',\%lists,$canedit).
1.538     raeburn  5030:                                 '</td>'.
1.633     raeburn  5031:                                 '<td colspan="3">&nbsp;</td>'.
                   5032:                                 '<td colspan="2">'.
1.611     raeburn  5033:                                 &multiple_check_form('settings',\%lists,$canedit).
1.538     raeburn  5034:                                 '</td>'.
                   5035:                                 &Apache::loncommon::end_data_table_row();
                   5036:                              $need_save = 1;
                   5037:                         }
1.537     raeburn  5038:                     }
                   5039:                 }
                   5040:                 $to_show .= $output.' '
1.510     raeburn  5041:                            .&Apache::loncommon::end_data_table()
                   5042:                            .'<br style="line-height:2px;" />'
                   5043:                            .&Apache::loncommon::end_scrollbox();
                   5044:             } else {
1.520     raeburn  5045:                 $to_show .= $toolslink
1.510     raeburn  5046:                            .&Apache::loncommon::start_data_table('LC_tableOfContent')
                   5047:                            .$output.' '
                   5048:                            .&Apache::loncommon::end_data_table();
1.393     raeburn  5049:             }
1.510     raeburn  5050:         } else {
1.520     raeburn  5051:             if (!$allowed) {
                   5052:                 $to_show .= $toolslink;
                   5053:             }
1.615     raeburn  5054:             my $noresmsg;
                   5055:             if ($allowed && $hiddentop && !$supplementalflag) {
                   5056:                 $noresmsg = &mt('Main Content Hidden'); 
                   5057:             } else {
                   5058:                 $noresmsg = &mt('Currently empty');
                   5059:             }
1.510     raeburn  5060:             $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
                   5061:                        .'<div class="LC_info" id="contentlist">'
1.615     raeburn  5062:                        .$noresmsg
1.510     raeburn  5063:                        .'</div>'
                   5064:                        .&Apache::loncommon::end_scrollbox();
1.393     raeburn  5065:         }
                   5066:     } else {
1.510     raeburn  5067:         if ($shown) {
                   5068:             $to_show = '<div>'
                   5069:                       .&Apache::loncommon::start_data_table('LC_tableOfContent')
                   5070:                       .$output
                   5071:                       .&Apache::loncommon::end_data_table()
                   5072:                       .'</div>';
                   5073:         } else {
                   5074:             $to_show = '<div class="LC_info" id="contentlist">'
1.550     raeburn  5075:                       .&mt('Currently empty')
1.510     raeburn  5076:                       .'</div>'
                   5077:         }
1.458     raeburn  5078:     }
                   5079:     my $tid = 1;
                   5080:     if ($supplementalflag) {
                   5081:         $tid = 2;
1.329     droeschl 5082:     }
                   5083:     if ($allowed) {
1.484     raeburn  5084:         my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538     raeburn  5085:         $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611     raeburn  5086:                                        $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
                   5087:         if ($canedit) {
                   5088:             &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
                   5089:         }
1.460     raeburn  5090:     } else {
                   5091:         $r->print($to_show);
1.329     droeschl 5092:     }
                   5093:     return;
                   5094: }
                   5095: 
1.538     raeburn  5096: sub multiple_check_form {
1.611     raeburn  5097:     my ($caller,$listsref,$canedit) = @_;
1.538     raeburn  5098:     return unless (ref($listsref) eq 'HASH');
1.611     raeburn  5099:     my $disabled;
                   5100:     unless ($canedit) {
1.700     raeburn  5101:         $disabled = ' disabled="disabled"';
1.611     raeburn  5102:     }
1.538     raeburn  5103:     my $output =
                   5104:     '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
                   5105:     '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
                   5106:     '<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>'.
                   5107:     '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
                   5108:     '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
                   5109:     '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
                   5110:     if ($caller eq 'settings') {
                   5111:         $output .= 
                   5112:             '<table><tr>'.
                   5113:             '<td class="LC_docs_entry_parameter">'.
                   5114:             '<span class="LC_nobreak"><label>'.
1.611     raeburn  5115:             '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538     raeburn  5116:             '</label></span></td>'.
                   5117:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  5118:             '<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  5119:             '</span></td>'.
                   5120:             '</tr>'."\n".
                   5121:             '<tr>'.
                   5122:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  5123:             '<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  5124:             '</label></span>'.
                   5125:             '</td></tr></table>'."\n";
                   5126:     } else {
                   5127:         $output .=
                   5128:             '<table><tr>'.
                   5129:             '<td class="LC_docs_entry_parameter">'.
                   5130:             '<span class="LC_nobreak LC_docs_remove">'.
1.611     raeburn  5131:             '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538     raeburn  5132:             '</label></span></td>'.
                   5133:             '<td class="LC_docs_entry_parameter">'.
                   5134:             '<span class="LC_nobreak LC_docs_cut">'.
1.611     raeburn  5135:             '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538     raeburn  5136:             '</label></span></td>'."\n".
                   5137:             '<td class="LC_docs_entry_parameter">'.
                   5138:             '<span class="LC_nobreak LC_docs_copy">'.
1.700     raeburn  5139:             '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538     raeburn  5140:             '</label></span></td>'.
                   5141:             '</tr></table>'."\n";
                   5142:     }
                   5143:     $output .= 
                   5144:         '</fieldset>'.
                   5145:         '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
                   5146:     if ($caller eq 'settings') {
                   5147:         $output .= 
1.543     raeburn  5148:         '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
                   5149:         '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
                   5150:         '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
                   5151:         '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
                   5152:         '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538     raeburn  5153:     } elsif ($caller eq 'actions') {
                   5154:         $output .=
                   5155:         '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
                   5156:         '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
                   5157:         '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
                   5158:     }
                   5159:     $output .= 
                   5160:         '</form>'.
                   5161:         '</div>';
                   5162:     return $output;
                   5163: }
                   5164: 
1.329     droeschl 5165: sub process_file_upload {
1.552     raeburn  5166:     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329     droeschl 5167: # upload a file, if present
1.552     raeburn  5168:     my $filesize = length($env{'form.uploaddoc'});
                   5169:     if (!$filesize) {
                   5170:         $$upload_output = '<div class="LC_error">'.
                   5171:                            &mt('Unable to upload [_1]. (size = [_2] bytes)',
                   5172:                           '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
                   5173:                           $filesize).'<br />'.
                   5174:                           &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
                   5175:                           '</div>';
                   5176:         return;
                   5177:     }
                   5178:     my $quotatype = 'unofficial';
                   5179:     if ($crstype eq 'Community') {
1.601     raeburn  5180:         $quotatype = 'community';
                   5181:     } elsif ($crstype eq 'Placement') {
                   5182:         $quotatype = 'placement';
1.580     raeburn  5183:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552     raeburn  5184:         $quotatype = 'official';
1.573     raeburn  5185:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   5186:         $quotatype = 'textbook';
1.552     raeburn  5187:     }
                   5188:     if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
                   5189:         $filesize = int($filesize/1000); #expressed in kb
                   5190:         $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579     raeburn  5191:                                                                       $env{'form.uploaddoc.filename'},$filesize,
                   5192:                                                                       'upload',$quotatype);
1.552     raeburn  5193:         return if ($$upload_output);
                   5194:     }
1.440     raeburn  5195:     my ($parseaction,$showupload,$nextphase,$mimetype);
                   5196:     if ($env{'form.parserflag'}) {
1.329     droeschl 5197:         $parseaction = 'parse';
                   5198:     }
                   5199:     my $folder=$env{'form.folder'};
                   5200:     if ($folder eq '') {
                   5201:         $folder='default';
                   5202:     }
                   5203:     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
                   5204:         my $errtext='';
                   5205:         my $fatal=0;
                   5206:         my $container='sequence';
1.519     raeburn  5207:         if ($env{'form.folderpath'} =~ /:1$/) {
1.329     droeschl 5208:             $container='page';
                   5209:         }
                   5210:         ($errtext,$fatal)=
1.534     raeburn  5211:             &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329     droeschl 5212:         if ($#LONCAPA::map::order<1) {
                   5213:             $LONCAPA::map::order[0]=1;
                   5214:             $LONCAPA::map::resources[1]='';
                   5215:         }
                   5216:         my $destination = 'docs/';
                   5217:         if ($folder =~ /^supplemental/) {
                   5218:             $destination = 'supplemental/';
                   5219:         }
                   5220:         if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   5221:             $destination .= 'default/';
                   5222:         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   5223:             $destination .=  $2.'/';
                   5224:         }
1.534     raeburn  5225:         if ($fatal) {
                   5226:             $$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>';
                   5227:             return;
                   5228:         }
1.440     raeburn  5229: # this is for a course, not a user, so set context to coursedoc.
1.329     droeschl 5230:         my $newidx=&LONCAPA::map::getresidx();
                   5231:         $destination .= $newidx;
1.439     raeburn  5232:         my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329     droeschl 5233: 						$parseaction,$allfiles,
1.440     raeburn  5234: 						$codebase,undef,undef,undef,undef,
                   5235:                                                 undef,undef,\$mimetype);
                   5236:         if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
                   5237:             my $stored = $1;
                   5238:             $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   5239:                           $stored.'</span>').'</p>';
                   5240:         } else {
                   5241:             my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
                   5242:             
1.457     raeburn  5243:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440     raeburn  5244:             return;
                   5245:         }
1.329     droeschl 5246:         my $ext='false';
                   5247:         if ($url=~m{^http://}) { $ext='true'; }
                   5248: 	$url     = &LONCAPA::map::qtunescape($url);
                   5249:         my $comment=$env{'form.comment'};
                   5250: 	$comment = &LONCAPA::map::qtunescape($comment);
                   5251:         if ($folder=~/^supplemental/) {
                   5252:               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   5253:                   $env{'user.domain'}.'___&&&___'.$comment;
                   5254:         }
                   5255: 
                   5256:         $LONCAPA::map::resources[$newidx]=
                   5257: 	    $comment.':'.$url.':'.$ext.':normal:res';
                   5258:         $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
                   5259:         ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  5260: 				    $folder.'.'.$container,1);
1.329     droeschl 5261:         if ($fatal) {
1.457     raeburn  5262:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440     raeburn  5263:             return;
1.329     droeschl 5264:         } else {
1.440     raeburn  5265:             if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
                   5266:                 $$upload_output = $showupload;
1.384     raeburn  5267:                 my $total_embedded = scalar(keys(%{$allfiles}));
1.329     droeschl 5268:                 if ($total_embedded > 0) {
1.440     raeburn  5269:                     my $uploadphase = 'upload_embedded';
                   5270:                     my $primaryurl = &HTML::Entities::encode($url,'<>&"');
                   5271: 		    my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx); 
1.630     raeburn  5272:                     my ($embedded,$num) =
1.440     raeburn  5273:                         &Apache::loncommon::ask_for_embedded_content(
                   5274:                             '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
                   5275:                     if ($embedded) {
                   5276:                         if ($num) {
                   5277:                             $$upload_output .=
                   5278: 			         '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
                   5279:                             $nextphase = $uploadphase;
                   5280:                         } else {
                   5281:                             $$upload_output .= $embedded;
                   5282:                         }
                   5283:                     } else {
                   5284:                         $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
                   5285:                     }
1.329     droeschl 5286:                 } else {
1.440     raeburn  5287:                     $$upload_output .= &mt('No embedded items identified').'<br />';
1.329     droeschl 5288:                 }
1.457     raeburn  5289:                 $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578     raeburn  5290:             } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
                   5291:                      ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476     raeburn  5292:                 $nextphase = 'decompress_uploaded';
                   5293:                 my $position = scalar(@LONCAPA::map::order)-1;
                   5294:                 my $noextract = &return_to_editor();
                   5295:                 my $archiveurl = &HTML::Entities::encode($url,'<>&"');
                   5296:                 my %archiveitems = (
                   5297:                     folderpath => $env{'form.folderpath'},
                   5298:                     cmd        => $nextphase,
                   5299:                     newidx     => $newidx,
                   5300:                     position   => $position,
                   5301:                     phase      => $nextphase,
1.477     raeburn  5302:                     comment    => $comment,
1.480     raeburn  5303:                 );
                   5304:                 my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
                   5305:                 my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx); 
1.476     raeburn  5306:                 $$upload_output = $showupload.
                   5307:                                   &Apache::loncommon::decompress_form($mimetype,
                   5308:                                       $archiveurl,'/adm/coursedocs',$noextract,
1.480     raeburn  5309:                                       \%archiveitems,\@current);
1.329     droeschl 5310:             }
                   5311:         }
                   5312:     }
1.440     raeburn  5313:     return $nextphase;
1.329     droeschl 5314: }
                   5315: 
1.480     raeburn  5316: sub get_dir_list {
                   5317:     my ($url,$coursenum,$coursedom,$newidx) = @_;
                   5318:     my ($destination,$dir_root) = &embedded_destination();
                   5319:     my ($dirlistref,$listerror) =  
                   5320:         &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
                   5321:     my @dir_lines;
                   5322:     my $dirptr=16384;
                   5323:     if (ref($dirlistref) eq 'ARRAY') {
                   5324:         foreach my $dir_line (sort
                   5325:                           {
                   5326:                               my ($afile)=split('&',$a,2);
                   5327:                               my ($bfile)=split('&',$b,2);
                   5328:                               return (lc($afile) cmp lc($bfile));
                   5329:                           } (@{$dirlistref})) {
                   5330:             my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
                   5331:             $filename =~ s/\s+$//;
                   5332:             next if ($filename =~ /^\.\.?$/); 
                   5333:             my $isdir = 0;
                   5334:             if ($dirptr&$testdir) {
                   5335:                 $isdir = 1;
                   5336:             }
                   5337:             push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
                   5338:         }
                   5339:     }
                   5340:     return @dir_lines;
                   5341: }
                   5342: 
1.329     droeschl 5343: sub is_supplemental_title {
                   5344:     my ($title) = @_;
                   5345:     return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
                   5346: }
                   5347: 
                   5348: # --------------------------------------------------------------- An entry line
                   5349: 
                   5350: sub entryline {
1.501     raeburn  5351:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598     raeburn  5352:         $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685     raeburn  5353:         $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687     raeburn  5354:     my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329     droeschl 5355:     if (&is_supplemental_title($title)) {
1.488     raeburn  5356: 	($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687     raeburn  5357:         $encodedtitle=$title;
1.329     droeschl 5358:     } else {
                   5359: 	$title=&HTML::Entities::encode($title,'"<>&\'');
1.687     raeburn  5360:         $encodedtitle=$title;
1.329     droeschl 5361: 	$renametitle=$title;
                   5362: 	$foldertitle=$title;
                   5363:     }
                   5364: 
1.611     raeburn  5365:     my ($disabled,$readonly,$js_lt);
                   5366:     unless ($canedit) {
                   5367:         $disabled = 'disabled="disabled"';
                   5368:         $readonly = 1;
                   5369:     }
                   5370: 
1.329     droeschl 5371:     my $orderidx=$LONCAPA::map::order[$index];
1.364     bisitz   5372: 
1.329     droeschl 5373:     $renametitle=~s/\\/\\\\/g;
                   5374:     $renametitle=~s/\&quot\;/\\\"/g;
1.585     raeburn  5375:     $renametitle=~s/"/%22/g;
1.581     raeburn  5376:     $renametitle=~s/ /%20/g;
                   5377:     $oldtitle = $renametitle;
1.576     raeburn  5378:     $renametitle=~s/\&#39;/\\\'/g;
1.379     bisitz   5379:     my $line=&Apache::loncommon::start_data_table_row();
1.538     raeburn  5380:     my ($form_start,$form_end,$form_common,$form_param);
1.329     droeschl 5381: # Edit commands
1.679     raeburn  5382:     my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329     droeschl 5383:     if ($env{'form.folderpath'}) {
                   5384: 	$esc_path=&escape($env{'form.folderpath'});
                   5385: 	$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   5386: 	# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
                   5387:     }
1.505     raeburn  5388:     my $isexternal;
1.510     raeburn  5389:     if ($residx) {
1.501     raeburn  5390:         my $currurl = $url;
                   5391:         $currurl =~ s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
1.505     raeburn  5392:         if ($currurl =~ m{^/adm/wrapper/ext/}) {
                   5393:             $isexternal = 1;
                   5394:         }
1.510     raeburn  5395:         if (!$supplementalflag) {
                   5396:             my $path = 'uploaded/'.
                   5397:                        $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   5398:                        $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
                   5399:             $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
                   5400:                                                  $residx,
                   5401:                                                  &Apache::lonnet::declutter($currurl));
                   5402:         }
1.501     raeburn  5403:     }
1.538     raeburn  5404:     my ($renamelink,%lt,$ishash);
                   5405:     if (ref($filtersref) eq 'HASH') {
                   5406:         $ishash = 1;
                   5407:     }
                   5408: 
1.329     droeschl 5409:     if ($allowed) {
1.538     raeburn  5410:         $form_start = '
                   5411:    <form action="/adm/coursedocs" method="post">
                   5412: ';
                   5413:         $form_common=(<<END);
                   5414:    <input type="hidden" name="folderpath" value="$path" />
                   5415:    <input type="hidden" name="symb" value="$symb" />
                   5416: END
                   5417:         $form_param=(<<END);
                   5418:    <input type="hidden" name="setparms" value="$orderidx" />
                   5419:    <input type="hidden" name="changeparms" value="0" />
                   5420: END
                   5421:         $form_end = '</form>';
                   5422: 
1.329     droeschl 5423: 	my $incindex=$index+1;
                   5424: 	my $selectbox='';
1.471     raeburn  5425: 	if (($#LONCAPA::map::order>0) &&
1.329     droeschl 5426: 	    ((split(/\:/,
1.344     bisitz   5427: 	     $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
                   5428: 	     ne '') &&
1.329     droeschl 5429: 	    ((split(/\:/,
1.344     bisitz   5430: 	     $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329     droeschl 5431: 	     ne '')) {
                   5432: 	    $selectbox=
                   5433: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611     raeburn  5434: 		'<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329     droeschl 5435: 	    for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
                   5436: 		if ($i==$incindex) {
1.358     bisitz   5437: 		    $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329     droeschl 5438: 		} else {
                   5439: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
                   5440: 		}
                   5441: 	    }
                   5442: 	    $selectbox.='</select>';
                   5443: 	}
1.501     raeburn  5444: 	%lt=&Apache::lonlocal::texthash(
1.329     droeschl 5445:                 'up' => 'Move Up',
                   5446: 		'dw' => 'Move Down',
                   5447: 		'rm' => 'Remove',
                   5448:                 'ct' => 'Cut',
                   5449: 		'rn' => 'Rename',
1.501     raeburn  5450: 		'cp' => 'Copy',
1.633     raeburn  5451:                 'da' => 'Unset alias', 
                   5452:                 'sa' => 'Set alias',
1.501     raeburn  5453:                 'ex' => 'External Resource',
1.598     raeburn  5454:                 'et' => 'External Tool',
1.501     raeburn  5455:                 'ed' => 'Edit',
                   5456:                 'pr' => 'Preview',
                   5457:                 'sv' => 'Save',
                   5458:                 'ul' => 'URL',
1.611     raeburn  5459:                 'ti' => 'Title',
1.618     raeburn  5460:                 'er' => 'Editing rights unavailable for your current role.', 
1.501     raeburn  5461:                 );
1.538     raeburn  5462: 	my %denied = &action_restrictions($coursenum,$coursedom,$url,
                   5463:                                           $env{'form.folderpath'},
                   5464:                                           $currgroups);
1.517     raeburn  5465:         my ($copylink,$cutlink,$removelink);
1.329     droeschl 5466: 	my $skip_confirm = 0;
1.603     raeburn  5467:         my $confirm_removal = 0;
1.329     droeschl 5468: 	if ( $folder =~ /^supplemental/
                   5469: 	     || ($url =~ m{( /smppg$
                   5470: 			    |/syllabus$
                   5471: 			    |/aboutme$
                   5472: 			    |/navmaps$
                   5473: 			    |/bulletinboard$
1.626     raeburn  5474:                             |/ext\.tool$
1.505     raeburn  5475: 			    |\.html$)}x)
                   5476:              || $isexternal) {
1.329     droeschl 5477: 	    $skip_confirm = 1;
                   5478: 	}
1.603     raeburn  5479:         if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   5480:             ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   5481:             $confirm_removal = 1;
                   5482:         }
1.633     raeburn  5483:         if ($url =~ /$LONCAPA::assess_re/) {
                   5484:             $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
                   5485:         }
1.329     droeschl 5486: 
1.538     raeburn  5487: 	if ($denied{'copy'}) {
1.543     raeburn  5488:             $copylink=(<<ENDCOPY)
1.507     raeburn  5489: <span style="visibility: hidden;">$lt{'cp'}</span>
                   5490: ENDCOPY
                   5491:         } else {
1.538     raeburn  5492:             my $formname = 'edit_copy_'.$orderidx;
                   5493:             my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 5494: 	    $copylink=(<<ENDCOPY);
1.538     raeburn  5495: <form name="$formname" method="post" action="/adm/coursedocs">
                   5496: $form_common
1.723   ! raeburn  5497: <label><input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a></label>
1.538     raeburn  5498: $form_end
1.329     droeschl 5499: ENDCOPY
1.538     raeburn  5500:             if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
                   5501:                 push(@{$filtersref->{'cancopy'}},$orderidx);
                   5502:             }
1.329     droeschl 5503:         }
1.538     raeburn  5504: 	if ($denied{'cut'}) {
1.507     raeburn  5505:             $cutlink=(<<ENDCUT);
                   5506: <span style="visibility: hidden;">$lt{'ct'}</span>
                   5507: ENDCUT
                   5508:         } else {
1.538     raeburn  5509:             my $formname = 'edit_cut_'.$orderidx;
                   5510:             my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 5511: 	    $cutlink=(<<ENDCUT);
1.538     raeburn  5512: <form name="$formname" method="post" action="/adm/coursedocs">
                   5513: $form_common
1.542     raeburn  5514: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.723   ! raeburn  5515: <label><input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a></label>
1.538     raeburn  5516: $form_end
1.329     droeschl 5517: ENDCUT
1.538     raeburn  5518:             if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
                   5519:                 push(@{$filtersref->{'cancut'}},$orderidx);
                   5520:             }
1.329     droeschl 5521:         }
1.538     raeburn  5522:         if ($denied{'remove'}) {
1.507     raeburn  5523:             $removelink=(<<ENDREM);
                   5524: <span style="visibility: hidden;">$lt{'rm'}</a>
                   5525: ENDREM
                   5526:         } else {
1.538     raeburn  5527:             my $formname = 'edit_remove_'.$orderidx;
1.603     raeburn  5528:             my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497     raeburn  5529:             $removelink=(<<ENDREM);
1.538     raeburn  5530: <form name="$formname" method="post" action="/adm/coursedocs">
                   5531: $form_common
1.542     raeburn  5532: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603     raeburn  5533: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.723   ! raeburn  5534: <label><input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a></label>
1.538     raeburn  5535: $form_end
1.497     raeburn  5536: ENDREM
1.538     raeburn  5537:             if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
                   5538:                 push(@{$filtersref->{'canremove'}},$orderidx);
                   5539:             }
1.497     raeburn  5540:         }
1.551     raeburn  5541:         $renamelink=(<<ENDREN);
1.581     raeburn  5542: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507     raeburn  5543: ENDREN
1.611     raeburn  5544:         my ($uplink,$downlink);
                   5545:         if ($canedit) {
                   5546:             $uplink = "/adm/coursedocs?cmd=up_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   5547:             $downlink = "/adm/coursedocs?cmd=down_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   5548:         } else {
                   5549:             $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
                   5550:             $downlink = $uplink;
                   5551:         }
1.329     droeschl 5552: 	$line.=(<<END);
                   5553: <td>
1.379     bisitz   5554: <div class="LC_docs_entry_move">
1.611     raeburn  5555:   <a href="$uplink">
1.501     raeburn  5556:     <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379     bisitz   5557:   </a>
                   5558: </div>
                   5559: <div class="LC_docs_entry_move">
1.611     raeburn  5560:   <a href="$downlink">
1.501     raeburn  5561:     <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379     bisitz   5562:   </a>
                   5563: </div>
1.329     droeschl 5564: </td>
                   5565: <td>
                   5566:    $form_start
1.538     raeburn  5567:    $form_param
1.478     raeburn  5568:    $form_common
1.329     droeschl 5569:    $selectbox
                   5570:    $form_end
                   5571: </td>
1.540     raeburn  5572: <td class="LC_docs_entry_commands LC_nobreak">
1.497     raeburn  5573: $removelink
1.329     droeschl 5574: $cutlink
                   5575: $copylink
                   5576: </td>
                   5577: END
                   5578:     }
1.723   ! raeburn  5579:     my $icontext;
1.329     droeschl 5580: # Figure out what kind of a resource this is
                   5581:     my ($extension)=($url=~/\.(\w+)$/);
1.723   ! raeburn  5582:     if ($extension eq 'sequence') {
        !          5583:         $icontext = &mt('folder icon');
        !          5584:     } elsif ($extension eq 'page') {
        !          5585:         $icontext = &mt('composite page icon');
        !          5586:     } else {
        !          5587:         $icontext = &mt('file icon');
        !          5588:     }
        !          5589:     $icontext = &HTML::Entities::encode($icontext);
1.329     droeschl 5590:     my $uploaded=($url=~/^\/*uploaded\//);
                   5591:     my $icon=&Apache::loncommon::icon($url);
1.519     raeburn  5592:     my $isfolder;
                   5593:     my $ispage;
                   5594:     my $containerarg;
1.615     raeburn  5595:     my $folderurl;
1.685     raeburn  5596:     my $plainurl;
1.329     droeschl 5597:     if ($uploaded) {
1.472     raeburn  5598:         if (($extension eq 'sequence') || ($extension eq 'page')) {
                   5599:             $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519     raeburn  5600:             $containerarg = $1;
1.472     raeburn  5601: 	    if ($extension eq 'sequence') {
                   5602: 	        $icon=$iconpath.'navmap.folder.closed.gif';
                   5603:                 $isfolder=1;
                   5604:             } else {
                   5605:                 $icon=$iconpath.'page.gif';
                   5606:                 $ispage=1;
                   5607:             }
1.615     raeburn  5608:             $folderurl = &Apache::lonnet::declutter($url);
1.472     raeburn  5609:             if ($allowed) {
                   5610:                 $url='/adm/coursedocs?';
                   5611:             } else {
                   5612:                 $url='/adm/supplemental?';
                   5613:             }
1.329     droeschl 5614: 	} else {
1.685     raeburn  5615: 	    $plainurl = $url;
1.329     droeschl 5616: 	}
                   5617:     }
1.364     bisitz   5618: 
1.621     raeburn  5619:     my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329     droeschl 5620:     my $orig_url = $url;
1.340     raeburn  5621:     $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.668     raeburn  5622:     if ($container eq 'page') {
                   5623:         $url=~s{^http(|s)(&colon;|:)//}{/ext/};
                   5624:     } else {
                   5625:         $url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
                   5626:     }
1.501     raeburn  5627:     if (!$supplementalflag && $residx && $symb) {
                   5628:         if ((!$isfolder) && (!$ispage)) {
                   5629: 	    (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668     raeburn  5630:             if (($url =~ m{^ext/}) && ($container eq 'page')) {
                   5631:                 $url=&Apache::lonnet::clutter_with_no_wrapper($url);
                   5632:             } else {
                   5633:                 $url=&Apache::lonnet::clutter($url);
                   5634:             } 
1.501     raeburn  5635: 	    if ($url=~/^\/*uploaded\//) {
                   5636: 	        $url=~/\.(\w+)$/;
                   5637: 	        my $embstyle=&Apache::loncommon::fileembstyle($1);
                   5638: 	        if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                   5639: 		    $url='/adm/wrapper'.$url;
                   5640: 	        } elsif ($embstyle eq 'ssi') {
                   5641: 		    #do nothing with these
                   5642: 	        } elsif ($url!~/\.(sequence|page)$/) {
                   5643: 		    $url='/adm/coursedocs/showdoc'.$url;
                   5644: 	        }
1.623     raeburn  5645: 	    } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
                   5646:                 my $wrapped = $1;
                   5647:                 my $exturl = $2;
1.668     raeburn  5648:                 if (($wrapped eq '') && ($container ne 'page')) { 
1.623     raeburn  5649:                     $url='/adm/wrapper'.$url;
                   5650:                 }
                   5651:                 if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
                   5652:                     $nomodal = 1;
                   5653:                 }
1.626     raeburn  5654: 	    } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  5655: 		$url='/adm/wrapper'.$url;
1.621     raeburn  5656:             } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
                   5657:                 if (($ENV{'SERVER_PORT'} == 443) &&
                   5658:                     ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  5659:                     unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  5660:                         $url .= '?usehttp=1';
                   5661:                     }
1.621     raeburn  5662:                     $nomodal = 1;
                   5663:                 }
1.598     raeburn  5664:             }
1.696     raeburn  5665:             my $checkencrypt;
1.680     raeburn  5666:             if (!$env{'request.role.adv'}) {
1.615     raeburn  5667:                 if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680     raeburn  5668:                     ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615     raeburn  5669:                     $checkencrypt = 1;
1.620     raeburn  5670:                 } elsif (ref($navmapref)) {
1.615     raeburn  5671:                     unless (ref($$navmapref)) {
                   5672:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   5673:                     }
                   5674:                     if (ref($$navmapref)) {
                   5675:                         if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680     raeburn  5676:                             $checkencrypt = 1;
1.615     raeburn  5677:                         }
                   5678:                     }
                   5679:                 }
1.680     raeburn  5680:             }
                   5681:             if ($checkencrypt) {
                   5682:                 my $currenc = $env{'request.enc'};
                   5683:                 $env{'request.enc'} = 1;
                   5684:                 $shownsymb = &Apache::lonenc::encrypted($symb);
1.696     raeburn  5685:                 my $shownurl = &Apache::lonenc::encrypted($url);
1.680     raeburn  5686:                 if (&Apache::lonnet::symbverify($symb,$url)) {
                   5687:                     $url = $shownurl;
                   5688:                 } else {
                   5689:                     $url = '';
                   5690:                 }
                   5691:                 $env{'request.enc'} = $currenc;
                   5692:             } elsif (&Apache::lonnet::symbverify($symb,$url)) {
                   5693:                 $shownsymb = $symb;
                   5694:                 if ($isexternal) {
                   5695:                     $url =~ s/\#[^#]+$//;
                   5696:                     if ($container eq 'page') {
                   5697:                         $url = &Apache::lonnet::clutter($url);
1.613     raeburn  5698:                     }
1.612     raeburn  5699:                 }
1.696     raeburn  5700:             } else {
                   5701:                 $url = '';
1.680     raeburn  5702:             }
                   5703:             unless ($env{'request.role.adv'}) {
                   5704:                 if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   5705:                     $url = '';
                   5706:                 }
                   5707:                 if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
                   5708:                     $url = '';
                   5709:                     $hiddenres = 1;
                   5710:                 }
                   5711:             }
1.696     raeburn  5712:             if (($url ne '') && ($shownsymb ne '')) {
                   5713:                 $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501     raeburn  5714:             }
1.329     droeschl 5715: 	}
1.621     raeburn  5716:     } elsif ($supplementalflag) {
1.610     raeburn  5717:         if ($isexternal) {
                   5718:             if ($url =~ /^([^#]+)#([^#]+)$/) {
                   5719:                 $url = $1;
                   5720:                 $anchor = $2;
1.623     raeburn  5721:                 if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678     raeburn  5722:                     unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  5723:                         if ($hostname ne '') {
                   5724:                             $url = 'http://'.$hostname.$url;
                   5725:                         }
                   5726:                         $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.623     raeburn  5727:                     }
                   5728:                     $nomodal = 1;
                   5729:                 }
1.610     raeburn  5730:             }
1.621     raeburn  5731:         } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   5732:             if (($ENV{'SERVER_PORT'} == 443) &&
                   5733:                 ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  5734:                 unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  5735:                     if ($hostname ne '') {
                   5736:                         $url = 'http://'.$hostname.$url;
                   5737:                     }
                   5738:                     $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  5739:                 }
1.621     raeburn  5740:                 $nomodal = 1;
                   5741:             }
1.705     raeburn  5742:         } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686     raeburn  5743:             my $embstyle=&Apache::loncommon::fileembstyle($extension);
                   5744:             unless ($embstyle eq 'ssi') {
                   5745:                 if (($embstyle eq 'img')
                   5746:                  || ($embstyle eq 'emb')
                   5747:                  || ($embstyle eq 'wrp')) {
                   5748:                     $url='/adm/wrapper'.$url;
                   5749:                 } elsif ($url !~ /\.(sequence|page)$/) {
                   5750:                     $url='/adm/coursedocs/showdoc'.$url;
                   5751:                 }
                   5752:             }
1.610     raeburn  5753:         }
1.685     raeburn  5754:         unless ($allowed && $env{'request.role.adv'}) {
                   5755:             if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   5756:                 $hiddenres = 1;
                   5757:             }
                   5758:         }
1.329     droeschl 5759:     }
1.615     raeburn  5760:     my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617     raeburn  5761:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519     raeburn  5762:     if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329     droeschl 5763: 	my $foldername=&escape($foldertitle);
                   5764: 	my $folderpath=$env{'form.folderpath'};
                   5765: 	if ($folderpath) { $folderpath.='&' };
1.510     raeburn  5766:         if (!$allowed && $supplementalflag) {
1.519     raeburn  5767:             $folderpath.=$containerarg.'&'.$foldername;
1.510     raeburn  5768:             $url.='folderpath='.&escape($folderpath);
1.685     raeburn  5769:             if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   5770:                 $hiddenfolder = 1;
1.682     raeburn  5771:             }
1.510     raeburn  5772:         } else {
1.617     raeburn  5773:             my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
                   5774:                                                         'parameter_randompick'))[0];
                   5775:             my $randorder = ((&LONCAPA::map::getparameter($orderidx,
                   5776:                                               'parameter_randomorder'))[0]=~/^yes$/i);
                   5777:             my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
                   5778:                                               'parameter_hiddenresource'))[0]=~/^yes$/i);
                   5779:             my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
                   5780:                                               'parameter_encrypturl'))[0]=~/^yes$/i);
                   5781:             unless ($hiddenmap) {
1.620     raeburn  5782:                 if (ref($navmapref)) {
                   5783:                     unless (ref($$navmapref)) {
                   5784:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   5785:                     }
                   5786:                     if (ref($$navmapref)) {
                   5787:                         if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
                   5788:                             my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
                   5789:                             unless (@resources) {
                   5790:                                 $hiddenmap = 1;
                   5791:                                 unless ($env{'request.role.adv'}) {  
                   5792:                                     $url = '';
                   5793:                                     $hiddenfolder = 1;
                   5794:                                 }
1.617     raeburn  5795:                             }
1.615     raeburn  5796:                         }
                   5797:                     }
                   5798:                 }
                   5799:             }
1.617     raeburn  5800:             unless ($encryptmap) {
1.620     raeburn  5801:                 if ((ref($navmapref)) && (ref($$navmapref))) {
                   5802:                     if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
                   5803:                         $encryptmap = 1;
                   5804:                     }
1.617     raeburn  5805:                 }
                   5806:             }
1.630     raeburn  5807: 
1.617     raeburn  5808: # Append randompick number, hidden, and encrypted with ":" to foldername,
                   5809: # so it gets transferred between levels
                   5810: 	    $folderpath.=$containerarg.'&'.$foldername.
                   5811:                          ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615     raeburn  5812:             unless ($url eq '') {
1.612     raeburn  5813:                 $url.='folderpath='.&escape($folderpath);
                   5814:             }
1.510     raeburn  5815:             my $rpckchk;
                   5816:             if ($rpicknum) {
                   5817:                 $rpckchk = ' checked="checked"';
1.543     raeburn  5818:                 if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
                   5819:                     push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
                   5820:                 }
1.510     raeburn  5821:             }
1.537     raeburn  5822:             my $formname = 'edit_randompick_'.$orderidx;
1.510     raeburn  5823: 	    $rand_pick_text = 
1.478     raeburn  5824: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  5825: $form_param."\n".
1.478     raeburn  5826: $form_common."\n".
1.611     raeburn  5827: '<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  5828:             if ($rpicknum ne '') {
                   5829:                 $rand_pick_text .= ':&nbsp;<a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
                   5830:             }
1.537     raeburn  5831:             $rand_pick_text .= '</span></span>'.
                   5832:                                $form_end;
1.543     raeburn  5833:             my $ro_set;
1.617     raeburn  5834:             if ($randorder) {
1.543     raeburn  5835:                 $ro_set = 'checked="checked"';
                   5836:                 if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
                   5837:                     push(@{$filtersref->{'randomorder'}},$orderidx);
                   5838:                 }
                   5839:             }
1.564     raeburn  5840:             $formname = 'edit_rorder_'.$orderidx;
1.510     raeburn  5841: 	    $rand_order_text = 
1.537     raeburn  5842: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  5843: $form_param."\n".
1.537     raeburn  5844: $form_common."\n".
1.611     raeburn  5845: '<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  5846: $form_end; 
1.510     raeburn  5847:         }
1.705     raeburn  5848:     } elsif ($supplementalflag) {
1.598     raeburn  5849:         my $isexttool;
1.626     raeburn  5850:         if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  5851:             $url='/adm/wrapper'.$url;
                   5852:             $isexttool = 1;
                   5853:         }
1.510     raeburn  5854:         $url .= ($url =~ /\?/) ? '&amp;':'?';
1.509     raeburn  5855:         $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510     raeburn  5856:         if ($title) {
1.687     raeburn  5857:             $url .= '&amp;title='.$encodedtitle;
1.510     raeburn  5858:         }
1.598     raeburn  5859:         if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510     raeburn  5860:             $url .= '&amp;idx='.$orderidx;
                   5861:         }
1.610     raeburn  5862:         if ($anchor ne '') {
                   5863:             $url .= '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   5864:         }
1.329     droeschl 5865:     }
1.519     raeburn  5866:     my ($tdalign,$tdwidth);
1.501     raeburn  5867:     if ($allowed) {
1.630     raeburn  5868:         my $fileloc =
1.501     raeburn  5869:             &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510     raeburn  5870:         if ($isexternal) {
1.630     raeburn  5871:             ($editlink,$extresform) =
1.611     raeburn  5872:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   5873:                                                      undef,undef,undef,undef,undef,undef,
                   5874:                                                      undef,$disabled);
1.626     raeburn  5875:         } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  5876:             ($editlink,$extresform) =
                   5877:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   5878:                                                      undef,undef,undef,'tool',$coursedom,
1.611     raeburn  5879:                                                      $coursenum,$ltitoolsref,$disabled);
1.511     raeburn  5880:         } elsif (!$isfolder && !$ispage) {
1.503     raeburn  5881:             my ($cfile,$home,$switchserver,$forceedit,$forceview) = 
                   5882:                 &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511     raeburn  5883:             if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610     raeburn  5884:                 my $suppanchor;
                   5885:                 if ($supplementalflag) {
                   5886:                     $suppanchor = $anchor;
                   5887:                 }
1.630     raeburn  5888:                 my $jscall =
1.501     raeburn  5889:                     &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
                   5890:                                                             $switchserver,
1.503     raeburn  5891:                                                             $forceedit,
1.679     raeburn  5892:                                                             undef,$symb,$shownsymb,
1.511     raeburn  5893:                                                             &escape($env{'form.folderpath'}),
1.622     raeburn  5894:                                                             $renametitle,$hostname,
                   5895:                                                             '','',1,$suppanchor);
1.501     raeburn  5896:                 if ($jscall) {
1.518     raeburn  5897:                     $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
                   5898:                                 $jscall.'" >'.&mt('Edit').'</a>&nbsp;'."\n";
1.501     raeburn  5899:                 }
                   5900:             }
                   5901:         }
1.519     raeburn  5902:         $tdalign = ' align="right" valign="top"';
                   5903:         $tdwidth = ' width="80%"';
1.329     droeschl 5904:     }
1.408     raeburn  5905:     my $reinit;
                   5906:     if ($crstype eq 'Community') {
                   5907:         $reinit = &mt('(re-initialize community to access)');
                   5908:     } else {
                   5909:         $reinit = &mt('(re-initialize course to access)');
1.519     raeburn  5910:     }
1.702     raeburn  5911:     $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650     raeburn  5912:     if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633     raeburn  5913:         $line.= '<br />';
                   5914:         if ($curralias ne '') {
                   5915:             $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   5916:                    $lt{'da'}.'</a></span>';
                   5917:         } else {
                   5918:             $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   5919:                    $lt{'sa'}.'</a></span>';
                   5920:         }
                   5921:     }
1.701     raeburn  5922:     $line.='</td><td><span class="LC_nobreak">';
1.685     raeburn  5923:     my ($link,$nolink);
1.472     raeburn  5924:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685     raeburn  5925:         if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
                   5926:             if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   5927:                 $nolink = 1;
                   5928:             }
                   5929:         }
                   5930:         if ($nolink) {
1.723   ! raeburn  5931:             $line .= '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" /></a>';
1.685     raeburn  5932:         } else {
1.723   ! raeburn  5933:             $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" /></a>';
1.685     raeburn  5934:         }
1.469     www      5935:     } elsif ($url) {
1.610     raeburn  5936:        if ($anchor ne '') {
                   5937:            if ($supplementalflag) {
                   5938:                $anchor = '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   5939:            } else {
                   5940:                $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
                   5941:            }
                   5942:        }
1.705     raeburn  5943:        if (($nomodal) && ($hostname ne '')) {
1.622     raeburn  5944:            $link = 'http://'.$hostname.$url;
                   5945:        } else {
                   5946:            $link = $url;
                   5947:        }
1.705     raeburn  5948:        my $inhibitmenu;
                   5949:        if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
                   5950:            (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
                   5951:                            ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
                   5952:            $inhibitmenu = 'only_body=1';
                   5953:        } else {
                   5954:            $inhibitmenu = 'inhibitmenu=yes';
                   5955:        }
                   5956:        $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').$inhibitmenu.$anchor);
1.685     raeburn  5957:        if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
                   5958:            if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   5959:                $nolink = 1;
                   5960:            }
                   5961:        }
                   5962:        if ($nolink) {
1.723   ! raeburn  5963:            $line.='<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />';
1.685     raeburn  5964:        } elsif ($nomodal) {
1.621     raeburn  5965:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
1.723   ! raeburn  5966:                   '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" border="0" /></a>';
1.621     raeburn  5967:        } else {
                   5968:            $line.=&Apache::loncommon::modal_link($link,
1.723   ! raeburn  5969:                                                  '<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />',600,500);
1.621     raeburn  5970:        }
1.469     www      5971:     } else {
1.723   ! raeburn  5972:        $line.='<img src="'.$icon.'" alt="'.$icontext.'" class="LC_icon" />';
1.469     www      5973:     }
1.519     raeburn  5974:     $line.='</span></td><td'.$tdwidth.'>';
1.472     raeburn  5975:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685     raeburn  5976:        if ($nolink) {
                   5977:            $line.=$title;
                   5978:        } else {
                   5979:            $line.='<a href="'.$url.'">'.$title.'</a>';
                   5980:        }
1.682     raeburn  5981:        if (!$allowed && $supplementalflag && $canedit && $isfolder) {
                   5982:            my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
                   5983:            my $editurl = $url;
                   5984:            $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;};
                   5985:            $line .= '&nbsp;'.'<a href="'.$editurl.'">'.
                   5986:                     '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
                   5987:                     '</a>';
                   5988:        }
                   5989:        if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag))  {
                   5990:            $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
                   5991:        }
1.469     www      5992:     } elsif ($url) {
1.685     raeburn  5993:        if ($nolink) {
                   5994:            $line.=$title;
                   5995:        } elsif ($nomodal) {
1.621     raeburn  5996:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   5997:                   $title.'</a>';
                   5998:        } else {
                   5999:            $line.=&Apache::loncommon::modal_link($link,$title,600,500);
                   6000:        }
1.617     raeburn  6001:     } elsif (($hiddenfolder) || ($hiddenres)) {
1.632     raeburn  6002:        $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469     www      6003:     } else {
                   6004:        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
                   6005:     }
1.633     raeburn  6006:     if (($allowed) && ($curralias ne '')) {
                   6007:         $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
                   6008:     } else {
                   6009:         $line .= $extresform;
                   6010:     }
                   6011:     $line .= '</td>';
1.478     raeburn  6012:     $rand_pick_text = '&nbsp;' if ($rand_pick_text eq '');
                   6013:     $rand_order_text = '&nbsp;' if ($rand_order_text eq '');
1.685     raeburn  6014:     if ($uploaded && $url && !$isfolder && !$ispage) {
                   6015:         if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
                   6016:             &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
                   6017:         }
                   6018:     }
1.682     raeburn  6019:     if ($allowed) {
                   6020:         my %lt=&Apache::lonlocal::texthash(
                   6021:                               'hd' => 'Hidden',
                   6022:                               'ec' => 'URL hidden');
                   6023:         my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543     raeburn  6024:         if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   6025:             $hidtext = ' checked="checked"';
1.694     raeburn  6026:             if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543     raeburn  6027:                 push(@{$filtersref->{'hiddenresource'}},$orderidx);
                   6028:             }
                   6029:         }
1.682     raeburn  6030:         $formhidden = 'edit_hiddenresource_'.$orderidx;
                   6031:         $line.=(<<ENDPARMS);
1.329     droeschl 6032:   <td class="LC_docs_entry_parameter">
1.537     raeburn  6033:     <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538     raeburn  6034:     $form_param
1.478     raeburn  6035:     $form_common
1.611     raeburn  6036:     <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329     droeschl 6037:     $form_end
1.682     raeburn  6038: ENDPARMS
                   6039:         if ($folder =~/^supplemental/) {
                   6040:             $line.= "\n    <td>";
                   6041:         } else {
                   6042:             if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
                   6043:                 $enctext = ' checked="checked"';
                   6044:                 if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
                   6045:                     push(@{$filtersref->{'encrypturl'}},$orderidx);
                   6046:                 }
                   6047:             }
                   6048:             $formurlhidden = 'edit_encrypturl_'.$orderidx;
                   6049: 	    $line.=(<<ENDPARMS);
1.458     raeburn  6050:     <br />
1.537     raeburn  6051:     <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538     raeburn  6052:     $form_param
1.478     raeburn  6053:     $form_common
1.611     raeburn  6054:     <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329     droeschl 6055:     $form_end
                   6056:   </td>
1.478     raeburn  6057:   <td class="LC_docs_entry_parameter">$rand_pick_text<br />
                   6058:                                       $rand_order_text</td>
1.329     droeschl 6059: ENDPARMS
1.682     raeburn  6060:         }
1.329     droeschl 6061:     }
1.379     bisitz   6062:     $line.=&Apache::loncommon::end_data_table_row();
1.329     droeschl 6063:     return $line;
                   6064: }
                   6065: 
1.538     raeburn  6066: sub action_restrictions {
                   6067:     my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
                   6068:     my %denied = (
                   6069:                    cut    => 0,
                   6070:                    copy   => 0,
                   6071:                    remove => 0,
                   6072:                  );
                   6073:     if ($url=~ m{^/res/.+\.(page|sequence)$}) {
                   6074:         # no copy for published maps
                   6075:         $denied{'copy'} = 1;
1.597     raeburn  6076:     } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
                   6077:         unless ($1 eq 'simpleproblem') {
                   6078:             $denied{'copy'} = 1;
                   6079:         }
                   6080:         $denied{'cut'} = 1;
1.538     raeburn  6081:     } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
                   6082:         if ($folderpath =~ /^default&[^\&]+$/) {
                   6083:             if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
                   6084:                 $denied{'remove'} = 1;
                   6085:             }
                   6086:             $denied{'cut'} = 1;
                   6087:             $denied{'copy'} = 1;
                   6088:         }
                   6089:     } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
                   6090:         my $group = $1;
                   6091:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
                   6092:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   6093:                 $denied{'remove'} = 1;
                   6094:             }
                   6095:         }
                   6096:         $denied{'cut'} = 1;
                   6097:         $denied{'copy'} = 1;
                   6098:     } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
                   6099:         my $group = $1;
                   6100:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
                   6101:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   6102:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   6103:                 if (keys(%groupsettings) > 0) {
                   6104:                     $denied{'remove'} = 1;
                   6105:                 }
                   6106:                 $denied{'cut'} = 1;
                   6107:                 $denied{'copy'} = 1;
                   6108:             }
                   6109:         }
                   6110:     } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
                   6111:         my $group = $1;
                   6112:         if ($url =~ /group_boards_\Q$group\E/) {
                   6113:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   6114:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   6115:                 if (keys(%groupsettings) > 0) {
                   6116:                     if (ref($groupsettings{'functions'}) eq 'HASH') {
                   6117:                         if ($groupsettings{'functions'}{'discussion'} eq 'on') {
                   6118:                             $denied{'remove'} = 1;
                   6119:                         }
                   6120:                     }
                   6121:                 }
                   6122:                 $denied{'cut'} = 1;
                   6123:                 $denied{'copy'} = 1;
                   6124:             }
                   6125:         }
                   6126:     }
                   6127:     return %denied;
                   6128: }
                   6129: 
1.533     raeburn  6130: sub new_timebased_suffix {
1.538     raeburn  6131:     my ($dom,$num,$type,$area,$container) = @_;
1.533     raeburn  6132:     my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538     raeburn  6133:     if ($type eq 'paste') {
                   6134:         $prefix = $type;
                   6135:         $namespace = 'courseeditor';
1.587     raeburn  6136:         $idtype = 'addcode';
1.538     raeburn  6137:     } elsif ($type eq 'map') {
1.533     raeburn  6138:         $prefix = 'docs';
                   6139:         if ($area eq 'supplemental') {
                   6140:             $prefix = 'supp';
                   6141:         }
                   6142:         $prefix .= $container;
                   6143:         $namespace = 'uploadedmaps';
                   6144:     } else {
                   6145:         $prefix = $type;
                   6146:         $namespace = 'templated';
1.504     raeburn  6147:     }
                   6148:     my ($suffix,$freedlock,$error) =
1.587     raeburn  6149:         &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504     raeburn  6150:     if (!$suffix) {
1.538     raeburn  6151:         if ($type eq 'paste') {
                   6152:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
                   6153:         } elsif ($type eq 'map') {
1.533     raeburn  6154:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
                   6155:         } elsif ($type eq 'smppg') {
                   6156:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626     raeburn  6157:         } elsif ($type eq 'exttool') {
                   6158:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533     raeburn  6159:         } else {
1.565     bisitz   6160:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533     raeburn  6161:         }
1.504     raeburn  6162:         if ($error) {
                   6163:             $errtext .= '<br />'.$error;
                   6164:         }
                   6165:     }
                   6166:     if ($freedlock ne 'ok') {
1.630     raeburn  6167:         $locknotfreed =
1.533     raeburn  6168:             '<div class="LC_error">'.
                   6169:             &mt('There was a problem removing a lockfile.').' ';
1.538     raeburn  6170:         if ($type eq 'paste') {
1.591     raeburn  6171:             if ($freedlock eq 'nolock') {
                   6172:                 $locknotfreed =
                   6173:                     '<div class="LC_error">'.
                   6174:                     &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
                   6175:  
1.593     droeschl 6176:                     &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591     raeburn  6177:             } else { 
                   6178:                 $locknotfreed .=
                   6179:                     &mt('This will prevent addition of items to the clipboard until your next log-in.');
                   6180:             }
1.538     raeburn  6181:         } elsif ($type eq 'map') {
1.591     raeburn  6182:             $locknotfreed .=
                   6183:                 &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533     raeburn  6184:         } elsif ($type eq 'smppg') {
                   6185:             $locknotfreed .=
                   6186:                 &mt('This will prevent creation of additional simple pages in this course.');
1.626     raeburn  6187:         } elsif ($type eq 'exttool') {
                   6188:             $locknotfreed .=
                   6189:                 &mt('This will prevent creation of additional external tools in this course.');
1.533     raeburn  6190:         } else {
                   6191:             $locknotfreed .=
1.565     bisitz   6192:                 &mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  6193:         }
1.538     raeburn  6194:         unless ($type eq 'paste') {
                   6195:             $locknotfreed .=
1.560     raeburn  6196:                 ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   6197:                         '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538     raeburn  6198:         }
                   6199:         $locknotfreed .= '</div>';
1.504     raeburn  6200:     }
                   6201:     return ($suffix,$errtext,$locknotfreed);
                   6202: }
                   6203: 
1.329     droeschl 6204: =pod
                   6205: 
                   6206: =item tiehash()
                   6207: 
                   6208: tie the hash
                   6209: 
                   6210: =cut
                   6211: 
                   6212: sub tiehash {
                   6213:     my ($mode)=@_;
                   6214:     $hashtied=0;
                   6215:     if ($env{'request.course.fn'}) {
                   6216: 	if ($mode eq 'write') {
                   6217: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   6218: 		    &GDBM_WRCREAT(),0640)) {
                   6219:                 $hashtied=2;
                   6220: 	    }
                   6221: 	} else {
                   6222: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   6223: 		    &GDBM_READER(),0640)) {
                   6224:                 $hashtied=1;
                   6225: 	    }
                   6226: 	}
1.364     bisitz   6227:     }
1.329     droeschl 6228: }
                   6229: 
                   6230: sub untiehash {
                   6231:     if ($hashtied) { untie %hash; }
                   6232:     $hashtied=0;
                   6233:     return OK;
                   6234: }
                   6235: 
                   6236: 
                   6237: 
                   6238: 
                   6239: sub checkonthis {
1.637     raeburn  6240:     my ($r,$url,$level,$title,$checkstale)=@_;
1.329     droeschl 6241:     $url=&unescape($url);
                   6242:     $alreadyseen{$url}=1;
                   6243:     $r->rflush();
                   6244:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
                   6245:        $r->print("\n<br />");
                   6246:        if ($level==0) {
                   6247:            $r->print("<br />");
                   6248:        }
                   6249:        for (my $i=0;$i<=$level*5;$i++) {
                   6250:            $r->print('&nbsp;');
                   6251:        }
                   6252:        $r->print('<a href="'.$url.'" target="cat">'.
                   6253: 		 ($title?$title:$url).'</a> ');
                   6254:        if ($url=~/^\/res\//) {
1.637     raeburn  6255:           my $updated;
                   6256:           if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
                   6257:               ($url !~ /\.\d+\.\w+$/)) {
                   6258:               $updated = &Apache::lonnet::remove_stale_resfile($url);
                   6259:           }
1.329     droeschl 6260: 	  my $result=&Apache::lonnet::repcopy(
                   6261:                               &Apache::lonnet::filelocation('',$url));
                   6262:           if ($result eq 'ok') {
                   6263:              $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637     raeburn  6264:              if ($updated) {
                   6265:                  $r->print('<br />');
                   6266:                  for (my $i=0;$i<=$level*5;$i++) {
                   6267:                      $r->print('&nbsp;');
                   6268:                  }
                   6269:                  $r->print('- '.&mt('Outdated copy removed'));
                   6270:              }
1.329     droeschl 6271:              $r->rflush();
                   6272:              &Apache::lonnet::countacc($url);
                   6273:              $url=~/\.(\w+)$/;
                   6274:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                   6275: 		 $r->print('<br />');
                   6276:                  $r->rflush();
                   6277:                  for (my $i=0;$i<=$level*5;$i++) {
                   6278:                      $r->print('&nbsp;');
                   6279:                  }
                   6280:                  $r->print('- '.&mt('Rendering:').' ');
                   6281: 		 my ($errorcount,$warningcount)=split(/:/,
                   6282: 	       &Apache::lonnet::ssi_body($url,
                   6283: 			       ('grade_target'=>'web',
                   6284: 				'return_only_error_and_warning_counts' => 1)));
                   6285:                  if (($errorcount) ||
                   6286:                      ($warningcount)) {
                   6287: 		     if ($errorcount) {
1.369     bisitz   6288:                         $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329     droeschl 6289:                           &mt('[quant,_1,error]',$errorcount).'</span>');
                   6290:                      }
                   6291: 		     if ($warningcount) {
                   6292:                         $r->print('<span class="LC_warning">'.
                   6293:                           &mt('[quant,_1,warning]',$warningcount).'</span>');
                   6294:                      }
                   6295:                  } else {
                   6296:                      $r->print('<span class="LC_success">'.&mt('ok').'</span>');
                   6297:                  }
                   6298:                  $r->rflush();
                   6299:              }
                   6300: 	     my $dependencies=
                   6301:                 &Apache::lonnet::metadata($url,'dependencies');
                   6302:              foreach my $dep (split(/\,/,$dependencies)) {
                   6303: 		 if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637     raeburn  6304:                     &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329     droeschl 6305:                  }
                   6306:              }
                   6307:           } elsif ($result eq 'unavailable') {
                   6308:              $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
                   6309:           } elsif ($result eq 'not_found') {
                   6310: 	      unless ($url=~/\$/) {
1.521     bisitz   6311: 		  $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329     droeschl 6312: 	      } else {
1.366     bisitz   6313: 		  $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329     droeschl 6314: 	      }
                   6315:           } else {
                   6316:              $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
                   6317:           }
1.637     raeburn  6318:           if (($updated) && ($result ne 'ok')) {
                   6319:               $r->print('<br />'.&mt('Outdated copy removed'));
                   6320:           }
1.329     droeschl 6321:        }
                   6322:     }
                   6323: }
                   6324: 
                   6325: 
                   6326: 
                   6327: =pod
                   6328: 
                   6329: =item list_symbs()
                   6330: 
1.485     raeburn  6331: List Content Identifiers
1.329     droeschl 6332: 
                   6333: =cut
                   6334: 
                   6335: sub list_symbs {
                   6336:     my ($r) = @_;
                   6337: 
1.408     raeburn  6338:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  6339:     $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
                   6340:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
                   6341:     $r->print(&startContentScreen('tools'));
1.329     droeschl 6342:     my $navmap = Apache::lonnavmaps::navmap->new();
                   6343:     if (!defined($navmap)) {
                   6344:         $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
                   6345:                   '<div class="LC_error">'.
                   6346:                   &mt('Unable to retrieve information about course contents').
                   6347:                   '</div>');
1.408     raeburn  6348:         &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329     droeschl 6349:     } else {
1.484     raeburn  6350:         $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
                   6351:                   &Apache::loncommon::start_data_table().
                   6352:                   &Apache::loncommon::start_data_table_header_row().
                   6353:                   '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
                   6354:                   &Apache::loncommon::end_data_table_header_row()."\n");
                   6355:         my $count;
1.329     droeschl 6356:         foreach my $res ($navmap->retrieveResources()) {
1.484     raeburn  6357:             $r->print(&Apache::loncommon::start_data_table_row().
                   6358:                       '<td>'.$res->compTitle().'</td>'.
                   6359:                       '<td>'.$res->symb().'</td>'.
1.521     bisitz   6360:                       &Apache::loncommon::end_data_table_row());
1.484     raeburn  6361:             $count ++;
                   6362:         }
                   6363:         if (!$count) {
                   6364:             $r->print(&Apache::loncommon::start_data_table_row().
                   6365:                       '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
                   6366:                       &Apache::loncommon::end_data_table_row()); 
1.329     droeschl 6367:         }
1.484     raeburn  6368:         $r->print(&Apache::loncommon::end_data_table());
1.329     droeschl 6369:     }
1.521     bisitz   6370:     $r->print(&endContentScreen());
1.329     droeschl 6371: }
                   6372: 
1.651     raeburn  6373: sub short_urls {
                   6374:     my ($r,$canedit) = @_;
                   6375:     my $crstype = &Apache::loncommon::course_type();
                   6376:     my $formname = 'shortenurl';
                   6377:     $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
                   6378:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
                   6379:     $r->print(&startContentScreen('tools'));
                   6380:     my ($navmap,$errormsg) =
                   6381:         &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
                   6382:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   6383:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   6384:     my (%maps,%resources,%titles);
                   6385:     if (!ref($navmap)) {
                   6386:         $r->print($errormsg.
                   6387:                   &endContentScreen());
                   6388:         return '';
                   6389:     } else {
1.652     raeburn  6390:         $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651     raeburn  6391:         $r->rflush();
                   6392:         my $readonly;
                   6393:         if ($canedit) {
1.671     raeburn  6394:             my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651     raeburn  6395:             if ($numnew) {
                   6396:                 $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
                   6397:             }
                   6398:             if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
                   6399:                 $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
                   6400:                 foreach my $error (@{$errors}) {
                   6401:                     $r->print('<li>'.$error.'</li>');
                   6402:                 }
                   6403:                 $r->print('</ul><br />');
                   6404:             }
                   6405:         } else {
                   6406:             $readonly = 1;
                   6407:         }
                   6408:         my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
                   6409:         $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
1.711     raeburn  6410:                                                              undef,undef,undef,undef,undef,\%currtiny,undef,$readonly));
1.651     raeburn  6411:     }
                   6412:     $r->print(&endContentScreen());
                   6413: }
                   6414: 
1.637     raeburn  6415: sub contentverifyform {
                   6416:     my ($r) = @_;
                   6417:     my $crstype = &Apache::loncommon::course_type();
                   6418:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   6419:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
                   6420:     $r->print(&startContentScreen('tools'));
                   6421:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
                   6422:     $r->print('<form method="post" action="/adm/coursedocs"><p>'.
                   6423:               &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
                   6424:               '&nbsp;<span class="LC_nobreak">'.
                   6425:               '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
                   6426:               &mt('No').'</label>'.('&nbsp;'x2).
                   6427:               '<label><input type="radio" name="checkstale" value="1" />'.
                   6428:               &mt('Yes').'</label></span></p><p>'.
1.674     raeburn  6429:               '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637     raeburn  6430:               '<input type="hidden" value="1" name="tools" />'.
                   6431:               '<input type="hidden" value="1" name="verify" /></p></form>');
                   6432:     $r->print(&endContentScreen());
                   6433:     return;
                   6434: }
1.329     droeschl 6435: 
                   6436: sub verifycontent {
1.637     raeburn  6437:     my ($r,$checkstale) = @_;
1.408     raeburn  6438:     my $crstype = &Apache::loncommon::course_type();
1.549     raeburn  6439:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   6440:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484     raeburn  6441:     $r->print(&startContentScreen('tools'));
                   6442:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>'); 
1.329     droeschl 6443:    $hashtied=0;
                   6444:    undef %alreadyseen;
                   6445:    %alreadyseen=();
                   6446:    &tiehash();
1.484     raeburn  6447:    
1.329     droeschl 6448:    foreach my $key (keys(%hash)) {
                   6449:        if ($hash{$key}=~/\.(page|sequence)$/) {
                   6450: 	   if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
                   6451: 	       $r->print('<hr /><span class="LC_error">'.
1.419     bisitz   6452: 			 &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329     droeschl 6453: 			 &unescape($hash{$key}).'</span><br />'.
1.419     bisitz   6454: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329     droeschl 6455: 	   }
                   6456:        }
                   6457:        if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637     raeburn  6458:            &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329     droeschl 6459:        }
                   6460:    }
                   6461:    &untiehash();
1.442     www      6462:    $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521     bisitz   6463:     $r->print(&endContentScreen());
1.329     droeschl 6464: }
                   6465: 
                   6466: sub devalidateversioncache {
                   6467:     my $src=shift;
                   6468:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
                   6469: 					  &Apache::lonnet::clutter($src));
                   6470: }
                   6471: 
                   6472: sub checkversions {
1.611     raeburn  6473:     my ($r,$canedit) = @_;
1.408     raeburn  6474:     my $crstype = &Apache::loncommon::course_type();
1.571     raeburn  6475:     $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
                   6476:     $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484     raeburn  6477:     $r->print(&startContentScreen('tools'));
1.442     www      6478: 
1.329     droeschl 6479:     my $header='';
                   6480:     my $startsel='';
                   6481:     my $monthsel='';
                   6482:     my $weeksel='';
                   6483:     my $daysel='';
                   6484:     my $allsel='';
                   6485:     my %changes=();
                   6486:     my $starttime=0;
                   6487:     my $haschanged=0;
                   6488:     my %setversions=&Apache::lonnet::dump('resourceversions',
                   6489: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   6490: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   6491: 
                   6492:     $hashtied=0;
                   6493:     &tiehash();
1.611     raeburn  6494:     if ($canedit) {
                   6495:         my %newsetversions=();
                   6496:         if ($env{'form.setmostrecent'}) {
                   6497: 	    $haschanged=1;
                   6498: 	    foreach my $key (keys(%hash)) {
                   6499: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   6500: 		    $newsetversions{$1}='mostrecent';
                   6501:                     &devalidateversioncache($1);
                   6502: 	        }
                   6503: 	    }
                   6504:         } elsif ($env{'form.setcurrent'}) {
                   6505: 	    $haschanged=1;
                   6506: 	    foreach my $key (keys(%hash)) {
                   6507: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   6508: 		    my $getvers=&Apache::lonnet::getversion($1);
                   6509: 		    if ($getvers>0) {
                   6510: 		        $newsetversions{$1}=$getvers;
                   6511: 		        &devalidateversioncache($1);
                   6512: 		    }
                   6513: 	        }
1.329     droeschl 6514: 	    }
1.611     raeburn  6515:         } elsif ($env{'form.setversions'}) {
                   6516: 	    $haschanged=1;
                   6517: 	    foreach my $key (keys(%env)) {
                   6518: 	        if ($key=~/^form\.set_version_(.+)$/) {
                   6519: 		    my $src=$1;
                   6520: 		    if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
                   6521: 		        $newsetversions{$src}=$env{$key};
                   6522: 		        &devalidateversioncache($src);
                   6523: 		    }
                   6524: 	        }
1.329     droeschl 6525: 	    }
1.611     raeburn  6526:         }
                   6527:         if ($haschanged) {
                   6528:             if (&Apache::lonnet::put('resourceversions',\%newsetversions,
                   6529: 			             $env{'course.'.$env{'request.course.id'}.'.domain'},
                   6530: 			             $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
                   6531: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   6532:                     &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
                   6533: 	    } else {
                   6534: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   6535:                     &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329     droeschl 6536: 	    }
1.611     raeburn  6537: 	    &mark_hash_old();
                   6538:         }
                   6539:         &changewarning($r,'');
1.329     droeschl 6540:     }
                   6541:     if ($env{'form.timerange'} eq 'all') {
                   6542: # show all documents
1.549     raeburn  6543: 	$header=&mt('All content in '.$crstype);
1.521     bisitz   6544: 	$allsel=' selected="selected"';
1.329     droeschl 6545: 	foreach my $key (keys(%hash)) {
                   6546: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   6547: 		my $src=$1;
                   6548: 		$changes{$src}=1;
                   6549: 	    }
                   6550: 	}
                   6551:     } else {
                   6552: # show documents which changed
                   6553: 	%changes=&Apache::lonnet::dump
                   6554: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
                   6555:                      $env{'course.'.$env{'request.course.id'}.'.num'});
                   6556: 	my $firstkey=(keys(%changes))[0];
                   6557: 	unless ($firstkey=~/^error\:/) {
                   6558: 	    unless ($env{'form.timerange'}) {
                   6559: 		$env{'form.timerange'}=604800;
                   6560: 	    }
                   6561: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
                   6562: 		.&mt('seconds');
                   6563: 	    if ($env{'form.timerange'}==-1) {
                   6564: 		$seltext='since start of course';
1.521     bisitz   6565: 		$startsel=' selected="selected"';
1.329     droeschl 6566: 		$env{'form.timerange'}=time;
                   6567: 	    }
                   6568: 	    $starttime=time-$env{'form.timerange'};
                   6569: 	    if ($env{'form.timerange'}==2592000) {
                   6570: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   6571: 		$monthsel=' selected="selected"';
1.329     droeschl 6572: 	    } elsif ($env{'form.timerange'}==604800) {
                   6573: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   6574: 		$weeksel=' selected="selected"';
1.329     droeschl 6575: 	    } elsif ($env{'form.timerange'}==86400) {
                   6576: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   6577: 		$daysel=' selected="selected"';
1.329     droeschl 6578: 	    }
                   6579: 	    $header=&mt('Content changed').' '.$seltext;
                   6580: 	} else {
                   6581: 	    $header=&mt('No content modifications yet.');
                   6582: 	}
                   6583:     }
                   6584:     %setversions=&Apache::lonnet::dump('resourceversions',
                   6585: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   6586: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   6587:     my %lt=&Apache::lonlocal::texthash
1.408     raeburn  6588: 	      ('st' => 'Version changes since start of '.$crstype,
1.329     droeschl 6589: 	       'lm' => 'Version changes since last Month',
                   6590: 	       'lw' => 'Version changes since last Week',
                   6591: 	       'sy' => 'Version changes since Yesterday',
                   6592:                'al' => 'All Resources (possibly large output)',
1.484     raeburn  6593:                'cd' => 'Change display', 
1.329     droeschl 6594: 	       'sd' => 'Display',
                   6595: 	       'fi' => 'File',
                   6596: 	       'md' => 'Modification Date',
                   6597:                'mr' => 'Most recently published Version',
1.408     raeburn  6598: 	       've' => 'Version used in '.$crstype,
                   6599:                'vu' => 'Set Version to be used in '.$crstype,
                   6600: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329     droeschl 6601: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                   6602: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479     golterma 6603: 	       'di' => 'Differences',
1.484     raeburn  6604: 	       'save' => 'Save changes',
                   6605:                'vers' => 'Version choice(s) for specific resources', 
1.479     golterma 6606: 	       'act' => 'Actions');
1.611     raeburn  6607:     my ($disabled,$readonly);
                   6608:     unless ($canedit) {
                   6609:         $disabled = 'disabled="disabled"';
                   6610:         $readonly = 1;
                   6611:     }
1.329     droeschl 6612:     $r->print(<<ENDHEADERS);
1.484     raeburn  6613: <h4 class="LC_info">$header</h4>
1.329     droeschl 6614: <form action="/adm/coursedocs" method="post">
                   6615: <input type="hidden" name="versions" value="1" />
1.484     raeburn  6616: <div class="LC_left_float">
1.479     golterma 6617: <fieldset>
1.484     raeburn  6618: <legend>$lt{'cd'}</legend>
1.329     droeschl 6619: <select name="timerange">
1.521     bisitz   6620: <option value='all'$allsel>$lt{'al'}</option>
                   6621: <option value="-1"$startsel>$lt{'st'}</option>
                   6622: <option value="2592000"$monthsel>$lt{'lm'}</option>
                   6623: <option value="604800"$weeksel>$lt{'lw'}</option>
                   6624: <option value="86400"$daysel>$lt{'sy'}</option>
1.329     droeschl 6625: </select>
                   6626: <input type="submit" name="display" value="$lt{'sd'}" />
1.484     raeburn  6627: </fieldset>
                   6628: </div>
                   6629: <div class="LC_left_float">
                   6630: <fieldset>
                   6631: <legend>$lt{'act'}</legend>
1.611     raeburn  6632: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
                   6633: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484     raeburn  6634: </fieldset>
                   6635: </div>
                   6636: <br clear="all" />
                   6637: <hr />
                   6638: <h4>$lt{'vers'}</h4>
1.329     droeschl 6639: ENDHEADERS
1.479     golterma 6640:     #number of columns for version history
1.571     raeburn  6641:     my %changedbytime;
                   6642:     foreach my $key (keys(%changes)) {
                   6643:         #excludes not versionable problems from resource version history:
                   6644:         next if ($key =~ /^\/res\/lib\/templates/);
                   6645:         my $chg;
                   6646:         if ($env{'form.timerange'} eq 'all') {
                   6647:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   6648:             $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
                   6649:         } else {
                   6650:             $chg = $changes{$key};
                   6651:             next if ($chg < $starttime);
                   6652:         }
                   6653:         push(@{$changedbytime{$chg}},$key);
                   6654:     }
                   6655:     if (keys(%changedbytime) == 0) {
                   6656:         &untiehash();
                   6657:         $r->print(&mt('No content changes in imported content in specified time frame').
                   6658:                   &endContentScreen());
                   6659:         return;
                   6660:     }
1.479     golterma 6661:     $r->print(
1.611     raeburn  6662:        '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   6663:         &Apache::loncommon::start_data_table().
                   6664:         &Apache::loncommon::start_data_table_header_row().
                   6665:         '<th>'.&mt('Resources').'</th>'.
                   6666:         "<th>$lt{'mr'}</th>".
                   6667:         "<th>$lt{'ve'}</th>".
                   6668:         "<th>$lt{'vu'}</th>".
                   6669:         '<th>'.&mt('History').'</th>'.
                   6670:         &Apache::loncommon::end_data_table_header_row()
                   6671:     );
1.571     raeburn  6672:     foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
                   6673:         foreach my $key (sort(@{$changedbytime{$chg}})) {
                   6674:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   6675:             my $currentversion=&Apache::lonnet::getversion($key);
                   6676:             if ($currentversion<0) {
                   6677:                 $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
                   6678:             }
                   6679:             my $linkurl=&Apache::lonnet::clutter($key);
                   6680:             $r->print(
                   6681:                 &Apache::loncommon::start_data_table_row().
                   6682:                 '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
                   6683:                 '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
                   6684:                 '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
                   6685:                 &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
                   6686:                 '<td align="right">'
                   6687:             );
                   6688:             # Used in course
                   6689:             my $usedversion=$hash{'version_'.$linkurl};
                   6690:             if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521     bisitz   6691:                 if ($usedversion != $currentversion) {
1.479     golterma 6692:                     $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521     bisitz   6693:                 } else {
1.479     golterma 6694:                     $r->print($usedversion);
                   6695:                 }
1.329     droeschl 6696:             } else {
1.521     bisitz   6697:                 $r->print($currentversion);
1.329     droeschl 6698:             }
1.571     raeburn  6699:             $r->print('</td><td title="'.$lt{'vu'}.'">');
                   6700:             # Set version
                   6701:             $r->print(&Apache::loncommon::select_form(
                   6702:                       $setversions{$linkurl},
                   6703:                       'set_version_'.$linkurl,
                   6704:                       {'select_form_order' => ['',1..$currentversion,'mostrecent'],
                   6705:                       '' => '',
                   6706:                       'mostrecent' => &mt('most recent'),
1.611     raeburn  6707:                       map {$_,$_} (1..$currentversion)},'',$readonly));
1.571     raeburn  6708:             my $lastold=1;
                   6709:             for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                   6710:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   6711:                 if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
                   6712:                     $lastold=$prevvers;
                   6713:                 }
                   6714:             }
                   6715:             $r->print('</td>');
                   6716:             # List all available versions
                   6717:             $r->print('<td valign="top"><span class="LC_fontsize_medium">');
                   6718:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
                   6719:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   6720:                 $r->print(
                   6721:                     '<span class="LC_nobreak">'
                   6722:                    .'<a href="'.&Apache::lonnet::clutter($url).'">'
                   6723:                    .&mt('Version [_1]',$prevvers).'</a>'
                   6724:                    .' ('.&Apache::lonlocal::locallocaltime(
1.521     bisitz   6725:                          &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571     raeburn  6726:                    .')');
                   6727:                 if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
                   6728:                     $r->print(
                   6729:                         ' <a href="/adm/diff?filename='.
                   6730:                         &Apache::lonnet::clutter($root.'.'.$extension).
                   6731:                         &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
                   6732:                         '" target="diffs">'.&mt('Diffs').'</a>');
                   6733:                 }
                   6734:                 $r->print('</span><br />');
1.329     droeschl 6735:             }
1.571     raeburn  6736:             $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521     bisitz   6737:         }
1.329     droeschl 6738:     }
1.521     bisitz   6739:     $r->print(
                   6740:         &Apache::loncommon::end_data_table().
1.611     raeburn  6741:         '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   6742:         '</form>'
                   6743:     );
1.329     droeschl 6744: 
                   6745:     &untiehash();
1.521     bisitz   6746:     $r->print(&endContentScreen());
1.571     raeburn  6747:     return;
1.329     droeschl 6748: }
                   6749: 
                   6750: sub mark_hash_old {
                   6751:     my $retie_hash=0;
                   6752:     if ($hashtied) {
                   6753: 	$retie_hash=1;
                   6754: 	&untiehash();
                   6755:     }
                   6756:     &tiehash('write');
                   6757:     $hash{'old'}=1;
                   6758:     &untiehash();
                   6759:     if ($retie_hash) { &tiehash(); }
                   6760: }
                   6761: 
                   6762: sub is_hash_old {
                   6763:     my $untie_hash=0;
                   6764:     if (!$hashtied) {
                   6765: 	$untie_hash=1;
                   6766: 	&tiehash();
                   6767:     }
                   6768:     my $return=$hash{'old'};
                   6769:     if ($untie_hash) { &untiehash(); }
                   6770:     return $return;
                   6771: }
                   6772: 
                   6773: sub changewarning {
                   6774:     my ($r,$postexec,$message,$url)=@_;
                   6775:     if (!&is_hash_old()) { return; }
                   6776:     my $pathvar='folderpath';
                   6777:     my $path=&escape($env{'form.folderpath'});
                   6778:     if (!defined($url)) {
                   6779: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
                   6780:     }
                   6781:     my $course_type = &Apache::loncommon::course_type();
                   6782:     if (!defined($message)) {
                   6783: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
                   6784:     }
1.653     raeburn  6785:     my $windowname = 'loncapaclient';
                   6786:     if ($env{'request.lti.login'}) {
                   6787:         $windowname .= 'lti';
                   6788:     }
1.329     droeschl 6789:     $r->print("\n\n".
1.372     bisitz   6790: '<script type="text/javascript">'."\n".
                   6791: '// <![CDATA['."\n".
                   6792: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
                   6793: '// ]]>'."\n".
1.369     bisitz   6794: '</script>'."\n".
1.653     raeburn  6795: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329     droeschl 6796: '<input type="hidden" name="orgurl" value="'.$url.
1.372     bisitz   6797: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329     droeschl 6798: &mt($message,' <input type="hidden" name="'.
                   6799:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369     bisitz   6800:     &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372     bisitz   6801: $help{'Caching'}.'</p></form>'."\n\n");
1.329     droeschl 6802: }
                   6803: 
                   6804: 
                   6805: sub init_breadcrumbs {
1.571     raeburn  6806:     my ($form,$text,$help)=@_;
1.329     droeschl 6807:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484     raeburn  6808:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405     bisitz   6809: 					    text=>&Apache::loncommon::course_type().' Editor',
1.329     droeschl 6810: 					    faq=>273,
                   6811: 					    bug=>'Instructor Interface',
1.571     raeburn  6812:                                             help => $help});
1.329     droeschl 6813:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
                   6814: 					    text=>$text,
                   6815: 					    faq=>273,
                   6816: 					    bug=>'Instructor Interface'});
                   6817: }
                   6818: 
1.441     www      6819: # subroutine to list form elements
                   6820: sub create_list_elements {
                   6821:    my @formarr = @_;
                   6822:    my $list = '';
1.501     raeburn  6823:    foreach my $button (@formarr){
                   6824:         foreach my $picture (keys(%{$button})) {
                   6825:             $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441     www      6826:         }
                   6827:    }
                   6828:    return $list;
                   6829: }
1.329     droeschl 6830: 
1.441     www      6831: # subroutine to create ul from list elements
                   6832: sub create_form_ul {
                   6833:    my $list = shift;
                   6834:    my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
                   6835:    return $ul;
                   6836: }
1.329     droeschl 6837: 
1.442     www      6838: #
                   6839: # Start tabs
                   6840: #
                   6841: 
                   6842: sub startContentScreen {
1.484     raeburn  6843:     my ($mode) = @_;
                   6844:     my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472     raeburn  6845:     if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484     raeburn  6846:         $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";
                   6847:         $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";
                   6848:         $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";
                   6849:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
                   6850:     } else {
1.549     raeburn  6851:         $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  6852:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
                   6853:         $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";
                   6854:                    '><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>';
                   6855:     }
                   6856:     $output .= "\n".'</ul>'."\n";
                   6857:     $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
                   6858:                '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
                   6859:                '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
                   6860:     return $output;
1.442     www      6861: }
                   6862: 
                   6863: #
                   6864: # End tabs
                   6865: #
                   6866: 
                   6867: sub endContentScreen {
1.484     raeburn  6868:     return '</div></div></div>';
1.442     www      6869: }
1.329     droeschl 6870: 
1.446     www      6871: sub supplemental_base {
1.548     raeburn  6872:     return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446     www      6873: }
                   6874: 
1.329     droeschl 6875: sub handler {
                   6876:     my $r = shift;
                   6877:     &Apache::loncommon::content_type($r,'text/html');
                   6878:     $r->send_http_header;
                   6879:     return OK if $r->header_only;
1.484     raeburn  6880: 
                   6881: # get course data
1.408     raeburn  6882:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  6883:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   6884:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.712     raeburn  6885:     my $coursehome=$env{'course.'.$env{'request.course.id'}.'.home'};
1.484     raeburn  6886: 
1.606     raeburn  6887: # get docroot
                   6888:     my $londocroot = $r->dir_config('lonDocRoot');
                   6889: 
1.484     raeburn  6890: # graphics settings
                   6891:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329     droeschl 6892: 
1.443     www      6893: #
1.329     droeschl 6894: # --------------------------------------------- Initialize help topics for this
                   6895:     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627     raeburn  6896: 	               'Adding_External_Resource','Adding_External_Tool',
                   6897:                        'Navigate_Content','Adding_Folders','Docs_Overview',
                   6898: 	               'Load_Map','Supplemental','Score_Upload_Form',
                   6899: 	               'Adding_Pages','Importing_LON-CAPA_Resource',
                   6900: 	               'Importing_IMS_Course','Uploading_From_Harddrive',
1.706     raeburn  6901:                        'Course_Roster','Web_Page','Dropbox','Simple_Problem',
                   6902:                        'Standard_Problem','Course_Resources',
                   6903:                        'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329     droeschl 6904: 	$help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
                   6905:     }
                   6906:     # Composite help files
                   6907:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   6908: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   6909:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   6910: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
                   6911:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   6912: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347     weissno  6913:     $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329     droeschl 6914: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353     weissno  6915:     $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329     droeschl 6916:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534     raeburn  6917:  
1.611     raeburn  6918:     my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682     raeburn  6919: # does this user have privileges to modify content.
                   6920:     if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472     raeburn  6921: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682     raeburn  6922:         unless ($r->uri eq '/adm/supplemental') {
1.611     raeburn  6923:             $allowed = 1;
1.682     raeburn  6924:         }
                   6925:         $canedit = 1;
                   6926:         $canview = 1;
                   6927:     } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
                   6928: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
                   6929:         unless ($r->uri eq '/adm/supplemental') {
1.611     raeburn  6930:             $allowed = 1;
                   6931:         }
1.682     raeburn  6932:         $canview = 1;
1.611     raeburn  6933:     }
                   6934:     unless ($canedit) {
                   6935:         $disabled = ' disabled="disabled"';
1.472     raeburn  6936:     }
1.582     raeburn  6937:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635     raeburn  6938:     if ($env{'form.inhibitmenu'}) {
                   6939:         unless ($env{'form.inhibitmenu'} eq 'yes') {
                   6940:             delete($env{'form.inhibitmenu'});
                   6941:         }
                   6942:     }
                   6943: 
1.582     raeburn  6944:   if ($allowed && $env{'form.verify'}) {
1.571     raeburn  6945:       &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637     raeburn  6946:       if (!$canedit) {
                   6947:           &verifycontent($r);
                   6948:       } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
                   6949:           &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
                   6950:                                                   text=>'Results',
                   6951:                                                   faq=>273,
                   6952:                                                   bug=>'Instructor Interface'});
                   6953:           &verifycontent($r,$env{'form.checkstale'});
                   6954:       } else {
                   6955:           &contentverifyform($r);
                   6956:       }
1.329     droeschl 6957:   } elsif ($allowed && $env{'form.listsymbs'}) {
1.484     raeburn  6958:       &init_breadcrumbs('listsymbs','List Content IDs');
1.329     droeschl 6959:       &list_symbs($r);
1.651     raeburn  6960:   } elsif ($allowed && $env{'form.shorturls'}) {
                   6961:       &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
                   6962:       &short_urls($r,$canedit);
1.329     droeschl 6963:   } elsif ($allowed && $env{'form.docslog'}) {
                   6964:       &init_breadcrumbs('docslog','Show Log');
1.484     raeburn  6965:       my $folder = $env{'form.folder'};
                   6966:       if ($folder eq '') {
                   6967:           $folder='default';
                   6968:       }
1.611     raeburn  6969:       &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329     droeschl 6970:   } elsif ($allowed && $env{'form.versions'}) {
1.571     raeburn  6971:       &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611     raeburn  6972:       &checkversions($r,$canedit);
                   6973:   } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709     raeburn  6974:       &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329     droeschl 6975:       &dumpcourse($r);
1.712     raeburn  6976:   } elsif (($canedit || $canview) && ($env{'form.copyauthored'})) {
                   6977:       &init_breadcrumbs('copyauthored','Copy from Course Authoring to User Authoring');
                   6978:       my $readonly;
                   6979:       if (!$canedit) {
                   6980:           $readonly = 1;
                   6981:       }
                   6982:       &copycrsauthored($r,$coursenum,$coursedom,$coursehome,$readonly);
1.611     raeburn  6983:   } elsif ($canedit && $env{'form.exportcourse'}) {
1.377     bisitz   6984:       &init_breadcrumbs('exportcourse','IMS Export');
1.475     raeburn  6985:       &Apache::imsexport::exportcourse($r);
1.329     droeschl 6986:   } else {
1.611     raeburn  6987:       if ($canedit && $env{'form.authorrole'}) {
1.606     raeburn  6988:           $noendpage = 1;
                   6989:           my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
                   6990:           if ($redirect) {
                   6991:               if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
                   6992:                   my $container = 'sequence'; 
                   6993:                   my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   6994:                       $is_random_order,$container) =
                   6995:                       &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   6996:                   my (@folders)=split('&',$env{'form.folderpath'});
                   6997:                   $env{'form.foldername'}=&unescape(pop(@folders));
                   6998:                   my $folder=pop(@folders);
                   6999:                   my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   7000:                                                   $folder.'.'.$container);
                   7001:                   my $warning;
                   7002:                   if ($fatal) {
                   7003:                       if ($container eq 'page') {
                   7004:                           $warning = &mt('An error occurred retrieving the contents of the current page.');
                   7005:                       } else {
                   7006:                           $warning = &mt('An error occurred retrieving the contents of the current folder.');
                   7007:                       }
                   7008:                   } else {
                   7009:                       my $url = $redirect;
                   7010:                       my $srcfile = $londocroot.$url;
                   7011:                       $url =~ s{^/priv/}{/res/};
                   7012:                       my $targetfile = $londocroot.$url;
                   7013:                       my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   7014:                       my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
                   7015:                       $env{'form.folder'} = $folder;
                   7016:                       &snapshotbefore();
                   7017:                       my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
                   7018:                       my $ext = 'false';
                   7019:                       my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   7020:                       $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   7021:                                                         ':'.$ext.':normal:res';
                   7022:                       push(@LONCAPA::map::order,$newidx);
                   7023:                       &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
                   7024:                                                    'string_yesno');
                   7025:                       &remember_parms($newidx,'hiddenresource','set','yes');
                   7026:                       ($errtext,$fatal) =
                   7027:                           &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
                   7028:                       &log_differences($plain);
                   7029:                       &mark_hash_old();
                   7030:                       $r->internal_redirect($redirect);
                   7031:                       return OK;
                   7032:                   }
1.654     raeburn  7033:               } else {
                   7034:                   $r->internal_redirect($redirect);
1.606     raeburn  7035:               }
                   7036:           }
                   7037:       }
1.445     www      7038: #
                   7039: # Done catching special calls
1.484     raeburn  7040: # The whole rest is for course and supplemental documents and utilities menu
1.445     www      7041: # Get the parameters that may be needed
                   7042: #
                   7043:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682     raeburn  7044:                                             ['folderpath','title',
1.519     raeburn  7045:                                              'forcesupplement','forcestandard',
1.510     raeburn  7046:                                              'tools','symb','command','supppath']);
1.445     www      7047: 
1.635     raeburn  7048:     foreach my $item ('forcesupplement','forcestandard','tools') {
                   7049:         next if ($env{'form.'.$item} eq '');
                   7050:         unless ($env{'form.'.$item} eq '1') {
                   7051:             delete($env{'form.'.$item});
                   7052:         }
                   7053:     }
                   7054: 
                   7055:     if ($env{'form.command'}) {
                   7056:         unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
                   7057:             delete($env{'form.command'});
                   7058:         }
                   7059:     }
                   7060: 
                   7061:     if ($env{'form.symb'}) {
                   7062:         my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   7063:         unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { 
                   7064:             delete($env{'form.symb'});
                   7065:         }
                   7066:     }
                   7067: 
1.445     www      7068: # standard=1: this is a "new-style" course with an uploaded map as top level
                   7069: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329     droeschl 7070: 
                   7071:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445     www      7072: 
1.484     raeburn  7073: # Decide whether this should display supplemental or main content or utilities
1.445     www      7074: # supplementalflag=1: show supplemental documents
                   7075: # supplementalflag=0: show standard documents
1.484     raeburn  7076: # toolsflag=1: show utilities
1.445     www      7077: 
1.561     raeburn  7078:     my $unesc_folderpath = &unescape($env{'form.folderpath'});
                   7079:     my $supplementalflag=($unesc_folderpath=~/^supplemental/);
                   7080:     if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445     www      7081:        $supplementalflag=0;
                   7082:     }
                   7083:     if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
                   7084:     if ($env{'form.forcestandard'})   { $supplementalflag=0; }
1.705     raeburn  7085:     unless (($supplementalflag) ||
                   7086:             ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
                   7087:         unless ($allowed) { $supplementalflag=1; }
                   7088:         unless ($standard) { $supplementalflag=1; }
                   7089:     }
1.484     raeburn  7090:     my $toolsflag=0;
                   7091:     if ($env{'form.tools'}) { $toolsflag=1; }
1.445     www      7092: 
1.635     raeburn  7093:     if ($env{'form.folderpath'} ne '') {
1.685     raeburn  7094:         &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635     raeburn  7095:     }
                   7096: 
1.685     raeburn  7097:     my $backto_supppath;
1.635     raeburn  7098:     if ($env{'form.supppath'} ne '') {
1.685     raeburn  7099:         if ($supplementalflag && $allowed) {
                   7100:             $backto_supppath = &validate_supppath($coursenum,$coursedom);
                   7101:         }
1.635     raeburn  7102:     }
                   7103: 
1.329     droeschl 7104:     my $script='';
                   7105:     my $showdoc=0;
1.457     raeburn  7106:     my $addentries = {};
1.475     raeburn  7107:     my $container;
1.329     droeschl 7108:     my $containertag;
1.508     raeburn  7109:     my $pathitem;
1.598     raeburn  7110:     my %ltitools;
1.699     raeburn  7111:     my $posslti;
1.617     raeburn  7112:     my $hiddentop;
1.615     raeburn  7113:     my $navmap;
1.617     raeburn  7114:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329     droeschl 7115: 
1.464     www      7116: # Do we directly jump somewhere?
1.525     raeburn  7117:    if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472     raeburn  7118:        if ($env{'form.symb'} ne '') {
1.522     raeburn  7119:            $env{'form.folderpath'}=
1.617     raeburn  7120:                &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530     raeburn  7121:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525     raeburn  7122:                $env{'form.command'}.'_'.$env{'form.symb'}});
1.685     raeburn  7123:        } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472     raeburn  7124:            $env{'form.folderpath'}=$env{'form.supppath'};
1.530     raeburn  7125:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685     raeburn  7126:                $env{'form.command'}.'_'.$backto_supppath});
1.466     www      7127:        }
1.472     raeburn  7128:    } elsif ($env{'form.command'} eq 'editdocs') {
1.617     raeburn  7129:        $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525     raeburn  7130:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472     raeburn  7131:    } elsif ($env{'form.command'} eq 'editsupp') {
1.617     raeburn  7132:        $env{'form.folderpath'} = &supplemental_base();
1.525     raeburn  7133:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
                   7134:    } elsif ($env{'form.command'} eq 'contents') {
                   7135:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
                   7136:    } elsif ($env{'form.command'} eq 'home') {
                   7137:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464     www      7138:    }
                   7139: 
1.525     raeburn  7140: 
1.445     www      7141: # Where do we store these for when we come back?
                   7142:     my $stored_folderpath='docs_folderpath';
                   7143:     if ($supplementalflag) {
                   7144:        $stored_folderpath='docs_sup_folderpath';
                   7145:     }
1.464     www      7146: 
1.519     raeburn  7147: # No folderpath, and in edit mode, see if we have something stored
                   7148:     if ((!$env{'form.folderpath'}) && $allowed) {
1.445     www      7149:         &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510     raeburn  7150:                                           {'folderpath' => 'scalar'});
1.615     raeburn  7151: 
                   7152:         if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
                   7153:             if ($supplementalflag) {
                   7154:                 undef($env{'form.folderpath'}) if ($1 eq 'default'); 
                   7155:             } else {
                   7156:                 undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
                   7157:             }
                   7158:         } else {
1.523     raeburn  7159:             undef($env{'form.folderpath'});
                   7160:         }
1.677     raeburn  7161:         if ($env{'form.folderpath'} ne '') {
1.685     raeburn  7162:             &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677     raeburn  7163:         }
1.329     droeschl 7164:     }
1.706     raeburn  7165: 
                   7166: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705     raeburn  7167:     if ((!$allowed) && ($supplementalflag)) {
1.446     www      7168:         unless ($env{'form.folderpath'} =~ /^supplemental/) {
                   7169:             $env{'form.folderpath'} = &supplemental_base();
1.409     raeburn  7170:         }
                   7171:     }
1.446     www      7172: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329     droeschl 7173:     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446     www      7174:         $env{'form.folderpath'} = &supplemental_base()
                   7175:                                   .'&'.
1.329     droeschl 7176:                                   $env{'form.folderpath'};
                   7177:     }
1.685     raeburn  7178: # If allowed and user's role is not advanced check folderpath is not hidden
                   7179:     my $hidden_and_empty;
1.687     raeburn  7180:     if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685     raeburn  7181:         my ($folderurl,$foldername,$hiddenfolder);
1.615     raeburn  7182:         my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617     raeburn  7183:         my $folder = $pathitems[-2];
                   7184:         if ($folder eq '') {
                   7185:             undef($env{'form.folderpath'});
                   7186:         } else {
                   7187:             $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666     raeburn  7188:             if ((split(/\:/,$pathitems[-1]))[5]) {
1.615     raeburn  7189:                 $folderurl .= '.page';
                   7190:             } else {
                   7191:                 $folderurl .= '.sequence';
                   7192:             }
1.685     raeburn  7193:             if ($supplementalflag) {
                   7194:                 ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
                   7195:                 $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688     raeburn  7196:                 my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn  7197:                 if (ref($supplemental) eq 'HASH') {
                   7198:                     my ($suppmap,$suppmapnum);
                   7199:                     if ($folder eq 'supplemental') {
                   7200:                         $suppmap = 'default';
                   7201:                         $suppmapnum = 0;
                   7202:                     } elsif ($folder =~ /^supplemental_(\d+)$/) {
                   7203:                         $suppmap = $1;
                   7204:                         $suppmapnum = $suppmap;
                   7205:                     }
                   7206:                     if ($hiddenfolder) {
                   7207:                         my $hascontent;
                   7208:                         foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
                   7209:                             if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
                   7210:                                 $hascontent = 1;
                   7211:                             } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
                   7212:                                 foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
                   7213:                                     if ($id =~ /^$suppmapnum\:/) {
                   7214:                                         $hascontent = 1;
                   7215:                                         last;
                   7216:                                     }
                   7217:                                 }
                   7218:                             }
                   7219:                             last if ($hascontent);
                   7220:                         }
                   7221:                         unless ($hascontent) {
                   7222:                             if ($foldername ne '') {
                   7223:                                 $hidden_and_empty = $foldername;
                   7224:                             } else {
                   7225:                                 $hidden_and_empty = $folder;
                   7226:                             }
                   7227:                         }
                   7228:                     }
                   7229:                 }
                   7230:             } else {
                   7231:                 unless (ref($navmap)) {
                   7232:                     $navmap = Apache::lonnavmaps::navmap->new();
                   7233:                 }
                   7234:                 ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
                   7235:                 $foldername = &HTML::Entities::decode(&unescape($foldername));
                   7236:                 if (ref($navmap)) {
                   7237:                     if ($hiddenfolder ||
                   7238:                         (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
                   7239:                         my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
                   7240:                         unless (@resources) {
                   7241:                             if ($foldername ne '') {
                   7242:                                 $hidden_and_empty = $foldername;
                   7243:                             } else {
                   7244:                                 $hidden_and_empty = $folder;
                   7245:                             }
                   7246:                         }
                   7247:                     }
                   7248:                 }
1.617     raeburn  7249:             }
1.685     raeburn  7250:             if ($hidden_and_empty ne '') {
                   7251:                 splice(@pathitems,-2);
                   7252:                 if (@pathitems) {
                   7253:                     $env{'form.folderpath'} = join('&',@pathitems);
                   7254:                 } else {
                   7255:                     undef($env{'form.folderpath'});
1.615     raeburn  7256:                 }
                   7257:             }
                   7258:         }
                   7259:     }
                   7260: 
1.446     www      7261: # If after all of this, we still don't have any paths, make them
1.519     raeburn  7262:     unless ($env{'form.folderpath'}) {
1.446     www      7263:        if ($supplementalflag) {
                   7264:           $env{'form.folderpath'}=&supplemental_base();
1.617     raeburn  7265:        } elsif ($allowed) {
                   7266:           ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446     www      7267:        }
1.472     raeburn  7268:     }
1.446     www      7269: 
1.445     www      7270: # Store this
1.484     raeburn  7271:     unless ($toolsflag) {
1.615     raeburn  7272:         if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510     raeburn  7273:             &Apache::loncommon::store_course_settings($stored_folderpath,
1.519     raeburn  7274:                                                       {'folderpath' => 'scalar'});
1.510     raeburn  7275:         }
1.519     raeburn  7276:         my $folderpath;
1.484     raeburn  7277:         if ($env{'form.folderpath'}) {
1.519     raeburn  7278:             $folderpath = $env{'form.folderpath'};
                   7279: 	    my (@folders)=split('&',$env{'form.folderpath'});
                   7280: 	    $env{'form.foldername'}=&unescape(pop(@folders));
                   7281:             if ($env{'form.foldername'} =~ /\:1$/) {
                   7282:                 $container = 'page';
                   7283:             } else {
                   7284:                 $container = 'sequence';
                   7285:             }
                   7286: 	    $env{'form.folder'}=pop(@folders);
1.484     raeburn  7287:         } else {
1.519     raeburn  7288:             if ($env{'form.folder'} eq '' ||
                   7289:                 $env{'form.folder'} eq 'supplemental') {
1.617     raeburn  7290:                 if ($env{'form.folder'} eq 'supplemental') {
                   7291:                     $folderpath=&supplemental_base();
                   7292:                 } elsif (!$hiddentop) {
                   7293:                     $folderpath='default&'.
                   7294:                                  &escape(&mt('Main Content').':::::');
                   7295:                 }
1.484     raeburn  7296:             }
                   7297:         }
1.519     raeburn  7298:         $containertag = '<input type="hidden" name="folderpath" value="" />';
                   7299:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484     raeburn  7300:         if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
                   7301:            $showdoc='/'.$1;
                   7302:         }
                   7303:         if ($showdoc) { # got called in sequence from course
                   7304: 	    $allowed=0; 
                   7305:         } else {
1.611     raeburn  7306:             if ($canedit) {
1.484     raeburn  7307:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   7308:                 $script=&Apache::lonratedt::editscript('simple');
1.433     raeburn  7309:             }
                   7310:         }
1.329     droeschl 7311:     }
                   7312: 
1.344     bisitz   7313: # get personal data
1.329     droeschl 7314:     my $uname=$env{'user.name'};
                   7315:     my $udom=$env{'user.domain'};
                   7316:     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
                   7317: 
                   7318:     if ($allowed) {
1.484     raeburn  7319:         if ($toolsflag) {
                   7320:             $script .= &inject_data_js();
                   7321:             my ($home,$other,%outhash)=&authorhosts();
                   7322:             if (!$home && $other) {
                   7323:                 my @hosts;
                   7324:                 foreach my $aurole (keys(%outhash)) {
                   7325:                     unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   7326:                         push(@hosts,$outhash{$aurole});
                   7327:                     }
                   7328:                 }
                   7329:                 $script .= &dump_switchserver_js(@hosts); 
                   7330:             }
1.458     raeburn  7331:         } else {
1.570     raeburn  7332:             my $tid = 1;
1.484     raeburn  7333:             my @tabids;
                   7334:             if ($supplementalflag) {
1.655     raeburn  7335:                 @tabids = ('002','dd2','ee2','ff2');
1.570     raeburn  7336:                 $tid = 2;
1.484     raeburn  7337:             } else {
                   7338:                 @tabids = ('aa1','bb1','cc1','ff1');
1.519     raeburn  7339:                 unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484     raeburn  7340:                     unshift(@tabids,'001');
                   7341:                     push(@tabids,('dd1','ee1'));
                   7342:                 }
1.458     raeburn  7343:             }
1.484     raeburn  7344:             my $tabidstr = join("','",@tabids);
1.699     raeburn  7345:             my (%domtools,%crstools);
                   7346:             my %tooltypes = &Apache::loncommon::usable_exttools();
                   7347:             if ($tooltypes{'dom'}) {
                   7348:                 %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
                   7349:             }
                   7350:             if ($tooltypes{'crs'}) {
                   7351:                 %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
                   7352:             }
                   7353:             %ltitools = (
                   7354:                           dom => \%domtools,
                   7355:                           crs => \%crstools,
                   7356:                         );
                   7357:             $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622     raeburn  7358:             my $hostname = $r->hostname();
1.606     raeburn  7359: 	    $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622     raeburn  7360:                                    $londocroot,$canedit,$hostname,\$navmap).
1.484     raeburn  7361:                        &history_tab_js().
                   7362:                        &inject_data_js().
1.570     raeburn  7363:                        &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598     raeburn  7364:                        &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685     raeburn  7365:             my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
                   7366:             if ($hidden_and_empty ne '') {
                   7367:                 my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
                   7368:                                 $hidden_and_empty);
                   7369:                 $onload .= "javascript:alert('".&js_escape($alert)."');";
                   7370:             }
1.484     raeburn  7371:             $addentries = {
1.685     raeburn  7372:                             onload => $onload,
1.484     raeburn  7373:                           };
1.458     raeburn  7374:         }
1.538     raeburn  7375:         $script .= &paste_popup_js(); 
1.501     raeburn  7376:         my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
                   7377:                              &mt('Switch server?');
                   7378:         
                   7379: 
1.329     droeschl 7380:     }
                   7381: # -------------------------------------------------------------------- Body tag
1.369     bisitz   7382:     $script = '<script type="text/javascript">'."\n"
1.372     bisitz   7383:               .'// <![CDATA['."\n"
                   7384:               .$script."\n"
                   7385:               .'// ]]>'."\n"
1.595     musolffc 7386:               .'</script>'."\n"
                   7387:               .'<script type="text/javascript" 
                   7388:                 src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385     bisitz   7389: 
                   7390:     # Breadcrumbs
                   7391:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510     raeburn  7392: 
                   7393:     if ($showdoc) {
1.682     raeburn  7394:         my $args;
                   7395:         if ($supplementalflag) {
1.687     raeburn  7396:             my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
                   7397:             my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705     raeburn  7398:             $args = {'bread_crumbs' => $brcrum,
                   7399:                      'bread_crumbs_nomenu' => 1};
1.682     raeburn  7400:         } else {
                   7401:             $args = {'force_register' => $showdoc};
                   7402:         }
                   7403:         $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571     raeburn  7404:     } elsif ($toolsflag) {
1.611     raeburn  7405:         my ($breadtext,$breadtitle);
1.617     raeburn  7406:         $breadtext = "$crstype Editor";
1.611     raeburn  7407:         if ($canedit) {
                   7408:             $breadtitle = 'Editing '.$crstype.' Contents';
                   7409:         } else {
                   7410:             $breadtext .= ' (View-only mode)';
                   7411:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   7412:         }
1.571     raeburn  7413:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  7414:             href=>"/adm/coursedocs",text=>$breadtext});
1.571     raeburn  7415:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
                   7416:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   7417:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  7418:                      $breadtitle)
1.571     raeburn  7419:                  );
1.510     raeburn  7420:     } elsif ($r->uri eq '/adm/supplemental') {
1.682     raeburn  7421:         unless ($env{'request.role.adv'}) {
                   7422:             unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
                   7423:                 $r->internal_redirect('/adm/navmaps');
                   7424:                 return OK;
                   7425:             }
                   7426:         }
1.510     raeburn  7427:         my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705     raeburn  7428:         my $args = {'bread_crumbs' => $brcrum};
                   7429:         unless (($env{'form.folderpath'} eq '') ||
                   7430:                 ($env{'form.folder'} eq 'supplemental')) {
                   7431:             $args->{'bread_crumbs_nomenu'} = 1;
                   7432:         }
1.510     raeburn  7433:         $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705     raeburn  7434:                                                  $args));
1.510     raeburn  7435:     } else {
1.611     raeburn  7436:         my ($breadtext,$breadtitle,$helpitem);
1.617     raeburn  7437:         $breadtext = "$crstype Editor";
1.611     raeburn  7438:         if ($canedit) {
                   7439:             $breadtitle = 'Editing '.$crstype.' Contents';
                   7440:             $helpitem = 'Docs_Adding_Course_Doc';
                   7441:         } else {
                   7442:             $breadtext .= ' (View-only mode)';
                   7443:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   7444:             $helpitem = 'Docs_Viewing_Course_Doc';
                   7445:         }
1.392     raeburn  7446:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  7447:             href=>"/adm/coursedocs",text=>$breadtext});
1.446     www      7448:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510     raeburn  7449:                                                  {'add_entries'    => $addentries}
                   7450:                                                 )
1.392     raeburn  7451:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   7452:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  7453:                      $breadtitle,
                   7454:                      $helpitem)
1.392     raeburn  7455:         );
                   7456:     }
1.364     bisitz   7457: 
1.329     droeschl 7458:   my %allfiles = ();
                   7459:   my %codebase = ();
1.440     raeburn  7460:   my ($upload_result,$upload_output,$uploadphase);
1.611     raeburn  7461:   if ($canedit) {
1.684     raeburn  7462:       undef($suppchanges);
1.329     droeschl 7463:       if (($env{'form.uploaddoc.filename'}) &&
                   7464: 	  ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440     raeburn  7465:           my $context = $1; 
                   7466:           # Process file upload - phase one - upload and parse primary file.
1.329     droeschl 7467: 	  undef($hadchanges);
1.440     raeburn  7468:           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552     raeburn  7469:                                               \%allfiles,\%codebase,$context,$crstype);
1.638     raeburn  7470:           undef($navmap);
1.329     droeschl 7471: 	  if ($hadchanges) {
                   7472: 	      &mark_hash_old();
                   7473: 	  }
1.684     raeburn  7474:           if ($suppchanges) {
                   7475:               &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
                   7476:               undef($suppchanges);
                   7477:           }
1.440     raeburn  7478:           $r->print($upload_output);
                   7479:       } elsif ($env{'form.phase'} eq 'upload_embedded') {
                   7480:           # Process file upload - phase two - upload embedded objects 
                   7481:           $uploadphase = 'check_embedded';
                   7482:           my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');   
                   7483:           my $state = &embedded_form_elems($uploadphase,$primaryurl,
                   7484:                                            $env{'form.newidx'});
                   7485:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   7486:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   7487:           my ($destination,$dir_root) = &embedded_destination();
                   7488:           my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
                   7489:           my $actionurl = '/adm/coursedocs';
1.630     raeburn  7490:           my ($result,$flag) =
1.440     raeburn  7491:               &Apache::loncommon::upload_embedded('coursedoc',$destination,
                   7492:                   $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
                   7493:                   $actionurl);
                   7494:           $r->print($result.&return_to_editor());
                   7495:       } elsif ($env{'form.phase'} eq 'check_embedded') {
                   7496:           # Process file upload - phase three - modify references in HTML file
                   7497:           $uploadphase = 'modified_orightml';
                   7498:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   7499:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   7500:           my ($destination,$dir_root) = &embedded_destination();
1.630     raeburn  7501:           my $result =
1.482     raeburn  7502:               &Apache::loncommon::modify_html_refs('coursedoc',$destination,
                   7503:                                                    $docuname,$docudom,undef,
                   7504:                                                    $dir_root);
1.630     raeburn  7505:           $r->print($result.&return_to_editor());
1.476     raeburn  7506:       } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
                   7507:           $uploadphase = 'decompress_phase_one';
                   7508:           $r->print(&decompression_phase_one().
                   7509:                     &return_to_editor());
                   7510:       } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
                   7511:           $uploadphase = 'decompress_phase_two';
                   7512:           $r->print(&decompression_phase_two().
                   7513:                     &return_to_editor());
1.329     droeschl 7514:       }
                   7515:   }
                   7516: 
1.484     raeburn  7517:   if ($allowed && $toolsflag) {
                   7518:       $r->print(&startContentScreen('tools'));
1.708     raeburn  7519:       $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484     raeburn  7520:       $r->print(&endContentScreen());
                   7521:   } elsif ((!$showdoc) && (!$uploadphase)) {
1.329     droeschl 7522: # -----------------------------------------------------------------------------
                   7523:        my %lt=&Apache::lonlocal::texthash(
                   7524: 		'copm' => 'All documents out of a published map into this folder',
1.501     raeburn  7525:                 'upfi' => 'Upload File',
1.553     raeburn  7526:                 'upld' => 'Upload Content',
1.706     raeburn  7527:                 'srch' => 'Search Repository',
                   7528:                 'impo' => 'Import from Repository',
1.487     raeburn  7529: 		'lnks' => 'Import from Stored Links',
1.502     raeburn  7530:                 'impm' => 'Import from Assembled Map',
1.630     raeburn  7531:                 'imcr' => 'Import from Course Resources',
1.598     raeburn  7532:                 'extr' => 'External Resource',
                   7533:                 'extt' => 'External Tool',
1.329     droeschl 7534:                 'selm' => 'Select Map',
                   7535:                 'load' => 'Load Map',
                   7536:                 'newf' => 'New Folder',
                   7537:                 'newp' => 'New Composite Page',
                   7538:                 'syll' => 'Syllabus',
1.425     raeburn  7539:                 'navc' => 'Table of Contents',
1.343     biermanm 7540:                 'sipa' => 'Simple Course Page',
1.329     droeschl 7541:                 'sipr' => 'Simple Problem',
1.630     raeburn  7542:                 'webp' => 'Blank Web Page (editable)',
1.606     raeburn  7543:                 'stpr' => 'Standard Problem',
                   7544:                 'news' => 'New sub-directory',
                   7545:                 'crpr' => 'Create Problem',
1.689     raeburn  7546:                 'swit' => 'Switch Server',
1.329     droeschl 7547:                 'drbx' => 'Drop Box',
1.451     www      7548:                 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336     schafran 7549:                 'bull' => 'Discussion Board',
1.347     weissno  7550:                 'mypi' => 'My Personal Information Page',
1.353     weissno  7551:                 'grpo' => 'Group Portfolio',
1.329     droeschl 7552:                 'rost' => 'Course Roster',
1.528     raeburn  7553:                 'abou' => 'Personal Information Page for a User',
1.553     raeburn  7554:                 'imsf' => 'IMS Upload',
                   7555:                 'imsl' => 'Upload IMS package',
1.501     raeburn  7556:                 'cms'  => 'Origin of IMS package',
                   7557:                 'se'   => 'Select',
1.329     droeschl 7558:                 'file' =>  'File',
                   7559:                 'title' => 'Title',
1.606     raeburn  7560:                 'addp' => 'Add Placeholder to course?',
                   7561:                 'uste' => 'Use Template?',
                   7562:                 'fnam' => 'File Name:',
                   7563:                 'loca' => 'Location:',
                   7564:                 'dire' => 'Directory:',
                   7565:                 'cate' => 'Category:',
                   7566:                 'tmpl' => 'Template:',
1.698     raeburn  7567:                 'empd' => 'No resources found',
1.329     droeschl 7568:                 'comment' => 'Comment',
1.403     raeburn  7569:                 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577     bisitz   7570:                 'bb5'      => 'Blackboard 5',
                   7571:                 'bb6'      => 'Blackboard 6',
                   7572:                 'angel5'   => 'ANGEL 5.5',
                   7573:                 'webctce4' => 'WebCT 4 Campus Edition',
1.606     raeburn  7574:                 'yes'      => 'Yes',
                   7575:                 'no'       => 'No',
1.618     raeburn  7576:                 'er' => 'Editing rights unavailable for your current role.',
1.577     bisitz   7577:         );
1.329     droeschl 7578: # -----------------------------------------------------------------------------
1.595     musolffc 7579: 
                   7580:     # Calculate free quota space for a user or course. A javascript function checks
                   7581:     # file size to determine if upload should be allowed.
                   7582:     my $quotatype = 'unofficial';
                   7583:     if ($crstype eq 'Community') {
1.601     raeburn  7584:         $quotatype = 'community';
                   7585:     } elsif ($crstype eq 'Placement') {
                   7586:         $quotatype = 'placement';
1.595     musolffc 7587:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
                   7588:         $quotatype = 'official';
                   7589:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   7590:         $quotatype = 'textbook';
                   7591:     }
                   7592:     my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
                   7593:                      'course',$quotatype); # expressed in MB
                   7594:     my $current_disk_usage = 0;
                   7595:     foreach my $subdir ('docs','supplemental') {
                   7596:         $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
                   7597:                                "userfiles/$subdir",1); # expressed in kB
                   7598:     }
                   7599:     my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605     raeburn  7600:     my $usage = $current_disk_usage/1024; # in MB
                   7601:     my $quota = $disk_quota;
                   7602:     my $percent;
                   7603:     if ($disk_quota == 0) {
                   7604:         $percent = 100.0;
                   7605:     } else {
1.619     raeburn  7606:         $percent = 100*($usage/$disk_quota);
1.605     raeburn  7607:     }
                   7608:     $usage = sprintf("%.2f",$usage);
                   7609:     $quota = sprintf("%.2f",$quota);
                   7610:     $percent = sprintf("%.0f",$percent);
                   7611:     my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
                   7612:                               $percent.'%',$quota.' MB').'</p>';
1.595     musolffc 7613: 
1.329     droeschl 7614: 	my $checkbox=(<<CHBO);
                   7615: 	<!-- <label>$lt{'parse'}?
                   7616: 	<input type="checkbox" name="parserflag" />
                   7617: 	</label> -->
                   7618: 	<label>
1.611     raeburn  7619: 	<input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329     droeschl 7620: 	</label>
                   7621: CHBO
1.501     raeburn  7622:         my $imsfolder = $env{'form.folder'};
                   7623:         if ($imsfolder eq '') {
                   7624:             $imsfolder = 'default';  
                   7625:         }
                   7626:         my $imspform=(<<IMSFORM);
                   7627:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
                   7628:         $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
                   7629:         <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516     raeburn  7630:         <fieldset id="uploadimsform" style="display: none;">
1.501     raeburn  7631:         <legend>$lt{'imsf'}</legend>
1.723   ! raeburn  7632:         $quotainfo
        !          7633:         <label>$lt{'file'}:<br />
        !          7634:         <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled /></label>
1.702     raeburn  7635:         <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501     raeburn  7636:         <br />
                   7637:         <p>
                   7638:         $lt{'cms'}:&nbsp; 
1.611     raeburn  7639:         <select name="source" $disabled>
1.501     raeburn  7640:         <option value="-1" selected="selected">$lt{'se'}</option>
1.577     bisitz   7641:         <option value="bb5">$lt{'bb5'}</option>
                   7642:         <option value="bb6">$lt{'bb6'}</option>
                   7643:         <option value="angel5">$lt{'angel5'}</option>
                   7644:         <option value="webctce4">$lt{'webctce4'}</option>
1.501     raeburn  7645:         </select>
                   7646:         <input type="hidden" name="folder" value="$imsfolder" />
                   7647:         </p>
                   7648:         <input type="hidden" name="phase" value="one" />
1.611     raeburn  7649:         <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501     raeburn  7650:         </fieldset>
                   7651:         </form>
                   7652: IMSFORM
1.329     droeschl 7653: 
                   7654: 	my $fileuploadform=(<<FUFORM);
1.501     raeburn  7655:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
                   7656:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
                   7657:         <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516     raeburn  7658:         <fieldset id="uploaddocform" style="display: none;">
1.501     raeburn  7659:         <legend>$lt{'upfi'}</legend>
1.371     tempelho 7660: 	<input type="hidden" name="active" value="aa" />
1.723   ! raeburn  7661:         $quotainfo
        !          7662:         <label>$lt{'file'}:<br />
        !          7663:         <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled /></label>
1.702     raeburn  7664:         <input type="hidden" id="LC_free_space" value="$free_space" />
1.329     droeschl 7665: 	<br />
1.723   ! raeburn  7666:         <label>
1.329     droeschl 7667: 	$lt{'title'}:<br />
1.723   ! raeburn  7668: 	<input type="text" size="60" name="comment" $disabled /></label>
1.508     raeburn  7669: 	$pathitem
1.329     droeschl 7670: 	<input type="hidden" name="cmd" value="upload_default" />
                   7671: 	<br />
1.458     raeburn  7672: 	<span class="LC_nobreak" style="float:left">
1.329     droeschl 7673: 	$checkbox
                   7674: 	</span>
1.501     raeburn  7675:         <br clear="all" />
1.611     raeburn  7676:         <input type="submit" value="$lt{'upld'}" $disabled />
1.501     raeburn  7677:         </fieldset>
                   7678:         </form>
1.383     tempelho 7679: FUFORM
1.329     droeschl 7680: 
1.611     raeburn  7681:         my $mapimportjs;
                   7682:         if ($canedit) {
                   7683:             $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');"; 
                   7684:         } else {
                   7685:             $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
                   7686:         }
1.502     raeburn  7687: 	my $importpubform=(<<SEDFFORM);
1.514     raeburn  7688:         <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502     raeburn  7689:         $lt{'impm'}</a>$help{'Load_Map'}
                   7690: 	<form action="/adm/coursedocs" method="post" name="mapimportform">
1.516     raeburn  7691:         <fieldset id="importmapform" style="display: none;">
1.502     raeburn  7692:         <legend>$lt{'impm'}</legend>
1.371     tempelho 7693: 	<input type="hidden" name="active" value="bb" />
1.723   ! raeburn  7694:         <label>$lt{'copm'}<br />
1.502     raeburn  7695:         <span class="LC_nobreak">
                   7696:         <input type="text" name="importmap" size="40" value="" 
1.611     raeburn  7697:         onfocus="this.blur();$mapimportjs" $disabled />
1.723   ! raeburn  7698:         &nbsp;<a href="$mapimportjs">$lt{'selm'}</a></span></label><br />
1.611     raeburn  7699:         <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502     raeburn  7700:         </fieldset>
                   7701:         </form>
                   7702: 
1.383     tempelho 7703: SEDFFORM
1.706     raeburn  7704:         my ($importcrsresform,$checkcrsres);
                   7705:         if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
                   7706:             $checkcrsres = 1;
                   7707:         } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
                   7708:             my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
1.710     raeburn  7709:             my $type = lc($env{'course.'.$env{'request.course.id'}.'.type'});
                   7710:             unless (($type eq 'community') || ($type eq 'placement')) {
                   7711:                 $type = 'unofficial';
                   7712:                 if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'} ne '') {
                   7713:                     $type = 'official';
                   7714:                 } elsif ($env{'course.'.$env{'request.course.id'}.'internal.textbook'} ne '') {
                   7715:                     $type = 'textbook';
                   7716:                 } else {
                   7717:                     $type = 'unofficial';
                   7718:                 }
                   7719:             }
                   7720:             if ($domdefs{$type.'crsauthor'}) {
1.706     raeburn  7721:                 $checkcrsres = 1;
                   7722:             }
                   7723:         }
                   7724:         if ($checkcrsres) {
                   7725:             my ($numdirs,$pickfile) = 
                   7726:                 &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
                   7727:                                                           "resize_scrollbox('contentscroll','1','0');",
                   7728:                                                           undef,'res');
                   7729:             if ($pickfile) {
                   7730:                 $importcrsresform=(<<CRSFORM);
1.690     raeburn  7731:         <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606     raeburn  7732:         $lt{'imcr'}</a>$help{'Course_Resources'}
                   7733:         <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
                   7734:         <fieldset id="importcrsresform" style="display: none;">
                   7735:         <legend>$lt{'imcr'}</legend>
1.698     raeburn  7736:         <div id="importcrsrescontent" style="display: none;">
1.606     raeburn  7737:         <input type="hidden" name="active" value="bb" />
                   7738:         $pickfile
1.723   ! raeburn  7739:         <p><label>
1.699     raeburn  7740:         $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.723   ! raeburn  7741:         </label></p>
1.606     raeburn  7742:         <input type="hidden" name="importdetail" value="" />
1.690     raeburn  7743:         <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698     raeburn  7744:         </div>
                   7745:         <div id="importcrsresempty" style="display: none;">
                   7746:         <p>
                   7747:         $lt{'empd'}
                   7748:         </p>
                   7749:         </div>
1.606     raeburn  7750:         </fieldset>
                   7751:         </form>
                   7752: CRSFORM
1.706     raeburn  7753:             }
1.606     raeburn  7754:         }
                   7755: 
1.611     raeburn  7756:         my $fromstoredjs;
                   7757:         if ($canedit) {
                   7758:             $fromstoredjs = 'open_StoredLinks_Import()'; 
                   7759:         } else {
                   7760:             $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
                   7761:         }
                   7762: 
1.502     raeburn  7763: 	my @importpubforma = (
1.706     raeburn  7764: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'"  onclick="javascript:groupsearch()" />' => $pathitem."<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>$help{'Search_LON-CAPA_Resource'}" },
1.423     onken    7765: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'"  onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
1.706     raeburn  7766: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:'.$fromstoredjs.';" />' => '<a class="LC_menubuttons_link" href="javascript:'.$fromstoredjs.';">'.$lt{'lnks'}.'</a>'.$help{'Import_Stored_Links'} },
1.606     raeburn  7767:         { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
                   7768:         );
1.706     raeburn  7769:         if ($importcrsresform) {
                   7770:             push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/impcrsau.png" alt="'.$lt{imcr}.'"  onclick="javascript:toggleImportCrsres(\'res\');" />' => $importcrsresform});
1.606     raeburn  7771: 	}
1.502     raeburn  7772: 	$importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510     raeburn  7773:         my $extresourcesform =
                   7774:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611     raeburn  7775:                                                  $help{'Adding_External_Resource'},
                   7776:                                                  undef,undef,undef,undef,undef,undef,$disabled);
1.598     raeburn  7777:         my $exttoolform =
                   7778:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
                   7779:                                                  $help{'Adding_External_Tool'},undef,
                   7780:                                                  undef,'tool',$coursedom,$coursenum,
1.611     raeburn  7781:                                                  \%ltitools,$disabled);
1.329     droeschl 7782:     if ($allowed) {
1.492     raeburn  7783:         my $folder = $env{'form.folder'};
                   7784:         if ($folder eq '') {
                   7785:             $folder='default';
                   7786:         }
1.615     raeburn  7787:         if ($canedit) {
                   7788: 	    my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
                   7789:             if ($output) {
                   7790:                 $r->print($output);
                   7791:             }
1.538     raeburn  7792:         }
1.337     ehlerst  7793: 	$r->print(<<HIDDENFORM);
                   7794: 	<form name="renameform" method="post" action="/adm/coursedocs">
                   7795:    <input type="hidden" name="title" />
                   7796:    <input type="hidden" name="cmd" />
                   7797:    <input type="hidden" name="markcopy" />
                   7798:    <input type="hidden" name="copyfolder" />
                   7799:    $containertag
                   7800:  </form>
1.633     raeburn  7801:  <form name="aliasform" method="post" action="/adm/coursedocs">
                   7802:    <input type="hidden" name="alias" />
                   7803:    <input type="hidden" name="cmd" />
                   7804:    $containertag
                   7805:  </form>
1.484     raeburn  7806: 
1.337     ehlerst  7807: HIDDENFORM
1.508     raeburn  7808:         $r->print(&makesimpleeditform($pathitem)."\n".
                   7809:                   &makedocslogform($pathitem."\n".
1.484     raeburn  7810:                                    '<input type="hidden" name="folder" value="'.
                   7811:                                    $env{'form.folder'}.'" />'."\n"));
1.329     droeschl 7812:     }
1.442     www      7813: 
                   7814: # Generate the tabs
1.510     raeburn  7815:     my ($mode,$needs_end);
1.472     raeburn  7816:     if (($supplementalflag) && (!$allowed)) {
1.510     raeburn  7817:         my @folders = split('&',$env{'form.folderpath'});
                   7818:         unless (@folders > 2) {
                   7819:             &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
                   7820:             $needs_end = 1;
                   7821:         }
1.472     raeburn  7822:     } else {
1.484     raeburn  7823:         $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510     raeburn  7824:         $needs_end = 1;
1.472     raeburn  7825:     }
1.443     www      7826: 
1.442     www      7827: #
1.622     raeburn  7828:     my $hostname = $r->hostname();
1.442     www      7829:     my $savefolderpath;
                   7830: 
1.395     raeburn  7831:     if ($allowed) {
1.329     droeschl 7832:        my $folder=$env{'form.folder'};
1.615     raeburn  7833:        if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329     droeschl 7834:            $folder='default';
1.356     tempelho 7835: 	   $savefolderpath = $env{'form.folderpath'};
1.548     raeburn  7836: 	   $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508     raeburn  7837:            $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329     droeschl 7838: 	       &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
                   7839:        }
                   7840:        my $postexec='';
                   7841:        if ($folder eq 'default') {
1.653     raeburn  7842:            my $windowname = 'loncapaclient';
                   7843:            if ($env{'request.lti.login'}) {
                   7844:                $windowname .= 'lti';
                   7845:            }
1.372     bisitz   7846:            $r->print('<script type="text/javascript">'."\n"
                   7847:                     .'// <![CDATA['."\n"
1.653     raeburn  7848:                     .'this.window.name="'.$windowname.'";'."\n"
1.372     bisitz   7849:                     .'// ]]>'."\n"
                   7850:                     .'</script>'."\n"
1.369     bisitz   7851:        );
1.329     droeschl 7852:        } else {
                   7853:            #$postexec='self.close();';
                   7854:        }
1.504     raeburn  7855:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
                   7856:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329     droeschl 7857: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
                   7858: 
                   7859: 	my $newnavform=(<<NNFORM);
                   7860: 	<form action="/adm/coursedocs" method="post" name="newnav">
1.655     raeburn  7861: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  7862: 	$pathitem
1.329     droeschl 7863: 	<input type="hidden" name="importdetail" 
                   7864: 	value="$lt{'navc'}=/adm/navmaps" />
1.611     raeburn  7865: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329     droeschl 7866: 	$help{'Navigate_Content'}
                   7867: 	</form>
                   7868: NNFORM
                   7869: 	my $newsmppageform=(<<NSPFORM);
                   7870: 	<form action="/adm/coursedocs" method="post" name="newsmppg">
1.655     raeburn  7871: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  7872: 	$pathitem
1.329     droeschl 7873: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7874: 	<a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383     tempelho 7875: 	$help{'Simple Page'}
1.329     droeschl 7876: 	</form>
                   7877: NSPFORM
                   7878: 
                   7879: 	my $newsmpproblemform=(<<NSPROBFORM);
                   7880: 	<form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655     raeburn  7881: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  7882: 	$pathitem
1.329     droeschl 7883: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7884: 	<a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572     raeburn  7885: 	$help{'Simple_Problem'}
1.329     droeschl 7886: 	</form>
                   7887: 
                   7888: NSPROBFORM
                   7889: 
                   7890: 	my $newdropboxform=(<<NDBFORM);
                   7891: 	<form action="/adm/coursedocs" method="post" name="newdropbox">
1.655     raeburn  7892: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  7893: 	$pathitem
1.329     droeschl 7894: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7895: 	<a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554     raeburn  7896:         $help{'Dropbox'}
1.344     bisitz   7897: 	</form>
1.329     droeschl 7898: NDBFORM
                   7899: 
                   7900: 	my $newexuploadform=(<<NEXUFORM);
                   7901: 	<form action="/adm/coursedocs" method="post" name="newexamupload">
1.655     raeburn  7902: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  7903: 	$pathitem
1.329     droeschl 7904: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7905: 	<a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329     droeschl 7906: 	$help{'Score_Upload_Form'}
                   7907: 	</form>
                   7908: NEXUFORM
                   7909: 
                   7910: 	my $newbulform=(<<NBFORM);
                   7911: 	<form action="/adm/coursedocs" method="post" name="newbul">
1.655     raeburn  7912: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  7913: 	$pathitem
1.329     droeschl 7914: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7915: 	<a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329     droeschl 7916: 	$help{'Bulletin Board'}
                   7917: 	</form>
                   7918: NBFORM
                   7919: 
                   7920: 	my $newaboutmeform=(<<NAMFORM);
                   7921: 	<form action="/adm/coursedocs" method="post" name="newaboutme">
1.655     raeburn  7922: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  7923: 	$pathitem
1.329     droeschl 7924: 	<input type="hidden" name="importdetail" 
                   7925: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  7926: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347     weissno  7927: 	$help{'My Personal Information Page'}
1.329     droeschl 7928: 	</form>
                   7929: NAMFORM
                   7930: 
                   7931: 	my $newaboutsomeoneform=(<<NASOFORM);
                   7932: 	<form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655     raeburn  7933: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  7934: 	$pathitem
1.329     droeschl 7935: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7936: 	<a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329     droeschl 7937: 	</form>
                   7938: NASOFORM
                   7939: 
                   7940: 	my $newrosterform=(<<NROSTFORM);
                   7941: 	<form action="/adm/coursedocs" method="post" name="newroster">
1.655     raeburn  7942: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  7943: 	$pathitem
1.329     droeschl 7944: 	<input type="hidden" name="importdetail" 
                   7945: 	value="$lt{'rost'}=/adm/viewclasslist" />
1.611     raeburn  7946: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556     raeburn  7947: 	$help{'Course_Roster'}
1.329     droeschl 7948: 	</form>
                   7949: NROSTFORM
                   7950: 
1.534     raeburn  7951:         my $newwebpage;
                   7952:         if ($folder =~ /^default_?(\d*)$/) {
                   7953:             $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
                   7954:             if ($1) {
                   7955:                 $newwebpage .= $1;
                   7956:             } else {
                   7957:                 $newwebpage .= 'default';
                   7958:             }
                   7959:             $newwebpage .= '/new.html';
                   7960:         }
                   7961:         my $newwebpageform =(<<NWEBFORM);
                   7962:         <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655     raeburn  7963:         <input type="hidden" name="active" value="ff" />
1.534     raeburn  7964:         $pathitem
                   7965:         <input type="hidden" name="importdetail" value="$newwebpage" />
                   7966:         <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556     raeburn  7967:         $help{'Web_Page'}
1.534     raeburn  7968:         </form>
                   7969: NWEBFORM
1.701     raeburn  7970:         my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606     raeburn  7971:         my @ids=&Apache::lonnet::current_machine_ids();
1.691     raeburn  7972:         my $machines_str = "'".join("','",@ids)."'";
                   7973:         my (%is_home,%toppath,$rolehomes);
1.606     raeburn  7974:         if ($env{'user.author'}) {
                   7975:             if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691     raeburn  7976:                 $is_home{'author'} = 1;
1.606     raeburn  7977:             }
1.691     raeburn  7978:             $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606     raeburn  7979:         }
                   7980:         my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
                   7981:                                                       ['active'],['ca','aa']);
1.691     raeburn  7982:         my %by_roletype;
1.606     raeburn  7983:         if (keys(%roleshash)) {
                   7984:             foreach my $entry (keys(%roleshash)) {
                   7985:                 my ($auname,$audom,$roletype) = split(/:/,$entry);
                   7986:                 my $key = $entry;
                   7987:                 $key =~ s/:/___/g;
1.691     raeburn  7988:                 my $author = $auname.'___'.$audom;
                   7989:                 $by_roletype{$roletype}{$author} = 1;
1.606     raeburn  7990:                 my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691     raeburn  7991:                 $toppath{$author} = "/priv/$audom/$auname";
                   7992:                 if (grep(/^\Q$rolehome\E$/,@ids)) {
                   7993:                     $is_home{$author} = 1;
1.606     raeburn  7994:                 }
1.691     raeburn  7995:                 $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
                   7996:                               'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606     raeburn  7997:             }
1.691     raeburn  7998:         }
                   7999:         my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   8000:         if (grep(/^\Q$crshome\E$/,@ids)) {
                   8001:             $is_home{'course'} = 1;
                   8002:         }
                   8003:         $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
1.723   ! raeburn  8004:         my $pickdir = '<label>'.$lt{'loca'}.
1.691     raeburn  8005:                    '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
                   8006:                    '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
                   8007:         if ($env{'user.author'}) {
                   8008:             $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
                   8009:         }
                   8010:         if (keys(%by_roletype)) {
                   8011:             foreach my $possrole ('ca','aa') {
                   8012:                 if (ref($by_roletype{$possrole}) eq 'HASH') {
                   8013:                     my $roletitle = &Apache::lonnet::plaintext($possrole);
                   8014:                     foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
                   8015:                         my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
                   8016:                         $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
                   8017:                                      $roletitle." ($audom/$auname)</option>\n";
1.606     raeburn  8018:                     }
                   8019:                 }
                   8020:             }
                   8021:         }
1.706     raeburn  8022:         if ($checkcrsres) {
                   8023:             $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
                   8024:         }
1.723   ! raeburn  8025:         $pickdir .= '</select></label><br />'."\n".
        !          8026:                     '<label>'.$lt{'dire'}.
1.691     raeburn  8027:                     '<select name="authorpath" onchange="toggleCrsResTitle();">'.
                   8028:                     '<option value=""></option>'.
1.723   ! raeburn  8029:                     '</select></label><br />'."\n";
1.606     raeburn  8030:         my %seltemplate_menus;
                   8031:         my @files = &Apache::lonhomework::get_template_list('problem');
                   8032:         my @noexamplelink = ('blank.problem','blank.library','script.library');
                   8033:         my $currentcategory = '';
                   8034:         my @ordered = ('');
                   8035:         my %templatehelp;
                   8036:         my $defcategory = '';
                   8037:         my @catorder = ($defcategory);
                   8038:         $seltemplate_menus{$defcategory}->{'order'} = [''];
                   8039:         $seltemplate_menus{$defcategory}->{'text'} = '';
                   8040:         foreach my $file (@files) {
                   8041:             if (ref($file) eq 'ARRAY') {
                   8042:                 my ($path,$title,$category,$help) = @{$file};
                   8043:                 next if ($title !~ /\S/);
                   8044:                 if (&js_escape($category) ne $currentcategory) {
                   8045:                     $currentcategory = &js_escape($category);
                   8046:                     push(@catorder,&js_escape($currentcategory));
                   8047:                     $seltemplate_menus{$currentcategory}->{'text'} = $category;
                   8048:                     $seltemplate_menus{$currentcategory}->{'default'} = '';
                   8049:                     $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
                   8050:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
                   8051:                 }
                   8052:                 if ($path) {
                   8053:                     $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
                   8054:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
                   8055:                     if ($help) {
                   8056:                         $templatehelp{$path} = $help;
                   8057:                     }
                   8058:                 }
                   8059:             }
                   8060:         }
                   8061: 
1.723   ! raeburn  8062:         my ($templates,$haslabel);
        !          8063:         if ($lt{'cate'} ne '') {
        !          8064:             $templates = '<label>';
        !          8065:             $haslabel = 1;
        !          8066:         }
        !          8067:         $templates .= $lt{'cate'}.' '.
        !          8068:                       &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
        !          8069:                                                               $defcategory,'tempcategory','template',
        !          8070:                                                               \%seltemplate_menus,\@catorder,
        !          8071:                                                               "resize_scrollbox('contentscroll','1','0');",
        !          8072:                                                               "toggleExampleText();",'template',$haslabel).'<br />';
1.606     raeburn  8073:         my $templatepreview =  '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true);  return false;">'.
1.701     raeburn  8074:                                '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706     raeburn  8075:         my $crsresform;
                   8076:         if (($env{'user.author'}) || ($checkcrsres)) {
                   8077:             $crsresform=(<<RESFORM);
1.691     raeburn  8078:         <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706     raeburn  8079:         $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606     raeburn  8080:         <form action="/adm/coursedocs" method="post" name="courseresform">
                   8081:         <fieldset id="crsresform" style="display:none;">
                   8082:         <legend>$lt{'stpr'}</legend>
1.655     raeburn  8083:         <input type="hidden" name="active" value="bb" />
1.606     raeburn  8084:         <p>
                   8085:         $pickdir
1.701     raeburn  8086:         </p>
1.691     raeburn  8087:         <div id="newstdproblem" style="display:none;">
1.701     raeburn  8088:         <p>
1.606     raeburn  8089:         <span class="LC_nobreak">$lt{'news'}?&nbsp;
1.611     raeburn  8090:         <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606     raeburn  8091:         &nbsp;
1.611     raeburn  8092:         <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.723   ! raeburn  8093:         </span><label for="newsubdirname"><span id="newsubdir"></span></label>
1.606     raeburn  8094:         <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701     raeburn  8095:         </p>
1.699     raeburn  8096:         </div>
1.723   ! raeburn  8097:         <label>$lt{'fnam'}
        !          8098:         <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled /></label>
1.701     raeburn  8099:         <div id="newresource" style="display:none">
1.606     raeburn  8100:         <p>
                   8101:         $lt{'addp'}
1.611     raeburn  8102:         <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  8103:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  8104:         <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  8105:         $lt{'yes'}</label>
1.723   ! raeburn  8106:         <label for="newresourcetitle"><span id="newrestitle"></span></label>
1.611     raeburn  8107:         <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701     raeburn  8108:         </p>
1.606     raeburn  8109:         </div>
                   8110:         <p>
                   8111:         $lt{'uste'}
1.611     raeburn  8112:         <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  8113:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  8114:         <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  8115:         $lt{'yes'}</label>
1.701     raeburn  8116:         </p>
1.606     raeburn  8117:         <div id="newrestemplate" style="display:none">
                   8118:         $templates
                   8119:         $templatepreview
                   8120:         </div>
                   8121:         <span class="LC_nobreak">
1.701     raeburn  8122:         <input type="hidden" name="folderpath" value="$showpath" />
1.611     raeburn  8123:         <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606     raeburn  8124:         </span>
1.691     raeburn  8125:         <div id="stdprobswitch" style="display:none;">
1.689     raeburn  8126:         $rolehomes
                   8127:         <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
                   8128:         </div>
1.606     raeburn  8129:         </fieldset>
                   8130:         </form>
                   8131: 
                   8132: RESFORM
1.706     raeburn  8133:         }
1.534     raeburn  8134: 
1.342     ehlerst  8135: my $specialdocumentsform;
1.383     tempelho 8136: my @specialdocumentsforma;
1.451     www      8137: my $gradingform;
                   8138: my @gradingforma;
                   8139: my $communityform;
                   8140: my @communityforma;
1.351     ehlerst  8141: my $newfolderform;
1.390     tempelho 8142: my $newfolderb;
1.342     ehlerst  8143: 
1.451     www      8144: 	my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383     tempelho 8145: 	
1.329     droeschl 8146: 	my $newpageform=(<<NPFORM);
                   8147: 	<form action="/adm/coursedocs" method="post" name="newpage">
                   8148: 	<input type="hidden" name="folderpath" value="$path" />
                   8149: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  8150: 	<input type="hidden" name="active" value="ee" />
1.423     onken    8151: 	<a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383     tempelho 8152: 	$help{'Adding_Pages'}
1.329     droeschl 8153: 	</form>
                   8154: NPFORM
1.390     tempelho 8155: 
                   8156: 
1.351     ehlerst  8157: 	$newfolderform=(<<NFFORM);
1.329     droeschl 8158: 	<form action="/adm/coursedocs" method="post" name="newfolder">
1.508     raeburn  8159: 	$pathitem
1.329     droeschl 8160: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  8161: 	<input type="hidden" name="active" value="" />
1.422     onken    8162: 	<a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329     droeschl 8163: 	</form>
                   8164: NFFORM
                   8165: 
                   8166: 	my $newsylform=(<<NSYLFORM);
                   8167: 	<form action="/adm/coursedocs" method="post" name="newsyl">
1.570     raeburn  8168: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  8169: 	$pathitem
1.329     droeschl 8170: 	<input type="hidden" name="importdetail" 
                   8171: 	value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  8172: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329     droeschl 8173: 	$help{'Syllabus'}
1.383     tempelho 8174: 
1.329     droeschl 8175: 	</form>
                   8176: NSYLFORM
1.364     bisitz   8177: 
1.329     droeschl 8178: 	my $newgroupfileform=(<<NGFFORM);
                   8179: 	<form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655     raeburn  8180: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  8181: 	$pathitem
1.329     droeschl 8182: 	<input type="hidden" name="importdetail"
                   8183: 	value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611     raeburn  8184: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353     weissno  8185: 	$help{'Group Portfolio'}
1.329     droeschl 8186: 	</form>
                   8187: NGFFORM
1.672     raeburn  8188:         if ($container eq 'page') {
                   8189:             @specialdocumentsforma=(
                   8190:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
                   8191:             );
                   8192:         } else {
                   8193: 	    @specialdocumentsforma=(
1.421     onken    8194: 	{'<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  8195: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611     raeburn  8196: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451     www      8197:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534     raeburn  8198:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672     raeburn  8199:             );
                   8200:         }
1.451     www      8201:         $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
                   8202: 
1.655     raeburn  8203:         my @external = (
                   8204:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519     raeburn  8205:         );
1.699     raeburn  8206:         if ($posslti) {
1.655     raeburn  8207:             push(@external,
                   8208:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
                   8209:             );
1.598     raeburn  8210:         }
1.655     raeburn  8211:         my $externalform = &create_form_ul(&create_list_elements(@external));
                   8212: 
                   8213:         my @importdoc = ();
1.519     raeburn  8214:         unless ($container eq 'page') {
                   8215:             push(@importdoc,
                   8216:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
                   8217:             );
                   8218:         }
                   8219:         push(@importdoc,
1.558     raeburn  8220:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519     raeburn  8221:         );
1.501     raeburn  8222:         $fileuploadform =  &create_form_ul(&create_list_elements(@importdoc));
1.434     raeburn  8223: 
1.451     www      8224:         @gradingforma=(
                   8225:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
                   8226:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706     raeburn  8227:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451     www      8228:         );
1.706     raeburn  8229:         if ($crsresform) {
                   8230:             push(@gradingforma,
                   8231:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
                   8232:             );
                   8233:         }
1.451     www      8234:         $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
                   8235: 
                   8236:         @communityforma=(
                   8237:        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
                   8238:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
                   8239:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611     raeburn  8240:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
                   8241:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451     www      8242:         );
                   8243:         $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383     tempelho 8244: 
1.330     tempelho 8245: my %orderhash = (
1.553     raeburn  8246:                 'aa' => ['Upload',$fileuploadform],
1.707     raeburn  8247:                 'bb' => ['External',$externalform],
                   8248:                 'cc' => ['Import',$importpubform],
1.701     raeburn  8249:                 'dd' => ['Assessment',$gradingform],
1.673     raeburn  8250:                 'ff' => ['Other',$specialdocumentsform],
1.330     tempelho 8251:                 );
1.519     raeburn  8252: unless ($container eq 'page') {
1.434     raeburn  8253:     $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655     raeburn  8254:     $orderhash{'ee'} = ['Collaboration',$communityform];
1.434     raeburn  8255: }
                   8256: 
1.341     ehlerst  8257:  $hadchanges=0;
1.484     raeburn  8258:        unless (($supplementalflag || $toolsflag)) {
1.458     raeburn  8259:           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615     raeburn  8260:                               $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622     raeburn  8261:                               \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617     raeburn  8262:           undef($navmap);
1.443     www      8263:           if ($error) {
                   8264:              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   8265:           }
1.639     raeburn  8266:           if ($hadchanges) {
                   8267:               unless (&is_hash_old()) {
1.638     raeburn  8268:                   &mark_hash_old();
                   8269:               }
                   8270: 	  }
1.341     ehlerst  8271: 
1.443     www      8272:           &changewarning($r,'');
                   8273:         }
1.458     raeburn  8274:     }
1.442     www      8275: 
1.443     www      8276: # Supplemental documents start here
                   8277: 
1.329     droeschl 8278:        my $folder=$env{'form.folder'};
1.443     www      8279:        unless ($supplementalflag) {
1.329     droeschl 8280: 	   $folder='supplemental';
                   8281:        }
1.685     raeburn  8282:        if (($folder eq 'supplemental') &&
1.329     droeschl 8283: 	   (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446     www      8284:           $env{'form.folderpath'} = &supplemental_base();
1.393     raeburn  8285:        } elsif ($allowed) {
1.356     tempelho 8286: 	  $env{'form.folderpath'} = $savefolderpath;
1.329     droeschl 8287:        }
1.508     raeburn  8288:        $pathitem = '<input type="hidden" name="folderpath" value="'.
                   8289:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329     droeschl 8290:        if ($allowed) {
                   8291: 	   my $folderseq=
1.504     raeburn  8292: 	       '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329     droeschl 8293: 
                   8294: 	my $supupdocform=(<<SUPDOCFORM);
1.501     raeburn  8295:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
                   8296:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383     tempelho 8297: 	<form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516     raeburn  8298:         <fieldset id="uploadsuppdocform" style="display: none;">
1.501     raeburn  8299:         <legend>$lt{'upfi'}</legend>
1.630     raeburn  8300: 	<input type="hidden" name="active" value="ee" />
1.723   ! raeburn  8301: 	$quotainfo
        !          8302:         <label>$lt{'file'}:<br />
        !          8303:         <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled /></label>
1.702     raeburn  8304:         <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329     droeschl 8305: 	<br />
                   8306: 	<br />
                   8307: 	<span class="LC_nobreak">
                   8308: 	$checkbox
                   8309: 	</span>
                   8310: 	<br /><br />
1.723   ! raeburn  8311: 	<label>$lt{'comment'}:<br />
        !          8312: 	<textarea cols="50" rows="4" name="comment"></textarea></label>
1.329     droeschl 8313: 	<br />
1.508     raeburn  8314: 	$pathitem
1.329     droeschl 8315: 	<input type="hidden" name="cmd" value="upload_supplemental" />
1.501     raeburn  8316:         <input type='submit' value="$lt{'upld'}" />
1.700     raeburn  8317:         </fieldset>
1.501     raeburn  8318:         </form>
1.329     droeschl 8319: SUPDOCFORM
                   8320: 
                   8321: 	my $supnewfolderform=(<<SNFFORM);
                   8322: 	<form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570     raeburn  8323: 	<input type="hidden" name="active" value="" />
1.508     raeburn  8324:         $pathitem
1.329     droeschl 8325: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    8326: 	<a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a> 
1.383     tempelho 8327: 	$help{'Adding_Folders'}
1.329     droeschl 8328: 	</form>
                   8329: SNFFORM
1.383     tempelho 8330: 	
1.510     raeburn  8331:         my $supextform =
                   8332:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611     raeburn  8333:                                                  $help{'Adding_External_Resource'},
                   8334:                                                  undef,undef,undef,undef,undef,undef,
                   8335:                                                  $disabled);
1.329     droeschl 8336: 
1.598     raeburn  8337:         my $supexttoolform =
                   8338:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
                   8339:                                                  $help{'Adding_External_Tool'},
                   8340:                                                  undef,undef,'tool',$coursedom,
1.611     raeburn  8341:                                                  $coursenum,\%ltitools,$disabled);
1.598     raeburn  8342: 
1.329     droeschl 8343: 	my $supnewsylform=(<<SNSFORM);
                   8344: 	<form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371     tempelho 8345: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  8346:         $pathitem
1.329     droeschl 8347: 	<input type="hidden" name="importdetail" 
                   8348: 	value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  8349: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329     droeschl 8350: 	$help{'Syllabus'}
                   8351: 	</form>
                   8352: SNSFORM
                   8353: 
                   8354: 	my $supnewaboutmeform=(<<SNAMFORM);
1.383     tempelho 8355: 	<form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371     tempelho 8356: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  8357:         $pathitem
1.329     droeschl 8358: 	<input type="hidden" name="importdetail" 
                   8359: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  8360: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347     weissno  8361: 	$help{'My Personal Information Page'}
1.329     droeschl 8362: 	</form>
                   8363: SNAMFORM
                   8364: 
1.534     raeburn  8365:         my $supwebpage;
                   8366:         if ($folder =~ /^supplemental_?(\d*)$/) {
                   8367:             $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
                   8368:             if ($1) {
                   8369:                 $supwebpage .= $1;
                   8370:             } else {
                   8371:                 $supwebpage .= 'default';
                   8372:             }
                   8373:             $supwebpage .= '/new.html';
                   8374:         }
                   8375:         my $supwebpageform =(<<SWEBFORM);
                   8376:         <form action="/adm/coursedocs" method="post" name="supwebpage">
                   8377:         <input type="hidden" name="active" value="cc" />
                   8378:         $pathitem
                   8379:         <input type="hidden" name="importdetail" value="$supwebpage" />
                   8380:         <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556     raeburn  8381:         $help{'Web_Page'}
1.534     raeburn  8382:         </form>
                   8383: SWEBFORM
                   8384: 
1.333     muellerd 8385: 
1.383     tempelho 8386: my @specialdocs = (
1.618     raeburn  8387: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417     droeschl 8388:             =>$supnewsylform},
1.611     raeburn  8389: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417     droeschl 8390:             =>$supnewaboutmeform},
1.534     raeburn  8391:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
                   8392: 
1.383     tempelho 8393: 		);
1.655     raeburn  8394:         my @supexternal = (
                   8395:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
                   8396:              =>$supextform});
1.699     raeburn  8397:         if ($posslti) {
1.655     raeburn  8398:             push(@supexternal,
                   8399:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598     raeburn  8400:             =>$supexttoolform});
                   8401:         }
1.655     raeburn  8402:         my @supimportdoc = (
1.598     raeburn  8403:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501     raeburn  8404:             =>$supupdocform},
1.598     raeburn  8405:         );
1.501     raeburn  8406: 
                   8407: $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc));
1.333     muellerd 8408: my %suporderhash = (
1.390     tempelho 8409: 		'00' => ['Supnewfolder', $supnewfolderform],
1.655     raeburn  8410:                 'dd' => ['Upload',$supupdocform],
                   8411:                 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553     raeburn  8412:                 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333     muellerd 8413:                 );
1.443     www      8414:         if ($supplementalflag) {
1.682     raeburn  8415:             $suppchanges = 0;
                   8416:             my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
                   8417:                                 $supplementalflag,\%suporderhash,$iconpath,$pathitem,
                   8418:                                 \%ltitools,$canedit,$hostname);
                   8419:             if ($error) {
                   8420:                 $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   8421:             }
                   8422:             if ($suppchanges) {
1.684     raeburn  8423:                 &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682     raeburn  8424:                 undef($suppchanges);
                   8425:             }
1.393     raeburn  8426:         }
1.443     www      8427:     } elsif ($supplementalflag) {
1.458     raeburn  8428:         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682     raeburn  8429:                             $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
                   8430:                             $hostname);
1.393     raeburn  8431:         if ($error) {
                   8432:             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383     tempelho 8433:         }
1.393     raeburn  8434:     }
1.389     tempelho 8435: 
1.510     raeburn  8436:     if ($needs_end) {
                   8437:         $r->print(&endContentScreen());
                   8438:     }
1.383     tempelho 8439: 
1.329     droeschl 8440:     if ($allowed) {
                   8441: 	$r->print('
                   8442: <form method="post" name="extimport" action="/adm/coursedocs">
                   8443:   <input type="hidden" name="title" />
                   8444:   <input type="hidden" name="url" />
                   8445:   <input type="hidden" name="useform" />
                   8446:   <input type="hidden" name="residx" />
                   8447: </form>');
                   8448:     }
1.484     raeburn  8449:   } elsif ($showdoc) {
1.329     droeschl 8450: # -------------------------------------------------------- This is showdoc mode
1.484     raeburn  8451:       $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498     bisitz   8452: 		&Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329     droeschl 8453: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484     raeburn  8454:                 &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329     droeschl 8455:   }
                   8456:  }
1.630     raeburn  8457:  unless ($noendpage) {
1.606     raeburn  8458:      $r->print(&Apache::loncommon::end_page());
                   8459:  }
1.329     droeschl 8460:  return OK;
1.364     bisitz   8461: }
1.329     droeschl 8462: 
1.440     raeburn  8463: sub embedded_form_elems {
                   8464:     my ($phase,$primaryurl,$newidx) = @_;
                   8465:     my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634     raeburn  8466:     $newidx =~s /\D+//g;
1.440     raeburn  8467:     return <<STATE;
                   8468:     <input type="hidden" name="folderpath" value="$folderpath" />
                   8469:     <input type="hidden" name="cmd" value="upload_embedded" />
                   8470:     <input type="hidden" name="newidx" value="$newidx" />
                   8471:     <input type="hidden" name="phase" value="$phase" />
                   8472:     <input type="hidden" name="primaryurl" value="$primaryurl" />
                   8473: STATE
                   8474: }
                   8475: 
                   8476: sub embedded_destination {
                   8477:     my $folder=$env{'form.folder'};
                   8478:     my $destination = 'docs/';
                   8479:     if ($folder =~ /^supplemental/) {
                   8480:         $destination = 'supplemental/';
                   8481:     }
                   8482:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   8483:         $destination .= 'default/';
                   8484:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   8485:         $destination .=  $2.'/';
                   8486:     }
1.634     raeburn  8487:     my $newidx = $env{'form.newidx'};
                   8488:     $newidx =~s /\D+//g;
                   8489:     if ($newidx) {
                   8490:         $destination .= $newidx;
                   8491:     }
1.440     raeburn  8492:     my $dir_root = '/userfiles';
                   8493:     return ($destination,$dir_root);
                   8494: }
                   8495: 
                   8496: sub return_to_editor {
                   8497:     my $actionurl = '/adm/coursedocs';
                   8498:     return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n". 
                   8499:            '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
                   8500:            '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
                   8501:            '</a></p>';
                   8502: }
                   8503: 
1.476     raeburn  8504: sub decompression_info {
                   8505:     my ($destination,$dir_root) = &embedded_destination();
                   8506:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                   8507:     my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   8508:     my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   8509:     my $container='sequence';
1.480     raeburn  8510:     my ($pathitem,$hiddenelem);
1.583     raeburn  8511:     my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519     raeburn  8512:     if ($env{'form.folderpath'} =~ /\:1$/) {
1.476     raeburn  8513:         $container='page';
                   8514:     }
1.480     raeburn  8515:     unshift(@hiddens,$pathitem);
                   8516:     foreach my $item (@hiddens) {
1.634     raeburn  8517:         if ($item eq 'newidx') {
                   8518:             next if ($env{'form.'.$item} =~ /\D/);
                   8519:         }
1.480     raeburn  8520:         if ($env{'form.'.$item}) {
                   8521:             $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583     raeburn  8522:                            &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480     raeburn  8523:         }
1.477     raeburn  8524:     }
1.476     raeburn  8525:     return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
                   8526:             $hiddenelem);
                   8527: }
                   8528: 
                   8529: sub decompression_phase_one {
                   8530:     my ($dir,$file,$warning,$error,$output);
                   8531:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   8532:         &decompression_info();
1.490     raeburn  8533:     if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476     raeburn  8534:         $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
                   8535:     } else {
                   8536:         my $file = $1;
1.630     raeburn  8537:         $output =
1.481     raeburn  8538:             &Apache::loncommon::process_decompression($docudom,$docuname,$file,
                   8539:                                                       $destination,$dir_root,
                   8540:                                                       $hiddenelem);
                   8541:         if ($env{'form.autoextract_camtasia'}) {
                   8542:             $output .= &remove_archive($docudom,$docuname,$container);
                   8543:         }
1.476     raeburn  8544:     }
                   8545:     if ($error) {
                   8546:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   8547:                    $error.'</p>'."\n";
                   8548:     }
                   8549:     if ($warning) {
                   8550:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   8551:     }
                   8552:     return $output;
                   8553: }
                   8554: 
                   8555: sub decompression_phase_two {
                   8556:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   8557:         &decompression_info();
1.481     raeburn  8558:     my $output;
1.480     raeburn  8559:     if ($env{'form.archivedelete'}) {
1.481     raeburn  8560:         $output = &remove_archive($docudom,$docuname,$container);
1.480     raeburn  8561:     }
                   8562:     $output .= 
1.481     raeburn  8563:         &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476     raeburn  8564:                                                     $destination,$dir_root,$hiddenelem);
                   8565:     return $output;
                   8566: }
                   8567: 
1.480     raeburn  8568: sub remove_archive {
                   8569:     my ($docudom,$docuname,$container) = @_;
                   8570:     my $map = $env{'form.folder'}.'.'.$container;
1.481     raeburn  8571:     my ($output,$delwarning,$delresult,$url);
1.480     raeburn  8572:     my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
                   8573:     if ($fatal) {
                   8574:         if ($container eq 'page') {
                   8575:             $delwarning = &mt('An error occurred retrieving the contents of the current page.');
                   8576:         } else {
                   8577:             $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
                   8578:         }
1.583     raeburn  8579:         $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  8580:     } else {
                   8581:         my $currcmd = $env{'form.cmd'};
                   8582:         my $position = $env{'form.position'};
1.583     raeburn  8583:         my $archiveidx = $position;
1.563     raeburn  8584:         if ($position > 0) {
1.583     raeburn  8585:             if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
                   8586:                 $archiveidx = $position-1;
                   8587:             }
                   8588:             $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584     raeburn  8589:             my ($title,$url,@rrest) =
1.583     raeburn  8590:                 split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
                   8591:             if ($url eq $env{'form.archiveurl'}) {
                   8592:                 if (&handle_edit_cmd($docuname,$docudom)) {
                   8593:                     ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684     raeburn  8594:                     if ($suppchanges) {
                   8595:                         &Apache::lonnet::update_supp_caches($docudom,$docuname);
                   8596:                         undef($suppchanges);
                   8597:                     }
1.583     raeburn  8598:                     if ($fatal) {
                   8599:                         if ($container eq 'page') {
                   8600:                             $delwarning = &mt('An error occurred updating the contents of the current page.');
                   8601:                         } else {
                   8602:                             $delwarning = &mt('An error occurred updating the contents of the current folder.');
                   8603:                         }
1.480     raeburn  8604:                     } else {
1.583     raeburn  8605:                         $delresult = &mt('Archive file removed.');
1.480     raeburn  8606:                     }
                   8607:                 }
1.583     raeburn  8608:             } else {
                   8609:                 $delwarning .=  &mt('Archive file had unexpected item number in folder.').
                   8610:                                 ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  8611:             }
                   8612:         }
                   8613:         $env{'form.cmd'} = $currcmd;
                   8614:     }
                   8615:     if ($delwarning) {
                   8616:         $output = '<p class="LC_warning">'.
                   8617:                    $delwarning.
                   8618:                    '</p>';
                   8619:     }
                   8620:     if ($delresult) {
                   8621:         $output .= '<p class="LC_info">'.
                   8622:                    $delresult.
                   8623:                    '</p>';
                   8624:     }
1.481     raeburn  8625:     return $output;
1.480     raeburn  8626: }
                   8627: 
1.484     raeburn  8628: sub generate_admin_menu {
1.708     raeburn  8629:     my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484     raeburn  8630:     my $lc_crstype = lc($crstype);
                   8631:     my ($home,$other,%outhash)=&authorhosts();
1.562     bisitz   8632:     my %lt= ( # do not translate here
1.484     raeburn  8633:                                          'vc'   => 'Verify Content',
                   8634:                                          'cv'   => 'Check/Set Resource Versions',
                   8635:                                          'ls'   => 'List Resource Identifiers',
1.651     raeburn  8636:                                          'ct'   => 'Display/Set Shortened URLs for Deep-linking',
1.708     raeburn  8637:                                          'ca'   => "Enter $crstype Authoring Space",
1.484     raeburn  8638:                                          'imse' => 'Export contents to IMS Archive',
1.712     raeburn  8639:                                          'dcd'  => 'Copy uploaded content to Authoring Space',
                   8640:                                          'cpc'  => 'Copy from Course Authoring to User Authoring',
1.562     bisitz   8641:             );
1.712     raeburn  8642:     my ($candump,$dumpurl,$exportcrsurl);
1.484     raeburn  8643:     if ($home + $other > 0) {
                   8644:         $candump = 'F';
                   8645:         if ($home) {
                   8646:             $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
1.712     raeburn  8647:             $exportcrsurl = "javascript:injectData(document.courseverify,'dummy','copyauthored','$lt{'cpc'}')";
1.484     raeburn  8648:         } else {
                   8649:             my @hosts;
                   8650:             foreach my $aurole (keys(%outhash)) {
                   8651:                 unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   8652:                     push(@hosts,$outhash{$aurole});
1.538     raeburn  8653:                 }
1.484     raeburn  8654:             }
                   8655:             if (@hosts == 1) {
                   8656:                 my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
                   8657:                                '&amp;role='.
                   8658:                                &HTML::Entities::encode($env{'request.role'},'"<>&').'&amp;origurl='.
                   8659:                                &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
                   8660:                 $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
1.712     raeburn  8661:                 $exportcrsurl = $dumpurl;
1.484     raeburn  8662:             } else {
                   8663:                 $dumpurl = "javascript:choose_switchserver_window()";
1.712     raeburn  8664:                 $exportcrsurl = $dumpurl;
1.484     raeburn  8665:             }
                   8666:         }
                   8667:     }
                   8668:     my @menu=
                   8669:         ({  categorytitle=>'Administration',
                   8670:             items =>[
                   8671:                 {   linktext   => $lt{'vc'},
                   8672:                     url        => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
                   8673:                     permission => 'F',
1.571     raeburn  8674:                     help       => 'Docs_Verify_Content',
1.484     raeburn  8675:                     icon       => 'verify.png',
                   8676:                     linktitle  => 'Verify contents can be retrieved/rendered',
                   8677:                 },
                   8678:                 {   linktext => $lt{'cv'},
                   8679:                     url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
                   8680:                     permission => 'F',
1.571     raeburn  8681:                     help       => 'Docs_Check_Resource_Versions',
1.484     raeburn  8682:                     icon       => 'resversion.png',
                   8683:                     linktitle  => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
                   8684:                 },
                   8685:                 {   linktext   => $lt{'ls'},
                   8686:                     url        => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
                   8687:                     permission => 'F',
                   8688:                     #help => '',
                   8689:                     icon       => 'symbs.png',
                   8690:                     linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"
                   8691:                 },
1.651     raeburn  8692:                 {   linktext   => $lt{'ct'},
                   8693:                     url        => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
                   8694:                     permission => 'F',
                   8695:                     help       => 'Docs_Short_URLs',
                   8696:                     icon       => 'shorturls.png',
                   8697:                     linktitle  => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
                   8698:                 },
1.484     raeburn  8699:                 ]
1.611     raeburn  8700:         });
                   8701:     if ($canedit) {
1.708     raeburn  8702:         my ($crsauname,$crsaudom,$crshome);
                   8703:         if (($coursenum ne '') && ($coursedom ne '')) {
                   8704:             my $crsauthorurl = "/priv/$coursedom/$coursenum/";
                   8705:             ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
                   8706:             if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
                   8707:                 my @ids=&Apache::lonnet::current_machine_ids();
                   8708:                 my $linkurl;
                   8709:                 if (grep(/^\Q$crshome\E$/,@ids)) {
                   8710:                     $linkurl = $crsauthorurl;
                   8711:                 } else {
1.720     raeburn  8712:                     my $jscall = &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
                   8713:                     if ($jscall) {
                   8714:                         $linkurl = 'javascript:'.$jscall;
                   8715:                     }
1.708     raeburn  8716:                 }
1.720     raeburn  8717:                 if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY') && ($linkurl)) {
1.708     raeburn  8718:                      push(@{$menu[0]->{items}},
                   8719:                      {   linktext   => $lt{'ca'},
                   8720:                          url        => $linkurl,
                   8721:                          permission => 'F',
                   8722:                          help       => 'Docs_Course_Authorspace',
                   8723:                          icon       => 'impcrsau.png',
                   8724:                          linktitle  => $lt{'ca'},
                   8725:                      });
                   8726:                 }
                   8727:             }
                   8728:         }
1.611     raeburn  8729:         push(@menu,
1.484     raeburn  8730:         {   categorytitle=>'Export',
                   8731:             items =>[
                   8732:                 {   linktext   => $lt{'imse'},
                   8733:                     url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
                   8734:                     permission => 'F',
                   8735:                     help       => 'Docs_Export_Course_Docs',
                   8736:                     icon       => 'imsexport.png',
                   8737:                     linktitle  => $lt{'imse'},
                   8738:                 },
                   8739:                 {   linktext   => $lt{'dcd'},
                   8740:                     url        => $dumpurl,
                   8741:                     permission => $candump,
1.571     raeburn  8742:                     help       => 'Docs_Dump_Course_Docs',
1.484     raeburn  8743:                     icon       => 'dump.png',
                   8744:                     linktitle  => $lt{'dcd'},
                   8745:                 },
                   8746:                 ]
                   8747:         });
1.712     raeburn  8748:         if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
                   8749:             if ((ref($menu[1]) eq 'HASH') && (ref($menu[1]->{'items'}) eq 'ARRAY')) {
                   8750:                 push(@{$menu[1]->{items}},
                   8751:                      {   linktext   => $lt{'cpc'},
                   8752:                          url        => $exportcrsurl,
                   8753:                          permission => 'F',
                   8754:                          help       => 'Docs_Export_Course_Author',
                   8755:                          icon       => 'res.png',
                   8756:                          linktitle  => $lt{'cpc'},
                   8757:                      });
                   8758:             }
                   8759:         }
1.611     raeburn  8760:     }
1.484     raeburn  8761:     return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
                   8762:            '<input type="hidden" id="dummy" />'."\n".
                   8763:            &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
                   8764:            '</form>';
1.329     droeschl 8765: }
                   8766: 
                   8767: sub generate_edit_table {
1.538     raeburn  8768:     my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611     raeburn  8769:         $need_save,$copyfolder,$canedit) = @_;
1.406     raeburn  8770:     return unless(ref($orderhash_ref) eq 'HASH');
1.342     ehlerst  8771:     my %orderhash = %{$orderhash_ref};
1.611     raeburn  8772:     my ($form, $activetab, $active, $disabled);
1.570     raeburn  8773:     if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371     tempelho 8774:         $activetab = $env{'form.active'};
                   8775:     }
1.611     raeburn  8776:     unless ($canedit) {
                   8777:         $disabled = ' disabled="disabled"';
                   8778:     }
1.472     raeburn  8779:     my $backicon = $iconpath.'clickhere.gif';
1.525     raeburn  8780:     my $backtext = &mt('Exit Editor');
1.458     raeburn  8781:     $form = '<div class="LC_Box" style="margin:0;">'.
1.488     raeburn  8782:             '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
                   8783:             '<li class="goback">'.
1.546     raeburn  8784:             '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488     raeburn  8785:             '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
                   8786:             '  alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
                   8787:             '<li>'.
                   8788:             '<a href="javascript:groupopen('."'$readfile'".',1);">'.
                   8789:             &mt('Undo Delete').'</a></li>'."\n";
                   8790:     if ($env{'form.docslog'}) {
                   8791:         $form .= '<li class="active">';
                   8792:     } else {
                   8793:         $form .= '<li>';
                   8794:     }
                   8795:     $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
                   8796:              &mt('History').'</a></li>'."\n";
                   8797:     if ($env{'form.docslog'}) {
                   8798:         $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
                   8799:                  &mt('Edit').'</a></li>'."\n";
1.484     raeburn  8800:     }
1.458     raeburn  8801:     foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390     tempelho 8802:         if($name ne '00'){
1.371     tempelho 8803:             if($activetab eq '' || $activetab ne $name){
                   8804:                $active = '';
                   8805:             }elsif($activetab eq $name){
                   8806:                $active = 'class="active"';
                   8807:             }
1.458     raeburn  8808:             $form .= '<li style="float:right" '.$active
1.484     raeburn  8809:                 .' 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 8810:         } else {
1.570     raeburn  8811: 	    $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390     tempelho 8812: 
                   8813: 	}
1.329     droeschl 8814:     }
1.484     raeburn  8815:     $form .= '</ul>'."\n";
                   8816:     $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458     raeburn  8817: 
                   8818:     if ($to_show ne '') {
1.538     raeburn  8819:         my $saveform;
                   8820:         if ($need_save) {
                   8821:             my $button = &mt('Make changes');
                   8822:             my $path;
                   8823:             if ($env{'form.folderpath'}) {
                   8824:                 $path =
                   8825:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   8826:             }
                   8827:             $saveform = <<"END";
                   8828: <div id="multisave" style="display:none; clear:both;" >
                   8829: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
                   8830: <input type="hidden" name="folderpath" value="$path" />
                   8831: <input type="hidden" name="symb" value="$env{'form.symb'}" />
                   8832: <input type="hidden" name="allhiddenresource" value="" />
                   8833: <input type="hidden" name="allencrypturl" value="" />
                   8834: <input type="hidden" name="allrandompick" value="" />
                   8835: <input type="hidden" name="allrandomorder" value="" />
                   8836: <input type="hidden" name="changeparms" value="" />
                   8837: <input type="hidden" name="multiremove" value="" />
                   8838: <input type="hidden" name="multicut" value="" />
                   8839: <input type="hidden" name="multicopy" value="" />
                   8840: <input type="hidden" name="multichange" value="" />
                   8841: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611     raeburn  8842: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538     raeburn  8843: </form>
                   8844: </div>
                   8845: END
                   8846:         }
                   8847:         $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458     raeburn  8848:     }
1.363     ehlerst  8849:     foreach my $field (keys(%orderhash)){
1.390     tempelho 8850: 	if($field ne '00'){
1.422     onken    8851:             if($activetab eq '' || $activetab ne $field){
1.458     raeburn  8852:                 $active = 'style="display: none;float:left"';
1.422     onken    8853:             }elsif($activetab eq $field){
1.458     raeburn  8854:                 $active = 'style="display:block;float:left"';
1.422     onken    8855:             }
                   8856:             $form .= '<div id="'.$field.$tid.'"'
                   8857:                     .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484     raeburn  8858:                     .'</div>'."\n";
1.363     ehlerst  8859:         }
                   8860:     }
1.484     raeburn  8861:     unless ($env{'form.docslog'}) {
                   8862:         $form .= '</div></div>'."\n";
                   8863:     }
1.329     droeschl 8864:     return $form;
                   8865: }
                   8866: 
                   8867: sub editing_js {
1.622     raeburn  8868:     my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
                   8869:         $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594     damieng  8870:     my %js_lt = &Apache::lonlocal::texthash(
1.329     droeschl 8871:                                           p_mnf => 'Name of New Folder',
                   8872:                                           t_mnf => 'New Folder',
                   8873:                                           p_mnp => 'Name of New Page',
                   8874:                                           t_mnp => 'New Page',
1.451     www      8875:                                           p_mxu => 'Title for the External Score',
1.349     biermanm 8876:                                           p_msp => 'Name of Simple Course Page',
1.329     droeschl 8877:                                           p_msb => 'Title for the Problem',
                   8878:                                           p_mdb => 'Title for the Drop Box',
1.336     schafran 8879:                                           p_mbb => 'Title for the Discussion Board',
1.604     raeburn  8880:                                           p_mwp => 'Title for Web Page',
1.606     raeburn  8881:                                           p_mnr => 'Title for the Resource',
1.348     weissno  8882:                                           p_mab => "Enter user:domain for User's Personal Information Page",
1.352     bisitz   8883:                                           p_mab2 => 'Personal Information Page of ',
1.329     droeschl 8884:                                           p_mab_alrt1 => 'Not a valid user:domain',
                   8885:                                           p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
                   8886:                                           p_chn => 'New Title',
                   8887:                                           p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603     raeburn  8888:                                           p_rmr2a => 'Remove',
                   8889:                                           p_rmr2b => '?',
                   8890:                                           p_rmr3a => 'Remove those',
                   8891:                                           p_rmr3b => 'items?',
                   8892:                                           p_rmr4  => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
                   8893:                                           p_rmr5  => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329     droeschl 8894:                                           p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
                   8895:                                           p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603     raeburn  8896:                                           p_ctr2a => 'Cut',
                   8897:                                           p_ctr2b => '?',
                   8898:                                           p_ctr3a => 'Cut those',
                   8899:                                           p_ctr3b => 'items?',
1.633     raeburn  8900:                                           setal   => 'Enter a (unique) alias',
                   8901:                                           delal   => 'Are you sure you want to eliminate the alias?',
1.478     raeburn  8902:                                           rpck    => 'Enter number to pick (e.g., 3)',
1.501     raeburn  8903:                                           imsfile => 'You must choose an IMS package for import',
                   8904:                                           imscms  => 'You must select which Course Management System was the source of the IMS package',
                   8905:                                           invurl  => 'Invalid URL',
                   8906:                                           titbl   => 'Title is blank',
1.538     raeburn  8907:                                           more    => '(More ...)',
                   8908:                                           less    => '(Less ...)',
1.543     raeburn  8909:                                           noor    => 'No actions selected or changes to settings specified.',
                   8910:                                           noch    => 'No changes to settings specified.',
                   8911:                                           noac    => 'No actions selected.',
1.606     raeburn  8912:                                           nofi    => 'No file selected',
                   8913:                                           tinc    => 'Title in course',
                   8914:                                           sunm    => 'Sub-directory name',
1.618     raeburn  8915:                                           edri    => 'Editing rights unavailable for your current role.',
1.691     raeburn  8916:                                           sele    => 'Select',
                   8917:                                           swit    => 'Switch server required',
1.329     droeschl 8918:                                         );
1.594     damieng  8919:     &js_escape(\%js_lt);
1.433     raeburn  8920:     my $crstype = &Apache::loncommon::course_type();
1.434     raeburn  8921:     my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
                   8922:     my $main_container_page;
1.519     raeburn  8923:     if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
                   8924:         $main_container_page = 1;
1.434     raeburn  8925:     }
1.617     raeburn  8926:     my $backtourl;
                   8927:     my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446     www      8928:     my $toplevelsupp = &supplemental_base();
1.690     raeburn  8929:     my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691     raeburn  8930:     my @ids=&Apache::lonnet::current_machine_ids();
                   8931:     my $machines_str = "'".join("','",@ids)."'";
1.530     raeburn  8932:     if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
                   8933:         my $caller = $1;
1.525     raeburn  8934:         if ($caller =~ /^supplemental/) {
                   8935:             $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
                   8936:         } else {
                   8937:             my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
                   8938:             $res = &Apache::lonnet::clutter($res);
                   8939:             if (&Apache::lonnet::is_on_map($res)) {
1.609     raeburn  8940:                 my ($url,$anchor);
                   8941:                 if ($res =~ /^([^#]+)#([^#]+)$/) {
                   8942:                     $url = $1;
                   8943:                     $anchor = $2;
                   8944:                     if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
                   8945:                         $caller = $1.&escape('#').$anchor;
                   8946:                     }
1.614     raeburn  8947:                 } else {
                   8948:                     $url = $res;
1.609     raeburn  8949:                 }
1.640     raeburn  8950:                 $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
                   8951:                 if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
                   8952:                     $backtourl .= '?navmap=1';
                   8953:                 } else {
                   8954:                     $backtourl .= '?symb='.
                   8955:                                   &HTML::Entities::encode($caller,'<>&"');
                   8956:                 }
1.622     raeburn  8957:                 if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   8958:                     if (($ENV{'SERVER_PORT'} == 443) &&
                   8959:                         ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  8960:                         unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  8961:                             if ($hostname ne '') {
                   8962:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   8963:                             }
                   8964:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  8965:                         }
                   8966:                     }
1.623     raeburn  8967:                 } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
                   8968:                     if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678     raeburn  8969:                         unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658     raeburn  8970:                             if ($hostname ne '') {
                   8971:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   8972:                             }
                   8973:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.657     raeburn  8974:                         }
1.623     raeburn  8975:                     }
1.622     raeburn  8976:                 }
1.609     raeburn  8977:                 if ($anchor ne '') {
                   8978:                     $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
                   8979:                 }
1.590     raeburn  8980:                 $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544     raeburn  8981:             } else {
                   8982:                 $backtourl = '/adm/navmaps';
1.525     raeburn  8983:             }
                   8984:         }
                   8985:     } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
                   8986:         $backtourl = '/adm/menu';
                   8987:     } elsif ($supplementalflag) {
1.682     raeburn  8988:         if (($env{'request.role.adv'}) ||
                   8989:             (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
                   8990:             $backtourl = '/adm/supplemental';
                   8991:         } else {
                   8992:             $backtourl = '/adm/navmaps';
                   8993:         }
1.525     raeburn  8994:     } else {
                   8995:         $backtourl = '/adm/navmaps';
1.472     raeburn  8996:     }
                   8997: 
1.655     raeburn  8998:     my $fieldsets = "'doc'";
1.519     raeburn  8999:     unless ($main_container_page) {
                   9000:         $fieldsets .=",'ims'";
                   9001:     }
1.655     raeburn  9002:     my $extfieldsets = "'ext'";
                   9003:     if ($posslti) {
                   9004:         $extfieldsets .= ",'tool'";
                   9005:     }
1.501     raeburn  9006:     if ($supplementalflag) {
1.655     raeburn  9007:         $fieldsets = "'suppdoc'";
                   9008:         $extfieldsets = "'suppext'";
1.600     raeburn  9009:         if ($posslti) {
1.655     raeburn  9010:             $extfieldsets .= ",'supptool'";
1.600     raeburn  9011:         }
1.501     raeburn  9012:     }
1.655     raeburn  9013: 
1.611     raeburn  9014:     my $jsmakefunctions;
                   9015:     if ($canedit) {
                   9016:         $jsmakefunctions = <<ENDNEWSCRIPT;
1.329     droeschl 9017: function makenewfolder(targetform,folderseq) {
1.594     damieng  9018:     var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329     droeschl 9019:     if (foldername) {
1.676     raeburn  9020:        targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329     droeschl 9021:         targetform.submit();
                   9022:     }
                   9023: }
                   9024: 
                   9025: function makenewpage(targetform,folderseq) {
1.594     damieng  9026:     var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329     droeschl 9027:     if (pagename) {
1.676     raeburn  9028:         targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329     droeschl 9029:         targetform.submit();
                   9030:     }
                   9031: }
                   9032: 
                   9033: function makeexamupload() {
1.594     damieng  9034:    var title=prompt('$js_lt{"p_mxu"}');
1.344     bisitz   9035:    if (title) {
1.329     droeschl 9036:     this.document.forms.newexamupload.importdetail.value=
1.676     raeburn  9037: 	encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329     droeschl 9038:     this.document.forms.newexamupload.submit();
                   9039:    }
                   9040: }
                   9041: 
                   9042: function makesmppage() {
1.594     damieng  9043:    var title=prompt('$js_lt{"p_msp"}');
1.344     bisitz   9044:    if (title) {
1.329     droeschl 9045:     this.document.forms.newsmppg.importdetail.value=
1.676     raeburn  9046: 	encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329     droeschl 9047:     this.document.forms.newsmppg.submit();
                   9048:    }
                   9049: }
                   9050: 
1.534     raeburn  9051: function makewebpage(type) {
1.594     damieng  9052:    var title=prompt('$js_lt{"p_mwp"}');
1.534     raeburn  9053:    var formname;
                   9054:    if (type == 'supp') {
                   9055:        formname = this.document.forms.supwebpage;
                   9056:    } else {
                   9057:        formname = this.document.forms.newwebpage;
                   9058:    }
                   9059:    if (title) {
                   9060:        var webpage = formname.importdetail.value; 
1.675     raeburn  9061:        formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534     raeburn  9062:        formname.submit();
                   9063:    }
                   9064: }
                   9065: 
1.329     droeschl 9066: function makesmpproblem() {
1.594     damieng  9067:    var title=prompt('$js_lt{"p_msb"}');
1.344     bisitz   9068:    if (title) {
1.329     droeschl 9069:     this.document.forms.newsmpproblem.importdetail.value=
1.676     raeburn  9070: 	encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329     droeschl 9071:     this.document.forms.newsmpproblem.submit();
                   9072:    }
                   9073: }
                   9074: 
                   9075: function makedropbox() {
1.594     damieng  9076:    var title=prompt('$js_lt{"p_mdb"}');
1.344     bisitz   9077:    if (title) {
1.329     droeschl 9078:     this.document.forms.newdropbox.importdetail.value=
1.676     raeburn  9079:         encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329     droeschl 9080:     this.document.forms.newdropbox.submit();
                   9081:    }
                   9082: }
                   9083: 
                   9084: function makebulboard() {
1.594     damieng  9085:    var title=prompt('$js_lt{"p_mbb"}');
1.329     droeschl 9086:    if (title) {
                   9087:     this.document.forms.newbul.importdetail.value=
1.676     raeburn  9088: 	encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329     droeschl 9089:     this.document.forms.newbul.submit();
                   9090:    }
                   9091: }
                   9092: 
                   9093: function makeabout() {
1.594     damieng  9094:    var user=prompt("$js_lt{'p_mab'}");
1.329     droeschl 9095:    if (user) {
                   9096:        var comp=new Array();
                   9097:        comp=user.split(':');
                   9098:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   9099: 	   if ((comp[0]) && (comp[1])) {
                   9100: 	       this.document.forms.newaboutsomeone.importdetail.value=
1.594     damieng  9101: 		   '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611     raeburn  9102:                this.document.forms.newaboutsomeone.submit();
                   9103:            } else {
                   9104:                alert("$js_lt{'p_mab_alrt1'}");
                   9105:            }
                   9106:        } else {
                   9107:            alert("$js_lt{'p_mab_alrt2'}");
                   9108:        }
                   9109:     }
                   9110: }
                   9111: 
                   9112: function makenew(targetform) {
                   9113:     targetform.submit();
                   9114: }
                   9115: 
                   9116: function changename(folderpath,index,oldtitle) {
                   9117:     var title=prompt('$js_lt{"p_chn"}',oldtitle);
                   9118:     if (title) {
                   9119:         this.document.forms.renameform.markcopy.value='';
                   9120:         this.document.forms.renameform.title.value=title;
                   9121:         this.document.forms.renameform.cmd.value='rename_'+index;
                   9122:         this.document.forms.renameform.folderpath.value=folderpath;
                   9123:         this.document.forms.renameform.submit();
                   9124:     }
                   9125: }
                   9126: 
1.633     raeburn  9127: function setalias(folderpath,index) {
                   9128:     var alias = prompt('$js_lt{"setal"}');
                   9129:     if ((alias != null) && (alias != '')) {
                   9130:         this.document.forms.aliasform.alias.value=alias;
                   9131:         this.document.forms.aliasform.cmd.value='setalias_'+index;
                   9132:         this.document.forms.aliasform.folderpath.value=folderpath;
                   9133:         this.document.forms.aliasform.submit();
                   9134:     }
                   9135: }
                   9136: 
                   9137: function delalias(folderpath,index) {
                   9138:     if (confirm('$js_lt{"delal"}')) {
                   9139:         this.document.forms.aliasform.cmd.value='delalias_'+index;
                   9140:         this.document.forms.aliasform.folderpath.value=folderpath;
                   9141:         this.document.forms.aliasform.submit();
                   9142:     }
                   9143: }
                   9144: 
1.611     raeburn  9145: ENDNEWSCRIPT
                   9146:     } else {
                   9147:         $jsmakefunctions = <<ENDNEWSCRIPT;
                   9148: 
                   9149: function makenewfolder() {
                   9150:     alert("$js_lt{'edri'}");
                   9151: }
                   9152: 
                   9153: function makenewpage() {
                   9154:     alert("$js_lt{'edri'}");
                   9155: }
                   9156: 
                   9157: function makeexamupload() {
                   9158:     alert("$js_lt{'edri'}");
                   9159: }
                   9160: 
                   9161: function makesmppage() {
                   9162:     alert("$js_lt{'edri'}");
                   9163: }
                   9164: 
                   9165: function makewebpage(type) {
                   9166:     alert("$js_lt{'edri'}");
                   9167: }
                   9168: 
                   9169: function makesmpproblem() {
                   9170:     alert("$js_lt{'edri'}");
                   9171: }
                   9172: 
                   9173: function makedropbox() {
                   9174:     alert("$js_lt{'edri'}");
                   9175: }
                   9176: 
                   9177: function makebulboard() {
                   9178:     alert("$js_lt{'edri'}");
                   9179: }
                   9180: 
                   9181: function makeabout() {
                   9182:     alert("$js_lt{'edri'}");
                   9183: }
                   9184: 
                   9185: function changename() {
                   9186:     alert("$js_lt{'edri'}");
                   9187: }
                   9188: 
1.633     raeburn  9189: function setalias() {
                   9190:     alert("$js_lt{'edri'}");
                   9191: }
                   9192: 
                   9193: function delalias() {
                   9194:     alert("$js_lt{'edri'}");
                   9195: }
                   9196: 
1.611     raeburn  9197: function makenew() {
                   9198:     alert("$js_lt{'edri'}");
                   9199: }
                   9200: 
                   9201: function groupimport() {
                   9202:     alert("$js_lt{'edri'}");
1.335     ehlerst  9203: }
1.611     raeburn  9204: 
                   9205: function groupsearch() {
                   9206:     alert("$js_lt{'edri'}");
1.335     ehlerst  9207: }
1.611     raeburn  9208: 
                   9209: function groupopen(url,recover) {
                   9210:    var options="scrollbars=1,resizable=1,menubar=0";
                   9211:    idxflag=1;
                   9212:    idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
                   9213:    idx.focus();
1.329     droeschl 9214: }
                   9215: 
1.611     raeburn  9216: ENDNEWSCRIPT
                   9217: 
                   9218:     }
                   9219:     return <<ENDSCRIPT;
                   9220: 
                   9221: $jsmakefunctions
                   9222: 
1.501     raeburn  9223: function toggleUpload(caller) {
                   9224:     var blocks = Array($fieldsets);
                   9225:     for (var i=0; i<blocks.length; i++) {
                   9226:         var disp = 'none';
                   9227:         if (caller == blocks[i]) {
                   9228:             var curr = document.getElementById('upload'+caller+'form').style.display;
                   9229:             if (curr == 'none') {
                   9230:                 disp='block';
                   9231:             }
                   9232:         }
                   9233:         document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655     raeburn  9234:     }
                   9235:     resize_scrollbox('contentscroll','1','1');
                   9236:     return;
                   9237: }
                   9238: 
                   9239: function toggleExternal(caller) {
                   9240:     var blocks = Array($extfieldsets);
                   9241:     for (var i=0; i<blocks.length; i++) {
                   9242:         var disp = 'none';
                   9243:         if (caller == blocks[i]) {
                   9244:             var curr = document.getElementById('external'+caller+'form').style.display;
                   9245:             if (curr == 'none') {
                   9246:                 disp='block';
                   9247:             }
                   9248:         }
                   9249:         document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598     raeburn  9250:         if ((caller == 'tool') || (caller == 'supptool')) {
                   9251:             if (disp == 'block') {
1.655     raeburn  9252:                 if (document.getElementById('LC_exttoolid')) {
                   9253:                     var toolselector = document.getElementById('LC_exttoolid');
1.598     raeburn  9254:                     var suppflag = 0;
                   9255:                     if (caller == 'supptool') {
                   9256:                         suppflag = 1;
                   9257:                     }
                   9258:                     currForm = document.getElementById('new'+caller);
1.655     raeburn  9259:                     updateExttool(toolselector,currForm,suppflag);
1.598     raeburn  9260:                 }
                   9261:             }
                   9262:         }
1.501     raeburn  9263:     }
1.502     raeburn  9264:     resize_scrollbox('contentscroll','1','1');
                   9265:     return;
                   9266: }
                   9267: 
1.514     raeburn  9268: function toggleMap(caller) {
1.502     raeburn  9269:     var disp = 'none';
1.510     raeburn  9270:     if (document.getElementById('importmapform')) {
1.514     raeburn  9271:         if (caller == 'map') {
                   9272:             var curr = document.getElementById('importmapform').style.display;
                   9273:             if (curr == 'none') {
                   9274:                 disp='block';
                   9275:             }
1.510     raeburn  9276:         }
                   9277:         document.getElementById('importmapform').style.display=disp;
1.706     raeburn  9278:         if (disp == 'block') {
                   9279:             if (document.getElementById('importcrsresform')) {
                   9280:                 if (document.getElementById('importcrsresform').style.display == 'block') {
                   9281:                     document.getElementById('importcrsresform').style.display = 'none';
                   9282:                 }
                   9283:             }
                   9284:         }
1.510     raeburn  9285:         resize_scrollbox('contentscroll','1','1');
1.502     raeburn  9286:     }
1.501     raeburn  9287:     return;
1.329     droeschl 9288: }
                   9289: 
1.691     raeburn  9290: function toggleCrsRes(caller) {
1.606     raeburn  9291:     var disp = 'none';
                   9292:     if (document.getElementById('crsresform')) {
                   9293:         if (caller == 'res') {
1.691     raeburn  9294:             var form = document.getElementById('crsresform');
                   9295:             var curr = form.style.display;
1.606     raeburn  9296:             if (curr == 'none') {
                   9297:                 disp='block';
1.691     raeburn  9298:                 document.courseresform.authorrole.selectedIndex = 0;
                   9299:                 document.courseresform.authorpath.selectedIndex = 0;
                   9300:                 document.courseresform.newresourceadd.selectedIndex = 0;
                   9301:                 populateDirSelects(form,'authorrole','authorpath',1,0,0);
                   9302:                 toggleNewInCourse(document.courseresform);
                   9303:                 if (document.getElementById('newresource')) {
                   9304:                     document.getElementById('newresource').style.display = 'none';
1.606     raeburn  9305:                 }
                   9306:                 if (document.courseresform.newresusetemp.length) {
                   9307:                     document.courseresform.newresusetemp[0].checked = true;
                   9308:                     toggleWithTemplate(document.courseresform);
                   9309:                 }
                   9310:                 document.courseresform.newresourcename.value = ''; 
                   9311:             }
                   9312:         }
                   9313:         if (document.courseresform.newsubdir.length) {
                   9314:             for (var j=0; j<document.courseresform.newsubdir.length; j++) {
                   9315:                 if (document.courseresform.newsubdir[j].value == 0) {
                   9316:                     document.courseresform.newsubdir[j].checked = true;
                   9317:                 }
                   9318:                 break;
                   9319:             }
                   9320:             if (document.getElementById('newsubdirname')) {
                   9321:                 document.getElementById('newsubdirname').type = "hidden";
                   9322:                 document.getElementById('newsubdirname').value = "";
                   9323:             }
                   9324:             if (document.getElementById('newsubdir')) {
                   9325:                 document.getElementById('newsubdir').innerHTML = "";
                   9326:             }
                   9327:         }
                   9328:         document.getElementById('crsresform').style.display=disp;
                   9329:         resize_scrollbox('contentscroll','1','0');
                   9330:     }
                   9331:     return;
                   9332: }
                   9333: 
                   9334: function toggleNewsubdir(form) {
                   9335:     if (form.newsubdir.length) {
                   9336:         for (var j=0; j<form.newsubdir.length; j++) {
                   9337:             if (form.newsubdir[j].checked) {
                   9338:                 if (document.getElementById('newsubdirname')) {
                   9339:                     if (form.newsubdir[j].value == '1') {
                   9340:                         document.getElementById('newsubdirname').type = "text"; 
                   9341:                         if (document.getElementById('newsubdir')) {
                   9342:                             document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
                   9343:                         }
                   9344:                     } else {
                   9345:                         document.getElementById('newsubdirname').type = "hidden";
                   9346:                         document.getElementById('newsubdirname').value = "";
                   9347:                         document.getElementById('newsubdir').innerHTML = "";
                   9348:                     }
                   9349:                 }
                   9350:                 break;
                   9351:             }
                   9352:         }
                   9353:     }
                   9354: }
                   9355: 
                   9356: function toggleCrsResTitle() {
                   9357:     if (document.getElementById('newresource')) {
1.691     raeburn  9358:         var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
                   9359:         if (selloc == 'course') {
1.606     raeburn  9360:             document.getElementById('newresource').style.display = 'inline';
                   9361:             document.courseresform.newresourceadd[0].checked = true;
                   9362:             toggleNewInCourse(document.courseresform);
                   9363:         } else {
                   9364:             document.getElementById('newresource').style.display = 'none';
                   9365:         }
1.689     raeburn  9366:     }
                   9367:     if (document.getElementById('newstdproblem')) {
                   9368:         if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
                   9369:             document.getElementById('newstdproblem').style.display = 'none'; 
                   9370:             if (document.getElementById('stdprobswitch')) {
                   9371:                 document.getElementById('stdprobswitch').style.display = 'block'; 
                   9372:             }
                   9373:         } else {
                   9374:             document.getElementById('newstdproblem').style.display = 'block';
                   9375:             if (document.getElementById('stdprobswitch')) {
                   9376:                 document.getElementById('stdprobswitch').style.display = 'none';
                   9377:             }
                   9378:         }
                   9379:     }
1.606     raeburn  9380: }
                   9381: 
                   9382: function toggleNewInCourse(form) {
                   9383:     if (form.newresourceadd.length) {
                   9384:         for (var i=0; i<form.newresourceadd.length; i++) {
                   9385:             if (form.newresourceadd[i].checked) {
                   9386:                 if (document.getElementById('newresourcetitle')) {
                   9387:                     if (form.newresourceadd[i].value == '1') {
                   9388:                         document.getElementById('newresourcetitle').type = 'text';
                   9389:                         if (document.getElementById('newrestitle')) {
                   9390:                             document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
                   9391:                         }
                   9392:                     } else {
                   9393:                         document.getElementById('newresourcetitle').type = 'hidden';
                   9394:                         document.getElementById('newresourcetitle').value = '';
                   9395:                         if (document.getElementById('newrestitle')) { 
                   9396:                             document.getElementById('newrestitle').innerHTML = '';
                   9397:                         }
                   9398:                     }
                   9399:                 }
                   9400:                 break;
                   9401:             }
                   9402:         }
                   9403:     }
                   9404: }
                   9405: 
                   9406: function toggleWithTemplate(form) {
                   9407:     if (form.newresusetemp.length) {
                   9408:         for (var i=0; i<form.newresusetemp.length; i++) {
                   9409:             if (form.newresusetemp[i].checked) {
                   9410:                 if (document.getElementById('newrestemplate')) { 
                   9411:                     if (form.newresusetemp[i].value == '1') {
                   9412:                         document.getElementById('newrestemplate').style.display = 'inline';
                   9413:                         toggleExampleText();
                   9414:                     } else {
                   9415:                         form.tempcategory.selectedIndex = 0;
                   9416:                         select1template_changed();
                   9417:                         document.getElementById('newrestemplate').style.display = 'none';
                   9418:                     }
                   9419:                 }
                   9420:             }
                   9421:         }
                   9422:     }
                   9423: }
                   9424: 
                   9425: function toggleExampleText() {
                   9426:     if (document.getElementById('newresexample')) {
                   9427:         var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   9428:         if (url == '') {
                   9429:             document.getElementById('newresexample').style.fontWeight = 'normal';
                   9430:         } else {
                   9431:             document.getElementById('newresexample').style.fontWeight = 'bold';
                   9432:         }
                   9433:     }
                   9434: }
                   9435: 
                   9436: function getExample(width,height,scrolling,transparency) {
                   9437:     var url;
                   9438:     if (document.courseresform.newresusetemp.length) {
                   9439:         for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
                   9440:             if (document.courseresform.newresusetemp[i].checked) {
                   9441:                 if (document.courseresform.newresusetemp[i].value == '1') {
                   9442:                     var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   9443:                     if (url == '') {
                   9444:                         alert('Pick a category and template');
                   9445:                     } else {
                   9446:                         url = url.replace("$londocroot",""); 
                   9447:                         url += '?inhibitmenu=yes';
                   9448:                     }
                   9449:                 }
                   9450:                 break;
                   9451:             }
                   9452:         }
                   9453:     }
                   9454:     if (url != '') {
                   9455:         openMyModal(url,width,height,scrolling,transparency,'');
                   9456:     }
                   9457: }
                   9458: 
1.690     raeburn  9459: function toggleImportCrsres(caller) {
1.606     raeburn  9460:     var disp = 'none';
                   9461:     if (document.getElementById('importcrsresform')) {
                   9462:         if (caller == 'res') {
                   9463:             var curr = document.getElementById('importcrsresform').style.display;
                   9464:             if (curr == 'none') {
                   9465:                 disp='block';
1.698     raeburn  9466:                 populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
                   9467:                 if ((document.getElementById('importcrsrescontent')) &&
                   9468:                     (document.getElementById('importcrsresempty'))) {
                   9469:                     var selelem = document.crsresimportform.elements['coursepath'];
                   9470:                     var numdirs = 0;
                   9471:                     if (selelem.options.length) {
                   9472:                         numdirs = selelem.options.length - 1;
                   9473:                     }
                   9474:                     if (numdirs) {
                   9475:                         document.getElementById('importcrsrescontent').style.display='block';
                   9476:                         document.getElementById('importcrsresempty').style.display='none';
                   9477:                     } else {
                   9478:                         document.getElementById('importcrsrescontent').style.display='none';
                   9479:                         document.getElementById('importcrsresempty').style.display='block';
                   9480:                     }
                   9481:                 }
1.606     raeburn  9482:             }
                   9483:         }
                   9484:         document.getElementById('importcrsresform').style.display=disp;
1.706     raeburn  9485:         if (disp == 'block') {
                   9486:             if (document.getElementById('importmapform')) {
                   9487:                 if (document.getElementById('importmapform').style.display == 'block') {
                   9488:                     document.getElementById('importmapform').style.display = 'none';
                   9489:                 }
                   9490:             }
                   9491:         }
1.606     raeburn  9492:         resize_scrollbox('contentscroll','1','0');
                   9493:     }
                   9494:     return;
                   9495: }
                   9496: 
1.690     raeburn  9497: $showfile_js
                   9498: 
1.691     raeburn  9499: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
                   9500:     var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
                   9501:     if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
                   9502:         var selelem = form.elements[dirsel];
                   9503:         var i, numfiles = selelem.options.length -1;
                   9504:         if (numfiles >=0) {
                   9505:             for (i = numfiles; i >= 0; i--) {
                   9506:                 selelem.remove(i);
                   9507:             }
                   9508:         }
                   9509:         if ((location == '') || (location == null) || (location == 'undefined')) {
                   9510:              if (selelem.options.length == 0) {
                   9511:                  selelem.options[selelem.options.length] = new Option('','');
                   9512:                  selelem.selectedIndex = 0;
                   9513:              }
                   9514:              if (document.getElementById('newstdproblem')) {
                   9515:                  document.getElementById('newstdproblem').style.display = 'none';
                   9516:              }
                   9517:              return;
                   9518:         }
                   9519:         var machineIds = new Array($machines_str);
                   9520:         var athome = 0;
                   9521:         var role = location;
                   9522:         if ((location == 'author') || (location == 'course')) {
                   9523:             if (document.getElementById('rolehome_'+location)) {
                   9524:                 var currhome = document.getElementById('rolehome_'+location).value;
                   9525:                 if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
                   9526:                     if (machineIds.includes(currhome)) {
                   9527:                         athome = 1;
                   9528:                     }
                   9529:                 }
                   9530:             }
                   9531:         } else {
                   9532:             const roleinfo = location.split('___');
                   9533:             role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
                   9534:             if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
                   9535:                 var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
                   9536:                 if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
                   9537:                     if (machineIds.includes(currhome)) {
                   9538:                         athome = 1;
                   9539:                     }
                   9540:                 }
                   9541:             }
                   9542:         }
1.706     raeburn  9543:         var templateradio = document.courseresform.elements['newresusetemp'];
1.691     raeburn  9544:         if (athome) {
                   9545:             if (document.getElementById('stdprobswitch')) {
                   9546:                 document.getElementById('stdprobswitch').style.display = 'none';
                   9547:             }
                   9548:             if (document.getElementById('newstdproblem')) {
                   9549:                 document.getElementById('newstdproblem').style.display = 'none';
                   9550:             }
1.706     raeburn  9551:             var canedit = '$canedit';
                   9552:             if (canedit) {
                   9553:                 if (templateradio.length > 1) {
                   9554:                     for (var i=0; i<templateradio.length; i++) {
                   9555:                         templateradio[i].disabled = false;
                   9556:                     }
                   9557:                 }
                   9558:                 document.courseresform.newresourcename.disabled = false;
                   9559:                 document.courseresform.newcrs.disabled = false;
                   9560:             }
1.691     raeburn  9561:             var http = new XMLHttpRequest();
                   9562:             var url = "/adm/courseauthor";
1.698     raeburn  9563:             var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691     raeburn  9564:             http.open("POST", url, true);
                   9565:             http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                   9566:             http.onreadystatechange = function() {
                   9567:                 if (http.readyState == 4 && http.status == 200) {
                   9568:                     var data = JSON.parse(http.responseText);
                   9569:                     if (Array.isArray(data.dirs)) {
                   9570:                         var len = data.dirs.length;
                   9571:                         if (len) {
                   9572:                             if (len > 1) {
                   9573:                                 selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
                   9574:                             }
                   9575:                         }
                   9576:                         if (len) {
                   9577:                             var j;
                   9578:                             for (j = 0; j < len; j++) {
                   9579:                                 selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
                   9580:                             }
                   9581:                             selelem.selectedIndex = 0;
1.697     raeburn  9582:                             if (len == 1) {
                   9583:                                 toggleCrsResTitle();
                   9584:                             }
1.691     raeburn  9585:                         }
                   9586:                     }
                   9587:                 }
                   9588:             }
                   9589:             http.send(params);
                   9590:         } else {
                   9591:             selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
                   9592:             selelem.selectedIndex = 0;
                   9593:             if (document.getElementById('stdprobswitch')) {
                   9594:                 document.getElementById('stdprobswitch').style.display = 'block';
                   9595:             }
                   9596:             if (document.getElementById('newstdproblem')) {
                   9597:                 document.getElementById('newstdproblem').style.display = 'none';
                   9598:             }
1.706     raeburn  9599:             if (templateradio.length > 1) {
                   9600:                 for (var i=0; i<templateradio.length; i++) {
                   9601:                     templateradio[i].disabled = true;
                   9602:                 }
                   9603:             }
                   9604:             document.courseresform.newresourcename.disabled = true;
                   9605:             document.courseresform.newcrs.disabled = true;
1.691     raeburn  9606:         }
                   9607:     }
                   9608:     return;
                   9609: }
                   9610: 
1.689     raeburn  9611: function switchForProb() {
                   9612:     if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
                   9613:         var url = '/adm/switchserver?otherserver=';
                   9614:         var newhostid = '';
                   9615:         var role = '';
                   9616:         var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
                   9617:         if (selloc == 'author') {
                   9618:             newhostid = document.courseresform.rolehome_author.value;
                   9619:             role = "au./&js_escape($env{'user.domain'})/";
                   9620:         } else if (selloc == 'course') {
                   9621:             newhostid = document.courseresform.rolehome_course.value;
                   9622:             role = "&js_escape($env{'request.role'})";
                   9623:         } else {
                   9624:             var items = new Array();
                   9625:             items = selloc.split('___');
                   9626:             var len = document.courseresform.rolehome_coauthor.length;
                   9627:             if (null == len) {
                   9628:                 var currval = document.courseresform.rolehome_coauthor.value;
                   9629:                 if (null != currval) {
                   9630:                     var info = new Array();
                   9631:                     info = currval.split('=');
                   9632:                     newhostid = info[2];
                   9633:                     role = info[0]+'./'+info[1];
                   9634:                 }
                   9635:             } else {
                   9636:                 for (var i=0; i<len; i++) {
                   9637:                     var currval = document.courseresform.rolehome_coauthor[i].value;
                   9638:                     if (null != currval) {
                   9639:                         var info = new Array();
                   9640:                         info = currval.split('=');
                   9641:                         if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
                   9642:                             newhostid = info[2];
                   9643:                             role = info[0]+'./'+info[1];
                   9644:                             break;
                   9645:                         }
                   9646:                     }
                   9647:                 }
                   9648:             }
                   9649:         }
                   9650:         if (newhostid != '') {
                   9651:             url += newhostid;
                   9652:             if (role != '') {
                   9653:                 url += '&role='+role;
                   9654:             }
                   9655:             document.location.href = url;
                   9656:         }
                   9657:     }
                   9658:     return;
                   9659: }
                   9660: 
1.501     raeburn  9661: function makeims(imsform) {
                   9662:     if ((imsform.uploaddoc.value == '')  || (!imsform.uploaddoc.value)) {
1.594     damieng  9663:         alert("$js_lt{'imsfile'}");
1.501     raeburn  9664:         return;
                   9665:     }
                   9666:     if (imsform.source.selectedIndex == 0) {
1.594     damieng  9667:         alert("$js_lt{'imscms'}");
1.501     raeburn  9668:         return;
                   9669:     }
                   9670:     newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
                   9671:     imsform.submit();
                   9672: }
                   9673: 
1.478     raeburn  9674: function updatePick(targetform,index,caller) {
1.537     raeburn  9675:     var pickitem;
                   9676:     var picknumitem;
                   9677:     var picknumtext;
                   9678:     if (index == 'all') {
                   9679:         pickitem = document.getElementById('randompickall');
                   9680:         picknumitem = document.getElementById('rpicknumall');
                   9681:         picknumtext = document.getElementById('rpicktextall');
                   9682:     } else {
                   9683:         pickitem = document.getElementById('randompick_'+index);
                   9684:         picknumitem = document.getElementById('rpicknum_'+index);
                   9685:         picknumtext = document.getElementById('randompicknum_'+index);
                   9686:     }
1.478     raeburn  9687:     if (pickitem.checked) {
1.594     damieng  9688:         var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478     raeburn  9689:         if (picknum == '' || picknum == null) {
                   9690:             if (caller == 'check') {
                   9691:                 pickitem.checked=false;
1.537     raeburn  9692:                 if (index == 'all') {
                   9693:                     picknumtext.innerHTML = '';
                   9694:                     if (caller == 'link') {
                   9695:                         propagateState(targetform,'rpicknum');
                   9696:                     }
                   9697:                 } else {
1.538     raeburn  9698:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  9699:                 }
1.478     raeburn  9700:             }
                   9701:         } else {
                   9702:             picknum.toString();
                   9703:             var regexdigit=/^\\d+\$/;
                   9704:             if (regexdigit.test(picknum)) {
                   9705:                 picknumitem.value = picknum;
1.537     raeburn  9706:                 if (index == 'all') {
1.538     raeburn  9707:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537     raeburn  9708:                     if (caller == 'link') {
                   9709:                         propagateState(targetform,'rpicknum');
                   9710:                     }
                   9711:                 } else {
                   9712:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538     raeburn  9713:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  9714:                 }
1.478     raeburn  9715:             } else {
                   9716:                 if (caller == 'check') {
1.537     raeburn  9717:                     if (index == 'all') {
                   9718:                         picknumtext.innerHTML = '';
                   9719:                         if (caller == 'link') {
                   9720:                             propagateState(targetform,'rpicknum');
                   9721:                         }
                   9722:                     } else {
                   9723:                         pickitem.checked=false;
1.538     raeburn  9724:                         checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  9725:                     }
1.478     raeburn  9726:                 }
                   9727:                 return;
                   9728:             }
                   9729:         }
                   9730:     } else {
1.537     raeburn  9731:         picknumitem.value = '';
                   9732:         picknumtext.innerHTML = '';
                   9733:         if (index == 'all') {
                   9734:             if (caller == 'link') {
                   9735:                 propagateState(targetform,'rpicknum');
                   9736:             }
                   9737:         } else {
1.538     raeburn  9738:             checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  9739:         }
                   9740:     }
                   9741: }
                   9742: 
                   9743: function propagateState(form,param) {
                   9744:     if (document.getElementById(param+'all')) {
                   9745:         var setcheck = 0;
                   9746:         var rpick = 0;
                   9747:         if (param == 'rpicknum') {
                   9748:             if (document.getElementById('randompickall')) {
                   9749:                 if (document.getElementById('randompickall').checked) {
                   9750:                     if (document.getElementById('rpicknumall')) {
                   9751:                         rpick = document.getElementById('rpicknumall').value;
                   9752:                     }
                   9753:                 }
                   9754:             }
                   9755:         } else {
                   9756:             if (document.getElementById(param+'all').checked) {
                   9757:                 setcheck = 1;
                   9758:             }
                   9759:         }
1.538     raeburn  9760:         var allidxlist;
                   9761:         if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   9762:             if (document.getElementById('all'+param+'idx')) {
                   9763:                 allidxlist = document.getElementById('all'+param+'idx').value;
                   9764:             }
                   9765:             var actions = new Array ('remove','cut','copy');
                   9766:             for (var i=0; i<actions.length; i++) {
                   9767:                 if (actions[i] != param) {
                   9768:                     if (document.getElementById(actions[i]+'all')) {
                   9769:                         document.getElementById(actions[i]+'all').checked = false; 
                   9770:                     }
                   9771:                 }
                   9772:             }
                   9773:         }
1.537     raeburn  9774:         if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538     raeburn  9775:             allidxlist = form.allidx.value;
                   9776:         }
                   9777:         if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
                   9778:             allidxlist = form.allmapidx.value;
                   9779:         }
                   9780:         if ((allidxlist != '') && (allidxlist != null)) {
                   9781:             var allidxs = allidxlist.split(',');
                   9782:             if (allidxs.length > 1) {
                   9783:                 for (var i=0; i<allidxs.length; i++) {
                   9784:                     if (document.getElementById(param+'_'+allidxs[i])) {
                   9785:                         if (param == 'rpicknum') {
                   9786:                             if (document.getElementById('randompick_'+allidxs[i])) {
                   9787:                                 if (document.getElementById('randompick_'+allidxs[i]).checked) {
                   9788:                                     document.getElementById(param+'_'+allidxs[i]).value = rpick;
                   9789:                                     if (rpick > 0) {
                   9790:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ':&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
                   9791:                                     } else {
                   9792:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   9793:                                     }
                   9794:                                 }
                   9795:                             }
                   9796:                         } else {
1.537     raeburn  9797:                             if (setcheck == 1) {
                   9798:                                 document.getElementById(param+'_'+allidxs[i]).checked = true;
                   9799:                             } else {
                   9800:                                 document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538     raeburn  9801:                                 if (param == 'randompick') {
                   9802:                                     document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   9803:                                 }
1.537     raeburn  9804:                             }
                   9805:                         }
                   9806:                     }
                   9807:                 }
1.538     raeburn  9808:                 if (setcheck == 1) {
                   9809:                     if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   9810:                         var actions = new Array('copy','cut','remove');
                   9811:                         for (var i=0; i<actions.length; i++) {
                   9812:                             var otheractions;
                   9813:                             var otheridxs;
                   9814:                             if (actions[i] === param) {
                   9815:                                 continue;
                   9816:                             } else {
                   9817:                                 if (document.getElementById('all'+actions[i]+'idx')) {
                   9818:                                     otheractions = document.getElementById('all'+actions[i]+'idx').value;
                   9819:                                     otheridxs = otheractions.split(',');
                   9820:                                     if (otheridxs.length > 1) {
                   9821:                                         for (var j=0; j<otheridxs.length; j++) {
                   9822:                                             if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
                   9823:                                                 document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
                   9824:                                             }
1.537     raeburn  9825:                                         }
                   9826:                                     }
                   9827:                                 }
1.538     raeburn  9828:                             }
                   9829:                         } 
                   9830:                     }
                   9831:                 }
                   9832:             }
                   9833:         }
                   9834:     }
                   9835:     return;
                   9836: }
                   9837: 
1.603     raeburn  9838: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611     raeburn  9839:     var canedit = '$canedit';
                   9840:     if (canedit == '') {
                   9841:         alert("$js_lt{'edri'}");
                   9842:         return;
                   9843:     }
1.539     raeburn  9844:     var dosettings;
                   9845:     var doaction;
1.538     raeburn  9846:     var control = document.togglemultsettings;
                   9847:     if (context == 'actions') {
                   9848:         control = document.togglemultactions;
1.539     raeburn  9849:         doaction = 1; 
                   9850:     } else {
                   9851:         dosettings = 1;
1.538     raeburn  9852:     }
1.539     raeburn  9853:     if (control) {
                   9854:         if (control.showmultpick.length) {
                   9855:             for (var i=0; i<control.showmultpick.length; i++) {
                   9856:                 if (control.showmultpick[i].checked) {
                   9857:                     if (control.showmultpick[i].value == 1) {
                   9858:                         if (context == 'settings') {
                   9859:                             dosettings = 0;
                   9860:                         } else {
                   9861:                             doaction = 0;
1.538     raeburn  9862:                         }
                   9863:                     }
                   9864:                 }
1.537     raeburn  9865:             }
                   9866:         }
1.539     raeburn  9867:     }
                   9868:     if (context == 'settings') {
                   9869:         if (dosettings == 1) {
1.538     raeburn  9870:             targetform.changeparms.value=param;
                   9871:             targetform.submit();
                   9872:         }
1.537     raeburn  9873:     }
1.539     raeburn  9874:     if (context == 'actions') {
                   9875:         if (doaction == 1) {
                   9876:             targetform.cmd.value=param+'_'+index;
                   9877:             targetform.folderpath.value=folderpath;
                   9878:             targetform.markcopy.value=idx+':'+param;
                   9879:             targetform.copyfolder.value=folder+'.'+container;
                   9880:             if (param == 'remove') {
1.603     raeburn  9881:                 var doremove = 0;
                   9882:                 if (skip_confirm) {
                   9883:                     if (confirm_removal) {
                   9884:                         if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
                   9885:                             doremove = 1;
                   9886:                         }
                   9887:                     } else {
                   9888:                         doremove = 1;
                   9889:                     }
                   9890:                 } else {
                   9891:                     if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
                   9892:                         doremove = 1;
                   9893:                     }
                   9894:                 }
                   9895:                 if (doremove) {
1.539     raeburn  9896:                     targetform.markcopy.value='';
                   9897:                     targetform.copyfolder.value='';
                   9898:                     targetform.submit();
                   9899:                 }
                   9900:             }
                   9901:             if (param == 'cut') {
1.594     damieng  9902:                 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  9903:                     targetform.submit();
                   9904:                     return;
                   9905:                 }
                   9906:             }
                   9907:             if (param == 'copy') {
                   9908:                 targetform.submit();
                   9909:                 return;
                   9910:             }
                   9911:             targetform.markcopy.value='';
                   9912:             targetform.copyfolder.value='';
                   9913:             targetform.cmd.value='';
                   9914:             targetform.folderpath.value='';
                   9915:             return;
                   9916:         } else {
                   9917:             if (document.getElementById(param+'_'+idx)) {
                   9918:                 item = document.getElementById(param+'_'+idx);
                   9919:                 if (item.type == 'checkbox') {
                   9920:                     if (item.checked) {
                   9921:                         item.checked = false;
                   9922:                     } else {
                   9923:                         item.checked = true;
                   9924:                         singleCheck(item,idx,param);
                   9925:                     }
                   9926:                 }
                   9927:             }
                   9928:         }
                   9929:     }
1.537     raeburn  9930:     return;
                   9931: }
                   9932: 
1.538     raeburn  9933: function singleCheck(caller,idx,action) {
                   9934:     actions = new Array('cut','copy','remove');
                   9935:     if (caller.checked) {
                   9936:         for (var i=0; i<actions.length; i++) {
                   9937:             if (actions[i] != action) {
                   9938:                 if (document.getElementById(actions[i]+'_'+idx)) {
                   9939:                     if (document.getElementById(actions[i]+'_'+idx).checked) {
                   9940:                         document.getElementById(actions[i]+'_'+idx).checked = false;
                   9941:                     }
1.537     raeburn  9942:                 }
                   9943:             }
                   9944:         }
1.478     raeburn  9945:     }
1.537     raeburn  9946:     return;
1.478     raeburn  9947: }
                   9948: 
1.334     muellerd 9949: function unselectInactive(nav) {
1.335     ehlerst  9950: currentNav = document.getElementById(nav);
                   9951: currentLis = currentNav.getElementsByTagName('LI');
                   9952: for (i = 0; i < currentLis.length; i++) {
1.472     raeburn  9953:         if (currentLis[i].className == 'goback') {
                   9954:             currentLis[i].className = 'goback';
                   9955:         } else {
                   9956: 	    if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374     tempelho 9957: 		currentLis[i].className = 'right';
1.472     raeburn  9958: 	    } else {
1.374     tempelho 9959: 		currentLis[i].className = 'i';
1.472     raeburn  9960: 	    }
                   9961:         }
1.335     ehlerst  9962: }
1.332     tempelho 9963: }
                   9964: 
1.334     muellerd 9965: function hideAll(current, nav, data) {
1.335     ehlerst  9966: unselectInactive(nav);
1.570     raeburn  9967: if (current) { 
                   9968:     if (current.className == 'right'){
                   9969:         current.className = 'right active'
                   9970:     } else {
                   9971:         current.className = 'active';
                   9972:     }
1.374     tempelho 9973: }
1.335     ehlerst  9974: currentData = document.getElementById(data);
                   9975: currentDivs = currentData.getElementsByTagName('DIV');
                   9976: for (i = 0; i < currentDivs.length; i++) {
                   9977: 	if(currentDivs[i].className == 'LC_ContentBox'){
1.333     muellerd 9978: 		currentDivs[i].style.display = 'none';
1.330     tempelho 9979: 	}
                   9980: }
1.335     ehlerst  9981: }
1.330     tempelho 9982: 
1.374     tempelho 9983: function openTabs(pageId) {
                   9984: 	tabnav = document.getElementById(pageId).getElementsByTagName('UL');	
1.383     tempelho 9985: 	if(tabnav.length > 2 ){
1.389     tempelho 9986: 		currentNav = document.getElementById(tabnav[1].id);
1.374     tempelho 9987: 		currentLis = currentNav.getElementsByTagName('LI');
                   9988: 		for(i = 0; i< currentLis.length; i++){
                   9989: 			if(currentLis[i].className == 'active') {
1.375     tempelho 9990: 				funcString = currentLis[i].onclick.toString();
                   9991: 				tab = funcString.split('"');
1.420     onken    9992:                                 if(tab.length < 2) {
                   9993:                                    tab = funcString.split("'");
                   9994:                                 }
1.375     tempelho 9995: 				currentData = document.getElementById(tab[1]);
                   9996:         			currentData.style.display = 'block';
1.374     tempelho 9997: 			}	
                   9998: 		}
                   9999: 	}
                   10000: }
                   10001: 
1.334     muellerd 10002: function showPage(current, pageId, nav, data) {
1.570     raeburn  10003:         currstate = current.className;
1.334     muellerd 10004: 	hideAll(current, nav, data);
1.375     tempelho 10005: 	openTabs(pageId);
1.334     muellerd 10006: 	unselectInactive(nav);
1.570     raeburn  10007:         if ((currstate == 'active') || (currstate == 'right active')) {
                   10008:             if (currstate == 'active') {
                   10009: 	        current.className = '';
                   10010:             } else {
                   10011:                 current.className = 'right';
                   10012:             }
                   10013:             activeTab = ''; 
1.656     raeburn  10014:             toggleExternal();
1.570     raeburn  10015:             toggleUpload();
                   10016:             toggleMap();
1.606     raeburn  10017:             toggleCrsRes();
                   10018:             toggleImportCrsres();
1.570     raeburn  10019:             resize_scrollbox('contentscroll','1','0');
                   10020:             return;
                   10021:         } else {
                   10022:             current.className = 'active';
                   10023:         }
1.330     tempelho 10024: 	currentData = document.getElementById(pageId);
                   10025: 	currentData.style.display = 'block';
1.458     raeburn  10026:         activeTab = pageId;
1.656     raeburn  10027:         toggleExternal();
1.501     raeburn  10028:         toggleUpload();
1.503     raeburn  10029:         toggleMap();
1.606     raeburn  10030:         toggleCrsRes();
                   10031:         toggleImportCrsres();
1.433     raeburn  10032:         if (nav == 'mainnav') {
                   10033:             var storedpath = "$docs_folderpath";
1.434     raeburn  10034:             var storedpage = "$main_container_page";
1.433     raeburn  10035:             var reg = new RegExp("^supplemental");
                   10036:             if (pageId == 'mainCourseDocuments') {
1.434     raeburn  10037:                 if (storedpage == 1) {
                   10038:                     document.simpleedit.folderpath.value = '';
                   10039:                     document.uploaddocument.folderpath.value = '';
                   10040:                 } else {
                   10041:                     if (reg.test(storedpath)) {
                   10042:                         document.simpleedit.folderpath.value = '$toplevelmain';
                   10043:                         document.uploaddocument.folderpath.value = '$toplevelmain';
                   10044:                         document.newext.folderpath.value = '$toplevelmain';
                   10045:                     } else {
                   10046:                         document.simpleedit.folderpath.value = storedpath;
                   10047:                         document.uploaddocument.folderpath.value = storedpath;
                   10048:                         document.newext.folderpath.value = storedpath;
                   10049:                     }
1.433     raeburn  10050:                 }
                   10051:             } else {
1.434     raeburn  10052:                 if (reg.test(storedpath)) {
                   10053:                     document.simpleedit.folderpath.value = storedpath;
                   10054:                     document.supuploaddocument.folderpath.value = storedpath;
                   10055:                     document.supnewext.folderpath.value = storedpath;
                   10056:                 } else {
1.433     raeburn  10057:                     document.simpleedit.folderpath.value = '$toplevelsupp';
                   10058:                     document.supuploaddocument.folderpath.value = '$toplevelsupp';
                   10059:                     document.supnewext.folderpath.value = '$toplevelsupp';
                   10060:                 }
                   10061:             }
                   10062:         }
1.485     raeburn  10063:         resize_scrollbox('contentscroll','1','0');
1.330     tempelho 10064: 	return false;
                   10065: }
1.329     droeschl 10066: 
1.472     raeburn  10067: function toContents(jumpto) {
                   10068:     var newurl = '$backtourl';
1.525     raeburn  10069:     if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472     raeburn  10070:         newurl = newurl+'?postdata='+jumpto;
                   10071:     }
                   10072:     location.href=newurl;
                   10073: }
                   10074: 
1.538     raeburn  10075: function togglePick(caller,value) {
                   10076:     var disp = 'none';
                   10077:     if (document.getElementById('multi'+caller)) {
                   10078:         var curr = document.getElementById('multi'+caller).style.display;
                   10079:         if (value == 1) {
                   10080:             disp='block';
                   10081:         }
                   10082:         if (curr == disp) {
                   10083:             return; 
                   10084:         }
                   10085:         document.getElementById('multi'+caller).style.display=disp;
                   10086:         if (value == 1) {
1.594     damieng  10087:             document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>'; 
1.538     raeburn  10088:         } else {
                   10089:             document.getElementById('more'+caller).innerHTML = '';
                   10090:         }
                   10091:         if (caller == 'actions') { 
                   10092:             setClass(value);
                   10093:             setBoxes(value);
                   10094:         }
                   10095:     }
                   10096:     var showButton = multiSettings();
                   10097:     if (showButton != 1) {
                   10098:         showButton = multiActions();
                   10099:     }
                   10100:     if (document.getElementById('multisave')) {
                   10101:         if (showButton == 1) {
                   10102:             document.getElementById('multisave').style.display='block';
                   10103:         } else {
                   10104:             document.getElementById('multisave').style.display='none';
                   10105:         }
                   10106:     }
                   10107:     resize_scrollbox('contentscroll','1','1');
                   10108:     return;
                   10109: }
                   10110: 
                   10111: function toggleCheckUncheck(caller,more) {
                   10112:     if (more == 1) {
1.594     damieng  10113:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538     raeburn  10114:         document.getElementById('allfields'+caller).style.display='block';
                   10115:     } else {
1.594     damieng  10116:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538     raeburn  10117:         document.getElementById('allfields'+caller).style.display='none';
                   10118:     }
                   10119:     resize_scrollbox('contentscroll','1','1');
                   10120: }
                   10121: 
                   10122: function multiSettings() {
                   10123:     var inuse = 0;
                   10124:     var settingsform = document.togglemultsettings;
                   10125:     if (settingsform.showmultpick.length > 1) {
                   10126:         for (var i=0; i<settingsform.showmultpick.length; i++) {
                   10127:             if (settingsform.showmultpick[i].checked) {
                   10128:                 if (settingsform.showmultpick[i].value == 1) {
                   10129:                     inuse = 1;  
                   10130:                 }
                   10131:             }
                   10132:         }
                   10133:     }
                   10134:     return inuse;
                   10135: }
                   10136: 
                   10137: function multiActions() {
                   10138:     var inuse = 0;
                   10139:     var actionsform = document.togglemultactions;
                   10140:     if (actionsform.showmultpick.length > 1) {
                   10141:         for (var i=0; i<actionsform.showmultpick.length; i++) {
                   10142:             if (actionsform.showmultpick[i].checked) {
                   10143:                 if (actionsform.showmultpick[i].value == 1) {
                   10144:                     inuse = 1;
                   10145:                 }
                   10146:             }
                   10147:         }
                   10148:     }
                   10149:     return inuse;
                   10150: } 
                   10151: 
                   10152: function checkSubmits() {
                   10153:     var numchanges = 0;
                   10154:     var form = document.saveactions;
                   10155:     var doactions = multiActions();
1.542     raeburn  10156:     var cutwarnings = 0;
                   10157:     var remwarnings = 0;
1.603     raeburn  10158:     var removalinfo = 0;
1.538     raeburn  10159:     if (doactions == 1) {
                   10160:         var remidxlist = document.cumulativeactions.allremoveidx.value;
                   10161:         if ((remidxlist != '') && (remidxlist != null)) {
                   10162:             var remidxs = remidxlist.split(',');
                   10163:             for (var i=0; i<remidxs.length; i++) {
                   10164:                 if (document.getElementById('remove_'+remidxs[i])) {
                   10165:                     if (document.getElementById('remove_'+remidxs[i]).checked) {
                   10166:                         form.multiremove.value += remidxs[i]+',';
                   10167:                         numchanges ++;
1.542     raeburn  10168:                         if (document.getElementById('skip_remove_'+remidxs[i])) {
                   10169:                             if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
                   10170:                                 remwarnings ++;
                   10171:                             }
                   10172:                         }
1.603     raeburn  10173:                         if (document.getElementById('confirm_removal_'+remidxs[i])) {
                   10174:                             if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
                   10175:                                 removalinfo ++;
                   10176:                             }
                   10177:                         }
1.537     raeburn  10178:                     }
                   10179:                 }
1.538     raeburn  10180:             }
                   10181:         }
                   10182:         var cutidxlist = document.cumulativeactions.allcutidx.value;
                   10183:         if ((cutidxlist != '') && (cutidxlist != null)) {
                   10184:             var cutidxs = cutidxlist.split(',');
                   10185:             for (var i=0; i<cutidxs.length; i++) {
                   10186:                 if (document.getElementById('cut_'+cutidxs[i])) {
                   10187:                     if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
                   10188:                         form.multicut.value += cutidxs[i]+',';
                   10189:                         numchanges ++;
1.542     raeburn  10190:                         if (document.getElementById('skip_cut_'+cutidxs[i])) {
                   10191:                             if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
                   10192:                                 cutwarnings ++;
                   10193:                             }
                   10194:                         }
1.537     raeburn  10195:                     }
                   10196:                 }
                   10197:             }
                   10198:         }
1.538     raeburn  10199:         var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   10200:         if ((copyidxlist != '') && (copyidxlist != null)) {
                   10201:             var copyidxs = copyidxlist.split(',');
                   10202:             for (var i=0; i<copyidxs.length; i++) {
                   10203:                 if (document.getElementById('copy_'+copyidxs[i])) {
                   10204:                     if (document.getElementById('copy_'+copyidxs[i]).checked) {
                   10205:                         form.multicopy.value += copyidxs[i]+',';
                   10206:                         numchanges ++;
                   10207:                     }
                   10208:                 }
                   10209:             }
                   10210:         }
                   10211:         if (numchanges > 0) {
                   10212:             form.multichange.value = numchanges;
                   10213:         }
1.537     raeburn  10214:     }
1.538     raeburn  10215:     var dosettings = multiSettings();
1.543     raeburn  10216:     var haschanges = 0;
1.538     raeburn  10217:     if (dosettings == 1) {
                   10218:         form.allencrypturl.value = '';
                   10219:         form.allhiddenresource.value = '';
1.543     raeburn  10220:         form.changeparms.value = 'all';
                   10221:         var patt=new RegExp(",\$");
1.538     raeburn  10222:         var allidxlist = document.cumulativesettings.allidx.value;
                   10223:         if ((allidxlist != '') && (allidxlist != null)) {
                   10224:             var allidxs = allidxlist.split(',');
                   10225:             if (allidxs.length > 1) {
                   10226:                 for (var i=0; i<allidxs.length; i++) {
                   10227:                     if (document.getElementById('hiddenresource_'+allidxs[i])) {
                   10228:                         if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
                   10229:                             form.allhiddenresource.value += allidxs[i]+',';
                   10230:                         }
                   10231:                     }
                   10232:                     if (document.getElementById('encrypturl_'+allidxs[i])) {
                   10233:                         if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
                   10234:                             form.allencrypturl.value += allidxs[i]+',';
                   10235:                         }
                   10236:                     }
                   10237:                 }
1.543     raeburn  10238:                 form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
                   10239:                 form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537     raeburn  10240:             }
1.538     raeburn  10241:         }
                   10242:         form.allrandompick.value = '';
                   10243:         form.allrandomorder.value = '';
                   10244:         var allmapidxlist = document.cumulativesettings.allmapidx.value;
                   10245:         if ((allmapidxlist != '') && (allmapidxlist != null)) {
                   10246:             var allmapidxs = allmapidxlist.split(',');
                   10247:             for (var i=0; i<allmapidxs.length; i++) {
                   10248:                 var randompick = document.getElementById('randompick_'+allmapidxs[i]);
                   10249:                 var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
                   10250:                 var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
                   10251:                 if ((randompick.checked) && (rpicknum.value != '')) {
                   10252:                     form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
                   10253:                 }
                   10254:                 if (randorder.checked) {
                   10255:                     form.allrandomorder.value += allmapidxs[i]+',';
                   10256:                 }
1.537     raeburn  10257:             }
1.543     raeburn  10258:             form.allrandompick.value = form.allrandompick.value.replace(patt,"");
                   10259:             form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
                   10260:         }
                   10261:         if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
                   10262:             haschanges = 1;
                   10263:         }
                   10264:         if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
                   10265:             haschanges = 1;
                   10266:         }
                   10267:         if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
                   10268:             haschanges = 1;
                   10269:         }
                   10270:         if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
                   10271:             haschanges = 1;
1.537     raeburn  10272:         }
                   10273:     }
1.543     raeburn  10274:     if (doactions == 1) {
1.542     raeburn  10275:         if (numchanges > 0) {
1.603     raeburn  10276:             if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542     raeburn  10277:                 if (remwarnings > 0) {
1.594     damieng  10278:                     if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542     raeburn  10279:                         return false;
                   10280:                     }
                   10281:                 }
1.603     raeburn  10282:                 if (removalinfo > 0) {
                   10283:                     if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
                   10284:                         return false;
                   10285:                     }
                   10286:                 }
1.542     raeburn  10287:                 if (cutwarnings > 0) {
1.594     damieng  10288:                     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  10289:                         return false;
                   10290:                     }
                   10291:                 }
                   10292:             }
                   10293:             form.submit();
                   10294:             return true;
1.543     raeburn  10295:         }
                   10296:     }
                   10297:     if (dosettings == 1) {
                   10298:         if (haschanges == 1) {
1.542     raeburn  10299:             form.submit();
                   10300:             return true;
                   10301:         }
1.543     raeburn  10302:     }
                   10303:     if ((dosettings == 1) && (doactions == 1)) {
1.594     damieng  10304:         alert("$js_lt{'noor'}");
1.543     raeburn  10305:     } else {
                   10306:         if (dosettings == 1) {
1.594     damieng  10307:             alert("$js_lt{'noch'}");
1.543     raeburn  10308:         } else {
1.594     damieng  10309:             alert("$js_lt{'noac'}");
1.543     raeburn  10310:         }
                   10311:     }
1.538     raeburn  10312:     return false;
                   10313: }
                   10314: 
                   10315: function setClass(value) {
                   10316:     var cutclass = 'LC_docs_cut';
                   10317:     var copyclass = 'LC_docs_copy';
                   10318:     var removeclass = 'LC_docs_remove';
                   10319:     var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
                   10320:     var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
                   10321:     var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
                   10322:     var links = document.getElementsByTagName('a');
                   10323:     for (var i=0; i<links.length; i++) {
                   10324:         var classes = links[i].className;
                   10325:         if (cutreg.test(classes)) {
                   10326:             links[i].className = cutclass;
                   10327:             if (value == 1) {
                   10328:                 links[i].className += " LC_menubuttons_link";
                   10329:             }
                   10330:         } else {
                   10331:             if (copyreg.test(classes)) {
                   10332:                 links[i].className = copyclass;
                   10333:                 if (value == 1) {
                   10334:                     links[i].className += " LC_menubuttons_link";
                   10335:                 } 
                   10336:             } else {
                   10337:                 if (removereg.test(classes)) {
                   10338:                     links[i].className = removeclass;
                   10339:                     if (value == 1) {
                   10340:                         links[i].className += " LC_menubuttons_link";
                   10341:                     }
                   10342:                 }
                   10343:             }
                   10344:         }
                   10345:     }
                   10346:     return;
1.537     raeburn  10347: }
                   10348: 
1.538     raeburn  10349: function setBoxes(value) {
                   10350:     var remidxlist = document.cumulativeactions.allremoveidx.value;
                   10351:     if ((remidxlist != '') && (remidxlist != null)) {
                   10352:         var remidxs = remidxlist.split(',');
                   10353:         for (var i=0; i<remidxs.length; i++) {
                   10354:             if (document.getElementById('remove_'+remidxs[i])) {
                   10355:                 var item = document.getElementById('remove_'+remidxs[i]);
                   10356:                 if (value == 1) {
                   10357:                     item.className = 'LC_docs_remove';
                   10358:                 } else {
                   10359:                     item.className = 'LC_hidden';
                   10360:                 }
                   10361:             }
                   10362:         }
                   10363:     }
                   10364:     var cutidxlist = document.cumulativeactions.allcutidx.value;
                   10365:     if ((cutidxlist != '') && (cutidxlist != null)) {
                   10366:         var cutidxs = cutidxlist.split(',');
                   10367:         for (var i=0; i<cutidxs.length; i++) {
                   10368:             if (document.getElementById('cut_'+cutidxs[i])) {
                   10369:                 var item = document.getElementById('cut_'+cutidxs[i]);
                   10370:                 if (value == 1) {
                   10371:                     item.className = 'LC_docs_cut';
                   10372:                 } else {
                   10373:                     item.className = 'LC_hidden';
                   10374:                 }
                   10375:             }
1.537     raeburn  10376:         }
                   10377:     }
1.538     raeburn  10378:     var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   10379:     if ((copyidxlist != '') && (copyidxlist != null)) {
                   10380:         var copyidxs = copyidxlist.split(',');
                   10381:         for (var i=0; i<copyidxs.length; i++) {
                   10382:             if (document.getElementById('copy_'+copyidxs[i])) {
                   10383:                 var item = document.getElementById('copy_'+copyidxs[i]);
                   10384:                 if (value == 1) {
                   10385:                     item.className = 'LC_docs_copy';
                   10386:                 } else {
                   10387:                     item.className = 'LC_hidden';
                   10388:                 }
                   10389:             }
1.537     raeburn  10390:         }
                   10391:     }
                   10392:     return;
                   10393: }
                   10394: 
1.606     raeburn  10395: function validImportCrsRes() {
                   10396:     var path =  document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
                   10397:     var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
                   10398:     if ((fname == '') || (fname == null)) {
                   10399:         alert("$js_lt{'nofi'}");
                   10400:         return false;
                   10401:     }
                   10402:     var url = '/res/$coursedom/$coursenum/';
                   10403:     if (path && path != '/') {
                   10404:         url += path+'/';
                   10405:     }
                   10406:     if (fname != '') {
                   10407:         url += fname;
                   10408:     }
                   10409:     var title = document.crsresimportform.crsrestitle.value;
1.676     raeburn  10410:     document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606     raeburn  10411:     return true;
                   10412: }
                   10413: 
                   10414: function validateNewRes(caller) {
                   10415:     if (caller == 'single') {
                   10416:         var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value; 
                   10417:         var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
                   10418:         var resname = document.courseresform.newresourcename.value;
                   10419:     }
                   10420: }
                   10421: 
1.611     raeburn  10422: ENDSCRIPT
1.329     droeschl 10423: }
1.457     raeburn  10424: 
1.483     raeburn  10425: sub history_tab_js {
                   10426:     return <<"ENDHIST";
                   10427: function toggleHistoryDisp(choice) {
                   10428:     document.docslogform.docslog.value = choice;
                   10429:     document.docslogform.submit();
                   10430:     return;
                   10431: }
                   10432: 
                   10433: ENDHIST
                   10434: }
                   10435: 
1.484     raeburn  10436: sub inject_data_js {
                   10437:     return <<ENDINJECT;
                   10438: 
                   10439: function injectData(current, hiddenField, name, value) {
                   10440:         currentElement = document.getElementById(hiddenField);
                   10441:         currentElement.name = name;
                   10442:         currentElement.value = value;
                   10443:         current.submit();
                   10444: }
                   10445: 
                   10446: ENDINJECT
                   10447: }
                   10448: 
                   10449: sub dump_switchserver_js {
                   10450:     my @hosts = @_;
1.594     damieng  10451:     my %js_lt = &Apache::lonlocal::texthash(
1.574     raeburn  10452:         dump => 'Copying content to Authoring Space requires switching server.',
1.484     raeburn  10453:         swit => 'Switch server?',
1.594     damieng  10454:     );
                   10455:     my %html_js_lt = &Apache::lonlocal::texthash(
                   10456:         swit => 'Switch server?',
1.709     raeburn  10457:         duco => 'Copying uploaded content to Authoring Space',
1.484     raeburn  10458:         yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
                   10459:         chos => 'Choose server',
                   10460:     );
1.594     damieng  10461:     &js_escape(\%js_lt);
                   10462:     &html_escape(\%html_js_lt);
                   10463:     &js_escape(\%html_js_lt);
1.484     raeburn  10464:     my $role = $env{'request.role'};
                   10465:     my $js = <<"ENDSWJS";
                   10466: <script type="text/javascript">
                   10467: function write_switchserver() {
                   10468:     var server;
                   10469:     if (document.setserver.posshosts.length > 0) {
                   10470:         for (var i=0; i<document.setserver.posshosts.length; i++) {
                   10471:             if (document.setserver.posshosts[i].checked) {
                   10472:                 server = document.setserver.posshosts[i].value;
                   10473:             }
                   10474:        }
                   10475:        opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
                   10476:     }
                   10477:     window.close();
                   10478: }
                   10479: </script>
                   10480: 
                   10481: ENDSWJS
                   10482: 
                   10483:     my $startpage = &Apache::loncommon::start_page('Choose server',$js,
                   10484:                                                    {'only_body' => 1,
                   10485:                                                     'js_ready'  => 1,});
                   10486:     my $endpage = &Apache::loncommon::end_page({'js_ready'  => 1});
                   10487: 
                   10488:     my $hostpicker;
                   10489:     my $count = 0;
                   10490:     foreach my $host (sort(@hosts)) {
                   10491:         my $checked;
                   10492:         if ($count == 0) {
                   10493:             $checked = ' checked="checked"';
                   10494:         }
                   10495:         $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
                   10496:                        $host.'"'.$checked.' />'.$host.'</label>&nbsp;&nbsp;';
                   10497:         $count++;
                   10498:     }
                   10499:     
                   10500:     return <<"ENDSWITCHJS";
                   10501: 
                   10502: function dump_needs_switchserver(url) {
                   10503:     if (url!='' && url!= null) {
1.594     damieng  10504:         if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484     raeburn  10505:             go(url);
                   10506:         }
                   10507:     }
                   10508:     return;
                   10509: }
                   10510: 
                   10511: function choose_switchserver_window() {
                   10512:     newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
                   10513:     newWindow.document.open();
                   10514:     newWindow.document.writeln('$startpage');
1.594     damieng  10515:     newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
                   10516:        '<p>$html_js_lt{'yone'}<\\/p>\\n'+
                   10517:        '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484     raeburn  10518:        '<form name="setserver" method="post" action="" \\/>\\n'+
                   10519:        '$hostpicker\\n'+
                   10520:        '<br \\/><br \\/>\\n'+
1.594     damieng  10521:        '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484     raeburn  10522:        'onclick="write_switchserver();" \\/>\\n'+
                   10523:        '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
                   10524:     newWindow.document.writeln('$endpage');
                   10525:     newWindow.document.close();
                   10526:     newWindow.focus();
                   10527: }
                   10528: 
                   10529: ENDSWITCHJS
                   10530: }
                   10531: 
                   10532: sub makedocslogform {
                   10533:     my ($formelems,$docslog) = @_;
                   10534:     return <<"LOGSFORM";
                   10535:  <form action="/adm/coursedocs" method="post" name="docslogform">
                   10536:    <input type="hidden" name="docslog" value="$docslog" />
                   10537:    $formelems
                   10538:  </form>
                   10539: LOGSFORM
                   10540: }
                   10541: 
                   10542: sub makesimpleeditform {
                   10543:     my ($formelems) = @_;
                   10544:     return <<"SIMPFORM";
                   10545:  <form name="simpleedit" method="post" action="/adm/coursedocs">
                   10546:    <input type="hidden" name="importdetail" value="" />
                   10547:    $formelems
                   10548:  </form>
                   10549: SIMPFORM
                   10550: }
                   10551: 
1.606     raeburn  10552: sub makenewproblem {
                   10553:     my ($r,$coursedom,$coursenum) = @_;
                   10554: # Creating a new problem
                   10555:     my ($redirect,$error);
                   10556:     if ($env{'form.authorrole'}) {
                   10557:         my ($newsubdir,$filename);
                   10558:         if ($env{'form.newsubdir'}) {
                   10559:             if ($env{'form.newsubdirname'} ne '') {
                   10560:                 $newsubdir = $env{'form.newsubdirname'};
1.654     raeburn  10561:             }
1.606     raeburn  10562:         }
                   10563:         if ($env{'form.newresourcename'}) {
                   10564:             $filename = $env{'form.newresourcename'};
                   10565:             $filename =~ s/\.(\d+)(\.\w+)$/$2/;
                   10566:             $filename =~ s/`//g;
                   10567:             $filename =~ s{/\.\./}{_}g;
                   10568:             $filename =~ s/\.+/./g;
                   10569:             $filename =~ s{/+}{_}g;
                   10570:             if ($filename ne '') {
                   10571:                 my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
                   10572:                 if (($ext) && ($ext ne '.problem')) {
                   10573:                     $filename = $name.'.problem';
                   10574:                 } elsif ($ext eq '') {
                   10575:                     $filename .= '.problem';
                   10576:                 }
                   10577:                 my $docroot = $r->dir_config('lonDocRoot');
                   10578:                 my @ids=&Apache::lonnet::current_machine_ids();
                   10579:                 if ($env{'form.authorrole'} eq 'author') {
                   10580:                     if ($env{'user.author'}) {
                   10581:                         if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
                   10582:                             my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
                   10583:                             my $path = $docroot.$url;
                   10584:                             my $subdir = $env{'form.authorpath'};
                   10585:                             $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   10586:                         }
                   10587:                     }
                   10588:                 } elsif ($env{'form.authorrole'} eq 'course') {
                   10589:                     my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   10590:                     if ($chome && grep(/^\Q$chome\E$/,@ids)) {
                   10591:                         my $url = "/priv/$coursedom/$coursenum";
                   10592:                         my $path=$docroot.$url;
                   10593:                         my $subdir = $env{'form.authorpath'};
                   10594:                         $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   10595:                         if ($redirect) {
                   10596:                             my $rightsfile = 'default.rights';
                   10597:                             my $sourcerights = "$path/$rightsfile";
1.709     raeburn  10598:                             &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606     raeburn  10599:                             my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654     raeburn  10600:                             if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
                   10601:                                 if (!-e "$docroot/res/$coursedom") {
                   10602:                                     mkdir("$docroot/res/$coursedom",0755);
1.606     raeburn  10603:                                 }
1.654     raeburn  10604:                                 if (!-e "$docroot/res/$coursedom/$coursenum") {
                   10605:                                     mkdir("$docroot/res/$coursedom/$coursenum",0755);
                   10606:                                 }
                   10607:                                 if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
                   10608:                                     my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   10609:                                     my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606     raeburn  10610:                                 }
                   10611:                             }
1.654     raeburn  10612:                             my $source = $docroot.$redirect;
                   10613:                             if (!-e "$source.meta") {
                   10614:                                 my $cid = $coursedom.'_'.$coursenum;
                   10615:                                 my $now = time;
                   10616:                                 if (open(my $fh,">$source.meta")) {
                   10617:                                     my $author=$env{'environment.firstname'}.' '.
                   10618:                                                $env{'environment.middlename'}.' '.
                   10619:                                                $env{'environment.lastname'}.' '.
                   10620:                                                $env{'environment.generation'};
                   10621:                                     $author =~ s/\s+$//;
                   10622:                                     my $title = $env{'form.newresourcetitle'};
                   10623:                                     $title =~ s/^\s+|\s+$//g;
                   10624:                                     print $fh <<END;
1.606     raeburn  10625: 
                   10626: <abstract></abstract>
                   10627: <author>$author</author>
                   10628: <authorspace>$coursenum:$coursedom</authorspace>
                   10629: <copyright>custom</copyright>
                   10630: <creationdate>$now</creationdate>
                   10631: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
                   10632: <dependencies></dependencies>
                   10633: <domain>$coursedom</domain>
                   10634: <highestgradelevel>0</highestgradelevel>
                   10635: <keywords></keywords>
                   10636: <language>notset </language>
                   10637: <lastrevisiondate>$now</lastrevisiondate>
                   10638: <lowestgradelevel>0</lowestgradelevel>
                   10639: <mime>problem</mime>
                   10640: <modifyinguser>$coursenum:$coursedom</modifyinguser>
                   10641: <notes></notes>
                   10642: <obsolete></obsolete>
                   10643: <obsoletereplacement></obsoletereplacement>
                   10644: <owner>$coursenum:$coursedom</owner>
                   10645: <sourceavail></sourceavail>
                   10646: <standards></standards>
                   10647: <subject></subject>
                   10648: <title>$title</title>
                   10649: END
1.654     raeburn  10650:                                     close($fh);
1.606     raeburn  10651:                                 }
                   10652:                             }
                   10653:                         }
                   10654:                     }
                   10655:                 } else {
                   10656:                     my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
                   10657:                     my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
                   10658:                     if (grep(/^\Q$rolehome\E$/,@ids)) {
                   10659:                         my $now = time;
                   10660:                         if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
                   10661:                             my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
                   10662:                             if (($start <= $now) && (($end == 0) || ($end >= $now))) { 
                   10663:                                 my $url = "/priv/$audom/$auname";  
                   10664:                                 my $path = $r->dir_config('lonDocRoot').$url;
                   10665:                                 my $subdir = $env{'form.authorpath'};
                   10666:                                 $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   10667:                             }
                   10668:                         }
                   10669:                     }
                   10670:                 }
                   10671:             }
                   10672:         }
                   10673:     }
                   10674:     return ($redirect,$error);
                   10675: }
                   10676: 
                   10677: sub finishnewprob {
1.654     raeburn  10678:     my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607     raeburn  10679:     unless (-d $path) {
                   10680:         unless (mkdir($path,02770)) {
                   10681:             return;
                   10682:         }
                   10683:     }
1.606     raeburn  10684:     my $redirect;
                   10685:     if ($subdir ne '/') {
                   10686:         $subdir = &cleandir($subdir);
                   10687:         if (($subdir ne '') && (-d "$path/$subdir")) {
                   10688:             $path .= "/$subdir";
                   10689:             $url .= "/$subdir";
                   10690:         }
                   10691:     }
                   10692:     my $dest;
                   10693:     if ($newsubdir ne '') {
                   10694:         $newsubdir = &cleandir($newsubdir);
                   10695:     }
                   10696:     if ($newsubdir ne '') {
                   10697:         if (-d "$path/$newsubdir") {
                   10698:             $dest = "$path/$newsubdir/$filename";
                   10699:         } else {
                   10700:             my $dirok;
                   10701:             unless (-e "$path/$newsubdir") {
                   10702:                 if (mkdir("$path/$newsubdir",02770)) {
                   10703:                     if (chmod(02770,"$path/$newsubdir")) {
                   10704:                         $dirok = 1;
                   10705:                     }
                   10706:                 }
                   10707:             }
                   10708:             if ($dirok) {
                   10709:                 $dest = "$path/$newsubdir/$filename";
                   10710:             }
                   10711:         }
                   10712:         if (($dest ne '') && (!-e $dest)) {
                   10713:             $redirect = "$url/$newsubdir/$filename";
                   10714:         }
                   10715:     } else {
                   10716:         $dest = "$path/$filename";
                   10717:         if (($dest ne '') && (!-e $dest)) {
                   10718:             $redirect = "$url/$filename";
                   10719:         }
                   10720:     }
1.654     raeburn  10721:     if ((!-e $dest) && ($context ne 'upload')) {
                   10722:         my $template = $env{'form.template'};
                   10723:         my $copyfrom;
                   10724:         if ($template ne '') {
                   10725:             my %templates;
                   10726:             my @files = &Apache::lonhomework::get_template_list('problem');
                   10727:             foreach my $poss (@files) {
                   10728:                 if (ref($poss) eq 'ARRAY') {
                   10729:                     if ($template eq $poss->[0]) {
                   10730:                         $templates{$template} = 1;
                   10731:                         last;
                   10732:                     }
                   10733:                 }
                   10734:             }
                   10735:             if ($templates{$template}) {
                   10736:                 $copyfrom = $template;
                   10737:             }
                   10738:         }
                   10739:         if ($filename =~ /\.problem$/) {
                   10740:             unless ($copyfrom) {
                   10741:                 $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
                   10742:             }
                   10743:             &File::Copy::copy($copyfrom,$dest);
                   10744:         }
                   10745:     }
1.606     raeburn  10746:     return $redirect;
                   10747: }
                   10748: 
                   10749: sub cleandir {
                   10750:     my ($dir) = @_;
                   10751:     $dir =~ s/^\s+//;
                   10752:     $dir =~ s/\s+$//;
                   10753:     $dir =~ s/\.+//g;
                   10754:     $dir =~ s/[\#\?&%\":]//g;
                   10755:     return $dir;
                   10756: }
                   10757: 
1.329     droeschl 10758: 1;
                   10759: __END__
                   10760: 
                   10761: 
                   10762: =head1 NAME
                   10763: 
                   10764: Apache::londocs.pm
                   10765: 
                   10766: =head1 SYNOPSIS
                   10767: 
                   10768: This is part of the LearningOnline Network with CAPA project
                   10769: described at http://www.lon-capa.org.
                   10770: 
                   10771: =head1 SUBROUTINES
                   10772: 
                   10773: =over
                   10774: 
                   10775: =item %help=()
                   10776: 
                   10777: Available help topics
                   10778: 
                   10779: =item mapread()
                   10780: 
1.344     bisitz   10781: Mapread read maps into LONCAPA::map:: global arrays
1.329     droeschl 10782: @order and @resources, determines status
                   10783: sets @order - pointer to resources in right order
                   10784: sets @resources - array with the resources with correct idx
                   10785: 
                   10786: =item authorhosts()
                   10787: 
                   10788: Return hash with valid author names
                   10789: 
                   10790: =item clean()
                   10791: 
                   10792: =item dumpcourse()
                   10793: 
                   10794:     Actually dump course
                   10795: 
                   10796: =item group_import()
                   10797: 
                   10798:     Imports the given (name, url) resources into the course
                   10799:     coursenum, coursedom, and folder must precede the list
                   10800: 
                   10801: =item breadcrumbs()
                   10802: 
                   10803: =item log_docs()
                   10804: 
                   10805: =item docs_change_log()
                   10806: 
                   10807: =item update_paste_buffer()
                   10808: 
                   10809: =item print_paste_buffer()
                   10810: 
                   10811: =item do_paste_from_buffer()
                   10812: 
1.538     raeburn  10813: =item do_buffer_empty() 
                   10814: 
                   10815: =item clear_from_buffer()
                   10816: 
1.492     raeburn  10817: =item get_newmap_url()
                   10818: 
                   10819: =item dbcopy()
                   10820: 
                   10821: =item uniqueness_check()
                   10822: 
                   10823: =item contained_map_check()
                   10824: 
                   10825: =item url_paste_fixups()
                   10826: 
                   10827: =item apply_fixups()
                   10828: 
                   10829: =item copy_dependencies()
                   10830: 
1.329     droeschl 10831: =item update_parameter()
                   10832: 
                   10833: =item handle_edit_cmd()
                   10834: 
                   10835: =item editor()
                   10836: 
                   10837: =item process_file_upload()
                   10838: 
                   10839: =item process_secondary_uploads()
                   10840: 
                   10841: =item is_supplemental_title()
                   10842: 
                   10843: =item entryline()
                   10844: 
                   10845: =item tiehash()
                   10846: 
                   10847: =item untiehash()
                   10848: 
                   10849: =item checkonthis()
                   10850: 
                   10851: check on this
                   10852: 
                   10853: =item verifycontent()
                   10854: 
                   10855: Verify Content
                   10856: 
1.636     raeburn  10857: =item devalidateversioncache() 
                   10858: 
                   10859: =item checkversions()
1.329     droeschl 10860: 
                   10861: Check Versions
                   10862: 
                   10863: =item mark_hash_old()
                   10864: 
                   10865: =item is_hash_old()
                   10866: 
                   10867: =item changewarning()
                   10868: 
                   10869: =item init_breadcrumbs()
                   10870: 
                   10871: Breadcrumbs for special functions
                   10872: 
1.484     raeburn  10873: =item create_list_elements()
                   10874: 
                   10875: =item create_form_ul()
                   10876: 
                   10877: =item startContentScreen() 
                   10878: 
                   10879: =item endContentScreen()
                   10880: 
                   10881: =item supplemental_base()
                   10882: 
                   10883: =item embedded_form_elems()
                   10884: 
                   10885: =item embedded_destination()
                   10886: 
                   10887: =item return_to_editor()
                   10888: 
                   10889: =item decompression_info()
                   10890: 
                   10891: =item decompression_phase_one()
                   10892: 
                   10893: =item decompression_phase_two()
                   10894: 
                   10895: =item remove_archive()
                   10896: 
                   10897: =item generate_admin_menu()
                   10898: 
                   10899: =item generate_edit_table()
                   10900: 
                   10901: =item editing_js()
                   10902: 
                   10903: =item history_tab_js()
                   10904: 
                   10905: =item inject_data_js()
                   10906: 
                   10907: =item dump_switchserver_js()
                   10908: 
1.485     raeburn  10909: =item resize_scrollbox_js()
1.484     raeburn  10910: 
                   10911: =item makedocslogform()
                   10912: 
1.485     raeburn  10913: =item makesimpleeditform()
                   10914: 
1.329     droeschl 10915: =back
                   10916: 
                   10917: =cut

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