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

1.329     droeschl    1: # The LearningOnline Network
                      2: # Documents
                      3: #
1.697   ! raeburn     4: # $Id: londocs.pm,v 1.696 2023/03/23 16:45:50 raeburn Exp $
1.329     droeschl    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: package Apache::londocs;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common :http);
                     33: use Apache::imsexport;
                     34: use Apache::lonnet;
                     35: use Apache::loncommon;
1.383     tempelho   36: use Apache::lonhtmlcommon;
1.329     droeschl   37: use LONCAPA::map();
                     38: use Apache::lonratedt();
                     39: use Apache::lonxml;
                     40: use Apache::lonclonecourse;
                     41: use Apache::lonnavmaps;
1.472     raeburn    42: use Apache::lonnavdisplay();
1.510     raeburn    43: use Apache::lonextresedit();
1.567     raeburn    44: use Apache::lontemplate();
                     45: use Apache::lonsimplepage();
1.606     raeburn    46: use Apache::lonhomework();
                     47: use Apache::lonpublisher();
1.645     raeburn    48: use Apache::lonparmset();
1.651     raeburn    49: use Apache::loncourserespicker();
1.329     droeschl   50: use HTML::Entities;
1.488     raeburn    51: use HTML::TokeParser;
1.329     droeschl   52: use GDBM_File;
1.578     raeburn    53: use File::MMagic;
1.606     raeburn    54: use File::Copy;
1.329     droeschl   55: use Apache::lonlocal;
                     56: use Cwd;
1.643     raeburn    57: use UUID::Tiny ':std';
1.329     droeschl   58: use LONCAPA qw(:DEFAULT :match);
                     59: 
                     60: my $iconpath;
                     61: 
                     62: my %hash;
                     63: 
                     64: my $hashtied;
                     65: my %alreadyseen=();
                     66: 
                     67: my $hadchanges;
1.557     raeburn    68: my $suppchanges;
1.329     droeschl   69: 
                     70: 
                     71: my %help=();
                     72: 
                     73: 
                     74: sub mapread {
                     75:     my ($coursenum,$coursedom,$map)=@_;
                     76:     return
                     77:       &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                     78: 			     $map);
                     79: }
                     80: 
                     81: sub storemap {
1.492     raeburn    82:     my ($coursenum,$coursedom,$map,$contentchg)=@_;
                     83:     my $report;
                     84:     if (($contentchg) && ($map =~ /^default/)) {
                     85:        $report = 1;
                     86:     }
1.329     droeschl   87:     my ($outtext,$errtext)=
                     88:       &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492     raeburn    89: 			      $map,1,$report);
1.329     droeschl   90:     if ($errtext) { return ($errtext,2); }
1.364     bisitz     91: 
1.557     raeburn    92:     if ($map =~ /^default/) {
                     93:         $hadchanges=1;
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;
                    106:     foreach my $key (keys(%env)) {
                    107: 	if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
                    108: 	    my $role=$1;
                    109: 	    my $realm=$2;
                    110: 	    my ($start,$end)=split(/\./,$env{$key});
                    111: 	    if (($start) && ($start>time)) { next; }
                    112: 	    if (($end) && (time>$end)) { next; }
                    113: 	    my ($ca,$cd);
                    114: 	    if ($1 eq 'au') {
                    115: 		$ca=$env{'user.name'};
                    116: 		$cd=$env{'user.domain'};
                    117: 	    } else {
                    118: 		($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
                    119: 	    }
                    120: 	    my $allowed=0;
                    121: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
                    122: 	    my @ids=&Apache::lonnet::current_machine_ids();
1.484     raeburn   123: 	    foreach my $id (@ids) {
                    124:                 if ($id eq $myhome) {
                    125:                     $allowed=1;
                    126:                     last;
                    127:                 }
                    128:             }
1.329     droeschl  129: 	    if ($allowed) {
                    130: 		$home++;
1.484     raeburn   131: 		$outhash{'home_'.$ca.':'.$cd}=1;
1.329     droeschl  132: 	    } else {
1.484     raeburn   133: 		$outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329     droeschl  134: 		$other++;
                    135: 	    }
                    136: 	}
                    137:     }
                    138:     return ($home,$other,%outhash);
                    139: }
                    140: 
                    141: 
                    142: sub clean {
                    143:     my ($title)=@_;
                    144:     $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344     bisitz    145:     return $title;
1.329     droeschl  146: }
                    147: 
1.617     raeburn   148: sub default_folderpath {
                    149:     my ($coursenum,$coursedom,$navmapref) = @_;
                    150:     return unless ($coursenum && $coursedom && ref($navmapref));
                    151: # Check if entire course is hidden and/or encrypted
                    152:     my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
                    153:     my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
                    154:     unless (ref($$navmapref)) {
                    155:         $$navmapref = Apache::lonnavmaps::navmap->new();
                    156:     }
                    157:     if (ref($$navmapref)) {
                    158:         if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
                    159:             my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
                    160:             my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
                    161:             unless (@resources) {
                    162:                 $hiddenmap = 1;
                    163:                 unless ($env{'request.role.adv'}) {
                    164:                     $hiddentop = 1;
                    165:                     if ($env{'form.folder'}) {
                    166:                         undef($env{'form.folder'});
                    167:                     }
                    168:                 }
                    169:             }
                    170:         }
                    171:         if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
                    172:             $encryptmap = 1;
                    173:         }
                    174:     }
                    175:     unless ($hiddentop) {
                    176:         $folderpath='default&'.&escape(&mt('Main Content')).
                    177:                     '::'.$hiddenmap.':'.$encryptmap.'::';
                    178:     }
                    179:     if (wantarray) {
                    180:         return ($folderpath,$hiddentop);
                    181:     } else {
                    182:         return $folderpath;
                    183:     }
                    184: }
1.329     droeschl  185: 
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.568     raeburn   267:     $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
                    268:               &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' 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) {
                    272:         $r->print(&endContentScreen());
                    273:         return '';
                    274:     }
1.329     droeschl  275:     my $origcrsid=$env{'request.course.id'};
                    276:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    277:     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    278: # Do the dumping
1.484     raeburn   279: 	unless ($outhash{'home_'.$env{'form.authorspace'}}) {
                    280:             $r->print(&endContentScreen());
                    281:             return '';
                    282:         }
1.531     raeburn   283: 	my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329     droeschl  284: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
                    285: 	my $title=$env{'form.authorfolder'};
                    286: 	$title=&clean($title);
1.567     raeburn   287:         my ($navmap,$errormsg) =
                    288:             &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
                    289:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    290:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    291:         my (%maps,%resources,%titles);
                    292:         if (!ref($navmap)) {
                    293:             $r->print($errormsg.
                    294:                       &endContentScreen());
                    295:             return '';
                    296:         } else {
                    297:             &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
                    298:                                                                    'dumpdocs',$cdom,$cnum);
1.329     droeschl  299: 	}
1.567     raeburn   300:         my @todump = &Apache::loncommon::get_env_multiple('form.archive');
                    301:         my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
                    302:             %newcontent,%has_simpleprobs);
                    303:         foreach my $item (sort {$a <=> $b} (@todump)) {
                    304:             my $name = $env{'form.namefor_'.$item};
                    305:             if ($resources{$item}) {
                    306:                 my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
                    307:                 if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
                    308:                     $tocopy{$1} = $name;
                    309:                     $display{$item} = $1;
                    310:                     $lookup{$1} = $item; 
                    311:                 } elsif ($res eq 'lib/templates/simpleproblem.problem') {
                    312:                     $simpleproblems{$item} = {
                    313:                                                 symb => $resources{$item},
                    314:                                                 name => $name,
                    315:                                              };
                    316:                     $display{$item} = 'simpleproblem_'.$name;
                    317:                     if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
                    318:                         $has_simpleprobs{$1}{$id} = $item;
                    319:                     }
                    320:                 } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
                    321:                     my $marker = $1;
                    322:                     my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
                    323:                     $simplepages{$item} = {
                    324:                                             res    => $res,
                    325:                                             title  => $titles{$item},
                    326:                                             db     => $db_name,
                    327:                                             marker => $marker,
                    328:                                             symb   => $resources{$item},
                    329:                                             name   => $name,
                    330:                                           };
                    331:                     $display{$item} = '/'.$res;
                    332:                 }
                    333:             } elsif ($maps{$item}) {
                    334:                 if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
                    335:                     $tocopy{$1} = $name;
                    336:                     $display{$item} = $1;
                    337:                     $lookup{$1} = $item;
                    338:                 }
                    339:             } else {
                    340:                 next;
                    341:             }
                    342:         }
1.329     droeschl  343: 	my $crs='/uploaded/'.$env{'request.course.id'}.'/';
                    344: 	$crs=~s/\_/\//g;
1.567     raeburn   345:         my $mm = new File::MMagic;
                    346:         my $prefix = "/uploaded/$cdom/$cnum/";
                    347:         %replacehash = %tocopy;
                    348:         foreach my $item (sort(keys(%simpleproblems))) {
                    349:             my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
                    350:             $newcontent{$display{$item}} = $content;
                    351:         }
                    352:         my $gateway = Apache::lonhtmlgateway->new('web');
                    353:         foreach my $item (sort(keys(%simplepages))) {
                    354:             if (ref($simplepages{$item}) eq 'HASH') {
                    355:                 my $pagetitle = $simplepages{$item}{'title'};
                    356:                 my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
                    357:                 my %contents;
                    358:                 foreach my $field (keys(%fields)) {
                    359:                     if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
                    360:                         my $name = $1;
                    361:                         my $msg = $fields{$field};
                    362:                         if ($name eq 'webreferences') {
                    363:                             if ($msg =~ m{^https?://}) {
                    364:                                 $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
                    365:                             }
                    366:                         } else {
                    367:                             $msg = &Encode::decode('utf8',$msg);
                    368:                             $msg = $gateway->process_outgoing_html($msg,1);
                    369:                             $contents{$name} = $msg;
                    370:                         }
                    371:                     } elsif ($field eq 'uploaded.photourl') {
                    372:                         my $marker = $simplepages{$item}{marker};
                    373:                         if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
                    374:                             my $filepath = $1;
                    375:                             my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
                    376:                             if ($fname ne '') {
                    377:                                 $fname=~s/\.(\w+)$//;
                    378:                                 my $ext=$1;
                    379:                                 $fname = &clean($fname);
                    380:                                 $fname.='.'.$ext;
                    381:                                 $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
                    382:                                 $replacehash{$filepath} = $relpath.$fname;
                    383:                                 $deps{$item}{$filepath} = 1;
                    384:                             }
                    385:                         }
                    386:                     }
                    387:                 }
                    388:                 $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
                    389:                 $lookup{'/'.$simplepages{$item}{'res'}} = $item;
                    390:                 my $content = '
                    391: <html>
                    392: <head>
                    393: <title>'.$pagetitle.'</title>
                    394: </head>
                    395: <body bgcolor="#ffffff">';
                    396:                 if ($contents{title}) {
                    397:                     $content .= "\n".'<h2>'.$contents{title}.'</h2>';
                    398:                 }
                    399:                 if ($contents{image}) {
                    400:                     $content .= "\n".$contents{image};
                    401:                 }
                    402:                 if ($contents{content}) {
                    403:                     $content .= '
                    404: <div class="LC_Box">
1.577     bisitz    405: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567     raeburn   406: $contents{content}.'
                    407: </div>';
                    408:                 }
                    409:                 if ($contents{webreferences}) {
                    410:                     $content .= ' 
                    411: <div class="LC_Box">
1.577     bisitz    412: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567     raeburn   413: $contents{webreferences}.'
                    414: </div>';
                    415:                 }
                    416:                 $content .= '
                    417: </body>
                    418: </html>
                    419: ';
                    420:                 $newcontent{'/'.$simplepages{$item}{res}} = $content; 
                    421:             }
                    422:         }
                    423: 	foreach my $item (keys(%tocopy)) {
                    424:             unless ($item=~/\.(sequence|page)$/) {
                    425:                 my $currurlpath = $prefix.$item;
                    426:                 my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
                    427:                 &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
                    428:             }
                    429:         }
                    430:         foreach my $num (sort {$a <=> $b} (@todump)) {
                    431:             my $src = $display{$num};
                    432:             next if ($src eq '');
                    433:             my @needcopy = ();
                    434:             if ($replacehash{$src}) {
                    435:                 push(@needcopy,$src);
                    436:                 if (ref($deps{$num}) eq 'HASH') {
                    437:                     foreach my $dep (sort(keys(%{$deps{$num}}))) {
                    438:                         if ($replacehash{$dep}) {
                    439:                             push(@needcopy,$dep);
                    440:                         }
                    441:                     }
                    442:                 }
                    443:             } elsif ($src =~ /^simpleproblem_/) {
                    444:                 push(@needcopy,$src);
                    445:             }
                    446:             next if (@needcopy == 0);
                    447:             my ($result,$depresult);
                    448:             for (my $i=0; $i<@needcopy; $i++) {
                    449:                 my $item = $needcopy[$i];
                    450:                 my $newfilename;
                    451:                 if ($simpleproblems{$num}) {
                    452:                     $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
                    453:                 } else {
                    454: 	            $newfilename=$title.'/'.$replacehash{$item};
                    455:                 }
                    456: 	        $newfilename=~s/\.(\w+)$//;
                    457: 	        my $ext=$1;
                    458: 	        $newfilename=&clean($newfilename);
                    459: 	        $newfilename.='.'.$ext;
                    460:                 my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); 
                    461:                 if ($newrelpath ne $replacehash{$item}) {
                    462:                     $replacehash{$item} = $newrelpath;
                    463:                 }
                    464: 	        my @dirs=split(/\//,$newfilename);
                    465: 	        my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
                    466: 	        my $makepath=$path;
                    467: 	        my $fail;
                    468:                 my $origin;
                    469: 	        for (my $i=0;$i<$#dirs;$i++) {
                    470: 		    $makepath.='/'.$dirs[$i];
                    471: 		    unless (-e $makepath) {
                    472: 		        unless(mkdir($makepath,0755)) { 
                    473:                             $fail = &mt('Directory creation failed.');
                    474:                         }
                    475: 		    }
                    476: 	        }
                    477:                 if ($i == 0) {
                    478: 	            $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
                    479:                 } else {
                    480:                     $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
                    481:                                   '<span class="LC_fontsize_small" style="font-weight: bold;">'.
                    482:                                   &mt('(dependency)').'</span>: ';
                    483:                 }
                    484:                 if (-e $path.'/'.$newfilename) {
                    485:                     $fail = &mt('Destination already exists -- not overwriting.'); 
                    486: 	        } else {
                    487:                     if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
                    488:                         if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
                    489:                             ($item =~ /^simpleproblem_/)) {
                    490:                             print $fh $newcontent{$item};
                    491:                         } else {
                    492:                             my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
                    493:                             if (-e $fileloc) {
                    494:                                 if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
                    495:                                     if ((($1 eq 'sequence') || ($1 eq 'page')) &&
                    496:                                         (ref($has_simpleprobs{$item}) eq 'HASH')) {
                    497:                                         my %changes = %{$has_simpleprobs{$item}};
                    498:                                         my $content = &Apache::lonclonecourse::rewritefile(
                    499:                      &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                    500:                                                       (%replacehash,$crs => '')
                    501:                                                                                           );
                    502:                                         my $updatedcontent = '';
                    503:                                         my $parser = HTML::TokeParser->new(\$content);
                    504:                                         $parser->attr_encoded(1);
                    505:                                         while (my $token = $parser->get_token) {
                    506:                                             if ($token->[0] eq 'S') {
                    507:                                                 if (($token->[1] eq 'resource') &&
                    508:                                                     ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && 
                    509:                                                     ($changes{$token->[2]->{'id'}})) {
                    510:                                                     my $id = $token->[2]->{'id'};
                    511:                                                     $updatedcontent .= '<'.$token->[1];
                    512:                                                     foreach my $attrib (@{$token->[3]}) {
                    513:                                                         next unless ($attrib =~ /^(src|type|title|id)$/);
                    514:                                                         if ($attrib eq 'src') {
                    515:                                                             my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); 
                    516:                                                             if ($file) {
                    517:                                                                 $updatedcontent .= ' '.$attrib.'="'.$file.'"';
                    518:                                                             } else {
                    519:                                                                 $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; 
                    520:                                                             }
                    521:                                                         } else {
                    522:                                                             $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
                    523:                                                         }
                    524:                                                     }
                    525:                                                     $updatedcontent .= ' />'."\n";
                    526:                                                 } else {
                    527:                                                     $updatedcontent .= $token->[4]."\n";
                    528:                                                 }
                    529:                                              } else {
                    530:                                                  $updatedcontent .= $token->[2];
                    531:                                              }
                    532:                                          }
                    533:                                          print $fh $updatedcontent;
                    534:                                     } else {  
                    535: 		                        print $fh &Apache::lonclonecourse::rewritefile(
                    536:                      &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                    537: 		                                      (%replacehash,$crs => '')
                    538: 							                              );
                    539:                                     }
                    540:                                 } else {
                    541: 		                    print $fh
                    542:                                         &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
                    543: 		                }
                    544:                             } else {
                    545:                                 $fail = &mt('Source does not exist.');  
                    546:                             }
                    547:                         }
                    548:                         $fh->close();
                    549: 	            } else {
                    550: 		        $fail = &mt('Could not write to destination.');
                    551:                     }
                    552: 	        }
                    553:                 my $text;
                    554: 	        if ($fail) {
                    555:                     $text = '<span class="LC_error">'.&mt('fail').('&nbsp;'x3).$fail.'</span>';
                    556: 	        } else {
                    557:                     $text = '<span class="LC_success">'.&mt('ok').'</span>';
                    558:                 }
                    559:                 if ($i == 0) {
                    560:                     $result .= $text;
                    561:                 } else {
                    562:                     $depresult .= $text.'</li>';
                    563: 	        }
                    564:             }
                    565:             $r->print($result);
                    566:             if ($depresult) {
                    567:                 $r->print('<ul>'.$depresult.'</ul>');
                    568:             }
                    569:         }
                    570:     } else {
                    571:         my ($navmap,$errormsg) =
                    572:             &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
                    573:         if (!ref($navmap)) {
                    574:             $r->print($errormsg);
                    575:         } else {
                    576:             $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
                    577:             $r->rflush();
                    578:             my ($preamble,$formname);
                    579:             $formname = 'dumpdoc';
                    580: 	    unless ($home==1) {
                    581: 	        $preamble = '<div class="LC_left_float">'.
                    582: 		            '<fieldset><legend>'.
                    583:                             &mt('Select the Authoring Space').
                    584:                             '</legend><select name="authorspace">';
1.329     droeschl  585: 	    }
1.567     raeburn   586:             my @orderspaces = ();
                    587: 	    foreach my $key (sort(keys(%outhash))) {
                    588:                 if ($key=~/^home_(.+)$/) {
                    589:                     if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
                    590:                         unshift(@orderspaces,$1);
                    591:                     } else {
                    592:                         push(@orderspaces,$1);
                    593:                     }
                    594:                 } 
                    595:             }
1.569     raeburn   596:             if ($home>1) {
                    597:                 $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
                    598:             }
1.567     raeburn   599:             foreach my $user (@orderspaces) {
1.329     droeschl  600: 		if ($home==1) {
1.567     raeburn   601: 		    $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329     droeschl  602: 		} else {
1.567     raeburn   603: 		    $preamble .= '<option value="'.$user.'">'.$user.' - '.
                    604: 			         &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
                    605: 	        }
1.329     droeschl  606: 	    }
1.567     raeburn   607: 	    unless ($home==1) {
                    608: 	        $preamble .= '</select></fieldset></div>'."\n";
1.329     droeschl  609: 	    }
1.567     raeburn   610: 	    my $title=$origcrsdata{'description'};
                    611: 	    $title=~s/[\/\s]+/\_/gs;
1.329     droeschl  612: 	    $title=&clean($title);
1.567     raeburn   613: 	    $preamble .= '<div class="LC_left_float">'.
                    614:                          '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
                    615:                          '<input type="text" size="50" name="authorfolder" value="'.
                    616:                          $title.'" />'.
                    617:                          '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
                    618:             my %uploadedfiles;
                    619: 	    &tiehash();
                    620: 	    foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
                    621: 	        my ($ext)=($file=~/\.(\w+)$/);
                    622: # FIXME Check supplemental here
                    623: 	        my $title=$hash{'title_'.$hash{
                    624: 		                'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
                    625: 	        if (!$title) {
                    626: 		    $title=$file;
                    627: 	        } else {
                    628: 		    $title=~s|/|_|g;
                    629: 	        }
                    630: 	        $title=~s/\.(\w+)$//;
                    631: 	        $title=&clean($title);
                    632: 	        $title.='.'.$ext;
                    633: #	    $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
                    634:                 $uploadedfiles{$file} = $title;
                    635: 	    }
                    636: 	    &untiehash();
                    637:             $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
                    638:                                                                  undef,undef,$preamble,$home,\%uploadedfiles));
                    639:         }
1.329     droeschl  640:     }
1.484     raeburn   641:     $r->print(&endContentScreen());
1.329     droeschl  642: }
                    643: 
1.567     raeburn   644: sub recurse_html {
                    645:     my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
                    646:     return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
                    647:     my (%allfiles,%codebase);
                    648:     if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
                    649:         if (keys(%allfiles)) {
                    650:             foreach my $dependency (keys(%allfiles)) {
                    651:                 next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
                    652:                 my ($depurl,$relfile,$newcontainer);
                    653:                 if ($dependency =~ m{^/}) {
                    654:                     if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
                    655:                         $relfile = $1;
                    656:                         if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
                    657:                             $newcontainer = $1;
                    658:                             next if ($replacehash->{$newcontainer});
                    659:                         }
                    660:                         $depurl = $dependency;
                    661:                     } else {
                    662:                         next;
                    663:                     }
                    664:                 } else {
                    665:                     $relfile = $dependency;
                    666:                     $depurl = $currurlpath;
1.630     raeburn   667:                     $depurl =~ s{[^/]+$}{};
1.567     raeburn   668:                     $depurl .= $dependency;
1.630     raeburn   669:                     ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567     raeburn   670:                 }
                    671:                 next if ($relfile eq '');
                    672:                 my $newname = $replacehash->{$container};
                    673:                 $newname =~ s{[^/]+$}{};
                    674:                 $replacehash->{$newcontainer} = $newname.$relfile;
                    675:                 $deps->{$item}{$newcontainer} = 1;
                    676:                 my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});  
                    677:                 my $depfile = &Apache::lonnet::filelocation('',$depurl);
                    678:                 my $type = $mm->checktype_filename($depfile);
                    679:                 if ($type eq 'text/html') {
                    680:                     &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
                    681:                 }
                    682:             }
                    683:         }
                    684:     }
                    685:     return;
                    686: }
                    687: 
1.329     droeschl  688: sub group_import {
1.598     raeburn   689:     my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529     raeburn   690:     my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
                    691:         %removeparam,$importuploaded,$fixuperrors);
                    692:     $allmaps = {};
1.329     droeschl  693:     while (@files) {
                    694: 	my ($name, $url, $residx) = @{ shift(@files) };
1.344     bisitz    695:         if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329     droeschl  696: 	     && ($caller eq 'londocs')
                    697: 	     && (!&Apache::lonnet::stat_file($url))) {
1.364     bisitz    698: 
1.329     droeschl  699:             my $errtext = '';
                    700:             my $fatal = 0;
                    701:             my $newmapstr = '<map>'."\n".
                    702:                             '<resource id="1" src="" type="start"></resource>'."\n".
                    703:                             '<link from="1" to="2" index="1"></link>'."\n".
                    704:                             '<resource id="2" src="" type="finish"></resource>'."\n".
                    705:                             '</map>';
                    706:             $env{'form.output'}=$newmapstr;
                    707:             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                    708:                                                 'output',$1.$2);
1.534     raeburn   709:             if ($result !~ m{^/uploaded/}) {
1.329     droeschl  710:                 $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
                    711:                 $fatal = 2;
                    712:             }
                    713:             if ($fatal) {
                    714:                 return ($errtext,$fatal);
                    715:             }
                    716:         }
                    717: 	if ($url) {
1.626     raeburn   718:             if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598     raeburn   719:                 $url = $1;
                    720:                 my $marker = $2;
                    721:                 my $info = $3;
1.604     raeburn   722:                 my ($toolid,%toolhash,%toolsettings);
1.642     raeburn   723:                 my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598     raeburn   724:                 my @toolinfo = split(/:/,$info);
                    725:                 if ($residx) {
1.604     raeburn   726:                     %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598     raeburn   727:                     $toolid = $toolsettings{'id'};
                    728:                 } else {
1.604     raeburn   729:                     $toolid = shift(@toolinfo);
1.598     raeburn   730:                 }
                    731:                 $toolid =~ s/\D//g;
1.604     raeburn   732:                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645     raeburn   733:                  $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
                    734:                  $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624     raeburn   735:                 foreach my $item (@extras) {
                    736:                     $toolhash{$item} = &unescape($toolhash{$item});
                    737:                 }
1.645     raeburn   738:                 if ($folder =~ /^supplemental/) {
1.648     raeburn   739:                     delete($toolhash{'gradable'});
                    740:                 } else {
                    741:                     $toolhash{'gradable'} =~ s/\D+//g;
1.645     raeburn   742:                 }
1.598     raeburn   743:                 if (ref($ltitoolsref) eq 'HASH') {
                    744:                     if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
1.643     raeburn   745:                         my @deleted;
1.598     raeburn   746:                         $toolhash{'id'} = $toolid;
1.628     raeburn   747:                         if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
                    748:                             ($toolhash{'target'} eq 'window')) {
1.604     raeburn   749:                             if ($toolhash{'target'} eq 'window') {
                    750:                                 foreach my $item ('width','height') {
                    751:                                     $toolhash{$item} =~ s/^\s+//;
                    752:                                     $toolhash{$item} =~ s/\s+$//;
1.624     raeburn   753:                                     if ($toolhash{$item} =~ /\D/) {
                    754:                                         delete($toolhash{$item});
                    755:                                         if ($residx) {
                    756:                                             if ($toolsettings{$item}) {
                    757:                                                 push(@deleted,$item);
                    758:                                             }
                    759:                                         }
                    760:                                     }
1.604     raeburn   761:                                 }
                    762:                             }
                    763:                         } elsif ($residx) {
                    764:                             $toolhash{'target'} = $toolsettings{'target'};
                    765:                             if ($toolhash{'target'} eq 'window') {
1.630     raeburn   766:                                 foreach my $item ('width','height') {
1.624     raeburn   767:                                     $toolhash{$item} = $toolsettings{$item};
                    768:                                 }
1.604     raeburn   769:                             }
                    770:                         } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
                    771:                             $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
                    772:                             if ($toolhash{'target'} eq 'window') {
                    773:                                 $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
                    774:                                 $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
                    775:                             }
                    776:                         }
1.598     raeburn   777:                         if ($toolhash{'target'} eq 'iframe') {
1.624     raeburn   778:                             foreach my $item ('width','height','linktext','explanation') {
                    779:                                 delete($toolhash{$item});
                    780:                                 if ($residx) {
                    781:                                     if ($toolsettings{$item}) {
                    782:                                         push(@deleted,$item);
                    783:                                     }
1.604     raeburn   784:                                 }
                    785:                             }
1.628     raeburn   786:                         } elsif ($toolhash{'target'} eq 'tab') {
                    787:                             foreach my $item ('width','height') {
                    788:                                 delete($toolhash{$item});
                    789:                                 if ($residx) {
                    790:                                     if ($toolsettings{$item}) {
                    791:                                         push(@deleted,$item);
                    792:                                     }
                    793:                                 }
                    794:                             }
1.604     raeburn   795:                         }
                    796:                         if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624     raeburn   797:                             foreach my $item ('label','title','linktext','explanation') {
                    798:                                 my $crsitem;
                    799:                                 if (($item eq 'label') || ($item eq 'title')) {
                    800:                                     $crsitem = 'crs'.$item;
                    801:                                 } else {
                    802:                                     $crsitem = $item;
                    803:                                 }
1.604     raeburn   804:                                 if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624     raeburn   805:                                     $toolhash{$crsitem} =~ s/^\s+//;
                    806:                                     $toolhash{$crsitem} =~ s/\s+$//;
                    807:                                     if ($toolhash{$crsitem} eq '') {
                    808:                                         delete($toolhash{$crsitem});
1.604     raeburn   809:                                     }
                    810:                                 } else {
1.624     raeburn   811:                                     delete($toolhash{$crsitem});
1.604     raeburn   812:                                 }
1.624     raeburn   813:                                 if (($residx) && (exists($toolsettings{$crsitem}))) {
                    814:                                     unless (exists($toolhash{$crsitem})) {
                    815:                                         push(@deleted,$crsitem);
1.604     raeburn   816:                                     }
                    817:                                 }
1.598     raeburn   818:                             }
                    819:                         }
1.643     raeburn   820:                         if ($toolhash{'passback'}) {
                    821:                             my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                    822:                             $toolhash{'gradesecret'} = $gradesecret;
                    823:                             $toolhash{'gradesecretdate'} = time;
                    824:                         }
                    825:                         if ($toolhash{'roster'}) {
                    826:                             my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                    827:                             $toolhash{'rostersecret'} = $rostersecret;
                    828:                             $toolhash{'rostersecretdate'} = time;
                    829:                         }
1.645     raeburn   830:                         my $changegradable;
                    831:                         if (($residx) && ($folder =~ /^default/)) {
1.648     raeburn   832:                             if ($toolsettings{'gradable'}) {
                    833:                                 unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1.645     raeburn   834:                                     push(@deleted,'gradable');
                    835:                                     $changegradable = 1;
                    836:                                 }
1.648     raeburn   837:                             } elsif ($toolhash{'gradable'}) {
                    838:                                 $changegradable = 1;
                    839:                             }
                    840:                             if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645     raeburn   841:                                 $changegradable = 1;
1.648     raeburn   842:                                 if ($toolsettings{'gradable'}) {
                    843:                                     $toolhash{'gradable'} = 1;
                    844:                                 }
1.645     raeburn   845:                             }
                    846:                         }
1.598     raeburn   847:                         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604     raeburn   848:                         if ($putres eq 'ok') {
                    849:                             if (@deleted) {
                    850:                                 &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.645     raeburn   851:                             }
                    852:                             if (($changegradable) && ($folder =~ /^default/)) {
                    853:                                 my $val;
                    854:                                 if ($toolhash{'gradable'}) {
                    855:                                     $val = 'yes';
                    856:                                 } else {
                    857:                                     $val = 'no';
                    858:                                 }
                    859:                                 &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
                    860:                                                               'string_yesno');
                    861:                                 &remember_parms($residx,'gradable','set',$val);
                    862:                             }
                    863:                         } else {
                    864:                             return (&mt('Failed to save update to external tool.'),1);
1.604     raeburn   865:                         }
1.598     raeburn   866:                     }
                    867:                 }
                    868:             }
1.529     raeburn   869:             if (($caller eq 'londocs') &&
                    870:                 ($folder =~ /^default/)) {
1.534     raeburn   871:                 if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529     raeburn   872:                     my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
                    873:                     my $cid = $coursedom.'_'.$coursenum;
                    874:                     $allmaps =
                    875:                         &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                    876:                                                              $chome,$cid);
                    877:                     $donechk = 1;
                    878:                 }
                    879:                 if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627     raeburn   880:                     &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
                    881:                                         \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529     raeburn   882:                     $importuploaded = 1;
                    883:                 } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
                    884:                     next if ($allmaps->{$url});
                    885:                 }
                    886:             }
1.344     bisitz    887: 	    if (!$residx
1.329     droeschl  888: 		|| defined($LONCAPA::map::zombies[$residx])) {
                    889: 		$residx = &LONCAPA::map::getresidx($url,$residx);
                    890: 		push(@LONCAPA::map::order, $residx);
                    891: 	    }
                    892: 	    my $ext = 'false';
                    893: 	    if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534     raeburn   894:             if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
                    895:                 my $filepath = $1;
1.675     raeburn   896:                 my $fname;
                    897:                 if ($name eq '') {
                    898:                     $name = &mt('Web Page');
1.534     raeburn   899:                     $fname = 'web';
                    900:                 } else {
1.675     raeburn   901:                     $fname = $name;
                    902:                     $fname=&Apache::lonnet::clean_filename($fname);
                    903:                     if ($fname eq '') {
                    904:                         $fname = 'web';
                    905:                     } elsif (length($fname) > 15) {
                    906:                         $fname = substr($fname,0,14);
                    907:                     }
1.534     raeburn   908:                 }
1.675     raeburn   909:                 my $title = &Apache::loncommon::cleanup_html($name);
1.534     raeburn   910:                 my $initialtext = &mt('Replace with your own content.');
                    911:                 my $newhtml = <<END;
1.545     raeburn   912: <html>
1.534     raeburn   913: <head>
1.675     raeburn   914: <title>$title</title>
1.534     raeburn   915: </head>
                    916: <body bgcolor="#ffffff">
                    917: $initialtext
                    918: </body>
                    919: </html>
                    920: END
                    921:                 $env{'form.output'}=$newhtml;
1.630     raeburn   922:                 my $result =
1.534     raeburn   923:                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                    924:                                                           'output',
                    925:                                                           "$filepath/$residx/$fname.html");
                    926:                 if ($result =~ m{^/uploaded/}) {
                    927:                     $url = $result;
                    928:                     if ($filepath =~ /^supplemental/) {
                    929:                         $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                    930:                                 $env{'user.domain'}.'___&&&___'.$name;
                    931:                     }
                    932:                 } else {
                    933:                     return (&mt('Failed to save new web page.'),1);
                    934:                 }
                    935:             }
1.675     raeburn   936:             $name = &LONCAPA::map::qtunescape($name);
1.538     raeburn   937:             $url  = &LONCAPA::map::qtunescape($url);
1.344     bisitz    938: 	    $LONCAPA::map::resources[$residx] =
1.329     droeschl  939: 		join(':', ($name, $url, $ext, 'normal', 'res'));
                    940: 	}
                    941:     }
1.529     raeburn   942:     if ($importuploaded) {
                    943:         my %import_errors;
                    944:         my %updated = (
                    945:                           removefrommap => \%removefrommap,
                    946:                           removeparam   => \%removeparam,
                    947:                       );
1.533     raeburn   948:         my ($result,$msgsarray,$lockerror) = 
                    949:             &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529     raeburn   950:         if (keys(%import_errors) > 0) {
1.530     raeburn   951:             $fixuperrors =
1.529     raeburn   952:                 '<p span class="LC_warning">'."\n".
                    953:                 &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".
                    954:                 '<ul>'."\n";
                    955:             foreach my $key (sort(keys(%import_errors))) {
                    956:                 $fixuperrors .= '<li>'.$key.'</li>'."\n";
                    957:             }
                    958:             $fixuperrors .= '</ul></p>'."\n";
                    959:         }
1.533     raeburn   960:         if (ref($msgsarray) eq 'ARRAY') {
                    961:             if (@{$msgsarray} > 0) {
                    962:                 $fixuperrors .= '<p class="LC_info">'.
                    963:                                 join('<br />',@{$msgsarray}).
                    964:                                 '</p>';
                    965:             }
                    966:         }
                    967:         if ($lockerror) {
                    968:             $fixuperrors .= '<p class="LC_error">'.
                    969:                             $lockerror.
                    970:                             '</p>';
                    971:         }
1.529     raeburn   972:     }
                    973:     my ($errtext,$fatal) =
                    974:         &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557     raeburn   975:     unless ($fatal) {
                    976:         if ($folder =~ /^supplemental/) {
1.561     raeburn   977:             my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                    978:                                             $folder.'.'.$container);
1.557     raeburn   979:         }
                    980:     }
1.529     raeburn   981:     return ($errtext,$fatal,$fixuperrors);
1.329     droeschl  982: }
                    983: 
                    984: sub log_docs {
1.494     raeburn   985:     return &Apache::lonnet::write_log('course','docslog',@_);
1.329     droeschl  986: }
                    987: 
                    988: {
                    989:     my @oldresources=();
                    990:     my @oldorder=();
                    991:     my $parmidx;
                    992:     my %parmaction=();
                    993:     my %parmvalue=();
                    994:     my $changedflag;
                    995: 
                    996:     sub snapshotbefore {
                    997:         @oldresources=@LONCAPA::map::resources;
                    998:         @oldorder=@LONCAPA::map::order;
                    999:         $parmidx=undef;
                   1000:         %parmaction=();
                   1001:         %parmvalue=();
                   1002:         $changedflag=0;
                   1003:     }
                   1004: 
                   1005:     sub remember_parms {
                   1006:         my ($idx,$parameter,$action,$value)=@_;
                   1007:         $parmidx=$idx;
                   1008:         $parmaction{$parameter}=$action;
                   1009:         $parmvalue{$parameter}=$value;
                   1010:         $changedflag=1;
                   1011:     }
                   1012: 
                   1013:     sub log_differences {
                   1014:         my ($plain)=@_;
                   1015:         my %storehash=('folder' => $plain,
                   1016:                        'currentfolder' => $env{'form.folder'});
                   1017:         if ($parmidx) {
                   1018:            $storehash{'parameter_res'}=$oldresources[$parmidx];
                   1019:            foreach my $parm (keys(%parmaction)) {
                   1020:               $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
                   1021:               $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
                   1022:            }
                   1023:         }
                   1024:         my $maxidx=$#oldresources;
                   1025:         if ($#LONCAPA::map::resources>$#oldresources) {
                   1026:            $maxidx=$#LONCAPA::map::resources;
                   1027:         }
                   1028:         for (my $idx=0; $idx<=$maxidx; $idx++) {
                   1029:            if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
                   1030:               $storehash{'before_resources_'.$idx}=$oldresources[$idx];
                   1031:               $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
                   1032:               $changedflag=1;
                   1033:            }
                   1034:            if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
                   1035:               $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
                   1036:               $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                   1037:               $changedflag=1;
                   1038:            }
                   1039:         }
                   1040: 	$storehash{'maxidx'}=$maxidx;
                   1041:         if ($changedflag) { &log_docs(\%storehash); }
                   1042:     }
                   1043: }
                   1044: 
                   1045: sub docs_change_log {
1.611     raeburn  1046:     my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486     raeburn  1047:     my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617     raeburn  1048:     my $navmap; 
1.483     raeburn  1049:     my $js = '<script type="text/javascript">'."\n".
                   1050:              '// <![CDATA['."\n".
                   1051:              &Apache::loncommon::display_filter_js('docslog')."\n".
1.606     raeburn  1052:              &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622     raeburn  1053:                          $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483     raeburn  1054:              &history_tab_js()."\n".
1.484     raeburn  1055:              &Apache::lonratedt::editscript('simple')."\n".
1.483     raeburn  1056:              '// ]]>'."\n".
                   1057:              '</script>'."\n";
1.484     raeburn  1058:     $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
                   1059:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489     raeburn  1060:     $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484     raeburn  1061:     my %orderhash;
                   1062:     my $container='sequence';
                   1063:     my $pathitem;
1.519     raeburn  1064:     if ($env{'form.folderpath'} =~ /\:1$/) {
1.484     raeburn  1065:         $container='page';
                   1066:     }
1.519     raeburn  1067:     my $folderpath=$env{'form.folderpath'};
                   1068:     if ($folderpath eq '') {
1.617     raeburn  1069:         $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519     raeburn  1070:     }
1.617     raeburn  1071:     undef($navmap);
1.519     raeburn  1072:     $pathitem = '<input type="hidden" name="folderpath" value="'.
                   1073:                 &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484     raeburn  1074:     my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
                   1075:     my $jumpto = $readfile;
                   1076:     $jumpto =~ s{^/}{};
                   1077:     my $tid = 1;
1.489     raeburn  1078:     if ($supplementalflag) {
                   1079:         $tid = 2;
                   1080:     }
1.630     raeburn  1081:     my ($breadcrumbtrail) =
1.509     raeburn  1082:         &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484     raeburn  1083:     $r->print($breadcrumbtrail.
                   1084:               &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
                   1085:               $readfile));
1.329     droeschl 1086:     my %docslog=&Apache::lonnet::dump('nohist_docslog',
                   1087:                                       $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1088:                                       $env{'course.'.$env{'request.course.id'}.'.num'});
                   1089: 
                   1090:     if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
                   1091: 
                   1092:     my %saveable_parameters = ('show' => 'scalar',);
                   1093:     &Apache::loncommon::store_course_settings('docs_log',
                   1094:                                               \%saveable_parameters);
                   1095:     &Apache::loncommon::restore_course_settings('docs_log',
                   1096:                                                 \%saveable_parameters);
                   1097:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452     www      1098: # FIXME: internationalization seems wrong here
1.329     droeschl 1099:     my %lt=('hiddenresource' => 'Resources hidden',
                   1100: 	    'encrypturl'     => 'URL hidden',
                   1101: 	    'randompick'     => 'Randomly pick',
                   1102: 	    'randomorder'    => 'Randomly ordered',
1.645     raeburn  1103:             'gradable'       => 'Grade can be assigned to External Tool',
1.329     droeschl 1104: 	    'set'            => 'set to',
                   1105: 	    'del'            => 'deleted');
1.484     raeburn  1106:     my $filter = &Apache::loncommon::display_filter('docslog')."\n".
                   1107:                  $pathitem."\n".
                   1108:                  '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
                   1109:                  ('&nbsp;'x2).'<input type="submit" value="'.&mt('Display').'" />';
                   1110:     $r->print('<div class="LC_left_float">'.
                   1111:               '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
                   1112:               &makedocslogform($filter,1).
                   1113:               '</fieldset></div><br clear="all" />');
1.329     droeschl 1114:     $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
                   1115:               '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
                   1116:               &mt('After').'</th>'.
                   1117:               &Apache::loncommon::end_data_table_header_row());
                   1118:     my $shown=0;
                   1119:     foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
                   1120: 	if ($env{'form.displayfilter'} eq 'currentfolder') {
                   1121: 	    if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
                   1122: 	}
                   1123:         my @changes=keys(%{$docslog{$id}{'logentry'}});
                   1124:         if ($env{'form.displayfilter'} eq 'containing') {
                   1125: 	    my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
                   1126: 		&Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
                   1127: 	    foreach my $key (@changes) {
                   1128: 		$wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
                   1129: 	    }
1.344     bisitz   1130: 	    if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329     droeschl 1131: 	}
                   1132:         my $count = 0;
                   1133:         my $time =
                   1134:             &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
                   1135:         my $plainname =
                   1136:             &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
                   1137:                                           $docslog{$id}{'exe_udom'});
                   1138:         my $about_me_link =
                   1139:             &Apache::loncommon::aboutmewrapper($plainname,
                   1140:                                                $docslog{$id}{'exe_uname'},
                   1141:                                                $docslog{$id}{'exe_udom'});
                   1142:         my $send_msg_link='';
                   1143:         if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
                   1144:              || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
                   1145:             $send_msg_link ='<br />'.
                   1146:                 &Apache::loncommon::messagewrapper(&mt('Send message'),
                   1147:                                                    $docslog{$id}{'exe_uname'},
                   1148:                                                    $docslog{$id}{'exe_udom'});
                   1149:         }
                   1150:         $r->print(&Apache::loncommon::start_data_table_row());
                   1151:         $r->print('<td>'.$time.'</td>
                   1152:                        <td>'.$about_me_link.
                   1153:                   '<br /><tt>'.$docslog{$id}{'exe_uname'}.
                   1154:                                   ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
                   1155:                   $send_msg_link.'</td><td>'.
                   1156:                   $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488     raeburn  1157:         my $is_supp = 0; 
                   1158:         if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
                   1159:             $is_supp = 1;
                   1160:         }
1.329     droeschl 1161: # Before
                   1162: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1163: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                   1164: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                   1165: 	    if ($oldname ne $newname) {
1.488     raeburn  1166:                 my $shown = &LONCAPA::map::qtescape($oldname);
                   1167:                 if ($is_supp) {
                   1168:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   1169:                 }
                   1170:                 $r->print($shown);
1.329     droeschl 1171: 	    }
                   1172: 	}
                   1173: 	$r->print('<ul>');
                   1174: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1175:             if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488     raeburn  1176:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
                   1177:                 if ($is_supp) {
                   1178:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   1179:                 }
                   1180: 		$r->print('<li>'.$shown.'</li>');
1.329     droeschl 1181: 	    }
                   1182: 	}
                   1183: 	$r->print('</ul>');
                   1184: # After
                   1185:         $r->print('</td><td>');
                   1186: 
                   1187: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1188: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                   1189: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                   1190: 	    if ($oldname ne '' && $oldname ne $newname) {
1.488     raeburn  1191:                 my $shown = &LONCAPA::map::qtescape($newname);
                   1192:                 if ($is_supp) {
                   1193:                     $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
                   1194:                 }
                   1195:                 $r->print($shown);
1.329     droeschl 1196: 	    }
1.364     bisitz   1197: 	}
1.329     droeschl 1198: 	$r->print('<ul>');
                   1199: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1200:             if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488     raeburn  1201:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
                   1202:                 if ($is_supp) {
                   1203:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   1204:                 }
                   1205:                 $r->print('<li>'.$shown.'</li>');
1.329     droeschl 1206: 	    }
                   1207: 	}
                   1208: 	$r->print('</ul>');
                   1209: 	if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693     raeburn  1210:             my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
                   1211:             if ($title eq '') {
                   1212:                 ($title) = ($url =~ m{/([^/]+)$});
1.695     raeburn  1213:             } elsif ($is_supp) {
                   1214:                 $title = &Apache::loncommon::parse_supplemental_title($title);
1.693     raeburn  1215:             }
                   1216:             $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645     raeburn  1217: 	    foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329     droeschl 1218: 		if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452     www      1219: # FIXME: internationalization seems wrong here
1.329     droeschl 1220: 		    $r->print('<li>'.
                   1221: 			      &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
                   1222: 				  $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
                   1223: 			      .'</li>');
                   1224: 		}
                   1225: 	    }
                   1226: 	    $r->print('</ul>');
                   1227: 	}
                   1228: # End
                   1229:         $r->print('</td>'.&Apache::loncommon::end_data_table_row());
                   1230:         $shown++;
                   1231:         if (!($env{'form.show'} eq &mt('all')
                   1232:               || $shown<=$env{'form.show'})) { last; }
                   1233:     }
1.484     raeburn  1234:     $r->print(&Apache::loncommon::end_data_table()."\n".
                   1235:               &makesimpleeditform($pathitem)."\n".
                   1236:               '</div></div>');
                   1237:     $r->print(&endContentScreen());
1.329     droeschl 1238: }
                   1239: 
                   1240: sub update_paste_buffer {
1.492     raeburn  1241:     my ($coursenum,$coursedom,$folder) = @_;
1.591     raeburn  1242:     my (@possibles,%removals,%cuts,$output);
1.538     raeburn  1243:     if ($env{'form.multiremove'}) {
                   1244:         $env{'form.multiremove'} =~ s/,$//;
                   1245:         map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
                   1246:     }
                   1247:     if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
                   1248:         if ($env{'form.multicut'}) {
                   1249:             $env{'form.multicut'} =~ s/,$//;
                   1250:             foreach my $item (split(/,/,$env{'form.multicut'})) {
                   1251:                 unless ($removals{$item}) {
                   1252:                     $cuts{$item} = 1;
                   1253:                     push(@possibles,$item.':cut');
                   1254:                 }
                   1255:             }
                   1256:         }
                   1257:         if ($env{'form.multicopy'}) {
                   1258:             $env{'form.multicopy'} =~ s/,$//;
                   1259:             foreach my $item (split(/,/,$env{'form.multicopy'})) {
                   1260:                 unless ($removals{$item} || $cuts{$item}) {
                   1261:                     push(@possibles,$item.':copy'); 
                   1262:                 }
                   1263:             }
                   1264:         }
                   1265:     } elsif ($env{'form.markcopy'}) {
                   1266:         @possibles = split(/,/,$env{'form.markcopy'});
                   1267:     }
1.329     droeschl 1268: 
1.538     raeburn  1269:     return if (@possibles == 0);
1.329     droeschl 1270:     return if (!defined($env{'form.copyfolder'}));
                   1271: 
                   1272:     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   1273: 				    $env{'form.copyfolder'});
1.538     raeburn  1274:     return if ($fatal);
                   1275: 
                   1276:     my %curr_groups = &Apache::longroup::coursegroups();
1.364     bisitz   1277: 
1.538     raeburn  1278: # Retrieve current paste buffer suffixes.
                   1279:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   1280:     my (%pasteurls,@newpaste);
                   1281: 
                   1282: # Construct identifiers for current contents of user's paste buffer
                   1283:     if (@currpaste) {
                   1284:         foreach my $suffix (@currpaste) {
1.667     raeburn  1285:             my $cid = $env{'docs.markedcopy_crs_'.$suffix};
                   1286:             my $url = $env{'docs.markedcopy_url_'.$suffix};
                   1287:             my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
                   1288:             if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
                   1289:                 ($url ne '')) {
                   1290:                 if ($url eq '/res/lib/templates/simpleproblem.problem') {
                   1291:                     $pasteurls{$cid.'_'.$mapidx} = 1;
                   1292:                 } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
                   1293:                     $pasteurls{$url} = 1;
                   1294:                 } else {
1.669     raeburn  1295:                     $pasteurls{$cid.'_'.$url} = 1;
1.667     raeburn  1296:                 }
                   1297:             }
1.538     raeburn  1298:         }
                   1299:     }
                   1300: 
                   1301: # Mark items for copying (skip any items already in user's paste buffer)
                   1302:     my %addtoenv;
1.597     raeburn  1303: 
                   1304:     my @pathitems = split(/\&/,$env{'form.folderpath'});
                   1305:     my @folderconf = split(/\:/,$pathitems[-1]);
1.666     raeburn  1306:     my $ispage = $folderconf[5];
1.597     raeburn  1307: 
1.538     raeburn  1308:     foreach my $item (@possibles) {
                   1309:         my ($orderidx,$cmd) = split(/:/,$item);
                   1310:         next if ($orderidx =~ /\D/);
                   1311:         next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597     raeburn  1312:         my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538     raeburn  1313:         my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
                   1314:         my %denied = &action_restrictions($coursenum,$coursedom,
                   1315:                                           &LONCAPA::map::qtescape($url),
                   1316:                                           $env{'form.folderpath'},\%curr_groups);
                   1317:         next if ($denied{'copy'});
                   1318:         $url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.667     raeburn  1319:         if ($url eq '/res/lib/templates/simpleproblem.problem') {
                   1320:             next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
                   1321:         } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
                   1322:             next if (exists($pasteurls{$url}));
                   1323:         } else {
                   1324:             next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
                   1325:         }
1.538     raeburn  1326:         my ($suffix,$errortxt,$locknotfreed) =
                   1327:             &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591     raeburn  1328:         if ($suffix ne '') {
                   1329:             push(@newpaste,$suffix);
                   1330:         } else {
                   1331:             if ($locknotfreed) {
                   1332:                 return $locknotfreed;
                   1333:             }
1.538     raeburn  1334:         }
                   1335:         if (&is_supplemental_title($title)) {
                   1336:             &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
                   1337: 	    ($title) = &Apache::loncommon::parse_supplemental_title($title);
                   1338:         }
1.329     droeschl 1339: 
1.538     raeburn  1340:         $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
                   1341:         $addtoenv{'docs.markedcopy_url_'.$suffix}   = $url,
                   1342:         $addtoenv{'docs.markedcopy_cmd_'.$suffix}   = $cmd,
                   1343:         $addtoenv{'docs.markedcopy_crs_'.$suffix}   = $env{'request.course.id'};
1.597     raeburn  1344:         $addtoenv{'docs.markedcopy_map_'.$suffix}   = $mapidx;
1.538     raeburn  1345:         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
                   1346:             my $prefix = $1;
                   1347:             my $subdir =$2;
                   1348:             if ($subdir eq '') {
                   1349:                 $subdir = $prefix;
1.492     raeburn  1350:             }
1.538     raeburn  1351:             my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627     raeburn  1352:             &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
                   1353:                                  \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538     raeburn  1354:             if (ref($hierarchy{$url}) eq 'HASH') {
                   1355:                 my ($nested,$nestednames);
                   1356:                 &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
                   1357:                 $nested =~ s/\&$//;
                   1358:                 $nestednames =~ s/\Q___&&&___\E$//;
                   1359:                 if ($nested ne '') {
                   1360:                     $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
                   1361:                 }
                   1362:                 if ($nestednames ne '') {
                   1363:                     $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
                   1364:                 }
1.492     raeburn  1365:             }
                   1366:         }
1.591     raeburn  1367:         if ($locknotfreed) {
                   1368:             $output = $locknotfreed;
                   1369:             last;
                   1370:         }
1.492     raeburn  1371:     }
1.538     raeburn  1372:     if (@newpaste) {
                   1373:         $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
                   1374:     }
1.492     raeburn  1375:     &Apache::lonnet::appenv(\%addtoenv);
1.329     droeschl 1376:     delete($env{'form.markcopy'});
1.591     raeburn  1377:     return $output;
1.329     droeschl 1378: }
                   1379: 
1.492     raeburn  1380: sub recurse_uploaded_maps {
                   1381:     my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
                   1382:     if (ref($hierarchy->{$url}) eq 'HASH') {
                   1383:         my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
                   1384:         my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
                   1385:         my (@uploaded,@names,%shorter);
                   1386:         for (my $i=0; $i<@maps; $i++) {
                   1387:             my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
                   1388:             if ($inner ne '') {
                   1389:                 push(@uploaded,$inner);
                   1390:                 push(@names,&escape($titles[$i]));
                   1391:                 $shorter{$maps[$i]} = $inner;
                   1392:             }
                   1393:         }
                   1394:         $$nestref .= "$dir:".join(',',@uploaded).'&';
                   1395:         $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
                   1396:         foreach my $map (@maps) {
                   1397:             if ($shorter{$map} ne '') {
                   1398:                 &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
                   1399:             }
                   1400:         }
                   1401:     }
                   1402:     return;
                   1403: }
                   1404: 
1.329     droeschl 1405: sub print_paste_buffer {
1.492     raeburn  1406:     my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538     raeburn  1407:     return if (!defined($env{'docs.markedcopies'}));
1.329     droeschl 1408: 
1.538     raeburn  1409:     unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
                   1410:         return if ($env{'docs.markedcopies'} eq '');
1.488     raeburn  1411:     }
                   1412: 
1.538     raeburn  1413:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   1414:     my ($pasteitems,@pasteable);
1.575     raeburn  1415:     my $clipboardcount = 0;
1.488     raeburn  1416: 
1.538     raeburn  1417: # Construct identifiers for current contents of user's paste buffer
                   1418:     foreach my $suffix (@currpaste) {
                   1419:         next if ($suffix =~ /\D/);
                   1420:         my $cid = $env{'docs.markedcopy_crs_'.$suffix};
                   1421:         my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597     raeburn  1422:         my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538     raeburn  1423:         if (($cid =~ /^$match_domain\_$match_courseid$/) &&
                   1424:             ($url ne '')) {
1.575     raeburn  1425:             $clipboardcount ++;
1.538     raeburn  1426:             my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598     raeburn  1427:                 $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538     raeburn  1428:             my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
                   1429:             if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
                   1430:                 $is_external = 1;
1.626     raeburn  1431:             } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598     raeburn  1432:                 $is_exttool = 1;
1.538     raeburn  1433:             }
                   1434:             if ($folder =~ /^supplemental/) {
                   1435:                 $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
                   1436:                 unless ($canpaste) {
                   1437:                     $nopaste = &mt('Paste into Supplemental Content unavailable.');
                   1438:                 }
                   1439:             } else {
                   1440:                 $canpaste = 1;
                   1441:             }
                   1442:             if ($canpaste) {
                   1443:                 if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
                   1444:                     my $srcdom = $1;
                   1445:                     my $srcnum = $2;
                   1446:                     my $rem = $3;
                   1447:                     if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
                   1448:                         $othercourse = 1;
                   1449:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596     raeburn  1450:                             $othercrs = '<br />'.&mt('(from another course)');
1.538     raeburn  1451:                         } else {
                   1452:                             $canpaste = 0;
                   1453:                             $nopaste = &mt('Paste from another course unavailable.'); 
                   1454:                         }
                   1455:                     }
                   1456:                     if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
                   1457:                         my $prefix = $1;
                   1458:                         $parent = $2;
                   1459:                         if ($folder !~ /^\Q$prefix\E/) {
                   1460:                             $areachange = 1;
                   1461:                         }
                   1462:                         $is_uploaded_map = 1;
1.492     raeburn  1463:                     }
1.597     raeburn  1464:                 } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627     raeburn  1465:                          ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596     raeburn  1466:                     if ($cid ne $env{'request.course.id'}) {
                   1467:                         my ($srcdom,$srcnum) = split(/_/,$cid);
                   1468:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627     raeburn  1469:                             if (($is_exttool) && ($srcdom ne $coursedom)) {
                   1470:                                 $canpaste = 0;
                   1471:                                 $nopaste = &mt('Paste from another domain unavailable.');
                   1472:                             } else {
                   1473:                                 $othercrs = '<br />'.&mt('(from another course)');
                   1474:                             }
1.596     raeburn  1475:                         } else {
                   1476:                             $canpaste = 0;
                   1477:                             $nopaste = &mt('Paste from another course unavailable.');
1.629     raeburn  1478:                         }
1.596     raeburn  1479:                     }
1.492     raeburn  1480:                 }
1.596     raeburn  1481:                 if ($canpaste) {
                   1482:                     push(@pasteable,$suffix);
1.629     raeburn  1483:                 }
1.538     raeburn  1484:             }
                   1485:             my $buffer;
1.627     raeburn  1486:             if ($is_external) {
1.538     raeburn  1487:                 $buffer = &mt('External Resource').': '.
                   1488:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
                   1489:                     &LONCAPA::map::qtescape($url).')';
1.627     raeburn  1490:             } elsif ($is_exttool) {
                   1491:                 $buffer = &mt('External Tool').': '.
                   1492:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538     raeburn  1493:             } else {
                   1494:                 my $icon = &Apache::loncommon::icon($extension);
                   1495:                 if ($extension eq 'sequence' &&
                   1496:                     $url =~ m{/default_\d+\.sequence$}x) {
                   1497:                     $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
                   1498:                     $icon .= '/navmap.folder.closed.gif';
                   1499:                 }
1.589     raeburn  1500:                 my $title = $env{'docs.markedcopy_title_'.$suffix};
                   1501:                 if ($title eq '') {
                   1502:                     ($title) = ($url =~ m{/([^/]+)$});
                   1503:                 }
1.538     raeburn  1504:                 $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
                   1505:                           ': '.
                   1506:                           &Apache::loncommon::parse_supplemental_title(
1.589     raeburn  1507:                              &LONCAPA::map::qtescape($title));
1.538     raeburn  1508:             }
                   1509:             $pasteitems .= '<div class="LC_left_float">';
                   1510:             my ($options,$onclick);
                   1511:             if (($canpaste) && (!$areachange) && (!$othercourse) &&
                   1512:                 ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
                   1513:                 if (($is_uploaded_map) ||
                   1514:                     ($url =~ /(bulletinboard|smppg)$/) ||
                   1515:                     ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
                   1516:                     $options = &paste_options($suffix,$is_uploaded_map,$parent);
                   1517:                     $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
                   1518:                 }
                   1519:             }
                   1520:             $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
                   1521:             if ($nopaste) {
1.681     raeburn  1522:                  $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';   
1.538     raeburn  1523:             } else {
                   1524:                 if ($othercrs) {
                   1525:                     $pasteitems .= $othercrs;
                   1526:                 }
                   1527:                 if ($options) {
                   1528:                     $pasteitems .= $options;
1.492     raeburn  1529:                 }
                   1530:             }
1.538     raeburn  1531:             $pasteitems .= '</div>';
                   1532:         }
                   1533:     }
                   1534:     if ($pasteitems eq '') {
                   1535:         &Apache::lonnet::delenv('docs.markedcopies');
                   1536:     }
                   1537:     my ($pasteform,$form_start,$buttons,$form_end);
                   1538:     if ($pasteitems) {
                   1539:         $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541     raeburn  1540:         $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538     raeburn  1541:         if (@pasteable) {
1.575     raeburn  1542:             my $value = &mt('Paste to current folder');
                   1543:             if ($container eq 'page') {
                   1544:                 $value = &mt('Paste to current page');
                   1545:             } 
                   1546:             $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.('&nbsp;'x2);
                   1547:         }
                   1548:         $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.('&nbsp;'x2);
                   1549:         if ($clipboardcount > 1) {
                   1550:             $buttons .=
                   1551:                 '<span style="text-decoration:line-through">'.('&nbsp;'x20).'</span>'.('&nbsp;'x2).
                   1552:                 '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
                   1553:                 ('&nbsp;'x2).
                   1554:                 '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
                   1555:                 ('&nbsp;'x2);
1.492     raeburn  1556:         }
1.575     raeburn  1557:         $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
                   1558:                     '</form>';
1.538     raeburn  1559:     } else {
                   1560:         $pasteitems = &mt('Clipboard is empty');
1.488     raeburn  1561:     }
1.538     raeburn  1562:     $r->print($form_start
                   1563:              .'<fieldset>'
                   1564:              .'<legend>'.&mt('Clipboard').('&nbsp;' x2).$buttons.'</legend>'
                   1565:              .$pasteitems
                   1566:              .'</fieldset>'
                   1567:              .$form_end);
                   1568: }
                   1569: 
                   1570: sub paste_options {
                   1571:     my ($suffix,$is_uploaded_map,$parent) = @_;
                   1572:     my ($copytext,$movetext);
                   1573:     if ($is_uploaded_map) {
                   1574:         $copytext = &mt('Copy to new folder');
                   1575:         $movetext = &mt('Move old');
                   1576:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
                   1577:         $copytext = &mt('Copy to new board');
                   1578:         $movetext = &mt('Move (not posts)');
                   1579:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
                   1580:         $copytext = &mt('Copy to new page');
                   1581:         $movetext = &mt('Move');
1.533     raeburn  1582:     } else {
1.538     raeburn  1583:         $copytext = &mt('Copy to new file');
                   1584:         $movetext = &mt('Move');
                   1585:     }
                   1586:     my $output = '<br />'.
                   1587:                  '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
                   1588:                  '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.('&nbsp;'x 4).
                   1589:                  '<label>'.
                   1590:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
                   1591:                  $copytext.'</label></span>'.('&nbsp;'x2).' '.
                   1592:                  '<span class="LC_nobreak"><label>'.
                   1593:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
                   1594:                  $movetext.'</label></span>';
                   1595:     if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
                   1596:         $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
                   1597:                    '</legend><table border="0">';
                   1598:         my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   1599:         my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
                   1600:         my $lastdir = $parent;
                   1601:         my %depths = (
                   1602:                        $lastdir => 0,
                   1603:                      );
                   1604:         my (%display,%deps);
                   1605:         for (my $i=0; $i<@pastemaps; $i++) {
                   1606:             ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
                   1607:             my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
                   1608:             my @subfolders = split(/,/,$subfolderstr);
                   1609:             $deps{$lastdir} = \@subfolders;
                   1610:             my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
                   1611:             my $depth = $depths{$lastdir} + 1;
                   1612:             my $offset = int($depth * 4);
                   1613:             my $indent = ('&nbsp;' x $offset);
                   1614:             for (my $j=0; $j<@subfolders; $j++) {
                   1615:                 $depths{$subfolders[$j]} = $depth;
                   1616:                 $display{$subfolders[$j]} =
                   1617:                     '<tr><td>'.$indent.$subfoldertitles[$j].'&nbsp;</td>'.
                   1618:                     '<td><label>'.
                   1619:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.('&nbsp;' x2).
                   1620:                     '<label>'.
                   1621:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
                   1622:                     &mt('Move old').'</label>'.
                   1623:                     '</td></tr>';
                   1624:              }
1.492     raeburn  1625:         }
1.538     raeburn  1626:         &recurse_print(\$output,$parent,\%deps,\%display);
                   1627:         $output .= '</table></fieldset>';
1.329     droeschl 1628:     }
1.538     raeburn  1629:     $output .= '</div>';
                   1630:     return $output;
1.488     raeburn  1631: }
                   1632: 
1.492     raeburn  1633: sub recurse_print {
1.538     raeburn  1634:     my ($outputref,$dir,$deps,$display) = @_;
                   1635:     $$outputref .= $display->{$dir}."\n";
1.492     raeburn  1636:     if (ref($deps->{$dir}) eq 'ARRAY') {
                   1637:         foreach my $subdir (@{$deps->{$dir}}) {
1.538     raeburn  1638:             &recurse_print($outputref,$subdir,$deps,$display);
1.492     raeburn  1639:         }
                   1640:     }
                   1641: }
                   1642: 
1.488     raeburn  1643: sub supp_pasteable {
                   1644:     my ($url) = @_;
                   1645:     if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//}) ||
                   1646:         (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
                   1647:         ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
                   1648:         ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598     raeburn  1649:         ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626     raeburn  1650:         ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488     raeburn  1651:         return 1;
                   1652:     }
                   1653:     return;
1.329     droeschl 1654: }
                   1655: 
1.492     raeburn  1656: sub paste_popup_js {
1.594     damieng  1657:     my %html_js_lt = &Apache::lonlocal::texthash(
1.538     raeburn  1658:                                           show => 'Show Options',
                   1659:                                           hide => 'Hide Options',
1.594     damieng  1660:                                         );
                   1661:     my %js_lt = &Apache::lonlocal::texthash(
1.541     raeburn  1662:                                           none => 'No items selected from clipboard.',
1.492     raeburn  1663:                                         );
1.594     damieng  1664:     &html_escape(\%html_js_lt);
                   1665:     &js_escape(\%html_js_lt);
                   1666:     &js_escape(\%js_lt);
1.492     raeburn  1667:     return <<"END";
                   1668: 
1.538     raeburn  1669: function showPasteOptions(suffix) {
                   1670:     document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594     damieng  1671:     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  1672:     return;
                   1673: }
                   1674: 
1.538     raeburn  1675: function hidePasteOptions(suffix) {
                   1676:     document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594     damieng  1677:     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  1678:     return;
                   1679: }
                   1680: 
                   1681: function showOptions(caller,suffix) {
                   1682:     if (document.getElementById('pasteoptionstext_'+suffix)) {
                   1683:         if (caller.checked) {
1.594     damieng  1684:             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  1685:         } else {
                   1686:             document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
                   1687:         }
                   1688:         if (document.getElementById('pasteoptions_'+suffix)) {
                   1689:             document.getElementById('pasteoptions_'+suffix).style.display='none';
                   1690:         }
                   1691:     }
1.492     raeburn  1692:     return;
                   1693: }
                   1694: 
1.541     raeburn  1695: function validateClipboard() {
                   1696:     var numchk = 0;
                   1697:     if (document.pasteform.pasting.length > 1) {
                   1698:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1699:             if (document.pasteform.pasting[i].checked) {
                   1700:                 numchk ++;
                   1701:             }
                   1702:         }
                   1703:     } else {
                   1704:         if (document.pasteform.pasting.type == 'checkbox') {
                   1705:             if (document.pasteform.pasting.checked) {
                   1706:                 numchk ++; 
                   1707:             } 
                   1708:         }
                   1709:     }
                   1710:     if (numchk > 0) { 
                   1711:         return true;
                   1712:     } else {
1.594     damieng  1713:         alert("$js_lt{'none'}");
1.541     raeburn  1714:         return false;
                   1715:     }
                   1716: }
                   1717: 
1.575     raeburn  1718: function checkClipboard() {
                   1719:     if (document.pasteform.pasting.length > 1) {
                   1720:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1721:             document.pasteform.pasting[i].checked = true;
                   1722:         } 
                   1723:     }
                   1724:     return;
                   1725: }
                   1726: 
                   1727: function uncheckClipboard() {
                   1728:     if (document.pasteform.pasting.length >1) {
                   1729:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1730:             document.pasteform.pasting[i].checked = false;
                   1731:         }
                   1732:     }
                   1733:     return;
                   1734: }
                   1735: 
1.492     raeburn  1736: END
                   1737: 
                   1738: }
                   1739: 
1.329     droeschl 1740: sub do_paste_from_buffer {
1.492     raeburn  1741:     my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329     droeschl 1742: 
1.538     raeburn  1743: # Array of items in paste buffer
                   1744:     my (@currpaste,%pastebuffer,%allerrors);
                   1745:     @currpaste = split(/,/,$env{'docs.markedcopies'});
                   1746: 
1.492     raeburn  1747: # Early out if paste buffer is empty
1.538     raeburn  1748:     if (@currpaste == 0) {
1.492     raeburn  1749:         return ();
1.538     raeburn  1750:     } 
                   1751:     map { $pastebuffer{$_} = 1; } @currpaste;
                   1752: 
                   1753: # Array of items selected items to paste
                   1754:     my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
                   1755: 
                   1756: # Early out if nothing selected to paste
                   1757:     if (@reqpaste == 0) {
                   1758:         return();
                   1759:     }
                   1760:     my @topaste;
                   1761:     foreach my $suffix (@reqpaste) {
                   1762:         next if ($suffix =~ /\D/);
                   1763:         next unless (exists($pastebuffer{$suffix}));
                   1764:         push(@topaste,$suffix);
                   1765:     }
                   1766: 
                   1767: # Early out if nothing available to paste
                   1768:     if (@topaste == 0) {
                   1769:         return();
1.329     droeschl 1770:     }
                   1771: 
1.627     raeburn  1772:     my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597     raeburn  1773:         %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538     raeburn  1774: 
                   1775:     foreach my $suffix (@topaste) {
                   1776:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596     raeburn  1777:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597     raeburn  1778:         my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix}); 
1.492     raeburn  1779: # Supplemental content may only include certain types of content
                   1780: # Early out if pasted content is not supported in Supplemental area
1.538     raeburn  1781:         if ($folder =~ /^supplemental/) {
                   1782:             unless (&supp_pasteable($url)) {
                   1783:                 $notinsupp{$suffix} = 1;
                   1784:                 next;
                   1785:             }
1.492     raeburn  1786:         }
1.538     raeburn  1787:         if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
                   1788:             my $srcd = $1;
                   1789:             my $srcn = $2;
1.492     raeburn  1790: # When paste buffer was populated using an active role in a different course
1.538     raeburn  1791: # check for mdc privilege in the course from which the resource was pasted
                   1792:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   1793:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   1794:                     $notincrs{$suffix} = 1;
                   1795:                     next;
                   1796:                 }
1.491     raeburn  1797:             }
1.538     raeburn  1798:             $srcdom{$suffix} = $srcd;
                   1799:             $srcnum{$suffix} = $srcn;
1.597     raeburn  1800:         } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632     raeburn  1801:                  ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
                   1802:                  ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596     raeburn  1803:             my ($srcd,$srcn) = split(/_/,$cid);
                   1804: # When paste buffer was populated using an active role in a different course
                   1805: # check for mdc privilege in the course from which the resource was pasted
                   1806:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   1807:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   1808:                     $notincrs{$suffix} = 1;
                   1809:                     next;
                   1810:                 }
                   1811:             }
1.632     raeburn  1812: # When buffer was populated using an active role in a different course
                   1813: # disallow pasting of External Tool if course is in a different domain.
                   1814:             if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627     raeburn  1815:                 $notindom{$suffix} = 1;
                   1816:                 next;
                   1817:             }
1.596     raeburn  1818:             $srcdom{$suffix} = $srcd;
                   1819:             $srcnum{$suffix} = $srcn;
1.491     raeburn  1820:         }
1.597     raeburn  1821:         $srcmapidx{$suffix} = $mapidx;
1.538     raeburn  1822:         push(@dopaste,$suffix);
                   1823:         if ($url=~/\.(page|sequence)$/) {
                   1824:             $is_map{$suffix} = 1; 
                   1825:         }
                   1826:         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
                   1827:             my $oldprefix = $1;
1.492     raeburn  1828: # When pasting content from Main Content to Supplemental Content and vice versa 
                   1829: # URLs will contain different paths (which depend on whether pasted item is
1.597     raeburn  1830: # a folder/page or a document).
1.538     raeburn  1831:             if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
                   1832:                 $prefixchg{$suffix} = 'docstosupp';
                   1833:             } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
                   1834:                 $prefixchg{$suffix} = 'supptodocs';
                   1835:             }
1.491     raeburn  1836: 
1.492     raeburn  1837: # If pasting an uploaded map, get list of contained uploaded maps.
1.538     raeburn  1838:             if ($env{'docs.markedcopy_nested_'.$suffix}) {
                   1839:                 my @nested;
                   1840:                 my ($type) = ($oldprefix =~ /^(default|supplemental)/);
                   1841:                 my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   1842:                 my @deps = map { /\d+:([\d,]+$)/ } @items;
                   1843:                 foreach my $dep (@deps) {
                   1844:                     if ($dep =~ /,/) {
                   1845:                         push(@nested,split(/,/,$dep));
                   1846:                     } else {
                   1847:                         push(@nested,$dep);
                   1848:                     }
1.492     raeburn  1849:                 }
1.538     raeburn  1850:                 foreach my $item (@nested) {
                   1851:                     if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
                   1852:                         push(@{$marktomove{$suffix}},$type.'_'.$item);
                   1853:                     }
1.492     raeburn  1854:                 }
                   1855:             }
1.488     raeburn  1856:         }
                   1857:     }
                   1858: 
1.538     raeburn  1859: # Early out if nothing available to paste
                   1860:     if (@dopaste == 0) {
                   1861:         return ();
                   1862:     }
                   1863: 
                   1864: # Populate message hash and hashes used for main content <=> supplemental content
                   1865: # changes    
                   1866: 
                   1867:     %msgs = &Apache::lonlocal::texthash (
                   1868:                 notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
                   1869:                 notincrs  => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661     raeburn  1870:                 notindom  => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538     raeburn  1871:                 duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
                   1872:             );
                   1873: 
                   1874:     %before = (
                   1875:                  docstosupp => {
                   1876:                                    map => 'default',
                   1877:                                    doc => 'docs',
                   1878:                                },
                   1879:                  supptodocs => {
                   1880:                                    map => 'supplemental',
                   1881:                                    doc => 'supplemental',
                   1882:                                },
                   1883:               );
                   1884: 
                   1885:     %after = (
                   1886:                  docstosupp => {
                   1887:                                    map => 'supplemental',
                   1888:                                    doc => 'supplemental'
                   1889:                                },
                   1890:                  supptodocs => {
                   1891:                                    map => 'default',
                   1892:                                    doc => 'docs',
                   1893:                                },
                   1894:              );
                   1895: 
                   1896: # Retrieve information about all course maps in main content area 
                   1897: 
                   1898:     my $allmaps = {};
1.660     raeburn  1899:     my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538     raeburn  1900: 
                   1901: # Loop over the items to paste
                   1902:     foreach my $suffix (@dopaste) {
1.329     droeschl 1903: # Maps need to be copied first
1.538     raeburn  1904:         my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
                   1905:             %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597     raeburn  1906:             %newurls,%tomove,%resdatacopy);
1.538     raeburn  1907:         if (ref($marktomove{$suffix}) eq 'ARRAY') {
                   1908:             map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
                   1909:         }
                   1910:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
                   1911:         my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596     raeburn  1912:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); 
1.538     raeburn  1913:         my $oldurl = $url;
                   1914:         if ($is_map{$suffix}) {
1.491     raeburn  1915: # If pasting a map, check if map contains other maps
1.538     raeburn  1916:             my (%hierarchy,%titles);
1.660     raeburn  1917:             if (($folder =~ /^default/) && (!$donechk)) {
                   1918:                 $allmaps =
                   1919:                     &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                   1920:                                                          $env{"course.$env{'request.course.id'}.home"},
                   1921:                                                          $env{'request.course.id'});
                   1922:                 $donechk = 1;
                   1923:             }
1.627     raeburn  1924:             &contained_map_check($url,$folder,$coursenum,$coursedom,
                   1925:                                  \%removefrommap,\%removeparam,\%addedmaps,
                   1926:                                  \%hierarchy,\%titles,$allmaps);
1.538     raeburn  1927:             if ($url=~ m{^/uploaded/}) {
                   1928:                 my $newurl;
                   1929:                 unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   1930:                     ($newurl,my $error) = 
                   1931:                         &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
                   1932:                                         $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   1933:                                         \$title,$allmaps,\%newurls);
                   1934:                     if ($error) {
                   1935:                         $allerrors{$suffix} = $error;
                   1936:                         next;
                   1937:                     }
                   1938:                     if ($newurl ne '') {
                   1939:                         if ($newurl ne $url) {
                   1940:                             if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
                   1941:                                 $newsubdir{$url} = $1;
                   1942:                             }
                   1943:                             $mapchanges{$url} = 1;
1.492     raeburn  1944:                         }
1.538     raeburn  1945:                     }
                   1946:                 }
                   1947:                 if (($srcdom{$suffix} ne $coursedom) ||
                   1948:                     ($srcnum{$suffix} ne $coursenum) ||
                   1949:                     ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
                   1950:                     unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
                   1951:                                               $coursedom,$coursenum,$srcdom{$suffix},
                   1952:                                               $srcnum{$suffix},$allmaps,\%rewrites,
                   1953:                                               \%retitles,\%copies,\%dbcopies,
                   1954:                                               \%zombies,\%params,\%mapmoves,
                   1955:                                               \%mapchanges,\%tomove,\%newsubdir,
1.597     raeburn  1956:                                               \%newurls,\%resdatacopy)) {
1.538     raeburn  1957:                         $mapmoves{$url} = 1;
                   1958:                     }
                   1959:                     $url = $newurl;
                   1960:                 } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
                   1961:                     &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
                   1962:                                       $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   1963:                                       $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
                   1964:                                       \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597     raeburn  1965:                                       \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538     raeburn  1966:                 }
                   1967:             } elsif ($url=~m {^/res/}) {
1.597     raeburn  1968: # published map can only exist once, so remove from paste buffer when done
1.538     raeburn  1969:                 push(@toclear,$suffix);
                   1970: # if pasting published map (main content area only) check map not already in course
                   1971:                 if ($folder =~ /^default/) {
                   1972:                     if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
                   1973:                         $duplicate{$suffix} = 1; 
                   1974:                         next;
1.492     raeburn  1975:                     }
1.491     raeburn  1976:                 }
                   1977:             }
1.538     raeburn  1978:         }
1.627     raeburn  1979:         if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538     raeburn  1980:             my $prefix = $1;
1.648     raeburn  1981:             my $fromothercrs;
1.538     raeburn  1982:             #need to copy the db contents to a new one, unless this is a move.
                   1983:             my %info = (
                   1984:                          src  => $url,
                   1985:                          cdom => $coursedom,
                   1986:                          cnum => $coursenum,
1.596     raeburn  1987:                        );
1.649     raeburn  1988:             if ($prefix eq 'ext.tool') {
1.655     raeburn  1989:                 if ($prefixchg{$suffix} eq 'docstosupp') {
1.649     raeburn  1990:                     $info{'delgradable'} = 1;
                   1991:                 }
                   1992:             }
1.596     raeburn  1993:             if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
                   1994:                 unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
                   1995:                     $fromothercrs = 1;
                   1996:                     $info{'cdom'} = $srcdom{$suffix};
                   1997:                     $info{'cnum'} = $srcnum{$suffix};
                   1998:                 }
                   1999:             }
                   2000:             unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630     raeburn  2001:                 my (%lockerr,$msg);
1.538     raeburn  2002:                 my ($newurl,$result,$errtext) =
                   2003:                     &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
                   2004:                 if ($result eq 'ok') {
                   2005:                     $url = $newurl;
                   2006:                     $title=&mt('Copy of').' '.$title;
                   2007:                 } else {
                   2008:                     if ($prefix eq 'smppg') {
                   2009:                         $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
                   2010:                     } elsif ($prefix eq 'bulletinboard') {
1.565     bisitz   2011:                         $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627     raeburn  2012:                     } elsif ($prefix eq 'ext.tool') {
                   2013:                         $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538     raeburn  2014:                     }
                   2015:                     $results{$suffix} = $result;
                   2016:                     $msgerrs{$suffix} = $msg;
                   2017:                     $lockerrs{$suffix} = $lockerr{$prefix}; 
                   2018:                     next;
                   2019: 	        }
                   2020:                 if ($lockerr{$prefix}) {
                   2021:                     $lockerrs{$suffix} = $lockerr{$prefix};  
1.491     raeburn  2022:                 }
1.489     raeburn  2023:             }
                   2024:         }
1.538     raeburn  2025:         $title = &LONCAPA::map::qtunescape($title);
                   2026:         my $ext='false';
                   2027:         if ($url=~m{^http(|s)://}) { $ext='true'; }
                   2028:         if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
                   2029:             if ($folder !~ /^supplemental/) {
                   2030:                 (undef,undef,$title) =
                   2031:                     &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
                   2032:             }
                   2033:         } else {
                   2034:             if ($folder=~/^supplemental/) {
                   2035:                 $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   2036:                        $env{'user.domain'}.'___&&&___'.$title;
1.491     raeburn  2037:             }
1.533     raeburn  2038:         }
1.491     raeburn  2039: 
                   2040: # For uploaded files (excluding pages/sequences) path in copied file is changed
                   2041: # if paste is from Main to Supplemental (or vice versa), or if pasting between
                   2042: # courses.
                   2043: 
1.538     raeburn  2044:         unless ($is_map{$suffix}) {
                   2045:             my $newidx;
1.492     raeburn  2046: # Now insert the URL at the bottom
1.538     raeburn  2047:             $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   2048:             if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
                   2049:                 my $relpath = $1;
                   2050:                 if ($relpath ne '') {
                   2051:                     my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
                   2052:                     my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
                   2053:                     my $newprefix = $newloc;
                   2054:                     if ($newloc eq 'default') {
                   2055:                         $newprefix = 'docs';
                   2056:                     }
                   2057:                     if ($newdocsdir eq '') {
                   2058:                         $newdocsdir = 'default';
                   2059:                     }
1.630     raeburn  2060:                     if (($prefixchg{$suffix}) ||
                   2061:                         ($srcdom{$suffix} ne $coursedom) ||
1.538     raeburn  2062:                         ($srcnum{$suffix} ne $coursenum) ||
                   2063:                         ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
                   2064:                         my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
                   2065:                         $url =
                   2066:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
                   2067:                                                                &Apache::lonnet::getfile($oldurl));
                   2068:                         if ($url eq '/adm/notfound.html') {
                   2069:                             $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
                   2070:                             next;
                   2071:                         } else {
                   2072:                             my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
                   2073:                             $newsubpath =~ s{/+$}{/};
                   2074:                             $docmoves{$oldurl} = $newsubpath;
                   2075:                         }
1.491     raeburn  2076:                     }
                   2077:                 }
1.597     raeburn  2078:             } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   2079:                 my $template = $1;
                   2080:                 if ($newidx) {
                   2081:                     &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
                   2082:                                           $coursedom,$coursenum,$template,$newidx,"$folder.$container");
                   2083:                 }
1.649     raeburn  2084:             } elsif ($url =~ /ext\.tool$/) {
1.655     raeburn  2085:                 if (($newidx) && ($folder=~/^default/)) {
1.649     raeburn  2086:                     my $marker = (split(m{/},$url))[4];
                   2087:                     my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
                   2088:                     my $val = 'no';
                   2089:                     if ($toolsettings{'gradable'}) {
                   2090:                         $val = 'yes';
                   2091:                     }
                   2092:                     &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
                   2093:                                                   'string_yesno');
                   2094:                     &remember_parms($newidx,'gradable','set',$val);
                   2095:                 }
1.491     raeburn  2096:             }
1.538     raeburn  2097:             $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   2098:                                               ':'.$ext.':normal:res';
                   2099:             push(@LONCAPA::map::order,$newidx);
                   2100: # Store the result
                   2101:             my ($errtext,$fatal) =
                   2102:                 &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   2103:             if ($fatal) {
                   2104:                 $save_err .= $errtext;
                   2105:                 $allresult = 'fail';
                   2106:             }
1.488     raeburn  2107:         }
1.538     raeburn  2108: 
1.597     raeburn  2109: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
                   2110: # resourcedata for simpleproblems copied from another course 
1.538     raeburn  2111:         unless ($allresult eq 'fail') {
                   2112:             my %updated = (
                   2113:                             rewrites      => \%rewrites,
                   2114:                             zombies       => \%zombies,
                   2115:                             removefrommap => \%removefrommap,
                   2116:                             removeparam   => \%removeparam,
                   2117:                             dbcopies      => \%dbcopies,
1.597     raeburn  2118:                             resdatacopy   => \%resdatacopy,
1.538     raeburn  2119:                             retitles      => \%retitles,
                   2120:                           );
                   2121:             my %info = (
                   2122:                            newsubdir => \%newsubdir,
                   2123:                            params    => \%params,
                   2124:                        );
                   2125:             if ($prefixchg{$suffix}) {
                   2126:                 $info{'before'} = $before{$prefixchg{$suffix}};
                   2127:                 $info{'after'} = $after{$prefixchg{$suffix}};
                   2128:             }
                   2129:             my %moves = (
                   2130:                            copies   => \%copies,
                   2131:                            docmoves => \%docmoves,
                   2132:                            mapmoves => \%mapmoves,
                   2133:                         );
                   2134:             (my $result,$msgs{$suffix},my $lockerror) =
                   2135:                 &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
                   2136:                               \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
                   2137:                               $url,'paste');
                   2138:             $lockerrors .= $lockerror;
                   2139:             if ($result eq 'ok') {
                   2140:                 if ($is_map{$suffix}) {
                   2141:                     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   2142:                                                     $folder.'.'.$container);
                   2143:                     if ($fatal) {
                   2144:                         $allresult = 'failread';
                   2145:                     } else {
                   2146:                         if ($#LONCAPA::map::order<1) {
                   2147:                             my $idx=&LONCAPA::map::getresidx();
                   2148:                             if ($idx<=0) { $idx=1; }
                   2149:                             $LONCAPA::map::order[0]=$idx;
                   2150:                             $LONCAPA::map::resources[$idx]='';
                   2151:                         }
                   2152:                         my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   2153:                         $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   2154:                                                           ':'.$ext.':normal:res';
                   2155:                         push(@LONCAPA::map::order,$newidx);
1.492     raeburn  2156: 
                   2157: # Store the result
1.538     raeburn  2158:                         my ($errtext,$fatal) = 
                   2159:                             &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   2160:                         if ($fatal) {
                   2161:                             $save_err .= $errtext;
                   2162:                             $allresult = 'failstore';
                   2163:                         }
                   2164:                     } 
                   2165:                 }
                   2166:                 if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   2167:                      push(@toclear,$suffix);
                   2168:                 }
                   2169:             }
1.492     raeburn  2170:         }
                   2171:     }
1.538     raeburn  2172:     &clear_from_buffer(\@toclear,\@currpaste);
                   2173:     my $msgsarray;
                   2174:     foreach my $suffix (keys(%msgs)) {
                   2175:          if (ref($msgs{$suffix}) eq 'ARRAY') {
                   2176:              $msgsarray .= join(',',@{$msgs{$suffix}});
                   2177:          }
                   2178:     }
                   2179:     return ($allresult,$save_err,$msgsarray,$lockerrors);
                   2180: }
1.533     raeburn  2181: 
1.538     raeburn  2182: sub do_buffer_empty {
                   2183:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   2184:     if (@currpaste == 0) {
                   2185:         return &mt('Clipboard is already empty');
                   2186:     }
                   2187:     my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
                   2188:     if (@toclear == 0) {
                   2189:         return &mt('Nothing selected to clear from clipboard');
                   2190:     }
                   2191:     my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
                   2192:     if ($numdel) {
                   2193:         return &mt('[quant,_1,item] cleared from clipboard',$numdel);
                   2194:     } else {
                   2195:         return &mt('Clipboard unchanged');
1.492     raeburn  2196:     }
1.538     raeburn  2197:     return;
                   2198: }
                   2199: 
                   2200: sub clear_from_buffer {
                   2201:     my ($toclear,$currpaste) = @_;
                   2202:     return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
                   2203:     my %pastebuffer;
                   2204:     map { $pastebuffer{$_} = 1; } @{$currpaste};
                   2205:     my $numdel = 0;
                   2206:     foreach my $suffix (@{$toclear}) {
                   2207:         next if ($suffix =~ /\D/);
                   2208:         next unless (exists($pastebuffer{$suffix}));
                   2209:         my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
                   2210:         if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
                   2211:             delete($pastebuffer{$suffix});
                   2212:             $numdel ++;
                   2213:         }
                   2214:     }
                   2215:     my $newbuffer = join(',',sort(keys(%pastebuffer)));
                   2216:     &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
                   2217:     return $numdel;
1.492     raeburn  2218: }
                   2219: 
                   2220: sub get_newmap_url {
                   2221:     my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
                   2222:         $titleref,$allmaps,$newurls) = @_;
                   2223:     my $newurl;
                   2224:     if ($url=~ m{^/uploaded/}) {
                   2225:         $$titleref=&mt('Copy of').' '.$$titleref;
                   2226:     }
                   2227:     my $now = time;
                   2228:     my $suffix=$$.int(rand(100)).$now;
                   2229:     my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
                   2230:     if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
                   2231:         my $path = $1;
                   2232:         my $prefix = $2;
                   2233:         my $ancestor = $3;
                   2234:         if (length($ancestor) > 10) {
                   2235:             $ancestor = substr($ancestor,-10,10);
                   2236:         }
                   2237:         my $newid;
                   2238:         if ($prefixchg) {
                   2239:             if ($folder =~ /^supplemental/) {
                   2240:                 $prefix =~ s/^default/supplemental/;
                   2241:             } else {
                   2242:                 $prefix =~ s/^supplemental/default/;
                   2243:             }
                   2244:         }
                   2245:         if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   2246:             $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   2247:         } else {
                   2248:             $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
                   2249:         }
                   2250:         my $counter = 0;
                   2251:         my $is_unique = &uniqueness_check($newurl);
                   2252:         if ($folder =~ /^default/) {
                   2253:             if ($allmaps->{$newurl}) {
                   2254:                 $is_unique = 0;
                   2255:             }
                   2256:         }
                   2257:         while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
                   2258:             $counter ++;
                   2259:             $suffix ++;
                   2260:             if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   2261:                 $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   2262:             } else {
                   2263:                 $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
                   2264:             }
                   2265:             $is_unique = &uniqueness_check($newurl);
                   2266:         }
                   2267:         if ($is_unique) {
                   2268:             $newurls->{$newurl} = 1;
                   2269:         } else {
                   2270:             if ($url=~/\.page$/) {
                   2271:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
                   2272:             } else {
                   2273:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
                   2274:             }
                   2275:         }
1.329     droeschl 2276:     }
1.492     raeburn  2277:     return ($newurl);
1.329     droeschl 2278: }
                   2279: 
1.488     raeburn  2280: sub dbcopy {
1.533     raeburn  2281:     my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
                   2282:     my ($url,$result,$errtext);
                   2283:     if (ref($dbref) eq 'HASH') {
1.596     raeburn  2284:         $url = $dbref->{'src'};
1.627     raeburn  2285:         if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533     raeburn  2286:             my $prefix = $1;
1.627     raeburn  2287:             if ($prefix eq 'ext.tool') {
                   2288:                 $prefix = 'exttool';
                   2289:             }
1.533     raeburn  2290:             if (($dbref->{'cdom'} =~ /^$match_domain$/) && 
                   2291:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   2292:                 my $db_name;
                   2293:                 my $marker = (split(m{/},$url))[4];
                   2294:                 $marker=~s/\D//g;
                   2295:                 if ($dbref->{'src'} =~ m{/smppg$}) {
                   2296:                     $db_name =
                   2297:                         &Apache::lonsimplepage::get_db_name($url,$marker,
                   2298:                                                             $dbref->{'cdom'},
                   2299:                                                             $dbref->{'cnum'});
1.627     raeburn  2300:                 } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
                   2301:                     $db_name = 'exttool_'.$marker;
1.533     raeburn  2302:                 } else {
                   2303:                     $db_name = 'bulletinpage_'.$marker;
                   2304:                 }
                   2305:                 my ($suffix,$freedlock,$error) =
                   2306:                     &Apache::lonnet::get_timebased_id($prefix,'num','templated',
                   2307:                                                       $coursedom,$coursenum,
                   2308:                                                       'concat');
                   2309:                 if (!$suffix) {
                   2310:                     if ($prefix eq 'smppg') {
                   2311:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631     raeburn  2312:                     } elsif ($prefix eq 'exttool') {
                   2313:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533     raeburn  2314:                     } else {
1.565     bisitz   2315:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533     raeburn  2316:                     }
                   2317:                     if ($error) {
                   2318:                         $errtext .= '<br />'.$error;
                   2319:                     }
                   2320:                 } else {
                   2321:                     #need to copy the db contents to a new one.
                   2322:                     my %contents=&Apache::lonnet::dump($db_name,
                   2323:                                                        $dbref->{'cdom'},
                   2324:                                                        $dbref->{'cnum'});
                   2325:                     if (exists($contents{'uploaded.photourl'})) {
                   2326:                         my $photo = $contents{'uploaded.photourl'};
                   2327:                         my ($subdir,$fname) =
                   2328:                             ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596     raeburn  2329:                         my $newphoto;
1.533     raeburn  2330:                         if ($fname ne '') {
                   2331:                             my $content = &Apache::lonnet::getfile($photo);
                   2332:                             unless ($content eq '-1') {
                   2333:                                 $env{'form.'.$suffix.'.photourl'} = $content;
                   2334:                                 $newphoto = 
                   2335:                                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
                   2336:                                 delete($env{'form.'.$suffix.'.photourl'});
                   2337:                             }
                   2338:                         }
                   2339:                         if ($newphoto =~ m{^/uploaded/}) {
                   2340:                             $contents{'uploaded.photourl'} = $newphoto;
                   2341:                         }
                   2342:                     }
                   2343:                     $db_name =~ s{_\d*$ }{_$suffix}x;
1.649     raeburn  2344:                     if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
                   2345:                         delete($contents{'gradable'});
                   2346:                     }
1.533     raeburn  2347:                     $result=&Apache::lonnet::put($db_name,\%contents,
                   2348:                                                  $coursedom,$coursenum);
                   2349:                     if ($result eq 'ok') {
1.627     raeburn  2350:                         $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533     raeburn  2351:                     }
                   2352:                 }
                   2353:                 if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559     raeburn  2354:                     $lockerrorsref->{$prefix} =
1.533     raeburn  2355:                         '<div class="LC_error">'.
                   2356:                         &mt('There was a problem removing a lockfile.');
                   2357:                     if ($prefix eq 'smppg') {
1.560     raeburn  2358:                         $lockerrorsref->{$prefix} .=
1.559     raeburn  2359:                             ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627     raeburn  2360:                     } elsif ($prefix eq 'exttool') {
                   2361:                         $lockerrorsref->{$prefix} .=
                   2362:                             ' '.&mt('This will prevent addition of more external tools to this course.');
1.533     raeburn  2363:                     } else {
1.565     bisitz   2364:                         $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  2365:                     }
1.560     raeburn  2366:                     $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   2367:                                                      '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
                   2368:                                                  '</div>';
1.533     raeburn  2369:                 }
                   2370:             }
                   2371:         } elsif ($url =~ m{/syllabus$}) {
                   2372:             if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
                   2373:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   2374:                 if (($dbref->{'cdom'} ne $coursedom) ||
                   2375:                     ($dbref->{'cnum'} ne $coursenum)) {
                   2376:                     my %contents=&Apache::lonnet::dump('syllabus',
                   2377:                                                        $dbref->{'cdom'},
                   2378:                                                        $dbref->{'cnum'});
                   2379:                     $result=&Apache::lonnet::put('syllabus',\%contents,
                   2380:                                                  $coursedom,$coursenum);
                   2381:                 }
                   2382:             }
1.488     raeburn  2383:         }
                   2384:     }
1.533     raeburn  2385:     return ($url,$result,$errtext);
1.488     raeburn  2386: }
                   2387: 
1.597     raeburn  2388: sub copy_templated_files {
                   2389:     my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
                   2390:     my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
                   2391:     my $srccontainer = 'sequence';
                   2392:     if ($srcwaspage) {
                   2393:         $srccontainer = 'page';
                   2394:     }
                   2395:     my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
                   2396:                   '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
                   2397:     my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
                   2398:     my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
                   2399:     my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
                   2400:                   $template.'.problem';
                   2401:     my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
                   2402:     if ($template eq 'simpleproblem') {
                   2403:         $srcprefix .= '.0.';
                   2404:         my $weightprefix = $newprefix;
                   2405:         $newprefix .= '.0.';
                   2406:         my @simpleprobqtypes = qw(radio option string essay numerical);
                   2407:         my $qtype=$srcparms{$srcprefix.'questiontype'};
                   2408:         if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665     raeburn  2409:             my %newdata = (
                   2410:                 $newprefix.'questiontype' => $qtype,
                   2411:             );
1.597     raeburn  2412:             foreach my $type (@simpleprobqtypes) {
                   2413:                 if ($type eq $qtype) {
                   2414:                     $newdata{"$weightprefix.$type.weight"}=1;
                   2415:                 } else {
                   2416:                     $newdata{"$weightprefix.$type.weight"}=0;
                   2417:                 }
                   2418:             }
                   2419:             $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
                   2420:             $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
                   2421:             $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
                   2422:             if ($qtype eq 'numerical') {
                   2423:                 $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
                   2424:                 $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
                   2425:                 $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
                   2426:                 $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
                   2427:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   2428:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   2429:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   2430:                     unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   2431:                         if ($maxfoils<=0) { $maxfoils=10; }
                   2432:                             my $randomize=$srcparms{$srcprefix.'randomize'};
                   2433:                             unless (defined($randomize)) { $randomize='yes'; }
                   2434:                             unless ($randomize eq 'no') { $randomize='yes'; }
                   2435:                             $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   2436:                             $newdata{$newprefix.'randomize'} = $randomize;
                   2437:                             if ($qtype eq 'option') {
                   2438:                                 $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   2439:                             }
                   2440:                             for (my $i=1; $i<=10; $i++) {
                   2441:                                 $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   2442:                                 $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   2443:                                 $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   2444:                             }
                   2445: 
                   2446:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   2447:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   2448:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   2449:                 unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   2450:                 if ($maxfoils<=0) { $maxfoils=10; }
                   2451:                 my $randomize=$srcparms{$srcprefix.'randomize'};
                   2452:                 unless (defined($randomize)) { $randomize='yes'; }
                   2453:                 unless ($randomize eq 'no') { $randomize='yes'; }
                   2454:                 $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   2455:                 $newdata{$newprefix.'randomize'} = $randomize;
                   2456:                 if ($qtype eq 'option') {
                   2457:                     $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   2458:                 }
                   2459:                 for (my $i=1; $i<=10; $i++) {
                   2460:                     $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   2461:                     $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   2462:                     $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   2463:                 }
                   2464:             } elsif ($qtype eq 'string') {
                   2465:                 $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
                   2466:                 $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
                   2467:             }
                   2468:             if (keys(%newdata)) {
                   2469:                 my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
                   2470:                                                    $coursenum);
                   2471:                 if ($putres eq 'ok') {
                   2472:                     &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
                   2473:                 }
                   2474:             }
                   2475:         }
                   2476:     }
                   2477: }
                   2478: 
1.329     droeschl 2479: sub uniqueness_check {
                   2480:     my ($newurl) = @_;
                   2481:     my $unique = 1;
                   2482:     foreach my $res (@LONCAPA::map::order) {
                   2483:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   2484:         $url=&LONCAPA::map::qtescape($url);
                   2485:         if ($newurl eq $url) {
                   2486:             $unique = 0;
1.344     bisitz   2487:             last;
1.329     droeschl 2488:         }
                   2489:     }
                   2490:     return $unique;
                   2491: }
                   2492: 
1.488     raeburn  2493: sub contained_map_check {
1.627     raeburn  2494:     my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
                   2495:         $hierarchy,$titles,$allmaps) = @_;
1.488     raeburn  2496:     my $content = &Apache::lonnet::getfile($url);
                   2497:     unless ($content eq '-1') {
                   2498:         my $parser = HTML::TokeParser->new(\$content);
                   2499:         $parser->attr_encoded(1);
                   2500:         while (my $token = $parser->get_token) {
                   2501:             next if ($token->[0] ne 'S');
                   2502:             if ($token->[1] eq 'resource') {
                   2503:                 next if ($token->[2]->{'type'} eq 'zombie');
                   2504:                 my $ressrc = $token->[2]->{'src'};
1.627     raeburn  2505:                 if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
                   2506:                     my $srcdom = $1;
                   2507:                     unless ($srcdom eq $coursedom) {
                   2508:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2509:                         next;
                   2510:                     }
                   2511:                 } elsif ($folder =~ /^supplemental/) {
1.488     raeburn  2512:                     unless (&supp_pasteable($ressrc)) {
1.492     raeburn  2513:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488     raeburn  2514:                         next;
                   2515:                     }
                   2516:                 }
1.492     raeburn  2517:                 if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
                   2518:                     if ($1 eq 'uploaded') {
                   2519:                         $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2520:                         $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488     raeburn  2521:                     } else {
1.492     raeburn  2522:                         if ($allmaps->{$ressrc}) {
1.529     raeburn  2523:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492     raeburn  2524:                         } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
                   2525:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2526:                         } else {
                   2527:                             $addedmaps->{$ressrc} = [$url];
                   2528:                         }
1.488     raeburn  2529:                     }
1.627     raeburn  2530:                     &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
                   2531:                                          $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488     raeburn  2532:                 }
1.492     raeburn  2533:             } elsif ($token->[1] eq 'param') {
1.488     raeburn  2534:                 if ($folder =~ /^supplemental/) {
1.492     raeburn  2535:                     if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
                   2536:                         push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
                   2537:                     } else {
                   2538:                         $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}]; 
                   2539:                     }
1.488     raeburn  2540:                 }
                   2541:             }
                   2542:         }
                   2543:     }
                   2544:     return;
                   2545: }
                   2546: 
                   2547: sub url_paste_fixups {
1.533     raeburn  2548:     my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
                   2549:         $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597     raeburn  2550:         $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491     raeburn  2551:     my $checktitle;
                   2552:     if (($prefixchg) &&
1.492     raeburn  2553:         ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491     raeburn  2554:         $checktitle = 1;
                   2555:     }
1.492     raeburn  2556:     my $skip;
                   2557:     if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
                   2558:         my $mapid = $1.$2;
                   2559:         if ($tomove->{$mapid}) {
                   2560:             $skip = 1;
                   2561:         }
                   2562:     }
1.491     raeburn  2563:     my $file = &Apache::lonnet::getfile($oldurl);
1.488     raeburn  2564:     return if ($file eq '-1');
                   2565:     my $parser = HTML::TokeParser->new(\$file);
                   2566:     $parser->attr_encoded(1);
1.491     raeburn  2567:     my $changed = 0;
1.488     raeburn  2568:     while (my $token = $parser->get_token) {
                   2569:         next if ($token->[0] ne 'S');
                   2570:         if ($token->[1] eq 'resource') {
                   2571:             my $ressrc = $token->[2]->{'src'};
                   2572:             next if ($ressrc eq '');
1.491     raeburn  2573:             my $id = $token->[2]->{'id'};
1.492     raeburn  2574:             my $title = $token->[2]->{'title'};
1.491     raeburn  2575:             if ($checktitle) {
                   2576:                 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  2577:                     $retitles->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2578:                 }
                   2579:             }
1.488     raeburn  2580:             next if ($token->[2]->{'type'} eq 'external');
                   2581:             if ($token->[2]->{'type'} eq 'zombie') {
1.492     raeburn  2582:                 next if ($skip);  
1.532     raeburn  2583:                 $zombies->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2584:                 $changed = 1;
                   2585:             } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  2586:                 my $srcdom = $1;
                   2587:                 my $srcnum = $2;
1.488     raeburn  2588:                 my $rem = $3;
1.492     raeburn  2589:                 my $newurl;
                   2590:                 my $mapname;
                   2591:                 if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
                   2592:                     my $prefix = $1;
                   2593:                     $mapname = $prefix.$2;
                   2594:                     if ($tomove->{$mapname}) {
1.533     raeburn  2595:                         &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   2596:                                           $srcdom,$srcnum,$allmaps,$rewrites,
                   2597:                                           $retitles,$copies,$dbcopies,$zombies,
                   2598:                                           $params,$mapmoves,$mapchanges,$tomove,
1.597     raeburn  2599:                                           $newsubdir,$newurls,$resdatacopy);
1.492     raeburn  2600:                         next;
                   2601:                     } else {
                   2602:                         ($newurl,my $error) =
                   2603:                             &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   2604:                                             $srcdom,$srcnum,\$title,$allmaps,$newurls);
                   2605:                         if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
                   2606:                             $newsubdir->{$ressrc} = $1;
                   2607:                         }
                   2608:                         if ($error) {
                   2609:                             next;
                   2610:                         }
                   2611:                     }
                   2612:                 }
                   2613:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
                   2614:                     ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
                   2615:                    
1.488     raeburn  2616:                     if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532     raeburn  2617:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2618:                         $mapchanges->{$ressrc} = 1;
1.533     raeburn  2619:                         unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
                   2620:                                                   $cnum,$srcdom,$srcnum,$allmaps,
                   2621:                                                   $rewrites,$retitles,$copies,$dbcopies,
                   2622:                                                   $zombies,$params,$mapmoves,$mapchanges,
1.597     raeburn  2623:                                                   $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491     raeburn  2624:                             $mapmoves->{$ressrc} = 1;
                   2625:                         }
                   2626:                         $changed = 1;
1.488     raeburn  2627:                     } else {
1.532     raeburn  2628:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.488     raeburn  2629:                         $copies->{$oldurl}{$ressrc} = $id;
1.491     raeburn  2630:                         $changed = 1;
1.488     raeburn  2631:                     }
                   2632:                 }
1.649     raeburn  2633:             } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533     raeburn  2634:                 next if ($skip);
1.492     raeburn  2635:                 my $srcdom = $1;
                   2636:                 my $srcnum = $2;
1.649     raeburn  2637:                 my $rem = $3;
                   2638:                 my ($is_exttool,$exttoolchg);
                   2639:                 if ($rem =~ m{\d+/ext\.tool$}) {
1.655     raeburn  2640:                     $is_exttool = 1;
1.649     raeburn  2641:                 }
1.492     raeburn  2642:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532     raeburn  2643:                     $rewrites->{$oldurl}{$id} = $ressrc;
1.533     raeburn  2644:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2645:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2646:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   2647:                     $changed = 1;
1.649     raeburn  2648:                     if ($is_exttool) {
                   2649:                         $exttoolchg = 1;
                   2650:                     }
                   2651:                 } elsif (($rem =~ m{\d+/ext\.tool$}) &&
                   2652:                          ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   2653:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2654:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2655:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   2656:                     $changed = 1;
                   2657:                     $exttoolchg = 1;
                   2658:                 }
                   2659:                 if (($is_exttool) && ($prefixchg)) {
                   2660:                     if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
                   2661:                         if ($exttoolchg) {
                   2662:                             $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
                   2663:                         }
                   2664:                     }
1.533     raeburn  2665:                 }
                   2666:             } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
                   2667:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
                   2668:                     ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   2669:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2670:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   2671:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491     raeburn  2672:                     $changed = 1;
1.488     raeburn  2673:                 }
1.597     raeburn  2674:             } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
                   2675:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
                   2676:                     $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
                   2677:                     $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   2678:                     $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
                   2679:                 }
1.488     raeburn  2680:             } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  2681:                 next if ($skip);
                   2682:                 my $srcdom = $1;
                   2683:                 my $srcnum = $2;
                   2684:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533     raeburn  2685:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2686:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2687:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491     raeburn  2688:                     $changed = 1;
1.488     raeburn  2689:                 }
                   2690:             }
                   2691:         } elsif ($token->[1] eq 'param') {
1.492     raeburn  2692:             next if ($skip);
1.488     raeburn  2693:             my $to = $token->[2]->{'to'}; 
                   2694:             if ($to ne '') {
                   2695:                 if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492     raeburn  2696:                     push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488     raeburn  2697:                 } else {
                   2698:                     @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
                   2699:                 }
                   2700:             }
                   2701:         }
                   2702:     }
1.491     raeburn  2703:     return $changed;
1.488     raeburn  2704: }
                   2705: 
                   2706: sub apply_fixups {
1.529     raeburn  2707:     my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
                   2708:         $oldurl,$url,$caller) = @_;
                   2709:     my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533     raeburn  2710:         %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597     raeburn  2711:         %resdatacopy,%lockerrors,$lockmsg);
1.529     raeburn  2712:     if (ref($updated) eq 'HASH') {
                   2713:         if (ref($updated->{'rewrites'}) eq 'HASH') {
                   2714:             %rewrites = %{$updated->{'rewrites'}};
                   2715:         }
                   2716:         if (ref($updated->{'zombies'}) eq 'HASH') {
                   2717:             %zombies = %{$updated->{'zombies'}};
                   2718:         }
                   2719:         if (ref($updated->{'removefrommap'}) eq 'HASH') {
                   2720:             %removefrommap = %{$updated->{'removefrommap'}};
                   2721:         }
                   2722:         if (ref($updated->{'removeparam'}) eq 'HASH') {
                   2723:             %removeparam = %{$updated->{'removeparam'}};
                   2724:         }
                   2725:         if (ref($updated->{'dbcopies'}) eq 'HASH') {
                   2726:             %dbcopies = %{$updated->{'dbcopies'}};
                   2727:         }
                   2728:         if (ref($updated->{'retitles'}) eq 'HASH') {
                   2729:             %retitles = %{$updated->{'retitles'}};
                   2730:         }
1.597     raeburn  2731:         if (ref($updated->{'resdatacopy'}) eq 'HASH') {
                   2732:             %resdatacopy = %{$updated->{'resdatacopy'}};
                   2733:         }
1.529     raeburn  2734:     }
                   2735:     if (ref($info) eq 'HASH') {
                   2736:         if (ref($info->{'newsubdir'}) eq 'HASH') {
                   2737:             %newsubdir = %{$info->{'newsubdir'}};
                   2738:         }
                   2739:         if (ref($info->{'params'}) eq 'HASH') {
                   2740:             %params = %{$info->{'params'}};
                   2741:         }
                   2742:         if (ref($info->{'before'}) eq 'HASH') {
                   2743:             %before = %{$info->{'before'}};
                   2744:         }
                   2745:         if (ref($info->{'after'}) eq 'HASH') {
                   2746:             %after = %{$info->{'after'}};
                   2747:         }
                   2748:     }
                   2749:     if (ref($moves) eq 'HASH') {
                   2750:         if (ref($moves->{'copies'}) eq 'HASH') {
                   2751:             %copies = %{$moves->{'copies'}};
                   2752:         }
                   2753:         if (ref($moves->{'docmoves'}) eq 'HASH') {
                   2754:             %docmoves = %{$moves->{'docmoves'}};
                   2755:         }
                   2756:         if (ref($moves->{'mapmoves'}) eq 'HASH') {
                   2757:             %mapmoves = %{$moves->{'mapmoves'}};
                   2758:         }
                   2759:     }
                   2760:     foreach my $key (keys(%copies),keys(%docmoves)) {
1.491     raeburn  2761:         my @allcopies;
1.529     raeburn  2762:         if (exists($copies{$key})) {
                   2763:             if (ref($copies{$key}) eq 'HASH') {
                   2764:                 my %added;
                   2765:                 foreach my $innerkey (keys(%{$copies{$key}})) {
                   2766:                     if (($innerkey ne '') && (!$added{$innerkey})) {
                   2767:                         push(@allcopies,$innerkey);
                   2768:                         $added{$innerkey} = 1;
                   2769:                     }
1.491     raeburn  2770:                 }
1.529     raeburn  2771:                 undef(%added);
1.491     raeburn  2772:             }
                   2773:         }
                   2774:         if ($key eq $oldurl) {
1.529     raeburn  2775:             if ((exists($docmoves{$key}))) {
1.532     raeburn  2776:                 unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491     raeburn  2777:                     push(@allcopies,$oldurl);
                   2778:                 }
                   2779:             }
                   2780:         }
                   2781:         if (@allcopies > 0) {
                   2782:             foreach my $item (@allcopies) {
1.492     raeburn  2783:                 my ($relpath,$oldsubdir,$fname) = 
                   2784:                     ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491     raeburn  2785:                 if ($fname ne '') {
                   2786:                     my $content = &Apache::lonnet::getfile($item);
                   2787:                     unless ($content eq '-1') {
                   2788:                         my $storefn;
1.529     raeburn  2789:                         if (($key eq $oldurl) && (exists($docmoves{$key}))) {
                   2790:                             $storefn = $docmoves{$key};
1.491     raeburn  2791:                         } else {
                   2792:                             $storefn = $relpath;
                   2793:                             $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  2794:                             if ($prefixchg && $before{'doc'} && $after{'doc'}) {
                   2795:                                 $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491     raeburn  2796:                             }
1.529     raeburn  2797:                             if ($newsubdir{$key}) {
1.532     raeburn  2798:                                 $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491     raeburn  2799:                             }
                   2800:                         }
                   2801:                         &copy_dependencies($item,$storefn,$relpath,$errors,\$content);
                   2802:                         my $copyurl = 
                   2803:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},
                   2804:                                                                $storefn.$fname,$content);
                   2805:                         if ($copyurl eq '/adm/notfound.html') {
1.529     raeburn  2806:                             if (exists($docmoves{$oldurl})) {
1.491     raeburn  2807:                                 return &mt('Paste failed: an error occurred copying the file.');
                   2808:                             } elsif (ref($errors) eq 'HASH') {
                   2809:                                 $errors->{$item} = 1;
1.489     raeburn  2810:                             }
                   2811:                         }
1.488     raeburn  2812:                     }
                   2813:                 }
1.491     raeburn  2814:             }
                   2815:         }
                   2816:     }
1.529     raeburn  2817:     foreach my $key (keys(%mapmoves)) {
1.491     raeburn  2818:         my $storefn=$key;
                   2819:         $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  2820:         if ($prefixchg && $before{'map'} && $after{'map'}) {
                   2821:             $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  2822:         }
1.529     raeburn  2823:         if ($newsubdir{$key}) {
                   2824:             $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  2825:         }
1.491     raeburn  2826:         my $mapcontent = &Apache::lonnet::getfile($key);
1.681     raeburn  2827:         if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
                   2828:             ($after{'map'} eq 'default') &&
                   2829:             ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
                   2830:             $mapcontent = '<map>'."\n".
                   2831:                           '<resource id="1" src="" type="start" />'."\n".
                   2832:                           '<link from="1" to="2" index="1" />'."\n".
                   2833:                           '<resource id="2" src="" type="finish" />'."\n".
                   2834:                           '</map>';
                   2835:         }
1.491     raeburn  2836:         if ($mapcontent eq '-1') {
                   2837:             if (ref($errors) eq 'HASH') {
                   2838:                 $errors->{$key} = 1;
                   2839:             }
                   2840:         } else {
                   2841:             my $newmap =
                   2842:                 &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
                   2843:                                                    $mapcontent);
                   2844:             if ($newmap eq '/adm/notfound.html') {
                   2845:                 if (ref($errors) eq 'HASH') {
                   2846:                     $errors->{$key} = 1;
1.489     raeburn  2847:                 }
1.488     raeburn  2848:             }
                   2849:         }
                   2850:     }
1.491     raeburn  2851:     my %updates;
                   2852:     if ($is_map) {
1.529     raeburn  2853:         if (ref($updated) eq 'HASH') {
                   2854:             foreach my $type (keys(%{$updated})) {
                   2855:                 if (ref($updated->{$type}) eq 'HASH') {
                   2856:                     foreach my $key (keys(%{$updated->{$type}})) {
                   2857:                         $updates{$key} = 1;
                   2858:                     }
                   2859:                 }
                   2860:             }
1.491     raeburn  2861:         }
                   2862:         foreach my $key (keys(%updates)) {
1.492     raeburn  2863:             my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529     raeburn  2864:             if (ref($rewrites{$key}) eq 'HASH') {
                   2865:                 %torewrite = %{$rewrites{$key}};
1.491     raeburn  2866:             }
1.529     raeburn  2867:             if (ref($retitles{$key}) eq 'HASH') {
                   2868:                 %toretitle = %{$retitles{$key}};
1.491     raeburn  2869:             }
1.529     raeburn  2870:             if (ref($removefrommap{$key}) eq 'HASH') {
                   2871:                 %toremove = %{$removefrommap{$key}};
1.491     raeburn  2872:             }
1.529     raeburn  2873:             if (ref($removeparam{$key}) eq 'HASH') {
                   2874:                 %remparam = %{$removeparam{$key}};
1.492     raeburn  2875:             }
1.529     raeburn  2876:             if (ref($zombies{$key}) eq 'HASH') {
                   2877:                 %zombie = %{$zombies{$key}};
1.491     raeburn  2878:             }
1.529     raeburn  2879:             if (ref($dbcopies{$key}) eq 'HASH') {
1.533     raeburn  2880:                 foreach my $idx (keys(%{$dbcopies{$key}})) {
                   2881:                     if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
                   2882:                         my ($newurl,$result,$errtext) =
                   2883:                             &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
                   2884:                         if ($result eq 'ok') {
                   2885:                             $newdb{$idx} = $newurl;
                   2886:                         } elsif (ref($errors) eq 'HASH') {
                   2887:                             $errors->{$key} = 1;
                   2888:                         }
                   2889:                         push(@msgs,$errtext);
                   2890:                     }
1.491     raeburn  2891:                 }
                   2892:             }
1.597     raeburn  2893:             if (ref($resdatacopy{$key}) eq 'HASH') {
1.664     raeburn  2894:                 my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597     raeburn  2895:                 foreach my $idx (keys(%{$resdatacopy{$key}})) {
                   2896:                     if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
                   2897:                         my $srcurl = $resdatacopy{$key}{$idx}{'src'};
                   2898:                         if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   2899:                             my $template = $1;
                   2900:                             if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
                   2901:                                 ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
                   2902:                                 my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
                   2903:                                 my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664     raeburn  2904:                                 unless ($gotnewmapname) {
                   2905:                                     ($newmapname) = ($key =~ m{/([^/]+)$});
                   2906:                                     ($srcfolder,$srccontainer) = split(/\./,$newmapname);
                   2907:                                     if ($newsubdir{$key}) {
                   2908:                                         $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
                   2909:                                     }
                   2910:                                     $gotnewmapname = 1;
                   2911:                                 }
1.597     raeburn  2912:                                 my $srcmapinfo = $srcfolder.':'.$idx;
                   2913:                                 if ($srccontainer eq 'page') {
                   2914:                                     $srcmapinfo .= ':1';
                   2915:                                 }
                   2916:                                 &copy_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
                   2917:                                                       $cnum,$template,$idx,$newmapname);
                   2918:                             }
                   2919:                         }
                   2920:                     }
                   2921:                 }
                   2922:             }
1.529     raeburn  2923:             if (ref($params{$key}) eq 'HASH') {
                   2924:                 %currparam = %{$params{$key}};
1.492     raeburn  2925:             }
                   2926:             my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
                   2927:             if ($fatal) {
1.533     raeburn  2928:                 return ($errtext);
1.492     raeburn  2929:             }
                   2930:             for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
                   2931:                 if (defined($LONCAPA::map::zombies[$i])) {
                   2932:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532     raeburn  2933:                     if ($zombie{$i} eq $src) {
1.492     raeburn  2934:                         undef($LONCAPA::map::zombies[$i]);
                   2935:                     }
                   2936:                 }
                   2937:             }
1.646     raeburn  2938:             my $total = scalar(@LONCAPA::map::order) - 1;
                   2939:             for (my $i=$total; $i>=0; $i--) {
1.529     raeburn  2940:                 my $idx = $LONCAPA::map::order[$i];
                   2941:                 if (defined($LONCAPA::map::resources[$idx])) {
1.492     raeburn  2942:                     my $changed;
1.529     raeburn  2943:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538     raeburn  2944:                     if ((exists($toremove{$idx})) && 
                   2945:                         ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492     raeburn  2946:                         splice(@LONCAPA::map::order,$i,1);
1.529     raeburn  2947:                         if (ref($currparam{$idx}) eq 'ARRAY') {
                   2948:                             foreach my $name (@{$currparam{$idx}}) {
1.647     raeburn  2949:                                 &LONCAPA::map::delparameter($idx,$name);
1.492     raeburn  2950:                             }
                   2951:                         }
                   2952:                         next;
                   2953:                     }
                   2954:                     my $origsrc = $src;
1.532     raeburn  2955:                     if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492     raeburn  2956:                         if ($title =~ m{^\d+\Q___&amp;&amp;&amp;___\E$match_username\Q___&amp;&amp;&amp;___\E$match_domain\Q___&amp;&amp;&amp;___\E(.+)$}) {
                   2957:                             $changed = 1;
1.491     raeburn  2958:                         }
1.492     raeburn  2959:                     }
1.532     raeburn  2960:                     if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492     raeburn  2961:                         $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
                   2962:                         if ($origsrc =~ m{^/uploaded/}) {
1.529     raeburn  2963:                             if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492     raeburn  2964:                                 if ($src =~ /\.(page|sequence)$/) {
1.529     raeburn  2965:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492     raeburn  2966:                                 } else {
1.529     raeburn  2967:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488     raeburn  2968:                                 }
1.491     raeburn  2969:                             }
1.532     raeburn  2970:                             if ($origsrc =~ /\.(page|sequence)$/) {
                   2971:                                 if ($newsubdir{$origsrc}) {
1.529     raeburn  2972:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491     raeburn  2973:                                 }
1.532     raeburn  2974:                             } elsif ($newsubdir{$key}) {
                   2975:                                 $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488     raeburn  2976:                             }
                   2977:                         }
1.492     raeburn  2978:                         $changed = 1;
1.533     raeburn  2979:                     } elsif ($newdb{$idx} ne '') {
                   2980:                         $src = $newdb{$idx};
1.492     raeburn  2981:                         $changed = 1;
                   2982:                     }
                   2983:                     if ($changed) {
1.538     raeburn  2984:                         $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492     raeburn  2985:                     }
                   2986:                 }
                   2987:             }
                   2988:             foreach my $idx (keys(%remparam)) {
                   2989:                 if (ref($remparam{$idx}) eq 'ARRAY') {
                   2990:                     foreach my $name (@{$remparam{$idx}}) {   
1.647     raeburn  2991:                         &LONCAPA::map::delparameter($idx,$name);
1.491     raeburn  2992:                     }
                   2993:                 }
                   2994:             }
1.533     raeburn  2995:             if (values(%lockerrors) > 0) {
                   2996:                 $lockmsg = join('<br />',values(%lockerrors));
                   2997:             }
1.491     raeburn  2998:             my $storefn;
                   2999:             if ($key eq $oldurl) {
                   3000:                 $storefn = $url;
                   3001:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
                   3002:             } else {
                   3003:                 $storefn = $key;
                   3004:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  3005:                 if ($prefixchg && $before{'map'} && $after{'map'}) {
                   3006:                     $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  3007:                 }
1.529     raeburn  3008:                 if ($newsubdir{$key}) {
                   3009:                     $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  3010:                 }
1.491     raeburn  3011:             }
1.492     raeburn  3012:             my $report;
                   3013:             if ($folder !~ /^supplemental/) {
                   3014:                 $report = 1;
                   3015:             }
1.527     raeburn  3016:             (my $outtext,$errtext) =
1.492     raeburn  3017:                 &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
                   3018:             if ($errtext) {
1.529     raeburn  3019:                 if ($caller eq 'paste') {
1.533     raeburn  3020:                     return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529     raeburn  3021:                 }
1.491     raeburn  3022:             }
                   3023:         }
                   3024:     }
1.533     raeburn  3025:     return ('ok',\@msgs,$lockmsg);
1.491     raeburn  3026: }
                   3027: 
                   3028: sub copy_dependencies {
                   3029:     my ($item,$storefn,$relpath,$errors,$contentref) = @_;
                   3030:     my $content;
                   3031:     if (ref($contentref)) {
                   3032:         $content = $$contentref;
                   3033:     } else {
                   3034:         $content = &Apache::lonnet::getfile($item);
                   3035:     }
                   3036:     unless ($content eq '-1') {
                   3037:         my $mm = new File::MMagic;
                   3038:         my $mimetype = $mm->checktype_contents($content);
                   3039:         if ($mimetype eq 'text/html') {
                   3040:             my (%allfiles,%codebase,$state);
                   3041:             my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
                   3042:             if ($res eq 'ok') {
                   3043:                 my ($numexisting,$numpathchanges,$existing);
                   3044:                 (undef,$numexisting,$numpathchanges,$existing) =
                   3045:                     &Apache::loncommon::ask_for_embedded_content(
                   3046:                         '/adm/coursedocs',$state,\%allfiles,\%codebase,
                   3047:                         {'error_on_invalid_names'   => 1,
                   3048:                          'ignore_remote_references' => 1,
                   3049:                          'docs_url'                 => $item,
                   3050:                          'context'                  => 'paste'});
                   3051:                 if ($numexisting > 0) {
                   3052:                     if (ref($existing) eq 'HASH') {
                   3053:                         foreach my $dep (keys(%{$existing})) {
                   3054:                             my $depfile = $dep;
                   3055:                             unless ($depfile =~ m{^\Q$relpath\E}) {
                   3056:                                 $depfile = $relpath.$dep;
                   3057:                             }
                   3058:                             my $depcontent = &Apache::lonnet::getfile($depfile);
                   3059:                             unless ($depcontent eq '-1') {
                   3060:                                 my $storedep = $dep;
                   3061:                                 $storedep =~ s{^\Q$relpath\E}{};
                   3062:                                 my $dep_url =
                   3063:                                     &Apache::lonclonecourse::writefile(
                   3064:                                         $env{'request.course.id'},
                   3065:                                         $storefn.$storedep,$depcontent);
                   3066:                                 if ($dep_url eq '/adm/notfound.html') {
                   3067:                                     if (ref($errors) eq 'HASH') {
                   3068:                                         $errors->{$depfile} = 1;
                   3069:                                     }
                   3070:                                 } else {
                   3071:                                     &copy_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
                   3072:                                 }
                   3073:                             }
                   3074:                         }
1.488     raeburn  3075:                     }
                   3076:                 }
                   3077:             }
                   3078:         }
                   3079:     }
                   3080:     return;
                   3081: }
                   3082: 
1.329     droeschl 3083: my %parameter_type = ( 'randompick'     => 'int_pos',
                   3084: 		       'hiddenresource' => 'string_yesno',
                   3085: 		       'encrypturl'     => 'string_yesno',
                   3086: 		       'randomorder'    => 'string_yesno',);
                   3087: my $valid_parameters_re = join('|',keys(%parameter_type));
                   3088: # set parameters
                   3089: sub update_parameter {
1.537     raeburn  3090:     if ($env{'form.changeparms'} eq 'all') {
                   3091:         my (@allidx,@allmapidx,%allchecked,%currchecked);
                   3092:         %allchecked = (
                   3093:                          'hiddenresource' => {},
                   3094:                          'encrypturl'     => {},
                   3095:                          'randompick'     => {},
                   3096:                          'randomorder'    => {},
                   3097:                       );
                   3098:         foreach my $which (keys(%allchecked)) {
1.630     raeburn  3099:             $env{'form.all'.$which} =~ s/,$//;
1.537     raeburn  3100:             if ($which eq 'randompick') {
                   3101:                 foreach my $item (split(/,/,$env{'form.all'.$which})) {
                   3102:                     my ($res,$value) = split(/:/,$item);
                   3103:                     if ($value =~ /^\d+$/) {
                   3104:                         $allchecked{$which}{$res} = $value;
                   3105:                     }
                   3106:                 }
                   3107:             } else {
1.539     raeburn  3108:                 if ($env{'form.all'.$which}) {
                   3109:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
                   3110:                 }
1.537     raeburn  3111:             }
                   3112:         }
                   3113:         my $haschanges = 0;
                   3114:         foreach my $res (@LONCAPA::map::order) {
                   3115:             my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3116:             $name=&LONCAPA::map::qtescape($name);
                   3117:             $url=&LONCAPA::map::qtescape($url);
1.692     raeburn  3118:             next unless $url;
1.537     raeburn  3119:             my $is_map;
                   3120:             if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   3121:                 $is_map = 1;
                   3122:             }
                   3123:             foreach my $which (keys(%allchecked)) {
                   3124:                 if (($which eq 'randompick' || $which eq 'randomorder')) {
                   3125:                     next if (!$is_map);
                   3126:                 } 
                   3127:                 my $oldvalue = 0;
                   3128:                 my $newvalue = 0;
                   3129:                 if ($allchecked{$which}{$res}) {
                   3130:                     $newvalue = $allchecked{$which}{$res};
                   3131:                 }
                   3132:                 my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
                   3133:                 if ($which eq 'randompick') {
                   3134:                     if ($current =~ /^(\d+)$/) {
                   3135:                         $oldvalue = $1;
                   3136:                     }
                   3137:                 } else {
                   3138:                     if ($current =~ /^yes$/i) {
                   3139:                         $oldvalue = 1;
                   3140:                     }
                   3141:                 }
                   3142:                 if ($oldvalue ne $newvalue) {
                   3143:                     $haschanges = 1;
                   3144:                     if ($newvalue) {
                   3145:                         my $storeval = 'yes';
                   3146:                         if ($which eq 'randompick') {
                   3147:                             $storeval = $newvalue;
                   3148:                         }
                   3149:                         &LONCAPA::map::storeparameter($res,'parameter_'.$which,
                   3150:                                                       $storeval,
                   3151:                                                       $parameter_type{$which});
                   3152:                         &remember_parms($res,$which,'set',$storeval);
                   3153:                     } elsif ($oldvalue) {
                   3154:                         &LONCAPA::map::delparameter($res,'parameter_'.$which);
                   3155:                         &remember_parms($res,$which,'del');
                   3156:                     }
                   3157:                 }
                   3158:             }
                   3159:         }
                   3160:         return $haschanges;
                   3161:     } else {
1.588     raeburn  3162:         my $haschanges = 0;
                   3163:         return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329     droeschl 3164: 
1.537     raeburn  3165:         my $which = $env{'form.changeparms'};
                   3166:         my $idx = $env{'form.setparms'};
1.588     raeburn  3167:         my $oldvalue = 0;
                   3168:         my $newvalue = 0;
                   3169:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
                   3170:         if ($which eq 'randompick') {
                   3171:             if ($current =~ /^(\d+)$/) {
                   3172:                 $oldvalue = $1;
                   3173:             }
                   3174:         } elsif ($current =~ /^yes$/i) {
                   3175:             $oldvalue = 1;
                   3176:         }
1.537     raeburn  3177:         if ($env{'form.'.$which.'_'.$idx}) {
1.588     raeburn  3178: 	    $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
                   3179: 	                                         : 1;
                   3180:         }
                   3181:         if ($oldvalue ne $newvalue) {
                   3182:             $haschanges = 1;
                   3183:             if ($newvalue) {
                   3184:                 my $storeval = 'yes';
                   3185:                 if ($which eq 'randompick') {
                   3186:                     $storeval = $newvalue;
                   3187:                 }
                   3188: 	        &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
                   3189: 				              $parameter_type{$which});
                   3190: 	        &remember_parms($idx,$which,'set',$storeval);
                   3191:             } else {
                   3192: 	        &LONCAPA::map::delparameter($idx,'parameter_'.$which);
                   3193: 	        &remember_parms($idx,$which,'del');
                   3194:             }
1.537     raeburn  3195:         }
1.588     raeburn  3196:         return $haschanges;
1.329     droeschl 3197:     }
                   3198: }
                   3199: 
                   3200: sub handle_edit_cmd {
                   3201:     my ($coursenum,$coursedom) =@_;
1.633     raeburn  3202:     my $haschanges = 0;
1.543     raeburn  3203:     if ($env{'form.cmd'} eq '') {
1.633     raeburn  3204:         return $haschanges; 
1.543     raeburn  3205:     }
1.329     droeschl 3206:     my ($cmd,$idx)=split('_',$env{'form.cmd'});
                   3207: 
                   3208:     my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                   3209:     my ($title, $url, @rrest) = split(':', $ratstr);
                   3210: 
1.538     raeburn  3211:     if ($cmd eq 'remove') {
1.329     droeschl 3212: 	if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463     www      3213: 	    ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329     droeschl 3214: 	    &Apache::lonnet::removeuploadedurl($url);
                   3215: 	} else {
                   3216: 	    &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   3217: 	}
                   3218: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  3219:         $haschanges = 1;
1.329     droeschl 3220:     } elsif ($cmd eq 'cut') {
                   3221: 	&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   3222: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  3223:         $haschanges = 1;
1.344     bisitz   3224:     } elsif ($cmd eq 'up'
1.329     droeschl 3225: 	     && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
                   3226: 	@LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633     raeburn  3227:         $haschanges = 1;
1.329     droeschl 3228:     } elsif ($cmd eq 'down'
                   3229: 	     && defined($LONCAPA::map::order[$idx+1])) {
                   3230: 	@LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633     raeburn  3231:         $haschanges = 1;
1.329     droeschl 3232:     } elsif ($cmd eq 'rename') {
                   3233: 	my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
                   3234: 	if ($comment=~/\S/) {
                   3235: 	    $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
                   3236: 		$comment.':'.join(':', $url, @rrest);
                   3237: 	}
                   3238: # Devalidate title cache
                   3239: 	my $renamed_url=&LONCAPA::map::qtescape($url);
                   3240: 	&Apache::lonnet::devalidate_title_cache($renamed_url);
1.633     raeburn  3241:         $haschanges = 1;
                   3242:     } elsif ($cmd eq 'setalias') {
                   3243:         my $newvalue = $env{'form.alias'};
                   3244:         if ($newvalue ne '') {
                   3245:             unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
                   3246:                 &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
                   3247:                                               'string');
                   3248:                 &remember_parms($idx,'mapalias','set',$newvalue);
                   3249:                 $haschanges = 1;
                   3250:             }
                   3251:         }
                   3252:     } elsif ($cmd eq 'delalias') {
                   3253:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];  
                   3254:         if ($current ne '') {
                   3255:             &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
                   3256:             &remember_parms($idx,'mapalias','del');
                   3257:             $haschanges = 1;
                   3258:         }
1.329     droeschl 3259:     }
1.633     raeburn  3260:     return $haschanges;
1.329     droeschl 3261: }
                   3262: 
                   3263: sub editor {
1.458     raeburn  3264:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615     raeburn  3265:         $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622     raeburn  3266:         $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519     raeburn  3267:     my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510     raeburn  3268:     if ($allowed) {
1.519     raeburn  3269:         (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   3270:          $is_random_order,$container) =
1.510     raeburn  3271:             &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   3272:         $r->print($breadcrumbtrail);
1.519     raeburn  3273:     } elsif ($env{'form.folderpath'} =~ /\:1$/) {
                   3274:         $container = 'page'; 
                   3275:     } else {
                   3276:         $container = 'sequence';
1.510     raeburn  3277:     }
1.484     raeburn  3278: 
1.525     raeburn  3279:     my $jumpto;
                   3280: 
                   3281:     unless ($supplementalflag) {
1.546     raeburn  3282:         $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525     raeburn  3283:     }
1.484     raeburn  3284: 
                   3285:     unless ($allowed) {
                   3286:         $randompick = -1;
                   3287:     }
                   3288: 
1.615     raeburn  3289:     my ($errtext,$fatal);
                   3290:     if (($folder eq '') && (!$supplementalflag)) {
                   3291:         if (@LONCAPA::map::order) {
                   3292:             undef(@LONCAPA::map::order);
                   3293:             undef(@LONCAPA::map::resources);
                   3294:             undef(@LONCAPA::map::resparms);
                   3295:             undef(@LONCAPA::map::zombies);
                   3296:         }
                   3297:         $folder = 'default';
                   3298:         $container = 'sequence'; 
                   3299:     } else {
                   3300:         ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   3301: 				     $folder.'.'.$container);
                   3302:         return $errtext if ($fatal);
                   3303:     }
1.329     droeschl 3304: 
                   3305:     if ($#LONCAPA::map::order<1) {
                   3306: 	my $idx=&LONCAPA::map::getresidx();
                   3307: 	if ($idx<=0) { $idx=1; }
                   3308:        	$LONCAPA::map::order[0]=$idx;
                   3309:         $LONCAPA::map::resources[$idx]='';
                   3310:     }
1.364     bisitz   3311: 
1.329     droeschl 3312: # ------------------------------------------------------------ Process commands
                   3313: 
                   3314: # ---------------- if they are for this folder and user allowed to make changes
1.611     raeburn  3315:     if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329     droeschl 3316: # set parameters and change order
                   3317: 	&snapshotbefore();
                   3318: 
                   3319: 	if (&update_parameter()) {
1.588     raeburn  3320: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329     droeschl 3321: 	    return $errtext if ($fatal);
                   3322: 	}
                   3323: 
                   3324: 	if ($env{'form.newpos'} && $env{'form.currentpos'}) {
                   3325: # change order
                   3326: 	    my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
                   3327: 	    splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
                   3328: 
                   3329: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
                   3330: 	    return $errtext if ($fatal);
                   3331: 	}
1.364     bisitz   3332: 
1.329     droeschl 3333: 	if ($env{'form.pastemarked'}) {
1.491     raeburn  3334:             my %paste_errors;
1.533     raeburn  3335:             my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492     raeburn  3336:                 &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
                   3337:                                       \%paste_errors);
1.541     raeburn  3338:             if (ref($pastemsgarray) eq 'ARRAY') {
                   3339:                 if (@{$pastemsgarray} > 0) {
                   3340:                     $r->print('<p class="LC_info">'.
                   3341:                               join('<br />',@{$pastemsgarray}).
1.533     raeburn  3342:                               '</p>');
                   3343:                 }
1.541     raeburn  3344:             }
                   3345:             if ($lockerror) {
                   3346:                 $r->print('<p class="LC_error">'.
                   3347:                           $lockerror.
                   3348:                           '</p>');
                   3349:             }
                   3350:             if ($save_error ne '') {
                   3351:                 return $save_error; 
                   3352:             }
                   3353:             if ($paste_res) {
                   3354:                 my %errortext = &Apache::lonlocal::texthash (
                   3355:                                     fail      => 'Storage of folder contents failed',
                   3356:                                     failread  => 'Reading folder contents failed',
                   3357:                                     failstore => 'Storage of folder contents failed',
                   3358:                                 );
                   3359:                 if ($errortext{$paste_res}) {
                   3360:                     $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492     raeburn  3361:                 }
1.329     droeschl 3362:             }
1.491     raeburn  3363:             if (keys(%paste_errors) > 0) {
1.538     raeburn  3364:                 $r->print('<p class="LC_warning">'."\n".
1.491     raeburn  3365:                           &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".
                   3366:                           '<ul>'."\n");
                   3367:                 foreach my $key (sort(keys(%paste_errors))) {
                   3368:                     $r->print('<li>'.$key.'</li>'."\n");
                   3369:                 }
                   3370:                 $r->print('</ul></p>'."\n");
                   3371:             }
1.538     raeburn  3372: 	} elsif ($env{'form.clearmarked'}) {
                   3373:             my $output = &do_buffer_empty();
                   3374:             if ($output) {
                   3375:                 $r->print('<p class="LC_info">'.$output.'</p>');
                   3376:             }
                   3377:         }
1.329     droeschl 3378: 
                   3379: 	$r->print($upload_output);
                   3380: 
1.538     raeburn  3381: # Rename, cut, copy or remove a single resource
1.602     raeburn  3382: 	if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492     raeburn  3383:             my $contentchg;
1.633     raeburn  3384:             if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492     raeburn  3385:                 $contentchg = 1;
                   3386:             }
                   3387: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329     droeschl 3388: 	    return $errtext if ($fatal);
                   3389: 	}
1.538     raeburn  3390: 
                   3391: # Cut, copy and/or remove multiple resources
                   3392:         if ($env{'form.multichange'}) {
                   3393:             my %allchecked = (
                   3394:                                cut     => {},
                   3395:                                remove  => {},
                   3396:                              );
                   3397:             my $needsupdate;
                   3398:             foreach my $which (keys(%allchecked)) {
                   3399:                 $env{'form.multi'.$which} =~ s/,$//;
                   3400:                 if ($env{'form.multi'.$which}) {
                   3401:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
                   3402:                     if (ref($allchecked{$which}) eq 'HASH') {
                   3403:                         $needsupdate += scalar(keys(%{$allchecked{$which}}));
                   3404:                     }
                   3405:                 }
                   3406:             }
                   3407:             if ($needsupdate) {
                   3408:                 my $haschanges = 0;
                   3409:                 my %curr_groups = &Apache::longroup::coursegroups();
                   3410:                 my $total = scalar(@LONCAPA::map::order) - 1; 
                   3411:                 for (my $i=$total; $i>=0; $i--) {
                   3412:                     my $res = $LONCAPA::map::order[$i];
                   3413:                     my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3414:                     $name=&LONCAPA::map::qtescape($name);
                   3415:                     $url=&LONCAPA::map::qtescape($url);
1.586     droeschl 3416:                     next unless $url;
1.538     raeburn  3417:                     my %denied =
                   3418:                         &action_restrictions($coursenum,$coursedom,$url,
                   3419:                                              $env{'form.folderpath'},\%curr_groups);
                   3420:                     foreach my $which (keys(%allchecked)) {
                   3421:                         next if ($denied{$which});
                   3422:                         next unless ($allchecked{$which}{$res});
                   3423:                         if ($which eq 'remove') {
                   3424:                             if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   3425:                                 ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   3426:                                 &Apache::lonnet::removeuploadedurl($url);
                   3427:                             } else {
                   3428:                                 &LONCAPA::map::makezombie($res);
                   3429:                             }
                   3430:                             splice(@LONCAPA::map::order,$i,1);
                   3431:                             $haschanges ++;
                   3432:                         } elsif ($which eq 'cut') {
                   3433:                             &LONCAPA::map::makezombie($res);
                   3434:                             splice(@LONCAPA::map::order,$i,1);
                   3435:                             $haschanges ++;
                   3436:                         }
                   3437:                     }
                   3438:                 }
                   3439:                 if ($haschanges) {
                   3440:                     ($errtext,$fatal) = 
                   3441:                         &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   3442:                     return $errtext if ($fatal);
                   3443:                 }
                   3444:             }
                   3445:         }
                   3446: 
1.329     droeschl 3447: # Group import/search
                   3448: 	if ($env{'form.importdetail'}) {
                   3449: 	    my @imports;
                   3450: 	    foreach my $item (split(/\&/,$env{'form.importdetail'})) {
                   3451: 		if (defined($item)) {
                   3452: 		    my ($name,$url,$residx)=
1.533     raeburn  3453: 			map { &unescape($_); } split(/\=/,$item);
                   3454:                     if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
                   3455:                         my ($suffix,$errortxt,$locknotfreed) =
                   3456:                             &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504     raeburn  3457:                         if ($locknotfreed) {
                   3458:                             $r->print($locknotfreed);
                   3459:                         }
                   3460:                         if ($suffix) {
                   3461:                             $url =~ s/_new\./_$suffix./; 
                   3462:                         } else {
                   3463:                             return $errortxt;
                   3464:                         }
1.533     raeburn  3465:                     } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
                   3466:                         my $type = $1;
                   3467:                         my ($suffix,$errortxt,$locknotfreed) =
                   3468:                             &new_timebased_suffix($coursedom,$coursenum,$type);
                   3469:                         if ($locknotfreed) {
                   3470:                             $r->print($locknotfreed);
                   3471:                         }
                   3472:                         if ($suffix) {
                   3473:                             $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
                   3474:                         } else {
                   3475:                             return $errortxt;
                   3476:                         }
1.626     raeburn  3477:                     } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598     raeburn  3478:                         my ($suffix,$errortxt,$locknotfreed) =
                   3479:                             &new_timebased_suffix($coursedom,$coursenum,'exttool');
                   3480:                         if ($locknotfreed) {
                   3481:                             $r->print($locknotfreed);
                   3482:                         }
                   3483:                         if ($suffix) {
                   3484:                             $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
                   3485:                         } else {
                   3486:                             return $errortxt;
                   3487:                         }
1.534     raeburn  3488:                     } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
                   3489:                         if ($supplementalflag) {
                   3490:                             next unless ($1 eq 'supplemental');
                   3491:                             if ($folder eq 'supplemental') {
                   3492:                                 next unless ($2 eq 'default');
                   3493:                             } else {
                   3494:                                 next unless ($folder eq 'supplemental_'.$2);
                   3495:                             }
                   3496:                         } else {
                   3497:                             next unless ($1 eq 'docs');
                   3498:                             if ($folder eq 'default') {
                   3499:                                 next unless ($2 eq 'default');
                   3500:                             } else {
                   3501:                                 next unless ($folder eq 'default_'.$2);
                   3502:                             }
                   3503:                         }
1.504     raeburn  3504:                     }
1.329     droeschl 3505: 		    push(@imports, [$name, $url, $residx]);
                   3506: 		}
                   3507: 	    }
1.530     raeburn  3508:             ($errtext,$fatal,my $fixuperrors) =
1.529     raeburn  3509:                 &group_import($coursenum, $coursedom, $folder,$container,
1.598     raeburn  3510:                               'londocs',$ltitoolsref,@imports);
1.329     droeschl 3511: 	    return $errtext if ($fatal);
1.529     raeburn  3512:             if ($fixuperrors) {
                   3513:                 $r->print($fixuperrors);
                   3514:             }
1.329     droeschl 3515: 	}
                   3516: # Loading a complete map
                   3517: 	if ($env{'form.loadmap'}) {
                   3518: 	    if ($env{'form.importmap'}=~/\w/) {
                   3519: 		foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
                   3520: 		    my ($title,$url,$ext,$type)=split(/\:/,$res);
                   3521: 		    my $idx=&LONCAPA::map::getresidx($url);
                   3522: 		    $LONCAPA::map::resources[$idx]=$res;
                   3523: 		    $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
                   3524: 		}
                   3525: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  3526: 					    $folder.'.'.$container,1);
1.329     droeschl 3527: 		return $errtext if ($fatal);
                   3528: 	    } else {
                   3529: 		$r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364     bisitz   3530: 
1.329     droeschl 3531: 	    }
                   3532: 	}
                   3533: 	&log_differences($plain);
                   3534:     }
                   3535: # ---------------------------------------------------------------- End commands
                   3536: # ---------------------------------------------------------------- Print screen
                   3537:     my $idx=0;
                   3538:     my $shown=0;
                   3539:     if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381     bisitz   3540: 	$r->print('<div class="LC_Box">'.
1.432     raeburn  3541:           '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
                   3542: 		  ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
                   3543: 		  ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
                   3544: 		  ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
                   3545: 		  ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431     raeburn  3546: 		  '</ol>');
1.381     bisitz   3547:         if ($randompick>=0) {
                   3548:             $r->print('<p class="LC_warning">'
                   3549:                  .&mt('Caution: this folder is set to randomly pick a subset'
                   3550:                      .' of resources. Adding or removing resources from this'
                   3551:                      .' folder will change the set of resources that the'
                   3552:                      .' students see, resulting in spurious or missing credit'
                   3553:                      .' for completed problems, not limited to ones you'
                   3554:                      .' modify. Do not modify the contents of this folder if'
                   3555:                      .' it is in active student use.')
                   3556:                  .'</p>'
                   3557:             );
                   3558:         }
                   3559:         if ($is_random_order) {
                   3560:             $r->print('<p class="LC_warning">'
                   3561:                  .&mt('Caution: this folder is set to randomly order its'
                   3562:                      .' contents. Adding or removing resources from this folder'
                   3563:                      .' will change the order of resources shown.')
                   3564:                  .'</p>'
                   3565:             );
                   3566:         }
                   3567:         $r->print('</div>');
1.364     bisitz   3568:     }
1.381     bisitz   3569: 
1.685     raeburn  3570:     if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688     raeburn  3571:         my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn  3572:         if (ref($supplemental) eq 'HASH') {
                   3573:             if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
                   3574:                 (ref($supplemental->{'ids'}) eq 'HASH')) {
                   3575:                 if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
                   3576:                     my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
                   3577:                     if ($supplemental->{'hidden'}->{$mapnum}) {
                   3578:                         $ishidden = 1;
                   3579:                     }
                   3580:                 }
                   3581:             }
                   3582:         }
                   3583:     }
                   3584: 
1.538     raeburn  3585:     my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
                   3586:     %filters =  (
1.543     raeburn  3587:                   canremove      => [],
                   3588:                   cancut         => [],
                   3589:                   cancopy        => [],
                   3590:                   hiddenresource => [],
                   3591:                   encrypturl     => [],
                   3592:                   randomorder    => [],
                   3593:                   randompick     => [],
1.538     raeburn  3594:                 );
                   3595:     %curr_groups = &Apache::longroup::coursegroups();
1.424     onken    3596:     &Apache::loncommon::start_data_table_count(); #setup a row counter 
1.381     bisitz   3597:     foreach my $res (@LONCAPA::map::order) {
                   3598:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3599:         $name=&LONCAPA::map::qtescape($name);
                   3600:         $url=&LONCAPA::map::qtescape($url);
                   3601:         unless ($name) {  $name=(split(/\//,$url))[-1]; }
                   3602:         unless ($name) { $idx++; next; }
1.537     raeburn  3603:         push(@allidx,$res);
                   3604:         if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   3605:             push(@allmapidx,$res);
                   3606:         }
1.617     raeburn  3607: 
1.682     raeburn  3608:         if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685     raeburn  3609:             if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
                   3610:                 $idx++;
                   3611:                 next;
                   3612:             }
1.682     raeburn  3613:         }
1.381     bisitz   3614:         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501     raeburn  3615:                               $coursenum,$coursedom,$crstype,
1.538     raeburn  3616:                               $pathitem,$supplementalflag,$container,
1.620     raeburn  3617:                               \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685     raeburn  3618:                               $isencrypted,$ishidden,$navmapref,$hostname);
1.381     bisitz   3619:         $idx++;
                   3620:         $shown++;
1.329     droeschl 3621:     }
1.424     onken    3622:     &Apache::loncommon::end_data_table_count();
1.510     raeburn  3623: 
1.538     raeburn  3624:     my $need_save;
1.611     raeburn  3625:     if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544     raeburn  3626:         my $toolslink;
1.682     raeburn  3627:         if ($allowed || $canedit) {
                   3628:             my $helpitem = 'Navigation_Screen';
                   3629:             if (!$allowed) {
                   3630:                 $helpitem = 'Supplemental_Navigation';
                   3631:             }
1.544     raeburn  3632:             $toolslink = '<table><tr><td>'
1.520     raeburn  3633:                        .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682     raeburn  3634:                                                            $helpitem,undef,'RAT')
1.520     raeburn  3635:                        .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
                   3636:                        .'<td align="left"><ul id="LC_toolbar">'
1.525     raeburn  3637:                        .'<li><a href="/adm/coursedocs?forcesupplement=1&amp;command=editsupp" '
1.520     raeburn  3638:                        .'id="LC_content_toolbar_edittoplevel" '
                   3639:                        .'class="LC_toolbarItem" '
                   3640:                        .'title="'.&mt('Supplemental Content Editor').'">'
                   3641:                        .'</a></li></ul></td></tr></table><br />';
1.544     raeburn  3642:         }
1.510     raeburn  3643:         if ($shown) {
                   3644:             if ($allowed) {
                   3645:                 $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
                   3646:                           .&Apache::loncommon::start_data_table(undef,'contentlist')
                   3647:                           .&Apache::loncommon::start_data_table_header_row()
                   3648:                           .'<th colspan="2">'.&mt('Move').'</th>'
1.633     raeburn  3649:                           .'<th colspan="3">'.&mt('Actions').'</th>'
1.682     raeburn  3650:                           .'<th>'.&mt('Document').'</th>'
                   3651:                           .'<th colspan="2">'.&mt('Settings').'</th>'
                   3652:                           .&Apache::loncommon::end_data_table_header_row();
1.537     raeburn  3653:                 if ($folder !~ /^supplemental/) {
1.538     raeburn  3654:                     $lists{'canhide'} = join(',',@allidx);
                   3655:                     $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543     raeburn  3656:                     my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
                   3657:                                        'randomorder','randompick');
                   3658:                     foreach my $item (@possfilters) {
1.538     raeburn  3659:                         if (ref($filters{$item}) eq 'ARRAY') {
1.543     raeburn  3660:                             if (@{$filters{$item}} > 0) {
                   3661:                                 $lists{$item} = join(',',@{$filters{$item}});
                   3662:                             }
1.538     raeburn  3663:                         }
                   3664:                     }
1.537     raeburn  3665:                     if (@allidx > 0) {
                   3666:                         my $path;
                   3667:                         if ($env{'form.folderpath'}) {
1.630     raeburn  3668:                             $path =
1.537     raeburn  3669:                                 &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   3670:                         }
1.538     raeburn  3671:                         if (@allidx > 1) {
1.630     raeburn  3672:                             $to_show .=
1.538     raeburn  3673:                                 &Apache::loncommon::continue_data_table_row().
                   3674:                                 '<td colspan="2">&nbsp;</td>'.
                   3675:                                 '<td>'.
1.611     raeburn  3676:                                 &multiple_check_form('actions',\%lists,$canedit).
1.538     raeburn  3677:                                 '</td>'.
1.633     raeburn  3678:                                 '<td colspan="3">&nbsp;</td>'.
                   3679:                                 '<td colspan="2">'.
1.611     raeburn  3680:                                 &multiple_check_form('settings',\%lists,$canedit).
1.538     raeburn  3681:                                 '</td>'.
                   3682:                                 &Apache::loncommon::end_data_table_row();
                   3683:                              $need_save = 1;
                   3684:                         }
1.537     raeburn  3685:                     }
                   3686:                 }
                   3687:                 $to_show .= $output.' '
1.510     raeburn  3688:                            .&Apache::loncommon::end_data_table()
                   3689:                            .'<br style="line-height:2px;" />'
                   3690:                            .&Apache::loncommon::end_scrollbox();
                   3691:             } else {
1.520     raeburn  3692:                 $to_show .= $toolslink
1.510     raeburn  3693:                            .&Apache::loncommon::start_data_table('LC_tableOfContent')
                   3694:                            .$output.' '
                   3695:                            .&Apache::loncommon::end_data_table();
1.393     raeburn  3696:             }
1.510     raeburn  3697:         } else {
1.520     raeburn  3698:             if (!$allowed) {
                   3699:                 $to_show .= $toolslink;
                   3700:             }
1.615     raeburn  3701:             my $noresmsg;
                   3702:             if ($allowed && $hiddentop && !$supplementalflag) {
                   3703:                 $noresmsg = &mt('Main Content Hidden'); 
                   3704:             } else {
                   3705:                 $noresmsg = &mt('Currently empty');
                   3706:             }
1.510     raeburn  3707:             $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
                   3708:                        .'<div class="LC_info" id="contentlist">'
1.615     raeburn  3709:                        .$noresmsg
1.510     raeburn  3710:                        .'</div>'
                   3711:                        .&Apache::loncommon::end_scrollbox();
1.393     raeburn  3712:         }
                   3713:     } else {
1.510     raeburn  3714:         if ($shown) {
                   3715:             $to_show = '<div>'
                   3716:                       .&Apache::loncommon::start_data_table('LC_tableOfContent')
                   3717:                       .$output
                   3718:                       .&Apache::loncommon::end_data_table()
                   3719:                       .'</div>';
                   3720:         } else {
                   3721:             $to_show = '<div class="LC_info" id="contentlist">'
1.550     raeburn  3722:                       .&mt('Currently empty')
1.510     raeburn  3723:                       .'</div>'
                   3724:         }
1.458     raeburn  3725:     }
                   3726:     my $tid = 1;
                   3727:     if ($supplementalflag) {
                   3728:         $tid = 2;
1.329     droeschl 3729:     }
                   3730:     if ($allowed) {
1.484     raeburn  3731:         my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538     raeburn  3732:         $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611     raeburn  3733:                                        $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
                   3734:         if ($canedit) {
                   3735:             &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
                   3736:         }
1.460     raeburn  3737:     } else {
                   3738:         $r->print($to_show);
1.329     droeschl 3739:     }
                   3740:     return;
                   3741: }
                   3742: 
1.538     raeburn  3743: sub multiple_check_form {
1.611     raeburn  3744:     my ($caller,$listsref,$canedit) = @_;
1.538     raeburn  3745:     return unless (ref($listsref) eq 'HASH');
1.611     raeburn  3746:     my $disabled;
                   3747:     unless ($canedit) {
                   3748:         $disabled = 'disabled="disabled"'; 
                   3749:     }
1.538     raeburn  3750:     my $output =
                   3751:     '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
                   3752:     '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
                   3753:     '<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>'.
                   3754:     '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
                   3755:     '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
                   3756:     '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
                   3757:     if ($caller eq 'settings') {
                   3758:         $output .= 
                   3759:             '<table><tr>'.
                   3760:             '<td class="LC_docs_entry_parameter">'.
                   3761:             '<span class="LC_nobreak"><label>'.
1.611     raeburn  3762:             '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538     raeburn  3763:             '</label></span></td>'.
                   3764:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  3765:             '<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  3766:             '</span></td>'.
                   3767:             '</tr>'."\n".
                   3768:             '<tr>'.
                   3769:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  3770:             '<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  3771:             '</label></span>'.
                   3772:             '</td></tr></table>'."\n";
                   3773:     } else {
                   3774:         $output .=
                   3775:             '<table><tr>'.
                   3776:             '<td class="LC_docs_entry_parameter">'.
                   3777:             '<span class="LC_nobreak LC_docs_remove">'.
1.611     raeburn  3778:             '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538     raeburn  3779:             '</label></span></td>'.
                   3780:             '<td class="LC_docs_entry_parameter">'.
                   3781:             '<span class="LC_nobreak LC_docs_cut">'.
1.611     raeburn  3782:             '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538     raeburn  3783:             '</label></span></td>'."\n".
                   3784:             '<td class="LC_docs_entry_parameter">'.
                   3785:             '<span class="LC_nobreak LC_docs_copy">'.
1.611     raeburn  3786:             '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538     raeburn  3787:             '</label></span></td>'.
                   3788:             '</tr></table>'."\n";
                   3789:     }
                   3790:     $output .= 
                   3791:         '</fieldset>'.
                   3792:         '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
                   3793:     if ($caller eq 'settings') {
                   3794:         $output .= 
1.543     raeburn  3795:         '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
                   3796:         '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
                   3797:         '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
                   3798:         '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
                   3799:         '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538     raeburn  3800:     } elsif ($caller eq 'actions') {
                   3801:         $output .=
                   3802:         '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
                   3803:         '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
                   3804:         '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
                   3805:     }
                   3806:     $output .= 
                   3807:         '</form>'.
                   3808:         '</div>';
                   3809:     return $output;
                   3810: }
                   3811: 
1.329     droeschl 3812: sub process_file_upload {
1.552     raeburn  3813:     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329     droeschl 3814: # upload a file, if present
1.552     raeburn  3815:     my $filesize = length($env{'form.uploaddoc'});
                   3816:     if (!$filesize) {
                   3817:         $$upload_output = '<div class="LC_error">'.
                   3818:                            &mt('Unable to upload [_1]. (size = [_2] bytes)',
                   3819:                           '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
                   3820:                           $filesize).'<br />'.
                   3821:                           &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
                   3822:                           '</div>';
                   3823:         return;
                   3824:     }
                   3825:     my $quotatype = 'unofficial';
                   3826:     if ($crstype eq 'Community') {
1.601     raeburn  3827:         $quotatype = 'community';
                   3828:     } elsif ($crstype eq 'Placement') {
                   3829:         $quotatype = 'placement';
1.580     raeburn  3830:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552     raeburn  3831:         $quotatype = 'official';
1.573     raeburn  3832:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   3833:         $quotatype = 'textbook';
1.552     raeburn  3834:     }
                   3835:     if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
                   3836:         $filesize = int($filesize/1000); #expressed in kb
                   3837:         $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579     raeburn  3838:                                                                       $env{'form.uploaddoc.filename'},$filesize,
                   3839:                                                                       'upload',$quotatype);
1.552     raeburn  3840:         return if ($$upload_output);
                   3841:     }
1.440     raeburn  3842:     my ($parseaction,$showupload,$nextphase,$mimetype);
                   3843:     if ($env{'form.parserflag'}) {
1.329     droeschl 3844:         $parseaction = 'parse';
                   3845:     }
                   3846:     my $folder=$env{'form.folder'};
                   3847:     if ($folder eq '') {
                   3848:         $folder='default';
                   3849:     }
                   3850:     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
                   3851:         my $errtext='';
                   3852:         my $fatal=0;
                   3853:         my $container='sequence';
1.519     raeburn  3854:         if ($env{'form.folderpath'} =~ /:1$/) {
1.329     droeschl 3855:             $container='page';
                   3856:         }
                   3857:         ($errtext,$fatal)=
1.534     raeburn  3858:             &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329     droeschl 3859:         if ($#LONCAPA::map::order<1) {
                   3860:             $LONCAPA::map::order[0]=1;
                   3861:             $LONCAPA::map::resources[1]='';
                   3862:         }
                   3863:         my $destination = 'docs/';
                   3864:         if ($folder =~ /^supplemental/) {
                   3865:             $destination = 'supplemental/';
                   3866:         }
                   3867:         if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   3868:             $destination .= 'default/';
                   3869:         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   3870:             $destination .=  $2.'/';
                   3871:         }
1.534     raeburn  3872:         if ($fatal) {
                   3873:             $$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>';
                   3874:             return;
                   3875:         }
1.440     raeburn  3876: # this is for a course, not a user, so set context to coursedoc.
1.329     droeschl 3877:         my $newidx=&LONCAPA::map::getresidx();
                   3878:         $destination .= $newidx;
1.439     raeburn  3879:         my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329     droeschl 3880: 						$parseaction,$allfiles,
1.440     raeburn  3881: 						$codebase,undef,undef,undef,undef,
                   3882:                                                 undef,undef,\$mimetype);
                   3883:         if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
                   3884:             my $stored = $1;
                   3885:             $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   3886:                           $stored.'</span>').'</p>';
                   3887:         } else {
                   3888:             my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
                   3889:             
1.457     raeburn  3890:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440     raeburn  3891:             return;
                   3892:         }
1.329     droeschl 3893:         my $ext='false';
                   3894:         if ($url=~m{^http://}) { $ext='true'; }
                   3895: 	$url     = &LONCAPA::map::qtunescape($url);
                   3896:         my $comment=$env{'form.comment'};
                   3897: 	$comment = &LONCAPA::map::qtunescape($comment);
                   3898:         if ($folder=~/^supplemental/) {
                   3899:               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   3900:                   $env{'user.domain'}.'___&&&___'.$comment;
                   3901:         }
                   3902: 
                   3903:         $LONCAPA::map::resources[$newidx]=
                   3904: 	    $comment.':'.$url.':'.$ext.':normal:res';
                   3905:         $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
                   3906:         ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  3907: 				    $folder.'.'.$container,1);
1.329     droeschl 3908:         if ($fatal) {
1.457     raeburn  3909:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440     raeburn  3910:             return;
1.329     droeschl 3911:         } else {
1.440     raeburn  3912:             if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
                   3913:                 $$upload_output = $showupload;
1.384     raeburn  3914:                 my $total_embedded = scalar(keys(%{$allfiles}));
1.329     droeschl 3915:                 if ($total_embedded > 0) {
1.440     raeburn  3916:                     my $uploadphase = 'upload_embedded';
                   3917:                     my $primaryurl = &HTML::Entities::encode($url,'<>&"');
                   3918: 		    my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx); 
1.630     raeburn  3919:                     my ($embedded,$num) =
1.440     raeburn  3920:                         &Apache::loncommon::ask_for_embedded_content(
                   3921:                             '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
                   3922:                     if ($embedded) {
                   3923:                         if ($num) {
                   3924:                             $$upload_output .=
                   3925: 			         '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
                   3926:                             $nextphase = $uploadphase;
                   3927:                         } else {
                   3928:                             $$upload_output .= $embedded;
                   3929:                         }
                   3930:                     } else {
                   3931:                         $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
                   3932:                     }
1.329     droeschl 3933:                 } else {
1.440     raeburn  3934:                     $$upload_output .= &mt('No embedded items identified').'<br />';
1.329     droeschl 3935:                 }
1.457     raeburn  3936:                 $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578     raeburn  3937:             } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
                   3938:                      ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476     raeburn  3939:                 $nextphase = 'decompress_uploaded';
                   3940:                 my $position = scalar(@LONCAPA::map::order)-1;
                   3941:                 my $noextract = &return_to_editor();
                   3942:                 my $archiveurl = &HTML::Entities::encode($url,'<>&"');
                   3943:                 my %archiveitems = (
                   3944:                     folderpath => $env{'form.folderpath'},
                   3945:                     cmd        => $nextphase,
                   3946:                     newidx     => $newidx,
                   3947:                     position   => $position,
                   3948:                     phase      => $nextphase,
1.477     raeburn  3949:                     comment    => $comment,
1.480     raeburn  3950:                 );
                   3951:                 my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
                   3952:                 my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx); 
1.476     raeburn  3953:                 $$upload_output = $showupload.
                   3954:                                   &Apache::loncommon::decompress_form($mimetype,
                   3955:                                       $archiveurl,'/adm/coursedocs',$noextract,
1.480     raeburn  3956:                                       \%archiveitems,\@current);
1.329     droeschl 3957:             }
                   3958:         }
                   3959:     }
1.440     raeburn  3960:     return $nextphase;
1.329     droeschl 3961: }
                   3962: 
1.480     raeburn  3963: sub get_dir_list {
                   3964:     my ($url,$coursenum,$coursedom,$newidx) = @_;
                   3965:     my ($destination,$dir_root) = &embedded_destination();
                   3966:     my ($dirlistref,$listerror) =  
                   3967:         &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
                   3968:     my @dir_lines;
                   3969:     my $dirptr=16384;
                   3970:     if (ref($dirlistref) eq 'ARRAY') {
                   3971:         foreach my $dir_line (sort
                   3972:                           {
                   3973:                               my ($afile)=split('&',$a,2);
                   3974:                               my ($bfile)=split('&',$b,2);
                   3975:                               return (lc($afile) cmp lc($bfile));
                   3976:                           } (@{$dirlistref})) {
                   3977:             my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
                   3978:             $filename =~ s/\s+$//;
                   3979:             next if ($filename =~ /^\.\.?$/); 
                   3980:             my $isdir = 0;
                   3981:             if ($dirptr&$testdir) {
                   3982:                 $isdir = 1;
                   3983:             }
                   3984:             push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
                   3985:         }
                   3986:     }
                   3987:     return @dir_lines;
                   3988: }
                   3989: 
1.329     droeschl 3990: sub is_supplemental_title {
                   3991:     my ($title) = @_;
                   3992:     return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
                   3993: }
                   3994: 
                   3995: # --------------------------------------------------------------- An entry line
                   3996: 
                   3997: sub entryline {
1.501     raeburn  3998:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598     raeburn  3999:         $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685     raeburn  4000:         $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687     raeburn  4001:     my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329     droeschl 4002:     if (&is_supplemental_title($title)) {
1.488     raeburn  4003: 	($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687     raeburn  4004:         $encodedtitle=$title;
1.329     droeschl 4005:     } else {
                   4006: 	$title=&HTML::Entities::encode($title,'"<>&\'');
1.687     raeburn  4007:         $encodedtitle=$title;
1.329     droeschl 4008: 	$renametitle=$title;
                   4009: 	$foldertitle=$title;
                   4010:     }
                   4011: 
1.611     raeburn  4012:     my ($disabled,$readonly,$js_lt);
                   4013:     unless ($canedit) {
                   4014:         $disabled = 'disabled="disabled"';
                   4015:         $readonly = 1;
                   4016:     }
                   4017: 
1.329     droeschl 4018:     my $orderidx=$LONCAPA::map::order[$index];
1.364     bisitz   4019: 
1.329     droeschl 4020:     $renametitle=~s/\\/\\\\/g;
                   4021:     $renametitle=~s/\&quot\;/\\\"/g;
1.585     raeburn  4022:     $renametitle=~s/"/%22/g;
1.581     raeburn  4023:     $renametitle=~s/ /%20/g;
                   4024:     $oldtitle = $renametitle;
1.576     raeburn  4025:     $renametitle=~s/\&#39;/\\\'/g;
1.379     bisitz   4026:     my $line=&Apache::loncommon::start_data_table_row();
1.538     raeburn  4027:     my ($form_start,$form_end,$form_common,$form_param);
1.329     droeschl 4028: # Edit commands
1.679     raeburn  4029:     my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329     droeschl 4030:     if ($env{'form.folderpath'}) {
                   4031: 	$esc_path=&escape($env{'form.folderpath'});
                   4032: 	$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   4033: 	# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
                   4034:     }
1.505     raeburn  4035:     my $isexternal;
1.510     raeburn  4036:     if ($residx) {
1.501     raeburn  4037:         my $currurl = $url;
                   4038:         $currurl =~ s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
1.505     raeburn  4039:         if ($currurl =~ m{^/adm/wrapper/ext/}) {
                   4040:             $isexternal = 1;
                   4041:         }
1.510     raeburn  4042:         if (!$supplementalflag) {
                   4043:             my $path = 'uploaded/'.
                   4044:                        $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   4045:                        $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
                   4046:             $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
                   4047:                                                  $residx,
                   4048:                                                  &Apache::lonnet::declutter($currurl));
                   4049:         }
1.501     raeburn  4050:     }
1.538     raeburn  4051:     my ($renamelink,%lt,$ishash);
                   4052:     if (ref($filtersref) eq 'HASH') {
                   4053:         $ishash = 1;
                   4054:     }
                   4055: 
1.329     droeschl 4056:     if ($allowed) {
1.538     raeburn  4057:         $form_start = '
                   4058:    <form action="/adm/coursedocs" method="post">
                   4059: ';
                   4060:         $form_common=(<<END);
                   4061:    <input type="hidden" name="folderpath" value="$path" />
                   4062:    <input type="hidden" name="symb" value="$symb" />
                   4063: END
                   4064:         $form_param=(<<END);
                   4065:    <input type="hidden" name="setparms" value="$orderidx" />
                   4066:    <input type="hidden" name="changeparms" value="0" />
                   4067: END
                   4068:         $form_end = '</form>';
                   4069: 
1.329     droeschl 4070: 	my $incindex=$index+1;
                   4071: 	my $selectbox='';
1.471     raeburn  4072: 	if (($#LONCAPA::map::order>0) &&
1.329     droeschl 4073: 	    ((split(/\:/,
1.344     bisitz   4074: 	     $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
                   4075: 	     ne '') &&
1.329     droeschl 4076: 	    ((split(/\:/,
1.344     bisitz   4077: 	     $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329     droeschl 4078: 	     ne '')) {
                   4079: 	    $selectbox=
                   4080: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611     raeburn  4081: 		'<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329     droeschl 4082: 	    for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
                   4083: 		if ($i==$incindex) {
1.358     bisitz   4084: 		    $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329     droeschl 4085: 		} else {
                   4086: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
                   4087: 		}
                   4088: 	    }
                   4089: 	    $selectbox.='</select>';
                   4090: 	}
1.501     raeburn  4091: 	%lt=&Apache::lonlocal::texthash(
1.329     droeschl 4092:                 'up' => 'Move Up',
                   4093: 		'dw' => 'Move Down',
                   4094: 		'rm' => 'Remove',
                   4095:                 'ct' => 'Cut',
                   4096: 		'rn' => 'Rename',
1.501     raeburn  4097: 		'cp' => 'Copy',
1.633     raeburn  4098:                 'da' => 'Unset alias', 
                   4099:                 'sa' => 'Set alias',
1.501     raeburn  4100:                 'ex' => 'External Resource',
1.598     raeburn  4101:                 'et' => 'External Tool',
1.501     raeburn  4102:                 'ed' => 'Edit',
                   4103:                 'pr' => 'Preview',
                   4104:                 'sv' => 'Save',
                   4105:                 'ul' => 'URL',
1.611     raeburn  4106:                 'ti' => 'Title',
1.618     raeburn  4107:                 'er' => 'Editing rights unavailable for your current role.', 
1.501     raeburn  4108:                 );
1.538     raeburn  4109: 	my %denied = &action_restrictions($coursenum,$coursedom,$url,
                   4110:                                           $env{'form.folderpath'},
                   4111:                                           $currgroups);
1.517     raeburn  4112:         my ($copylink,$cutlink,$removelink);
1.329     droeschl 4113: 	my $skip_confirm = 0;
1.603     raeburn  4114:         my $confirm_removal = 0;
1.329     droeschl 4115: 	if ( $folder =~ /^supplemental/
                   4116: 	     || ($url =~ m{( /smppg$
                   4117: 			    |/syllabus$
                   4118: 			    |/aboutme$
                   4119: 			    |/navmaps$
                   4120: 			    |/bulletinboard$
1.626     raeburn  4121:                             |/ext\.tool$
1.505     raeburn  4122: 			    |\.html$)}x)
                   4123:              || $isexternal) {
1.329     droeschl 4124: 	    $skip_confirm = 1;
                   4125: 	}
1.603     raeburn  4126:         if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   4127:             ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   4128:             $confirm_removal = 1;
                   4129:         }
1.633     raeburn  4130:         if ($url =~ /$LONCAPA::assess_re/) {
                   4131:             $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
                   4132:         }
1.329     droeschl 4133: 
1.538     raeburn  4134: 	if ($denied{'copy'}) {
1.543     raeburn  4135:             $copylink=(<<ENDCOPY)
1.507     raeburn  4136: <span style="visibility: hidden;">$lt{'cp'}</span>
                   4137: ENDCOPY
                   4138:         } else {
1.538     raeburn  4139:             my $formname = 'edit_copy_'.$orderidx;
                   4140:             my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 4141: 	    $copylink=(<<ENDCOPY);
1.538     raeburn  4142: <form name="$formname" method="post" action="/adm/coursedocs">
                   4143: $form_common
1.611     raeburn  4144: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.538     raeburn  4145: $form_end
1.329     droeschl 4146: ENDCOPY
1.538     raeburn  4147:             if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
                   4148:                 push(@{$filtersref->{'cancopy'}},$orderidx);
                   4149:             }
1.329     droeschl 4150:         }
1.538     raeburn  4151: 	if ($denied{'cut'}) {
1.507     raeburn  4152:             $cutlink=(<<ENDCUT);
                   4153: <span style="visibility: hidden;">$lt{'ct'}</span>
                   4154: ENDCUT
                   4155:         } else {
1.538     raeburn  4156:             my $formname = 'edit_cut_'.$orderidx;
                   4157:             my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 4158: 	    $cutlink=(<<ENDCUT);
1.538     raeburn  4159: <form name="$formname" method="post" action="/adm/coursedocs">
                   4160: $form_common
1.542     raeburn  4161: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611     raeburn  4162: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.538     raeburn  4163: $form_end
1.329     droeschl 4164: ENDCUT
1.538     raeburn  4165:             if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
                   4166:                 push(@{$filtersref->{'cancut'}},$orderidx);
                   4167:             }
1.329     droeschl 4168:         }
1.538     raeburn  4169:         if ($denied{'remove'}) {
1.507     raeburn  4170:             $removelink=(<<ENDREM);
                   4171: <span style="visibility: hidden;">$lt{'rm'}</a>
                   4172: ENDREM
                   4173:         } else {
1.538     raeburn  4174:             my $formname = 'edit_remove_'.$orderidx;
1.603     raeburn  4175:             my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497     raeburn  4176:             $removelink=(<<ENDREM);
1.538     raeburn  4177: <form name="$formname" method="post" action="/adm/coursedocs">
                   4178: $form_common
1.542     raeburn  4179: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603     raeburn  4180: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611     raeburn  4181: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.538     raeburn  4182: $form_end
1.497     raeburn  4183: ENDREM
1.538     raeburn  4184:             if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
                   4185:                 push(@{$filtersref->{'canremove'}},$orderidx);
                   4186:             }
1.497     raeburn  4187:         }
1.551     raeburn  4188:         $renamelink=(<<ENDREN);
1.581     raeburn  4189: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507     raeburn  4190: ENDREN
1.611     raeburn  4191:         my ($uplink,$downlink);
                   4192:         if ($canedit) {
                   4193:             $uplink = "/adm/coursedocs?cmd=up_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   4194:             $downlink = "/adm/coursedocs?cmd=down_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   4195:         } else {
                   4196:             $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
                   4197:             $downlink = $uplink;
                   4198:         }
1.329     droeschl 4199: 	$line.=(<<END);
                   4200: <td>
1.379     bisitz   4201: <div class="LC_docs_entry_move">
1.611     raeburn  4202:   <a href="$uplink">
1.501     raeburn  4203:     <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379     bisitz   4204:   </a>
                   4205: </div>
                   4206: <div class="LC_docs_entry_move">
1.611     raeburn  4207:   <a href="$downlink">
1.501     raeburn  4208:     <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379     bisitz   4209:   </a>
                   4210: </div>
1.329     droeschl 4211: </td>
                   4212: <td>
                   4213:    $form_start
1.538     raeburn  4214:    $form_param
1.478     raeburn  4215:    $form_common
1.329     droeschl 4216:    $selectbox
                   4217:    $form_end
                   4218: </td>
1.540     raeburn  4219: <td class="LC_docs_entry_commands LC_nobreak">
1.497     raeburn  4220: $removelink
1.329     droeschl 4221: $cutlink
                   4222: $copylink
                   4223: </td>
                   4224: END
                   4225:     }
                   4226: # Figure out what kind of a resource this is
                   4227:     my ($extension)=($url=~/\.(\w+)$/);
                   4228:     my $uploaded=($url=~/^\/*uploaded\//);
                   4229:     my $icon=&Apache::loncommon::icon($url);
1.519     raeburn  4230:     my $isfolder;
                   4231:     my $ispage;
                   4232:     my $containerarg;
1.615     raeburn  4233:     my $folderurl;
1.685     raeburn  4234:     my $plainurl;
1.329     droeschl 4235:     if ($uploaded) {
1.472     raeburn  4236:         if (($extension eq 'sequence') || ($extension eq 'page')) {
                   4237:             $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519     raeburn  4238:             $containerarg = $1;
1.472     raeburn  4239: 	    if ($extension eq 'sequence') {
                   4240: 	        $icon=$iconpath.'navmap.folder.closed.gif';
                   4241:                 $isfolder=1;
                   4242:             } else {
                   4243:                 $icon=$iconpath.'page.gif';
                   4244:                 $ispage=1;
                   4245:             }
1.615     raeburn  4246:             $folderurl = &Apache::lonnet::declutter($url);
1.472     raeburn  4247:             if ($allowed) {
                   4248:                 $url='/adm/coursedocs?';
                   4249:             } else {
                   4250:                 $url='/adm/supplemental?';
                   4251:             }
1.329     droeschl 4252: 	} else {
1.685     raeburn  4253: 	    $plainurl = $url;
1.329     droeschl 4254: 	}
                   4255:     }
1.364     bisitz   4256: 
1.621     raeburn  4257:     my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329     droeschl 4258:     my $orig_url = $url;
1.340     raeburn  4259:     $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.668     raeburn  4260:     if ($container eq 'page') {
                   4261:         $url=~s{^http(|s)(&colon;|:)//}{/ext/};
                   4262:     } else {
                   4263:         $url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
                   4264:     }
1.501     raeburn  4265:     if (!$supplementalflag && $residx && $symb) {
                   4266:         if ((!$isfolder) && (!$ispage)) {
                   4267: 	    (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668     raeburn  4268:             if (($url =~ m{^ext/}) && ($container eq 'page')) {
                   4269:                 $url=&Apache::lonnet::clutter_with_no_wrapper($url);
                   4270:             } else {
                   4271:                 $url=&Apache::lonnet::clutter($url);
                   4272:             } 
1.501     raeburn  4273: 	    if ($url=~/^\/*uploaded\//) {
                   4274: 	        $url=~/\.(\w+)$/;
                   4275: 	        my $embstyle=&Apache::loncommon::fileembstyle($1);
                   4276: 	        if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                   4277: 		    $url='/adm/wrapper'.$url;
                   4278: 	        } elsif ($embstyle eq 'ssi') {
                   4279: 		    #do nothing with these
                   4280: 	        } elsif ($url!~/\.(sequence|page)$/) {
                   4281: 		    $url='/adm/coursedocs/showdoc'.$url;
                   4282: 	        }
1.623     raeburn  4283: 	    } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
                   4284:                 my $wrapped = $1;
                   4285:                 my $exturl = $2;
1.668     raeburn  4286:                 if (($wrapped eq '') && ($container ne 'page')) { 
1.623     raeburn  4287:                     $url='/adm/wrapper'.$url;
                   4288:                 }
                   4289:                 if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
                   4290:                     $nomodal = 1;
                   4291:                 }
1.626     raeburn  4292: 	    } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4293: 		$url='/adm/wrapper'.$url;
1.621     raeburn  4294:             } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
                   4295:                 if (($ENV{'SERVER_PORT'} == 443) &&
                   4296:                     ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  4297:                     unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  4298:                         $url .= '?usehttp=1';
                   4299:                     }
1.621     raeburn  4300:                     $nomodal = 1;
                   4301:                 }
1.598     raeburn  4302:             }
1.696     raeburn  4303:             my $checkencrypt;
1.680     raeburn  4304:             if (!$env{'request.role.adv'}) {
1.615     raeburn  4305:                 if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680     raeburn  4306:                     ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615     raeburn  4307:                     $checkencrypt = 1;
1.620     raeburn  4308:                 } elsif (ref($navmapref)) {
1.615     raeburn  4309:                     unless (ref($$navmapref)) {
                   4310:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   4311:                     }
                   4312:                     if (ref($$navmapref)) {
                   4313:                         if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680     raeburn  4314:                             $checkencrypt = 1;
1.615     raeburn  4315:                         }
                   4316:                     }
                   4317:                 }
1.680     raeburn  4318:             }
                   4319:             if ($checkencrypt) {
                   4320:                 my $currenc = $env{'request.enc'};
                   4321:                 $env{'request.enc'} = 1;
                   4322:                 $shownsymb = &Apache::lonenc::encrypted($symb);
1.696     raeburn  4323:                 my $shownurl = &Apache::lonenc::encrypted($url);
1.680     raeburn  4324:                 if (&Apache::lonnet::symbverify($symb,$url)) {
                   4325:                     $url = $shownurl;
                   4326:                 } else {
                   4327:                     $url = '';
                   4328:                 }
                   4329:                 $env{'request.enc'} = $currenc;
                   4330:             } elsif (&Apache::lonnet::symbverify($symb,$url)) {
                   4331:                 $shownsymb = $symb;
                   4332:                 if ($isexternal) {
                   4333:                     $url =~ s/\#[^#]+$//;
                   4334:                     if ($container eq 'page') {
                   4335:                         $url = &Apache::lonnet::clutter($url);
1.613     raeburn  4336:                     }
1.612     raeburn  4337:                 }
1.696     raeburn  4338:             } else {
                   4339:                 $url = '';
1.680     raeburn  4340:             }
                   4341:             unless ($env{'request.role.adv'}) {
                   4342:                 if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4343:                     $url = '';
                   4344:                 }
                   4345:                 if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
                   4346:                     $url = '';
                   4347:                     $hiddenres = 1;
                   4348:                 }
                   4349:             }
1.696     raeburn  4350:             if (($url ne '') && ($shownsymb ne '')) {
                   4351:                 $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501     raeburn  4352:             }
1.329     droeschl 4353: 	}
1.621     raeburn  4354:     } elsif ($supplementalflag) {
1.610     raeburn  4355:         if ($isexternal) {
                   4356:             if ($url =~ /^([^#]+)#([^#]+)$/) {
                   4357:                 $url = $1;
                   4358:                 $anchor = $2;
1.623     raeburn  4359:                 if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678     raeburn  4360:                     unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  4361:                         if ($hostname ne '') {
                   4362:                             $url = 'http://'.$hostname.$url;
                   4363:                         }
                   4364:                         $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.623     raeburn  4365:                     }
                   4366:                     $nomodal = 1;
                   4367:                 }
1.610     raeburn  4368:             }
1.621     raeburn  4369:         } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   4370:             if (($ENV{'SERVER_PORT'} == 443) &&
                   4371:                 ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  4372:                 unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  4373:                     if ($hostname ne '') {
                   4374:                         $url = 'http://'.$hostname.$url;
                   4375:                     }
                   4376:                     $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  4377:                 }
1.621     raeburn  4378:                 $nomodal = 1;
                   4379:             }
1.686     raeburn  4380:         } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
                   4381:             my $embstyle=&Apache::loncommon::fileembstyle($extension);
                   4382:             unless ($embstyle eq 'ssi') {
                   4383:                 if (($embstyle eq 'img')
                   4384:                  || ($embstyle eq 'emb')
                   4385:                  || ($embstyle eq 'wrp')) {
                   4386:                     $url='/adm/wrapper'.$url;
                   4387:                 } elsif ($url !~ /\.(sequence|page)$/) {
                   4388:                     $url='/adm/coursedocs/showdoc'.$url;
                   4389:                 }
                   4390:             }
1.610     raeburn  4391:         }
1.685     raeburn  4392:         unless ($allowed && $env{'request.role.adv'}) {
                   4393:             if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4394:                 $hiddenres = 1;
                   4395:             }
                   4396:         }
1.329     droeschl 4397:     }
1.615     raeburn  4398:     my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617     raeburn  4399:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519     raeburn  4400:     if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329     droeschl 4401: 	my $foldername=&escape($foldertitle);
                   4402: 	my $folderpath=$env{'form.folderpath'};
                   4403: 	if ($folderpath) { $folderpath.='&' };
1.510     raeburn  4404:         if (!$allowed && $supplementalflag) {
1.519     raeburn  4405:             $folderpath.=$containerarg.'&'.$foldername;
1.510     raeburn  4406:             $url.='folderpath='.&escape($folderpath);
1.685     raeburn  4407:             if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4408:                 $hiddenfolder = 1;
1.682     raeburn  4409:             }
1.510     raeburn  4410:         } else {
1.617     raeburn  4411:             my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
                   4412:                                                         'parameter_randompick'))[0];
                   4413:             my $randorder = ((&LONCAPA::map::getparameter($orderidx,
                   4414:                                               'parameter_randomorder'))[0]=~/^yes$/i);
                   4415:             my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
                   4416:                                               'parameter_hiddenresource'))[0]=~/^yes$/i);
                   4417:             my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
                   4418:                                               'parameter_encrypturl'))[0]=~/^yes$/i);
                   4419:             unless ($hiddenmap) {
1.620     raeburn  4420:                 if (ref($navmapref)) {
                   4421:                     unless (ref($$navmapref)) {
                   4422:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   4423:                     }
                   4424:                     if (ref($$navmapref)) {
                   4425:                         if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
                   4426:                             my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
                   4427:                             unless (@resources) {
                   4428:                                 $hiddenmap = 1;
                   4429:                                 unless ($env{'request.role.adv'}) {  
                   4430:                                     $url = '';
                   4431:                                     $hiddenfolder = 1;
                   4432:                                 }
1.617     raeburn  4433:                             }
1.615     raeburn  4434:                         }
                   4435:                     }
                   4436:                 }
                   4437:             }
1.617     raeburn  4438:             unless ($encryptmap) {
1.620     raeburn  4439:                 if ((ref($navmapref)) && (ref($$navmapref))) {
                   4440:                     if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
                   4441:                         $encryptmap = 1;
                   4442:                     }
1.617     raeburn  4443:                 }
                   4444:             }
1.630     raeburn  4445: 
1.617     raeburn  4446: # Append randompick number, hidden, and encrypted with ":" to foldername,
                   4447: # so it gets transferred between levels
                   4448: 	    $folderpath.=$containerarg.'&'.$foldername.
                   4449:                          ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615     raeburn  4450:             unless ($url eq '') {
1.612     raeburn  4451:                 $url.='folderpath='.&escape($folderpath);
                   4452:             }
1.510     raeburn  4453:             my $rpckchk;
                   4454:             if ($rpicknum) {
                   4455:                 $rpckchk = ' checked="checked"';
1.543     raeburn  4456:                 if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
                   4457:                     push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
                   4458:                 }
1.510     raeburn  4459:             }
1.537     raeburn  4460:             my $formname = 'edit_randompick_'.$orderidx;
1.510     raeburn  4461: 	    $rand_pick_text = 
1.478     raeburn  4462: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  4463: $form_param."\n".
1.478     raeburn  4464: $form_common."\n".
1.611     raeburn  4465: '<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  4466:             if ($rpicknum ne '') {
                   4467:                 $rand_pick_text .= ':&nbsp;<a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
                   4468:             }
1.537     raeburn  4469:             $rand_pick_text .= '</span></span>'.
                   4470:                                $form_end;
1.543     raeburn  4471:             my $ro_set;
1.617     raeburn  4472:             if ($randorder) {
1.543     raeburn  4473:                 $ro_set = 'checked="checked"';
                   4474:                 if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
                   4475:                     push(@{$filtersref->{'randomorder'}},$orderidx);
                   4476:                 }
                   4477:             }
1.564     raeburn  4478:             $formname = 'edit_rorder_'.$orderidx;
1.510     raeburn  4479: 	    $rand_order_text = 
1.537     raeburn  4480: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  4481: $form_param."\n".
1.537     raeburn  4482: $form_common."\n".
1.611     raeburn  4483: '<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  4484: $form_end; 
1.510     raeburn  4485:         }
1.509     raeburn  4486:     } elsif ($supplementalflag && !$allowed) {
1.598     raeburn  4487:         my $isexttool;
1.626     raeburn  4488:         if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4489:             $url='/adm/wrapper'.$url;
                   4490:             $isexttool = 1;
                   4491:         }
1.510     raeburn  4492:         $url .= ($url =~ /\?/) ? '&amp;':'?';
1.509     raeburn  4493:         $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510     raeburn  4494:         if ($title) {
1.687     raeburn  4495:             $url .= '&amp;title='.$encodedtitle;
1.510     raeburn  4496:         }
1.598     raeburn  4497:         if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510     raeburn  4498:             $url .= '&amp;idx='.$orderidx;
                   4499:         }
1.610     raeburn  4500:         if ($anchor ne '') {
                   4501:             $url .= '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   4502:         }
1.329     droeschl 4503:     }
1.519     raeburn  4504:     my ($tdalign,$tdwidth);
1.501     raeburn  4505:     if ($allowed) {
1.630     raeburn  4506:         my $fileloc =
1.501     raeburn  4507:             &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510     raeburn  4508:         if ($isexternal) {
1.630     raeburn  4509:             ($editlink,$extresform) =
1.611     raeburn  4510:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   4511:                                                      undef,undef,undef,undef,undef,undef,
                   4512:                                                      undef,$disabled);
1.626     raeburn  4513:         } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4514:             ($editlink,$extresform) =
                   4515:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   4516:                                                      undef,undef,undef,'tool',$coursedom,
1.611     raeburn  4517:                                                      $coursenum,$ltitoolsref,$disabled);
1.511     raeburn  4518:         } elsif (!$isfolder && !$ispage) {
1.503     raeburn  4519:             my ($cfile,$home,$switchserver,$forceedit,$forceview) = 
                   4520:                 &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511     raeburn  4521:             if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610     raeburn  4522:                 my $suppanchor;
                   4523:                 if ($supplementalflag) {
                   4524:                     $suppanchor = $anchor;
                   4525:                 }
1.630     raeburn  4526:                 my $jscall =
1.501     raeburn  4527:                     &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
                   4528:                                                             $switchserver,
1.503     raeburn  4529:                                                             $forceedit,
1.679     raeburn  4530:                                                             undef,$symb,$shownsymb,
1.511     raeburn  4531:                                                             &escape($env{'form.folderpath'}),
1.622     raeburn  4532:                                                             $renametitle,$hostname,
                   4533:                                                             '','',1,$suppanchor);
1.501     raeburn  4534:                 if ($jscall) {
1.518     raeburn  4535:                     $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
                   4536:                                 $jscall.'" >'.&mt('Edit').'</a>&nbsp;'."\n";
1.501     raeburn  4537:                 }
                   4538:             }
                   4539:         }
1.519     raeburn  4540:         $tdalign = ' align="right" valign="top"';
                   4541:         $tdwidth = ' width="80%"';
1.329     droeschl 4542:     }
1.408     raeburn  4543:     my $reinit;
                   4544:     if ($crstype eq 'Community') {
                   4545:         $reinit = &mt('(re-initialize community to access)');
                   4546:     } else {
                   4547:         $reinit = &mt('(re-initialize course to access)');
1.519     raeburn  4548:     }
                   4549:     $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650     raeburn  4550:     if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633     raeburn  4551:         $line.= '<br />';
                   4552:         if ($curralias ne '') {
                   4553:             $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   4554:                    $lt{'da'}.'</a></span>';
                   4555:         } else {
                   4556:             $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   4557:                    $lt{'sa'}.'</a></span>';
                   4558:         }
                   4559:     }
                   4560:     $line.='</td><td>';
1.685     raeburn  4561:     my ($link,$nolink);
1.472     raeburn  4562:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685     raeburn  4563:         if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
                   4564:             if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4565:                 $nolink = 1;
                   4566:             }
                   4567:         }
                   4568:         if ($nolink) {
                   4569:             $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
                   4570:         } else {
                   4571:             $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
                   4572:         }
1.469     www      4573:     } elsif ($url) {
1.610     raeburn  4574:        if ($anchor ne '') {
                   4575:            if ($supplementalflag) {
                   4576:                $anchor = '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   4577:            } else {
                   4578:                $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
                   4579:            }
                   4580:        }
1.622     raeburn  4581:        if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
                   4582:            $link = 'http://'.$hostname.$url;
                   4583:        } else {
                   4584:            $link = $url;
                   4585:        }
1.659     raeburn  4586:        $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.$anchor);
1.685     raeburn  4587:        if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
                   4588:            if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4589:                $nolink = 1;
                   4590:            }
                   4591:        }
                   4592:        if ($nolink) {
                   4593:            $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
                   4594:        } elsif ($nomodal) {
1.621     raeburn  4595:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   4596:                   '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
                   4597:        } else {
                   4598:            $line.=&Apache::loncommon::modal_link($link,
                   4599:                                                  '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
                   4600:        }
1.469     www      4601:     } else {
                   4602:        $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
                   4603:     }
1.519     raeburn  4604:     $line.='</span></td><td'.$tdwidth.'>';
1.472     raeburn  4605:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685     raeburn  4606:        if ($nolink) {
                   4607:            $line.=$title;
                   4608:        } else {
                   4609:            $line.='<a href="'.$url.'">'.$title.'</a>';
                   4610:        }
1.682     raeburn  4611:        if (!$allowed && $supplementalflag && $canedit && $isfolder) {
                   4612:            my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
                   4613:            my $editurl = $url;
                   4614:            $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;};
                   4615:            $line .= '&nbsp;'.'<a href="'.$editurl.'">'.
                   4616:                     '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
                   4617:                     '</a>';
                   4618:        }
                   4619:        if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag))  {
                   4620:            $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
                   4621:        }
1.469     www      4622:     } elsif ($url) {
1.685     raeburn  4623:        if ($nolink) {
                   4624:            $line.=$title;
                   4625:        } elsif ($nomodal) {
1.621     raeburn  4626:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   4627:                   $title.'</a>';
                   4628:        } else {
                   4629:            $line.=&Apache::loncommon::modal_link($link,$title,600,500);
                   4630:        }
1.617     raeburn  4631:     } elsif (($hiddenfolder) || ($hiddenres)) {
1.632     raeburn  4632:        $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469     www      4633:     } else {
                   4634:        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
                   4635:     }
1.633     raeburn  4636:     if (($allowed) && ($curralias ne '')) {
                   4637:         $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
                   4638:     } else {
                   4639:         $line .= $extresform;
                   4640:     }
                   4641:     $line .= '</td>';
1.478     raeburn  4642:     $rand_pick_text = '&nbsp;' if ($rand_pick_text eq '');
                   4643:     $rand_order_text = '&nbsp;' if ($rand_order_text eq '');
1.685     raeburn  4644:     if ($uploaded && $url && !$isfolder && !$ispage) {
                   4645:         if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
                   4646:             &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
                   4647:         }
                   4648:     }
1.682     raeburn  4649:     if ($allowed) {
                   4650:         my %lt=&Apache::lonlocal::texthash(
                   4651:                               'hd' => 'Hidden',
                   4652:                               'ec' => 'URL hidden');
                   4653:         my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543     raeburn  4654:         if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4655:             $hidtext = ' checked="checked"';
1.694     raeburn  4656:             if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543     raeburn  4657:                 push(@{$filtersref->{'hiddenresource'}},$orderidx);
                   4658:             }
                   4659:         }
1.682     raeburn  4660:         $formhidden = 'edit_hiddenresource_'.$orderidx;
                   4661:         $line.=(<<ENDPARMS);
1.329     droeschl 4662:   <td class="LC_docs_entry_parameter">
1.537     raeburn  4663:     <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538     raeburn  4664:     $form_param
1.478     raeburn  4665:     $form_common
1.611     raeburn  4666:     <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329     droeschl 4667:     $form_end
1.682     raeburn  4668: ENDPARMS
                   4669:         if ($folder =~/^supplemental/) {
                   4670:             $line.= "\n    <td>";
                   4671:         } else {
                   4672:             if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
                   4673:                 $enctext = ' checked="checked"';
                   4674:                 if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
                   4675:                     push(@{$filtersref->{'encrypturl'}},$orderidx);
                   4676:                 }
                   4677:             }
                   4678:             $formurlhidden = 'edit_encrypturl_'.$orderidx;
                   4679: 	    $line.=(<<ENDPARMS);
1.458     raeburn  4680:     <br />
1.537     raeburn  4681:     <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538     raeburn  4682:     $form_param
1.478     raeburn  4683:     $form_common
1.611     raeburn  4684:     <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329     droeschl 4685:     $form_end
                   4686:   </td>
1.478     raeburn  4687:   <td class="LC_docs_entry_parameter">$rand_pick_text<br />
                   4688:                                       $rand_order_text</td>
1.329     droeschl 4689: ENDPARMS
1.682     raeburn  4690:         }
1.329     droeschl 4691:     }
1.379     bisitz   4692:     $line.=&Apache::loncommon::end_data_table_row();
1.329     droeschl 4693:     return $line;
                   4694: }
                   4695: 
1.538     raeburn  4696: sub action_restrictions {
                   4697:     my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
                   4698:     my %denied = (
                   4699:                    cut    => 0,
                   4700:                    copy   => 0,
                   4701:                    remove => 0,
                   4702:                  );
                   4703:     if ($url=~ m{^/res/.+\.(page|sequence)$}) {
                   4704:         # no copy for published maps
                   4705:         $denied{'copy'} = 1;
1.597     raeburn  4706:     } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
                   4707:         unless ($1 eq 'simpleproblem') {
                   4708:             $denied{'copy'} = 1;
                   4709:         }
                   4710:         $denied{'cut'} = 1;
1.538     raeburn  4711:     } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
                   4712:         if ($folderpath =~ /^default&[^\&]+$/) {
                   4713:             if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
                   4714:                 $denied{'remove'} = 1;
                   4715:             }
                   4716:             $denied{'cut'} = 1;
                   4717:             $denied{'copy'} = 1;
                   4718:         }
                   4719:     } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
                   4720:         my $group = $1;
                   4721:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
                   4722:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   4723:                 $denied{'remove'} = 1;
                   4724:             }
                   4725:         }
                   4726:         $denied{'cut'} = 1;
                   4727:         $denied{'copy'} = 1;
                   4728:     } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
                   4729:         my $group = $1;
                   4730:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
                   4731:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   4732:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   4733:                 if (keys(%groupsettings) > 0) {
                   4734:                     $denied{'remove'} = 1;
                   4735:                 }
                   4736:                 $denied{'cut'} = 1;
                   4737:                 $denied{'copy'} = 1;
                   4738:             }
                   4739:         }
                   4740:     } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
                   4741:         my $group = $1;
                   4742:         if ($url =~ /group_boards_\Q$group\E/) {
                   4743:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   4744:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   4745:                 if (keys(%groupsettings) > 0) {
                   4746:                     if (ref($groupsettings{'functions'}) eq 'HASH') {
                   4747:                         if ($groupsettings{'functions'}{'discussion'} eq 'on') {
                   4748:                             $denied{'remove'} = 1;
                   4749:                         }
                   4750:                     }
                   4751:                 }
                   4752:                 $denied{'cut'} = 1;
                   4753:                 $denied{'copy'} = 1;
                   4754:             }
                   4755:         }
                   4756:     }
                   4757:     return %denied;
                   4758: }
                   4759: 
1.533     raeburn  4760: sub new_timebased_suffix {
1.538     raeburn  4761:     my ($dom,$num,$type,$area,$container) = @_;
1.533     raeburn  4762:     my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538     raeburn  4763:     if ($type eq 'paste') {
                   4764:         $prefix = $type;
                   4765:         $namespace = 'courseeditor';
1.587     raeburn  4766:         $idtype = 'addcode';
1.538     raeburn  4767:     } elsif ($type eq 'map') {
1.533     raeburn  4768:         $prefix = 'docs';
                   4769:         if ($area eq 'supplemental') {
                   4770:             $prefix = 'supp';
                   4771:         }
                   4772:         $prefix .= $container;
                   4773:         $namespace = 'uploadedmaps';
                   4774:     } else {
                   4775:         $prefix = $type;
                   4776:         $namespace = 'templated';
1.504     raeburn  4777:     }
                   4778:     my ($suffix,$freedlock,$error) =
1.587     raeburn  4779:         &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504     raeburn  4780:     if (!$suffix) {
1.538     raeburn  4781:         if ($type eq 'paste') {
                   4782:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
                   4783:         } elsif ($type eq 'map') {
1.533     raeburn  4784:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
                   4785:         } elsif ($type eq 'smppg') {
                   4786:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626     raeburn  4787:         } elsif ($type eq 'exttool') {
                   4788:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533     raeburn  4789:         } else {
1.565     bisitz   4790:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533     raeburn  4791:         }
1.504     raeburn  4792:         if ($error) {
                   4793:             $errtext .= '<br />'.$error;
                   4794:         }
                   4795:     }
                   4796:     if ($freedlock ne 'ok') {
1.630     raeburn  4797:         $locknotfreed =
1.533     raeburn  4798:             '<div class="LC_error">'.
                   4799:             &mt('There was a problem removing a lockfile.').' ';
1.538     raeburn  4800:         if ($type eq 'paste') {
1.591     raeburn  4801:             if ($freedlock eq 'nolock') {
                   4802:                 $locknotfreed =
                   4803:                     '<div class="LC_error">'.
                   4804:                     &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
                   4805:  
1.593     droeschl 4806:                     &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591     raeburn  4807:             } else { 
                   4808:                 $locknotfreed .=
                   4809:                     &mt('This will prevent addition of items to the clipboard until your next log-in.');
                   4810:             }
1.538     raeburn  4811:         } elsif ($type eq 'map') {
1.591     raeburn  4812:             $locknotfreed .=
                   4813:                 &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533     raeburn  4814:         } elsif ($type eq 'smppg') {
                   4815:             $locknotfreed .=
                   4816:                 &mt('This will prevent creation of additional simple pages in this course.');
1.626     raeburn  4817:         } elsif ($type eq 'exttool') {
                   4818:             $locknotfreed .=
                   4819:                 &mt('This will prevent creation of additional external tools in this course.');
1.533     raeburn  4820:         } else {
                   4821:             $locknotfreed .=
1.565     bisitz   4822:                 &mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  4823:         }
1.538     raeburn  4824:         unless ($type eq 'paste') {
                   4825:             $locknotfreed .=
1.560     raeburn  4826:                 ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   4827:                         '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538     raeburn  4828:         }
                   4829:         $locknotfreed .= '</div>';
1.504     raeburn  4830:     }
                   4831:     return ($suffix,$errtext,$locknotfreed);
                   4832: }
                   4833: 
1.329     droeschl 4834: =pod
                   4835: 
                   4836: =item tiehash()
                   4837: 
                   4838: tie the hash
                   4839: 
                   4840: =cut
                   4841: 
                   4842: sub tiehash {
                   4843:     my ($mode)=@_;
                   4844:     $hashtied=0;
                   4845:     if ($env{'request.course.fn'}) {
                   4846: 	if ($mode eq 'write') {
                   4847: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   4848: 		    &GDBM_WRCREAT(),0640)) {
                   4849:                 $hashtied=2;
                   4850: 	    }
                   4851: 	} else {
                   4852: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   4853: 		    &GDBM_READER(),0640)) {
                   4854:                 $hashtied=1;
                   4855: 	    }
                   4856: 	}
1.364     bisitz   4857:     }
1.329     droeschl 4858: }
                   4859: 
                   4860: sub untiehash {
                   4861:     if ($hashtied) { untie %hash; }
                   4862:     $hashtied=0;
                   4863:     return OK;
                   4864: }
                   4865: 
                   4866: 
                   4867: 
                   4868: 
                   4869: sub checkonthis {
1.637     raeburn  4870:     my ($r,$url,$level,$title,$checkstale)=@_;
1.329     droeschl 4871:     $url=&unescape($url);
                   4872:     $alreadyseen{$url}=1;
                   4873:     $r->rflush();
                   4874:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
                   4875:        $r->print("\n<br />");
                   4876:        if ($level==0) {
                   4877:            $r->print("<br />");
                   4878:        }
                   4879:        for (my $i=0;$i<=$level*5;$i++) {
                   4880:            $r->print('&nbsp;');
                   4881:        }
                   4882:        $r->print('<a href="'.$url.'" target="cat">'.
                   4883: 		 ($title?$title:$url).'</a> ');
                   4884:        if ($url=~/^\/res\//) {
1.637     raeburn  4885:           my $updated;
                   4886:           if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
                   4887:               ($url !~ /\.\d+\.\w+$/)) {
                   4888:               $updated = &Apache::lonnet::remove_stale_resfile($url);
                   4889:           }
1.329     droeschl 4890: 	  my $result=&Apache::lonnet::repcopy(
                   4891:                               &Apache::lonnet::filelocation('',$url));
                   4892:           if ($result eq 'ok') {
                   4893:              $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637     raeburn  4894:              if ($updated) {
                   4895:                  $r->print('<br />');
                   4896:                  for (my $i=0;$i<=$level*5;$i++) {
                   4897:                      $r->print('&nbsp;');
                   4898:                  }
                   4899:                  $r->print('- '.&mt('Outdated copy removed'));
                   4900:              }
1.329     droeschl 4901:              $r->rflush();
                   4902:              &Apache::lonnet::countacc($url);
                   4903:              $url=~/\.(\w+)$/;
                   4904:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                   4905: 		 $r->print('<br />');
                   4906:                  $r->rflush();
                   4907:                  for (my $i=0;$i<=$level*5;$i++) {
                   4908:                      $r->print('&nbsp;');
                   4909:                  }
                   4910:                  $r->print('- '.&mt('Rendering:').' ');
                   4911: 		 my ($errorcount,$warningcount)=split(/:/,
                   4912: 	       &Apache::lonnet::ssi_body($url,
                   4913: 			       ('grade_target'=>'web',
                   4914: 				'return_only_error_and_warning_counts' => 1)));
                   4915:                  if (($errorcount) ||
                   4916:                      ($warningcount)) {
                   4917: 		     if ($errorcount) {
1.369     bisitz   4918:                         $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329     droeschl 4919:                           &mt('[quant,_1,error]',$errorcount).'</span>');
                   4920:                      }
                   4921: 		     if ($warningcount) {
                   4922:                         $r->print('<span class="LC_warning">'.
                   4923:                           &mt('[quant,_1,warning]',$warningcount).'</span>');
                   4924:                      }
                   4925:                  } else {
                   4926:                      $r->print('<span class="LC_success">'.&mt('ok').'</span>');
                   4927:                  }
                   4928:                  $r->rflush();
                   4929:              }
                   4930: 	     my $dependencies=
                   4931:                 &Apache::lonnet::metadata($url,'dependencies');
                   4932:              foreach my $dep (split(/\,/,$dependencies)) {
                   4933: 		 if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637     raeburn  4934:                     &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329     droeschl 4935:                  }
                   4936:              }
                   4937:           } elsif ($result eq 'unavailable') {
                   4938:              $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
                   4939:           } elsif ($result eq 'not_found') {
                   4940: 	      unless ($url=~/\$/) {
1.521     bisitz   4941: 		  $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329     droeschl 4942: 	      } else {
1.366     bisitz   4943: 		  $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329     droeschl 4944: 	      }
                   4945:           } else {
                   4946:              $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
                   4947:           }
1.637     raeburn  4948:           if (($updated) && ($result ne 'ok')) {
                   4949:               $r->print('<br />'.&mt('Outdated copy removed'));
                   4950:           }
1.329     droeschl 4951:        }
                   4952:     }
                   4953: }
                   4954: 
                   4955: 
                   4956: 
                   4957: =pod
                   4958: 
                   4959: =item list_symbs()
                   4960: 
1.485     raeburn  4961: List Content Identifiers
1.329     droeschl 4962: 
                   4963: =cut
                   4964: 
                   4965: sub list_symbs {
                   4966:     my ($r) = @_;
                   4967: 
1.408     raeburn  4968:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  4969:     $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
                   4970:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
                   4971:     $r->print(&startContentScreen('tools'));
1.329     droeschl 4972:     my $navmap = Apache::lonnavmaps::navmap->new();
                   4973:     if (!defined($navmap)) {
                   4974:         $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
                   4975:                   '<div class="LC_error">'.
                   4976:                   &mt('Unable to retrieve information about course contents').
                   4977:                   '</div>');
1.408     raeburn  4978:         &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329     droeschl 4979:     } else {
1.484     raeburn  4980:         $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
                   4981:                   &Apache::loncommon::start_data_table().
                   4982:                   &Apache::loncommon::start_data_table_header_row().
                   4983:                   '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
                   4984:                   &Apache::loncommon::end_data_table_header_row()."\n");
                   4985:         my $count;
1.329     droeschl 4986:         foreach my $res ($navmap->retrieveResources()) {
1.484     raeburn  4987:             $r->print(&Apache::loncommon::start_data_table_row().
                   4988:                       '<td>'.$res->compTitle().'</td>'.
                   4989:                       '<td>'.$res->symb().'</td>'.
1.521     bisitz   4990:                       &Apache::loncommon::end_data_table_row());
1.484     raeburn  4991:             $count ++;
                   4992:         }
                   4993:         if (!$count) {
                   4994:             $r->print(&Apache::loncommon::start_data_table_row().
                   4995:                       '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
                   4996:                       &Apache::loncommon::end_data_table_row()); 
1.329     droeschl 4997:         }
1.484     raeburn  4998:         $r->print(&Apache::loncommon::end_data_table());
1.329     droeschl 4999:     }
1.521     bisitz   5000:     $r->print(&endContentScreen());
1.329     droeschl 5001: }
                   5002: 
1.651     raeburn  5003: sub short_urls {
                   5004:     my ($r,$canedit) = @_;
                   5005:     my $crstype = &Apache::loncommon::course_type();
                   5006:     my $formname = 'shortenurl';
                   5007:     $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
                   5008:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
                   5009:     $r->print(&startContentScreen('tools'));
                   5010:     my ($navmap,$errormsg) =
                   5011:         &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
                   5012:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   5013:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   5014:     my (%maps,%resources,%titles);
                   5015:     if (!ref($navmap)) {
                   5016:         $r->print($errormsg.
                   5017:                   &endContentScreen());
                   5018:         return '';
                   5019:     } else {
1.652     raeburn  5020:         $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651     raeburn  5021:         $r->rflush();
                   5022:         my $readonly;
                   5023:         if ($canedit) {
1.671     raeburn  5024:             my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651     raeburn  5025:             if ($numnew) {
                   5026:                 $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
                   5027:             }
                   5028:             if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
                   5029:                 $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
                   5030:                 foreach my $error (@{$errors}) {
                   5031:                     $r->print('<li>'.$error.'</li>');
                   5032:                 }
                   5033:                 $r->print('</ul><br />');
                   5034:             }
                   5035:         } else {
                   5036:             $readonly = 1;
                   5037:         }
                   5038:         my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
                   5039:         $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
                   5040:                                                              undef,undef,undef,undef,undef,\%currtiny,$readonly));
                   5041:     }
                   5042:     $r->print(&endContentScreen());
                   5043: }
                   5044: 
1.637     raeburn  5045: sub contentverifyform {
                   5046:     my ($r) = @_;
                   5047:     my $crstype = &Apache::loncommon::course_type();
                   5048:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   5049:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
                   5050:     $r->print(&startContentScreen('tools'));
                   5051:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
                   5052:     $r->print('<form method="post" action="/adm/coursedocs"><p>'.
                   5053:               &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
                   5054:               '&nbsp;<span class="LC_nobreak">'.
                   5055:               '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
                   5056:               &mt('No').'</label>'.('&nbsp;'x2).
                   5057:               '<label><input type="radio" name="checkstale" value="1" />'.
                   5058:               &mt('Yes').'</label></span></p><p>'.
1.674     raeburn  5059:               '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637     raeburn  5060:               '<input type="hidden" value="1" name="tools" />'.
                   5061:               '<input type="hidden" value="1" name="verify" /></p></form>');
                   5062:     $r->print(&endContentScreen());
                   5063:     return;
                   5064: }
1.329     droeschl 5065: 
                   5066: sub verifycontent {
1.637     raeburn  5067:     my ($r,$checkstale) = @_;
1.408     raeburn  5068:     my $crstype = &Apache::loncommon::course_type();
1.549     raeburn  5069:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   5070:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484     raeburn  5071:     $r->print(&startContentScreen('tools'));
                   5072:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>'); 
1.329     droeschl 5073:    $hashtied=0;
                   5074:    undef %alreadyseen;
                   5075:    %alreadyseen=();
                   5076:    &tiehash();
1.484     raeburn  5077:    
1.329     droeschl 5078:    foreach my $key (keys(%hash)) {
                   5079:        if ($hash{$key}=~/\.(page|sequence)$/) {
                   5080: 	   if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
                   5081: 	       $r->print('<hr /><span class="LC_error">'.
1.419     bisitz   5082: 			 &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329     droeschl 5083: 			 &unescape($hash{$key}).'</span><br />'.
1.419     bisitz   5084: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329     droeschl 5085: 	   }
                   5086:        }
                   5087:        if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637     raeburn  5088:            &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329     droeschl 5089:        }
                   5090:    }
                   5091:    &untiehash();
1.442     www      5092:    $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521     bisitz   5093:     $r->print(&endContentScreen());
1.329     droeschl 5094: }
                   5095: 
                   5096: sub devalidateversioncache {
                   5097:     my $src=shift;
                   5098:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
                   5099: 					  &Apache::lonnet::clutter($src));
                   5100: }
                   5101: 
                   5102: sub checkversions {
1.611     raeburn  5103:     my ($r,$canedit) = @_;
1.408     raeburn  5104:     my $crstype = &Apache::loncommon::course_type();
1.571     raeburn  5105:     $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
                   5106:     $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484     raeburn  5107:     $r->print(&startContentScreen('tools'));
1.442     www      5108: 
1.329     droeschl 5109:     my $header='';
                   5110:     my $startsel='';
                   5111:     my $monthsel='';
                   5112:     my $weeksel='';
                   5113:     my $daysel='';
                   5114:     my $allsel='';
                   5115:     my %changes=();
                   5116:     my $starttime=0;
                   5117:     my $haschanged=0;
                   5118:     my %setversions=&Apache::lonnet::dump('resourceversions',
                   5119: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   5120: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   5121: 
                   5122:     $hashtied=0;
                   5123:     &tiehash();
1.611     raeburn  5124:     if ($canedit) {
                   5125:         my %newsetversions=();
                   5126:         if ($env{'form.setmostrecent'}) {
                   5127: 	    $haschanged=1;
                   5128: 	    foreach my $key (keys(%hash)) {
                   5129: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   5130: 		    $newsetversions{$1}='mostrecent';
                   5131:                     &devalidateversioncache($1);
                   5132: 	        }
                   5133: 	    }
                   5134:         } elsif ($env{'form.setcurrent'}) {
                   5135: 	    $haschanged=1;
                   5136: 	    foreach my $key (keys(%hash)) {
                   5137: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   5138: 		    my $getvers=&Apache::lonnet::getversion($1);
                   5139: 		    if ($getvers>0) {
                   5140: 		        $newsetversions{$1}=$getvers;
                   5141: 		        &devalidateversioncache($1);
                   5142: 		    }
                   5143: 	        }
1.329     droeschl 5144: 	    }
1.611     raeburn  5145:         } elsif ($env{'form.setversions'}) {
                   5146: 	    $haschanged=1;
                   5147: 	    foreach my $key (keys(%env)) {
                   5148: 	        if ($key=~/^form\.set_version_(.+)$/) {
                   5149: 		    my $src=$1;
                   5150: 		    if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
                   5151: 		        $newsetversions{$src}=$env{$key};
                   5152: 		        &devalidateversioncache($src);
                   5153: 		    }
                   5154: 	        }
1.329     droeschl 5155: 	    }
1.611     raeburn  5156:         }
                   5157:         if ($haschanged) {
                   5158:             if (&Apache::lonnet::put('resourceversions',\%newsetversions,
                   5159: 			             $env{'course.'.$env{'request.course.id'}.'.domain'},
                   5160: 			             $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
                   5161: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   5162:                     &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
                   5163: 	    } else {
                   5164: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   5165:                     &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329     droeschl 5166: 	    }
1.611     raeburn  5167: 	    &mark_hash_old();
                   5168:         }
                   5169:         &changewarning($r,'');
1.329     droeschl 5170:     }
                   5171:     if ($env{'form.timerange'} eq 'all') {
                   5172: # show all documents
1.549     raeburn  5173: 	$header=&mt('All content in '.$crstype);
1.521     bisitz   5174: 	$allsel=' selected="selected"';
1.329     droeschl 5175: 	foreach my $key (keys(%hash)) {
                   5176: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   5177: 		my $src=$1;
                   5178: 		$changes{$src}=1;
                   5179: 	    }
                   5180: 	}
                   5181:     } else {
                   5182: # show documents which changed
                   5183: 	%changes=&Apache::lonnet::dump
                   5184: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
                   5185:                      $env{'course.'.$env{'request.course.id'}.'.num'});
                   5186: 	my $firstkey=(keys(%changes))[0];
                   5187: 	unless ($firstkey=~/^error\:/) {
                   5188: 	    unless ($env{'form.timerange'}) {
                   5189: 		$env{'form.timerange'}=604800;
                   5190: 	    }
                   5191: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
                   5192: 		.&mt('seconds');
                   5193: 	    if ($env{'form.timerange'}==-1) {
                   5194: 		$seltext='since start of course';
1.521     bisitz   5195: 		$startsel=' selected="selected"';
1.329     droeschl 5196: 		$env{'form.timerange'}=time;
                   5197: 	    }
                   5198: 	    $starttime=time-$env{'form.timerange'};
                   5199: 	    if ($env{'form.timerange'}==2592000) {
                   5200: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5201: 		$monthsel=' selected="selected"';
1.329     droeschl 5202: 	    } elsif ($env{'form.timerange'}==604800) {
                   5203: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5204: 		$weeksel=' selected="selected"';
1.329     droeschl 5205: 	    } elsif ($env{'form.timerange'}==86400) {
                   5206: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5207: 		$daysel=' selected="selected"';
1.329     droeschl 5208: 	    }
                   5209: 	    $header=&mt('Content changed').' '.$seltext;
                   5210: 	} else {
                   5211: 	    $header=&mt('No content modifications yet.');
                   5212: 	}
                   5213:     }
                   5214:     %setversions=&Apache::lonnet::dump('resourceversions',
                   5215: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   5216: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   5217:     my %lt=&Apache::lonlocal::texthash
1.408     raeburn  5218: 	      ('st' => 'Version changes since start of '.$crstype,
1.329     droeschl 5219: 	       'lm' => 'Version changes since last Month',
                   5220: 	       'lw' => 'Version changes since last Week',
                   5221: 	       'sy' => 'Version changes since Yesterday',
                   5222:                'al' => 'All Resources (possibly large output)',
1.484     raeburn  5223:                'cd' => 'Change display', 
1.329     droeschl 5224: 	       'sd' => 'Display',
                   5225: 	       'fi' => 'File',
                   5226: 	       'md' => 'Modification Date',
                   5227:                'mr' => 'Most recently published Version',
1.408     raeburn  5228: 	       've' => 'Version used in '.$crstype,
                   5229:                'vu' => 'Set Version to be used in '.$crstype,
                   5230: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329     droeschl 5231: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                   5232: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479     golterma 5233: 	       'di' => 'Differences',
1.484     raeburn  5234: 	       'save' => 'Save changes',
                   5235:                'vers' => 'Version choice(s) for specific resources', 
1.479     golterma 5236: 	       'act' => 'Actions');
1.611     raeburn  5237:     my ($disabled,$readonly);
                   5238:     unless ($canedit) {
                   5239:         $disabled = 'disabled="disabled"';
                   5240:         $readonly = 1;
                   5241:     }
1.329     droeschl 5242:     $r->print(<<ENDHEADERS);
1.484     raeburn  5243: <h4 class="LC_info">$header</h4>
1.329     droeschl 5244: <form action="/adm/coursedocs" method="post">
                   5245: <input type="hidden" name="versions" value="1" />
1.484     raeburn  5246: <div class="LC_left_float">
1.479     golterma 5247: <fieldset>
1.484     raeburn  5248: <legend>$lt{'cd'}</legend>
1.329     droeschl 5249: <select name="timerange">
1.521     bisitz   5250: <option value='all'$allsel>$lt{'al'}</option>
                   5251: <option value="-1"$startsel>$lt{'st'}</option>
                   5252: <option value="2592000"$monthsel>$lt{'lm'}</option>
                   5253: <option value="604800"$weeksel>$lt{'lw'}</option>
                   5254: <option value="86400"$daysel>$lt{'sy'}</option>
1.329     droeschl 5255: </select>
                   5256: <input type="submit" name="display" value="$lt{'sd'}" />
1.484     raeburn  5257: </fieldset>
                   5258: </div>
                   5259: <div class="LC_left_float">
                   5260: <fieldset>
                   5261: <legend>$lt{'act'}</legend>
1.611     raeburn  5262: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
                   5263: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484     raeburn  5264: </fieldset>
                   5265: </div>
                   5266: <br clear="all" />
                   5267: <hr />
                   5268: <h4>$lt{'vers'}</h4>
1.329     droeschl 5269: ENDHEADERS
1.479     golterma 5270:     #number of columns for version history
1.571     raeburn  5271:     my %changedbytime;
                   5272:     foreach my $key (keys(%changes)) {
                   5273:         #excludes not versionable problems from resource version history:
                   5274:         next if ($key =~ /^\/res\/lib\/templates/);
                   5275:         my $chg;
                   5276:         if ($env{'form.timerange'} eq 'all') {
                   5277:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   5278:             $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
                   5279:         } else {
                   5280:             $chg = $changes{$key};
                   5281:             next if ($chg < $starttime);
                   5282:         }
                   5283:         push(@{$changedbytime{$chg}},$key);
                   5284:     }
                   5285:     if (keys(%changedbytime) == 0) {
                   5286:         &untiehash();
                   5287:         $r->print(&mt('No content changes in imported content in specified time frame').
                   5288:                   &endContentScreen());
                   5289:         return;
                   5290:     }
1.479     golterma 5291:     $r->print(
1.611     raeburn  5292:        '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   5293:         &Apache::loncommon::start_data_table().
                   5294:         &Apache::loncommon::start_data_table_header_row().
                   5295:         '<th>'.&mt('Resources').'</th>'.
                   5296:         "<th>$lt{'mr'}</th>".
                   5297:         "<th>$lt{'ve'}</th>".
                   5298:         "<th>$lt{'vu'}</th>".
                   5299:         '<th>'.&mt('History').'</th>'.
                   5300:         &Apache::loncommon::end_data_table_header_row()
                   5301:     );
1.571     raeburn  5302:     foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
                   5303:         foreach my $key (sort(@{$changedbytime{$chg}})) {
                   5304:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   5305:             my $currentversion=&Apache::lonnet::getversion($key);
                   5306:             if ($currentversion<0) {
                   5307:                 $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
                   5308:             }
                   5309:             my $linkurl=&Apache::lonnet::clutter($key);
                   5310:             $r->print(
                   5311:                 &Apache::loncommon::start_data_table_row().
                   5312:                 '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
                   5313:                 '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
                   5314:                 '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
                   5315:                 &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
                   5316:                 '<td align="right">'
                   5317:             );
                   5318:             # Used in course
                   5319:             my $usedversion=$hash{'version_'.$linkurl};
                   5320:             if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521     bisitz   5321:                 if ($usedversion != $currentversion) {
1.479     golterma 5322:                     $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521     bisitz   5323:                 } else {
1.479     golterma 5324:                     $r->print($usedversion);
                   5325:                 }
1.329     droeschl 5326:             } else {
1.521     bisitz   5327:                 $r->print($currentversion);
1.329     droeschl 5328:             }
1.571     raeburn  5329:             $r->print('</td><td title="'.$lt{'vu'}.'">');
                   5330:             # Set version
                   5331:             $r->print(&Apache::loncommon::select_form(
                   5332:                       $setversions{$linkurl},
                   5333:                       'set_version_'.$linkurl,
                   5334:                       {'select_form_order' => ['',1..$currentversion,'mostrecent'],
                   5335:                       '' => '',
                   5336:                       'mostrecent' => &mt('most recent'),
1.611     raeburn  5337:                       map {$_,$_} (1..$currentversion)},'',$readonly));
1.571     raeburn  5338:             my $lastold=1;
                   5339:             for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                   5340:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   5341:                 if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
                   5342:                     $lastold=$prevvers;
                   5343:                 }
                   5344:             }
                   5345:             $r->print('</td>');
                   5346:             # List all available versions
                   5347:             $r->print('<td valign="top"><span class="LC_fontsize_medium">');
                   5348:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
                   5349:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   5350:                 $r->print(
                   5351:                     '<span class="LC_nobreak">'
                   5352:                    .'<a href="'.&Apache::lonnet::clutter($url).'">'
                   5353:                    .&mt('Version [_1]',$prevvers).'</a>'
                   5354:                    .' ('.&Apache::lonlocal::locallocaltime(
1.521     bisitz   5355:                          &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571     raeburn  5356:                    .')');
                   5357:                 if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
                   5358:                     $r->print(
                   5359:                         ' <a href="/adm/diff?filename='.
                   5360:                         &Apache::lonnet::clutter($root.'.'.$extension).
                   5361:                         &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
                   5362:                         '" target="diffs">'.&mt('Diffs').'</a>');
                   5363:                 }
                   5364:                 $r->print('</span><br />');
1.329     droeschl 5365:             }
1.571     raeburn  5366:             $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521     bisitz   5367:         }
1.329     droeschl 5368:     }
1.521     bisitz   5369:     $r->print(
                   5370:         &Apache::loncommon::end_data_table().
1.611     raeburn  5371:         '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   5372:         '</form>'
                   5373:     );
1.329     droeschl 5374: 
                   5375:     &untiehash();
1.521     bisitz   5376:     $r->print(&endContentScreen());
1.571     raeburn  5377:     return;
1.329     droeschl 5378: }
                   5379: 
                   5380: sub mark_hash_old {
                   5381:     my $retie_hash=0;
                   5382:     if ($hashtied) {
                   5383: 	$retie_hash=1;
                   5384: 	&untiehash();
                   5385:     }
                   5386:     &tiehash('write');
                   5387:     $hash{'old'}=1;
                   5388:     &untiehash();
                   5389:     if ($retie_hash) { &tiehash(); }
                   5390: }
                   5391: 
                   5392: sub is_hash_old {
                   5393:     my $untie_hash=0;
                   5394:     if (!$hashtied) {
                   5395: 	$untie_hash=1;
                   5396: 	&tiehash();
                   5397:     }
                   5398:     my $return=$hash{'old'};
                   5399:     if ($untie_hash) { &untiehash(); }
                   5400:     return $return;
                   5401: }
                   5402: 
                   5403: sub changewarning {
                   5404:     my ($r,$postexec,$message,$url)=@_;
                   5405:     if (!&is_hash_old()) { return; }
                   5406:     my $pathvar='folderpath';
                   5407:     my $path=&escape($env{'form.folderpath'});
                   5408:     if (!defined($url)) {
                   5409: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
                   5410:     }
                   5411:     my $course_type = &Apache::loncommon::course_type();
                   5412:     if (!defined($message)) {
                   5413: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
                   5414:     }
1.653     raeburn  5415:     my $windowname = 'loncapaclient';
                   5416:     if ($env{'request.lti.login'}) {
                   5417:         $windowname .= 'lti';
                   5418:     }
1.329     droeschl 5419:     $r->print("\n\n".
1.372     bisitz   5420: '<script type="text/javascript">'."\n".
                   5421: '// <![CDATA['."\n".
                   5422: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
                   5423: '// ]]>'."\n".
1.369     bisitz   5424: '</script>'."\n".
1.653     raeburn  5425: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329     droeschl 5426: '<input type="hidden" name="orgurl" value="'.$url.
1.372     bisitz   5427: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329     droeschl 5428: &mt($message,' <input type="hidden" name="'.
                   5429:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369     bisitz   5430:     &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372     bisitz   5431: $help{'Caching'}.'</p></form>'."\n\n");
1.329     droeschl 5432: }
                   5433: 
                   5434: 
                   5435: sub init_breadcrumbs {
1.571     raeburn  5436:     my ($form,$text,$help)=@_;
1.329     droeschl 5437:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484     raeburn  5438:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405     bisitz   5439: 					    text=>&Apache::loncommon::course_type().' Editor',
1.329     droeschl 5440: 					    faq=>273,
                   5441: 					    bug=>'Instructor Interface',
1.571     raeburn  5442:                                             help => $help});
1.329     droeschl 5443:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
                   5444: 					    text=>$text,
                   5445: 					    faq=>273,
                   5446: 					    bug=>'Instructor Interface'});
                   5447: }
                   5448: 
1.441     www      5449: # subroutine to list form elements
                   5450: sub create_list_elements {
                   5451:    my @formarr = @_;
                   5452:    my $list = '';
1.501     raeburn  5453:    foreach my $button (@formarr){
                   5454:         foreach my $picture (keys(%{$button})) {
                   5455:             $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441     www      5456:         }
                   5457:    }
                   5458:    return $list;
                   5459: }
1.329     droeschl 5460: 
1.441     www      5461: # subroutine to create ul from list elements
                   5462: sub create_form_ul {
                   5463:    my $list = shift;
                   5464:    my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
                   5465:    return $ul;
                   5466: }
1.329     droeschl 5467: 
1.442     www      5468: #
                   5469: # Start tabs
                   5470: #
                   5471: 
                   5472: sub startContentScreen {
1.484     raeburn  5473:     my ($mode) = @_;
                   5474:     my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472     raeburn  5475:     if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484     raeburn  5476:         $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";
                   5477:         $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";
                   5478:         $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";
                   5479:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
                   5480:     } else {
1.549     raeburn  5481:         $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  5482:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
                   5483:         $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";
                   5484:                    '><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>';
                   5485:     }
                   5486:     $output .= "\n".'</ul>'."\n";
                   5487:     $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
                   5488:                '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
                   5489:                '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
                   5490:     return $output;
1.442     www      5491: }
                   5492: 
                   5493: #
                   5494: # End tabs
                   5495: #
                   5496: 
                   5497: sub endContentScreen {
1.484     raeburn  5498:     return '</div></div></div>';
1.442     www      5499: }
1.329     droeschl 5500: 
1.446     www      5501: sub supplemental_base {
1.548     raeburn  5502:     return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446     www      5503: }
                   5504: 
1.329     droeschl 5505: sub handler {
                   5506:     my $r = shift;
                   5507:     &Apache::loncommon::content_type($r,'text/html');
                   5508:     $r->send_http_header;
                   5509:     return OK if $r->header_only;
1.484     raeburn  5510: 
                   5511: # get course data
1.408     raeburn  5512:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  5513:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   5514:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   5515: 
1.606     raeburn  5516: # get docroot
                   5517:     my $londocroot = $r->dir_config('lonDocRoot');
                   5518: 
1.484     raeburn  5519: # graphics settings
                   5520:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329     droeschl 5521: 
1.443     www      5522: #
1.329     droeschl 5523: # --------------------------------------------- Initialize help topics for this
                   5524:     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627     raeburn  5525: 	               'Adding_External_Resource','Adding_External_Tool',
                   5526:                        'Navigate_Content','Adding_Folders','Docs_Overview',
                   5527: 	               'Load_Map','Supplemental','Score_Upload_Form',
                   5528: 	               'Adding_Pages','Importing_LON-CAPA_Resource',
                   5529: 	               'Importing_IMS_Course','Uploading_From_Harddrive',
                   5530:                        'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329     droeschl 5531: 	$help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
                   5532:     }
                   5533:     # Composite help files
                   5534:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   5535: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   5536:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   5537: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
                   5538:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   5539: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347     weissno  5540:     $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329     droeschl 5541: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353     weissno  5542:     $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329     droeschl 5543:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534     raeburn  5544:  
1.611     raeburn  5545:     my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682     raeburn  5546: # does this user have privileges to modify content.
                   5547:     if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472     raeburn  5548: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682     raeburn  5549:         unless ($r->uri eq '/adm/supplemental') {
1.611     raeburn  5550:             $allowed = 1;
1.682     raeburn  5551:         }
                   5552:         $canedit = 1;
                   5553:         $canview = 1;
                   5554:     } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
                   5555: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
                   5556:         unless ($r->uri eq '/adm/supplemental') {
1.611     raeburn  5557:             $allowed = 1;
                   5558:         }
1.682     raeburn  5559:         $canview = 1;
1.611     raeburn  5560:     }
                   5561:     unless ($canedit) {
                   5562:         $disabled = ' disabled="disabled"';
1.472     raeburn  5563:     }
1.582     raeburn  5564:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635     raeburn  5565:     if ($env{'form.inhibitmenu'}) {
                   5566:         unless ($env{'form.inhibitmenu'} eq 'yes') {
                   5567:             delete($env{'form.inhibitmenu'});
                   5568:         }
                   5569:     }
                   5570: 
1.582     raeburn  5571:   if ($allowed && $env{'form.verify'}) {
1.571     raeburn  5572:       &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637     raeburn  5573:       if (!$canedit) {
                   5574:           &verifycontent($r);
                   5575:       } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
                   5576:           &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
                   5577:                                                   text=>'Results',
                   5578:                                                   faq=>273,
                   5579:                                                   bug=>'Instructor Interface'});
                   5580:           &verifycontent($r,$env{'form.checkstale'});
                   5581:       } else {
                   5582:           &contentverifyform($r);
                   5583:       }
1.329     droeschl 5584:   } elsif ($allowed && $env{'form.listsymbs'}) {
1.484     raeburn  5585:       &init_breadcrumbs('listsymbs','List Content IDs');
1.329     droeschl 5586:       &list_symbs($r);
1.651     raeburn  5587:   } elsif ($allowed && $env{'form.shorturls'}) {
                   5588:       &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
                   5589:       &short_urls($r,$canedit);
1.329     droeschl 5590:   } elsif ($allowed && $env{'form.docslog'}) {
                   5591:       &init_breadcrumbs('docslog','Show Log');
1.484     raeburn  5592:       my $folder = $env{'form.folder'};
                   5593:       if ($folder eq '') {
                   5594:           $folder='default';
                   5595:       }
1.611     raeburn  5596:       &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329     droeschl 5597:   } elsif ($allowed && $env{'form.versions'}) {
1.571     raeburn  5598:       &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611     raeburn  5599:       &checkversions($r,$canedit);
                   5600:   } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568     raeburn  5601:       &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329     droeschl 5602:       &dumpcourse($r);
1.611     raeburn  5603:   } elsif ($canedit && $env{'form.exportcourse'}) {
1.377     bisitz   5604:       &init_breadcrumbs('exportcourse','IMS Export');
1.475     raeburn  5605:       &Apache::imsexport::exportcourse($r);
1.329     droeschl 5606:   } else {
1.611     raeburn  5607:       if ($canedit && $env{'form.authorrole'}) {
1.606     raeburn  5608:           $noendpage = 1;
                   5609:           my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
                   5610:           if ($redirect) {
                   5611:               if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
                   5612:                   my $container = 'sequence'; 
                   5613:                   my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   5614:                       $is_random_order,$container) =
                   5615:                       &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   5616:                   my (@folders)=split('&',$env{'form.folderpath'});
                   5617:                   $env{'form.foldername'}=&unescape(pop(@folders));
                   5618:                   my $folder=pop(@folders);
                   5619:                   my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   5620:                                                   $folder.'.'.$container);
                   5621:                   my $warning;
                   5622:                   if ($fatal) {
                   5623:                       if ($container eq 'page') {
                   5624:                           $warning = &mt('An error occurred retrieving the contents of the current page.');
                   5625:                       } else {
                   5626:                           $warning = &mt('An error occurred retrieving the contents of the current folder.');
                   5627:                       }
                   5628:                   } else {
                   5629:                       my $url = $redirect;
                   5630:                       my $srcfile = $londocroot.$url;
                   5631:                       $url =~ s{^/priv/}{/res/};
                   5632:                       my $targetfile = $londocroot.$url;
                   5633:                       my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   5634:                       my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
                   5635:                       $env{'form.folder'} = $folder;
                   5636:                       &snapshotbefore();
                   5637:                       my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
                   5638:                       my $ext = 'false';
                   5639:                       my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   5640:                       $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   5641:                                                         ':'.$ext.':normal:res';
                   5642:                       push(@LONCAPA::map::order,$newidx);
                   5643:                       &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
                   5644:                                                    'string_yesno');
                   5645:                       &remember_parms($newidx,'hiddenresource','set','yes');
                   5646:                       ($errtext,$fatal) =
                   5647:                           &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
                   5648:                       &log_differences($plain);
                   5649:                       &mark_hash_old();
                   5650:                       $r->internal_redirect($redirect);
                   5651:                       return OK;
                   5652:                   }
1.654     raeburn  5653:               } else {
                   5654:                   $r->internal_redirect($redirect);
1.606     raeburn  5655:               }
                   5656:           }
                   5657:       }
1.445     www      5658: #
                   5659: # Done catching special calls
1.484     raeburn  5660: # The whole rest is for course and supplemental documents and utilities menu
1.445     www      5661: # Get the parameters that may be needed
                   5662: #
                   5663:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682     raeburn  5664:                                             ['folderpath','title',
1.519     raeburn  5665:                                              'forcesupplement','forcestandard',
1.510     raeburn  5666:                                              'tools','symb','command','supppath']);
1.445     www      5667: 
1.635     raeburn  5668:     foreach my $item ('forcesupplement','forcestandard','tools') {
                   5669:         next if ($env{'form.'.$item} eq '');
                   5670:         unless ($env{'form.'.$item} eq '1') {
                   5671:             delete($env{'form.'.$item});
                   5672:         }
                   5673:     }
                   5674: 
                   5675:     if ($env{'form.command'}) {
                   5676:         unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
                   5677:             delete($env{'form.command'});
                   5678:         }
                   5679:     }
                   5680: 
                   5681:     if ($env{'form.symb'}) {
                   5682:         my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   5683:         unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { 
                   5684:             delete($env{'form.symb'});
                   5685:         }
                   5686:     }
                   5687: 
1.445     www      5688: # standard=1: this is a "new-style" course with an uploaded map as top level
                   5689: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329     droeschl 5690: 
                   5691:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445     www      5692: 
1.484     raeburn  5693: # Decide whether this should display supplemental or main content or utilities
1.445     www      5694: # supplementalflag=1: show supplemental documents
                   5695: # supplementalflag=0: show standard documents
1.484     raeburn  5696: # toolsflag=1: show utilities
1.445     www      5697: 
1.561     raeburn  5698:     my $unesc_folderpath = &unescape($env{'form.folderpath'});
                   5699:     my $supplementalflag=($unesc_folderpath=~/^supplemental/);
                   5700:     if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445     www      5701:        $supplementalflag=0;
                   5702:     }
                   5703:     if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
                   5704:     if ($env{'form.forcestandard'})   { $supplementalflag=0; }
                   5705:     unless ($allowed) { $supplementalflag=1; }
                   5706:     unless ($standard) { $supplementalflag=1; }
1.484     raeburn  5707:     my $toolsflag=0;
                   5708:     if ($env{'form.tools'}) { $toolsflag=1; }
1.445     www      5709: 
1.635     raeburn  5710:     if ($env{'form.folderpath'} ne '') {
1.685     raeburn  5711:         &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635     raeburn  5712:     }
                   5713: 
1.685     raeburn  5714:     my $backto_supppath;
1.635     raeburn  5715:     if ($env{'form.supppath'} ne '') {
1.685     raeburn  5716:         if ($supplementalflag && $allowed) {
                   5717:             $backto_supppath = &validate_supppath($coursenum,$coursedom);
                   5718:         }
1.635     raeburn  5719:     }
                   5720: 
1.329     droeschl 5721:     my $script='';
                   5722:     my $showdoc=0;
1.457     raeburn  5723:     my $addentries = {};
1.475     raeburn  5724:     my $container;
1.329     droeschl 5725:     my $containertag;
1.508     raeburn  5726:     my $pathitem;
1.598     raeburn  5727:     my %ltitools;
1.617     raeburn  5728:     my $hiddentop;
1.615     raeburn  5729:     my $navmap;
1.617     raeburn  5730:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329     droeschl 5731: 
1.464     www      5732: # Do we directly jump somewhere?
1.525     raeburn  5733:    if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472     raeburn  5734:        if ($env{'form.symb'} ne '') {
1.522     raeburn  5735:            $env{'form.folderpath'}=
1.617     raeburn  5736:                &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530     raeburn  5737:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525     raeburn  5738:                $env{'form.command'}.'_'.$env{'form.symb'}});
1.685     raeburn  5739:        } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472     raeburn  5740:            $env{'form.folderpath'}=$env{'form.supppath'};
1.530     raeburn  5741:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685     raeburn  5742:                $env{'form.command'}.'_'.$backto_supppath});
1.466     www      5743:        }
1.472     raeburn  5744:    } elsif ($env{'form.command'} eq 'editdocs') {
1.617     raeburn  5745:        $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525     raeburn  5746:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472     raeburn  5747:    } elsif ($env{'form.command'} eq 'editsupp') {
1.617     raeburn  5748:        $env{'form.folderpath'} = &supplemental_base();
1.525     raeburn  5749:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
                   5750:    } elsif ($env{'form.command'} eq 'contents') {
                   5751:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
                   5752:    } elsif ($env{'form.command'} eq 'home') {
                   5753:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464     www      5754:    }
                   5755: 
1.525     raeburn  5756: 
1.445     www      5757: # Where do we store these for when we come back?
                   5758:     my $stored_folderpath='docs_folderpath';
                   5759:     if ($supplementalflag) {
                   5760:        $stored_folderpath='docs_sup_folderpath';
                   5761:     }
1.464     www      5762: 
1.519     raeburn  5763: # No folderpath, and in edit mode, see if we have something stored
                   5764:     if ((!$env{'form.folderpath'}) && $allowed) {
1.445     www      5765:         &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510     raeburn  5766:                                           {'folderpath' => 'scalar'});
1.615     raeburn  5767: 
                   5768:         if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
                   5769:             if ($supplementalflag) {
                   5770:                 undef($env{'form.folderpath'}) if ($1 eq 'default'); 
                   5771:             } else {
                   5772:                 undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
                   5773:             }
                   5774:         } else {
1.523     raeburn  5775:             undef($env{'form.folderpath'});
                   5776:         }
1.677     raeburn  5777:         if ($env{'form.folderpath'} ne '') {
1.685     raeburn  5778:             &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677     raeburn  5779:         }
1.329     droeschl 5780:     }
1.446     www      5781:    
                   5782: # If we are not allowed to make changes, all we can see are supplemental docs
1.409     raeburn  5783:     if (!$allowed) {
1.446     www      5784:         unless ($env{'form.folderpath'} =~ /^supplemental/) {
                   5785:             $env{'form.folderpath'} = &supplemental_base();
1.409     raeburn  5786:         }
                   5787:     }
1.446     www      5788: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329     droeschl 5789:     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446     www      5790:         $env{'form.folderpath'} = &supplemental_base()
                   5791:                                   .'&'.
1.329     droeschl 5792:                                   $env{'form.folderpath'};
                   5793:     }
1.685     raeburn  5794: # If allowed and user's role is not advanced check folderpath is not hidden
                   5795:     my $hidden_and_empty;
1.687     raeburn  5796:     if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685     raeburn  5797:         my ($folderurl,$foldername,$hiddenfolder);
1.615     raeburn  5798:         my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617     raeburn  5799:         my $folder = $pathitems[-2];
                   5800:         if ($folder eq '') {
                   5801:             undef($env{'form.folderpath'});
                   5802:         } else {
                   5803:             $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666     raeburn  5804:             if ((split(/\:/,$pathitems[-1]))[5]) {
1.615     raeburn  5805:                 $folderurl .= '.page';
                   5806:             } else {
                   5807:                 $folderurl .= '.sequence';
                   5808:             }
1.685     raeburn  5809:             if ($supplementalflag) {
                   5810:                 ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
                   5811:                 $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688     raeburn  5812:                 my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn  5813:                 if (ref($supplemental) eq 'HASH') {
                   5814:                     my ($suppmap,$suppmapnum);
                   5815:                     if ($folder eq 'supplemental') {
                   5816:                         $suppmap = 'default';
                   5817:                         $suppmapnum = 0;
                   5818:                     } elsif ($folder =~ /^supplemental_(\d+)$/) {
                   5819:                         $suppmap = $1;
                   5820:                         $suppmapnum = $suppmap;
                   5821:                     }
                   5822:                     if ($hiddenfolder) {
                   5823:                         my $hascontent;
                   5824:                         foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
                   5825:                             if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
                   5826:                                 $hascontent = 1;
                   5827:                             } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
                   5828:                                 foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
                   5829:                                     if ($id =~ /^$suppmapnum\:/) {
                   5830:                                         $hascontent = 1;
                   5831:                                         last;
                   5832:                                     }
                   5833:                                 }
                   5834:                             }
                   5835:                             last if ($hascontent);
                   5836:                         }
                   5837:                         unless ($hascontent) {
                   5838:                             if ($foldername ne '') {
                   5839:                                 $hidden_and_empty = $foldername;
                   5840:                             } else {
                   5841:                                 $hidden_and_empty = $folder;
                   5842:                             }
                   5843:                         }
                   5844:                     }
                   5845:                 }
                   5846:             } else {
                   5847:                 unless (ref($navmap)) {
                   5848:                     $navmap = Apache::lonnavmaps::navmap->new();
                   5849:                 }
                   5850:                 ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
                   5851:                 $foldername = &HTML::Entities::decode(&unescape($foldername));
                   5852:                 if (ref($navmap)) {
                   5853:                     if ($hiddenfolder ||
                   5854:                         (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
                   5855:                         my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
                   5856:                         unless (@resources) {
                   5857:                             if ($foldername ne '') {
                   5858:                                 $hidden_and_empty = $foldername;
                   5859:                             } else {
                   5860:                                 $hidden_and_empty = $folder;
                   5861:                             }
                   5862:                         }
                   5863:                     }
                   5864:                 }
1.617     raeburn  5865:             }
1.685     raeburn  5866:             if ($hidden_and_empty ne '') {
                   5867:                 splice(@pathitems,-2);
                   5868:                 if (@pathitems) {
                   5869:                     $env{'form.folderpath'} = join('&',@pathitems);
                   5870:                 } else {
                   5871:                     undef($env{'form.folderpath'});
1.615     raeburn  5872:                 }
                   5873:             }
                   5874:         }
                   5875:     }
                   5876: 
1.446     www      5877: # If after all of this, we still don't have any paths, make them
1.519     raeburn  5878:     unless ($env{'form.folderpath'}) {
1.446     www      5879:        if ($supplementalflag) {
                   5880:           $env{'form.folderpath'}=&supplemental_base();
1.617     raeburn  5881:        } elsif ($allowed) {
                   5882:           ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446     www      5883:        }
1.472     raeburn  5884:     }
1.446     www      5885: 
1.445     www      5886: # Store this
1.484     raeburn  5887:     unless ($toolsflag) {
1.615     raeburn  5888:         if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510     raeburn  5889:             &Apache::loncommon::store_course_settings($stored_folderpath,
1.519     raeburn  5890:                                                       {'folderpath' => 'scalar'});
1.510     raeburn  5891:         }
1.519     raeburn  5892:         my $folderpath;
1.484     raeburn  5893:         if ($env{'form.folderpath'}) {
1.519     raeburn  5894:             $folderpath = $env{'form.folderpath'};
                   5895: 	    my (@folders)=split('&',$env{'form.folderpath'});
                   5896: 	    $env{'form.foldername'}=&unescape(pop(@folders));
                   5897:             if ($env{'form.foldername'} =~ /\:1$/) {
                   5898:                 $container = 'page';
                   5899:             } else {
                   5900:                 $container = 'sequence';
                   5901:             }
                   5902: 	    $env{'form.folder'}=pop(@folders);
1.484     raeburn  5903:         } else {
1.519     raeburn  5904:             if ($env{'form.folder'} eq '' ||
                   5905:                 $env{'form.folder'} eq 'supplemental') {
1.617     raeburn  5906:                 if ($env{'form.folder'} eq 'supplemental') {
                   5907:                     $folderpath=&supplemental_base();
                   5908:                 } elsif (!$hiddentop) {
                   5909:                     $folderpath='default&'.
                   5910:                                  &escape(&mt('Main Content').':::::');
                   5911:                 }
1.484     raeburn  5912:             }
                   5913:         }
1.519     raeburn  5914:         $containertag = '<input type="hidden" name="folderpath" value="" />';
                   5915:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484     raeburn  5916:         if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
                   5917:            $showdoc='/'.$1;
                   5918:         }
                   5919:         if ($showdoc) { # got called in sequence from course
                   5920: 	    $allowed=0; 
                   5921:         } else {
1.611     raeburn  5922:             if ($canedit) {
1.484     raeburn  5923:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   5924:                 $script=&Apache::lonratedt::editscript('simple');
1.433     raeburn  5925:             }
                   5926:         }
1.329     droeschl 5927:     }
                   5928: 
1.344     bisitz   5929: # get personal data
1.329     droeschl 5930:     my $uname=$env{'user.name'};
                   5931:     my $udom=$env{'user.domain'};
                   5932:     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
                   5933: 
                   5934:     if ($allowed) {
1.484     raeburn  5935:         if ($toolsflag) {
                   5936:             $script .= &inject_data_js();
                   5937:             my ($home,$other,%outhash)=&authorhosts();
                   5938:             if (!$home && $other) {
                   5939:                 my @hosts;
                   5940:                 foreach my $aurole (keys(%outhash)) {
                   5941:                     unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   5942:                         push(@hosts,$outhash{$aurole});
                   5943:                     }
                   5944:                 }
                   5945:                 $script .= &dump_switchserver_js(@hosts); 
                   5946:             }
1.458     raeburn  5947:         } else {
1.570     raeburn  5948:             my $tid = 1;
1.484     raeburn  5949:             my @tabids;
                   5950:             if ($supplementalflag) {
1.655     raeburn  5951:                 @tabids = ('002','dd2','ee2','ff2');
1.570     raeburn  5952:                 $tid = 2;
1.484     raeburn  5953:             } else {
                   5954:                 @tabids = ('aa1','bb1','cc1','ff1');
1.519     raeburn  5955:                 unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484     raeburn  5956:                     unshift(@tabids,'001');
                   5957:                     push(@tabids,('dd1','ee1'));
                   5958:                 }
1.458     raeburn  5959:             }
1.484     raeburn  5960:             my $tabidstr = join("','",@tabids);
1.644     raeburn  5961:             %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600     raeburn  5962:             my $posslti = keys(%ltitools);
1.622     raeburn  5963:             my $hostname = $r->hostname();
1.606     raeburn  5964: 	    $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622     raeburn  5965:                                    $londocroot,$canedit,$hostname,\$navmap).
1.484     raeburn  5966:                        &history_tab_js().
                   5967:                        &inject_data_js().
1.570     raeburn  5968:                        &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598     raeburn  5969:                        &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685     raeburn  5970:             my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
                   5971:             if ($hidden_and_empty ne '') {
                   5972:                 my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
                   5973:                                 $hidden_and_empty);
                   5974:                 $onload .= "javascript:alert('".&js_escape($alert)."');";
                   5975:             }
1.484     raeburn  5976:             $addentries = {
1.685     raeburn  5977:                             onload => $onload,
1.484     raeburn  5978:                           };
1.458     raeburn  5979:         }
1.538     raeburn  5980:         $script .= &paste_popup_js(); 
1.501     raeburn  5981:         my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
                   5982:                              &mt('Switch server?');
                   5983:         
                   5984: 
1.329     droeschl 5985:     }
                   5986: # -------------------------------------------------------------------- Body tag
1.369     bisitz   5987:     $script = '<script type="text/javascript">'."\n"
1.372     bisitz   5988:               .'// <![CDATA['."\n"
                   5989:               .$script."\n"
                   5990:               .'// ]]>'."\n"
1.595     musolffc 5991:               .'</script>'."\n"
                   5992:               .'<script type="text/javascript" 
                   5993:                 src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385     bisitz   5994: 
                   5995:     # Breadcrumbs
                   5996:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510     raeburn  5997: 
                   5998:     if ($showdoc) {
1.682     raeburn  5999:         my $args;
                   6000:         if ($supplementalflag) {
1.687     raeburn  6001:             my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
                   6002:             my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.682     raeburn  6003:             $args = {'bread_crumbs' => $brcrum};
                   6004:         } else {
                   6005:             $args = {'force_register' => $showdoc};
                   6006:         }
                   6007:         $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571     raeburn  6008:     } elsif ($toolsflag) {
1.611     raeburn  6009:         my ($breadtext,$breadtitle);
1.617     raeburn  6010:         $breadtext = "$crstype Editor";
1.611     raeburn  6011:         if ($canedit) {
                   6012:             $breadtitle = 'Editing '.$crstype.' Contents';
                   6013:         } else {
                   6014:             $breadtext .= ' (View-only mode)';
                   6015:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   6016:         }
1.571     raeburn  6017:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  6018:             href=>"/adm/coursedocs",text=>$breadtext});
1.571     raeburn  6019:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
                   6020:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   6021:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  6022:                      $breadtitle)
1.571     raeburn  6023:                  );
1.510     raeburn  6024:     } elsif ($r->uri eq '/adm/supplemental') {
1.682     raeburn  6025:         unless ($env{'request.role.adv'}) {
                   6026:             unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
                   6027:                 $r->internal_redirect('/adm/navmaps');
                   6028:                 return OK;
                   6029:             }
                   6030:         }
1.510     raeburn  6031:         my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
                   6032:         $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
                   6033:                                                 {'bread_crumbs' => $brcrum,}));
                   6034:     } else {
1.611     raeburn  6035:         my ($breadtext,$breadtitle,$helpitem);
1.617     raeburn  6036:         $breadtext = "$crstype Editor";
1.611     raeburn  6037:         if ($canedit) {
                   6038:             $breadtitle = 'Editing '.$crstype.' Contents';
                   6039:             $helpitem = 'Docs_Adding_Course_Doc';
                   6040:         } else {
                   6041:             $breadtext .= ' (View-only mode)';
                   6042:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   6043:             $helpitem = 'Docs_Viewing_Course_Doc';
                   6044:         }
1.392     raeburn  6045:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  6046:             href=>"/adm/coursedocs",text=>$breadtext});
1.446     www      6047:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510     raeburn  6048:                                                  {'add_entries'    => $addentries}
                   6049:                                                 )
1.392     raeburn  6050:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   6051:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  6052:                      $breadtitle,
                   6053:                      $helpitem)
1.392     raeburn  6054:         );
                   6055:     }
1.364     bisitz   6056: 
1.329     droeschl 6057:   my %allfiles = ();
                   6058:   my %codebase = ();
1.440     raeburn  6059:   my ($upload_result,$upload_output,$uploadphase);
1.611     raeburn  6060:   if ($canedit) {
1.684     raeburn  6061:       undef($suppchanges);
1.329     droeschl 6062:       if (($env{'form.uploaddoc.filename'}) &&
                   6063: 	  ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440     raeburn  6064:           my $context = $1; 
                   6065:           # Process file upload - phase one - upload and parse primary file.
1.329     droeschl 6066: 	  undef($hadchanges);
1.440     raeburn  6067:           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552     raeburn  6068:                                               \%allfiles,\%codebase,$context,$crstype);
1.638     raeburn  6069:           undef($navmap);
1.329     droeschl 6070: 	  if ($hadchanges) {
                   6071: 	      &mark_hash_old();
                   6072: 	  }
1.684     raeburn  6073:           if ($suppchanges) {
                   6074:               &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
                   6075:               undef($suppchanges);
                   6076:           }
1.440     raeburn  6077:           $r->print($upload_output);
                   6078:       } elsif ($env{'form.phase'} eq 'upload_embedded') {
                   6079:           # Process file upload - phase two - upload embedded objects 
                   6080:           $uploadphase = 'check_embedded';
                   6081:           my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');   
                   6082:           my $state = &embedded_form_elems($uploadphase,$primaryurl,
                   6083:                                            $env{'form.newidx'});
                   6084:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   6085:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   6086:           my ($destination,$dir_root) = &embedded_destination();
                   6087:           my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
                   6088:           my $actionurl = '/adm/coursedocs';
1.630     raeburn  6089:           my ($result,$flag) =
1.440     raeburn  6090:               &Apache::loncommon::upload_embedded('coursedoc',$destination,
                   6091:                   $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
                   6092:                   $actionurl);
                   6093:           $r->print($result.&return_to_editor());
                   6094:       } elsif ($env{'form.phase'} eq 'check_embedded') {
                   6095:           # Process file upload - phase three - modify references in HTML file
                   6096:           $uploadphase = 'modified_orightml';
                   6097:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   6098:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   6099:           my ($destination,$dir_root) = &embedded_destination();
1.630     raeburn  6100:           my $result =
1.482     raeburn  6101:               &Apache::loncommon::modify_html_refs('coursedoc',$destination,
                   6102:                                                    $docuname,$docudom,undef,
                   6103:                                                    $dir_root);
1.630     raeburn  6104:           $r->print($result.&return_to_editor());
1.476     raeburn  6105:       } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
                   6106:           $uploadphase = 'decompress_phase_one';
                   6107:           $r->print(&decompression_phase_one().
                   6108:                     &return_to_editor());
                   6109:       } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
                   6110:           $uploadphase = 'decompress_phase_two';
                   6111:           $r->print(&decompression_phase_two().
                   6112:                     &return_to_editor());
1.329     droeschl 6113:       }
                   6114:   }
                   6115: 
1.484     raeburn  6116:   if ($allowed && $toolsflag) {
                   6117:       $r->print(&startContentScreen('tools'));
1.611     raeburn  6118:       $r->print(&generate_admin_menu($crstype,$canedit));
1.484     raeburn  6119:       $r->print(&endContentScreen());
                   6120:   } elsif ((!$showdoc) && (!$uploadphase)) {
1.329     droeschl 6121: # -----------------------------------------------------------------------------
                   6122:        my %lt=&Apache::lonlocal::texthash(
                   6123: 		'copm' => 'All documents out of a published map into this folder',
1.501     raeburn  6124:                 'upfi' => 'Upload File',
1.553     raeburn  6125:                 'upld' => 'Upload Content',
1.329     droeschl 6126:                 'srch' => 'Search',
                   6127:                 'impo' => 'Import',
1.487     raeburn  6128: 		'lnks' => 'Import from Stored Links',
1.502     raeburn  6129:                 'impm' => 'Import from Assembled Map',
1.630     raeburn  6130:                 'imcr' => 'Import from Course Resources',
1.598     raeburn  6131:                 'extr' => 'External Resource',
                   6132:                 'extt' => 'External Tool',
1.329     droeschl 6133:                 'selm' => 'Select Map',
                   6134:                 'load' => 'Load Map',
                   6135:                 'newf' => 'New Folder',
                   6136:                 'newp' => 'New Composite Page',
                   6137:                 'syll' => 'Syllabus',
1.425     raeburn  6138:                 'navc' => 'Table of Contents',
1.343     biermanm 6139:                 'sipa' => 'Simple Course Page',
1.329     droeschl 6140:                 'sipr' => 'Simple Problem',
1.630     raeburn  6141:                 'webp' => 'Blank Web Page (editable)',
1.606     raeburn  6142:                 'stpr' => 'Standard Problem',
                   6143:                 'news' => 'New sub-directory',
                   6144:                 'crpr' => 'Create Problem',
1.689     raeburn  6145:                 'swit' => 'Switch Server',
1.329     droeschl 6146:                 'drbx' => 'Drop Box',
1.451     www      6147:                 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336     schafran 6148:                 'bull' => 'Discussion Board',
1.347     weissno  6149:                 'mypi' => 'My Personal Information Page',
1.353     weissno  6150:                 'grpo' => 'Group Portfolio',
1.329     droeschl 6151:                 'rost' => 'Course Roster',
1.528     raeburn  6152:                 'abou' => 'Personal Information Page for a User',
1.553     raeburn  6153:                 'imsf' => 'IMS Upload',
                   6154:                 'imsl' => 'Upload IMS package',
1.501     raeburn  6155:                 'cms'  => 'Origin of IMS package',
                   6156:                 'se'   => 'Select',
1.329     droeschl 6157:                 'file' =>  'File',
                   6158:                 'title' => 'Title',
1.606     raeburn  6159:                 'addp' => 'Add Placeholder to course?',
                   6160:                 'uste' => 'Use Template?',
                   6161:                 'fnam' => 'File Name:',
                   6162:                 'loca' => 'Location:',
                   6163:                 'dire' => 'Directory:',
                   6164:                 'cate' => 'Category:',
                   6165:                 'tmpl' => 'Template:',
1.329     droeschl 6166:                 'comment' => 'Comment',
1.403     raeburn  6167:                 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577     bisitz   6168:                 'bb5'      => 'Blackboard 5',
                   6169:                 'bb6'      => 'Blackboard 6',
                   6170:                 'angel5'   => 'ANGEL 5.5',
                   6171:                 'webctce4' => 'WebCT 4 Campus Edition',
1.606     raeburn  6172:                 'yes'      => 'Yes',
                   6173:                 'no'       => 'No',
1.618     raeburn  6174:                 'er' => 'Editing rights unavailable for your current role.',
1.577     bisitz   6175:         );
1.329     droeschl 6176: # -----------------------------------------------------------------------------
1.595     musolffc 6177: 
                   6178:     # Calculate free quota space for a user or course. A javascript function checks
                   6179:     # file size to determine if upload should be allowed.
                   6180:     my $quotatype = 'unofficial';
                   6181:     if ($crstype eq 'Community') {
1.601     raeburn  6182:         $quotatype = 'community';
                   6183:     } elsif ($crstype eq 'Placement') {
                   6184:         $quotatype = 'placement';
1.595     musolffc 6185:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
                   6186:         $quotatype = 'official';
                   6187:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   6188:         $quotatype = 'textbook';
                   6189:     }
                   6190:     my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
                   6191:                      'course',$quotatype); # expressed in MB
                   6192:     my $current_disk_usage = 0;
                   6193:     foreach my $subdir ('docs','supplemental') {
                   6194:         $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
                   6195:                                "userfiles/$subdir",1); # expressed in kB
                   6196:     }
                   6197:     my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605     raeburn  6198:     my $usage = $current_disk_usage/1024; # in MB
                   6199:     my $quota = $disk_quota;
                   6200:     my $percent;
                   6201:     if ($disk_quota == 0) {
                   6202:         $percent = 100.0;
                   6203:     } else {
1.619     raeburn  6204:         $percent = 100*($usage/$disk_quota);
1.605     raeburn  6205:     }
                   6206:     $usage = sprintf("%.2f",$usage);
                   6207:     $quota = sprintf("%.2f",$quota);
                   6208:     $percent = sprintf("%.0f",$percent);
                   6209:     my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
                   6210:                               $percent.'%',$quota.' MB').'</p>';
1.595     musolffc 6211: 
1.329     droeschl 6212: 	my $fileupload=(<<FIUP);
1.605     raeburn  6213:         $quotainfo
1.329     droeschl 6214: 	$lt{'file'}:<br />
1.662     raeburn  6215: 	<input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663     raeburn  6216:         <input type="hidden" id="LC_free_space" value="$free_space" />
1.329     droeschl 6217: FIUP
                   6218: 
                   6219: 	my $checkbox=(<<CHBO);
                   6220: 	<!-- <label>$lt{'parse'}?
                   6221: 	<input type="checkbox" name="parserflag" />
                   6222: 	</label> -->
                   6223: 	<label>
1.611     raeburn  6224: 	<input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329     droeschl 6225: 	</label>
                   6226: CHBO
1.501     raeburn  6227:         my $imsfolder = $env{'form.folder'};
                   6228:         if ($imsfolder eq '') {
                   6229:             $imsfolder = 'default';  
                   6230:         }
                   6231:         my $imspform=(<<IMSFORM);
                   6232:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
                   6233:         $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
                   6234:         <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516     raeburn  6235:         <fieldset id="uploadimsform" style="display: none;">
1.501     raeburn  6236:         <legend>$lt{'imsf'}</legend>
                   6237:         $fileupload
                   6238:         <br />
                   6239:         <p>
                   6240:         $lt{'cms'}:&nbsp; 
1.611     raeburn  6241:         <select name="source" $disabled>
1.501     raeburn  6242:         <option value="-1" selected="selected">$lt{'se'}</option>
1.577     bisitz   6243:         <option value="bb5">$lt{'bb5'}</option>
                   6244:         <option value="bb6">$lt{'bb6'}</option>
                   6245:         <option value="angel5">$lt{'angel5'}</option>
                   6246:         <option value="webctce4">$lt{'webctce4'}</option>
1.501     raeburn  6247:         </select>
                   6248:         <input type="hidden" name="folder" value="$imsfolder" />
                   6249:         </p>
                   6250:         <input type="hidden" name="phase" value="one" />
1.611     raeburn  6251:         <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501     raeburn  6252:         </fieldset>
                   6253:         </form>
                   6254: IMSFORM
1.329     droeschl 6255: 
                   6256: 	my $fileuploadform=(<<FUFORM);
1.501     raeburn  6257:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
                   6258:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
                   6259:         <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516     raeburn  6260:         <fieldset id="uploaddocform" style="display: none;">
1.501     raeburn  6261:         <legend>$lt{'upfi'}</legend>
1.371     tempelho 6262: 	<input type="hidden" name="active" value="aa" />
1.595     musolffc 6263:     $fileupload
1.329     droeschl 6264: 	<br />
                   6265: 	$lt{'title'}:<br />
1.611     raeburn  6266: 	<input type="text" size="60" name="comment" $disabled />
1.508     raeburn  6267: 	$pathitem
1.329     droeschl 6268: 	<input type="hidden" name="cmd" value="upload_default" />
                   6269: 	<br />
1.458     raeburn  6270: 	<span class="LC_nobreak" style="float:left">
1.329     droeschl 6271: 	$checkbox
                   6272: 	</span>
1.501     raeburn  6273:         <br clear="all" />
1.611     raeburn  6274:         <input type="submit" value="$lt{'upld'}" $disabled />
1.501     raeburn  6275:         </fieldset>
                   6276:         </form>
1.383     tempelho 6277: FUFORM
1.329     droeschl 6278: 
1.611     raeburn  6279:         my $mapimportjs;
                   6280:         if ($canedit) {
                   6281:             $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');"; 
                   6282:         } else {
                   6283:             $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
                   6284:         }
1.502     raeburn  6285: 	my $importpubform=(<<SEDFFORM);
1.514     raeburn  6286:         <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502     raeburn  6287:         $lt{'impm'}</a>$help{'Load_Map'}
                   6288: 	<form action="/adm/coursedocs" method="post" name="mapimportform">
1.516     raeburn  6289:         <fieldset id="importmapform" style="display: none;">
1.502     raeburn  6290:         <legend>$lt{'impm'}</legend>
1.371     tempelho 6291: 	<input type="hidden" name="active" value="bb" />
1.502     raeburn  6292:         $lt{'copm'}<br />
                   6293:         <span class="LC_nobreak">
                   6294:         <input type="text" name="importmap" size="40" value="" 
1.611     raeburn  6295:         onfocus="this.blur();$mapimportjs" $disabled />
                   6296:         &nbsp;<a href="$mapimportjs">$lt{'selm'}</a></span><br />
                   6297:         <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502     raeburn  6298:         </fieldset>
                   6299:         </form>
                   6300: 
1.383     tempelho 6301: SEDFFORM
1.606     raeburn  6302:         my $importcrsresform;
1.608     raeburn  6303:         my ($numdirs,$pickfile) = 
1.690     raeburn  6304:             &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
1.608     raeburn  6305:                                                       "resize_scrollbox('contentscroll','1','0');",
                   6306:                                                       undef,'res');
1.606     raeburn  6307:         if ($pickfile) {
                   6308:             $importcrsresform=(<<CRSFORM);
1.690     raeburn  6309:         <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606     raeburn  6310:         $lt{'imcr'}</a>$help{'Course_Resources'}
                   6311:         <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
                   6312:         <fieldset id="importcrsresform" style="display: none;">
                   6313:         <legend>$lt{'imcr'}</legend>
                   6314:         <input type="hidden" name="active" value="bb" />
                   6315:         $pickfile
                   6316:         <p>
1.611     raeburn  6317:         $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606     raeburn  6318:         </p>
                   6319:         <input type="hidden" name="importdetail" value="" />
1.690     raeburn  6320:         <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.606     raeburn  6321:         </fieldset>
                   6322:         </form>
                   6323: CRSFORM
                   6324:         }
                   6325: 
1.611     raeburn  6326:         my $fromstoredjs;
                   6327:         if ($canedit) {
                   6328:             $fromstoredjs = 'open_StoredLinks_Import()'; 
                   6329:         } else {
                   6330:             $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
                   6331:         }
                   6332: 
1.502     raeburn  6333: 	my @importpubforma = (
1.508     raeburn  6334: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'"  onclick="javascript:groupsearch()" />' => $pathitem."<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>" },
1.423     onken    6335: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'"  onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
1.611     raeburn  6336: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:'.$fromstoredjs.';" />' => '<a class="LC_menubuttons_link" href="javascript:'.$fromstoredjs.';">'.$lt{'lnks'}.'</a>' },
1.606     raeburn  6337:         { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
                   6338:         );
                   6339:         if ($pickfile) {
1.690     raeburn  6340:             push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'"  onclick="javascript:toggleImportCrsres(\'res\');" />' => $importcrsresform});
1.606     raeburn  6341: 	}
1.502     raeburn  6342: 	$importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510     raeburn  6343:         my $extresourcesform =
                   6344:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611     raeburn  6345:                                                  $help{'Adding_External_Resource'},
                   6346:                                                  undef,undef,undef,undef,undef,undef,$disabled);
1.598     raeburn  6347:         my $exttoolform =
                   6348:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
                   6349:                                                  $help{'Adding_External_Tool'},undef,
                   6350:                                                  undef,'tool',$coursedom,$coursenum,
1.611     raeburn  6351:                                                  \%ltitools,$disabled);
1.329     droeschl 6352:     if ($allowed) {
1.492     raeburn  6353:         my $folder = $env{'form.folder'};
                   6354:         if ($folder eq '') {
                   6355:             $folder='default';
                   6356:         }
1.615     raeburn  6357:         if ($canedit) {
                   6358: 	    my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
                   6359:             if ($output) {
                   6360:                 $r->print($output);
                   6361:             }
1.538     raeburn  6362:         }
1.337     ehlerst  6363: 	$r->print(<<HIDDENFORM);
                   6364: 	<form name="renameform" method="post" action="/adm/coursedocs">
                   6365:    <input type="hidden" name="title" />
                   6366:    <input type="hidden" name="cmd" />
                   6367:    <input type="hidden" name="markcopy" />
                   6368:    <input type="hidden" name="copyfolder" />
                   6369:    $containertag
                   6370:  </form>
1.633     raeburn  6371:  <form name="aliasform" method="post" action="/adm/coursedocs">
                   6372:    <input type="hidden" name="alias" />
                   6373:    <input type="hidden" name="cmd" />
                   6374:    $containertag
                   6375:  </form>
1.484     raeburn  6376: 
1.337     ehlerst  6377: HIDDENFORM
1.508     raeburn  6378:         $r->print(&makesimpleeditform($pathitem)."\n".
                   6379:                   &makedocslogform($pathitem."\n".
1.484     raeburn  6380:                                    '<input type="hidden" name="folder" value="'.
                   6381:                                    $env{'form.folder'}.'" />'."\n"));
1.329     droeschl 6382:     }
1.442     www      6383: 
                   6384: # Generate the tabs
1.510     raeburn  6385:     my ($mode,$needs_end);
1.472     raeburn  6386:     if (($supplementalflag) && (!$allowed)) {
1.510     raeburn  6387:         my @folders = split('&',$env{'form.folderpath'});
                   6388:         unless (@folders > 2) {
                   6389:             &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
                   6390:             $needs_end = 1;
                   6391:         }
1.472     raeburn  6392:     } else {
1.484     raeburn  6393:         $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510     raeburn  6394:         $needs_end = 1;
1.472     raeburn  6395:     }
1.443     www      6396: 
1.442     www      6397: #
1.622     raeburn  6398:     my $hostname = $r->hostname();
1.442     www      6399:     my $savefolderpath;
                   6400: 
1.395     raeburn  6401:     if ($allowed) {
1.329     droeschl 6402:        my $folder=$env{'form.folder'};
1.615     raeburn  6403:        if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329     droeschl 6404:            $folder='default';
1.356     tempelho 6405: 	   $savefolderpath = $env{'form.folderpath'};
1.548     raeburn  6406: 	   $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508     raeburn  6407:            $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329     droeschl 6408: 	       &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
                   6409:        }
                   6410:        my $postexec='';
                   6411:        if ($folder eq 'default') {
1.653     raeburn  6412:            my $windowname = 'loncapaclient';
                   6413:            if ($env{'request.lti.login'}) {
                   6414:                $windowname .= 'lti';
                   6415:            }
1.372     bisitz   6416:            $r->print('<script type="text/javascript">'."\n"
                   6417:                     .'// <![CDATA['."\n"
1.653     raeburn  6418:                     .'this.window.name="'.$windowname.'";'."\n"
1.372     bisitz   6419:                     .'// ]]>'."\n"
                   6420:                     .'</script>'."\n"
1.369     bisitz   6421:        );
1.329     droeschl 6422:        } else {
                   6423:            #$postexec='self.close();';
                   6424:        }
1.504     raeburn  6425:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
                   6426:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329     droeschl 6427: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
                   6428: 
                   6429: 	my $newnavform=(<<NNFORM);
                   6430: 	<form action="/adm/coursedocs" method="post" name="newnav">
1.655     raeburn  6431: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6432: 	$pathitem
1.329     droeschl 6433: 	<input type="hidden" name="importdetail" 
                   6434: 	value="$lt{'navc'}=/adm/navmaps" />
1.611     raeburn  6435: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329     droeschl 6436: 	$help{'Navigate_Content'}
                   6437: 	</form>
                   6438: NNFORM
                   6439: 	my $newsmppageform=(<<NSPFORM);
                   6440: 	<form action="/adm/coursedocs" method="post" name="newsmppg">
1.655     raeburn  6441: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6442: 	$pathitem
1.329     droeschl 6443: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6444: 	<a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383     tempelho 6445: 	$help{'Simple Page'}
1.329     droeschl 6446: 	</form>
                   6447: NSPFORM
                   6448: 
                   6449: 	my $newsmpproblemform=(<<NSPROBFORM);
                   6450: 	<form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655     raeburn  6451: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6452: 	$pathitem
1.329     droeschl 6453: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6454: 	<a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572     raeburn  6455: 	$help{'Simple_Problem'}
1.329     droeschl 6456: 	</form>
                   6457: 
                   6458: NSPROBFORM
                   6459: 
                   6460: 	my $newdropboxform=(<<NDBFORM);
                   6461: 	<form action="/adm/coursedocs" method="post" name="newdropbox">
1.655     raeburn  6462: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6463: 	$pathitem
1.329     droeschl 6464: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6465: 	<a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554     raeburn  6466:         $help{'Dropbox'}
1.344     bisitz   6467: 	</form>
1.329     droeschl 6468: NDBFORM
                   6469: 
                   6470: 	my $newexuploadform=(<<NEXUFORM);
                   6471: 	<form action="/adm/coursedocs" method="post" name="newexamupload">
1.655     raeburn  6472: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6473: 	$pathitem
1.329     droeschl 6474: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6475: 	<a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329     droeschl 6476: 	$help{'Score_Upload_Form'}
                   6477: 	</form>
                   6478: NEXUFORM
                   6479: 
                   6480: 	my $newbulform=(<<NBFORM);
                   6481: 	<form action="/adm/coursedocs" method="post" name="newbul">
1.655     raeburn  6482: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6483: 	$pathitem
1.329     droeschl 6484: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6485: 	<a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329     droeschl 6486: 	$help{'Bulletin Board'}
                   6487: 	</form>
                   6488: NBFORM
                   6489: 
                   6490: 	my $newaboutmeform=(<<NAMFORM);
                   6491: 	<form action="/adm/coursedocs" method="post" name="newaboutme">
1.655     raeburn  6492: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6493: 	$pathitem
1.329     droeschl 6494: 	<input type="hidden" name="importdetail" 
                   6495: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  6496: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347     weissno  6497: 	$help{'My Personal Information Page'}
1.329     droeschl 6498: 	</form>
                   6499: NAMFORM
                   6500: 
                   6501: 	my $newaboutsomeoneform=(<<NASOFORM);
                   6502: 	<form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655     raeburn  6503: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6504: 	$pathitem
1.329     droeschl 6505: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6506: 	<a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329     droeschl 6507: 	</form>
                   6508: NASOFORM
                   6509: 
                   6510: 	my $newrosterform=(<<NROSTFORM);
                   6511: 	<form action="/adm/coursedocs" method="post" name="newroster">
1.655     raeburn  6512: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6513: 	$pathitem
1.329     droeschl 6514: 	<input type="hidden" name="importdetail" 
                   6515: 	value="$lt{'rost'}=/adm/viewclasslist" />
1.611     raeburn  6516: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556     raeburn  6517: 	$help{'Course_Roster'}
1.329     droeschl 6518: 	</form>
                   6519: NROSTFORM
                   6520: 
1.534     raeburn  6521:         my $newwebpage;
                   6522:         if ($folder =~ /^default_?(\d*)$/) {
                   6523:             $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
                   6524:             if ($1) {
                   6525:                 $newwebpage .= $1;
                   6526:             } else {
                   6527:                 $newwebpage .= 'default';
                   6528:             }
                   6529:             $newwebpage .= '/new.html';
                   6530:         }
                   6531:         my $newwebpageform =(<<NWEBFORM);
                   6532:         <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655     raeburn  6533:         <input type="hidden" name="active" value="ff" />
1.534     raeburn  6534:         $pathitem
                   6535:         <input type="hidden" name="importdetail" value="$newwebpage" />
                   6536:         <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556     raeburn  6537:         $help{'Web_Page'}
1.534     raeburn  6538:         </form>
                   6539: NWEBFORM
1.604     raeburn  6540: 
1.606     raeburn  6541:         my @ids=&Apache::lonnet::current_machine_ids();
1.691     raeburn  6542:         my $machines_str = "'".join("','",@ids)."'";
                   6543:         my (%is_home,%toppath,$rolehomes);
1.606     raeburn  6544:         if ($env{'user.author'}) {
                   6545:             if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691     raeburn  6546:                 $is_home{'author'} = 1;
1.606     raeburn  6547:             }
1.691     raeburn  6548:             $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606     raeburn  6549:         }
                   6550:         my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
                   6551:                                                       ['active'],['ca','aa']);
1.691     raeburn  6552:         my %by_roletype;
1.606     raeburn  6553:         if (keys(%roleshash)) {
                   6554:             foreach my $entry (keys(%roleshash)) {
                   6555:                 my ($auname,$audom,$roletype) = split(/:/,$entry);
                   6556:                 my $key = $entry;
                   6557:                 $key =~ s/:/___/g;
1.691     raeburn  6558:                 my $author = $auname.'___'.$audom;
                   6559:                 $by_roletype{$roletype}{$author} = 1;
1.606     raeburn  6560:                 my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691     raeburn  6561:                 $toppath{$author} = "/priv/$audom/$auname";
                   6562:                 if (grep(/^\Q$rolehome\E$/,@ids)) {
                   6563:                     $is_home{$author} = 1;
1.606     raeburn  6564:                 }
1.691     raeburn  6565:                 $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
                   6566:                               'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606     raeburn  6567:             }
1.691     raeburn  6568:         }
                   6569:         my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   6570:         if (grep(/^\Q$crshome\E$/,@ids)) {
                   6571:             $is_home{'course'} = 1;
                   6572:         }
                   6573:         $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
                   6574:         my $pickdir = $lt{'loca'}.
                   6575:                    '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
                   6576:                    '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
                   6577:         if ($env{'user.author'}) {
                   6578:             $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
                   6579:         }
                   6580:         if (keys(%by_roletype)) {
                   6581:             foreach my $possrole ('ca','aa') {
                   6582:                 if (ref($by_roletype{$possrole}) eq 'HASH') {
                   6583:                     my $roletitle = &Apache::lonnet::plaintext($possrole);
                   6584:                     foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
                   6585:                         my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
                   6586:                         $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
                   6587:                                      $roletitle." ($audom/$auname)</option>\n";
1.606     raeburn  6588:                     }
                   6589:                 }
                   6590:             }
                   6591:         }
1.691     raeburn  6592:         $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n".
                   6593:                     '</select><br />'."\n".
                   6594:                     $lt{'dire'}.
                   6595:                     '<select name="authorpath" onchange="toggleCrsResTitle();">'.
                   6596:                     '<option value=""></option>'.
                   6597:                     '</select><br />'."\n";
1.606     raeburn  6598: 
                   6599:         my %seltemplate_menus;
                   6600:         my @files = &Apache::lonhomework::get_template_list('problem');
                   6601:         my @noexamplelink = ('blank.problem','blank.library','script.library');
                   6602:         my $currentcategory = '';
                   6603:         my @ordered = ('');
                   6604:         my %templatehelp;
                   6605:         my $defcategory = '';
                   6606:         my @catorder = ($defcategory);
                   6607:         $seltemplate_menus{$defcategory}->{'order'} = [''];
                   6608:         $seltemplate_menus{$defcategory}->{'text'} = '';
                   6609:         foreach my $file (@files) {
                   6610:             if (ref($file) eq 'ARRAY') {
                   6611:                 my ($path,$title,$category,$help) = @{$file};
                   6612:                 next if ($title !~ /\S/);
                   6613:                 if (&js_escape($category) ne $currentcategory) {
                   6614:                     $currentcategory = &js_escape($category);
                   6615:                     push(@catorder,&js_escape($currentcategory));
                   6616:                     $seltemplate_menus{$currentcategory}->{'text'} = $category;
                   6617:                     $seltemplate_menus{$currentcategory}->{'default'} = '';
                   6618:                     $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
                   6619:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
                   6620:                 }
                   6621:                 if ($path) {
                   6622:                     $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
                   6623:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
                   6624:                     if ($help) {
                   6625:                         $templatehelp{$path} = $help;
                   6626:                     }
                   6627:                 }
                   6628:             }
                   6629:         }
                   6630: 
                   6631:         my $templates = $lt{'cate'}.' '.
                   6632:                         &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
                   6633:                                                                 $defcategory,'tempcategory','template',
                   6634:                                                                 \%seltemplate_menus,\@catorder,
                   6635:                                                                 "resize_scrollbox('contentscroll','1','0');",
                   6636:                                                                 "toggleExampleText();",'template').'<br />';
                   6637:         my $templatepreview =  '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true);  return false;">'.
                   6638:                                '<span id="newresexample">'.&mt('Example').'<span></a>';
                   6639:         my $crsresform=(<<RESFORM);
1.691     raeburn  6640:         <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.606     raeburn  6641:         $lt{'stpr'}</a>$help{'Course_Resource'}
                   6642:         <form action="/adm/coursedocs" method="post" name="courseresform">
                   6643:         <fieldset id="crsresform" style="display:none;">
                   6644:         <legend>$lt{'stpr'}</legend>
1.655     raeburn  6645:         <input type="hidden" name="active" value="bb" />
1.606     raeburn  6646:         <p>
                   6647:         $pickdir
1.691     raeburn  6648:         <div id="newstdproblem" style="display:none;">
1.606     raeburn  6649:         <span class="LC_nobreak">$lt{'news'}?&nbsp;
1.611     raeburn  6650:         <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606     raeburn  6651:         &nbsp;
1.611     raeburn  6652:         <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606     raeburn  6653:         </span><span id="newsubdir"></span>
                   6654:         <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
                   6655:         </p>
                   6656:         $lt{'fnam'}
1.611     raeburn  6657:         <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606     raeburn  6658:         <p>
1.691     raeburn  6659:         <div id="newresource" style="display:none">
1.606     raeburn  6660:         $lt{'addp'}
1.611     raeburn  6661:         <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  6662:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  6663:         <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  6664:         $lt{'yes'}</label>
                   6665:         <span id="newrestitle"></span>
1.611     raeburn  6666:         <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606     raeburn  6667:         </div>
                   6668:         </p>
                   6669:         <p>
                   6670:         $lt{'uste'}
1.611     raeburn  6671:         <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  6672:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  6673:         <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  6674:         $lt{'yes'}</label>
                   6675:         <div id="newrestemplate" style="display:none">
                   6676:         $templates
                   6677:         $templatepreview
                   6678:         </div>
                   6679:         </p>
                   6680:         <span class="LC_nobreak">
                   6681:         <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611     raeburn  6682:         <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606     raeburn  6683:         </span>
1.689     raeburn  6684:         </div>
1.691     raeburn  6685:         <div id="stdprobswitch" style="display:none;">
1.689     raeburn  6686:         $rolehomes
                   6687:         <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
                   6688:         </div>
1.606     raeburn  6689:         </fieldset>
                   6690:         </form>
                   6691: 
                   6692: RESFORM
1.534     raeburn  6693: 
1.342     ehlerst  6694: my $specialdocumentsform;
1.383     tempelho 6695: my @specialdocumentsforma;
1.451     www      6696: my $gradingform;
                   6697: my @gradingforma;
                   6698: my $communityform;
                   6699: my @communityforma;
1.351     ehlerst  6700: my $newfolderform;
1.390     tempelho 6701: my $newfolderb;
1.342     ehlerst  6702: 
1.451     www      6703: 	my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383     tempelho 6704: 	
1.329     droeschl 6705: 	my $newpageform=(<<NPFORM);
                   6706: 	<form action="/adm/coursedocs" method="post" name="newpage">
                   6707: 	<input type="hidden" name="folderpath" value="$path" />
                   6708: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  6709: 	<input type="hidden" name="active" value="ee" />
1.423     onken    6710: 	<a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383     tempelho 6711: 	$help{'Adding_Pages'}
1.329     droeschl 6712: 	</form>
                   6713: NPFORM
1.390     tempelho 6714: 
                   6715: 
1.351     ehlerst  6716: 	$newfolderform=(<<NFFORM);
1.329     droeschl 6717: 	<form action="/adm/coursedocs" method="post" name="newfolder">
1.508     raeburn  6718: 	$pathitem
1.329     droeschl 6719: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  6720: 	<input type="hidden" name="active" value="" />
1.422     onken    6721: 	<a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329     droeschl 6722: 	</form>
                   6723: NFFORM
                   6724: 
                   6725: 	my $newsylform=(<<NSYLFORM);
                   6726: 	<form action="/adm/coursedocs" method="post" name="newsyl">
1.570     raeburn  6727: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6728: 	$pathitem
1.329     droeschl 6729: 	<input type="hidden" name="importdetail" 
                   6730: 	value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  6731: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329     droeschl 6732: 	$help{'Syllabus'}
1.383     tempelho 6733: 
1.329     droeschl 6734: 	</form>
                   6735: NSYLFORM
1.364     bisitz   6736: 
1.329     droeschl 6737: 	my $newgroupfileform=(<<NGFFORM);
                   6738: 	<form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655     raeburn  6739: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6740: 	$pathitem
1.329     droeschl 6741: 	<input type="hidden" name="importdetail"
                   6742: 	value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611     raeburn  6743: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353     weissno  6744: 	$help{'Group Portfolio'}
1.329     droeschl 6745: 	</form>
                   6746: NGFFORM
1.672     raeburn  6747:         if ($container eq 'page') {
                   6748:             @specialdocumentsforma=(
                   6749:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
                   6750:             );
                   6751:         } else {
                   6752: 	    @specialdocumentsforma=(
1.421     onken    6753: 	{'<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  6754: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611     raeburn  6755: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451     www      6756:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534     raeburn  6757:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672     raeburn  6758:             );
                   6759:         }
1.451     www      6760:         $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
                   6761: 
1.655     raeburn  6762:         my @external = (
                   6763:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519     raeburn  6764:         );
1.598     raeburn  6765:         if (keys(%ltitools)) {
1.655     raeburn  6766:             push(@external,
                   6767:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
                   6768:             );
1.598     raeburn  6769:         }
1.655     raeburn  6770:         my $externalform = &create_form_ul(&create_list_elements(@external));
                   6771: 
                   6772:         my @importdoc = ();
1.519     raeburn  6773:         unless ($container eq 'page') {
                   6774:             push(@importdoc,
                   6775:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
                   6776:             );
                   6777:         }
                   6778:         push(@importdoc,
1.558     raeburn  6779:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519     raeburn  6780:         );
1.501     raeburn  6781:         $fileuploadform =  &create_form_ul(&create_list_elements(@importdoc));
1.434     raeburn  6782: 
1.451     www      6783:         @gradingforma=(
                   6784:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
                   6785:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
                   6786:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.691     raeburn  6787:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform},
1.451     www      6788:         );
                   6789:         $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
                   6790: 
                   6791:         @communityforma=(
                   6792:        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
                   6793:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
                   6794:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611     raeburn  6795:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
                   6796:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451     www      6797:         );
                   6798:         $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383     tempelho 6799: 
1.330     tempelho 6800: my %orderhash = (
1.553     raeburn  6801:                 'aa' => ['Upload',$fileuploadform],
                   6802:                 'bb' => ['Import',$importpubform],
1.655     raeburn  6803:                 'cc' => ['External',$externalform],
                   6804:                 'dd' => ['Grading',$gradingform],
1.673     raeburn  6805:                 'ff' => ['Other',$specialdocumentsform],
1.330     tempelho 6806:                 );
1.519     raeburn  6807: unless ($container eq 'page') {
1.434     raeburn  6808:     $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655     raeburn  6809:     $orderhash{'ee'} = ['Collaboration',$communityform];
1.434     raeburn  6810: }
                   6811: 
1.341     ehlerst  6812:  $hadchanges=0;
1.484     raeburn  6813:        unless (($supplementalflag || $toolsflag)) {
1.458     raeburn  6814:           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615     raeburn  6815:                               $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622     raeburn  6816:                               \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617     raeburn  6817:           undef($navmap);
1.443     www      6818:           if ($error) {
                   6819:              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   6820:           }
1.639     raeburn  6821:           if ($hadchanges) {
                   6822:               unless (&is_hash_old()) {
1.638     raeburn  6823:                   &mark_hash_old();
                   6824:               }
                   6825: 	  }
1.341     ehlerst  6826: 
1.443     www      6827:           &changewarning($r,'');
                   6828:         }
1.458     raeburn  6829:     }
1.442     www      6830: 
1.443     www      6831: # Supplemental documents start here
                   6832: 
1.329     droeschl 6833:        my $folder=$env{'form.folder'};
1.443     www      6834:        unless ($supplementalflag) {
1.329     droeschl 6835: 	   $folder='supplemental';
                   6836:        }
1.685     raeburn  6837:        if (($folder eq 'supplemental') &&
1.329     droeschl 6838: 	   (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446     www      6839:           $env{'form.folderpath'} = &supplemental_base();
1.393     raeburn  6840:        } elsif ($allowed) {
1.356     tempelho 6841: 	  $env{'form.folderpath'} = $savefolderpath;
1.329     droeschl 6842:        }
1.508     raeburn  6843:        $pathitem = '<input type="hidden" name="folderpath" value="'.
                   6844:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329     droeschl 6845:        if ($allowed) {
                   6846: 	   my $folderseq=
1.504     raeburn  6847: 	       '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329     droeschl 6848: 
                   6849: 	my $supupdocform=(<<SUPDOCFORM);
1.501     raeburn  6850:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
                   6851:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383     tempelho 6852: 	<form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516     raeburn  6853:         <fieldset id="uploadsuppdocform" style="display: none;">
1.501     raeburn  6854:         <legend>$lt{'upfi'}</legend>
1.630     raeburn  6855: 	<input type="hidden" name="active" value="ee" />
1.329     droeschl 6856: 	$fileupload
                   6857: 	<br />
                   6858: 	<br />
                   6859: 	<span class="LC_nobreak">
                   6860: 	$checkbox
                   6861: 	</span>
                   6862: 	<br /><br />
                   6863: 	$lt{'comment'}:<br />
1.383     tempelho 6864: 	<textarea cols="50" rows="4" name="comment"></textarea>
1.329     droeschl 6865: 	<br />
1.508     raeburn  6866: 	$pathitem
1.329     droeschl 6867: 	<input type="hidden" name="cmd" value="upload_supplemental" />
1.501     raeburn  6868:         <input type='submit' value="$lt{'upld'}" />
                   6869:         </form>
1.329     droeschl 6870: SUPDOCFORM
                   6871: 
                   6872: 	my $supnewfolderform=(<<SNFFORM);
                   6873: 	<form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570     raeburn  6874: 	<input type="hidden" name="active" value="" />
1.508     raeburn  6875:         $pathitem
1.329     droeschl 6876: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6877: 	<a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a> 
1.383     tempelho 6878: 	$help{'Adding_Folders'}
1.329     droeschl 6879: 	</form>
                   6880: SNFFORM
1.383     tempelho 6881: 	
1.510     raeburn  6882:         my $supextform =
                   6883:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611     raeburn  6884:                                                  $help{'Adding_External_Resource'},
                   6885:                                                  undef,undef,undef,undef,undef,undef,
                   6886:                                                  $disabled);
1.329     droeschl 6887: 
1.598     raeburn  6888:         my $supexttoolform =
                   6889:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
                   6890:                                                  $help{'Adding_External_Tool'},
                   6891:                                                  undef,undef,'tool',$coursedom,
1.611     raeburn  6892:                                                  $coursenum,\%ltitools,$disabled);
1.598     raeburn  6893: 
1.329     droeschl 6894: 	my $supnewsylform=(<<SNSFORM);
                   6895: 	<form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371     tempelho 6896: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6897:         $pathitem
1.329     droeschl 6898: 	<input type="hidden" name="importdetail" 
                   6899: 	value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  6900: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329     droeschl 6901: 	$help{'Syllabus'}
                   6902: 	</form>
                   6903: SNSFORM
                   6904: 
                   6905: 	my $supnewaboutmeform=(<<SNAMFORM);
1.383     tempelho 6906: 	<form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371     tempelho 6907: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6908:         $pathitem
1.329     droeschl 6909: 	<input type="hidden" name="importdetail" 
                   6910: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  6911: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347     weissno  6912: 	$help{'My Personal Information Page'}
1.329     droeschl 6913: 	</form>
                   6914: SNAMFORM
                   6915: 
1.534     raeburn  6916:         my $supwebpage;
                   6917:         if ($folder =~ /^supplemental_?(\d*)$/) {
                   6918:             $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
                   6919:             if ($1) {
                   6920:                 $supwebpage .= $1;
                   6921:             } else {
                   6922:                 $supwebpage .= 'default';
                   6923:             }
                   6924:             $supwebpage .= '/new.html';
                   6925:         }
                   6926:         my $supwebpageform =(<<SWEBFORM);
                   6927:         <form action="/adm/coursedocs" method="post" name="supwebpage">
                   6928:         <input type="hidden" name="active" value="cc" />
                   6929:         $pathitem
                   6930:         <input type="hidden" name="importdetail" value="$supwebpage" />
                   6931:         <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556     raeburn  6932:         $help{'Web_Page'}
1.534     raeburn  6933:         </form>
                   6934: SWEBFORM
                   6935: 
1.333     muellerd 6936: 
1.383     tempelho 6937: my @specialdocs = (
1.618     raeburn  6938: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417     droeschl 6939:             =>$supnewsylform},
1.611     raeburn  6940: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417     droeschl 6941:             =>$supnewaboutmeform},
1.534     raeburn  6942:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
                   6943: 
1.383     tempelho 6944: 		);
1.655     raeburn  6945:         my @supexternal = (
                   6946:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
                   6947:              =>$supextform});
1.598     raeburn  6948:         if (keys(%ltitools)) {
1.655     raeburn  6949:             push(@supexternal,
                   6950:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598     raeburn  6951:             =>$supexttoolform});
                   6952:         }
1.655     raeburn  6953:         my @supimportdoc = (
1.598     raeburn  6954:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501     raeburn  6955:             =>$supupdocform},
1.598     raeburn  6956:         );
1.501     raeburn  6957: 
                   6958: $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc));
1.333     muellerd 6959: my %suporderhash = (
1.390     tempelho 6960: 		'00' => ['Supnewfolder', $supnewfolderform],
1.655     raeburn  6961:                 'dd' => ['Upload',$supupdocform],
                   6962:                 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553     raeburn  6963:                 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333     muellerd 6964:                 );
1.443     www      6965:         if ($supplementalflag) {
1.682     raeburn  6966:             $suppchanges = 0;
                   6967:             my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
                   6968:                                 $supplementalflag,\%suporderhash,$iconpath,$pathitem,
                   6969:                                 \%ltitools,$canedit,$hostname);
                   6970:             if ($error) {
                   6971:                 $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   6972:             }
                   6973:             if ($suppchanges) {
1.684     raeburn  6974:                 &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682     raeburn  6975:                 undef($suppchanges);
                   6976:             }
1.393     raeburn  6977:         }
1.443     www      6978:     } elsif ($supplementalflag) {
1.458     raeburn  6979:         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682     raeburn  6980:                             $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
                   6981:                             $hostname);
1.393     raeburn  6982:         if ($error) {
                   6983:             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383     tempelho 6984:         }
1.393     raeburn  6985:     }
1.389     tempelho 6986: 
1.510     raeburn  6987:     if ($needs_end) {
                   6988:         $r->print(&endContentScreen());
                   6989:     }
1.383     tempelho 6990: 
1.329     droeschl 6991:     if ($allowed) {
                   6992: 	$r->print('
                   6993: <form method="post" name="extimport" action="/adm/coursedocs">
                   6994:   <input type="hidden" name="title" />
                   6995:   <input type="hidden" name="url" />
                   6996:   <input type="hidden" name="useform" />
                   6997:   <input type="hidden" name="residx" />
                   6998: </form>');
                   6999:     }
1.484     raeburn  7000:   } elsif ($showdoc) {
1.329     droeschl 7001: # -------------------------------------------------------- This is showdoc mode
1.484     raeburn  7002:       $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498     bisitz   7003: 		&Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329     droeschl 7004: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484     raeburn  7005:                 &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329     droeschl 7006:   }
                   7007:  }
1.630     raeburn  7008:  unless ($noendpage) {
1.606     raeburn  7009:      $r->print(&Apache::loncommon::end_page());
                   7010:  }
1.329     droeschl 7011:  return OK;
1.364     bisitz   7012: }
1.329     droeschl 7013: 
1.440     raeburn  7014: sub embedded_form_elems {
                   7015:     my ($phase,$primaryurl,$newidx) = @_;
                   7016:     my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634     raeburn  7017:     $newidx =~s /\D+//g;
1.440     raeburn  7018:     return <<STATE;
                   7019:     <input type="hidden" name="folderpath" value="$folderpath" />
                   7020:     <input type="hidden" name="cmd" value="upload_embedded" />
                   7021:     <input type="hidden" name="newidx" value="$newidx" />
                   7022:     <input type="hidden" name="phase" value="$phase" />
                   7023:     <input type="hidden" name="primaryurl" value="$primaryurl" />
                   7024: STATE
                   7025: }
                   7026: 
                   7027: sub embedded_destination {
                   7028:     my $folder=$env{'form.folder'};
                   7029:     my $destination = 'docs/';
                   7030:     if ($folder =~ /^supplemental/) {
                   7031:         $destination = 'supplemental/';
                   7032:     }
                   7033:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   7034:         $destination .= 'default/';
                   7035:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   7036:         $destination .=  $2.'/';
                   7037:     }
1.634     raeburn  7038:     my $newidx = $env{'form.newidx'};
                   7039:     $newidx =~s /\D+//g;
                   7040:     if ($newidx) {
                   7041:         $destination .= $newidx;
                   7042:     }
1.440     raeburn  7043:     my $dir_root = '/userfiles';
                   7044:     return ($destination,$dir_root);
                   7045: }
                   7046: 
                   7047: sub return_to_editor {
                   7048:     my $actionurl = '/adm/coursedocs';
                   7049:     return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n". 
                   7050:            '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
                   7051:            '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
                   7052:            '</a></p>';
                   7053: }
                   7054: 
1.476     raeburn  7055: sub decompression_info {
                   7056:     my ($destination,$dir_root) = &embedded_destination();
                   7057:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                   7058:     my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   7059:     my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   7060:     my $container='sequence';
1.480     raeburn  7061:     my ($pathitem,$hiddenelem);
1.583     raeburn  7062:     my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519     raeburn  7063:     if ($env{'form.folderpath'} =~ /\:1$/) {
1.476     raeburn  7064:         $container='page';
                   7065:     }
1.480     raeburn  7066:     unshift(@hiddens,$pathitem);
                   7067:     foreach my $item (@hiddens) {
1.634     raeburn  7068:         if ($item eq 'newidx') {
                   7069:             next if ($env{'form.'.$item} =~ /\D/);
                   7070:         }
1.480     raeburn  7071:         if ($env{'form.'.$item}) {
                   7072:             $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583     raeburn  7073:                            &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480     raeburn  7074:         }
1.477     raeburn  7075:     }
1.476     raeburn  7076:     return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
                   7077:             $hiddenelem);
                   7078: }
                   7079: 
                   7080: sub decompression_phase_one {
                   7081:     my ($dir,$file,$warning,$error,$output);
                   7082:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   7083:         &decompression_info();
1.490     raeburn  7084:     if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476     raeburn  7085:         $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
                   7086:     } else {
                   7087:         my $file = $1;
1.630     raeburn  7088:         $output =
1.481     raeburn  7089:             &Apache::loncommon::process_decompression($docudom,$docuname,$file,
                   7090:                                                       $destination,$dir_root,
                   7091:                                                       $hiddenelem);
                   7092:         if ($env{'form.autoextract_camtasia'}) {
                   7093:             $output .= &remove_archive($docudom,$docuname,$container);
                   7094:         }
1.476     raeburn  7095:     }
                   7096:     if ($error) {
                   7097:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   7098:                    $error.'</p>'."\n";
                   7099:     }
                   7100:     if ($warning) {
                   7101:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   7102:     }
                   7103:     return $output;
                   7104: }
                   7105: 
                   7106: sub decompression_phase_two {
                   7107:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   7108:         &decompression_info();
1.481     raeburn  7109:     my $output;
1.480     raeburn  7110:     if ($env{'form.archivedelete'}) {
1.481     raeburn  7111:         $output = &remove_archive($docudom,$docuname,$container);
1.480     raeburn  7112:     }
                   7113:     $output .= 
1.481     raeburn  7114:         &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476     raeburn  7115:                                                     $destination,$dir_root,$hiddenelem);
                   7116:     return $output;
                   7117: }
                   7118: 
1.480     raeburn  7119: sub remove_archive {
                   7120:     my ($docudom,$docuname,$container) = @_;
                   7121:     my $map = $env{'form.folder'}.'.'.$container;
1.481     raeburn  7122:     my ($output,$delwarning,$delresult,$url);
1.480     raeburn  7123:     my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
                   7124:     if ($fatal) {
                   7125:         if ($container eq 'page') {
                   7126:             $delwarning = &mt('An error occurred retrieving the contents of the current page.');
                   7127:         } else {
                   7128:             $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
                   7129:         }
1.583     raeburn  7130:         $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  7131:     } else {
                   7132:         my $currcmd = $env{'form.cmd'};
                   7133:         my $position = $env{'form.position'};
1.583     raeburn  7134:         my $archiveidx = $position;
1.563     raeburn  7135:         if ($position > 0) {
1.583     raeburn  7136:             if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
                   7137:                 $archiveidx = $position-1;
                   7138:             }
                   7139:             $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584     raeburn  7140:             my ($title,$url,@rrest) =
1.583     raeburn  7141:                 split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
                   7142:             if ($url eq $env{'form.archiveurl'}) {
                   7143:                 if (&handle_edit_cmd($docuname,$docudom)) {
                   7144:                     ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684     raeburn  7145:                     if ($suppchanges) {
                   7146:                         &Apache::lonnet::update_supp_caches($docudom,$docuname);
                   7147:                         undef($suppchanges);
                   7148:                     }
1.583     raeburn  7149:                     if ($fatal) {
                   7150:                         if ($container eq 'page') {
                   7151:                             $delwarning = &mt('An error occurred updating the contents of the current page.');
                   7152:                         } else {
                   7153:                             $delwarning = &mt('An error occurred updating the contents of the current folder.');
                   7154:                         }
1.480     raeburn  7155:                     } else {
1.583     raeburn  7156:                         $delresult = &mt('Archive file removed.');
1.480     raeburn  7157:                     }
                   7158:                 }
1.583     raeburn  7159:             } else {
                   7160:                 $delwarning .=  &mt('Archive file had unexpected item number in folder.').
                   7161:                                 ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  7162:             }
                   7163:         }
                   7164:         $env{'form.cmd'} = $currcmd;
                   7165:     }
                   7166:     if ($delwarning) {
                   7167:         $output = '<p class="LC_warning">'.
                   7168:                    $delwarning.
                   7169:                    '</p>';
                   7170:     }
                   7171:     if ($delresult) {
                   7172:         $output .= '<p class="LC_info">'.
                   7173:                    $delresult.
                   7174:                    '</p>';
                   7175:     }
1.481     raeburn  7176:     return $output;
1.480     raeburn  7177: }
                   7178: 
1.484     raeburn  7179: sub generate_admin_menu {
1.611     raeburn  7180:     my ($crstype,$canedit) = @_;
1.484     raeburn  7181:     my $lc_crstype = lc($crstype);
                   7182:     my ($home,$other,%outhash)=&authorhosts();
1.562     bisitz   7183:     my %lt= ( # do not translate here
1.484     raeburn  7184:                                          'vc'   => 'Verify Content',
                   7185:                                          'cv'   => 'Check/Set Resource Versions',
                   7186:                                          'ls'   => 'List Resource Identifiers',
1.651     raeburn  7187:                                          'ct'   => 'Display/Set Shortened URLs for Deep-linking',
1.484     raeburn  7188:                                          'imse' => 'Export contents to IMS Archive',
1.568     raeburn  7189:                                          'dcd'  => "Copy $crstype Content to Authoring Space",
1.562     bisitz   7190:             );
1.484     raeburn  7191:     my ($candump,$dumpurl);
                   7192:     if ($home + $other > 0) {
                   7193:         $candump = 'F';
                   7194:         if ($home) {
                   7195:             $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
                   7196:         } else {
                   7197:             my @hosts;
                   7198:             foreach my $aurole (keys(%outhash)) {
                   7199:                 unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   7200:                     push(@hosts,$outhash{$aurole});
1.538     raeburn  7201:                 }
1.484     raeburn  7202:             }
                   7203:             if (@hosts == 1) {
                   7204:                 my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
                   7205:                                '&amp;role='.
                   7206:                                &HTML::Entities::encode($env{'request.role'},'"<>&').'&amp;origurl='.
                   7207:                                &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
                   7208:                 $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
                   7209:             } else {
                   7210:                 $dumpurl = "javascript:choose_switchserver_window()";
                   7211:             }
                   7212:         }
                   7213:     }
                   7214:     my @menu=
                   7215:         ({  categorytitle=>'Administration',
                   7216:             items =>[
                   7217:                 {   linktext   => $lt{'vc'},
                   7218:                     url        => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
                   7219:                     permission => 'F',
1.571     raeburn  7220:                     help       => 'Docs_Verify_Content',
1.484     raeburn  7221:                     icon       => 'verify.png',
                   7222:                     linktitle  => 'Verify contents can be retrieved/rendered',
                   7223:                 },
                   7224:                 {   linktext => $lt{'cv'},
                   7225:                     url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
                   7226:                     permission => 'F',
1.571     raeburn  7227:                     help       => 'Docs_Check_Resource_Versions',
1.484     raeburn  7228:                     icon       => 'resversion.png',
                   7229:                     linktitle  => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
                   7230:                 },
                   7231:                 {   linktext   => $lt{'ls'},
                   7232:                     url        => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
                   7233:                     permission => 'F',
                   7234:                     #help => '',
                   7235:                     icon       => 'symbs.png',
                   7236:                     linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"
                   7237:                 },
1.651     raeburn  7238:                 {   linktext   => $lt{'ct'},
                   7239:                     url        => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
                   7240:                     permission => 'F',
                   7241:                     help       => 'Docs_Short_URLs',
                   7242:                     icon       => 'shorturls.png',
                   7243:                     linktitle  => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
                   7244:                 },
1.484     raeburn  7245:                 ]
1.611     raeburn  7246:         });
                   7247:     if ($canedit) {
                   7248:         push(@menu,
1.484     raeburn  7249:         {   categorytitle=>'Export',
                   7250:             items =>[
                   7251:                 {   linktext   => $lt{'imse'},
                   7252:                     url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
                   7253:                     permission => 'F',
                   7254:                     help       => 'Docs_Export_Course_Docs',
                   7255:                     icon       => 'imsexport.png',
                   7256:                     linktitle  => $lt{'imse'},
                   7257:                 },
                   7258:                 {   linktext   => $lt{'dcd'},
                   7259:                     url        => $dumpurl,
                   7260:                     permission => $candump,
1.571     raeburn  7261:                     help       => 'Docs_Dump_Course_Docs',
1.484     raeburn  7262:                     icon       => 'dump.png',
                   7263:                     linktitle  => $lt{'dcd'},
                   7264:                 },
                   7265:                 ]
                   7266:         });
1.611     raeburn  7267:     }
1.484     raeburn  7268:     return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
                   7269:            '<input type="hidden" id="dummy" />'."\n".
                   7270:            &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
                   7271:            '</form>';
1.329     droeschl 7272: }
                   7273: 
                   7274: sub generate_edit_table {
1.538     raeburn  7275:     my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611     raeburn  7276:         $need_save,$copyfolder,$canedit) = @_;
1.406     raeburn  7277:     return unless(ref($orderhash_ref) eq 'HASH');
1.342     ehlerst  7278:     my %orderhash = %{$orderhash_ref};
1.611     raeburn  7279:     my ($form, $activetab, $active, $disabled);
1.570     raeburn  7280:     if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371     tempelho 7281:         $activetab = $env{'form.active'};
                   7282:     }
1.611     raeburn  7283:     unless ($canedit) {
                   7284:         $disabled = ' disabled="disabled"';
                   7285:     }
1.472     raeburn  7286:     my $backicon = $iconpath.'clickhere.gif';
1.525     raeburn  7287:     my $backtext = &mt('Exit Editor');
1.458     raeburn  7288:     $form = '<div class="LC_Box" style="margin:0;">'.
1.488     raeburn  7289:             '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
                   7290:             '<li class="goback">'.
1.546     raeburn  7291:             '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488     raeburn  7292:             '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
                   7293:             '  alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
                   7294:             '<li>'.
                   7295:             '<a href="javascript:groupopen('."'$readfile'".',1);">'.
                   7296:             &mt('Undo Delete').'</a></li>'."\n";
                   7297:     if ($env{'form.docslog'}) {
                   7298:         $form .= '<li class="active">';
                   7299:     } else {
                   7300:         $form .= '<li>';
                   7301:     }
                   7302:     $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
                   7303:              &mt('History').'</a></li>'."\n";
                   7304:     if ($env{'form.docslog'}) {
                   7305:         $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
                   7306:                  &mt('Edit').'</a></li>'."\n";
1.484     raeburn  7307:     }
1.458     raeburn  7308:     foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390     tempelho 7309:         if($name ne '00'){
1.371     tempelho 7310:             if($activetab eq '' || $activetab ne $name){
                   7311:                $active = '';
                   7312:             }elsif($activetab eq $name){
                   7313:                $active = 'class="active"';
                   7314:             }
1.458     raeburn  7315:             $form .= '<li style="float:right" '.$active
1.484     raeburn  7316:                 .' 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 7317:         } else {
1.570     raeburn  7318: 	    $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390     tempelho 7319: 
                   7320: 	}
1.329     droeschl 7321:     }
1.484     raeburn  7322:     $form .= '</ul>'."\n";
                   7323:     $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458     raeburn  7324: 
                   7325:     if ($to_show ne '') {
1.538     raeburn  7326:         my $saveform;
                   7327:         if ($need_save) {
                   7328:             my $button = &mt('Make changes');
                   7329:             my $path;
                   7330:             if ($env{'form.folderpath'}) {
                   7331:                 $path =
                   7332:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   7333:             }
                   7334:             $saveform = <<"END";
                   7335: <div id="multisave" style="display:none; clear:both;" >
                   7336: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
                   7337: <input type="hidden" name="folderpath" value="$path" />
                   7338: <input type="hidden" name="symb" value="$env{'form.symb'}" />
                   7339: <input type="hidden" name="allhiddenresource" value="" />
                   7340: <input type="hidden" name="allencrypturl" value="" />
                   7341: <input type="hidden" name="allrandompick" value="" />
                   7342: <input type="hidden" name="allrandomorder" value="" />
                   7343: <input type="hidden" name="changeparms" value="" />
                   7344: <input type="hidden" name="multiremove" value="" />
                   7345: <input type="hidden" name="multicut" value="" />
                   7346: <input type="hidden" name="multicopy" value="" />
                   7347: <input type="hidden" name="multichange" value="" />
                   7348: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611     raeburn  7349: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538     raeburn  7350: </form>
                   7351: </div>
                   7352: END
                   7353:         }
                   7354:         $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458     raeburn  7355:     }
1.363     ehlerst  7356:     foreach my $field (keys(%orderhash)){
1.390     tempelho 7357: 	if($field ne '00'){
1.422     onken    7358:             if($activetab eq '' || $activetab ne $field){
1.458     raeburn  7359:                 $active = 'style="display: none;float:left"';
1.422     onken    7360:             }elsif($activetab eq $field){
1.458     raeburn  7361:                 $active = 'style="display:block;float:left"';
1.422     onken    7362:             }
                   7363:             $form .= '<div id="'.$field.$tid.'"'
                   7364:                     .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484     raeburn  7365:                     .'</div>'."\n";
1.363     ehlerst  7366:         }
                   7367:     }
1.484     raeburn  7368:     unless ($env{'form.docslog'}) {
                   7369:         $form .= '</div></div>'."\n";
                   7370:     }
1.329     droeschl 7371:     return $form;
                   7372: }
                   7373: 
                   7374: sub editing_js {
1.622     raeburn  7375:     my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
                   7376:         $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594     damieng  7377:     my %js_lt = &Apache::lonlocal::texthash(
1.329     droeschl 7378:                                           p_mnf => 'Name of New Folder',
                   7379:                                           t_mnf => 'New Folder',
                   7380:                                           p_mnp => 'Name of New Page',
                   7381:                                           t_mnp => 'New Page',
1.451     www      7382:                                           p_mxu => 'Title for the External Score',
1.349     biermanm 7383:                                           p_msp => 'Name of Simple Course Page',
1.329     droeschl 7384:                                           p_msb => 'Title for the Problem',
                   7385:                                           p_mdb => 'Title for the Drop Box',
1.336     schafran 7386:                                           p_mbb => 'Title for the Discussion Board',
1.604     raeburn  7387:                                           p_mwp => 'Title for Web Page',
1.606     raeburn  7388:                                           p_mnr => 'Title for the Resource',
1.348     weissno  7389:                                           p_mab => "Enter user:domain for User's Personal Information Page",
1.352     bisitz   7390:                                           p_mab2 => 'Personal Information Page of ',
1.329     droeschl 7391:                                           p_mab_alrt1 => 'Not a valid user:domain',
                   7392:                                           p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
                   7393:                                           p_chn => 'New Title',
                   7394:                                           p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603     raeburn  7395:                                           p_rmr2a => 'Remove',
                   7396:                                           p_rmr2b => '?',
                   7397:                                           p_rmr3a => 'Remove those',
                   7398:                                           p_rmr3b => 'items?',
                   7399:                                           p_rmr4  => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
                   7400:                                           p_rmr5  => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329     droeschl 7401:                                           p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
                   7402:                                           p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603     raeburn  7403:                                           p_ctr2a => 'Cut',
                   7404:                                           p_ctr2b => '?',
                   7405:                                           p_ctr3a => 'Cut those',
                   7406:                                           p_ctr3b => 'items?',
1.633     raeburn  7407:                                           setal   => 'Enter a (unique) alias',
                   7408:                                           delal   => 'Are you sure you want to eliminate the alias?',
1.478     raeburn  7409:                                           rpck    => 'Enter number to pick (e.g., 3)',
1.501     raeburn  7410:                                           imsfile => 'You must choose an IMS package for import',
                   7411:                                           imscms  => 'You must select which Course Management System was the source of the IMS package',
                   7412:                                           invurl  => 'Invalid URL',
                   7413:                                           titbl   => 'Title is blank',
1.538     raeburn  7414:                                           more    => '(More ...)',
                   7415:                                           less    => '(Less ...)',
1.543     raeburn  7416:                                           noor    => 'No actions selected or changes to settings specified.',
                   7417:                                           noch    => 'No changes to settings specified.',
                   7418:                                           noac    => 'No actions selected.',
1.606     raeburn  7419:                                           nofi    => 'No file selected',
                   7420:                                           tinc    => 'Title in course',
                   7421:                                           sunm    => 'Sub-directory name',
1.618     raeburn  7422:                                           edri    => 'Editing rights unavailable for your current role.',
1.691     raeburn  7423:                                           sele    => 'Select',
                   7424:                                           swit    => 'Switch server required',
1.329     droeschl 7425:                                         );
1.594     damieng  7426:     &js_escape(\%js_lt);
1.433     raeburn  7427:     my $crstype = &Apache::loncommon::course_type();
1.434     raeburn  7428:     my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
                   7429:     my $main_container_page;
1.519     raeburn  7430:     if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
                   7431:         $main_container_page = 1;
1.434     raeburn  7432:     }
1.617     raeburn  7433:     my $backtourl;
                   7434:     my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446     www      7435:     my $toplevelsupp = &supplemental_base();
1.690     raeburn  7436:     my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691     raeburn  7437:     my @ids=&Apache::lonnet::current_machine_ids();
                   7438:     my $machines_str = "'".join("','",@ids)."'";
1.530     raeburn  7439:     if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
                   7440:         my $caller = $1;
1.525     raeburn  7441:         if ($caller =~ /^supplemental/) {
                   7442:             $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
                   7443:         } else {
                   7444:             my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
                   7445:             $res = &Apache::lonnet::clutter($res);
                   7446:             if (&Apache::lonnet::is_on_map($res)) {
1.609     raeburn  7447:                 my ($url,$anchor);
                   7448:                 if ($res =~ /^([^#]+)#([^#]+)$/) {
                   7449:                     $url = $1;
                   7450:                     $anchor = $2;
                   7451:                     if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
                   7452:                         $caller = $1.&escape('#').$anchor;
                   7453:                     }
1.614     raeburn  7454:                 } else {
                   7455:                     $url = $res;
1.609     raeburn  7456:                 }
1.640     raeburn  7457:                 $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
                   7458:                 if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
                   7459:                     $backtourl .= '?navmap=1';
                   7460:                 } else {
                   7461:                     $backtourl .= '?symb='.
                   7462:                                   &HTML::Entities::encode($caller,'<>&"');
                   7463:                 }
1.622     raeburn  7464:                 if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   7465:                     if (($ENV{'SERVER_PORT'} == 443) &&
                   7466:                         ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  7467:                         unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  7468:                             if ($hostname ne '') {
                   7469:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   7470:                             }
                   7471:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  7472:                         }
                   7473:                     }
1.623     raeburn  7474:                 } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
                   7475:                     if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678     raeburn  7476:                         unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658     raeburn  7477:                             if ($hostname ne '') {
                   7478:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   7479:                             }
                   7480:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.657     raeburn  7481:                         }
1.623     raeburn  7482:                     }
1.622     raeburn  7483:                 }
1.609     raeburn  7484:                 if ($anchor ne '') {
                   7485:                     $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
                   7486:                 }
1.590     raeburn  7487:                 $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544     raeburn  7488:             } else {
                   7489:                 $backtourl = '/adm/navmaps';
1.525     raeburn  7490:             }
                   7491:         }
                   7492:     } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
                   7493:         $backtourl = '/adm/menu';
                   7494:     } elsif ($supplementalflag) {
1.682     raeburn  7495:         if (($env{'request.role.adv'}) ||
                   7496:             (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
                   7497:             $backtourl = '/adm/supplemental';
                   7498:         } else {
                   7499:             $backtourl = '/adm/navmaps';
                   7500:         }
1.525     raeburn  7501:     } else {
                   7502:         $backtourl = '/adm/navmaps';
1.472     raeburn  7503:     }
                   7504: 
1.655     raeburn  7505:     my $fieldsets = "'doc'";
1.519     raeburn  7506:     unless ($main_container_page) {
                   7507:         $fieldsets .=",'ims'";
                   7508:     }
1.655     raeburn  7509:     my $extfieldsets = "'ext'";
                   7510:     if ($posslti) {
                   7511:         $extfieldsets .= ",'tool'";
                   7512:     }
1.501     raeburn  7513:     if ($supplementalflag) {
1.655     raeburn  7514:         $fieldsets = "'suppdoc'";
                   7515:         $extfieldsets = "'suppext'";
1.600     raeburn  7516:         if ($posslti) {
1.655     raeburn  7517:             $extfieldsets .= ",'supptool'";
1.600     raeburn  7518:         }
1.501     raeburn  7519:     }
1.655     raeburn  7520: 
1.611     raeburn  7521:     my $jsmakefunctions;
                   7522:     if ($canedit) {
                   7523:         $jsmakefunctions = <<ENDNEWSCRIPT;
1.329     droeschl 7524: function makenewfolder(targetform,folderseq) {
1.594     damieng  7525:     var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329     droeschl 7526:     if (foldername) {
1.676     raeburn  7527:        targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329     droeschl 7528:         targetform.submit();
                   7529:     }
                   7530: }
                   7531: 
                   7532: function makenewpage(targetform,folderseq) {
1.594     damieng  7533:     var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329     droeschl 7534:     if (pagename) {
1.676     raeburn  7535:         targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329     droeschl 7536:         targetform.submit();
                   7537:     }
                   7538: }
                   7539: 
                   7540: function makeexamupload() {
1.594     damieng  7541:    var title=prompt('$js_lt{"p_mxu"}');
1.344     bisitz   7542:    if (title) {
1.329     droeschl 7543:     this.document.forms.newexamupload.importdetail.value=
1.676     raeburn  7544: 	encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329     droeschl 7545:     this.document.forms.newexamupload.submit();
                   7546:    }
                   7547: }
                   7548: 
                   7549: function makesmppage() {
1.594     damieng  7550:    var title=prompt('$js_lt{"p_msp"}');
1.344     bisitz   7551:    if (title) {
1.329     droeschl 7552:     this.document.forms.newsmppg.importdetail.value=
1.676     raeburn  7553: 	encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329     droeschl 7554:     this.document.forms.newsmppg.submit();
                   7555:    }
                   7556: }
                   7557: 
1.534     raeburn  7558: function makewebpage(type) {
1.594     damieng  7559:    var title=prompt('$js_lt{"p_mwp"}');
1.534     raeburn  7560:    var formname;
                   7561:    if (type == 'supp') {
                   7562:        formname = this.document.forms.supwebpage;
                   7563:    } else {
                   7564:        formname = this.document.forms.newwebpage;
                   7565:    }
                   7566:    if (title) {
                   7567:        var webpage = formname.importdetail.value; 
1.675     raeburn  7568:        formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534     raeburn  7569:        formname.submit();
                   7570:    }
                   7571: }
                   7572: 
1.329     droeschl 7573: function makesmpproblem() {
1.594     damieng  7574:    var title=prompt('$js_lt{"p_msb"}');
1.344     bisitz   7575:    if (title) {
1.329     droeschl 7576:     this.document.forms.newsmpproblem.importdetail.value=
1.676     raeburn  7577: 	encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329     droeschl 7578:     this.document.forms.newsmpproblem.submit();
                   7579:    }
                   7580: }
                   7581: 
                   7582: function makedropbox() {
1.594     damieng  7583:    var title=prompt('$js_lt{"p_mdb"}');
1.344     bisitz   7584:    if (title) {
1.329     droeschl 7585:     this.document.forms.newdropbox.importdetail.value=
1.676     raeburn  7586:         encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329     droeschl 7587:     this.document.forms.newdropbox.submit();
                   7588:    }
                   7589: }
                   7590: 
                   7591: function makebulboard() {
1.594     damieng  7592:    var title=prompt('$js_lt{"p_mbb"}');
1.329     droeschl 7593:    if (title) {
                   7594:     this.document.forms.newbul.importdetail.value=
1.676     raeburn  7595: 	encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329     droeschl 7596:     this.document.forms.newbul.submit();
                   7597:    }
                   7598: }
                   7599: 
                   7600: function makeabout() {
1.594     damieng  7601:    var user=prompt("$js_lt{'p_mab'}");
1.329     droeschl 7602:    if (user) {
                   7603:        var comp=new Array();
                   7604:        comp=user.split(':');
                   7605:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   7606: 	   if ((comp[0]) && (comp[1])) {
                   7607: 	       this.document.forms.newaboutsomeone.importdetail.value=
1.594     damieng  7608: 		   '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611     raeburn  7609:                this.document.forms.newaboutsomeone.submit();
                   7610:            } else {
                   7611:                alert("$js_lt{'p_mab_alrt1'}");
                   7612:            }
                   7613:        } else {
                   7614:            alert("$js_lt{'p_mab_alrt2'}");
                   7615:        }
                   7616:     }
                   7617: }
                   7618: 
                   7619: function makenew(targetform) {
                   7620:     targetform.submit();
                   7621: }
                   7622: 
                   7623: function changename(folderpath,index,oldtitle) {
                   7624:     var title=prompt('$js_lt{"p_chn"}',oldtitle);
                   7625:     if (title) {
                   7626:         this.document.forms.renameform.markcopy.value='';
                   7627:         this.document.forms.renameform.title.value=title;
                   7628:         this.document.forms.renameform.cmd.value='rename_'+index;
                   7629:         this.document.forms.renameform.folderpath.value=folderpath;
                   7630:         this.document.forms.renameform.submit();
                   7631:     }
                   7632: }
                   7633: 
1.633     raeburn  7634: function setalias(folderpath,index) {
                   7635:     var alias = prompt('$js_lt{"setal"}');
                   7636:     if ((alias != null) && (alias != '')) {
                   7637:         this.document.forms.aliasform.alias.value=alias;
                   7638:         this.document.forms.aliasform.cmd.value='setalias_'+index;
                   7639:         this.document.forms.aliasform.folderpath.value=folderpath;
                   7640:         this.document.forms.aliasform.submit();
                   7641:     }
                   7642: }
                   7643: 
                   7644: function delalias(folderpath,index) {
                   7645:     if (confirm('$js_lt{"delal"}')) {
                   7646:         this.document.forms.aliasform.cmd.value='delalias_'+index;
                   7647:         this.document.forms.aliasform.folderpath.value=folderpath;
                   7648:         this.document.forms.aliasform.submit();
                   7649:     }
                   7650: }
                   7651: 
1.611     raeburn  7652: ENDNEWSCRIPT
                   7653:     } else {
                   7654:         $jsmakefunctions = <<ENDNEWSCRIPT;
                   7655: 
                   7656: function makenewfolder() {
                   7657:     alert("$js_lt{'edri'}");
                   7658: }
                   7659: 
                   7660: function makenewpage() {
                   7661:     alert("$js_lt{'edri'}");
                   7662: }
                   7663: 
                   7664: function makeexamupload() {
                   7665:     alert("$js_lt{'edri'}");
                   7666: }
                   7667: 
                   7668: function makesmppage() {
                   7669:     alert("$js_lt{'edri'}");
                   7670: }
                   7671: 
                   7672: function makewebpage(type) {
                   7673:     alert("$js_lt{'edri'}");
                   7674: }
                   7675: 
                   7676: function makesmpproblem() {
                   7677:     alert("$js_lt{'edri'}");
                   7678: }
                   7679: 
                   7680: function makedropbox() {
                   7681:     alert("$js_lt{'edri'}");
                   7682: }
                   7683: 
                   7684: function makebulboard() {
                   7685:     alert("$js_lt{'edri'}");
                   7686: }
                   7687: 
                   7688: function makeabout() {
                   7689:     alert("$js_lt{'edri'}");
                   7690: }
                   7691: 
                   7692: function changename() {
                   7693:     alert("$js_lt{'edri'}");
                   7694: }
                   7695: 
1.633     raeburn  7696: function setalias() {
                   7697:     alert("$js_lt{'edri'}");
                   7698: }
                   7699: 
                   7700: function delalias() {
                   7701:     alert("$js_lt{'edri'}");
                   7702: }
                   7703: 
1.611     raeburn  7704: function makenew() {
                   7705:     alert("$js_lt{'edri'}");
                   7706: }
                   7707: 
                   7708: function groupimport() {
                   7709:     alert("$js_lt{'edri'}");
1.335     ehlerst  7710: }
1.611     raeburn  7711: 
                   7712: function groupsearch() {
                   7713:     alert("$js_lt{'edri'}");
1.335     ehlerst  7714: }
1.611     raeburn  7715: 
                   7716: function groupopen(url,recover) {
                   7717:    var options="scrollbars=1,resizable=1,menubar=0";
                   7718:    idxflag=1;
                   7719:    idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
                   7720:    idx.focus();
1.329     droeschl 7721: }
                   7722: 
1.611     raeburn  7723: ENDNEWSCRIPT
                   7724: 
                   7725:     }
                   7726:     return <<ENDSCRIPT;
                   7727: 
                   7728: $jsmakefunctions
                   7729: 
1.501     raeburn  7730: function toggleUpload(caller) {
                   7731:     var blocks = Array($fieldsets);
                   7732:     for (var i=0; i<blocks.length; i++) {
                   7733:         var disp = 'none';
                   7734:         if (caller == blocks[i]) {
                   7735:             var curr = document.getElementById('upload'+caller+'form').style.display;
                   7736:             if (curr == 'none') {
                   7737:                 disp='block';
                   7738:             }
                   7739:         }
                   7740:         document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655     raeburn  7741:     }
                   7742:     resize_scrollbox('contentscroll','1','1');
                   7743:     return;
                   7744: }
                   7745: 
                   7746: function toggleExternal(caller) {
                   7747:     var blocks = Array($extfieldsets);
                   7748:     for (var i=0; i<blocks.length; i++) {
                   7749:         var disp = 'none';
                   7750:         if (caller == blocks[i]) {
                   7751:             var curr = document.getElementById('external'+caller+'form').style.display;
                   7752:             if (curr == 'none') {
                   7753:                 disp='block';
                   7754:             }
                   7755:         }
                   7756:         document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598     raeburn  7757:         if ((caller == 'tool') || (caller == 'supptool')) {
                   7758:             if (disp == 'block') {
1.655     raeburn  7759:                 if (document.getElementById('LC_exttoolid')) {
                   7760:                     var toolselector = document.getElementById('LC_exttoolid');
1.598     raeburn  7761:                     var suppflag = 0;
                   7762:                     if (caller == 'supptool') {
                   7763:                         suppflag = 1;
                   7764:                     }
                   7765:                     currForm = document.getElementById('new'+caller);
1.655     raeburn  7766:                     updateExttool(toolselector,currForm,suppflag);
1.598     raeburn  7767:                 }
                   7768:             }
                   7769:         }
1.501     raeburn  7770:     }
1.502     raeburn  7771:     resize_scrollbox('contentscroll','1','1');
                   7772:     return;
                   7773: }
                   7774: 
1.514     raeburn  7775: function toggleMap(caller) {
1.502     raeburn  7776:     var disp = 'none';
1.510     raeburn  7777:     if (document.getElementById('importmapform')) {
1.514     raeburn  7778:         if (caller == 'map') {
                   7779:             var curr = document.getElementById('importmapform').style.display;
                   7780:             if (curr == 'none') {
                   7781:                 disp='block';
                   7782:             }
1.510     raeburn  7783:         }
                   7784:         document.getElementById('importmapform').style.display=disp;
                   7785:         resize_scrollbox('contentscroll','1','1');
1.502     raeburn  7786:     }
1.501     raeburn  7787:     return;
1.329     droeschl 7788: }
                   7789: 
1.691     raeburn  7790: function toggleCrsRes(caller) {
1.606     raeburn  7791:     var disp = 'none';
                   7792:     if (document.getElementById('crsresform')) {
                   7793:         if (caller == 'res') {
1.691     raeburn  7794:             var form = document.getElementById('crsresform');
                   7795:             var curr = form.style.display;
1.606     raeburn  7796:             if (curr == 'none') {
                   7797:                 disp='block';
1.691     raeburn  7798:                 document.courseresform.authorrole.selectedIndex = 0;
                   7799:                 document.courseresform.authorpath.selectedIndex = 0;
                   7800:                 document.courseresform.newresourceadd.selectedIndex = 0;
                   7801:                 populateDirSelects(form,'authorrole','authorpath',1,0,0);
                   7802:                 toggleNewInCourse(document.courseresform);
                   7803:                 if (document.getElementById('newresource')) {
                   7804:                     document.getElementById('newresource').style.display = 'none';
1.606     raeburn  7805:                 }
                   7806:                 if (document.courseresform.newresusetemp.length) {
                   7807:                     document.courseresform.newresusetemp[0].checked = true;
                   7808:                     toggleWithTemplate(document.courseresform);
                   7809:                 }
                   7810:                 document.courseresform.newresourcename.value = ''; 
                   7811:             }
                   7812:         }
                   7813:         if (document.courseresform.newsubdir.length) {
                   7814:             for (var j=0; j<document.courseresform.newsubdir.length; j++) {
                   7815:                 if (document.courseresform.newsubdir[j].value == 0) {
                   7816:                     document.courseresform.newsubdir[j].checked = true;
                   7817:                 }
                   7818:                 break;
                   7819:             }
                   7820:             if (document.getElementById('newsubdirname')) {
                   7821:                 document.getElementById('newsubdirname').type = "hidden";
                   7822:                 document.getElementById('newsubdirname').value = "";
                   7823:             }
                   7824:             if (document.getElementById('newsubdir')) {
                   7825:                 document.getElementById('newsubdir').innerHTML = "";
                   7826:             }
                   7827:         }
                   7828:         document.getElementById('crsresform').style.display=disp;
                   7829:         resize_scrollbox('contentscroll','1','0');
                   7830:     }
                   7831:     return;
                   7832: }
                   7833: 
                   7834: function toggleNewsubdir(form) {
                   7835:     if (form.newsubdir.length) {
                   7836:         for (var j=0; j<form.newsubdir.length; j++) {
                   7837:             if (form.newsubdir[j].checked) {
                   7838:                 if (document.getElementById('newsubdirname')) {
                   7839:                     if (form.newsubdir[j].value == '1') {
                   7840:                         document.getElementById('newsubdirname').type = "text"; 
                   7841:                         if (document.getElementById('newsubdir')) {
                   7842:                             document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
                   7843:                         }
                   7844:                     } else {
                   7845:                         document.getElementById('newsubdirname').type = "hidden";
                   7846:                         document.getElementById('newsubdirname').value = "";
                   7847:                         document.getElementById('newsubdir').innerHTML = "";
                   7848:                     }
                   7849:                 }
                   7850:                 break;
                   7851:             }
                   7852:         }
                   7853:     }
                   7854: }
                   7855: 
                   7856: function toggleCrsResTitle() {
                   7857:     if (document.getElementById('newresource')) {
1.691     raeburn  7858:         var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
                   7859:         if (selloc == 'course') {
1.606     raeburn  7860:             document.getElementById('newresource').style.display = 'inline';
                   7861:             document.courseresform.newresourceadd[0].checked = true;
                   7862:             toggleNewInCourse(document.courseresform);
                   7863:         } else {
                   7864:             document.getElementById('newresource').style.display = 'none';
                   7865:         }
1.689     raeburn  7866:     }
                   7867:     if (document.getElementById('newstdproblem')) {
                   7868:         if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
                   7869:             document.getElementById('newstdproblem').style.display = 'none'; 
                   7870:             if (document.getElementById('stdprobswitch')) {
                   7871:                 document.getElementById('stdprobswitch').style.display = 'block'; 
                   7872:             }
                   7873:         } else {
                   7874:             document.getElementById('newstdproblem').style.display = 'block';
                   7875:             if (document.getElementById('stdprobswitch')) {
                   7876:                 document.getElementById('stdprobswitch').style.display = 'none';
                   7877:             }
                   7878:         }
                   7879:     }
1.606     raeburn  7880: }
                   7881: 
                   7882: function toggleNewInCourse(form) {
                   7883:     if (form.newresourceadd.length) {
                   7884:         for (var i=0; i<form.newresourceadd.length; i++) {
                   7885:             if (form.newresourceadd[i].checked) {
                   7886:                 if (document.getElementById('newresourcetitle')) {
                   7887:                     if (form.newresourceadd[i].value == '1') {
                   7888:                         document.getElementById('newresourcetitle').type = 'text';
                   7889:                         if (document.getElementById('newrestitle')) {
                   7890:                             document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
                   7891:                         }
                   7892:                     } else {
                   7893:                         document.getElementById('newresourcetitle').type = 'hidden';
                   7894:                         document.getElementById('newresourcetitle').value = '';
                   7895:                         if (document.getElementById('newrestitle')) { 
                   7896:                             document.getElementById('newrestitle').innerHTML = '';
                   7897:                         }
                   7898:                     }
                   7899:                 }
                   7900:                 break;
                   7901:             }
                   7902:         }
                   7903:     }
                   7904: }
                   7905: 
                   7906: function toggleWithTemplate(form) {
                   7907:     if (form.newresusetemp.length) {
                   7908:         for (var i=0; i<form.newresusetemp.length; i++) {
                   7909:             if (form.newresusetemp[i].checked) {
                   7910:                 if (document.getElementById('newrestemplate')) { 
                   7911:                     if (form.newresusetemp[i].value == '1') {
                   7912:                         document.getElementById('newrestemplate').style.display = 'inline';
                   7913:                         toggleExampleText();
                   7914:                     } else {
                   7915:                         form.tempcategory.selectedIndex = 0;
                   7916:                         select1template_changed();
                   7917:                         document.getElementById('newrestemplate').style.display = 'none';
                   7918:                     }
                   7919:                 }
                   7920:             }
                   7921:         }
                   7922:     }
                   7923: }
                   7924: 
                   7925: function toggleExampleText() {
                   7926:     if (document.getElementById('newresexample')) {
                   7927:         var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   7928:         if (url == '') {
                   7929:             document.getElementById('newresexample').style.fontWeight = 'normal';
                   7930:         } else {
                   7931:             document.getElementById('newresexample').style.fontWeight = 'bold';
                   7932:         }
                   7933:     }
                   7934: }
                   7935: 
                   7936: function getExample(width,height,scrolling,transparency) {
                   7937:     var url;
                   7938:     if (document.courseresform.newresusetemp.length) {
                   7939:         for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
                   7940:             if (document.courseresform.newresusetemp[i].checked) {
                   7941:                 if (document.courseresform.newresusetemp[i].value == '1') {
                   7942:                     var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   7943:                     if (url == '') {
                   7944:                         alert('Pick a category and template');
                   7945:                     } else {
                   7946:                         url = url.replace("$londocroot",""); 
                   7947:                         url += '?inhibitmenu=yes';
                   7948:                     }
                   7949:                 }
                   7950:                 break;
                   7951:             }
                   7952:         }
                   7953:     }
                   7954:     if (url != '') {
                   7955:         openMyModal(url,width,height,scrolling,transparency,'');
                   7956:     }
                   7957: }
                   7958: 
1.690     raeburn  7959: function toggleImportCrsres(caller) {
1.606     raeburn  7960:     var disp = 'none';
                   7961:     if (document.getElementById('importcrsresform')) {
                   7962:         if (caller == 'res') {
                   7963:             var curr = document.getElementById('importcrsresform').style.display;
                   7964:             if (curr == 'none') {
                   7965:                 disp='block';
1.690     raeburn  7966:                 populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1);
1.606     raeburn  7967:             }
                   7968:         }
                   7969:         document.getElementById('importcrsresform').style.display=disp;
                   7970:         resize_scrollbox('contentscroll','1','0');
                   7971:     }
                   7972:     return;
                   7973: }
                   7974: 
1.690     raeburn  7975: $showfile_js
                   7976: 
1.691     raeburn  7977: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
                   7978:     var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
                   7979:     if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
                   7980:         var selelem = form.elements[dirsel];
                   7981:         var i, numfiles = selelem.options.length -1;
                   7982:         if (numfiles >=0) {
                   7983:             for (i = numfiles; i >= 0; i--) {
                   7984:                 selelem.remove(i);
                   7985:             }
                   7986:         }
                   7987:         if ((location == '') || (location == null) || (location == 'undefined')) {
                   7988:              if (selelem.options.length == 0) {
                   7989:                  selelem.options[selelem.options.length] = new Option('','');
                   7990:                  selelem.selectedIndex = 0;
                   7991:              }
                   7992:              if (document.getElementById('newstdproblem')) {
                   7993:                  document.getElementById('newstdproblem').style.display = 'none';
                   7994:              }
                   7995:              return;
                   7996:         }
                   7997:         var machineIds = new Array($machines_str);
                   7998:         var athome = 0;
                   7999:         var role = location;
                   8000:         if ((location == 'author') || (location == 'course')) {
                   8001:             if (document.getElementById('rolehome_'+location)) {
                   8002:                 var currhome = document.getElementById('rolehome_'+location).value;
                   8003:                 if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
                   8004:                     if (machineIds.includes(currhome)) {
                   8005:                         athome = 1;
                   8006:                     }
                   8007:                 }
                   8008:             }
                   8009:         } else {
                   8010:             const roleinfo = location.split('___');
                   8011:             role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
                   8012:             if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
                   8013:                 var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
                   8014:                 if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
                   8015:                     if (machineIds.includes(currhome)) {
                   8016:                         athome = 1;
                   8017:                     }
                   8018:                 }
                   8019:             }
                   8020:         }
                   8021:         if (athome) {
                   8022:             if (document.getElementById('stdprobswitch')) {
                   8023:                 document.getElementById('stdprobswitch').style.display = 'none';
                   8024:             }
                   8025:             if (document.getElementById('newstdproblem')) {
                   8026:                 document.getElementById('newstdproblem').style.display = 'none';
                   8027:             }
                   8028:             var http = new XMLHttpRequest();
                   8029:             var url = "/adm/courseauthor";
                   8030:             var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir;
                   8031:             http.open("POST", url, true);
                   8032:             http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                   8033:             http.onreadystatechange = function() {
                   8034:                 if (http.readyState == 4 && http.status == 200) {
                   8035:                     var data = JSON.parse(http.responseText);
                   8036:                     if (Array.isArray(data.dirs)) {
                   8037:                         var len = data.dirs.length;
                   8038:                         if (len) {
                   8039:                             if (len > 1) {
                   8040:                                 selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
                   8041:                             }
                   8042:                         }
                   8043:                         if (len) {
                   8044:                             var j;
                   8045:                             for (j = 0; j < len; j++) {
                   8046:                                 selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
                   8047:                             }
                   8048:                             selelem.selectedIndex = 0;
1.697   ! raeburn  8049:                             if (len == 1) {
        !          8050:                                 toggleCrsResTitle();
        !          8051:                             }
1.691     raeburn  8052:                         }
                   8053:                     }
                   8054:                 }
                   8055:             }
                   8056:             http.send(params);
                   8057:         } else {
                   8058:             selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
                   8059:             selelem.selectedIndex = 0;
                   8060:             if (document.getElementById('stdprobswitch')) {
                   8061:                 document.getElementById('stdprobswitch').style.display = 'block';
                   8062:             }
                   8063:             if (document.getElementById('newstdproblem')) {
                   8064:                 document.getElementById('newstdproblem').style.display = 'none';
                   8065:             }
                   8066:         }
                   8067:     }
                   8068:     return;
                   8069: }
                   8070: 
1.689     raeburn  8071: function switchForProb() {
                   8072:     if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
                   8073:         var url = '/adm/switchserver?otherserver=';
                   8074:         var newhostid = '';
                   8075:         var role = '';
                   8076:         var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
                   8077:         if (selloc == 'author') {
                   8078:             newhostid = document.courseresform.rolehome_author.value;
                   8079:             role = "au./&js_escape($env{'user.domain'})/";
                   8080:         } else if (selloc == 'course') {
                   8081:             newhostid = document.courseresform.rolehome_course.value;
                   8082:             role = "&js_escape($env{'request.role'})";
                   8083:         } else {
                   8084:             var items = new Array();
                   8085:             items = selloc.split('___');
                   8086:             var len = document.courseresform.rolehome_coauthor.length;
                   8087:             if (null == len) {
                   8088:                 var currval = document.courseresform.rolehome_coauthor.value;
                   8089:                 if (null != currval) {
                   8090:                     var info = new Array();
                   8091:                     info = currval.split('=');
                   8092:                     newhostid = info[2];
                   8093:                     role = info[0]+'./'+info[1];
                   8094:                 }
                   8095:             } else {
                   8096:                 for (var i=0; i<len; i++) {
                   8097:                     var currval = document.courseresform.rolehome_coauthor[i].value;
                   8098:                     if (null != currval) {
                   8099:                         var info = new Array();
                   8100:                         info = currval.split('=');
                   8101:                         if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
                   8102:                             newhostid = info[2];
                   8103:                             role = info[0]+'./'+info[1];
                   8104:                             break;
                   8105:                         }
                   8106:                     }
                   8107:                 }
                   8108:             }
                   8109:         }
                   8110:         if (newhostid != '') {
                   8111:             url += newhostid;
                   8112:             if (role != '') {
                   8113:                 url += '&role='+role;
                   8114:             }
                   8115:             document.location.href = url;
                   8116:         }
                   8117:     }
                   8118:     return;
                   8119: }
                   8120: 
1.501     raeburn  8121: function makeims(imsform) {
                   8122:     if ((imsform.uploaddoc.value == '')  || (!imsform.uploaddoc.value)) {
1.594     damieng  8123:         alert("$js_lt{'imsfile'}");
1.501     raeburn  8124:         return;
                   8125:     }
                   8126:     if (imsform.source.selectedIndex == 0) {
1.594     damieng  8127:         alert("$js_lt{'imscms'}");
1.501     raeburn  8128:         return;
                   8129:     }
                   8130:     newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
                   8131:     imsform.submit();
                   8132: }
                   8133: 
1.478     raeburn  8134: function updatePick(targetform,index,caller) {
1.537     raeburn  8135:     var pickitem;
                   8136:     var picknumitem;
                   8137:     var picknumtext;
                   8138:     if (index == 'all') {
                   8139:         pickitem = document.getElementById('randompickall');
                   8140:         picknumitem = document.getElementById('rpicknumall');
                   8141:         picknumtext = document.getElementById('rpicktextall');
                   8142:     } else {
                   8143:         pickitem = document.getElementById('randompick_'+index);
                   8144:         picknumitem = document.getElementById('rpicknum_'+index);
                   8145:         picknumtext = document.getElementById('randompicknum_'+index);
                   8146:     }
1.478     raeburn  8147:     if (pickitem.checked) {
1.594     damieng  8148:         var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478     raeburn  8149:         if (picknum == '' || picknum == null) {
                   8150:             if (caller == 'check') {
                   8151:                 pickitem.checked=false;
1.537     raeburn  8152:                 if (index == 'all') {
                   8153:                     picknumtext.innerHTML = '';
                   8154:                     if (caller == 'link') {
                   8155:                         propagateState(targetform,'rpicknum');
                   8156:                     }
                   8157:                 } else {
1.538     raeburn  8158:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8159:                 }
1.478     raeburn  8160:             }
                   8161:         } else {
                   8162:             picknum.toString();
                   8163:             var regexdigit=/^\\d+\$/;
                   8164:             if (regexdigit.test(picknum)) {
                   8165:                 picknumitem.value = picknum;
1.537     raeburn  8166:                 if (index == 'all') {
1.538     raeburn  8167:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537     raeburn  8168:                     if (caller == 'link') {
                   8169:                         propagateState(targetform,'rpicknum');
                   8170:                     }
                   8171:                 } else {
                   8172:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538     raeburn  8173:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8174:                 }
1.478     raeburn  8175:             } else {
                   8176:                 if (caller == 'check') {
1.537     raeburn  8177:                     if (index == 'all') {
                   8178:                         picknumtext.innerHTML = '';
                   8179:                         if (caller == 'link') {
                   8180:                             propagateState(targetform,'rpicknum');
                   8181:                         }
                   8182:                     } else {
                   8183:                         pickitem.checked=false;
1.538     raeburn  8184:                         checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8185:                     }
1.478     raeburn  8186:                 }
                   8187:                 return;
                   8188:             }
                   8189:         }
                   8190:     } else {
1.537     raeburn  8191:         picknumitem.value = '';
                   8192:         picknumtext.innerHTML = '';
                   8193:         if (index == 'all') {
                   8194:             if (caller == 'link') {
                   8195:                 propagateState(targetform,'rpicknum');
                   8196:             }
                   8197:         } else {
1.538     raeburn  8198:             checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8199:         }
                   8200:     }
                   8201: }
                   8202: 
                   8203: function propagateState(form,param) {
                   8204:     if (document.getElementById(param+'all')) {
                   8205:         var setcheck = 0;
                   8206:         var rpick = 0;
                   8207:         if (param == 'rpicknum') {
                   8208:             if (document.getElementById('randompickall')) {
                   8209:                 if (document.getElementById('randompickall').checked) {
                   8210:                     if (document.getElementById('rpicknumall')) {
                   8211:                         rpick = document.getElementById('rpicknumall').value;
                   8212:                     }
                   8213:                 }
                   8214:             }
                   8215:         } else {
                   8216:             if (document.getElementById(param+'all').checked) {
                   8217:                 setcheck = 1;
                   8218:             }
                   8219:         }
1.538     raeburn  8220:         var allidxlist;
                   8221:         if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   8222:             if (document.getElementById('all'+param+'idx')) {
                   8223:                 allidxlist = document.getElementById('all'+param+'idx').value;
                   8224:             }
                   8225:             var actions = new Array ('remove','cut','copy');
                   8226:             for (var i=0; i<actions.length; i++) {
                   8227:                 if (actions[i] != param) {
                   8228:                     if (document.getElementById(actions[i]+'all')) {
                   8229:                         document.getElementById(actions[i]+'all').checked = false; 
                   8230:                     }
                   8231:                 }
                   8232:             }
                   8233:         }
1.537     raeburn  8234:         if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538     raeburn  8235:             allidxlist = form.allidx.value;
                   8236:         }
                   8237:         if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
                   8238:             allidxlist = form.allmapidx.value;
                   8239:         }
                   8240:         if ((allidxlist != '') && (allidxlist != null)) {
                   8241:             var allidxs = allidxlist.split(',');
                   8242:             if (allidxs.length > 1) {
                   8243:                 for (var i=0; i<allidxs.length; i++) {
                   8244:                     if (document.getElementById(param+'_'+allidxs[i])) {
                   8245:                         if (param == 'rpicknum') {
                   8246:                             if (document.getElementById('randompick_'+allidxs[i])) {
                   8247:                                 if (document.getElementById('randompick_'+allidxs[i]).checked) {
                   8248:                                     document.getElementById(param+'_'+allidxs[i]).value = rpick;
                   8249:                                     if (rpick > 0) {
                   8250:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ':&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
                   8251:                                     } else {
                   8252:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   8253:                                     }
                   8254:                                 }
                   8255:                             }
                   8256:                         } else {
1.537     raeburn  8257:                             if (setcheck == 1) {
                   8258:                                 document.getElementById(param+'_'+allidxs[i]).checked = true;
                   8259:                             } else {
                   8260:                                 document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538     raeburn  8261:                                 if (param == 'randompick') {
                   8262:                                     document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   8263:                                 }
1.537     raeburn  8264:                             }
                   8265:                         }
                   8266:                     }
                   8267:                 }
1.538     raeburn  8268:                 if (setcheck == 1) {
                   8269:                     if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   8270:                         var actions = new Array('copy','cut','remove');
                   8271:                         for (var i=0; i<actions.length; i++) {
                   8272:                             var otheractions;
                   8273:                             var otheridxs;
                   8274:                             if (actions[i] === param) {
                   8275:                                 continue;
                   8276:                             } else {
                   8277:                                 if (document.getElementById('all'+actions[i]+'idx')) {
                   8278:                                     otheractions = document.getElementById('all'+actions[i]+'idx').value;
                   8279:                                     otheridxs = otheractions.split(',');
                   8280:                                     if (otheridxs.length > 1) {
                   8281:                                         for (var j=0; j<otheridxs.length; j++) {
                   8282:                                             if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
                   8283:                                                 document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
                   8284:                                             }
1.537     raeburn  8285:                                         }
                   8286:                                     }
                   8287:                                 }
1.538     raeburn  8288:                             }
                   8289:                         } 
                   8290:                     }
                   8291:                 }
                   8292:             }
                   8293:         }
                   8294:     }
                   8295:     return;
                   8296: }
                   8297: 
1.603     raeburn  8298: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611     raeburn  8299:     var canedit = '$canedit';
                   8300:     if (canedit == '') {
                   8301:         alert("$js_lt{'edri'}");
                   8302:         return;
                   8303:     }
1.539     raeburn  8304:     var dosettings;
                   8305:     var doaction;
1.538     raeburn  8306:     var control = document.togglemultsettings;
                   8307:     if (context == 'actions') {
                   8308:         control = document.togglemultactions;
1.539     raeburn  8309:         doaction = 1; 
                   8310:     } else {
                   8311:         dosettings = 1;
1.538     raeburn  8312:     }
1.539     raeburn  8313:     if (control) {
                   8314:         if (control.showmultpick.length) {
                   8315:             for (var i=0; i<control.showmultpick.length; i++) {
                   8316:                 if (control.showmultpick[i].checked) {
                   8317:                     if (control.showmultpick[i].value == 1) {
                   8318:                         if (context == 'settings') {
                   8319:                             dosettings = 0;
                   8320:                         } else {
                   8321:                             doaction = 0;
1.538     raeburn  8322:                         }
                   8323:                     }
                   8324:                 }
1.537     raeburn  8325:             }
                   8326:         }
1.539     raeburn  8327:     }
                   8328:     if (context == 'settings') {
                   8329:         if (dosettings == 1) {
1.538     raeburn  8330:             targetform.changeparms.value=param;
                   8331:             targetform.submit();
                   8332:         }
1.537     raeburn  8333:     }
1.539     raeburn  8334:     if (context == 'actions') {
                   8335:         if (doaction == 1) {
                   8336:             targetform.cmd.value=param+'_'+index;
                   8337:             targetform.folderpath.value=folderpath;
                   8338:             targetform.markcopy.value=idx+':'+param;
                   8339:             targetform.copyfolder.value=folder+'.'+container;
                   8340:             if (param == 'remove') {
1.603     raeburn  8341:                 var doremove = 0;
                   8342:                 if (skip_confirm) {
                   8343:                     if (confirm_removal) {
                   8344:                         if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
                   8345:                             doremove = 1;
                   8346:                         }
                   8347:                     } else {
                   8348:                         doremove = 1;
                   8349:                     }
                   8350:                 } else {
                   8351:                     if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
                   8352:                         doremove = 1;
                   8353:                     }
                   8354:                 }
                   8355:                 if (doremove) {
1.539     raeburn  8356:                     targetform.markcopy.value='';
                   8357:                     targetform.copyfolder.value='';
                   8358:                     targetform.submit();
                   8359:                 }
                   8360:             }
                   8361:             if (param == 'cut') {
1.594     damieng  8362:                 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  8363:                     targetform.submit();
                   8364:                     return;
                   8365:                 }
                   8366:             }
                   8367:             if (param == 'copy') {
                   8368:                 targetform.submit();
                   8369:                 return;
                   8370:             }
                   8371:             targetform.markcopy.value='';
                   8372:             targetform.copyfolder.value='';
                   8373:             targetform.cmd.value='';
                   8374:             targetform.folderpath.value='';
                   8375:             return;
                   8376:         } else {
                   8377:             if (document.getElementById(param+'_'+idx)) {
                   8378:                 item = document.getElementById(param+'_'+idx);
                   8379:                 if (item.type == 'checkbox') {
                   8380:                     if (item.checked) {
                   8381:                         item.checked = false;
                   8382:                     } else {
                   8383:                         item.checked = true;
                   8384:                         singleCheck(item,idx,param);
                   8385:                     }
                   8386:                 }
                   8387:             }
                   8388:         }
                   8389:     }
1.537     raeburn  8390:     return;
                   8391: }
                   8392: 
1.538     raeburn  8393: function singleCheck(caller,idx,action) {
                   8394:     actions = new Array('cut','copy','remove');
                   8395:     if (caller.checked) {
                   8396:         for (var i=0; i<actions.length; i++) {
                   8397:             if (actions[i] != action) {
                   8398:                 if (document.getElementById(actions[i]+'_'+idx)) {
                   8399:                     if (document.getElementById(actions[i]+'_'+idx).checked) {
                   8400:                         document.getElementById(actions[i]+'_'+idx).checked = false;
                   8401:                     }
1.537     raeburn  8402:                 }
                   8403:             }
                   8404:         }
1.478     raeburn  8405:     }
1.537     raeburn  8406:     return;
1.478     raeburn  8407: }
                   8408: 
1.334     muellerd 8409: function unselectInactive(nav) {
1.335     ehlerst  8410: currentNav = document.getElementById(nav);
                   8411: currentLis = currentNav.getElementsByTagName('LI');
                   8412: for (i = 0; i < currentLis.length; i++) {
1.472     raeburn  8413:         if (currentLis[i].className == 'goback') {
                   8414:             currentLis[i].className = 'goback';
                   8415:         } else {
                   8416: 	    if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374     tempelho 8417: 		currentLis[i].className = 'right';
1.472     raeburn  8418: 	    } else {
1.374     tempelho 8419: 		currentLis[i].className = 'i';
1.472     raeburn  8420: 	    }
                   8421:         }
1.335     ehlerst  8422: }
1.332     tempelho 8423: }
                   8424: 
1.334     muellerd 8425: function hideAll(current, nav, data) {
1.335     ehlerst  8426: unselectInactive(nav);
1.570     raeburn  8427: if (current) { 
                   8428:     if (current.className == 'right'){
                   8429:         current.className = 'right active'
                   8430:     } else {
                   8431:         current.className = 'active';
                   8432:     }
1.374     tempelho 8433: }
1.335     ehlerst  8434: currentData = document.getElementById(data);
                   8435: currentDivs = currentData.getElementsByTagName('DIV');
                   8436: for (i = 0; i < currentDivs.length; i++) {
                   8437: 	if(currentDivs[i].className == 'LC_ContentBox'){
1.333     muellerd 8438: 		currentDivs[i].style.display = 'none';
1.330     tempelho 8439: 	}
                   8440: }
1.335     ehlerst  8441: }
1.330     tempelho 8442: 
1.374     tempelho 8443: function openTabs(pageId) {
                   8444: 	tabnav = document.getElementById(pageId).getElementsByTagName('UL');	
1.383     tempelho 8445: 	if(tabnav.length > 2 ){
1.389     tempelho 8446: 		currentNav = document.getElementById(tabnav[1].id);
1.374     tempelho 8447: 		currentLis = currentNav.getElementsByTagName('LI');
                   8448: 		for(i = 0; i< currentLis.length; i++){
                   8449: 			if(currentLis[i].className == 'active') {
1.375     tempelho 8450: 				funcString = currentLis[i].onclick.toString();
                   8451: 				tab = funcString.split('"');
1.420     onken    8452:                                 if(tab.length < 2) {
                   8453:                                    tab = funcString.split("'");
                   8454:                                 }
1.375     tempelho 8455: 				currentData = document.getElementById(tab[1]);
                   8456:         			currentData.style.display = 'block';
1.374     tempelho 8457: 			}	
                   8458: 		}
                   8459: 	}
                   8460: }
                   8461: 
1.334     muellerd 8462: function showPage(current, pageId, nav, data) {
1.570     raeburn  8463:         currstate = current.className;
1.334     muellerd 8464: 	hideAll(current, nav, data);
1.375     tempelho 8465: 	openTabs(pageId);
1.334     muellerd 8466: 	unselectInactive(nav);
1.570     raeburn  8467:         if ((currstate == 'active') || (currstate == 'right active')) {
                   8468:             if (currstate == 'active') {
                   8469: 	        current.className = '';
                   8470:             } else {
                   8471:                 current.className = 'right';
                   8472:             }
                   8473:             activeTab = ''; 
1.656     raeburn  8474:             toggleExternal();
1.570     raeburn  8475:             toggleUpload();
                   8476:             toggleMap();
1.606     raeburn  8477:             toggleCrsRes();
                   8478:             toggleImportCrsres();
1.570     raeburn  8479:             resize_scrollbox('contentscroll','1','0');
                   8480:             return;
                   8481:         } else {
                   8482:             current.className = 'active';
                   8483:         }
1.330     tempelho 8484: 	currentData = document.getElementById(pageId);
                   8485: 	currentData.style.display = 'block';
1.458     raeburn  8486:         activeTab = pageId;
1.656     raeburn  8487:         toggleExternal();
1.501     raeburn  8488:         toggleUpload();
1.503     raeburn  8489:         toggleMap();
1.606     raeburn  8490:         toggleCrsRes();
                   8491:         toggleImportCrsres();
1.433     raeburn  8492:         if (nav == 'mainnav') {
                   8493:             var storedpath = "$docs_folderpath";
1.434     raeburn  8494:             var storedpage = "$main_container_page";
1.433     raeburn  8495:             var reg = new RegExp("^supplemental");
                   8496:             if (pageId == 'mainCourseDocuments') {
1.434     raeburn  8497:                 if (storedpage == 1) {
                   8498:                     document.simpleedit.folderpath.value = '';
                   8499:                     document.uploaddocument.folderpath.value = '';
                   8500:                 } else {
                   8501:                     if (reg.test(storedpath)) {
                   8502:                         document.simpleedit.folderpath.value = '$toplevelmain';
                   8503:                         document.uploaddocument.folderpath.value = '$toplevelmain';
                   8504:                         document.newext.folderpath.value = '$toplevelmain';
                   8505:                     } else {
                   8506:                         document.simpleedit.folderpath.value = storedpath;
                   8507:                         document.uploaddocument.folderpath.value = storedpath;
                   8508:                         document.newext.folderpath.value = storedpath;
                   8509:                     }
1.433     raeburn  8510:                 }
                   8511:             } else {
1.434     raeburn  8512:                 if (reg.test(storedpath)) {
                   8513:                     document.simpleedit.folderpath.value = storedpath;
                   8514:                     document.supuploaddocument.folderpath.value = storedpath;
                   8515:                     document.supnewext.folderpath.value = storedpath;
                   8516:                 } else {
1.433     raeburn  8517:                     document.simpleedit.folderpath.value = '$toplevelsupp';
                   8518:                     document.supuploaddocument.folderpath.value = '$toplevelsupp';
                   8519:                     document.supnewext.folderpath.value = '$toplevelsupp';
                   8520:                 }
                   8521:             }
                   8522:         }
1.485     raeburn  8523:         resize_scrollbox('contentscroll','1','0');
1.330     tempelho 8524: 	return false;
                   8525: }
1.329     droeschl 8526: 
1.472     raeburn  8527: function toContents(jumpto) {
                   8528:     var newurl = '$backtourl';
1.525     raeburn  8529:     if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472     raeburn  8530:         newurl = newurl+'?postdata='+jumpto;
                   8531:     }
                   8532:     location.href=newurl;
                   8533: }
                   8534: 
1.538     raeburn  8535: function togglePick(caller,value) {
                   8536:     var disp = 'none';
                   8537:     if (document.getElementById('multi'+caller)) {
                   8538:         var curr = document.getElementById('multi'+caller).style.display;
                   8539:         if (value == 1) {
                   8540:             disp='block';
                   8541:         }
                   8542:         if (curr == disp) {
                   8543:             return; 
                   8544:         }
                   8545:         document.getElementById('multi'+caller).style.display=disp;
                   8546:         if (value == 1) {
1.594     damieng  8547:             document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>'; 
1.538     raeburn  8548:         } else {
                   8549:             document.getElementById('more'+caller).innerHTML = '';
                   8550:         }
                   8551:         if (caller == 'actions') { 
                   8552:             setClass(value);
                   8553:             setBoxes(value);
                   8554:         }
                   8555:     }
                   8556:     var showButton = multiSettings();
                   8557:     if (showButton != 1) {
                   8558:         showButton = multiActions();
                   8559:     }
                   8560:     if (document.getElementById('multisave')) {
                   8561:         if (showButton == 1) {
                   8562:             document.getElementById('multisave').style.display='block';
                   8563:         } else {
                   8564:             document.getElementById('multisave').style.display='none';
                   8565:         }
                   8566:     }
                   8567:     resize_scrollbox('contentscroll','1','1');
                   8568:     return;
                   8569: }
                   8570: 
                   8571: function toggleCheckUncheck(caller,more) {
                   8572:     if (more == 1) {
1.594     damieng  8573:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538     raeburn  8574:         document.getElementById('allfields'+caller).style.display='block';
                   8575:     } else {
1.594     damieng  8576:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538     raeburn  8577:         document.getElementById('allfields'+caller).style.display='none';
                   8578:     }
                   8579:     resize_scrollbox('contentscroll','1','1');
                   8580: }
                   8581: 
                   8582: function multiSettings() {
                   8583:     var inuse = 0;
                   8584:     var settingsform = document.togglemultsettings;
                   8585:     if (settingsform.showmultpick.length > 1) {
                   8586:         for (var i=0; i<settingsform.showmultpick.length; i++) {
                   8587:             if (settingsform.showmultpick[i].checked) {
                   8588:                 if (settingsform.showmultpick[i].value == 1) {
                   8589:                     inuse = 1;  
                   8590:                 }
                   8591:             }
                   8592:         }
                   8593:     }
                   8594:     return inuse;
                   8595: }
                   8596: 
                   8597: function multiActions() {
                   8598:     var inuse = 0;
                   8599:     var actionsform = document.togglemultactions;
                   8600:     if (actionsform.showmultpick.length > 1) {
                   8601:         for (var i=0; i<actionsform.showmultpick.length; i++) {
                   8602:             if (actionsform.showmultpick[i].checked) {
                   8603:                 if (actionsform.showmultpick[i].value == 1) {
                   8604:                     inuse = 1;
                   8605:                 }
                   8606:             }
                   8607:         }
                   8608:     }
                   8609:     return inuse;
                   8610: } 
                   8611: 
                   8612: function checkSubmits() {
                   8613:     var numchanges = 0;
                   8614:     var form = document.saveactions;
                   8615:     var doactions = multiActions();
1.542     raeburn  8616:     var cutwarnings = 0;
                   8617:     var remwarnings = 0;
1.603     raeburn  8618:     var removalinfo = 0;
1.538     raeburn  8619:     if (doactions == 1) {
                   8620:         var remidxlist = document.cumulativeactions.allremoveidx.value;
                   8621:         if ((remidxlist != '') && (remidxlist != null)) {
                   8622:             var remidxs = remidxlist.split(',');
                   8623:             for (var i=0; i<remidxs.length; i++) {
                   8624:                 if (document.getElementById('remove_'+remidxs[i])) {
                   8625:                     if (document.getElementById('remove_'+remidxs[i]).checked) {
                   8626:                         form.multiremove.value += remidxs[i]+',';
                   8627:                         numchanges ++;
1.542     raeburn  8628:                         if (document.getElementById('skip_remove_'+remidxs[i])) {
                   8629:                             if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
                   8630:                                 remwarnings ++;
                   8631:                             }
                   8632:                         }
1.603     raeburn  8633:                         if (document.getElementById('confirm_removal_'+remidxs[i])) {
                   8634:                             if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
                   8635:                                 removalinfo ++;
                   8636:                             }
                   8637:                         }
1.537     raeburn  8638:                     }
                   8639:                 }
1.538     raeburn  8640:             }
                   8641:         }
                   8642:         var cutidxlist = document.cumulativeactions.allcutidx.value;
                   8643:         if ((cutidxlist != '') && (cutidxlist != null)) {
                   8644:             var cutidxs = cutidxlist.split(',');
                   8645:             for (var i=0; i<cutidxs.length; i++) {
                   8646:                 if (document.getElementById('cut_'+cutidxs[i])) {
                   8647:                     if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
                   8648:                         form.multicut.value += cutidxs[i]+',';
                   8649:                         numchanges ++;
1.542     raeburn  8650:                         if (document.getElementById('skip_cut_'+cutidxs[i])) {
                   8651:                             if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
                   8652:                                 cutwarnings ++;
                   8653:                             }
                   8654:                         }
1.537     raeburn  8655:                     }
                   8656:                 }
                   8657:             }
                   8658:         }
1.538     raeburn  8659:         var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   8660:         if ((copyidxlist != '') && (copyidxlist != null)) {
                   8661:             var copyidxs = copyidxlist.split(',');
                   8662:             for (var i=0; i<copyidxs.length; i++) {
                   8663:                 if (document.getElementById('copy_'+copyidxs[i])) {
                   8664:                     if (document.getElementById('copy_'+copyidxs[i]).checked) {
                   8665:                         form.multicopy.value += copyidxs[i]+',';
                   8666:                         numchanges ++;
                   8667:                     }
                   8668:                 }
                   8669:             }
                   8670:         }
                   8671:         if (numchanges > 0) {
                   8672:             form.multichange.value = numchanges;
                   8673:         }
1.537     raeburn  8674:     }
1.538     raeburn  8675:     var dosettings = multiSettings();
1.543     raeburn  8676:     var haschanges = 0;
1.538     raeburn  8677:     if (dosettings == 1) {
                   8678:         form.allencrypturl.value = '';
                   8679:         form.allhiddenresource.value = '';
1.543     raeburn  8680:         form.changeparms.value = 'all';
                   8681:         var patt=new RegExp(",\$");
1.538     raeburn  8682:         var allidxlist = document.cumulativesettings.allidx.value;
                   8683:         if ((allidxlist != '') && (allidxlist != null)) {
                   8684:             var allidxs = allidxlist.split(',');
                   8685:             if (allidxs.length > 1) {
                   8686:                 for (var i=0; i<allidxs.length; i++) {
                   8687:                     if (document.getElementById('hiddenresource_'+allidxs[i])) {
                   8688:                         if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
                   8689:                             form.allhiddenresource.value += allidxs[i]+',';
                   8690:                         }
                   8691:                     }
                   8692:                     if (document.getElementById('encrypturl_'+allidxs[i])) {
                   8693:                         if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
                   8694:                             form.allencrypturl.value += allidxs[i]+',';
                   8695:                         }
                   8696:                     }
                   8697:                 }
1.543     raeburn  8698:                 form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
                   8699:                 form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537     raeburn  8700:             }
1.538     raeburn  8701:         }
                   8702:         form.allrandompick.value = '';
                   8703:         form.allrandomorder.value = '';
                   8704:         var allmapidxlist = document.cumulativesettings.allmapidx.value;
                   8705:         if ((allmapidxlist != '') && (allmapidxlist != null)) {
                   8706:             var allmapidxs = allmapidxlist.split(',');
                   8707:             for (var i=0; i<allmapidxs.length; i++) {
                   8708:                 var randompick = document.getElementById('randompick_'+allmapidxs[i]);
                   8709:                 var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
                   8710:                 var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
                   8711:                 if ((randompick.checked) && (rpicknum.value != '')) {
                   8712:                     form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
                   8713:                 }
                   8714:                 if (randorder.checked) {
                   8715:                     form.allrandomorder.value += allmapidxs[i]+',';
                   8716:                 }
1.537     raeburn  8717:             }
1.543     raeburn  8718:             form.allrandompick.value = form.allrandompick.value.replace(patt,"");
                   8719:             form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
                   8720:         }
                   8721:         if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
                   8722:             haschanges = 1;
                   8723:         }
                   8724:         if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
                   8725:             haschanges = 1;
                   8726:         }
                   8727:         if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
                   8728:             haschanges = 1;
                   8729:         }
                   8730:         if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
                   8731:             haschanges = 1;
1.537     raeburn  8732:         }
                   8733:     }
1.543     raeburn  8734:     if (doactions == 1) {
1.542     raeburn  8735:         if (numchanges > 0) {
1.603     raeburn  8736:             if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542     raeburn  8737:                 if (remwarnings > 0) {
1.594     damieng  8738:                     if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542     raeburn  8739:                         return false;
                   8740:                     }
                   8741:                 }
1.603     raeburn  8742:                 if (removalinfo > 0) {
                   8743:                     if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
                   8744:                         return false;
                   8745:                     }
                   8746:                 }
1.542     raeburn  8747:                 if (cutwarnings > 0) {
1.594     damieng  8748:                     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  8749:                         return false;
                   8750:                     }
                   8751:                 }
                   8752:             }
                   8753:             form.submit();
                   8754:             return true;
1.543     raeburn  8755:         }
                   8756:     }
                   8757:     if (dosettings == 1) {
                   8758:         if (haschanges == 1) {
1.542     raeburn  8759:             form.submit();
                   8760:             return true;
                   8761:         }
1.543     raeburn  8762:     }
                   8763:     if ((dosettings == 1) && (doactions == 1)) {
1.594     damieng  8764:         alert("$js_lt{'noor'}");
1.543     raeburn  8765:     } else {
                   8766:         if (dosettings == 1) {
1.594     damieng  8767:             alert("$js_lt{'noch'}");
1.543     raeburn  8768:         } else {
1.594     damieng  8769:             alert("$js_lt{'noac'}");
1.543     raeburn  8770:         }
                   8771:     }
1.538     raeburn  8772:     return false;
                   8773: }
                   8774: 
                   8775: function setClass(value) {
                   8776:     var cutclass = 'LC_docs_cut';
                   8777:     var copyclass = 'LC_docs_copy';
                   8778:     var removeclass = 'LC_docs_remove';
                   8779:     var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
                   8780:     var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
                   8781:     var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
                   8782:     var links = document.getElementsByTagName('a');
                   8783:     for (var i=0; i<links.length; i++) {
                   8784:         var classes = links[i].className;
                   8785:         if (cutreg.test(classes)) {
                   8786:             links[i].className = cutclass;
                   8787:             if (value == 1) {
                   8788:                 links[i].className += " LC_menubuttons_link";
                   8789:             }
                   8790:         } else {
                   8791:             if (copyreg.test(classes)) {
                   8792:                 links[i].className = copyclass;
                   8793:                 if (value == 1) {
                   8794:                     links[i].className += " LC_menubuttons_link";
                   8795:                 } 
                   8796:             } else {
                   8797:                 if (removereg.test(classes)) {
                   8798:                     links[i].className = removeclass;
                   8799:                     if (value == 1) {
                   8800:                         links[i].className += " LC_menubuttons_link";
                   8801:                     }
                   8802:                 }
                   8803:             }
                   8804:         }
                   8805:     }
                   8806:     return;
1.537     raeburn  8807: }
                   8808: 
1.538     raeburn  8809: function setBoxes(value) {
                   8810:     var remidxlist = document.cumulativeactions.allremoveidx.value;
                   8811:     if ((remidxlist != '') && (remidxlist != null)) {
                   8812:         var remidxs = remidxlist.split(',');
                   8813:         for (var i=0; i<remidxs.length; i++) {
                   8814:             if (document.getElementById('remove_'+remidxs[i])) {
                   8815:                 var item = document.getElementById('remove_'+remidxs[i]);
                   8816:                 if (value == 1) {
                   8817:                     item.className = 'LC_docs_remove';
                   8818:                 } else {
                   8819:                     item.className = 'LC_hidden';
                   8820:                 }
                   8821:             }
                   8822:         }
                   8823:     }
                   8824:     var cutidxlist = document.cumulativeactions.allcutidx.value;
                   8825:     if ((cutidxlist != '') && (cutidxlist != null)) {
                   8826:         var cutidxs = cutidxlist.split(',');
                   8827:         for (var i=0; i<cutidxs.length; i++) {
                   8828:             if (document.getElementById('cut_'+cutidxs[i])) {
                   8829:                 var item = document.getElementById('cut_'+cutidxs[i]);
                   8830:                 if (value == 1) {
                   8831:                     item.className = 'LC_docs_cut';
                   8832:                 } else {
                   8833:                     item.className = 'LC_hidden';
                   8834:                 }
                   8835:             }
1.537     raeburn  8836:         }
                   8837:     }
1.538     raeburn  8838:     var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   8839:     if ((copyidxlist != '') && (copyidxlist != null)) {
                   8840:         var copyidxs = copyidxlist.split(',');
                   8841:         for (var i=0; i<copyidxs.length; i++) {
                   8842:             if (document.getElementById('copy_'+copyidxs[i])) {
                   8843:                 var item = document.getElementById('copy_'+copyidxs[i]);
                   8844:                 if (value == 1) {
                   8845:                     item.className = 'LC_docs_copy';
                   8846:                 } else {
                   8847:                     item.className = 'LC_hidden';
                   8848:                 }
                   8849:             }
1.537     raeburn  8850:         }
                   8851:     }
                   8852:     return;
                   8853: }
                   8854: 
1.606     raeburn  8855: function validImportCrsRes() {
                   8856:     var path =  document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
                   8857:     var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
                   8858:     if ((fname == '') || (fname == null)) {
                   8859:         alert("$js_lt{'nofi'}");
                   8860:         return false;
                   8861:     }
                   8862:     var url = '/res/$coursedom/$coursenum/';
                   8863:     if (path && path != '/') {
                   8864:         url += path+'/';
                   8865:     }
                   8866:     if (fname != '') {
                   8867:         url += fname;
                   8868:     }
                   8869:     var title = document.crsresimportform.crsrestitle.value;
1.676     raeburn  8870:     document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606     raeburn  8871:     return true;
                   8872: }
                   8873: 
                   8874: function validateNewRes(caller) {
                   8875:     if (caller == 'single') {
                   8876:         var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value; 
                   8877:         var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
                   8878:         var resname = document.courseresform.newresourcename.value;
                   8879:     }
                   8880: }
                   8881: 
1.611     raeburn  8882: ENDSCRIPT
1.329     droeschl 8883: }
1.457     raeburn  8884: 
1.483     raeburn  8885: sub history_tab_js {
                   8886:     return <<"ENDHIST";
                   8887: function toggleHistoryDisp(choice) {
                   8888:     document.docslogform.docslog.value = choice;
                   8889:     document.docslogform.submit();
                   8890:     return;
                   8891: }
                   8892: 
                   8893: ENDHIST
                   8894: }
                   8895: 
1.484     raeburn  8896: sub inject_data_js {
                   8897:     return <<ENDINJECT;
                   8898: 
                   8899: function injectData(current, hiddenField, name, value) {
                   8900:         currentElement = document.getElementById(hiddenField);
                   8901:         currentElement.name = name;
                   8902:         currentElement.value = value;
                   8903:         current.submit();
                   8904: }
                   8905: 
                   8906: ENDINJECT
                   8907: }
                   8908: 
                   8909: sub dump_switchserver_js {
                   8910:     my @hosts = @_;
1.594     damieng  8911:     my %js_lt = &Apache::lonlocal::texthash(
1.574     raeburn  8912:         dump => 'Copying content to Authoring Space requires switching server.',
1.484     raeburn  8913:         swit => 'Switch server?',
1.594     damieng  8914:     );
                   8915:     my %html_js_lt = &Apache::lonlocal::texthash(
                   8916:         swit => 'Switch server?',
1.568     raeburn  8917:         duco => 'Copying Content to Authoring Space',
1.484     raeburn  8918:         yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
                   8919:         chos => 'Choose server',
                   8920:     );
1.594     damieng  8921:     &js_escape(\%js_lt);
                   8922:     &html_escape(\%html_js_lt);
                   8923:     &js_escape(\%html_js_lt);
1.484     raeburn  8924:     my $role = $env{'request.role'};
                   8925:     my $js = <<"ENDSWJS";
                   8926: <script type="text/javascript">
                   8927: function write_switchserver() {
                   8928:     var server;
                   8929:     if (document.setserver.posshosts.length > 0) {
                   8930:         for (var i=0; i<document.setserver.posshosts.length; i++) {
                   8931:             if (document.setserver.posshosts[i].checked) {
                   8932:                 server = document.setserver.posshosts[i].value;
                   8933:             }
                   8934:        }
                   8935:        opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
                   8936:     }
                   8937:     window.close();
                   8938: }
                   8939: </script>
                   8940: 
                   8941: ENDSWJS
                   8942: 
                   8943:     my $startpage = &Apache::loncommon::start_page('Choose server',$js,
                   8944:                                                    {'only_body' => 1,
                   8945:                                                     'js_ready'  => 1,});
                   8946:     my $endpage = &Apache::loncommon::end_page({'js_ready'  => 1});
                   8947: 
                   8948:     my $hostpicker;
                   8949:     my $count = 0;
                   8950:     foreach my $host (sort(@hosts)) {
                   8951:         my $checked;
                   8952:         if ($count == 0) {
                   8953:             $checked = ' checked="checked"';
                   8954:         }
                   8955:         $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
                   8956:                        $host.'"'.$checked.' />'.$host.'</label>&nbsp;&nbsp;';
                   8957:         $count++;
                   8958:     }
                   8959:     
                   8960:     return <<"ENDSWITCHJS";
                   8961: 
                   8962: function dump_needs_switchserver(url) {
                   8963:     if (url!='' && url!= null) {
1.594     damieng  8964:         if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484     raeburn  8965:             go(url);
                   8966:         }
                   8967:     }
                   8968:     return;
                   8969: }
                   8970: 
                   8971: function choose_switchserver_window() {
                   8972:     newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
                   8973:     newWindow.document.open();
                   8974:     newWindow.document.writeln('$startpage');
1.594     damieng  8975:     newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
                   8976:        '<p>$html_js_lt{'yone'}<\\/p>\\n'+
                   8977:        '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484     raeburn  8978:        '<form name="setserver" method="post" action="" \\/>\\n'+
                   8979:        '$hostpicker\\n'+
                   8980:        '<br \\/><br \\/>\\n'+
1.594     damieng  8981:        '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484     raeburn  8982:        'onclick="write_switchserver();" \\/>\\n'+
                   8983:        '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
                   8984:     newWindow.document.writeln('$endpage');
                   8985:     newWindow.document.close();
                   8986:     newWindow.focus();
                   8987: }
                   8988: 
                   8989: ENDSWITCHJS
                   8990: }
                   8991: 
                   8992: sub makedocslogform {
                   8993:     my ($formelems,$docslog) = @_;
                   8994:     return <<"LOGSFORM";
                   8995:  <form action="/adm/coursedocs" method="post" name="docslogform">
                   8996:    <input type="hidden" name="docslog" value="$docslog" />
                   8997:    $formelems
                   8998:  </form>
                   8999: LOGSFORM
                   9000: }
                   9001: 
                   9002: sub makesimpleeditform {
                   9003:     my ($formelems) = @_;
                   9004:     return <<"SIMPFORM";
                   9005:  <form name="simpleedit" method="post" action="/adm/coursedocs">
                   9006:    <input type="hidden" name="importdetail" value="" />
                   9007:    $formelems
                   9008:  </form>
                   9009: SIMPFORM
                   9010: }
                   9011: 
1.606     raeburn  9012: sub makenewproblem {
                   9013:     my ($r,$coursedom,$coursenum) = @_;
                   9014: # Creating a new problem
                   9015:     my ($redirect,$error);
                   9016:     if ($env{'form.authorrole'}) {
                   9017:         my ($newsubdir,$filename);
                   9018:         if ($env{'form.newsubdir'}) {
                   9019:             if ($env{'form.newsubdirname'} ne '') {
                   9020:                 $newsubdir = $env{'form.newsubdirname'};
1.654     raeburn  9021:             }
1.606     raeburn  9022:         }
                   9023:         if ($env{'form.newresourcename'}) {
                   9024:             $filename = $env{'form.newresourcename'};
                   9025:             $filename =~ s/\.(\d+)(\.\w+)$/$2/;
                   9026:             $filename =~ s/`//g;
                   9027:             $filename =~ s{/\.\./}{_}g;
                   9028:             $filename =~ s/\.+/./g;
                   9029:             $filename =~ s{/+}{_}g;
                   9030:             if ($filename ne '') {
                   9031:                 my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
                   9032:                 if (($ext) && ($ext ne '.problem')) {
                   9033:                     $filename = $name.'.problem';
                   9034:                 } elsif ($ext eq '') {
                   9035:                     $filename .= '.problem';
                   9036:                 }
                   9037:                 my $docroot = $r->dir_config('lonDocRoot');
                   9038:                 my @ids=&Apache::lonnet::current_machine_ids();
                   9039:                 if ($env{'form.authorrole'} eq 'author') {
                   9040:                     if ($env{'user.author'}) {
                   9041:                         if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
                   9042:                             my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
                   9043:                             my $path = $docroot.$url;
                   9044:                             my $subdir = $env{'form.authorpath'};
                   9045:                             $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   9046:                         }
                   9047:                     }
                   9048:                 } elsif ($env{'form.authorrole'} eq 'course') {
                   9049:                     my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   9050:                     if ($chome && grep(/^\Q$chome\E$/,@ids)) {
                   9051:                         my $url = "/priv/$coursedom/$coursenum";
                   9052:                         my $path=$docroot.$url;
                   9053:                         my $subdir = $env{'form.authorpath'};
                   9054:                         $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   9055:                         if ($redirect) {
                   9056:                             my $rightsfile = 'default.rights';
                   9057:                             my $sourcerights = "$path/$rightsfile";
                   9058:                             my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
                   9059:                             my $now = time;
                   9060:                             if (!-e $sourcerights) {
                   9061:                                 my $cid = $coursedom.'_'.$coursenum;
                   9062:                                 if (open(my $fh,">$sourcerights")) {
                   9063:                                     print $fh <<END;
                   9064: <accessrule effect="deny" realm="" type="course" role="" />
                   9065: <accessrule effect="allow" realm="$cid" type="course" role="" />
                   9066: END
                   9067:                                     close($fh);
                   9068:                                 }
                   9069:                             }
                   9070:                             if (!-e "$sourcerights.meta") {
                   9071:                                 if (open(my $fh,">$sourcerights.meta")) {
                   9072:                                     my $author=$env{'environment.firstname'}.' '.
                   9073:                                                $env{'environment.middlename'}.' '.
                   9074:                                                $env{'environment.lastname'}.' '.
                   9075:                                                $env{'environment.generation'};
                   9076:                                     $author =~ s/\s+$//;
                   9077:                                     print $fh <<"END";
                   9078: 
                   9079: <abstract></abstract>
                   9080: <author>$author</author>
                   9081: <authorspace>$coursenum:$coursedom</authorspace>
                   9082: <copyright>private</copyright>
                   9083: <creationdate>$now</creationdate>
                   9084: <customdistributionfile></customdistributionfile>
                   9085: <dependencies></dependencies>
                   9086: <domain>$coursedom</domain>
                   9087: <highestgradelevel>0</highestgradelevel>
                   9088: <keywords></keywords>
                   9089: <language>notset </language>
                   9090: <lastrevisiondate>$now</lastrevisiondate>
                   9091: <lowestgradelevel>0</lowestgradelevel>
                   9092: <mime>rights</mime>
                   9093: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
                   9094: <notes></notes>
                   9095: <obsolete></obsolete>
                   9096: <obsoletereplacement></obsoletereplacement>
                   9097: <owner>$coursenum:$coursedom</owner>
                   9098: <rule>deny:::course,allow:$cid::course</rule>
                   9099: <sourceavail></sourceavail>
                   9100: <standards></standards>
                   9101: <subject></subject>
                   9102: <title></title>
                   9103: END
1.654     raeburn  9104:                                     close($fh);
                   9105:                                 }
                   9106:                             }
                   9107:                             if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
                   9108:                                 if (!-e "$docroot/res/$coursedom") {
                   9109:                                     mkdir("$docroot/res/$coursedom",0755);
1.606     raeburn  9110:                                 }
1.654     raeburn  9111:                                 if (!-e "$docroot/res/$coursedom/$coursenum") {
                   9112:                                     mkdir("$docroot/res/$coursedom/$coursenum",0755);
                   9113:                                 }
                   9114:                                 if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
                   9115:                                     my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   9116:                                     my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606     raeburn  9117:                                 }
                   9118:                             }
1.654     raeburn  9119:                             my $source = $docroot.$redirect;
                   9120:                             if (!-e "$source.meta") {
                   9121:                                 my $cid = $coursedom.'_'.$coursenum;
                   9122:                                 my $now = time;
                   9123:                                 if (open(my $fh,">$source.meta")) {
                   9124:                                     my $author=$env{'environment.firstname'}.' '.
                   9125:                                                $env{'environment.middlename'}.' '.
                   9126:                                                $env{'environment.lastname'}.' '.
                   9127:                                                $env{'environment.generation'};
                   9128:                                     $author =~ s/\s+$//;
                   9129:                                     my $title = $env{'form.newresourcetitle'};
                   9130:                                     $title =~ s/^\s+|\s+$//g;
                   9131:                                     print $fh <<END;
1.606     raeburn  9132: 
                   9133: <abstract></abstract>
                   9134: <author>$author</author>
                   9135: <authorspace>$coursenum:$coursedom</authorspace>
                   9136: <copyright>custom</copyright>
                   9137: <creationdate>$now</creationdate>
                   9138: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
                   9139: <dependencies></dependencies>
                   9140: <domain>$coursedom</domain>
                   9141: <highestgradelevel>0</highestgradelevel>
                   9142: <keywords></keywords>
                   9143: <language>notset </language>
                   9144: <lastrevisiondate>$now</lastrevisiondate>
                   9145: <lowestgradelevel>0</lowestgradelevel>
                   9146: <mime>problem</mime>
                   9147: <modifyinguser>$coursenum:$coursedom</modifyinguser>
                   9148: <notes></notes>
                   9149: <obsolete></obsolete>
                   9150: <obsoletereplacement></obsoletereplacement>
                   9151: <owner>$coursenum:$coursedom</owner>
                   9152: <sourceavail></sourceavail>
                   9153: <standards></standards>
                   9154: <subject></subject>
                   9155: <title>$title</title>
                   9156: END
1.654     raeburn  9157:                                     close($fh);
1.606     raeburn  9158:                                 }
                   9159:                             }
                   9160:                         }
                   9161:                     }
                   9162:                 } else {
                   9163:                     my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
                   9164:                     my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
                   9165:                     if (grep(/^\Q$rolehome\E$/,@ids)) {
                   9166:                         my $now = time;
                   9167:                         if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
                   9168:                             my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
                   9169:                             if (($start <= $now) && (($end == 0) || ($end >= $now))) { 
                   9170:                                 my $url = "/priv/$audom/$auname";  
                   9171:                                 my $path = $r->dir_config('lonDocRoot').$url;
                   9172:                                 my $subdir = $env{'form.authorpath'};
                   9173:                                 $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   9174:                             }
                   9175:                         }
                   9176:                     }
                   9177:                 }
                   9178:             }
                   9179:         }
                   9180:     }
                   9181:     return ($redirect,$error);
                   9182: }
                   9183: 
                   9184: sub finishnewprob {
1.654     raeburn  9185:     my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607     raeburn  9186:     unless (-d $path) {
                   9187:         unless (mkdir($path,02770)) {
                   9188:             return;
                   9189:         }
                   9190:     }
1.606     raeburn  9191:     my $redirect;
                   9192:     if ($subdir ne '/') {
                   9193:         $subdir = &cleandir($subdir);
                   9194:         if (($subdir ne '') && (-d "$path/$subdir")) {
                   9195:             $path .= "/$subdir";
                   9196:             $url .= "/$subdir";
                   9197:         }
                   9198:     }
                   9199:     my $dest;
                   9200:     if ($newsubdir ne '') {
                   9201:         $newsubdir = &cleandir($newsubdir);
                   9202:     }
                   9203:     if ($newsubdir ne '') {
                   9204:         if (-d "$path/$newsubdir") {
                   9205:             $dest = "$path/$newsubdir/$filename";
                   9206:         } else {
                   9207:             my $dirok;
                   9208:             unless (-e "$path/$newsubdir") {
                   9209:                 if (mkdir("$path/$newsubdir",02770)) {
                   9210:                     if (chmod(02770,"$path/$newsubdir")) {
                   9211:                         $dirok = 1;
                   9212:                     }
                   9213:                 }
                   9214:             }
                   9215:             if ($dirok) {
                   9216:                 $dest = "$path/$newsubdir/$filename";
                   9217:             }
                   9218:         }
                   9219:         if (($dest ne '') && (!-e $dest)) {
                   9220:             $redirect = "$url/$newsubdir/$filename";
                   9221:         }
                   9222:     } else {
                   9223:         $dest = "$path/$filename";
                   9224:         if (($dest ne '') && (!-e $dest)) {
                   9225:             $redirect = "$url/$filename";
                   9226:         }
                   9227:     }
1.654     raeburn  9228:     if ((!-e $dest) && ($context ne 'upload')) {
                   9229:         my $template = $env{'form.template'};
                   9230:         my $copyfrom;
                   9231:         if ($template ne '') {
                   9232:             my %templates;
                   9233:             my @files = &Apache::lonhomework::get_template_list('problem');
                   9234:             foreach my $poss (@files) {
                   9235:                 if (ref($poss) eq 'ARRAY') {
                   9236:                     if ($template eq $poss->[0]) {
                   9237:                         $templates{$template} = 1;
                   9238:                         last;
                   9239:                     }
                   9240:                 }
                   9241:             }
                   9242:             if ($templates{$template}) {
                   9243:                 $copyfrom = $template;
                   9244:             }
                   9245:         }
                   9246:         if ($filename =~ /\.problem$/) {
                   9247:             unless ($copyfrom) {
                   9248:                 $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
                   9249:             }
                   9250:             &File::Copy::copy($copyfrom,$dest);
                   9251:         }
                   9252:     }
1.606     raeburn  9253:     return $redirect;
                   9254: }
                   9255: 
                   9256: sub cleandir {
                   9257:     my ($dir) = @_;
                   9258:     $dir =~ s/^\s+//;
                   9259:     $dir =~ s/\s+$//;
                   9260:     $dir =~ s/\.+//g;
                   9261:     $dir =~ s/[\#\?&%\":]//g;
                   9262:     return $dir;
                   9263: }
                   9264: 
1.329     droeschl 9265: 1;
                   9266: __END__
                   9267: 
                   9268: 
                   9269: =head1 NAME
                   9270: 
                   9271: Apache::londocs.pm
                   9272: 
                   9273: =head1 SYNOPSIS
                   9274: 
                   9275: This is part of the LearningOnline Network with CAPA project
                   9276: described at http://www.lon-capa.org.
                   9277: 
                   9278: =head1 SUBROUTINES
                   9279: 
                   9280: =over
                   9281: 
                   9282: =item %help=()
                   9283: 
                   9284: Available help topics
                   9285: 
                   9286: =item mapread()
                   9287: 
1.344     bisitz   9288: Mapread read maps into LONCAPA::map:: global arrays
1.329     droeschl 9289: @order and @resources, determines status
                   9290: sets @order - pointer to resources in right order
                   9291: sets @resources - array with the resources with correct idx
                   9292: 
                   9293: =item authorhosts()
                   9294: 
                   9295: Return hash with valid author names
                   9296: 
                   9297: =item clean()
                   9298: 
                   9299: =item dumpcourse()
                   9300: 
                   9301:     Actually dump course
                   9302: 
                   9303: =item group_import()
                   9304: 
                   9305:     Imports the given (name, url) resources into the course
                   9306:     coursenum, coursedom, and folder must precede the list
                   9307: 
                   9308: =item breadcrumbs()
                   9309: 
                   9310: =item log_docs()
                   9311: 
                   9312: =item docs_change_log()
                   9313: 
                   9314: =item update_paste_buffer()
                   9315: 
                   9316: =item print_paste_buffer()
                   9317: 
                   9318: =item do_paste_from_buffer()
                   9319: 
1.538     raeburn  9320: =item do_buffer_empty() 
                   9321: 
                   9322: =item clear_from_buffer()
                   9323: 
1.492     raeburn  9324: =item get_newmap_url()
                   9325: 
                   9326: =item dbcopy()
                   9327: 
                   9328: =item uniqueness_check()
                   9329: 
                   9330: =item contained_map_check()
                   9331: 
                   9332: =item url_paste_fixups()
                   9333: 
                   9334: =item apply_fixups()
                   9335: 
                   9336: =item copy_dependencies()
                   9337: 
1.329     droeschl 9338: =item update_parameter()
                   9339: 
                   9340: =item handle_edit_cmd()
                   9341: 
                   9342: =item editor()
                   9343: 
                   9344: =item process_file_upload()
                   9345: 
                   9346: =item process_secondary_uploads()
                   9347: 
                   9348: =item is_supplemental_title()
                   9349: 
                   9350: =item entryline()
                   9351: 
                   9352: =item tiehash()
                   9353: 
                   9354: =item untiehash()
                   9355: 
                   9356: =item checkonthis()
                   9357: 
                   9358: check on this
                   9359: 
                   9360: =item verifycontent()
                   9361: 
                   9362: Verify Content
                   9363: 
1.636     raeburn  9364: =item devalidateversioncache() 
                   9365: 
                   9366: =item checkversions()
1.329     droeschl 9367: 
                   9368: Check Versions
                   9369: 
                   9370: =item mark_hash_old()
                   9371: 
                   9372: =item is_hash_old()
                   9373: 
                   9374: =item changewarning()
                   9375: 
                   9376: =item init_breadcrumbs()
                   9377: 
                   9378: Breadcrumbs for special functions
                   9379: 
1.484     raeburn  9380: =item create_list_elements()
                   9381: 
                   9382: =item create_form_ul()
                   9383: 
                   9384: =item startContentScreen() 
                   9385: 
                   9386: =item endContentScreen()
                   9387: 
                   9388: =item supplemental_base()
                   9389: 
                   9390: =item embedded_form_elems()
                   9391: 
                   9392: =item embedded_destination()
                   9393: 
                   9394: =item return_to_editor()
                   9395: 
                   9396: =item decompression_info()
                   9397: 
                   9398: =item decompression_phase_one()
                   9399: 
                   9400: =item decompression_phase_two()
                   9401: 
                   9402: =item remove_archive()
                   9403: 
                   9404: =item generate_admin_menu()
                   9405: 
                   9406: =item generate_edit_table()
                   9407: 
                   9408: =item editing_js()
                   9409: 
                   9410: =item history_tab_js()
                   9411: 
                   9412: =item inject_data_js()
                   9413: 
                   9414: =item dump_switchserver_js()
                   9415: 
1.485     raeburn  9416: =item resize_scrollbox_js()
1.484     raeburn  9417: 
                   9418: =item makedocslogform()
                   9419: 
1.485     raeburn  9420: =item makesimpleeditform()
                   9421: 
1.329     droeschl 9422: =back
                   9423: 
                   9424: =cut

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