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

1.329     droeschl    1: # The LearningOnline Network
                      2: # Documents
                      3: #
1.700   ! raeburn     4: # $Id: londocs.pm,v 1.699 2023/05/22 21:10:55 raeburn Exp $
1.329     droeschl    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: package Apache::londocs;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common :http);
                     33: use Apache::imsexport;
                     34: use Apache::lonnet;
                     35: use Apache::loncommon;
1.383     tempelho   36: use Apache::lonhtmlcommon;
1.329     droeschl   37: use LONCAPA::map();
                     38: use Apache::lonratedt();
                     39: use Apache::lonxml;
                     40: use Apache::lonclonecourse;
                     41: use Apache::lonnavmaps;
1.472     raeburn    42: use Apache::lonnavdisplay();
1.510     raeburn    43: use Apache::lonextresedit();
1.567     raeburn    44: use Apache::lontemplate();
                     45: use Apache::lonsimplepage();
1.606     raeburn    46: use Apache::lonhomework();
                     47: use Apache::lonpublisher();
1.651     raeburn    48: use Apache::loncourserespicker();
1.329     droeschl   49: use HTML::Entities;
1.488     raeburn    50: use HTML::TokeParser;
1.329     droeschl   51: use GDBM_File;
1.578     raeburn    52: use File::MMagic;
1.606     raeburn    53: use File::Copy;
1.329     droeschl   54: use Apache::lonlocal;
                     55: use Cwd;
1.643     raeburn    56: use UUID::Tiny ':std';
1.329     droeschl   57: use LONCAPA qw(:DEFAULT :match);
                     58: 
                     59: my $iconpath;
                     60: 
                     61: my %hash;
                     62: 
                     63: my $hashtied;
                     64: my %alreadyseen=();
                     65: 
                     66: my $hadchanges;
1.557     raeburn    67: my $suppchanges;
1.329     droeschl   68: 
                     69: 
                     70: my %help=();
                     71: 
                     72: 
                     73: sub mapread {
                     74:     my ($coursenum,$coursedom,$map)=@_;
                     75:     return
                     76:       &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                     77: 			     $map);
                     78: }
                     79: 
                     80: sub storemap {
1.492     raeburn    81:     my ($coursenum,$coursedom,$map,$contentchg)=@_;
                     82:     my $report;
                     83:     if (($contentchg) && ($map =~ /^default/)) {
                     84:        $report = 1;
                     85:     }
1.329     droeschl   86:     my ($outtext,$errtext)=
                     87:       &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492     raeburn    88: 			      $map,1,$report);
1.329     droeschl   89:     if ($errtext) { return ($errtext,2); }
1.364     bisitz     90: 
1.557     raeburn    91:     if ($map =~ /^default/) {
                     92:         $hadchanges=1;
1.682     raeburn    93:     } elsif ($contentchg) {
1.557     raeburn    94:         $suppchanges=1;
                     95:     }
1.329     droeschl   96:     return ($errtext,0);
                     97: }
                     98: 
                     99: 
                    100: 
                    101: sub authorhosts {
                    102:     my %outhash=();
                    103:     my $home=0;
                    104:     my $other=0;
                    105:     foreach my $key (keys(%env)) {
                    106: 	if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
                    107: 	    my $role=$1;
                    108: 	    my $realm=$2;
                    109: 	    my ($start,$end)=split(/\./,$env{$key});
                    110: 	    if (($start) && ($start>time)) { next; }
                    111: 	    if (($end) && (time>$end)) { next; }
                    112: 	    my ($ca,$cd);
                    113: 	    if ($1 eq 'au') {
                    114: 		$ca=$env{'user.name'};
                    115: 		$cd=$env{'user.domain'};
                    116: 	    } else {
                    117: 		($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
                    118: 	    }
                    119: 	    my $allowed=0;
                    120: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
                    121: 	    my @ids=&Apache::lonnet::current_machine_ids();
1.484     raeburn   122: 	    foreach my $id (@ids) {
                    123:                 if ($id eq $myhome) {
                    124:                     $allowed=1;
                    125:                     last;
                    126:                 }
                    127:             }
1.329     droeschl  128: 	    if ($allowed) {
                    129: 		$home++;
1.484     raeburn   130: 		$outhash{'home_'.$ca.':'.$cd}=1;
1.329     droeschl  131: 	    } else {
1.484     raeburn   132: 		$outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329     droeschl  133: 		$other++;
                    134: 	    }
                    135: 	}
                    136:     }
                    137:     return ($home,$other,%outhash);
                    138: }
                    139: 
                    140: 
                    141: sub clean {
                    142:     my ($title)=@_;
                    143:     $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344     bisitz    144:     return $title;
1.329     droeschl  145: }
                    146: 
1.617     raeburn   147: sub default_folderpath {
                    148:     my ($coursenum,$coursedom,$navmapref) = @_;
                    149:     return unless ($coursenum && $coursedom && ref($navmapref));
                    150: # Check if entire course is hidden and/or encrypted
                    151:     my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
                    152:     my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
                    153:     unless (ref($$navmapref)) {
                    154:         $$navmapref = Apache::lonnavmaps::navmap->new();
                    155:     }
                    156:     if (ref($$navmapref)) {
                    157:         if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
                    158:             my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
                    159:             my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
                    160:             unless (@resources) {
                    161:                 $hiddenmap = 1;
                    162:                 unless ($env{'request.role.adv'}) {
                    163:                     $hiddentop = 1;
                    164:                     if ($env{'form.folder'}) {
                    165:                         undef($env{'form.folder'});
                    166:                     }
                    167:                 }
                    168:             }
                    169:         }
                    170:         if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
                    171:             $encryptmap = 1;
                    172:         }
                    173:     }
                    174:     unless ($hiddentop) {
                    175:         $folderpath='default&'.&escape(&mt('Main Content')).
                    176:                     '::'.$hiddenmap.':'.$encryptmap.'::';
                    177:     }
                    178:     if (wantarray) {
                    179:         return ($folderpath,$hiddentop);
                    180:     } else {
                    181:         return $folderpath;
                    182:     }
                    183: }
1.329     droeschl  184: 
1.685     raeburn   185: sub validate_supppath {
                    186:     my ($coursenum,$coursedom) = @_;
                    187:     my $backto;
1.677     raeburn   188:     if ($env{'form.supppath'} ne '') {
                    189:         my @items = split(/\&/,$env{'form.supppath'});
1.685     raeburn   190:         my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.677     raeburn   191:         for (my $i=0; $i<@items; $i++) {
                    192:             my $odd = $i%2;
                    193:             if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
                    194:                 $badpath = 1;
1.685     raeburn   195:                 last;
                    196:             } elsif ($odd) {
                    197:                 my $suffix;
                    198:                 my $idx = $i-1;
                    199:                 if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
                    200:                     $backto .= '&'.$1;
                    201:                 } elsif ($items[$idx] eq 'supplemental') {
                    202:                     $backto .= '&'.$items[$i];
                    203:                 } else {
                    204:                     $backto .= '&'.$items[$i];
                    205:                     my $is_hidden;
                    206:                     unless ($got_supp) {
1.688     raeburn   207:                         my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn   208:                         if (ref($supplemental) eq 'HASH') {
                    209:                             if (ref($supplemental->{'hidden'}) eq 'HASH') {
                    210:                                 %supphidden = %{$supplemental->{'hidden'}};
                    211:                             }
                    212:                             if (ref($supplemental->{'ids'}) eq 'HASH') {
                    213:                                 %suppids = %{$supplemental->{'ids'}};
                    214:                             }
                    215:                         }
                    216:                         $got_supp = 1;
                    217:                     }
                    218:                     if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
                    219:                         my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
                    220:                         if ($supphidden{$mapid}) {
                    221:                             $is_hidden = 1;
                    222:                         }
                    223:                     }
                    224:                     $suffix = '::'.$is_hidden.':::';
                    225:                 }
                    226:                 $supppath .= '&'.$items[$i].$suffix;
                    227:             } else {
                    228:                 $supppath .= '&'.$items[$i];
                    229:                 $backto .= '&'.$items[$i];
1.677     raeburn   230:             }
                    231:         }
                    232:         if ($badpath) {
                    233:             delete($env{'form.supppath'});
1.685     raeburn   234:         } else {
                    235:             $supppath =~ s/^\&//;
                    236:             $backto =~ s/^\&//;
                    237:             $env{'form.supppath'} = $supppath;
1.677     raeburn   238:         }
                    239:     }
1.685     raeburn   240:     return $backto;
1.677     raeburn   241: }
                    242: 
1.329     droeschl  243: sub dumpcourse {
                    244:     my ($r) = @_;
1.408     raeburn   245:     my $crstype = &Apache::loncommon::course_type();
1.567     raeburn   246:     my ($starthash,$js);
                    247:     unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    248:         $js = <<"ENDJS";
                    249: <script type="text/javascript">
                    250: // <![CDATA[
                    251: 
                    252: function hide_searching() {
                    253:     if (document.getElementById('searching')) {
                    254:         document.getElementById('searching').style.display = 'none';
                    255:     }
                    256:     return;
                    257: }
                    258: 
                    259: // ]]>
                    260: </script>
                    261: ENDJS
                    262:         $starthash = {
                    263:                          add_entries => {'onload' => "hide_searching();"},
                    264:                      };
                    265:     }
1.568     raeburn   266:     $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
                    267:               &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484     raeburn   268:     $r->print(&startContentScreen('tools'));
1.329     droeschl  269:     my ($home,$other,%outhash)=&authorhosts();
1.484     raeburn   270:     unless ($home) {
                    271:         $r->print(&endContentScreen());
                    272:         return '';
                    273:     }
1.329     droeschl  274:     my $origcrsid=$env{'request.course.id'};
                    275:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    276:     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    277: # Do the dumping
1.484     raeburn   278: 	unless ($outhash{'home_'.$env{'form.authorspace'}}) {
                    279:             $r->print(&endContentScreen());
                    280:             return '';
                    281:         }
1.531     raeburn   282: 	my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329     droeschl  283: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
                    284: 	my $title=$env{'form.authorfolder'};
                    285: 	$title=&clean($title);
1.567     raeburn   286:         my ($navmap,$errormsg) =
                    287:             &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
                    288:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    289:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    290:         my (%maps,%resources,%titles);
                    291:         if (!ref($navmap)) {
                    292:             $r->print($errormsg.
                    293:                       &endContentScreen());
                    294:             return '';
                    295:         } else {
                    296:             &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
                    297:                                                                    'dumpdocs',$cdom,$cnum);
1.329     droeschl  298: 	}
1.567     raeburn   299:         my @todump = &Apache::loncommon::get_env_multiple('form.archive');
                    300:         my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
                    301:             %newcontent,%has_simpleprobs);
                    302:         foreach my $item (sort {$a <=> $b} (@todump)) {
                    303:             my $name = $env{'form.namefor_'.$item};
                    304:             if ($resources{$item}) {
                    305:                 my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
                    306:                 if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
                    307:                     $tocopy{$1} = $name;
                    308:                     $display{$item} = $1;
                    309:                     $lookup{$1} = $item; 
                    310:                 } elsif ($res eq 'lib/templates/simpleproblem.problem') {
                    311:                     $simpleproblems{$item} = {
                    312:                                                 symb => $resources{$item},
                    313:                                                 name => $name,
                    314:                                              };
                    315:                     $display{$item} = 'simpleproblem_'.$name;
                    316:                     if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
                    317:                         $has_simpleprobs{$1}{$id} = $item;
                    318:                     }
                    319:                 } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
                    320:                     my $marker = $1;
                    321:                     my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
                    322:                     $simplepages{$item} = {
                    323:                                             res    => $res,
                    324:                                             title  => $titles{$item},
                    325:                                             db     => $db_name,
                    326:                                             marker => $marker,
                    327:                                             symb   => $resources{$item},
                    328:                                             name   => $name,
                    329:                                           };
                    330:                     $display{$item} = '/'.$res;
                    331:                 }
                    332:             } elsif ($maps{$item}) {
                    333:                 if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
                    334:                     $tocopy{$1} = $name;
                    335:                     $display{$item} = $1;
                    336:                     $lookup{$1} = $item;
                    337:                 }
                    338:             } else {
                    339:                 next;
                    340:             }
                    341:         }
1.329     droeschl  342: 	my $crs='/uploaded/'.$env{'request.course.id'}.'/';
                    343: 	$crs=~s/\_/\//g;
1.567     raeburn   344:         my $mm = new File::MMagic;
                    345:         my $prefix = "/uploaded/$cdom/$cnum/";
                    346:         %replacehash = %tocopy;
                    347:         foreach my $item (sort(keys(%simpleproblems))) {
                    348:             my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
                    349:             $newcontent{$display{$item}} = $content;
                    350:         }
                    351:         my $gateway = Apache::lonhtmlgateway->new('web');
                    352:         foreach my $item (sort(keys(%simplepages))) {
                    353:             if (ref($simplepages{$item}) eq 'HASH') {
                    354:                 my $pagetitle = $simplepages{$item}{'title'};
                    355:                 my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
                    356:                 my %contents;
                    357:                 foreach my $field (keys(%fields)) {
                    358:                     if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
                    359:                         my $name = $1;
                    360:                         my $msg = $fields{$field};
                    361:                         if ($name eq 'webreferences') {
                    362:                             if ($msg =~ m{^https?://}) {
                    363:                                 $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
                    364:                             }
                    365:                         } else {
                    366:                             $msg = &Encode::decode('utf8',$msg);
                    367:                             $msg = $gateway->process_outgoing_html($msg,1);
                    368:                             $contents{$name} = $msg;
                    369:                         }
                    370:                     } elsif ($field eq 'uploaded.photourl') {
                    371:                         my $marker = $simplepages{$item}{marker};
                    372:                         if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
                    373:                             my $filepath = $1;
                    374:                             my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
                    375:                             if ($fname ne '') {
                    376:                                 $fname=~s/\.(\w+)$//;
                    377:                                 my $ext=$1;
                    378:                                 $fname = &clean($fname);
                    379:                                 $fname.='.'.$ext;
                    380:                                 $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
                    381:                                 $replacehash{$filepath} = $relpath.$fname;
                    382:                                 $deps{$item}{$filepath} = 1;
                    383:                             }
                    384:                         }
                    385:                     }
                    386:                 }
                    387:                 $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
                    388:                 $lookup{'/'.$simplepages{$item}{'res'}} = $item;
                    389:                 my $content = '
                    390: <html>
                    391: <head>
                    392: <title>'.$pagetitle.'</title>
                    393: </head>
                    394: <body bgcolor="#ffffff">';
                    395:                 if ($contents{title}) {
                    396:                     $content .= "\n".'<h2>'.$contents{title}.'</h2>';
                    397:                 }
                    398:                 if ($contents{image}) {
                    399:                     $content .= "\n".$contents{image};
                    400:                 }
                    401:                 if ($contents{content}) {
                    402:                     $content .= '
                    403: <div class="LC_Box">
1.577     bisitz    404: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567     raeburn   405: $contents{content}.'
                    406: </div>';
                    407:                 }
                    408:                 if ($contents{webreferences}) {
                    409:                     $content .= ' 
                    410: <div class="LC_Box">
1.577     bisitz    411: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567     raeburn   412: $contents{webreferences}.'
                    413: </div>';
                    414:                 }
                    415:                 $content .= '
                    416: </body>
                    417: </html>
                    418: ';
                    419:                 $newcontent{'/'.$simplepages{$item}{res}} = $content; 
                    420:             }
                    421:         }
                    422: 	foreach my $item (keys(%tocopy)) {
                    423:             unless ($item=~/\.(sequence|page)$/) {
                    424:                 my $currurlpath = $prefix.$item;
                    425:                 my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
                    426:                 &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
                    427:             }
                    428:         }
                    429:         foreach my $num (sort {$a <=> $b} (@todump)) {
                    430:             my $src = $display{$num};
                    431:             next if ($src eq '');
                    432:             my @needcopy = ();
                    433:             if ($replacehash{$src}) {
                    434:                 push(@needcopy,$src);
                    435:                 if (ref($deps{$num}) eq 'HASH') {
                    436:                     foreach my $dep (sort(keys(%{$deps{$num}}))) {
                    437:                         if ($replacehash{$dep}) {
                    438:                             push(@needcopy,$dep);
                    439:                         }
                    440:                     }
                    441:                 }
                    442:             } elsif ($src =~ /^simpleproblem_/) {
                    443:                 push(@needcopy,$src);
                    444:             }
                    445:             next if (@needcopy == 0);
                    446:             my ($result,$depresult);
                    447:             for (my $i=0; $i<@needcopy; $i++) {
                    448:                 my $item = $needcopy[$i];
                    449:                 my $newfilename;
                    450:                 if ($simpleproblems{$num}) {
                    451:                     $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
                    452:                 } else {
                    453: 	            $newfilename=$title.'/'.$replacehash{$item};
                    454:                 }
                    455: 	        $newfilename=~s/\.(\w+)$//;
                    456: 	        my $ext=$1;
                    457: 	        $newfilename=&clean($newfilename);
                    458: 	        $newfilename.='.'.$ext;
                    459:                 my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); 
                    460:                 if ($newrelpath ne $replacehash{$item}) {
                    461:                     $replacehash{$item} = $newrelpath;
                    462:                 }
                    463: 	        my @dirs=split(/\//,$newfilename);
                    464: 	        my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
                    465: 	        my $makepath=$path;
                    466: 	        my $fail;
                    467:                 my $origin;
                    468: 	        for (my $i=0;$i<$#dirs;$i++) {
                    469: 		    $makepath.='/'.$dirs[$i];
                    470: 		    unless (-e $makepath) {
                    471: 		        unless(mkdir($makepath,0755)) { 
                    472:                             $fail = &mt('Directory creation failed.');
                    473:                         }
                    474: 		    }
                    475: 	        }
                    476:                 if ($i == 0) {
                    477: 	            $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
                    478:                 } else {
                    479:                     $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
                    480:                                   '<span class="LC_fontsize_small" style="font-weight: bold;">'.
                    481:                                   &mt('(dependency)').'</span>: ';
                    482:                 }
                    483:                 if (-e $path.'/'.$newfilename) {
                    484:                     $fail = &mt('Destination already exists -- not overwriting.'); 
                    485: 	        } else {
                    486:                     if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
                    487:                         if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
                    488:                             ($item =~ /^simpleproblem_/)) {
                    489:                             print $fh $newcontent{$item};
                    490:                         } else {
                    491:                             my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
                    492:                             if (-e $fileloc) {
                    493:                                 if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
                    494:                                     if ((($1 eq 'sequence') || ($1 eq 'page')) &&
                    495:                                         (ref($has_simpleprobs{$item}) eq 'HASH')) {
                    496:                                         my %changes = %{$has_simpleprobs{$item}};
                    497:                                         my $content = &Apache::lonclonecourse::rewritefile(
                    498:                      &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                    499:                                                       (%replacehash,$crs => '')
                    500:                                                                                           );
                    501:                                         my $updatedcontent = '';
                    502:                                         my $parser = HTML::TokeParser->new(\$content);
                    503:                                         $parser->attr_encoded(1);
                    504:                                         while (my $token = $parser->get_token) {
                    505:                                             if ($token->[0] eq 'S') {
                    506:                                                 if (($token->[1] eq 'resource') &&
                    507:                                                     ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && 
                    508:                                                     ($changes{$token->[2]->{'id'}})) {
                    509:                                                     my $id = $token->[2]->{'id'};
                    510:                                                     $updatedcontent .= '<'.$token->[1];
                    511:                                                     foreach my $attrib (@{$token->[3]}) {
                    512:                                                         next unless ($attrib =~ /^(src|type|title|id)$/);
                    513:                                                         if ($attrib eq 'src') {
                    514:                                                             my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); 
                    515:                                                             if ($file) {
                    516:                                                                 $updatedcontent .= ' '.$attrib.'="'.$file.'"';
                    517:                                                             } else {
                    518:                                                                 $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; 
                    519:                                                             }
                    520:                                                         } else {
                    521:                                                             $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
                    522:                                                         }
                    523:                                                     }
                    524:                                                     $updatedcontent .= ' />'."\n";
                    525:                                                 } else {
                    526:                                                     $updatedcontent .= $token->[4]."\n";
                    527:                                                 }
                    528:                                              } else {
                    529:                                                  $updatedcontent .= $token->[2];
                    530:                                              }
                    531:                                          }
                    532:                                          print $fh $updatedcontent;
                    533:                                     } else {  
                    534: 		                        print $fh &Apache::lonclonecourse::rewritefile(
                    535:                      &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                    536: 		                                      (%replacehash,$crs => '')
                    537: 							                              );
                    538:                                     }
                    539:                                 } else {
                    540: 		                    print $fh
                    541:                                         &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
                    542: 		                }
                    543:                             } else {
                    544:                                 $fail = &mt('Source does not exist.');  
                    545:                             }
                    546:                         }
                    547:                         $fh->close();
                    548: 	            } else {
                    549: 		        $fail = &mt('Could not write to destination.');
                    550:                     }
                    551: 	        }
                    552:                 my $text;
                    553: 	        if ($fail) {
                    554:                     $text = '<span class="LC_error">'.&mt('fail').('&nbsp;'x3).$fail.'</span>';
                    555: 	        } else {
                    556:                     $text = '<span class="LC_success">'.&mt('ok').'</span>';
                    557:                 }
                    558:                 if ($i == 0) {
                    559:                     $result .= $text;
                    560:                 } else {
                    561:                     $depresult .= $text.'</li>';
                    562: 	        }
                    563:             }
                    564:             $r->print($result);
                    565:             if ($depresult) {
                    566:                 $r->print('<ul>'.$depresult.'</ul>');
                    567:             }
                    568:         }
                    569:     } else {
                    570:         my ($navmap,$errormsg) =
                    571:             &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
                    572:         if (!ref($navmap)) {
                    573:             $r->print($errormsg);
                    574:         } else {
                    575:             $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
                    576:             $r->rflush();
                    577:             my ($preamble,$formname);
                    578:             $formname = 'dumpdoc';
                    579: 	    unless ($home==1) {
                    580: 	        $preamble = '<div class="LC_left_float">'.
                    581: 		            '<fieldset><legend>'.
                    582:                             &mt('Select the Authoring Space').
                    583:                             '</legend><select name="authorspace">';
1.329     droeschl  584: 	    }
1.567     raeburn   585:             my @orderspaces = ();
                    586: 	    foreach my $key (sort(keys(%outhash))) {
                    587:                 if ($key=~/^home_(.+)$/) {
                    588:                     if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
                    589:                         unshift(@orderspaces,$1);
                    590:                     } else {
                    591:                         push(@orderspaces,$1);
                    592:                     }
                    593:                 } 
                    594:             }
1.569     raeburn   595:             if ($home>1) {
                    596:                 $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
                    597:             }
1.567     raeburn   598:             foreach my $user (@orderspaces) {
1.329     droeschl  599: 		if ($home==1) {
1.567     raeburn   600: 		    $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329     droeschl  601: 		} else {
1.567     raeburn   602: 		    $preamble .= '<option value="'.$user.'">'.$user.' - '.
                    603: 			         &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
                    604: 	        }
1.329     droeschl  605: 	    }
1.567     raeburn   606: 	    unless ($home==1) {
                    607: 	        $preamble .= '</select></fieldset></div>'."\n";
1.329     droeschl  608: 	    }
1.567     raeburn   609: 	    my $title=$origcrsdata{'description'};
                    610: 	    $title=~s/[\/\s]+/\_/gs;
1.329     droeschl  611: 	    $title=&clean($title);
1.567     raeburn   612: 	    $preamble .= '<div class="LC_left_float">'.
                    613:                          '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
                    614:                          '<input type="text" size="50" name="authorfolder" value="'.
                    615:                          $title.'" />'.
                    616:                          '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
                    617:             my %uploadedfiles;
                    618: 	    &tiehash();
                    619: 	    foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
                    620: 	        my ($ext)=($file=~/\.(\w+)$/);
                    621: # FIXME Check supplemental here
                    622: 	        my $title=$hash{'title_'.$hash{
                    623: 		                'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
                    624: 	        if (!$title) {
                    625: 		    $title=$file;
                    626: 	        } else {
                    627: 		    $title=~s|/|_|g;
                    628: 	        }
                    629: 	        $title=~s/\.(\w+)$//;
                    630: 	        $title=&clean($title);
                    631: 	        $title.='.'.$ext;
                    632: #	    $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
                    633:                 $uploadedfiles{$file} = $title;
                    634: 	    }
                    635: 	    &untiehash();
                    636:             $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
                    637:                                                                  undef,undef,$preamble,$home,\%uploadedfiles));
                    638:         }
1.329     droeschl  639:     }
1.484     raeburn   640:     $r->print(&endContentScreen());
1.329     droeschl  641: }
                    642: 
1.567     raeburn   643: sub recurse_html {
                    644:     my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
                    645:     return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
                    646:     my (%allfiles,%codebase);
                    647:     if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
                    648:         if (keys(%allfiles)) {
                    649:             foreach my $dependency (keys(%allfiles)) {
                    650:                 next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
                    651:                 my ($depurl,$relfile,$newcontainer);
                    652:                 if ($dependency =~ m{^/}) {
                    653:                     if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
                    654:                         $relfile = $1;
                    655:                         if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
                    656:                             $newcontainer = $1;
                    657:                             next if ($replacehash->{$newcontainer});
                    658:                         }
                    659:                         $depurl = $dependency;
                    660:                     } else {
                    661:                         next;
                    662:                     }
                    663:                 } else {
                    664:                     $relfile = $dependency;
                    665:                     $depurl = $currurlpath;
1.630     raeburn   666:                     $depurl =~ s{[^/]+$}{};
1.567     raeburn   667:                     $depurl .= $dependency;
1.630     raeburn   668:                     ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567     raeburn   669:                 }
                    670:                 next if ($relfile eq '');
                    671:                 my $newname = $replacehash->{$container};
                    672:                 $newname =~ s{[^/]+$}{};
                    673:                 $replacehash->{$newcontainer} = $newname.$relfile;
                    674:                 $deps->{$item}{$newcontainer} = 1;
                    675:                 my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});  
                    676:                 my $depfile = &Apache::lonnet::filelocation('',$depurl);
                    677:                 my $type = $mm->checktype_filename($depfile);
                    678:                 if ($type eq 'text/html') {
                    679:                     &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
                    680:                 }
                    681:             }
                    682:         }
                    683:     }
                    684:     return;
                    685: }
                    686: 
1.329     droeschl  687: sub group_import {
1.598     raeburn   688:     my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529     raeburn   689:     my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
                    690:         %removeparam,$importuploaded,$fixuperrors);
                    691:     $allmaps = {};
1.329     droeschl  692:     while (@files) {
                    693: 	my ($name, $url, $residx) = @{ shift(@files) };
1.344     bisitz    694:         if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329     droeschl  695: 	     && ($caller eq 'londocs')
                    696: 	     && (!&Apache::lonnet::stat_file($url))) {
1.364     bisitz    697: 
1.329     droeschl  698:             my $errtext = '';
                    699:             my $fatal = 0;
                    700:             my $newmapstr = '<map>'."\n".
                    701:                             '<resource id="1" src="" type="start"></resource>'."\n".
                    702:                             '<link from="1" to="2" index="1"></link>'."\n".
                    703:                             '<resource id="2" src="" type="finish"></resource>'."\n".
                    704:                             '</map>';
                    705:             $env{'form.output'}=$newmapstr;
                    706:             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                    707:                                                 'output',$1.$2);
1.534     raeburn   708:             if ($result !~ m{^/uploaded/}) {
1.329     droeschl  709:                 $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
                    710:                 $fatal = 2;
                    711:             }
                    712:             if ($fatal) {
                    713:                 return ($errtext,$fatal);
                    714:             }
                    715:         }
                    716: 	if ($url) {
1.626     raeburn   717:             if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598     raeburn   718:                 $url = $1;
                    719:                 my $marker = $2;
                    720:                 my $info = $3;
1.699     raeburn   721:                 my ($toolid,$toolprefix,$tooltype,%toolhash,%toolsettings);
1.642     raeburn   722:                 my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598     raeburn   723:                 my @toolinfo = split(/:/,$info);
                    724:                 if ($residx) {
1.604     raeburn   725:                     %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598     raeburn   726:                     $toolid = $toolsettings{'id'};
                    727:                 } else {
1.604     raeburn   728:                     $toolid = shift(@toolinfo);
1.598     raeburn   729:                 }
1.699     raeburn   730:                 if ($toolid =~ /^c/) {
                    731:                     $tooltype = 'crs';
                    732:                     $toolprefix = 'c';
                    733:                 } else {
                    734:                     $tooltype = 'dom';
                    735:                 }
1.598     raeburn   736:                 $toolid =~ s/\D//g;
1.604     raeburn   737:                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645     raeburn   738:                  $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
                    739:                  $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624     raeburn   740:                 foreach my $item (@extras) {
                    741:                     $toolhash{$item} = &unescape($toolhash{$item});
                    742:                 }
1.645     raeburn   743:                 if ($folder =~ /^supplemental/) {
1.648     raeburn   744:                     delete($toolhash{'gradable'});
                    745:                 } else {
                    746:                     $toolhash{'gradable'} =~ s/\D+//g;
1.645     raeburn   747:                 }
1.598     raeburn   748:                 if (ref($ltitoolsref) eq 'HASH') {
1.699     raeburn   749:                     if (ref($ltitoolsref->{$tooltype}) eq 'HASH') {
                    750:                         if (ref($ltitoolsref->{$tooltype}->{$toolid}) eq 'HASH') {
                    751:                             my %tools = %{$ltitoolsref->{$tooltype}->{$toolid}};
                    752:                             my @deleted;
                    753:                             $toolhash{'id'} = $toolprefix.$toolid;
                    754:                             if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
                    755:                                 ($toolhash{'target'} eq 'window')) {
                    756:                                 if ($toolhash{'target'} eq 'window') {
                    757:                                     foreach my $item ('width','height') {
                    758:                                         $toolhash{$item} =~ s/^\s+//;
                    759:                                         $toolhash{$item} =~ s/\s+$//;
                    760:                                         if ($toolhash{$item} =~ /\D/) {
                    761:                                             delete($toolhash{$item});
                    762:                                             if ($residx) {
                    763:                                                 if ($toolsettings{$item}) {
                    764:                                                     push(@deleted,$item);
                    765:                                                 }
1.624     raeburn   766:                                             }
                    767:                                         }
                    768:                                     }
1.604     raeburn   769:                                 }
1.699     raeburn   770:                             } elsif ($residx) {
                    771:                                 $toolhash{'target'} = $toolsettings{'target'};
                    772:                                 if ($toolhash{'target'} eq 'window') {
                    773:                                     foreach my $item ('width','height') {
                    774:                                         $toolhash{$item} = $toolsettings{$item};
                    775:                                     }
                    776:                                 }
                    777:                             } elsif (ref($tools{'display'}) eq 'HASH') {
                    778:                                 $toolhash{'target'} = $tools{'display'}{'target'};
                    779:                                 if ($toolhash{'target'} eq 'window') {
                    780:                                     $toolhash{'width'} = $tools{'display'}{'width'};
                    781:                                     $toolhash{'height'} = $tools{'display'}{'height'};
1.624     raeburn   782:                                 }
1.604     raeburn   783:                             }
1.699     raeburn   784:                             if ($toolhash{'target'} eq 'iframe') {
                    785:                                 foreach my $item ('width','height','linktext','explanation') {
                    786:                                     delete($toolhash{$item});
                    787:                                     if ($residx) {
                    788:                                         if ($toolsettings{$item}) {
                    789:                                             push(@deleted,$item);
                    790:                                         }
1.624     raeburn   791:                                     }
1.604     raeburn   792:                                 }
1.699     raeburn   793:                             } elsif ($toolhash{'target'} eq 'tab') {
                    794:                                 foreach my $item ('width','height') {
                    795:                                     delete($toolhash{$item});
                    796:                                     if ($residx) {
                    797:                                         if ($toolsettings{$item}) {
                    798:                                             push(@deleted,$item);
                    799:                                         }
1.628     raeburn   800:                                     }
                    801:                                 }
                    802:                             }
1.699     raeburn   803:                             if (ref($tools{'crsconf'}) eq 'HASH') {
                    804:                                 foreach my $item ('label','title','linktext','explanation') {
                    805:                                     my $crsitem;
                    806:                                     if (($item eq 'label') || ($item eq 'title')) {
                    807:                                         $crsitem = 'crs'.$item;
                    808:                                     } else {
                    809:                                         $crsitem = $item;
                    810:                                     }
                    811:                                     if ($tools{'crsconf'}{$item}) {
                    812:                                         $toolhash{$crsitem} =~ s/^\s+//;
                    813:                                         $toolhash{$crsitem} =~ s/\s+$//;
                    814:                                         if ($toolhash{$crsitem} eq '') {
                    815:                                             delete($toolhash{$crsitem});
                    816:                                         }
                    817:                                     } else {
1.624     raeburn   818:                                         delete($toolhash{$crsitem});
1.604     raeburn   819:                                     }
1.699     raeburn   820:                                     if (($residx) && (exists($toolsettings{$crsitem}))) {
                    821:                                         unless (exists($toolhash{$crsitem})) {
                    822:                                             push(@deleted,$crsitem);
                    823:                                         }
                    824:                                     }
1.604     raeburn   825:                                 }
1.699     raeburn   826:                             }
                    827:                             if ($toolhash{'passback'}) {
                    828:                                 my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                    829:                                 $toolhash{'gradesecret'} = $gradesecret;
                    830:                                 $toolhash{'gradesecretdate'} = time;
                    831:                             }
                    832:                             if ($toolhash{'roster'}) {
                    833:                                 my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                    834:                                 $toolhash{'rostersecret'} = $rostersecret;
                    835:                                 $toolhash{'rostersecretdate'} = time;
                    836:                             }
                    837:                             my $changegradable;
                    838:                             if (($residx) && ($folder =~ /^default/)) {
                    839:                                 if ($toolsettings{'gradable'}) {
                    840:                                     unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
                    841:                                         push(@deleted,'gradable');
                    842:                                         $changegradable = 1;
1.604     raeburn   843:                                     }
1.699     raeburn   844:                                 } elsif ($toolhash{'gradable'}) {
                    845:                                     $changegradable = 1;
1.604     raeburn   846:                                 }
1.699     raeburn   847:                                 if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645     raeburn   848:                                     $changegradable = 1;
1.699     raeburn   849:                                     if ($toolsettings{'gradable'}) {
                    850:                                         $toolhash{'gradable'} = 1;
                    851:                                     }
1.645     raeburn   852:                                 }
1.648     raeburn   853:                             }
1.699     raeburn   854:                             my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
                    855:                             if ($putres eq 'ok') {
                    856:                                 if (@deleted) {
                    857:                                     &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.648     raeburn   858:                                 }
1.699     raeburn   859:                                 if (($changegradable) && ($folder =~ /^default/)) {
                    860:                                     my $val;
                    861:                                     if ($toolhash{'gradable'}) {
                    862:                                         $val = 'yes';
                    863:                                     } else {
                    864:                                         $val = 'no';
                    865:                                     }
                    866:                                     &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
                    867:                                                                   'string_yesno');
                    868:                                     &remember_parms($residx,'gradable','set',$val);
1.645     raeburn   869:                                 }
1.699     raeburn   870:                             } else {
                    871:                                 return (&mt('Failed to save update to external tool.'),1);
1.645     raeburn   872:                             }
1.604     raeburn   873:                         }
1.598     raeburn   874:                     }
                    875:                 }
                    876:             }
1.529     raeburn   877:             if (($caller eq 'londocs') &&
                    878:                 ($folder =~ /^default/)) {
1.534     raeburn   879:                 if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529     raeburn   880:                     my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
                    881:                     my $cid = $coursedom.'_'.$coursenum;
                    882:                     $allmaps =
                    883:                         &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                    884:                                                              $chome,$cid);
                    885:                     $donechk = 1;
                    886:                 }
                    887:                 if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627     raeburn   888:                     &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
                    889:                                         \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529     raeburn   890:                     $importuploaded = 1;
                    891:                 } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
                    892:                     next if ($allmaps->{$url});
                    893:                 }
                    894:             }
1.344     bisitz    895: 	    if (!$residx
1.329     droeschl  896: 		|| defined($LONCAPA::map::zombies[$residx])) {
                    897: 		$residx = &LONCAPA::map::getresidx($url,$residx);
                    898: 		push(@LONCAPA::map::order, $residx);
                    899: 	    }
                    900: 	    my $ext = 'false';
                    901: 	    if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534     raeburn   902:             if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
                    903:                 my $filepath = $1;
1.675     raeburn   904:                 my $fname;
                    905:                 if ($name eq '') {
                    906:                     $name = &mt('Web Page');
1.534     raeburn   907:                     $fname = 'web';
                    908:                 } else {
1.675     raeburn   909:                     $fname = $name;
                    910:                     $fname=&Apache::lonnet::clean_filename($fname);
                    911:                     if ($fname eq '') {
                    912:                         $fname = 'web';
                    913:                     } elsif (length($fname) > 15) {
                    914:                         $fname = substr($fname,0,14);
                    915:                     }
1.534     raeburn   916:                 }
1.675     raeburn   917:                 my $title = &Apache::loncommon::cleanup_html($name);
1.534     raeburn   918:                 my $initialtext = &mt('Replace with your own content.');
                    919:                 my $newhtml = <<END;
1.545     raeburn   920: <html>
1.534     raeburn   921: <head>
1.675     raeburn   922: <title>$title</title>
1.534     raeburn   923: </head>
                    924: <body bgcolor="#ffffff">
                    925: $initialtext
                    926: </body>
                    927: </html>
                    928: END
                    929:                 $env{'form.output'}=$newhtml;
1.630     raeburn   930:                 my $result =
1.534     raeburn   931:                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                    932:                                                           'output',
                    933:                                                           "$filepath/$residx/$fname.html");
                    934:                 if ($result =~ m{^/uploaded/}) {
                    935:                     $url = $result;
                    936:                     if ($filepath =~ /^supplemental/) {
                    937:                         $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                    938:                                 $env{'user.domain'}.'___&&&___'.$name;
                    939:                     }
                    940:                 } else {
                    941:                     return (&mt('Failed to save new web page.'),1);
                    942:                 }
                    943:             }
1.675     raeburn   944:             $name = &LONCAPA::map::qtunescape($name);
1.538     raeburn   945:             $url  = &LONCAPA::map::qtunescape($url);
1.344     bisitz    946: 	    $LONCAPA::map::resources[$residx] =
1.329     droeschl  947: 		join(':', ($name, $url, $ext, 'normal', 'res'));
                    948: 	}
                    949:     }
1.529     raeburn   950:     if ($importuploaded) {
                    951:         my %import_errors;
                    952:         my %updated = (
                    953:                           removefrommap => \%removefrommap,
                    954:                           removeparam   => \%removeparam,
                    955:                       );
1.533     raeburn   956:         my ($result,$msgsarray,$lockerror) = 
                    957:             &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529     raeburn   958:         if (keys(%import_errors) > 0) {
1.530     raeburn   959:             $fixuperrors =
1.529     raeburn   960:                 '<p span class="LC_warning">'."\n".
                    961:                 &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".
                    962:                 '<ul>'."\n";
                    963:             foreach my $key (sort(keys(%import_errors))) {
                    964:                 $fixuperrors .= '<li>'.$key.'</li>'."\n";
                    965:             }
                    966:             $fixuperrors .= '</ul></p>'."\n";
                    967:         }
1.533     raeburn   968:         if (ref($msgsarray) eq 'ARRAY') {
                    969:             if (@{$msgsarray} > 0) {
                    970:                 $fixuperrors .= '<p class="LC_info">'.
                    971:                                 join('<br />',@{$msgsarray}).
                    972:                                 '</p>';
                    973:             }
                    974:         }
                    975:         if ($lockerror) {
                    976:             $fixuperrors .= '<p class="LC_error">'.
                    977:                             $lockerror.
                    978:                             '</p>';
                    979:         }
1.529     raeburn   980:     }
                    981:     my ($errtext,$fatal) =
                    982:         &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557     raeburn   983:     unless ($fatal) {
                    984:         if ($folder =~ /^supplemental/) {
1.561     raeburn   985:             my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                    986:                                             $folder.'.'.$container);
1.557     raeburn   987:         }
                    988:     }
1.529     raeburn   989:     return ($errtext,$fatal,$fixuperrors);
1.329     droeschl  990: }
                    991: 
                    992: sub log_docs {
1.494     raeburn   993:     return &Apache::lonnet::write_log('course','docslog',@_);
1.329     droeschl  994: }
                    995: 
                    996: {
                    997:     my @oldresources=();
                    998:     my @oldorder=();
                    999:     my $parmidx;
                   1000:     my %parmaction=();
                   1001:     my %parmvalue=();
                   1002:     my $changedflag;
                   1003: 
                   1004:     sub snapshotbefore {
                   1005:         @oldresources=@LONCAPA::map::resources;
                   1006:         @oldorder=@LONCAPA::map::order;
                   1007:         $parmidx=undef;
                   1008:         %parmaction=();
                   1009:         %parmvalue=();
                   1010:         $changedflag=0;
                   1011:     }
                   1012: 
                   1013:     sub remember_parms {
                   1014:         my ($idx,$parameter,$action,$value)=@_;
                   1015:         $parmidx=$idx;
                   1016:         $parmaction{$parameter}=$action;
                   1017:         $parmvalue{$parameter}=$value;
                   1018:         $changedflag=1;
                   1019:     }
                   1020: 
                   1021:     sub log_differences {
                   1022:         my ($plain)=@_;
                   1023:         my %storehash=('folder' => $plain,
                   1024:                        'currentfolder' => $env{'form.folder'});
                   1025:         if ($parmidx) {
                   1026:            $storehash{'parameter_res'}=$oldresources[$parmidx];
                   1027:            foreach my $parm (keys(%parmaction)) {
                   1028:               $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
                   1029:               $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
                   1030:            }
                   1031:         }
                   1032:         my $maxidx=$#oldresources;
                   1033:         if ($#LONCAPA::map::resources>$#oldresources) {
                   1034:            $maxidx=$#LONCAPA::map::resources;
                   1035:         }
                   1036:         for (my $idx=0; $idx<=$maxidx; $idx++) {
                   1037:            if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
                   1038:               $storehash{'before_resources_'.$idx}=$oldresources[$idx];
                   1039:               $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
                   1040:               $changedflag=1;
                   1041:            }
                   1042:            if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
                   1043:               $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
                   1044:               $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                   1045:               $changedflag=1;
                   1046:            }
                   1047:         }
                   1048: 	$storehash{'maxidx'}=$maxidx;
                   1049:         if ($changedflag) { &log_docs(\%storehash); }
                   1050:     }
                   1051: }
                   1052: 
                   1053: sub docs_change_log {
1.611     raeburn  1054:     my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486     raeburn  1055:     my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617     raeburn  1056:     my $navmap; 
1.483     raeburn  1057:     my $js = '<script type="text/javascript">'."\n".
                   1058:              '// <![CDATA['."\n".
                   1059:              &Apache::loncommon::display_filter_js('docslog')."\n".
1.606     raeburn  1060:              &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622     raeburn  1061:                          $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483     raeburn  1062:              &history_tab_js()."\n".
1.484     raeburn  1063:              &Apache::lonratedt::editscript('simple')."\n".
1.483     raeburn  1064:              '// ]]>'."\n".
                   1065:              '</script>'."\n";
1.484     raeburn  1066:     $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
                   1067:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489     raeburn  1068:     $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484     raeburn  1069:     my %orderhash;
                   1070:     my $container='sequence';
                   1071:     my $pathitem;
1.519     raeburn  1072:     if ($env{'form.folderpath'} =~ /\:1$/) {
1.484     raeburn  1073:         $container='page';
                   1074:     }
1.519     raeburn  1075:     my $folderpath=$env{'form.folderpath'};
                   1076:     if ($folderpath eq '') {
1.617     raeburn  1077:         $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519     raeburn  1078:     }
1.617     raeburn  1079:     undef($navmap);
1.519     raeburn  1080:     $pathitem = '<input type="hidden" name="folderpath" value="'.
                   1081:                 &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484     raeburn  1082:     my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
                   1083:     my $jumpto = $readfile;
                   1084:     $jumpto =~ s{^/}{};
                   1085:     my $tid = 1;
1.489     raeburn  1086:     if ($supplementalflag) {
                   1087:         $tid = 2;
                   1088:     }
1.630     raeburn  1089:     my ($breadcrumbtrail) =
1.509     raeburn  1090:         &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484     raeburn  1091:     $r->print($breadcrumbtrail.
                   1092:               &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
                   1093:               $readfile));
1.329     droeschl 1094:     my %docslog=&Apache::lonnet::dump('nohist_docslog',
                   1095:                                       $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1096:                                       $env{'course.'.$env{'request.course.id'}.'.num'});
                   1097: 
                   1098:     if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
                   1099: 
                   1100:     my %saveable_parameters = ('show' => 'scalar',);
                   1101:     &Apache::loncommon::store_course_settings('docs_log',
                   1102:                                               \%saveable_parameters);
                   1103:     &Apache::loncommon::restore_course_settings('docs_log',
                   1104:                                                 \%saveable_parameters);
                   1105:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452     www      1106: # FIXME: internationalization seems wrong here
1.329     droeschl 1107:     my %lt=('hiddenresource' => 'Resources hidden',
                   1108: 	    'encrypturl'     => 'URL hidden',
                   1109: 	    'randompick'     => 'Randomly pick',
                   1110: 	    'randomorder'    => 'Randomly ordered',
1.645     raeburn  1111:             'gradable'       => 'Grade can be assigned to External Tool',
1.329     droeschl 1112: 	    'set'            => 'set to',
                   1113: 	    'del'            => 'deleted');
1.484     raeburn  1114:     my $filter = &Apache::loncommon::display_filter('docslog')."\n".
                   1115:                  $pathitem."\n".
                   1116:                  '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
                   1117:                  ('&nbsp;'x2).'<input type="submit" value="'.&mt('Display').'" />';
                   1118:     $r->print('<div class="LC_left_float">'.
                   1119:               '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
                   1120:               &makedocslogform($filter,1).
                   1121:               '</fieldset></div><br clear="all" />');
1.329     droeschl 1122:     $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
                   1123:               '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
                   1124:               &mt('After').'</th>'.
                   1125:               &Apache::loncommon::end_data_table_header_row());
                   1126:     my $shown=0;
                   1127:     foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
                   1128: 	if ($env{'form.displayfilter'} eq 'currentfolder') {
                   1129: 	    if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
                   1130: 	}
                   1131:         my @changes=keys(%{$docslog{$id}{'logentry'}});
                   1132:         if ($env{'form.displayfilter'} eq 'containing') {
                   1133: 	    my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
                   1134: 		&Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
                   1135: 	    foreach my $key (@changes) {
                   1136: 		$wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
                   1137: 	    }
1.344     bisitz   1138: 	    if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329     droeschl 1139: 	}
                   1140:         my $count = 0;
                   1141:         my $time =
                   1142:             &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
                   1143:         my $plainname =
                   1144:             &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
                   1145:                                           $docslog{$id}{'exe_udom'});
                   1146:         my $about_me_link =
                   1147:             &Apache::loncommon::aboutmewrapper($plainname,
                   1148:                                                $docslog{$id}{'exe_uname'},
                   1149:                                                $docslog{$id}{'exe_udom'});
                   1150:         my $send_msg_link='';
                   1151:         if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
                   1152:              || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
                   1153:             $send_msg_link ='<br />'.
                   1154:                 &Apache::loncommon::messagewrapper(&mt('Send message'),
                   1155:                                                    $docslog{$id}{'exe_uname'},
                   1156:                                                    $docslog{$id}{'exe_udom'});
                   1157:         }
                   1158:         $r->print(&Apache::loncommon::start_data_table_row());
                   1159:         $r->print('<td>'.$time.'</td>
                   1160:                        <td>'.$about_me_link.
                   1161:                   '<br /><tt>'.$docslog{$id}{'exe_uname'}.
                   1162:                                   ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
                   1163:                   $send_msg_link.'</td><td>'.
                   1164:                   $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488     raeburn  1165:         my $is_supp = 0; 
                   1166:         if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
                   1167:             $is_supp = 1;
                   1168:         }
1.329     droeschl 1169: # Before
                   1170: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1171: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                   1172: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                   1173: 	    if ($oldname ne $newname) {
1.488     raeburn  1174:                 my $shown = &LONCAPA::map::qtescape($oldname);
                   1175:                 if ($is_supp) {
                   1176:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   1177:                 }
                   1178:                 $r->print($shown);
1.329     droeschl 1179: 	    }
                   1180: 	}
                   1181: 	$r->print('<ul>');
                   1182: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1183:             if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488     raeburn  1184:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
                   1185:                 if ($is_supp) {
                   1186:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   1187:                 }
                   1188: 		$r->print('<li>'.$shown.'</li>');
1.329     droeschl 1189: 	    }
                   1190: 	}
                   1191: 	$r->print('</ul>');
                   1192: # After
                   1193:         $r->print('</td><td>');
                   1194: 
                   1195: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1196: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                   1197: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                   1198: 	    if ($oldname ne '' && $oldname ne $newname) {
1.488     raeburn  1199:                 my $shown = &LONCAPA::map::qtescape($newname);
                   1200:                 if ($is_supp) {
                   1201:                     $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
                   1202:                 }
                   1203:                 $r->print($shown);
1.329     droeschl 1204: 	    }
1.364     bisitz   1205: 	}
1.329     droeschl 1206: 	$r->print('<ul>');
                   1207: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                   1208:             if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488     raeburn  1209:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
                   1210:                 if ($is_supp) {
                   1211:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
                   1212:                 }
                   1213:                 $r->print('<li>'.$shown.'</li>');
1.329     droeschl 1214: 	    }
                   1215: 	}
                   1216: 	$r->print('</ul>');
                   1217: 	if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693     raeburn  1218:             my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
                   1219:             if ($title eq '') {
                   1220:                 ($title) = ($url =~ m{/([^/]+)$});
1.695     raeburn  1221:             } elsif ($is_supp) {
                   1222:                 $title = &Apache::loncommon::parse_supplemental_title($title);
1.693     raeburn  1223:             }
                   1224:             $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645     raeburn  1225: 	    foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329     droeschl 1226: 		if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452     www      1227: # FIXME: internationalization seems wrong here
1.329     droeschl 1228: 		    $r->print('<li>'.
                   1229: 			      &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
                   1230: 				  $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
                   1231: 			      .'</li>');
                   1232: 		}
                   1233: 	    }
                   1234: 	    $r->print('</ul>');
                   1235: 	}
                   1236: # End
                   1237:         $r->print('</td>'.&Apache::loncommon::end_data_table_row());
                   1238:         $shown++;
                   1239:         if (!($env{'form.show'} eq &mt('all')
                   1240:               || $shown<=$env{'form.show'})) { last; }
                   1241:     }
1.484     raeburn  1242:     $r->print(&Apache::loncommon::end_data_table()."\n".
                   1243:               &makesimpleeditform($pathitem)."\n".
                   1244:               '</div></div>');
                   1245:     $r->print(&endContentScreen());
1.329     droeschl 1246: }
                   1247: 
                   1248: sub update_paste_buffer {
1.492     raeburn  1249:     my ($coursenum,$coursedom,$folder) = @_;
1.591     raeburn  1250:     my (@possibles,%removals,%cuts,$output);
1.538     raeburn  1251:     if ($env{'form.multiremove'}) {
                   1252:         $env{'form.multiremove'} =~ s/,$//;
                   1253:         map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
                   1254:     }
                   1255:     if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
                   1256:         if ($env{'form.multicut'}) {
                   1257:             $env{'form.multicut'} =~ s/,$//;
                   1258:             foreach my $item (split(/,/,$env{'form.multicut'})) {
                   1259:                 unless ($removals{$item}) {
                   1260:                     $cuts{$item} = 1;
                   1261:                     push(@possibles,$item.':cut');
                   1262:                 }
                   1263:             }
                   1264:         }
                   1265:         if ($env{'form.multicopy'}) {
                   1266:             $env{'form.multicopy'} =~ s/,$//;
                   1267:             foreach my $item (split(/,/,$env{'form.multicopy'})) {
                   1268:                 unless ($removals{$item} || $cuts{$item}) {
                   1269:                     push(@possibles,$item.':copy'); 
                   1270:                 }
                   1271:             }
                   1272:         }
                   1273:     } elsif ($env{'form.markcopy'}) {
                   1274:         @possibles = split(/,/,$env{'form.markcopy'});
                   1275:     }
1.329     droeschl 1276: 
1.538     raeburn  1277:     return if (@possibles == 0);
1.329     droeschl 1278:     return if (!defined($env{'form.copyfolder'}));
                   1279: 
                   1280:     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   1281: 				    $env{'form.copyfolder'});
1.538     raeburn  1282:     return if ($fatal);
                   1283: 
                   1284:     my %curr_groups = &Apache::longroup::coursegroups();
1.364     bisitz   1285: 
1.538     raeburn  1286: # Retrieve current paste buffer suffixes.
                   1287:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   1288:     my (%pasteurls,@newpaste);
                   1289: 
                   1290: # Construct identifiers for current contents of user's paste buffer
                   1291:     if (@currpaste) {
                   1292:         foreach my $suffix (@currpaste) {
1.667     raeburn  1293:             my $cid = $env{'docs.markedcopy_crs_'.$suffix};
                   1294:             my $url = $env{'docs.markedcopy_url_'.$suffix};
                   1295:             my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
                   1296:             if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
                   1297:                 ($url ne '')) {
                   1298:                 if ($url eq '/res/lib/templates/simpleproblem.problem') {
                   1299:                     $pasteurls{$cid.'_'.$mapidx} = 1;
                   1300:                 } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
                   1301:                     $pasteurls{$url} = 1;
                   1302:                 } else {
1.669     raeburn  1303:                     $pasteurls{$cid.'_'.$url} = 1;
1.667     raeburn  1304:                 }
                   1305:             }
1.538     raeburn  1306:         }
                   1307:     }
                   1308: 
                   1309: # Mark items for copying (skip any items already in user's paste buffer)
                   1310:     my %addtoenv;
1.597     raeburn  1311: 
                   1312:     my @pathitems = split(/\&/,$env{'form.folderpath'});
                   1313:     my @folderconf = split(/\:/,$pathitems[-1]);
1.666     raeburn  1314:     my $ispage = $folderconf[5];
1.597     raeburn  1315: 
1.538     raeburn  1316:     foreach my $item (@possibles) {
                   1317:         my ($orderidx,$cmd) = split(/:/,$item);
                   1318:         next if ($orderidx =~ /\D/);
                   1319:         next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597     raeburn  1320:         my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538     raeburn  1321:         my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
                   1322:         my %denied = &action_restrictions($coursenum,$coursedom,
                   1323:                                           &LONCAPA::map::qtescape($url),
                   1324:                                           $env{'form.folderpath'},\%curr_groups);
                   1325:         next if ($denied{'copy'});
                   1326:         $url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.667     raeburn  1327:         if ($url eq '/res/lib/templates/simpleproblem.problem') {
                   1328:             next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
                   1329:         } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
                   1330:             next if (exists($pasteurls{$url}));
                   1331:         } else {
                   1332:             next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
                   1333:         }
1.538     raeburn  1334:         my ($suffix,$errortxt,$locknotfreed) =
                   1335:             &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591     raeburn  1336:         if ($suffix ne '') {
                   1337:             push(@newpaste,$suffix);
                   1338:         } else {
                   1339:             if ($locknotfreed) {
                   1340:                 return $locknotfreed;
                   1341:             }
1.538     raeburn  1342:         }
                   1343:         if (&is_supplemental_title($title)) {
                   1344:             &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
                   1345: 	    ($title) = &Apache::loncommon::parse_supplemental_title($title);
                   1346:         }
1.329     droeschl 1347: 
1.538     raeburn  1348:         $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
                   1349:         $addtoenv{'docs.markedcopy_url_'.$suffix}   = $url,
                   1350:         $addtoenv{'docs.markedcopy_cmd_'.$suffix}   = $cmd,
                   1351:         $addtoenv{'docs.markedcopy_crs_'.$suffix}   = $env{'request.course.id'};
1.597     raeburn  1352:         $addtoenv{'docs.markedcopy_map_'.$suffix}   = $mapidx;
1.538     raeburn  1353:         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
                   1354:             my $prefix = $1;
                   1355:             my $subdir =$2;
                   1356:             if ($subdir eq '') {
                   1357:                 $subdir = $prefix;
1.492     raeburn  1358:             }
1.538     raeburn  1359:             my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627     raeburn  1360:             &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
                   1361:                                  \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538     raeburn  1362:             if (ref($hierarchy{$url}) eq 'HASH') {
                   1363:                 my ($nested,$nestednames);
                   1364:                 &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
                   1365:                 $nested =~ s/\&$//;
                   1366:                 $nestednames =~ s/\Q___&&&___\E$//;
                   1367:                 if ($nested ne '') {
                   1368:                     $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
                   1369:                 }
                   1370:                 if ($nestednames ne '') {
                   1371:                     $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
                   1372:                 }
1.492     raeburn  1373:             }
                   1374:         }
1.591     raeburn  1375:         if ($locknotfreed) {
                   1376:             $output = $locknotfreed;
                   1377:             last;
                   1378:         }
1.492     raeburn  1379:     }
1.538     raeburn  1380:     if (@newpaste) {
                   1381:         $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
                   1382:     }
1.492     raeburn  1383:     &Apache::lonnet::appenv(\%addtoenv);
1.329     droeschl 1384:     delete($env{'form.markcopy'});
1.591     raeburn  1385:     return $output;
1.329     droeschl 1386: }
                   1387: 
1.492     raeburn  1388: sub recurse_uploaded_maps {
                   1389:     my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
                   1390:     if (ref($hierarchy->{$url}) eq 'HASH') {
                   1391:         my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
                   1392:         my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
                   1393:         my (@uploaded,@names,%shorter);
                   1394:         for (my $i=0; $i<@maps; $i++) {
                   1395:             my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
                   1396:             if ($inner ne '') {
                   1397:                 push(@uploaded,$inner);
                   1398:                 push(@names,&escape($titles[$i]));
                   1399:                 $shorter{$maps[$i]} = $inner;
                   1400:             }
                   1401:         }
                   1402:         $$nestref .= "$dir:".join(',',@uploaded).'&';
                   1403:         $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
                   1404:         foreach my $map (@maps) {
                   1405:             if ($shorter{$map} ne '') {
                   1406:                 &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
                   1407:             }
                   1408:         }
                   1409:     }
                   1410:     return;
                   1411: }
                   1412: 
1.329     droeschl 1413: sub print_paste_buffer {
1.492     raeburn  1414:     my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538     raeburn  1415:     return if (!defined($env{'docs.markedcopies'}));
1.329     droeschl 1416: 
1.538     raeburn  1417:     unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
                   1418:         return if ($env{'docs.markedcopies'} eq '');
1.488     raeburn  1419:     }
                   1420: 
1.538     raeburn  1421:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   1422:     my ($pasteitems,@pasteable);
1.575     raeburn  1423:     my $clipboardcount = 0;
1.488     raeburn  1424: 
1.538     raeburn  1425: # Construct identifiers for current contents of user's paste buffer
                   1426:     foreach my $suffix (@currpaste) {
                   1427:         next if ($suffix =~ /\D/);
                   1428:         my $cid = $env{'docs.markedcopy_crs_'.$suffix};
                   1429:         my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597     raeburn  1430:         my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538     raeburn  1431:         if (($cid =~ /^$match_domain\_$match_courseid$/) &&
                   1432:             ($url ne '')) {
1.575     raeburn  1433:             $clipboardcount ++;
1.538     raeburn  1434:             my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598     raeburn  1435:                 $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538     raeburn  1436:             my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
                   1437:             if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
                   1438:                 $is_external = 1;
1.626     raeburn  1439:             } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598     raeburn  1440:                 $is_exttool = 1;
1.538     raeburn  1441:             }
                   1442:             if ($folder =~ /^supplemental/) {
                   1443:                 $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
                   1444:                 unless ($canpaste) {
                   1445:                     $nopaste = &mt('Paste into Supplemental Content unavailable.');
                   1446:                 }
                   1447:             } else {
                   1448:                 $canpaste = 1;
                   1449:             }
                   1450:             if ($canpaste) {
                   1451:                 if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
                   1452:                     my $srcdom = $1;
                   1453:                     my $srcnum = $2;
                   1454:                     my $rem = $3;
                   1455:                     if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
                   1456:                         $othercourse = 1;
                   1457:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596     raeburn  1458:                             $othercrs = '<br />'.&mt('(from another course)');
1.538     raeburn  1459:                         } else {
                   1460:                             $canpaste = 0;
                   1461:                             $nopaste = &mt('Paste from another course unavailable.'); 
                   1462:                         }
                   1463:                     }
                   1464:                     if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
                   1465:                         my $prefix = $1;
                   1466:                         $parent = $2;
                   1467:                         if ($folder !~ /^\Q$prefix\E/) {
                   1468:                             $areachange = 1;
                   1469:                         }
                   1470:                         $is_uploaded_map = 1;
1.492     raeburn  1471:                     }
1.597     raeburn  1472:                 } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627     raeburn  1473:                          ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596     raeburn  1474:                     if ($cid ne $env{'request.course.id'}) {
                   1475:                         my ($srcdom,$srcnum) = split(/_/,$cid);
                   1476:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627     raeburn  1477:                             if (($is_exttool) && ($srcdom ne $coursedom)) {
                   1478:                                 $canpaste = 0;
                   1479:                                 $nopaste = &mt('Paste from another domain unavailable.');
                   1480:                             } else {
                   1481:                                 $othercrs = '<br />'.&mt('(from another course)');
                   1482:                             }
1.596     raeburn  1483:                         } else {
                   1484:                             $canpaste = 0;
                   1485:                             $nopaste = &mt('Paste from another course unavailable.');
1.629     raeburn  1486:                         }
1.596     raeburn  1487:                     }
1.492     raeburn  1488:                 }
1.596     raeburn  1489:                 if ($canpaste) {
                   1490:                     push(@pasteable,$suffix);
1.629     raeburn  1491:                 }
1.538     raeburn  1492:             }
                   1493:             my $buffer;
1.627     raeburn  1494:             if ($is_external) {
1.538     raeburn  1495:                 $buffer = &mt('External Resource').': '.
                   1496:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
                   1497:                     &LONCAPA::map::qtescape($url).')';
1.627     raeburn  1498:             } elsif ($is_exttool) {
                   1499:                 $buffer = &mt('External Tool').': '.
                   1500:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538     raeburn  1501:             } else {
                   1502:                 my $icon = &Apache::loncommon::icon($extension);
                   1503:                 if ($extension eq 'sequence' &&
                   1504:                     $url =~ m{/default_\d+\.sequence$}x) {
                   1505:                     $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
                   1506:                     $icon .= '/navmap.folder.closed.gif';
                   1507:                 }
1.589     raeburn  1508:                 my $title = $env{'docs.markedcopy_title_'.$suffix};
                   1509:                 if ($title eq '') {
                   1510:                     ($title) = ($url =~ m{/([^/]+)$});
                   1511:                 }
1.538     raeburn  1512:                 $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
                   1513:                           ': '.
                   1514:                           &Apache::loncommon::parse_supplemental_title(
1.589     raeburn  1515:                              &LONCAPA::map::qtescape($title));
1.538     raeburn  1516:             }
                   1517:             $pasteitems .= '<div class="LC_left_float">';
                   1518:             my ($options,$onclick);
                   1519:             if (($canpaste) && (!$areachange) && (!$othercourse) &&
                   1520:                 ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
                   1521:                 if (($is_uploaded_map) ||
                   1522:                     ($url =~ /(bulletinboard|smppg)$/) ||
                   1523:                     ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
                   1524:                     $options = &paste_options($suffix,$is_uploaded_map,$parent);
                   1525:                     $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
                   1526:                 }
                   1527:             }
                   1528:             $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
                   1529:             if ($nopaste) {
1.681     raeburn  1530:                  $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';   
1.538     raeburn  1531:             } else {
                   1532:                 if ($othercrs) {
                   1533:                     $pasteitems .= $othercrs;
                   1534:                 }
                   1535:                 if ($options) {
                   1536:                     $pasteitems .= $options;
1.492     raeburn  1537:                 }
                   1538:             }
1.538     raeburn  1539:             $pasteitems .= '</div>';
                   1540:         }
                   1541:     }
                   1542:     if ($pasteitems eq '') {
                   1543:         &Apache::lonnet::delenv('docs.markedcopies');
                   1544:     }
                   1545:     my ($pasteform,$form_start,$buttons,$form_end);
                   1546:     if ($pasteitems) {
                   1547:         $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541     raeburn  1548:         $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538     raeburn  1549:         if (@pasteable) {
1.575     raeburn  1550:             my $value = &mt('Paste to current folder');
                   1551:             if ($container eq 'page') {
                   1552:                 $value = &mt('Paste to current page');
                   1553:             } 
                   1554:             $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.('&nbsp;'x2);
                   1555:         }
                   1556:         $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.('&nbsp;'x2);
                   1557:         if ($clipboardcount > 1) {
                   1558:             $buttons .=
                   1559:                 '<span style="text-decoration:line-through">'.('&nbsp;'x20).'</span>'.('&nbsp;'x2).
                   1560:                 '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
                   1561:                 ('&nbsp;'x2).
                   1562:                 '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
                   1563:                 ('&nbsp;'x2);
1.492     raeburn  1564:         }
1.575     raeburn  1565:         $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
                   1566:                     '</form>';
1.538     raeburn  1567:     } else {
                   1568:         $pasteitems = &mt('Clipboard is empty');
1.488     raeburn  1569:     }
1.538     raeburn  1570:     $r->print($form_start
                   1571:              .'<fieldset>'
                   1572:              .'<legend>'.&mt('Clipboard').('&nbsp;' x2).$buttons.'</legend>'
                   1573:              .$pasteitems
                   1574:              .'</fieldset>'
                   1575:              .$form_end);
                   1576: }
                   1577: 
                   1578: sub paste_options {
                   1579:     my ($suffix,$is_uploaded_map,$parent) = @_;
                   1580:     my ($copytext,$movetext);
                   1581:     if ($is_uploaded_map) {
                   1582:         $copytext = &mt('Copy to new folder');
                   1583:         $movetext = &mt('Move old');
                   1584:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
                   1585:         $copytext = &mt('Copy to new board');
                   1586:         $movetext = &mt('Move (not posts)');
                   1587:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
                   1588:         $copytext = &mt('Copy to new page');
                   1589:         $movetext = &mt('Move');
1.533     raeburn  1590:     } else {
1.538     raeburn  1591:         $copytext = &mt('Copy to new file');
                   1592:         $movetext = &mt('Move');
                   1593:     }
                   1594:     my $output = '<br />'.
                   1595:                  '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
                   1596:                  '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.('&nbsp;'x 4).
                   1597:                  '<label>'.
                   1598:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
                   1599:                  $copytext.'</label></span>'.('&nbsp;'x2).' '.
                   1600:                  '<span class="LC_nobreak"><label>'.
                   1601:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
                   1602:                  $movetext.'</label></span>';
                   1603:     if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
                   1604:         $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
                   1605:                    '</legend><table border="0">';
                   1606:         my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   1607:         my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
                   1608:         my $lastdir = $parent;
                   1609:         my %depths = (
                   1610:                        $lastdir => 0,
                   1611:                      );
                   1612:         my (%display,%deps);
                   1613:         for (my $i=0; $i<@pastemaps; $i++) {
                   1614:             ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
                   1615:             my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
                   1616:             my @subfolders = split(/,/,$subfolderstr);
                   1617:             $deps{$lastdir} = \@subfolders;
                   1618:             my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
                   1619:             my $depth = $depths{$lastdir} + 1;
                   1620:             my $offset = int($depth * 4);
                   1621:             my $indent = ('&nbsp;' x $offset);
                   1622:             for (my $j=0; $j<@subfolders; $j++) {
                   1623:                 $depths{$subfolders[$j]} = $depth;
                   1624:                 $display{$subfolders[$j]} =
                   1625:                     '<tr><td>'.$indent.$subfoldertitles[$j].'&nbsp;</td>'.
                   1626:                     '<td><label>'.
                   1627:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.('&nbsp;' x2).
                   1628:                     '<label>'.
                   1629:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
                   1630:                     &mt('Move old').'</label>'.
                   1631:                     '</td></tr>';
                   1632:              }
1.492     raeburn  1633:         }
1.538     raeburn  1634:         &recurse_print(\$output,$parent,\%deps,\%display);
                   1635:         $output .= '</table></fieldset>';
1.329     droeschl 1636:     }
1.538     raeburn  1637:     $output .= '</div>';
                   1638:     return $output;
1.488     raeburn  1639: }
                   1640: 
1.492     raeburn  1641: sub recurse_print {
1.538     raeburn  1642:     my ($outputref,$dir,$deps,$display) = @_;
                   1643:     $$outputref .= $display->{$dir}."\n";
1.492     raeburn  1644:     if (ref($deps->{$dir}) eq 'ARRAY') {
                   1645:         foreach my $subdir (@{$deps->{$dir}}) {
1.538     raeburn  1646:             &recurse_print($outputref,$subdir,$deps,$display);
1.492     raeburn  1647:         }
                   1648:     }
                   1649: }
                   1650: 
1.488     raeburn  1651: sub supp_pasteable {
                   1652:     my ($url) = @_;
                   1653:     if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//}) ||
                   1654:         (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
                   1655:         ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
                   1656:         ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598     raeburn  1657:         ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626     raeburn  1658:         ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488     raeburn  1659:         return 1;
                   1660:     }
                   1661:     return;
1.329     droeschl 1662: }
                   1663: 
1.492     raeburn  1664: sub paste_popup_js {
1.594     damieng  1665:     my %html_js_lt = &Apache::lonlocal::texthash(
1.538     raeburn  1666:                                           show => 'Show Options',
                   1667:                                           hide => 'Hide Options',
1.594     damieng  1668:                                         );
                   1669:     my %js_lt = &Apache::lonlocal::texthash(
1.541     raeburn  1670:                                           none => 'No items selected from clipboard.',
1.492     raeburn  1671:                                         );
1.594     damieng  1672:     &html_escape(\%html_js_lt);
                   1673:     &js_escape(\%html_js_lt);
                   1674:     &js_escape(\%js_lt);
1.492     raeburn  1675:     return <<"END";
                   1676: 
1.538     raeburn  1677: function showPasteOptions(suffix) {
                   1678:     document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594     damieng  1679:     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  1680:     return;
                   1681: }
                   1682: 
1.538     raeburn  1683: function hidePasteOptions(suffix) {
                   1684:     document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594     damieng  1685:     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  1686:     return;
                   1687: }
                   1688: 
                   1689: function showOptions(caller,suffix) {
                   1690:     if (document.getElementById('pasteoptionstext_'+suffix)) {
                   1691:         if (caller.checked) {
1.594     damieng  1692:             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  1693:         } else {
                   1694:             document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
                   1695:         }
                   1696:         if (document.getElementById('pasteoptions_'+suffix)) {
                   1697:             document.getElementById('pasteoptions_'+suffix).style.display='none';
                   1698:         }
                   1699:     }
1.492     raeburn  1700:     return;
                   1701: }
                   1702: 
1.541     raeburn  1703: function validateClipboard() {
                   1704:     var numchk = 0;
                   1705:     if (document.pasteform.pasting.length > 1) {
                   1706:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1707:             if (document.pasteform.pasting[i].checked) {
                   1708:                 numchk ++;
                   1709:             }
                   1710:         }
                   1711:     } else {
                   1712:         if (document.pasteform.pasting.type == 'checkbox') {
                   1713:             if (document.pasteform.pasting.checked) {
                   1714:                 numchk ++; 
                   1715:             } 
                   1716:         }
                   1717:     }
                   1718:     if (numchk > 0) { 
                   1719:         return true;
                   1720:     } else {
1.594     damieng  1721:         alert("$js_lt{'none'}");
1.541     raeburn  1722:         return false;
                   1723:     }
                   1724: }
                   1725: 
1.575     raeburn  1726: function checkClipboard() {
                   1727:     if (document.pasteform.pasting.length > 1) {
                   1728:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1729:             document.pasteform.pasting[i].checked = true;
                   1730:         } 
                   1731:     }
                   1732:     return;
                   1733: }
                   1734: 
                   1735: function uncheckClipboard() {
                   1736:     if (document.pasteform.pasting.length >1) {
                   1737:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1738:             document.pasteform.pasting[i].checked = false;
                   1739:         }
                   1740:     }
                   1741:     return;
                   1742: }
                   1743: 
1.492     raeburn  1744: END
                   1745: 
                   1746: }
                   1747: 
1.329     droeschl 1748: sub do_paste_from_buffer {
1.492     raeburn  1749:     my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329     droeschl 1750: 
1.538     raeburn  1751: # Array of items in paste buffer
                   1752:     my (@currpaste,%pastebuffer,%allerrors);
                   1753:     @currpaste = split(/,/,$env{'docs.markedcopies'});
                   1754: 
1.492     raeburn  1755: # Early out if paste buffer is empty
1.538     raeburn  1756:     if (@currpaste == 0) {
1.492     raeburn  1757:         return ();
1.538     raeburn  1758:     } 
                   1759:     map { $pastebuffer{$_} = 1; } @currpaste;
                   1760: 
                   1761: # Array of items selected items to paste
                   1762:     my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
                   1763: 
                   1764: # Early out if nothing selected to paste
                   1765:     if (@reqpaste == 0) {
                   1766:         return();
                   1767:     }
                   1768:     my @topaste;
                   1769:     foreach my $suffix (@reqpaste) {
                   1770:         next if ($suffix =~ /\D/);
                   1771:         next unless (exists($pastebuffer{$suffix}));
                   1772:         push(@topaste,$suffix);
                   1773:     }
                   1774: 
                   1775: # Early out if nothing available to paste
                   1776:     if (@topaste == 0) {
                   1777:         return();
1.329     droeschl 1778:     }
                   1779: 
1.627     raeburn  1780:     my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597     raeburn  1781:         %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538     raeburn  1782: 
                   1783:     foreach my $suffix (@topaste) {
                   1784:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596     raeburn  1785:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597     raeburn  1786:         my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix}); 
1.492     raeburn  1787: # Supplemental content may only include certain types of content
                   1788: # Early out if pasted content is not supported in Supplemental area
1.538     raeburn  1789:         if ($folder =~ /^supplemental/) {
                   1790:             unless (&supp_pasteable($url)) {
                   1791:                 $notinsupp{$suffix} = 1;
                   1792:                 next;
                   1793:             }
1.492     raeburn  1794:         }
1.538     raeburn  1795:         if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
                   1796:             my $srcd = $1;
                   1797:             my $srcn = $2;
1.492     raeburn  1798: # When paste buffer was populated using an active role in a different course
1.538     raeburn  1799: # check for mdc privilege in the course from which the resource was pasted
                   1800:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   1801:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   1802:                     $notincrs{$suffix} = 1;
                   1803:                     next;
                   1804:                 }
1.491     raeburn  1805:             }
1.538     raeburn  1806:             $srcdom{$suffix} = $srcd;
                   1807:             $srcnum{$suffix} = $srcn;
1.597     raeburn  1808:         } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632     raeburn  1809:                  ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
                   1810:                  ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596     raeburn  1811:             my ($srcd,$srcn) = split(/_/,$cid);
                   1812: # When paste buffer was populated using an active role in a different course
                   1813: # check for mdc privilege in the course from which the resource was pasted
                   1814:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   1815:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   1816:                     $notincrs{$suffix} = 1;
                   1817:                     next;
                   1818:                 }
                   1819:             }
1.632     raeburn  1820: # When buffer was populated using an active role in a different course
                   1821: # disallow pasting of External Tool if course is in a different domain.
                   1822:             if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627     raeburn  1823:                 $notindom{$suffix} = 1;
                   1824:                 next;
                   1825:             }
1.596     raeburn  1826:             $srcdom{$suffix} = $srcd;
                   1827:             $srcnum{$suffix} = $srcn;
1.491     raeburn  1828:         }
1.597     raeburn  1829:         $srcmapidx{$suffix} = $mapidx;
1.538     raeburn  1830:         push(@dopaste,$suffix);
                   1831:         if ($url=~/\.(page|sequence)$/) {
                   1832:             $is_map{$suffix} = 1; 
                   1833:         }
                   1834:         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
                   1835:             my $oldprefix = $1;
1.492     raeburn  1836: # When pasting content from Main Content to Supplemental Content and vice versa 
                   1837: # URLs will contain different paths (which depend on whether pasted item is
1.597     raeburn  1838: # a folder/page or a document).
1.538     raeburn  1839:             if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
                   1840:                 $prefixchg{$suffix} = 'docstosupp';
                   1841:             } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
                   1842:                 $prefixchg{$suffix} = 'supptodocs';
                   1843:             }
1.491     raeburn  1844: 
1.492     raeburn  1845: # If pasting an uploaded map, get list of contained uploaded maps.
1.538     raeburn  1846:             if ($env{'docs.markedcopy_nested_'.$suffix}) {
                   1847:                 my @nested;
                   1848:                 my ($type) = ($oldprefix =~ /^(default|supplemental)/);
                   1849:                 my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   1850:                 my @deps = map { /\d+:([\d,]+$)/ } @items;
                   1851:                 foreach my $dep (@deps) {
                   1852:                     if ($dep =~ /,/) {
                   1853:                         push(@nested,split(/,/,$dep));
                   1854:                     } else {
                   1855:                         push(@nested,$dep);
                   1856:                     }
1.492     raeburn  1857:                 }
1.538     raeburn  1858:                 foreach my $item (@nested) {
                   1859:                     if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
                   1860:                         push(@{$marktomove{$suffix}},$type.'_'.$item);
                   1861:                     }
1.492     raeburn  1862:                 }
                   1863:             }
1.488     raeburn  1864:         }
                   1865:     }
                   1866: 
1.538     raeburn  1867: # Early out if nothing available to paste
                   1868:     if (@dopaste == 0) {
                   1869:         return ();
                   1870:     }
                   1871: 
                   1872: # Populate message hash and hashes used for main content <=> supplemental content
                   1873: # changes    
                   1874: 
                   1875:     %msgs = &Apache::lonlocal::texthash (
                   1876:                 notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
                   1877:                 notincrs  => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661     raeburn  1878:                 notindom  => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538     raeburn  1879:                 duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
                   1880:             );
                   1881: 
                   1882:     %before = (
                   1883:                  docstosupp => {
                   1884:                                    map => 'default',
                   1885:                                    doc => 'docs',
                   1886:                                },
                   1887:                  supptodocs => {
                   1888:                                    map => 'supplemental',
                   1889:                                    doc => 'supplemental',
                   1890:                                },
                   1891:               );
                   1892: 
                   1893:     %after = (
                   1894:                  docstosupp => {
                   1895:                                    map => 'supplemental',
                   1896:                                    doc => 'supplemental'
                   1897:                                },
                   1898:                  supptodocs => {
                   1899:                                    map => 'default',
                   1900:                                    doc => 'docs',
                   1901:                                },
                   1902:              );
                   1903: 
                   1904: # Retrieve information about all course maps in main content area 
                   1905: 
                   1906:     my $allmaps = {};
1.660     raeburn  1907:     my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538     raeburn  1908: 
                   1909: # Loop over the items to paste
                   1910:     foreach my $suffix (@dopaste) {
1.329     droeschl 1911: # Maps need to be copied first
1.538     raeburn  1912:         my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
                   1913:             %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597     raeburn  1914:             %newurls,%tomove,%resdatacopy);
1.538     raeburn  1915:         if (ref($marktomove{$suffix}) eq 'ARRAY') {
                   1916:             map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
                   1917:         }
                   1918:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
                   1919:         my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596     raeburn  1920:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); 
1.538     raeburn  1921:         my $oldurl = $url;
                   1922:         if ($is_map{$suffix}) {
1.491     raeburn  1923: # If pasting a map, check if map contains other maps
1.538     raeburn  1924:             my (%hierarchy,%titles);
1.660     raeburn  1925:             if (($folder =~ /^default/) && (!$donechk)) {
                   1926:                 $allmaps =
                   1927:                     &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                   1928:                                                          $env{"course.$env{'request.course.id'}.home"},
                   1929:                                                          $env{'request.course.id'});
                   1930:                 $donechk = 1;
                   1931:             }
1.627     raeburn  1932:             &contained_map_check($url,$folder,$coursenum,$coursedom,
                   1933:                                  \%removefrommap,\%removeparam,\%addedmaps,
                   1934:                                  \%hierarchy,\%titles,$allmaps);
1.538     raeburn  1935:             if ($url=~ m{^/uploaded/}) {
                   1936:                 my $newurl;
                   1937:                 unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   1938:                     ($newurl,my $error) = 
                   1939:                         &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
                   1940:                                         $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   1941:                                         \$title,$allmaps,\%newurls);
                   1942:                     if ($error) {
                   1943:                         $allerrors{$suffix} = $error;
                   1944:                         next;
                   1945:                     }
                   1946:                     if ($newurl ne '') {
                   1947:                         if ($newurl ne $url) {
                   1948:                             if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
                   1949:                                 $newsubdir{$url} = $1;
                   1950:                             }
                   1951:                             $mapchanges{$url} = 1;
1.492     raeburn  1952:                         }
1.538     raeburn  1953:                     }
                   1954:                 }
                   1955:                 if (($srcdom{$suffix} ne $coursedom) ||
                   1956:                     ($srcnum{$suffix} ne $coursenum) ||
                   1957:                     ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
                   1958:                     unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
                   1959:                                               $coursedom,$coursenum,$srcdom{$suffix},
                   1960:                                               $srcnum{$suffix},$allmaps,\%rewrites,
                   1961:                                               \%retitles,\%copies,\%dbcopies,
                   1962:                                               \%zombies,\%params,\%mapmoves,
                   1963:                                               \%mapchanges,\%tomove,\%newsubdir,
1.597     raeburn  1964:                                               \%newurls,\%resdatacopy)) {
1.538     raeburn  1965:                         $mapmoves{$url} = 1;
                   1966:                     }
                   1967:                     $url = $newurl;
                   1968:                 } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
                   1969:                     &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
                   1970:                                       $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   1971:                                       $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
                   1972:                                       \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597     raeburn  1973:                                       \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538     raeburn  1974:                 }
                   1975:             } elsif ($url=~m {^/res/}) {
1.597     raeburn  1976: # published map can only exist once, so remove from paste buffer when done
1.538     raeburn  1977:                 push(@toclear,$suffix);
                   1978: # if pasting published map (main content area only) check map not already in course
                   1979:                 if ($folder =~ /^default/) {
                   1980:                     if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
                   1981:                         $duplicate{$suffix} = 1; 
                   1982:                         next;
1.492     raeburn  1983:                     }
1.491     raeburn  1984:                 }
                   1985:             }
1.538     raeburn  1986:         }
1.627     raeburn  1987:         if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538     raeburn  1988:             my $prefix = $1;
1.648     raeburn  1989:             my $fromothercrs;
1.538     raeburn  1990:             #need to copy the db contents to a new one, unless this is a move.
                   1991:             my %info = (
                   1992:                          src  => $url,
                   1993:                          cdom => $coursedom,
                   1994:                          cnum => $coursenum,
1.596     raeburn  1995:                        );
1.649     raeburn  1996:             if ($prefix eq 'ext.tool') {
1.655     raeburn  1997:                 if ($prefixchg{$suffix} eq 'docstosupp') {
1.649     raeburn  1998:                     $info{'delgradable'} = 1;
                   1999:                 }
                   2000:             }
1.596     raeburn  2001:             if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
                   2002:                 unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
                   2003:                     $fromothercrs = 1;
                   2004:                     $info{'cdom'} = $srcdom{$suffix};
                   2005:                     $info{'cnum'} = $srcnum{$suffix};
                   2006:                 }
                   2007:             }
                   2008:             unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630     raeburn  2009:                 my (%lockerr,$msg);
1.538     raeburn  2010:                 my ($newurl,$result,$errtext) =
                   2011:                     &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
                   2012:                 if ($result eq 'ok') {
                   2013:                     $url = $newurl;
                   2014:                     $title=&mt('Copy of').' '.$title;
                   2015:                 } else {
                   2016:                     if ($prefix eq 'smppg') {
                   2017:                         $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
                   2018:                     } elsif ($prefix eq 'bulletinboard') {
1.565     bisitz   2019:                         $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627     raeburn  2020:                     } elsif ($prefix eq 'ext.tool') {
                   2021:                         $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538     raeburn  2022:                     }
                   2023:                     $results{$suffix} = $result;
                   2024:                     $msgerrs{$suffix} = $msg;
                   2025:                     $lockerrs{$suffix} = $lockerr{$prefix}; 
                   2026:                     next;
                   2027: 	        }
                   2028:                 if ($lockerr{$prefix}) {
                   2029:                     $lockerrs{$suffix} = $lockerr{$prefix};  
1.491     raeburn  2030:                 }
1.489     raeburn  2031:             }
                   2032:         }
1.538     raeburn  2033:         $title = &LONCAPA::map::qtunescape($title);
                   2034:         my $ext='false';
                   2035:         if ($url=~m{^http(|s)://}) { $ext='true'; }
                   2036:         if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
                   2037:             if ($folder !~ /^supplemental/) {
                   2038:                 (undef,undef,$title) =
                   2039:                     &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
                   2040:             }
                   2041:         } else {
                   2042:             if ($folder=~/^supplemental/) {
                   2043:                 $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   2044:                        $env{'user.domain'}.'___&&&___'.$title;
1.491     raeburn  2045:             }
1.533     raeburn  2046:         }
1.491     raeburn  2047: 
                   2048: # For uploaded files (excluding pages/sequences) path in copied file is changed
                   2049: # if paste is from Main to Supplemental (or vice versa), or if pasting between
                   2050: # courses.
                   2051: 
1.538     raeburn  2052:         unless ($is_map{$suffix}) {
                   2053:             my $newidx;
1.492     raeburn  2054: # Now insert the URL at the bottom
1.538     raeburn  2055:             $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   2056:             if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
                   2057:                 my $relpath = $1;
                   2058:                 if ($relpath ne '') {
                   2059:                     my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
                   2060:                     my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
                   2061:                     my $newprefix = $newloc;
                   2062:                     if ($newloc eq 'default') {
                   2063:                         $newprefix = 'docs';
                   2064:                     }
                   2065:                     if ($newdocsdir eq '') {
                   2066:                         $newdocsdir = 'default';
                   2067:                     }
1.630     raeburn  2068:                     if (($prefixchg{$suffix}) ||
                   2069:                         ($srcdom{$suffix} ne $coursedom) ||
1.538     raeburn  2070:                         ($srcnum{$suffix} ne $coursenum) ||
                   2071:                         ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
                   2072:                         my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
                   2073:                         $url =
                   2074:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
                   2075:                                                                &Apache::lonnet::getfile($oldurl));
                   2076:                         if ($url eq '/adm/notfound.html') {
                   2077:                             $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
                   2078:                             next;
                   2079:                         } else {
                   2080:                             my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
                   2081:                             $newsubpath =~ s{/+$}{/};
                   2082:                             $docmoves{$oldurl} = $newsubpath;
                   2083:                         }
1.491     raeburn  2084:                     }
                   2085:                 }
1.597     raeburn  2086:             } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   2087:                 my $template = $1;
                   2088:                 if ($newidx) {
                   2089:                     &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
                   2090:                                           $coursedom,$coursenum,$template,$newidx,"$folder.$container");
                   2091:                 }
1.649     raeburn  2092:             } elsif ($url =~ /ext\.tool$/) {
1.655     raeburn  2093:                 if (($newidx) && ($folder=~/^default/)) {
1.649     raeburn  2094:                     my $marker = (split(m{/},$url))[4];
                   2095:                     my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
                   2096:                     my $val = 'no';
                   2097:                     if ($toolsettings{'gradable'}) {
                   2098:                         $val = 'yes';
                   2099:                     }
                   2100:                     &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
                   2101:                                                   'string_yesno');
                   2102:                     &remember_parms($newidx,'gradable','set',$val);
                   2103:                 }
1.491     raeburn  2104:             }
1.538     raeburn  2105:             $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   2106:                                               ':'.$ext.':normal:res';
                   2107:             push(@LONCAPA::map::order,$newidx);
                   2108: # Store the result
                   2109:             my ($errtext,$fatal) =
                   2110:                 &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   2111:             if ($fatal) {
                   2112:                 $save_err .= $errtext;
                   2113:                 $allresult = 'fail';
                   2114:             }
1.488     raeburn  2115:         }
1.538     raeburn  2116: 
1.597     raeburn  2117: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
                   2118: # resourcedata for simpleproblems copied from another course 
1.538     raeburn  2119:         unless ($allresult eq 'fail') {
                   2120:             my %updated = (
                   2121:                             rewrites      => \%rewrites,
                   2122:                             zombies       => \%zombies,
                   2123:                             removefrommap => \%removefrommap,
                   2124:                             removeparam   => \%removeparam,
                   2125:                             dbcopies      => \%dbcopies,
1.597     raeburn  2126:                             resdatacopy   => \%resdatacopy,
1.538     raeburn  2127:                             retitles      => \%retitles,
                   2128:                           );
                   2129:             my %info = (
                   2130:                            newsubdir => \%newsubdir,
                   2131:                            params    => \%params,
                   2132:                        );
                   2133:             if ($prefixchg{$suffix}) {
                   2134:                 $info{'before'} = $before{$prefixchg{$suffix}};
                   2135:                 $info{'after'} = $after{$prefixchg{$suffix}};
                   2136:             }
                   2137:             my %moves = (
                   2138:                            copies   => \%copies,
                   2139:                            docmoves => \%docmoves,
                   2140:                            mapmoves => \%mapmoves,
                   2141:                         );
                   2142:             (my $result,$msgs{$suffix},my $lockerror) =
                   2143:                 &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
                   2144:                               \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
                   2145:                               $url,'paste');
                   2146:             $lockerrors .= $lockerror;
                   2147:             if ($result eq 'ok') {
                   2148:                 if ($is_map{$suffix}) {
                   2149:                     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   2150:                                                     $folder.'.'.$container);
                   2151:                     if ($fatal) {
                   2152:                         $allresult = 'failread';
                   2153:                     } else {
                   2154:                         if ($#LONCAPA::map::order<1) {
                   2155:                             my $idx=&LONCAPA::map::getresidx();
                   2156:                             if ($idx<=0) { $idx=1; }
                   2157:                             $LONCAPA::map::order[0]=$idx;
                   2158:                             $LONCAPA::map::resources[$idx]='';
                   2159:                         }
                   2160:                         my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   2161:                         $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   2162:                                                           ':'.$ext.':normal:res';
                   2163:                         push(@LONCAPA::map::order,$newidx);
1.492     raeburn  2164: 
                   2165: # Store the result
1.538     raeburn  2166:                         my ($errtext,$fatal) = 
                   2167:                             &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   2168:                         if ($fatal) {
                   2169:                             $save_err .= $errtext;
                   2170:                             $allresult = 'failstore';
                   2171:                         }
                   2172:                     } 
                   2173:                 }
                   2174:                 if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   2175:                      push(@toclear,$suffix);
                   2176:                 }
                   2177:             }
1.492     raeburn  2178:         }
                   2179:     }
1.538     raeburn  2180:     &clear_from_buffer(\@toclear,\@currpaste);
                   2181:     my $msgsarray;
                   2182:     foreach my $suffix (keys(%msgs)) {
                   2183:          if (ref($msgs{$suffix}) eq 'ARRAY') {
                   2184:              $msgsarray .= join(',',@{$msgs{$suffix}});
                   2185:          }
                   2186:     }
                   2187:     return ($allresult,$save_err,$msgsarray,$lockerrors);
                   2188: }
1.533     raeburn  2189: 
1.538     raeburn  2190: sub do_buffer_empty {
                   2191:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   2192:     if (@currpaste == 0) {
                   2193:         return &mt('Clipboard is already empty');
                   2194:     }
                   2195:     my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
                   2196:     if (@toclear == 0) {
                   2197:         return &mt('Nothing selected to clear from clipboard');
                   2198:     }
                   2199:     my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
                   2200:     if ($numdel) {
                   2201:         return &mt('[quant,_1,item] cleared from clipboard',$numdel);
                   2202:     } else {
                   2203:         return &mt('Clipboard unchanged');
1.492     raeburn  2204:     }
1.538     raeburn  2205:     return;
                   2206: }
                   2207: 
                   2208: sub clear_from_buffer {
                   2209:     my ($toclear,$currpaste) = @_;
                   2210:     return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
                   2211:     my %pastebuffer;
                   2212:     map { $pastebuffer{$_} = 1; } @{$currpaste};
                   2213:     my $numdel = 0;
                   2214:     foreach my $suffix (@{$toclear}) {
                   2215:         next if ($suffix =~ /\D/);
                   2216:         next unless (exists($pastebuffer{$suffix}));
                   2217:         my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
                   2218:         if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
                   2219:             delete($pastebuffer{$suffix});
                   2220:             $numdel ++;
                   2221:         }
                   2222:     }
                   2223:     my $newbuffer = join(',',sort(keys(%pastebuffer)));
                   2224:     &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
                   2225:     return $numdel;
1.492     raeburn  2226: }
                   2227: 
                   2228: sub get_newmap_url {
                   2229:     my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
                   2230:         $titleref,$allmaps,$newurls) = @_;
                   2231:     my $newurl;
                   2232:     if ($url=~ m{^/uploaded/}) {
                   2233:         $$titleref=&mt('Copy of').' '.$$titleref;
                   2234:     }
                   2235:     my $now = time;
                   2236:     my $suffix=$$.int(rand(100)).$now;
                   2237:     my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
                   2238:     if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
                   2239:         my $path = $1;
                   2240:         my $prefix = $2;
                   2241:         my $ancestor = $3;
                   2242:         if (length($ancestor) > 10) {
                   2243:             $ancestor = substr($ancestor,-10,10);
                   2244:         }
                   2245:         my $newid;
                   2246:         if ($prefixchg) {
                   2247:             if ($folder =~ /^supplemental/) {
                   2248:                 $prefix =~ s/^default/supplemental/;
                   2249:             } else {
                   2250:                 $prefix =~ s/^supplemental/default/;
                   2251:             }
                   2252:         }
                   2253:         if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   2254:             $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   2255:         } else {
                   2256:             $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
                   2257:         }
                   2258:         my $counter = 0;
                   2259:         my $is_unique = &uniqueness_check($newurl);
                   2260:         if ($folder =~ /^default/) {
                   2261:             if ($allmaps->{$newurl}) {
                   2262:                 $is_unique = 0;
                   2263:             }
                   2264:         }
                   2265:         while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
                   2266:             $counter ++;
                   2267:             $suffix ++;
                   2268:             if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   2269:                 $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   2270:             } else {
                   2271:                 $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
                   2272:             }
                   2273:             $is_unique = &uniqueness_check($newurl);
                   2274:         }
                   2275:         if ($is_unique) {
                   2276:             $newurls->{$newurl} = 1;
                   2277:         } else {
                   2278:             if ($url=~/\.page$/) {
                   2279:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
                   2280:             } else {
                   2281:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
                   2282:             }
                   2283:         }
1.329     droeschl 2284:     }
1.492     raeburn  2285:     return ($newurl);
1.329     droeschl 2286: }
                   2287: 
1.488     raeburn  2288: sub dbcopy {
1.533     raeburn  2289:     my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
                   2290:     my ($url,$result,$errtext);
                   2291:     if (ref($dbref) eq 'HASH') {
1.596     raeburn  2292:         $url = $dbref->{'src'};
1.627     raeburn  2293:         if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533     raeburn  2294:             my $prefix = $1;
1.627     raeburn  2295:             if ($prefix eq 'ext.tool') {
                   2296:                 $prefix = 'exttool';
                   2297:             }
1.533     raeburn  2298:             if (($dbref->{'cdom'} =~ /^$match_domain$/) && 
                   2299:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   2300:                 my $db_name;
                   2301:                 my $marker = (split(m{/},$url))[4];
                   2302:                 $marker=~s/\D//g;
                   2303:                 if ($dbref->{'src'} =~ m{/smppg$}) {
                   2304:                     $db_name =
                   2305:                         &Apache::lonsimplepage::get_db_name($url,$marker,
                   2306:                                                             $dbref->{'cdom'},
                   2307:                                                             $dbref->{'cnum'});
1.627     raeburn  2308:                 } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
                   2309:                     $db_name = 'exttool_'.$marker;
1.533     raeburn  2310:                 } else {
                   2311:                     $db_name = 'bulletinpage_'.$marker;
                   2312:                 }
                   2313:                 my ($suffix,$freedlock,$error) =
                   2314:                     &Apache::lonnet::get_timebased_id($prefix,'num','templated',
                   2315:                                                       $coursedom,$coursenum,
                   2316:                                                       'concat');
                   2317:                 if (!$suffix) {
                   2318:                     if ($prefix eq 'smppg') {
                   2319:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631     raeburn  2320:                     } elsif ($prefix eq 'exttool') {
                   2321:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533     raeburn  2322:                     } else {
1.565     bisitz   2323:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533     raeburn  2324:                     }
                   2325:                     if ($error) {
                   2326:                         $errtext .= '<br />'.$error;
                   2327:                     }
                   2328:                 } else {
                   2329:                     #need to copy the db contents to a new one.
                   2330:                     my %contents=&Apache::lonnet::dump($db_name,
                   2331:                                                        $dbref->{'cdom'},
                   2332:                                                        $dbref->{'cnum'});
                   2333:                     if (exists($contents{'uploaded.photourl'})) {
                   2334:                         my $photo = $contents{'uploaded.photourl'};
                   2335:                         my ($subdir,$fname) =
                   2336:                             ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596     raeburn  2337:                         my $newphoto;
1.533     raeburn  2338:                         if ($fname ne '') {
                   2339:                             my $content = &Apache::lonnet::getfile($photo);
                   2340:                             unless ($content eq '-1') {
                   2341:                                 $env{'form.'.$suffix.'.photourl'} = $content;
                   2342:                                 $newphoto = 
                   2343:                                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
                   2344:                                 delete($env{'form.'.$suffix.'.photourl'});
                   2345:                             }
                   2346:                         }
                   2347:                         if ($newphoto =~ m{^/uploaded/}) {
                   2348:                             $contents{'uploaded.photourl'} = $newphoto;
                   2349:                         }
                   2350:                     }
                   2351:                     $db_name =~ s{_\d*$ }{_$suffix}x;
1.649     raeburn  2352:                     if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
                   2353:                         delete($contents{'gradable'});
                   2354:                     }
1.533     raeburn  2355:                     $result=&Apache::lonnet::put($db_name,\%contents,
                   2356:                                                  $coursedom,$coursenum);
                   2357:                     if ($result eq 'ok') {
1.627     raeburn  2358:                         $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533     raeburn  2359:                     }
                   2360:                 }
                   2361:                 if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559     raeburn  2362:                     $lockerrorsref->{$prefix} =
1.533     raeburn  2363:                         '<div class="LC_error">'.
                   2364:                         &mt('There was a problem removing a lockfile.');
                   2365:                     if ($prefix eq 'smppg') {
1.560     raeburn  2366:                         $lockerrorsref->{$prefix} .=
1.559     raeburn  2367:                             ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627     raeburn  2368:                     } elsif ($prefix eq 'exttool') {
                   2369:                         $lockerrorsref->{$prefix} .=
                   2370:                             ' '.&mt('This will prevent addition of more external tools to this course.');
1.533     raeburn  2371:                     } else {
1.565     bisitz   2372:                         $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  2373:                     }
1.560     raeburn  2374:                     $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   2375:                                                      '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
                   2376:                                                  '</div>';
1.533     raeburn  2377:                 }
                   2378:             }
                   2379:         } elsif ($url =~ m{/syllabus$}) {
                   2380:             if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
                   2381:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   2382:                 if (($dbref->{'cdom'} ne $coursedom) ||
                   2383:                     ($dbref->{'cnum'} ne $coursenum)) {
                   2384:                     my %contents=&Apache::lonnet::dump('syllabus',
                   2385:                                                        $dbref->{'cdom'},
                   2386:                                                        $dbref->{'cnum'});
                   2387:                     $result=&Apache::lonnet::put('syllabus',\%contents,
                   2388:                                                  $coursedom,$coursenum);
                   2389:                 }
                   2390:             }
1.488     raeburn  2391:         }
                   2392:     }
1.533     raeburn  2393:     return ($url,$result,$errtext);
1.488     raeburn  2394: }
                   2395: 
1.597     raeburn  2396: sub copy_templated_files {
                   2397:     my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
                   2398:     my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
                   2399:     my $srccontainer = 'sequence';
                   2400:     if ($srcwaspage) {
                   2401:         $srccontainer = 'page';
                   2402:     }
                   2403:     my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
                   2404:                   '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
                   2405:     my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
                   2406:     my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
                   2407:     my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
                   2408:                   $template.'.problem';
                   2409:     my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
                   2410:     if ($template eq 'simpleproblem') {
                   2411:         $srcprefix .= '.0.';
                   2412:         my $weightprefix = $newprefix;
                   2413:         $newprefix .= '.0.';
                   2414:         my @simpleprobqtypes = qw(radio option string essay numerical);
                   2415:         my $qtype=$srcparms{$srcprefix.'questiontype'};
                   2416:         if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665     raeburn  2417:             my %newdata = (
                   2418:                 $newprefix.'questiontype' => $qtype,
                   2419:             );
1.597     raeburn  2420:             foreach my $type (@simpleprobqtypes) {
                   2421:                 if ($type eq $qtype) {
                   2422:                     $newdata{"$weightprefix.$type.weight"}=1;
                   2423:                 } else {
                   2424:                     $newdata{"$weightprefix.$type.weight"}=0;
                   2425:                 }
                   2426:             }
                   2427:             $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
                   2428:             $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
                   2429:             $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
                   2430:             if ($qtype eq 'numerical') {
                   2431:                 $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
                   2432:                 $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
                   2433:                 $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
                   2434:                 $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
                   2435:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   2436:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   2437:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   2438:                     unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   2439:                         if ($maxfoils<=0) { $maxfoils=10; }
                   2440:                             my $randomize=$srcparms{$srcprefix.'randomize'};
                   2441:                             unless (defined($randomize)) { $randomize='yes'; }
                   2442:                             unless ($randomize eq 'no') { $randomize='yes'; }
                   2443:                             $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   2444:                             $newdata{$newprefix.'randomize'} = $randomize;
                   2445:                             if ($qtype eq 'option') {
                   2446:                                 $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   2447:                             }
                   2448:                             for (my $i=1; $i<=10; $i++) {
                   2449:                                 $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   2450:                                 $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   2451:                                 $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   2452:                             }
                   2453: 
                   2454:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   2455:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   2456:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   2457:                 unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   2458:                 if ($maxfoils<=0) { $maxfoils=10; }
                   2459:                 my $randomize=$srcparms{$srcprefix.'randomize'};
                   2460:                 unless (defined($randomize)) { $randomize='yes'; }
                   2461:                 unless ($randomize eq 'no') { $randomize='yes'; }
                   2462:                 $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   2463:                 $newdata{$newprefix.'randomize'} = $randomize;
                   2464:                 if ($qtype eq 'option') {
                   2465:                     $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   2466:                 }
                   2467:                 for (my $i=1; $i<=10; $i++) {
                   2468:                     $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   2469:                     $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   2470:                     $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   2471:                 }
                   2472:             } elsif ($qtype eq 'string') {
                   2473:                 $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
                   2474:                 $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
                   2475:             }
                   2476:             if (keys(%newdata)) {
                   2477:                 my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
                   2478:                                                    $coursenum);
                   2479:                 if ($putres eq 'ok') {
                   2480:                     &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
                   2481:                 }
                   2482:             }
                   2483:         }
                   2484:     }
                   2485: }
                   2486: 
1.329     droeschl 2487: sub uniqueness_check {
                   2488:     my ($newurl) = @_;
                   2489:     my $unique = 1;
                   2490:     foreach my $res (@LONCAPA::map::order) {
                   2491:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   2492:         $url=&LONCAPA::map::qtescape($url);
                   2493:         if ($newurl eq $url) {
                   2494:             $unique = 0;
1.344     bisitz   2495:             last;
1.329     droeschl 2496:         }
                   2497:     }
                   2498:     return $unique;
                   2499: }
                   2500: 
1.488     raeburn  2501: sub contained_map_check {
1.627     raeburn  2502:     my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
                   2503:         $hierarchy,$titles,$allmaps) = @_;
1.488     raeburn  2504:     my $content = &Apache::lonnet::getfile($url);
                   2505:     unless ($content eq '-1') {
                   2506:         my $parser = HTML::TokeParser->new(\$content);
                   2507:         $parser->attr_encoded(1);
                   2508:         while (my $token = $parser->get_token) {
                   2509:             next if ($token->[0] ne 'S');
                   2510:             if ($token->[1] eq 'resource') {
                   2511:                 next if ($token->[2]->{'type'} eq 'zombie');
                   2512:                 my $ressrc = $token->[2]->{'src'};
1.627     raeburn  2513:                 if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
                   2514:                     my $srcdom = $1;
                   2515:                     unless ($srcdom eq $coursedom) {
                   2516:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2517:                         next;
                   2518:                     }
                   2519:                 } elsif ($folder =~ /^supplemental/) {
1.488     raeburn  2520:                     unless (&supp_pasteable($ressrc)) {
1.492     raeburn  2521:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488     raeburn  2522:                         next;
                   2523:                     }
                   2524:                 }
1.492     raeburn  2525:                 if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
                   2526:                     if ($1 eq 'uploaded') {
                   2527:                         $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2528:                         $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488     raeburn  2529:                     } else {
1.492     raeburn  2530:                         if ($allmaps->{$ressrc}) {
1.529     raeburn  2531:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492     raeburn  2532:                         } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
                   2533:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2534:                         } else {
                   2535:                             $addedmaps->{$ressrc} = [$url];
                   2536:                         }
1.488     raeburn  2537:                     }
1.627     raeburn  2538:                     &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
                   2539:                                          $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488     raeburn  2540:                 }
1.492     raeburn  2541:             } elsif ($token->[1] eq 'param') {
1.488     raeburn  2542:                 if ($folder =~ /^supplemental/) {
1.492     raeburn  2543:                     if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
                   2544:                         push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
                   2545:                     } else {
                   2546:                         $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}]; 
                   2547:                     }
1.488     raeburn  2548:                 }
                   2549:             }
                   2550:         }
                   2551:     }
                   2552:     return;
                   2553: }
                   2554: 
                   2555: sub url_paste_fixups {
1.533     raeburn  2556:     my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
                   2557:         $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597     raeburn  2558:         $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491     raeburn  2559:     my $checktitle;
                   2560:     if (($prefixchg) &&
1.492     raeburn  2561:         ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491     raeburn  2562:         $checktitle = 1;
                   2563:     }
1.492     raeburn  2564:     my $skip;
                   2565:     if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
                   2566:         my $mapid = $1.$2;
                   2567:         if ($tomove->{$mapid}) {
                   2568:             $skip = 1;
                   2569:         }
                   2570:     }
1.491     raeburn  2571:     my $file = &Apache::lonnet::getfile($oldurl);
1.488     raeburn  2572:     return if ($file eq '-1');
                   2573:     my $parser = HTML::TokeParser->new(\$file);
                   2574:     $parser->attr_encoded(1);
1.491     raeburn  2575:     my $changed = 0;
1.488     raeburn  2576:     while (my $token = $parser->get_token) {
                   2577:         next if ($token->[0] ne 'S');
                   2578:         if ($token->[1] eq 'resource') {
                   2579:             my $ressrc = $token->[2]->{'src'};
                   2580:             next if ($ressrc eq '');
1.491     raeburn  2581:             my $id = $token->[2]->{'id'};
1.492     raeburn  2582:             my $title = $token->[2]->{'title'};
1.491     raeburn  2583:             if ($checktitle) {
                   2584:                 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  2585:                     $retitles->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2586:                 }
                   2587:             }
1.488     raeburn  2588:             next if ($token->[2]->{'type'} eq 'external');
                   2589:             if ($token->[2]->{'type'} eq 'zombie') {
1.492     raeburn  2590:                 next if ($skip);  
1.532     raeburn  2591:                 $zombies->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2592:                 $changed = 1;
                   2593:             } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  2594:                 my $srcdom = $1;
                   2595:                 my $srcnum = $2;
1.488     raeburn  2596:                 my $rem = $3;
1.492     raeburn  2597:                 my $newurl;
                   2598:                 my $mapname;
                   2599:                 if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
                   2600:                     my $prefix = $1;
                   2601:                     $mapname = $prefix.$2;
                   2602:                     if ($tomove->{$mapname}) {
1.533     raeburn  2603:                         &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   2604:                                           $srcdom,$srcnum,$allmaps,$rewrites,
                   2605:                                           $retitles,$copies,$dbcopies,$zombies,
                   2606:                                           $params,$mapmoves,$mapchanges,$tomove,
1.597     raeburn  2607:                                           $newsubdir,$newurls,$resdatacopy);
1.492     raeburn  2608:                         next;
                   2609:                     } else {
                   2610:                         ($newurl,my $error) =
                   2611:                             &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   2612:                                             $srcdom,$srcnum,\$title,$allmaps,$newurls);
                   2613:                         if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
                   2614:                             $newsubdir->{$ressrc} = $1;
                   2615:                         }
                   2616:                         if ($error) {
                   2617:                             next;
                   2618:                         }
                   2619:                     }
                   2620:                 }
                   2621:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
                   2622:                     ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
                   2623:                    
1.488     raeburn  2624:                     if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532     raeburn  2625:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2626:                         $mapchanges->{$ressrc} = 1;
1.533     raeburn  2627:                         unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
                   2628:                                                   $cnum,$srcdom,$srcnum,$allmaps,
                   2629:                                                   $rewrites,$retitles,$copies,$dbcopies,
                   2630:                                                   $zombies,$params,$mapmoves,$mapchanges,
1.597     raeburn  2631:                                                   $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491     raeburn  2632:                             $mapmoves->{$ressrc} = 1;
                   2633:                         }
                   2634:                         $changed = 1;
1.488     raeburn  2635:                     } else {
1.532     raeburn  2636:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.488     raeburn  2637:                         $copies->{$oldurl}{$ressrc} = $id;
1.491     raeburn  2638:                         $changed = 1;
1.488     raeburn  2639:                     }
                   2640:                 }
1.649     raeburn  2641:             } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533     raeburn  2642:                 next if ($skip);
1.492     raeburn  2643:                 my $srcdom = $1;
                   2644:                 my $srcnum = $2;
1.649     raeburn  2645:                 my $rem = $3;
                   2646:                 my ($is_exttool,$exttoolchg);
                   2647:                 if ($rem =~ m{\d+/ext\.tool$}) {
1.655     raeburn  2648:                     $is_exttool = 1;
1.649     raeburn  2649:                 }
1.492     raeburn  2650:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532     raeburn  2651:                     $rewrites->{$oldurl}{$id} = $ressrc;
1.533     raeburn  2652:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2653:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2654:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   2655:                     $changed = 1;
1.649     raeburn  2656:                     if ($is_exttool) {
                   2657:                         $exttoolchg = 1;
                   2658:                     }
1.700   ! raeburn  2659:                 } elsif (($is_exttool) &&
1.649     raeburn  2660:                          ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   2661:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2662:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2663:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   2664:                     $changed = 1;
                   2665:                     $exttoolchg = 1;
                   2666:                 }
                   2667:                 if (($is_exttool) && ($prefixchg)) {
                   2668:                     if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
                   2669:                         if ($exttoolchg) {
                   2670:                             $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
                   2671:                         }
                   2672:                     }
1.533     raeburn  2673:                 }
                   2674:             } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
                   2675:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
                   2676:                     ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   2677:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2678:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   2679:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491     raeburn  2680:                     $changed = 1;
1.488     raeburn  2681:                 }
1.597     raeburn  2682:             } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
                   2683:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
                   2684:                     $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
                   2685:                     $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   2686:                     $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
                   2687:                 }
1.488     raeburn  2688:             } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  2689:                 next if ($skip);
                   2690:                 my $srcdom = $1;
                   2691:                 my $srcnum = $2;
                   2692:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533     raeburn  2693:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2694:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2695:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491     raeburn  2696:                     $changed = 1;
1.488     raeburn  2697:                 }
                   2698:             }
                   2699:         } elsif ($token->[1] eq 'param') {
1.492     raeburn  2700:             next if ($skip);
1.488     raeburn  2701:             my $to = $token->[2]->{'to'}; 
                   2702:             if ($to ne '') {
                   2703:                 if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492     raeburn  2704:                     push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488     raeburn  2705:                 } else {
                   2706:                     @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
                   2707:                 }
                   2708:             }
                   2709:         }
                   2710:     }
1.491     raeburn  2711:     return $changed;
1.488     raeburn  2712: }
                   2713: 
                   2714: sub apply_fixups {
1.529     raeburn  2715:     my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
                   2716:         $oldurl,$url,$caller) = @_;
                   2717:     my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533     raeburn  2718:         %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597     raeburn  2719:         %resdatacopy,%lockerrors,$lockmsg);
1.529     raeburn  2720:     if (ref($updated) eq 'HASH') {
                   2721:         if (ref($updated->{'rewrites'}) eq 'HASH') {
                   2722:             %rewrites = %{$updated->{'rewrites'}};
                   2723:         }
                   2724:         if (ref($updated->{'zombies'}) eq 'HASH') {
                   2725:             %zombies = %{$updated->{'zombies'}};
                   2726:         }
                   2727:         if (ref($updated->{'removefrommap'}) eq 'HASH') {
                   2728:             %removefrommap = %{$updated->{'removefrommap'}};
                   2729:         }
                   2730:         if (ref($updated->{'removeparam'}) eq 'HASH') {
                   2731:             %removeparam = %{$updated->{'removeparam'}};
                   2732:         }
                   2733:         if (ref($updated->{'dbcopies'}) eq 'HASH') {
                   2734:             %dbcopies = %{$updated->{'dbcopies'}};
                   2735:         }
                   2736:         if (ref($updated->{'retitles'}) eq 'HASH') {
                   2737:             %retitles = %{$updated->{'retitles'}};
                   2738:         }
1.597     raeburn  2739:         if (ref($updated->{'resdatacopy'}) eq 'HASH') {
                   2740:             %resdatacopy = %{$updated->{'resdatacopy'}};
                   2741:         }
1.529     raeburn  2742:     }
                   2743:     if (ref($info) eq 'HASH') {
                   2744:         if (ref($info->{'newsubdir'}) eq 'HASH') {
                   2745:             %newsubdir = %{$info->{'newsubdir'}};
                   2746:         }
                   2747:         if (ref($info->{'params'}) eq 'HASH') {
                   2748:             %params = %{$info->{'params'}};
                   2749:         }
                   2750:         if (ref($info->{'before'}) eq 'HASH') {
                   2751:             %before = %{$info->{'before'}};
                   2752:         }
                   2753:         if (ref($info->{'after'}) eq 'HASH') {
                   2754:             %after = %{$info->{'after'}};
                   2755:         }
                   2756:     }
                   2757:     if (ref($moves) eq 'HASH') {
                   2758:         if (ref($moves->{'copies'}) eq 'HASH') {
                   2759:             %copies = %{$moves->{'copies'}};
                   2760:         }
                   2761:         if (ref($moves->{'docmoves'}) eq 'HASH') {
                   2762:             %docmoves = %{$moves->{'docmoves'}};
                   2763:         }
                   2764:         if (ref($moves->{'mapmoves'}) eq 'HASH') {
                   2765:             %mapmoves = %{$moves->{'mapmoves'}};
                   2766:         }
                   2767:     }
                   2768:     foreach my $key (keys(%copies),keys(%docmoves)) {
1.491     raeburn  2769:         my @allcopies;
1.529     raeburn  2770:         if (exists($copies{$key})) {
                   2771:             if (ref($copies{$key}) eq 'HASH') {
                   2772:                 my %added;
                   2773:                 foreach my $innerkey (keys(%{$copies{$key}})) {
                   2774:                     if (($innerkey ne '') && (!$added{$innerkey})) {
                   2775:                         push(@allcopies,$innerkey);
                   2776:                         $added{$innerkey} = 1;
                   2777:                     }
1.491     raeburn  2778:                 }
1.529     raeburn  2779:                 undef(%added);
1.491     raeburn  2780:             }
                   2781:         }
                   2782:         if ($key eq $oldurl) {
1.529     raeburn  2783:             if ((exists($docmoves{$key}))) {
1.532     raeburn  2784:                 unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491     raeburn  2785:                     push(@allcopies,$oldurl);
                   2786:                 }
                   2787:             }
                   2788:         }
                   2789:         if (@allcopies > 0) {
                   2790:             foreach my $item (@allcopies) {
1.492     raeburn  2791:                 my ($relpath,$oldsubdir,$fname) = 
                   2792:                     ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491     raeburn  2793:                 if ($fname ne '') {
                   2794:                     my $content = &Apache::lonnet::getfile($item);
                   2795:                     unless ($content eq '-1') {
                   2796:                         my $storefn;
1.529     raeburn  2797:                         if (($key eq $oldurl) && (exists($docmoves{$key}))) {
                   2798:                             $storefn = $docmoves{$key};
1.491     raeburn  2799:                         } else {
                   2800:                             $storefn = $relpath;
                   2801:                             $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  2802:                             if ($prefixchg && $before{'doc'} && $after{'doc'}) {
                   2803:                                 $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491     raeburn  2804:                             }
1.529     raeburn  2805:                             if ($newsubdir{$key}) {
1.532     raeburn  2806:                                 $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491     raeburn  2807:                             }
                   2808:                         }
                   2809:                         &copy_dependencies($item,$storefn,$relpath,$errors,\$content);
                   2810:                         my $copyurl = 
                   2811:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},
                   2812:                                                                $storefn.$fname,$content);
                   2813:                         if ($copyurl eq '/adm/notfound.html') {
1.529     raeburn  2814:                             if (exists($docmoves{$oldurl})) {
1.491     raeburn  2815:                                 return &mt('Paste failed: an error occurred copying the file.');
                   2816:                             } elsif (ref($errors) eq 'HASH') {
                   2817:                                 $errors->{$item} = 1;
1.489     raeburn  2818:                             }
                   2819:                         }
1.488     raeburn  2820:                     }
                   2821:                 }
1.491     raeburn  2822:             }
                   2823:         }
                   2824:     }
1.529     raeburn  2825:     foreach my $key (keys(%mapmoves)) {
1.491     raeburn  2826:         my $storefn=$key;
                   2827:         $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  2828:         if ($prefixchg && $before{'map'} && $after{'map'}) {
                   2829:             $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  2830:         }
1.529     raeburn  2831:         if ($newsubdir{$key}) {
                   2832:             $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  2833:         }
1.491     raeburn  2834:         my $mapcontent = &Apache::lonnet::getfile($key);
1.681     raeburn  2835:         if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
                   2836:             ($after{'map'} eq 'default') &&
                   2837:             ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
                   2838:             $mapcontent = '<map>'."\n".
                   2839:                           '<resource id="1" src="" type="start" />'."\n".
                   2840:                           '<link from="1" to="2" index="1" />'."\n".
                   2841:                           '<resource id="2" src="" type="finish" />'."\n".
                   2842:                           '</map>';
                   2843:         }
1.491     raeburn  2844:         if ($mapcontent eq '-1') {
                   2845:             if (ref($errors) eq 'HASH') {
                   2846:                 $errors->{$key} = 1;
                   2847:             }
                   2848:         } else {
                   2849:             my $newmap =
                   2850:                 &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
                   2851:                                                    $mapcontent);
                   2852:             if ($newmap eq '/adm/notfound.html') {
                   2853:                 if (ref($errors) eq 'HASH') {
                   2854:                     $errors->{$key} = 1;
1.489     raeburn  2855:                 }
1.488     raeburn  2856:             }
                   2857:         }
                   2858:     }
1.491     raeburn  2859:     my %updates;
                   2860:     if ($is_map) {
1.529     raeburn  2861:         if (ref($updated) eq 'HASH') {
                   2862:             foreach my $type (keys(%{$updated})) {
                   2863:                 if (ref($updated->{$type}) eq 'HASH') {
                   2864:                     foreach my $key (keys(%{$updated->{$type}})) {
                   2865:                         $updates{$key} = 1;
                   2866:                     }
                   2867:                 }
                   2868:             }
1.491     raeburn  2869:         }
                   2870:         foreach my $key (keys(%updates)) {
1.492     raeburn  2871:             my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529     raeburn  2872:             if (ref($rewrites{$key}) eq 'HASH') {
                   2873:                 %torewrite = %{$rewrites{$key}};
1.491     raeburn  2874:             }
1.529     raeburn  2875:             if (ref($retitles{$key}) eq 'HASH') {
                   2876:                 %toretitle = %{$retitles{$key}};
1.491     raeburn  2877:             }
1.529     raeburn  2878:             if (ref($removefrommap{$key}) eq 'HASH') {
                   2879:                 %toremove = %{$removefrommap{$key}};
1.491     raeburn  2880:             }
1.529     raeburn  2881:             if (ref($removeparam{$key}) eq 'HASH') {
                   2882:                 %remparam = %{$removeparam{$key}};
1.492     raeburn  2883:             }
1.529     raeburn  2884:             if (ref($zombies{$key}) eq 'HASH') {
                   2885:                 %zombie = %{$zombies{$key}};
1.491     raeburn  2886:             }
1.529     raeburn  2887:             if (ref($dbcopies{$key}) eq 'HASH') {
1.533     raeburn  2888:                 foreach my $idx (keys(%{$dbcopies{$key}})) {
                   2889:                     if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
                   2890:                         my ($newurl,$result,$errtext) =
                   2891:                             &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
                   2892:                         if ($result eq 'ok') {
                   2893:                             $newdb{$idx} = $newurl;
                   2894:                         } elsif (ref($errors) eq 'HASH') {
                   2895:                             $errors->{$key} = 1;
                   2896:                         }
                   2897:                         push(@msgs,$errtext);
                   2898:                     }
1.491     raeburn  2899:                 }
                   2900:             }
1.597     raeburn  2901:             if (ref($resdatacopy{$key}) eq 'HASH') {
1.664     raeburn  2902:                 my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597     raeburn  2903:                 foreach my $idx (keys(%{$resdatacopy{$key}})) {
                   2904:                     if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
                   2905:                         my $srcurl = $resdatacopy{$key}{$idx}{'src'};
                   2906:                         if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   2907:                             my $template = $1;
                   2908:                             if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
                   2909:                                 ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
                   2910:                                 my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
                   2911:                                 my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664     raeburn  2912:                                 unless ($gotnewmapname) {
                   2913:                                     ($newmapname) = ($key =~ m{/([^/]+)$});
                   2914:                                     ($srcfolder,$srccontainer) = split(/\./,$newmapname);
                   2915:                                     if ($newsubdir{$key}) {
                   2916:                                         $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
                   2917:                                     }
                   2918:                                     $gotnewmapname = 1;
                   2919:                                 }
1.597     raeburn  2920:                                 my $srcmapinfo = $srcfolder.':'.$idx;
                   2921:                                 if ($srccontainer eq 'page') {
                   2922:                                     $srcmapinfo .= ':1';
                   2923:                                 }
                   2924:                                 &copy_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
                   2925:                                                       $cnum,$template,$idx,$newmapname);
                   2926:                             }
                   2927:                         }
                   2928:                     }
                   2929:                 }
                   2930:             }
1.529     raeburn  2931:             if (ref($params{$key}) eq 'HASH') {
                   2932:                 %currparam = %{$params{$key}};
1.492     raeburn  2933:             }
                   2934:             my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
                   2935:             if ($fatal) {
1.533     raeburn  2936:                 return ($errtext);
1.492     raeburn  2937:             }
                   2938:             for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
                   2939:                 if (defined($LONCAPA::map::zombies[$i])) {
                   2940:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532     raeburn  2941:                     if ($zombie{$i} eq $src) {
1.492     raeburn  2942:                         undef($LONCAPA::map::zombies[$i]);
                   2943:                     }
                   2944:                 }
                   2945:             }
1.646     raeburn  2946:             my $total = scalar(@LONCAPA::map::order) - 1;
                   2947:             for (my $i=$total; $i>=0; $i--) {
1.529     raeburn  2948:                 my $idx = $LONCAPA::map::order[$i];
                   2949:                 if (defined($LONCAPA::map::resources[$idx])) {
1.492     raeburn  2950:                     my $changed;
1.529     raeburn  2951:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538     raeburn  2952:                     if ((exists($toremove{$idx})) && 
                   2953:                         ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492     raeburn  2954:                         splice(@LONCAPA::map::order,$i,1);
1.529     raeburn  2955:                         if (ref($currparam{$idx}) eq 'ARRAY') {
                   2956:                             foreach my $name (@{$currparam{$idx}}) {
1.647     raeburn  2957:                                 &LONCAPA::map::delparameter($idx,$name);
1.492     raeburn  2958:                             }
                   2959:                         }
                   2960:                         next;
                   2961:                     }
                   2962:                     my $origsrc = $src;
1.532     raeburn  2963:                     if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492     raeburn  2964:                         if ($title =~ m{^\d+\Q___&amp;&amp;&amp;___\E$match_username\Q___&amp;&amp;&amp;___\E$match_domain\Q___&amp;&amp;&amp;___\E(.+)$}) {
                   2965:                             $changed = 1;
1.491     raeburn  2966:                         }
1.492     raeburn  2967:                     }
1.532     raeburn  2968:                     if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492     raeburn  2969:                         $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
                   2970:                         if ($origsrc =~ m{^/uploaded/}) {
1.529     raeburn  2971:                             if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492     raeburn  2972:                                 if ($src =~ /\.(page|sequence)$/) {
1.529     raeburn  2973:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492     raeburn  2974:                                 } else {
1.529     raeburn  2975:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488     raeburn  2976:                                 }
1.491     raeburn  2977:                             }
1.532     raeburn  2978:                             if ($origsrc =~ /\.(page|sequence)$/) {
                   2979:                                 if ($newsubdir{$origsrc}) {
1.529     raeburn  2980:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491     raeburn  2981:                                 }
1.532     raeburn  2982:                             } elsif ($newsubdir{$key}) {
                   2983:                                 $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488     raeburn  2984:                             }
                   2985:                         }
1.492     raeburn  2986:                         $changed = 1;
1.533     raeburn  2987:                     } elsif ($newdb{$idx} ne '') {
                   2988:                         $src = $newdb{$idx};
1.492     raeburn  2989:                         $changed = 1;
                   2990:                     }
                   2991:                     if ($changed) {
1.538     raeburn  2992:                         $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492     raeburn  2993:                     }
                   2994:                 }
                   2995:             }
                   2996:             foreach my $idx (keys(%remparam)) {
                   2997:                 if (ref($remparam{$idx}) eq 'ARRAY') {
                   2998:                     foreach my $name (@{$remparam{$idx}}) {   
1.647     raeburn  2999:                         &LONCAPA::map::delparameter($idx,$name);
1.491     raeburn  3000:                     }
                   3001:                 }
                   3002:             }
1.533     raeburn  3003:             if (values(%lockerrors) > 0) {
                   3004:                 $lockmsg = join('<br />',values(%lockerrors));
                   3005:             }
1.491     raeburn  3006:             my $storefn;
                   3007:             if ($key eq $oldurl) {
                   3008:                 $storefn = $url;
                   3009:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
                   3010:             } else {
                   3011:                 $storefn = $key;
                   3012:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  3013:                 if ($prefixchg && $before{'map'} && $after{'map'}) {
                   3014:                     $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  3015:                 }
1.529     raeburn  3016:                 if ($newsubdir{$key}) {
                   3017:                     $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  3018:                 }
1.491     raeburn  3019:             }
1.492     raeburn  3020:             my $report;
                   3021:             if ($folder !~ /^supplemental/) {
                   3022:                 $report = 1;
                   3023:             }
1.527     raeburn  3024:             (my $outtext,$errtext) =
1.492     raeburn  3025:                 &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
                   3026:             if ($errtext) {
1.529     raeburn  3027:                 if ($caller eq 'paste') {
1.533     raeburn  3028:                     return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529     raeburn  3029:                 }
1.491     raeburn  3030:             }
                   3031:         }
                   3032:     }
1.533     raeburn  3033:     return ('ok',\@msgs,$lockmsg);
1.491     raeburn  3034: }
                   3035: 
                   3036: sub copy_dependencies {
                   3037:     my ($item,$storefn,$relpath,$errors,$contentref) = @_;
                   3038:     my $content;
                   3039:     if (ref($contentref)) {
                   3040:         $content = $$contentref;
                   3041:     } else {
                   3042:         $content = &Apache::lonnet::getfile($item);
                   3043:     }
                   3044:     unless ($content eq '-1') {
                   3045:         my $mm = new File::MMagic;
                   3046:         my $mimetype = $mm->checktype_contents($content);
                   3047:         if ($mimetype eq 'text/html') {
                   3048:             my (%allfiles,%codebase,$state);
                   3049:             my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
                   3050:             if ($res eq 'ok') {
                   3051:                 my ($numexisting,$numpathchanges,$existing);
                   3052:                 (undef,$numexisting,$numpathchanges,$existing) =
                   3053:                     &Apache::loncommon::ask_for_embedded_content(
                   3054:                         '/adm/coursedocs',$state,\%allfiles,\%codebase,
                   3055:                         {'error_on_invalid_names'   => 1,
                   3056:                          'ignore_remote_references' => 1,
                   3057:                          'docs_url'                 => $item,
                   3058:                          'context'                  => 'paste'});
                   3059:                 if ($numexisting > 0) {
                   3060:                     if (ref($existing) eq 'HASH') {
                   3061:                         foreach my $dep (keys(%{$existing})) {
                   3062:                             my $depfile = $dep;
                   3063:                             unless ($depfile =~ m{^\Q$relpath\E}) {
                   3064:                                 $depfile = $relpath.$dep;
                   3065:                             }
                   3066:                             my $depcontent = &Apache::lonnet::getfile($depfile);
                   3067:                             unless ($depcontent eq '-1') {
                   3068:                                 my $storedep = $dep;
                   3069:                                 $storedep =~ s{^\Q$relpath\E}{};
                   3070:                                 my $dep_url =
                   3071:                                     &Apache::lonclonecourse::writefile(
                   3072:                                         $env{'request.course.id'},
                   3073:                                         $storefn.$storedep,$depcontent);
                   3074:                                 if ($dep_url eq '/adm/notfound.html') {
                   3075:                                     if (ref($errors) eq 'HASH') {
                   3076:                                         $errors->{$depfile} = 1;
                   3077:                                     }
                   3078:                                 } else {
                   3079:                                     &copy_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
                   3080:                                 }
                   3081:                             }
                   3082:                         }
1.488     raeburn  3083:                     }
                   3084:                 }
                   3085:             }
                   3086:         }
                   3087:     }
                   3088:     return;
                   3089: }
                   3090: 
1.329     droeschl 3091: my %parameter_type = ( 'randompick'     => 'int_pos',
                   3092: 		       'hiddenresource' => 'string_yesno',
                   3093: 		       'encrypturl'     => 'string_yesno',
                   3094: 		       'randomorder'    => 'string_yesno',);
                   3095: my $valid_parameters_re = join('|',keys(%parameter_type));
                   3096: # set parameters
                   3097: sub update_parameter {
1.537     raeburn  3098:     if ($env{'form.changeparms'} eq 'all') {
                   3099:         my (@allidx,@allmapidx,%allchecked,%currchecked);
                   3100:         %allchecked = (
                   3101:                          'hiddenresource' => {},
                   3102:                          'encrypturl'     => {},
                   3103:                          'randompick'     => {},
                   3104:                          'randomorder'    => {},
                   3105:                       );
                   3106:         foreach my $which (keys(%allchecked)) {
1.630     raeburn  3107:             $env{'form.all'.$which} =~ s/,$//;
1.537     raeburn  3108:             if ($which eq 'randompick') {
                   3109:                 foreach my $item (split(/,/,$env{'form.all'.$which})) {
                   3110:                     my ($res,$value) = split(/:/,$item);
                   3111:                     if ($value =~ /^\d+$/) {
                   3112:                         $allchecked{$which}{$res} = $value;
                   3113:                     }
                   3114:                 }
                   3115:             } else {
1.539     raeburn  3116:                 if ($env{'form.all'.$which}) {
                   3117:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
                   3118:                 }
1.537     raeburn  3119:             }
                   3120:         }
                   3121:         my $haschanges = 0;
                   3122:         foreach my $res (@LONCAPA::map::order) {
                   3123:             my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3124:             $name=&LONCAPA::map::qtescape($name);
                   3125:             $url=&LONCAPA::map::qtescape($url);
1.692     raeburn  3126:             next unless $url;
1.537     raeburn  3127:             my $is_map;
                   3128:             if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   3129:                 $is_map = 1;
                   3130:             }
                   3131:             foreach my $which (keys(%allchecked)) {
                   3132:                 if (($which eq 'randompick' || $which eq 'randomorder')) {
                   3133:                     next if (!$is_map);
                   3134:                 } 
                   3135:                 my $oldvalue = 0;
                   3136:                 my $newvalue = 0;
                   3137:                 if ($allchecked{$which}{$res}) {
                   3138:                     $newvalue = $allchecked{$which}{$res};
                   3139:                 }
                   3140:                 my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
                   3141:                 if ($which eq 'randompick') {
                   3142:                     if ($current =~ /^(\d+)$/) {
                   3143:                         $oldvalue = $1;
                   3144:                     }
                   3145:                 } else {
                   3146:                     if ($current =~ /^yes$/i) {
                   3147:                         $oldvalue = 1;
                   3148:                     }
                   3149:                 }
                   3150:                 if ($oldvalue ne $newvalue) {
                   3151:                     $haschanges = 1;
                   3152:                     if ($newvalue) {
                   3153:                         my $storeval = 'yes';
                   3154:                         if ($which eq 'randompick') {
                   3155:                             $storeval = $newvalue;
                   3156:                         }
                   3157:                         &LONCAPA::map::storeparameter($res,'parameter_'.$which,
                   3158:                                                       $storeval,
                   3159:                                                       $parameter_type{$which});
                   3160:                         &remember_parms($res,$which,'set',$storeval);
                   3161:                     } elsif ($oldvalue) {
                   3162:                         &LONCAPA::map::delparameter($res,'parameter_'.$which);
                   3163:                         &remember_parms($res,$which,'del');
                   3164:                     }
                   3165:                 }
                   3166:             }
                   3167:         }
                   3168:         return $haschanges;
                   3169:     } else {
1.588     raeburn  3170:         my $haschanges = 0;
                   3171:         return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329     droeschl 3172: 
1.537     raeburn  3173:         my $which = $env{'form.changeparms'};
                   3174:         my $idx = $env{'form.setparms'};
1.588     raeburn  3175:         my $oldvalue = 0;
                   3176:         my $newvalue = 0;
                   3177:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
                   3178:         if ($which eq 'randompick') {
                   3179:             if ($current =~ /^(\d+)$/) {
                   3180:                 $oldvalue = $1;
                   3181:             }
                   3182:         } elsif ($current =~ /^yes$/i) {
                   3183:             $oldvalue = 1;
                   3184:         }
1.537     raeburn  3185:         if ($env{'form.'.$which.'_'.$idx}) {
1.588     raeburn  3186: 	    $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
                   3187: 	                                         : 1;
                   3188:         }
                   3189:         if ($oldvalue ne $newvalue) {
                   3190:             $haschanges = 1;
                   3191:             if ($newvalue) {
                   3192:                 my $storeval = 'yes';
                   3193:                 if ($which eq 'randompick') {
                   3194:                     $storeval = $newvalue;
                   3195:                 }
                   3196: 	        &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
                   3197: 				              $parameter_type{$which});
                   3198: 	        &remember_parms($idx,$which,'set',$storeval);
                   3199:             } else {
                   3200: 	        &LONCAPA::map::delparameter($idx,'parameter_'.$which);
                   3201: 	        &remember_parms($idx,$which,'del');
                   3202:             }
1.537     raeburn  3203:         }
1.588     raeburn  3204:         return $haschanges;
1.329     droeschl 3205:     }
                   3206: }
                   3207: 
                   3208: sub handle_edit_cmd {
                   3209:     my ($coursenum,$coursedom) =@_;
1.633     raeburn  3210:     my $haschanges = 0;
1.543     raeburn  3211:     if ($env{'form.cmd'} eq '') {
1.633     raeburn  3212:         return $haschanges; 
1.543     raeburn  3213:     }
1.329     droeschl 3214:     my ($cmd,$idx)=split('_',$env{'form.cmd'});
                   3215: 
                   3216:     my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                   3217:     my ($title, $url, @rrest) = split(':', $ratstr);
                   3218: 
1.538     raeburn  3219:     if ($cmd eq 'remove') {
1.329     droeschl 3220: 	if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463     www      3221: 	    ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329     droeschl 3222: 	    &Apache::lonnet::removeuploadedurl($url);
                   3223: 	} else {
                   3224: 	    &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   3225: 	}
                   3226: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  3227:         $haschanges = 1;
1.329     droeschl 3228:     } elsif ($cmd eq 'cut') {
                   3229: 	&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   3230: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  3231:         $haschanges = 1;
1.344     bisitz   3232:     } elsif ($cmd eq 'up'
1.329     droeschl 3233: 	     && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
                   3234: 	@LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633     raeburn  3235:         $haschanges = 1;
1.329     droeschl 3236:     } elsif ($cmd eq 'down'
                   3237: 	     && defined($LONCAPA::map::order[$idx+1])) {
                   3238: 	@LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633     raeburn  3239:         $haschanges = 1;
1.329     droeschl 3240:     } elsif ($cmd eq 'rename') {
                   3241: 	my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
                   3242: 	if ($comment=~/\S/) {
                   3243: 	    $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
                   3244: 		$comment.':'.join(':', $url, @rrest);
                   3245: 	}
                   3246: # Devalidate title cache
                   3247: 	my $renamed_url=&LONCAPA::map::qtescape($url);
                   3248: 	&Apache::lonnet::devalidate_title_cache($renamed_url);
1.633     raeburn  3249:         $haschanges = 1;
                   3250:     } elsif ($cmd eq 'setalias') {
                   3251:         my $newvalue = $env{'form.alias'};
                   3252:         if ($newvalue ne '') {
                   3253:             unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
                   3254:                 &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
                   3255:                                               'string');
                   3256:                 &remember_parms($idx,'mapalias','set',$newvalue);
                   3257:                 $haschanges = 1;
                   3258:             }
                   3259:         }
                   3260:     } elsif ($cmd eq 'delalias') {
                   3261:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];  
                   3262:         if ($current ne '') {
                   3263:             &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
                   3264:             &remember_parms($idx,'mapalias','del');
                   3265:             $haschanges = 1;
                   3266:         }
1.329     droeschl 3267:     }
1.633     raeburn  3268:     return $haschanges;
1.329     droeschl 3269: }
                   3270: 
                   3271: sub editor {
1.458     raeburn  3272:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615     raeburn  3273:         $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622     raeburn  3274:         $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519     raeburn  3275:     my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510     raeburn  3276:     if ($allowed) {
1.519     raeburn  3277:         (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   3278:          $is_random_order,$container) =
1.510     raeburn  3279:             &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   3280:         $r->print($breadcrumbtrail);
1.519     raeburn  3281:     } elsif ($env{'form.folderpath'} =~ /\:1$/) {
                   3282:         $container = 'page'; 
                   3283:     } else {
                   3284:         $container = 'sequence';
1.510     raeburn  3285:     }
1.484     raeburn  3286: 
1.525     raeburn  3287:     my $jumpto;
                   3288: 
                   3289:     unless ($supplementalflag) {
1.546     raeburn  3290:         $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525     raeburn  3291:     }
1.484     raeburn  3292: 
                   3293:     unless ($allowed) {
                   3294:         $randompick = -1;
                   3295:     }
                   3296: 
1.615     raeburn  3297:     my ($errtext,$fatal);
                   3298:     if (($folder eq '') && (!$supplementalflag)) {
                   3299:         if (@LONCAPA::map::order) {
                   3300:             undef(@LONCAPA::map::order);
                   3301:             undef(@LONCAPA::map::resources);
                   3302:             undef(@LONCAPA::map::resparms);
                   3303:             undef(@LONCAPA::map::zombies);
                   3304:         }
                   3305:         $folder = 'default';
                   3306:         $container = 'sequence'; 
                   3307:     } else {
                   3308:         ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   3309: 				     $folder.'.'.$container);
                   3310:         return $errtext if ($fatal);
                   3311:     }
1.329     droeschl 3312: 
                   3313:     if ($#LONCAPA::map::order<1) {
                   3314: 	my $idx=&LONCAPA::map::getresidx();
                   3315: 	if ($idx<=0) { $idx=1; }
                   3316:        	$LONCAPA::map::order[0]=$idx;
                   3317:         $LONCAPA::map::resources[$idx]='';
                   3318:     }
1.364     bisitz   3319: 
1.329     droeschl 3320: # ------------------------------------------------------------ Process commands
                   3321: 
                   3322: # ---------------- if they are for this folder and user allowed to make changes
1.611     raeburn  3323:     if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329     droeschl 3324: # set parameters and change order
                   3325: 	&snapshotbefore();
                   3326: 
                   3327: 	if (&update_parameter()) {
1.588     raeburn  3328: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329     droeschl 3329: 	    return $errtext if ($fatal);
                   3330: 	}
                   3331: 
                   3332: 	if ($env{'form.newpos'} && $env{'form.currentpos'}) {
                   3333: # change order
                   3334: 	    my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
                   3335: 	    splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
                   3336: 
                   3337: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
                   3338: 	    return $errtext if ($fatal);
                   3339: 	}
1.364     bisitz   3340: 
1.329     droeschl 3341: 	if ($env{'form.pastemarked'}) {
1.491     raeburn  3342:             my %paste_errors;
1.533     raeburn  3343:             my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492     raeburn  3344:                 &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
                   3345:                                       \%paste_errors);
1.541     raeburn  3346:             if (ref($pastemsgarray) eq 'ARRAY') {
                   3347:                 if (@{$pastemsgarray} > 0) {
                   3348:                     $r->print('<p class="LC_info">'.
                   3349:                               join('<br />',@{$pastemsgarray}).
1.533     raeburn  3350:                               '</p>');
                   3351:                 }
1.541     raeburn  3352:             }
                   3353:             if ($lockerror) {
                   3354:                 $r->print('<p class="LC_error">'.
                   3355:                           $lockerror.
                   3356:                           '</p>');
                   3357:             }
                   3358:             if ($save_error ne '') {
                   3359:                 return $save_error; 
                   3360:             }
                   3361:             if ($paste_res) {
                   3362:                 my %errortext = &Apache::lonlocal::texthash (
                   3363:                                     fail      => 'Storage of folder contents failed',
                   3364:                                     failread  => 'Reading folder contents failed',
                   3365:                                     failstore => 'Storage of folder contents failed',
                   3366:                                 );
                   3367:                 if ($errortext{$paste_res}) {
                   3368:                     $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492     raeburn  3369:                 }
1.329     droeschl 3370:             }
1.491     raeburn  3371:             if (keys(%paste_errors) > 0) {
1.538     raeburn  3372:                 $r->print('<p class="LC_warning">'."\n".
1.491     raeburn  3373:                           &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".
                   3374:                           '<ul>'."\n");
                   3375:                 foreach my $key (sort(keys(%paste_errors))) {
                   3376:                     $r->print('<li>'.$key.'</li>'."\n");
                   3377:                 }
                   3378:                 $r->print('</ul></p>'."\n");
                   3379:             }
1.538     raeburn  3380: 	} elsif ($env{'form.clearmarked'}) {
                   3381:             my $output = &do_buffer_empty();
                   3382:             if ($output) {
                   3383:                 $r->print('<p class="LC_info">'.$output.'</p>');
                   3384:             }
                   3385:         }
1.329     droeschl 3386: 
                   3387: 	$r->print($upload_output);
                   3388: 
1.538     raeburn  3389: # Rename, cut, copy or remove a single resource
1.602     raeburn  3390: 	if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492     raeburn  3391:             my $contentchg;
1.633     raeburn  3392:             if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492     raeburn  3393:                 $contentchg = 1;
                   3394:             }
                   3395: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329     droeschl 3396: 	    return $errtext if ($fatal);
                   3397: 	}
1.538     raeburn  3398: 
                   3399: # Cut, copy and/or remove multiple resources
                   3400:         if ($env{'form.multichange'}) {
                   3401:             my %allchecked = (
                   3402:                                cut     => {},
                   3403:                                remove  => {},
                   3404:                              );
                   3405:             my $needsupdate;
                   3406:             foreach my $which (keys(%allchecked)) {
                   3407:                 $env{'form.multi'.$which} =~ s/,$//;
                   3408:                 if ($env{'form.multi'.$which}) {
                   3409:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
                   3410:                     if (ref($allchecked{$which}) eq 'HASH') {
                   3411:                         $needsupdate += scalar(keys(%{$allchecked{$which}}));
                   3412:                     }
                   3413:                 }
                   3414:             }
                   3415:             if ($needsupdate) {
                   3416:                 my $haschanges = 0;
                   3417:                 my %curr_groups = &Apache::longroup::coursegroups();
                   3418:                 my $total = scalar(@LONCAPA::map::order) - 1; 
                   3419:                 for (my $i=$total; $i>=0; $i--) {
                   3420:                     my $res = $LONCAPA::map::order[$i];
                   3421:                     my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3422:                     $name=&LONCAPA::map::qtescape($name);
                   3423:                     $url=&LONCAPA::map::qtescape($url);
1.586     droeschl 3424:                     next unless $url;
1.538     raeburn  3425:                     my %denied =
                   3426:                         &action_restrictions($coursenum,$coursedom,$url,
                   3427:                                              $env{'form.folderpath'},\%curr_groups);
                   3428:                     foreach my $which (keys(%allchecked)) {
                   3429:                         next if ($denied{$which});
                   3430:                         next unless ($allchecked{$which}{$res});
                   3431:                         if ($which eq 'remove') {
                   3432:                             if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   3433:                                 ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   3434:                                 &Apache::lonnet::removeuploadedurl($url);
                   3435:                             } else {
                   3436:                                 &LONCAPA::map::makezombie($res);
                   3437:                             }
                   3438:                             splice(@LONCAPA::map::order,$i,1);
                   3439:                             $haschanges ++;
                   3440:                         } elsif ($which eq 'cut') {
                   3441:                             &LONCAPA::map::makezombie($res);
                   3442:                             splice(@LONCAPA::map::order,$i,1);
                   3443:                             $haschanges ++;
                   3444:                         }
                   3445:                     }
                   3446:                 }
                   3447:                 if ($haschanges) {
                   3448:                     ($errtext,$fatal) = 
                   3449:                         &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   3450:                     return $errtext if ($fatal);
                   3451:                 }
                   3452:             }
                   3453:         }
                   3454: 
1.329     droeschl 3455: # Group import/search
                   3456: 	if ($env{'form.importdetail'}) {
                   3457: 	    my @imports;
                   3458: 	    foreach my $item (split(/\&/,$env{'form.importdetail'})) {
                   3459: 		if (defined($item)) {
                   3460: 		    my ($name,$url,$residx)=
1.533     raeburn  3461: 			map { &unescape($_); } split(/\=/,$item);
                   3462:                     if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
                   3463:                         my ($suffix,$errortxt,$locknotfreed) =
                   3464:                             &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504     raeburn  3465:                         if ($locknotfreed) {
                   3466:                             $r->print($locknotfreed);
                   3467:                         }
                   3468:                         if ($suffix) {
                   3469:                             $url =~ s/_new\./_$suffix./; 
                   3470:                         } else {
                   3471:                             return $errortxt;
                   3472:                         }
1.533     raeburn  3473:                     } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
                   3474:                         my $type = $1;
                   3475:                         my ($suffix,$errortxt,$locknotfreed) =
                   3476:                             &new_timebased_suffix($coursedom,$coursenum,$type);
                   3477:                         if ($locknotfreed) {
                   3478:                             $r->print($locknotfreed);
                   3479:                         }
                   3480:                         if ($suffix) {
                   3481:                             $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
                   3482:                         } else {
                   3483:                             return $errortxt;
                   3484:                         }
1.626     raeburn  3485:                     } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598     raeburn  3486:                         my ($suffix,$errortxt,$locknotfreed) =
                   3487:                             &new_timebased_suffix($coursedom,$coursenum,'exttool');
                   3488:                         if ($locknotfreed) {
                   3489:                             $r->print($locknotfreed);
                   3490:                         }
                   3491:                         if ($suffix) {
                   3492:                             $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
                   3493:                         } else {
                   3494:                             return $errortxt;
                   3495:                         }
1.534     raeburn  3496:                     } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
                   3497:                         if ($supplementalflag) {
                   3498:                             next unless ($1 eq 'supplemental');
                   3499:                             if ($folder eq 'supplemental') {
                   3500:                                 next unless ($2 eq 'default');
                   3501:                             } else {
                   3502:                                 next unless ($folder eq 'supplemental_'.$2);
                   3503:                             }
                   3504:                         } else {
                   3505:                             next unless ($1 eq 'docs');
                   3506:                             if ($folder eq 'default') {
                   3507:                                 next unless ($2 eq 'default');
                   3508:                             } else {
                   3509:                                 next unless ($folder eq 'default_'.$2);
                   3510:                             }
                   3511:                         }
1.504     raeburn  3512:                     }
1.329     droeschl 3513: 		    push(@imports, [$name, $url, $residx]);
                   3514: 		}
                   3515: 	    }
1.530     raeburn  3516:             ($errtext,$fatal,my $fixuperrors) =
1.529     raeburn  3517:                 &group_import($coursenum, $coursedom, $folder,$container,
1.598     raeburn  3518:                               'londocs',$ltitoolsref,@imports);
1.329     droeschl 3519: 	    return $errtext if ($fatal);
1.529     raeburn  3520:             if ($fixuperrors) {
                   3521:                 $r->print($fixuperrors);
                   3522:             }
1.329     droeschl 3523: 	}
                   3524: # Loading a complete map
                   3525: 	if ($env{'form.loadmap'}) {
                   3526: 	    if ($env{'form.importmap'}=~/\w/) {
                   3527: 		foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
                   3528: 		    my ($title,$url,$ext,$type)=split(/\:/,$res);
                   3529: 		    my $idx=&LONCAPA::map::getresidx($url);
                   3530: 		    $LONCAPA::map::resources[$idx]=$res;
                   3531: 		    $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
                   3532: 		}
                   3533: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  3534: 					    $folder.'.'.$container,1);
1.329     droeschl 3535: 		return $errtext if ($fatal);
                   3536: 	    } else {
                   3537: 		$r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364     bisitz   3538: 
1.329     droeschl 3539: 	    }
                   3540: 	}
                   3541: 	&log_differences($plain);
                   3542:     }
                   3543: # ---------------------------------------------------------------- End commands
                   3544: # ---------------------------------------------------------------- Print screen
                   3545:     my $idx=0;
                   3546:     my $shown=0;
                   3547:     if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381     bisitz   3548: 	$r->print('<div class="LC_Box">'.
1.432     raeburn  3549:           '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
                   3550: 		  ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
                   3551: 		  ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
                   3552: 		  ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
                   3553: 		  ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431     raeburn  3554: 		  '</ol>');
1.381     bisitz   3555:         if ($randompick>=0) {
                   3556:             $r->print('<p class="LC_warning">'
                   3557:                  .&mt('Caution: this folder is set to randomly pick a subset'
                   3558:                      .' of resources. Adding or removing resources from this'
                   3559:                      .' folder will change the set of resources that the'
                   3560:                      .' students see, resulting in spurious or missing credit'
                   3561:                      .' for completed problems, not limited to ones you'
                   3562:                      .' modify. Do not modify the contents of this folder if'
                   3563:                      .' it is in active student use.')
                   3564:                  .'</p>'
                   3565:             );
                   3566:         }
                   3567:         if ($is_random_order) {
                   3568:             $r->print('<p class="LC_warning">'
                   3569:                  .&mt('Caution: this folder is set to randomly order its'
                   3570:                      .' contents. Adding or removing resources from this folder'
                   3571:                      .' will change the order of resources shown.')
                   3572:                  .'</p>'
                   3573:             );
                   3574:         }
                   3575:         $r->print('</div>');
1.364     bisitz   3576:     }
1.381     bisitz   3577: 
1.685     raeburn  3578:     if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688     raeburn  3579:         my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn  3580:         if (ref($supplemental) eq 'HASH') {
                   3581:             if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
                   3582:                 (ref($supplemental->{'ids'}) eq 'HASH')) {
                   3583:                 if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
                   3584:                     my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
                   3585:                     if ($supplemental->{'hidden'}->{$mapnum}) {
                   3586:                         $ishidden = 1;
                   3587:                     }
                   3588:                 }
                   3589:             }
                   3590:         }
                   3591:     }
                   3592: 
1.538     raeburn  3593:     my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
                   3594:     %filters =  (
1.543     raeburn  3595:                   canremove      => [],
                   3596:                   cancut         => [],
                   3597:                   cancopy        => [],
                   3598:                   hiddenresource => [],
                   3599:                   encrypturl     => [],
                   3600:                   randomorder    => [],
                   3601:                   randompick     => [],
1.538     raeburn  3602:                 );
                   3603:     %curr_groups = &Apache::longroup::coursegroups();
1.424     onken    3604:     &Apache::loncommon::start_data_table_count(); #setup a row counter 
1.381     bisitz   3605:     foreach my $res (@LONCAPA::map::order) {
                   3606:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3607:         $name=&LONCAPA::map::qtescape($name);
                   3608:         $url=&LONCAPA::map::qtescape($url);
                   3609:         unless ($name) {  $name=(split(/\//,$url))[-1]; }
                   3610:         unless ($name) { $idx++; next; }
1.537     raeburn  3611:         push(@allidx,$res);
                   3612:         if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   3613:             push(@allmapidx,$res);
                   3614:         }
1.617     raeburn  3615: 
1.682     raeburn  3616:         if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685     raeburn  3617:             if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
                   3618:                 $idx++;
                   3619:                 next;
                   3620:             }
1.682     raeburn  3621:         }
1.381     bisitz   3622:         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501     raeburn  3623:                               $coursenum,$coursedom,$crstype,
1.538     raeburn  3624:                               $pathitem,$supplementalflag,$container,
1.620     raeburn  3625:                               \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685     raeburn  3626:                               $isencrypted,$ishidden,$navmapref,$hostname);
1.381     bisitz   3627:         $idx++;
                   3628:         $shown++;
1.329     droeschl 3629:     }
1.424     onken    3630:     &Apache::loncommon::end_data_table_count();
1.510     raeburn  3631: 
1.538     raeburn  3632:     my $need_save;
1.611     raeburn  3633:     if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544     raeburn  3634:         my $toolslink;
1.682     raeburn  3635:         if ($allowed || $canedit) {
                   3636:             my $helpitem = 'Navigation_Screen';
                   3637:             if (!$allowed) {
                   3638:                 $helpitem = 'Supplemental_Navigation';
                   3639:             }
1.544     raeburn  3640:             $toolslink = '<table><tr><td>'
1.520     raeburn  3641:                        .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682     raeburn  3642:                                                            $helpitem,undef,'RAT')
1.520     raeburn  3643:                        .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
                   3644:                        .'<td align="left"><ul id="LC_toolbar">'
1.525     raeburn  3645:                        .'<li><a href="/adm/coursedocs?forcesupplement=1&amp;command=editsupp" '
1.520     raeburn  3646:                        .'id="LC_content_toolbar_edittoplevel" '
                   3647:                        .'class="LC_toolbarItem" '
                   3648:                        .'title="'.&mt('Supplemental Content Editor').'">'
                   3649:                        .'</a></li></ul></td></tr></table><br />';
1.544     raeburn  3650:         }
1.510     raeburn  3651:         if ($shown) {
                   3652:             if ($allowed) {
                   3653:                 $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
                   3654:                           .&Apache::loncommon::start_data_table(undef,'contentlist')
                   3655:                           .&Apache::loncommon::start_data_table_header_row()
                   3656:                           .'<th colspan="2">'.&mt('Move').'</th>'
1.633     raeburn  3657:                           .'<th colspan="3">'.&mt('Actions').'</th>'
1.682     raeburn  3658:                           .'<th>'.&mt('Document').'</th>'
                   3659:                           .'<th colspan="2">'.&mt('Settings').'</th>'
                   3660:                           .&Apache::loncommon::end_data_table_header_row();
1.537     raeburn  3661:                 if ($folder !~ /^supplemental/) {
1.538     raeburn  3662:                     $lists{'canhide'} = join(',',@allidx);
                   3663:                     $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543     raeburn  3664:                     my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
                   3665:                                        'randomorder','randompick');
                   3666:                     foreach my $item (@possfilters) {
1.538     raeburn  3667:                         if (ref($filters{$item}) eq 'ARRAY') {
1.543     raeburn  3668:                             if (@{$filters{$item}} > 0) {
                   3669:                                 $lists{$item} = join(',',@{$filters{$item}});
                   3670:                             }
1.538     raeburn  3671:                         }
                   3672:                     }
1.537     raeburn  3673:                     if (@allidx > 0) {
                   3674:                         my $path;
                   3675:                         if ($env{'form.folderpath'}) {
1.630     raeburn  3676:                             $path =
1.537     raeburn  3677:                                 &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   3678:                         }
1.538     raeburn  3679:                         if (@allidx > 1) {
1.630     raeburn  3680:                             $to_show .=
1.538     raeburn  3681:                                 &Apache::loncommon::continue_data_table_row().
                   3682:                                 '<td colspan="2">&nbsp;</td>'.
                   3683:                                 '<td>'.
1.611     raeburn  3684:                                 &multiple_check_form('actions',\%lists,$canedit).
1.538     raeburn  3685:                                 '</td>'.
1.633     raeburn  3686:                                 '<td colspan="3">&nbsp;</td>'.
                   3687:                                 '<td colspan="2">'.
1.611     raeburn  3688:                                 &multiple_check_form('settings',\%lists,$canedit).
1.538     raeburn  3689:                                 '</td>'.
                   3690:                                 &Apache::loncommon::end_data_table_row();
                   3691:                              $need_save = 1;
                   3692:                         }
1.537     raeburn  3693:                     }
                   3694:                 }
                   3695:                 $to_show .= $output.' '
1.510     raeburn  3696:                            .&Apache::loncommon::end_data_table()
                   3697:                            .'<br style="line-height:2px;" />'
                   3698:                            .&Apache::loncommon::end_scrollbox();
                   3699:             } else {
1.520     raeburn  3700:                 $to_show .= $toolslink
1.510     raeburn  3701:                            .&Apache::loncommon::start_data_table('LC_tableOfContent')
                   3702:                            .$output.' '
                   3703:                            .&Apache::loncommon::end_data_table();
1.393     raeburn  3704:             }
1.510     raeburn  3705:         } else {
1.520     raeburn  3706:             if (!$allowed) {
                   3707:                 $to_show .= $toolslink;
                   3708:             }
1.615     raeburn  3709:             my $noresmsg;
                   3710:             if ($allowed && $hiddentop && !$supplementalflag) {
                   3711:                 $noresmsg = &mt('Main Content Hidden'); 
                   3712:             } else {
                   3713:                 $noresmsg = &mt('Currently empty');
                   3714:             }
1.510     raeburn  3715:             $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
                   3716:                        .'<div class="LC_info" id="contentlist">'
1.615     raeburn  3717:                        .$noresmsg
1.510     raeburn  3718:                        .'</div>'
                   3719:                        .&Apache::loncommon::end_scrollbox();
1.393     raeburn  3720:         }
                   3721:     } else {
1.510     raeburn  3722:         if ($shown) {
                   3723:             $to_show = '<div>'
                   3724:                       .&Apache::loncommon::start_data_table('LC_tableOfContent')
                   3725:                       .$output
                   3726:                       .&Apache::loncommon::end_data_table()
                   3727:                       .'</div>';
                   3728:         } else {
                   3729:             $to_show = '<div class="LC_info" id="contentlist">'
1.550     raeburn  3730:                       .&mt('Currently empty')
1.510     raeburn  3731:                       .'</div>'
                   3732:         }
1.458     raeburn  3733:     }
                   3734:     my $tid = 1;
                   3735:     if ($supplementalflag) {
                   3736:         $tid = 2;
1.329     droeschl 3737:     }
                   3738:     if ($allowed) {
1.484     raeburn  3739:         my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538     raeburn  3740:         $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611     raeburn  3741:                                        $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
                   3742:         if ($canedit) {
                   3743:             &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
                   3744:         }
1.460     raeburn  3745:     } else {
                   3746:         $r->print($to_show);
1.329     droeschl 3747:     }
                   3748:     return;
                   3749: }
                   3750: 
1.538     raeburn  3751: sub multiple_check_form {
1.611     raeburn  3752:     my ($caller,$listsref,$canedit) = @_;
1.538     raeburn  3753:     return unless (ref($listsref) eq 'HASH');
1.611     raeburn  3754:     my $disabled;
                   3755:     unless ($canedit) {
1.700   ! raeburn  3756:         $disabled = ' disabled="disabled"';
1.611     raeburn  3757:     }
1.538     raeburn  3758:     my $output =
                   3759:     '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
                   3760:     '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
                   3761:     '<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>'.
                   3762:     '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
                   3763:     '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
                   3764:     '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
                   3765:     if ($caller eq 'settings') {
                   3766:         $output .= 
                   3767:             '<table><tr>'.
                   3768:             '<td class="LC_docs_entry_parameter">'.
                   3769:             '<span class="LC_nobreak"><label>'.
1.611     raeburn  3770:             '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538     raeburn  3771:             '</label></span></td>'.
                   3772:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  3773:             '<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  3774:             '</span></td>'.
                   3775:             '</tr>'."\n".
                   3776:             '<tr>'.
                   3777:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  3778:             '<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  3779:             '</label></span>'.
                   3780:             '</td></tr></table>'."\n";
                   3781:     } else {
                   3782:         $output .=
                   3783:             '<table><tr>'.
                   3784:             '<td class="LC_docs_entry_parameter">'.
                   3785:             '<span class="LC_nobreak LC_docs_remove">'.
1.611     raeburn  3786:             '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538     raeburn  3787:             '</label></span></td>'.
                   3788:             '<td class="LC_docs_entry_parameter">'.
                   3789:             '<span class="LC_nobreak LC_docs_cut">'.
1.611     raeburn  3790:             '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538     raeburn  3791:             '</label></span></td>'."\n".
                   3792:             '<td class="LC_docs_entry_parameter">'.
                   3793:             '<span class="LC_nobreak LC_docs_copy">'.
1.700   ! raeburn  3794:             '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538     raeburn  3795:             '</label></span></td>'.
                   3796:             '</tr></table>'."\n";
                   3797:     }
                   3798:     $output .= 
                   3799:         '</fieldset>'.
                   3800:         '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
                   3801:     if ($caller eq 'settings') {
                   3802:         $output .= 
1.543     raeburn  3803:         '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
                   3804:         '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
                   3805:         '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
                   3806:         '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
                   3807:         '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538     raeburn  3808:     } elsif ($caller eq 'actions') {
                   3809:         $output .=
                   3810:         '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
                   3811:         '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
                   3812:         '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
                   3813:     }
                   3814:     $output .= 
                   3815:         '</form>'.
                   3816:         '</div>';
                   3817:     return $output;
                   3818: }
                   3819: 
1.329     droeschl 3820: sub process_file_upload {
1.552     raeburn  3821:     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329     droeschl 3822: # upload a file, if present
1.552     raeburn  3823:     my $filesize = length($env{'form.uploaddoc'});
                   3824:     if (!$filesize) {
                   3825:         $$upload_output = '<div class="LC_error">'.
                   3826:                            &mt('Unable to upload [_1]. (size = [_2] bytes)',
                   3827:                           '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
                   3828:                           $filesize).'<br />'.
                   3829:                           &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
                   3830:                           '</div>';
                   3831:         return;
                   3832:     }
                   3833:     my $quotatype = 'unofficial';
                   3834:     if ($crstype eq 'Community') {
1.601     raeburn  3835:         $quotatype = 'community';
                   3836:     } elsif ($crstype eq 'Placement') {
                   3837:         $quotatype = 'placement';
1.580     raeburn  3838:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552     raeburn  3839:         $quotatype = 'official';
1.573     raeburn  3840:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   3841:         $quotatype = 'textbook';
1.552     raeburn  3842:     }
                   3843:     if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
                   3844:         $filesize = int($filesize/1000); #expressed in kb
                   3845:         $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579     raeburn  3846:                                                                       $env{'form.uploaddoc.filename'},$filesize,
                   3847:                                                                       'upload',$quotatype);
1.552     raeburn  3848:         return if ($$upload_output);
                   3849:     }
1.440     raeburn  3850:     my ($parseaction,$showupload,$nextphase,$mimetype);
                   3851:     if ($env{'form.parserflag'}) {
1.329     droeschl 3852:         $parseaction = 'parse';
                   3853:     }
                   3854:     my $folder=$env{'form.folder'};
                   3855:     if ($folder eq '') {
                   3856:         $folder='default';
                   3857:     }
                   3858:     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
                   3859:         my $errtext='';
                   3860:         my $fatal=0;
                   3861:         my $container='sequence';
1.519     raeburn  3862:         if ($env{'form.folderpath'} =~ /:1$/) {
1.329     droeschl 3863:             $container='page';
                   3864:         }
                   3865:         ($errtext,$fatal)=
1.534     raeburn  3866:             &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329     droeschl 3867:         if ($#LONCAPA::map::order<1) {
                   3868:             $LONCAPA::map::order[0]=1;
                   3869:             $LONCAPA::map::resources[1]='';
                   3870:         }
                   3871:         my $destination = 'docs/';
                   3872:         if ($folder =~ /^supplemental/) {
                   3873:             $destination = 'supplemental/';
                   3874:         }
                   3875:         if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   3876:             $destination .= 'default/';
                   3877:         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   3878:             $destination .=  $2.'/';
                   3879:         }
1.534     raeburn  3880:         if ($fatal) {
                   3881:             $$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>';
                   3882:             return;
                   3883:         }
1.440     raeburn  3884: # this is for a course, not a user, so set context to coursedoc.
1.329     droeschl 3885:         my $newidx=&LONCAPA::map::getresidx();
                   3886:         $destination .= $newidx;
1.439     raeburn  3887:         my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329     droeschl 3888: 						$parseaction,$allfiles,
1.440     raeburn  3889: 						$codebase,undef,undef,undef,undef,
                   3890:                                                 undef,undef,\$mimetype);
                   3891:         if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
                   3892:             my $stored = $1;
                   3893:             $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   3894:                           $stored.'</span>').'</p>';
                   3895:         } else {
                   3896:             my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
                   3897:             
1.457     raeburn  3898:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440     raeburn  3899:             return;
                   3900:         }
1.329     droeschl 3901:         my $ext='false';
                   3902:         if ($url=~m{^http://}) { $ext='true'; }
                   3903: 	$url     = &LONCAPA::map::qtunescape($url);
                   3904:         my $comment=$env{'form.comment'};
                   3905: 	$comment = &LONCAPA::map::qtunescape($comment);
                   3906:         if ($folder=~/^supplemental/) {
                   3907:               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   3908:                   $env{'user.domain'}.'___&&&___'.$comment;
                   3909:         }
                   3910: 
                   3911:         $LONCAPA::map::resources[$newidx]=
                   3912: 	    $comment.':'.$url.':'.$ext.':normal:res';
                   3913:         $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
                   3914:         ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  3915: 				    $folder.'.'.$container,1);
1.329     droeschl 3916:         if ($fatal) {
1.457     raeburn  3917:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440     raeburn  3918:             return;
1.329     droeschl 3919:         } else {
1.440     raeburn  3920:             if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
                   3921:                 $$upload_output = $showupload;
1.384     raeburn  3922:                 my $total_embedded = scalar(keys(%{$allfiles}));
1.329     droeschl 3923:                 if ($total_embedded > 0) {
1.440     raeburn  3924:                     my $uploadphase = 'upload_embedded';
                   3925:                     my $primaryurl = &HTML::Entities::encode($url,'<>&"');
                   3926: 		    my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx); 
1.630     raeburn  3927:                     my ($embedded,$num) =
1.440     raeburn  3928:                         &Apache::loncommon::ask_for_embedded_content(
                   3929:                             '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
                   3930:                     if ($embedded) {
                   3931:                         if ($num) {
                   3932:                             $$upload_output .=
                   3933: 			         '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
                   3934:                             $nextphase = $uploadphase;
                   3935:                         } else {
                   3936:                             $$upload_output .= $embedded;
                   3937:                         }
                   3938:                     } else {
                   3939:                         $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
                   3940:                     }
1.329     droeschl 3941:                 } else {
1.440     raeburn  3942:                     $$upload_output .= &mt('No embedded items identified').'<br />';
1.329     droeschl 3943:                 }
1.457     raeburn  3944:                 $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578     raeburn  3945:             } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
                   3946:                      ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476     raeburn  3947:                 $nextphase = 'decompress_uploaded';
                   3948:                 my $position = scalar(@LONCAPA::map::order)-1;
                   3949:                 my $noextract = &return_to_editor();
                   3950:                 my $archiveurl = &HTML::Entities::encode($url,'<>&"');
                   3951:                 my %archiveitems = (
                   3952:                     folderpath => $env{'form.folderpath'},
                   3953:                     cmd        => $nextphase,
                   3954:                     newidx     => $newidx,
                   3955:                     position   => $position,
                   3956:                     phase      => $nextphase,
1.477     raeburn  3957:                     comment    => $comment,
1.480     raeburn  3958:                 );
                   3959:                 my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
                   3960:                 my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx); 
1.476     raeburn  3961:                 $$upload_output = $showupload.
                   3962:                                   &Apache::loncommon::decompress_form($mimetype,
                   3963:                                       $archiveurl,'/adm/coursedocs',$noextract,
1.480     raeburn  3964:                                       \%archiveitems,\@current);
1.329     droeschl 3965:             }
                   3966:         }
                   3967:     }
1.440     raeburn  3968:     return $nextphase;
1.329     droeschl 3969: }
                   3970: 
1.480     raeburn  3971: sub get_dir_list {
                   3972:     my ($url,$coursenum,$coursedom,$newidx) = @_;
                   3973:     my ($destination,$dir_root) = &embedded_destination();
                   3974:     my ($dirlistref,$listerror) =  
                   3975:         &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
                   3976:     my @dir_lines;
                   3977:     my $dirptr=16384;
                   3978:     if (ref($dirlistref) eq 'ARRAY') {
                   3979:         foreach my $dir_line (sort
                   3980:                           {
                   3981:                               my ($afile)=split('&',$a,2);
                   3982:                               my ($bfile)=split('&',$b,2);
                   3983:                               return (lc($afile) cmp lc($bfile));
                   3984:                           } (@{$dirlistref})) {
                   3985:             my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
                   3986:             $filename =~ s/\s+$//;
                   3987:             next if ($filename =~ /^\.\.?$/); 
                   3988:             my $isdir = 0;
                   3989:             if ($dirptr&$testdir) {
                   3990:                 $isdir = 1;
                   3991:             }
                   3992:             push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
                   3993:         }
                   3994:     }
                   3995:     return @dir_lines;
                   3996: }
                   3997: 
1.329     droeschl 3998: sub is_supplemental_title {
                   3999:     my ($title) = @_;
                   4000:     return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
                   4001: }
                   4002: 
                   4003: # --------------------------------------------------------------- An entry line
                   4004: 
                   4005: sub entryline {
1.501     raeburn  4006:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598     raeburn  4007:         $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685     raeburn  4008:         $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687     raeburn  4009:     my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329     droeschl 4010:     if (&is_supplemental_title($title)) {
1.488     raeburn  4011: 	($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687     raeburn  4012:         $encodedtitle=$title;
1.329     droeschl 4013:     } else {
                   4014: 	$title=&HTML::Entities::encode($title,'"<>&\'');
1.687     raeburn  4015:         $encodedtitle=$title;
1.329     droeschl 4016: 	$renametitle=$title;
                   4017: 	$foldertitle=$title;
                   4018:     }
                   4019: 
1.611     raeburn  4020:     my ($disabled,$readonly,$js_lt);
                   4021:     unless ($canedit) {
                   4022:         $disabled = 'disabled="disabled"';
                   4023:         $readonly = 1;
                   4024:     }
                   4025: 
1.329     droeschl 4026:     my $orderidx=$LONCAPA::map::order[$index];
1.364     bisitz   4027: 
1.329     droeschl 4028:     $renametitle=~s/\\/\\\\/g;
                   4029:     $renametitle=~s/\&quot\;/\\\"/g;
1.585     raeburn  4030:     $renametitle=~s/"/%22/g;
1.581     raeburn  4031:     $renametitle=~s/ /%20/g;
                   4032:     $oldtitle = $renametitle;
1.576     raeburn  4033:     $renametitle=~s/\&#39;/\\\'/g;
1.379     bisitz   4034:     my $line=&Apache::loncommon::start_data_table_row();
1.538     raeburn  4035:     my ($form_start,$form_end,$form_common,$form_param);
1.329     droeschl 4036: # Edit commands
1.679     raeburn  4037:     my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329     droeschl 4038:     if ($env{'form.folderpath'}) {
                   4039: 	$esc_path=&escape($env{'form.folderpath'});
                   4040: 	$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   4041: 	# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
                   4042:     }
1.505     raeburn  4043:     my $isexternal;
1.510     raeburn  4044:     if ($residx) {
1.501     raeburn  4045:         my $currurl = $url;
                   4046:         $currurl =~ s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
1.505     raeburn  4047:         if ($currurl =~ m{^/adm/wrapper/ext/}) {
                   4048:             $isexternal = 1;
                   4049:         }
1.510     raeburn  4050:         if (!$supplementalflag) {
                   4051:             my $path = 'uploaded/'.
                   4052:                        $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   4053:                        $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
                   4054:             $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
                   4055:                                                  $residx,
                   4056:                                                  &Apache::lonnet::declutter($currurl));
                   4057:         }
1.501     raeburn  4058:     }
1.538     raeburn  4059:     my ($renamelink,%lt,$ishash);
                   4060:     if (ref($filtersref) eq 'HASH') {
                   4061:         $ishash = 1;
                   4062:     }
                   4063: 
1.329     droeschl 4064:     if ($allowed) {
1.538     raeburn  4065:         $form_start = '
                   4066:    <form action="/adm/coursedocs" method="post">
                   4067: ';
                   4068:         $form_common=(<<END);
                   4069:    <input type="hidden" name="folderpath" value="$path" />
                   4070:    <input type="hidden" name="symb" value="$symb" />
                   4071: END
                   4072:         $form_param=(<<END);
                   4073:    <input type="hidden" name="setparms" value="$orderidx" />
                   4074:    <input type="hidden" name="changeparms" value="0" />
                   4075: END
                   4076:         $form_end = '</form>';
                   4077: 
1.329     droeschl 4078: 	my $incindex=$index+1;
                   4079: 	my $selectbox='';
1.471     raeburn  4080: 	if (($#LONCAPA::map::order>0) &&
1.329     droeschl 4081: 	    ((split(/\:/,
1.344     bisitz   4082: 	     $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
                   4083: 	     ne '') &&
1.329     droeschl 4084: 	    ((split(/\:/,
1.344     bisitz   4085: 	     $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329     droeschl 4086: 	     ne '')) {
                   4087: 	    $selectbox=
                   4088: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611     raeburn  4089: 		'<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329     droeschl 4090: 	    for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
                   4091: 		if ($i==$incindex) {
1.358     bisitz   4092: 		    $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329     droeschl 4093: 		} else {
                   4094: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
                   4095: 		}
                   4096: 	    }
                   4097: 	    $selectbox.='</select>';
                   4098: 	}
1.501     raeburn  4099: 	%lt=&Apache::lonlocal::texthash(
1.329     droeschl 4100:                 'up' => 'Move Up',
                   4101: 		'dw' => 'Move Down',
                   4102: 		'rm' => 'Remove',
                   4103:                 'ct' => 'Cut',
                   4104: 		'rn' => 'Rename',
1.501     raeburn  4105: 		'cp' => 'Copy',
1.633     raeburn  4106:                 'da' => 'Unset alias', 
                   4107:                 'sa' => 'Set alias',
1.501     raeburn  4108:                 'ex' => 'External Resource',
1.598     raeburn  4109:                 'et' => 'External Tool',
1.501     raeburn  4110:                 'ed' => 'Edit',
                   4111:                 'pr' => 'Preview',
                   4112:                 'sv' => 'Save',
                   4113:                 'ul' => 'URL',
1.611     raeburn  4114:                 'ti' => 'Title',
1.618     raeburn  4115:                 'er' => 'Editing rights unavailable for your current role.', 
1.501     raeburn  4116:                 );
1.538     raeburn  4117: 	my %denied = &action_restrictions($coursenum,$coursedom,$url,
                   4118:                                           $env{'form.folderpath'},
                   4119:                                           $currgroups);
1.517     raeburn  4120:         my ($copylink,$cutlink,$removelink);
1.329     droeschl 4121: 	my $skip_confirm = 0;
1.603     raeburn  4122:         my $confirm_removal = 0;
1.329     droeschl 4123: 	if ( $folder =~ /^supplemental/
                   4124: 	     || ($url =~ m{( /smppg$
                   4125: 			    |/syllabus$
                   4126: 			    |/aboutme$
                   4127: 			    |/navmaps$
                   4128: 			    |/bulletinboard$
1.626     raeburn  4129:                             |/ext\.tool$
1.505     raeburn  4130: 			    |\.html$)}x)
                   4131:              || $isexternal) {
1.329     droeschl 4132: 	    $skip_confirm = 1;
                   4133: 	}
1.603     raeburn  4134:         if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   4135:             ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   4136:             $confirm_removal = 1;
                   4137:         }
1.633     raeburn  4138:         if ($url =~ /$LONCAPA::assess_re/) {
                   4139:             $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
                   4140:         }
1.329     droeschl 4141: 
1.538     raeburn  4142: 	if ($denied{'copy'}) {
1.543     raeburn  4143:             $copylink=(<<ENDCOPY)
1.507     raeburn  4144: <span style="visibility: hidden;">$lt{'cp'}</span>
                   4145: ENDCOPY
                   4146:         } else {
1.538     raeburn  4147:             my $formname = 'edit_copy_'.$orderidx;
                   4148:             my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 4149: 	    $copylink=(<<ENDCOPY);
1.538     raeburn  4150: <form name="$formname" method="post" action="/adm/coursedocs">
                   4151: $form_common
1.611     raeburn  4152: <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  4153: $form_end
1.329     droeschl 4154: ENDCOPY
1.538     raeburn  4155:             if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
                   4156:                 push(@{$filtersref->{'cancopy'}},$orderidx);
                   4157:             }
1.329     droeschl 4158:         }
1.538     raeburn  4159: 	if ($denied{'cut'}) {
1.507     raeburn  4160:             $cutlink=(<<ENDCUT);
                   4161: <span style="visibility: hidden;">$lt{'ct'}</span>
                   4162: ENDCUT
                   4163:         } else {
1.538     raeburn  4164:             my $formname = 'edit_cut_'.$orderidx;
                   4165:             my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 4166: 	    $cutlink=(<<ENDCUT);
1.538     raeburn  4167: <form name="$formname" method="post" action="/adm/coursedocs">
                   4168: $form_common
1.542     raeburn  4169: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611     raeburn  4170: <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  4171: $form_end
1.329     droeschl 4172: ENDCUT
1.538     raeburn  4173:             if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
                   4174:                 push(@{$filtersref->{'cancut'}},$orderidx);
                   4175:             }
1.329     droeschl 4176:         }
1.538     raeburn  4177:         if ($denied{'remove'}) {
1.507     raeburn  4178:             $removelink=(<<ENDREM);
                   4179: <span style="visibility: hidden;">$lt{'rm'}</a>
                   4180: ENDREM
                   4181:         } else {
1.538     raeburn  4182:             my $formname = 'edit_remove_'.$orderidx;
1.603     raeburn  4183:             my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497     raeburn  4184:             $removelink=(<<ENDREM);
1.538     raeburn  4185: <form name="$formname" method="post" action="/adm/coursedocs">
                   4186: $form_common
1.542     raeburn  4187: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603     raeburn  4188: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611     raeburn  4189: <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  4190: $form_end
1.497     raeburn  4191: ENDREM
1.538     raeburn  4192:             if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
                   4193:                 push(@{$filtersref->{'canremove'}},$orderidx);
                   4194:             }
1.497     raeburn  4195:         }
1.551     raeburn  4196:         $renamelink=(<<ENDREN);
1.581     raeburn  4197: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507     raeburn  4198: ENDREN
1.611     raeburn  4199:         my ($uplink,$downlink);
                   4200:         if ($canedit) {
                   4201:             $uplink = "/adm/coursedocs?cmd=up_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   4202:             $downlink = "/adm/coursedocs?cmd=down_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   4203:         } else {
                   4204:             $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
                   4205:             $downlink = $uplink;
                   4206:         }
1.329     droeschl 4207: 	$line.=(<<END);
                   4208: <td>
1.379     bisitz   4209: <div class="LC_docs_entry_move">
1.611     raeburn  4210:   <a href="$uplink">
1.501     raeburn  4211:     <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379     bisitz   4212:   </a>
                   4213: </div>
                   4214: <div class="LC_docs_entry_move">
1.611     raeburn  4215:   <a href="$downlink">
1.501     raeburn  4216:     <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379     bisitz   4217:   </a>
                   4218: </div>
1.329     droeschl 4219: </td>
                   4220: <td>
                   4221:    $form_start
1.538     raeburn  4222:    $form_param
1.478     raeburn  4223:    $form_common
1.329     droeschl 4224:    $selectbox
                   4225:    $form_end
                   4226: </td>
1.540     raeburn  4227: <td class="LC_docs_entry_commands LC_nobreak">
1.497     raeburn  4228: $removelink
1.329     droeschl 4229: $cutlink
                   4230: $copylink
                   4231: </td>
                   4232: END
                   4233:     }
                   4234: # Figure out what kind of a resource this is
                   4235:     my ($extension)=($url=~/\.(\w+)$/);
                   4236:     my $uploaded=($url=~/^\/*uploaded\//);
                   4237:     my $icon=&Apache::loncommon::icon($url);
1.519     raeburn  4238:     my $isfolder;
                   4239:     my $ispage;
                   4240:     my $containerarg;
1.615     raeburn  4241:     my $folderurl;
1.685     raeburn  4242:     my $plainurl;
1.329     droeschl 4243:     if ($uploaded) {
1.472     raeburn  4244:         if (($extension eq 'sequence') || ($extension eq 'page')) {
                   4245:             $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519     raeburn  4246:             $containerarg = $1;
1.472     raeburn  4247: 	    if ($extension eq 'sequence') {
                   4248: 	        $icon=$iconpath.'navmap.folder.closed.gif';
                   4249:                 $isfolder=1;
                   4250:             } else {
                   4251:                 $icon=$iconpath.'page.gif';
                   4252:                 $ispage=1;
                   4253:             }
1.615     raeburn  4254:             $folderurl = &Apache::lonnet::declutter($url);
1.472     raeburn  4255:             if ($allowed) {
                   4256:                 $url='/adm/coursedocs?';
                   4257:             } else {
                   4258:                 $url='/adm/supplemental?';
                   4259:             }
1.329     droeschl 4260: 	} else {
1.685     raeburn  4261: 	    $plainurl = $url;
1.329     droeschl 4262: 	}
                   4263:     }
1.364     bisitz   4264: 
1.621     raeburn  4265:     my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329     droeschl 4266:     my $orig_url = $url;
1.340     raeburn  4267:     $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.668     raeburn  4268:     if ($container eq 'page') {
                   4269:         $url=~s{^http(|s)(&colon;|:)//}{/ext/};
                   4270:     } else {
                   4271:         $url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
                   4272:     }
1.501     raeburn  4273:     if (!$supplementalflag && $residx && $symb) {
                   4274:         if ((!$isfolder) && (!$ispage)) {
                   4275: 	    (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668     raeburn  4276:             if (($url =~ m{^ext/}) && ($container eq 'page')) {
                   4277:                 $url=&Apache::lonnet::clutter_with_no_wrapper($url);
                   4278:             } else {
                   4279:                 $url=&Apache::lonnet::clutter($url);
                   4280:             } 
1.501     raeburn  4281: 	    if ($url=~/^\/*uploaded\//) {
                   4282: 	        $url=~/\.(\w+)$/;
                   4283: 	        my $embstyle=&Apache::loncommon::fileembstyle($1);
                   4284: 	        if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                   4285: 		    $url='/adm/wrapper'.$url;
                   4286: 	        } elsif ($embstyle eq 'ssi') {
                   4287: 		    #do nothing with these
                   4288: 	        } elsif ($url!~/\.(sequence|page)$/) {
                   4289: 		    $url='/adm/coursedocs/showdoc'.$url;
                   4290: 	        }
1.623     raeburn  4291: 	    } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
                   4292:                 my $wrapped = $1;
                   4293:                 my $exturl = $2;
1.668     raeburn  4294:                 if (($wrapped eq '') && ($container ne 'page')) { 
1.623     raeburn  4295:                     $url='/adm/wrapper'.$url;
                   4296:                 }
                   4297:                 if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
                   4298:                     $nomodal = 1;
                   4299:                 }
1.626     raeburn  4300: 	    } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4301: 		$url='/adm/wrapper'.$url;
1.621     raeburn  4302:             } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
                   4303:                 if (($ENV{'SERVER_PORT'} == 443) &&
                   4304:                     ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  4305:                     unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  4306:                         $url .= '?usehttp=1';
                   4307:                     }
1.621     raeburn  4308:                     $nomodal = 1;
                   4309:                 }
1.598     raeburn  4310:             }
1.696     raeburn  4311:             my $checkencrypt;
1.680     raeburn  4312:             if (!$env{'request.role.adv'}) {
1.615     raeburn  4313:                 if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680     raeburn  4314:                     ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615     raeburn  4315:                     $checkencrypt = 1;
1.620     raeburn  4316:                 } elsif (ref($navmapref)) {
1.615     raeburn  4317:                     unless (ref($$navmapref)) {
                   4318:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   4319:                     }
                   4320:                     if (ref($$navmapref)) {
                   4321:                         if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680     raeburn  4322:                             $checkencrypt = 1;
1.615     raeburn  4323:                         }
                   4324:                     }
                   4325:                 }
1.680     raeburn  4326:             }
                   4327:             if ($checkencrypt) {
                   4328:                 my $currenc = $env{'request.enc'};
                   4329:                 $env{'request.enc'} = 1;
                   4330:                 $shownsymb = &Apache::lonenc::encrypted($symb);
1.696     raeburn  4331:                 my $shownurl = &Apache::lonenc::encrypted($url);
1.680     raeburn  4332:                 if (&Apache::lonnet::symbverify($symb,$url)) {
                   4333:                     $url = $shownurl;
                   4334:                 } else {
                   4335:                     $url = '';
                   4336:                 }
                   4337:                 $env{'request.enc'} = $currenc;
                   4338:             } elsif (&Apache::lonnet::symbverify($symb,$url)) {
                   4339:                 $shownsymb = $symb;
                   4340:                 if ($isexternal) {
                   4341:                     $url =~ s/\#[^#]+$//;
                   4342:                     if ($container eq 'page') {
                   4343:                         $url = &Apache::lonnet::clutter($url);
1.613     raeburn  4344:                     }
1.612     raeburn  4345:                 }
1.696     raeburn  4346:             } else {
                   4347:                 $url = '';
1.680     raeburn  4348:             }
                   4349:             unless ($env{'request.role.adv'}) {
                   4350:                 if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4351:                     $url = '';
                   4352:                 }
                   4353:                 if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
                   4354:                     $url = '';
                   4355:                     $hiddenres = 1;
                   4356:                 }
                   4357:             }
1.696     raeburn  4358:             if (($url ne '') && ($shownsymb ne '')) {
                   4359:                 $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501     raeburn  4360:             }
1.329     droeschl 4361: 	}
1.621     raeburn  4362:     } elsif ($supplementalflag) {
1.610     raeburn  4363:         if ($isexternal) {
                   4364:             if ($url =~ /^([^#]+)#([^#]+)$/) {
                   4365:                 $url = $1;
                   4366:                 $anchor = $2;
1.623     raeburn  4367:                 if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678     raeburn  4368:                     unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  4369:                         if ($hostname ne '') {
                   4370:                             $url = 'http://'.$hostname.$url;
                   4371:                         }
                   4372:                         $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.623     raeburn  4373:                     }
                   4374:                     $nomodal = 1;
                   4375:                 }
1.610     raeburn  4376:             }
1.621     raeburn  4377:         } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   4378:             if (($ENV{'SERVER_PORT'} == 443) &&
                   4379:                 ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  4380:                 unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  4381:                     if ($hostname ne '') {
                   4382:                         $url = 'http://'.$hostname.$url;
                   4383:                     }
                   4384:                     $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  4385:                 }
1.621     raeburn  4386:                 $nomodal = 1;
                   4387:             }
1.686     raeburn  4388:         } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
                   4389:             my $embstyle=&Apache::loncommon::fileembstyle($extension);
                   4390:             unless ($embstyle eq 'ssi') {
                   4391:                 if (($embstyle eq 'img')
                   4392:                  || ($embstyle eq 'emb')
                   4393:                  || ($embstyle eq 'wrp')) {
                   4394:                     $url='/adm/wrapper'.$url;
                   4395:                 } elsif ($url !~ /\.(sequence|page)$/) {
                   4396:                     $url='/adm/coursedocs/showdoc'.$url;
                   4397:                 }
                   4398:             }
1.610     raeburn  4399:         }
1.685     raeburn  4400:         unless ($allowed && $env{'request.role.adv'}) {
                   4401:             if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4402:                 $hiddenres = 1;
                   4403:             }
                   4404:         }
1.329     droeschl 4405:     }
1.615     raeburn  4406:     my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617     raeburn  4407:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519     raeburn  4408:     if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329     droeschl 4409: 	my $foldername=&escape($foldertitle);
                   4410: 	my $folderpath=$env{'form.folderpath'};
                   4411: 	if ($folderpath) { $folderpath.='&' };
1.510     raeburn  4412:         if (!$allowed && $supplementalflag) {
1.519     raeburn  4413:             $folderpath.=$containerarg.'&'.$foldername;
1.510     raeburn  4414:             $url.='folderpath='.&escape($folderpath);
1.685     raeburn  4415:             if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4416:                 $hiddenfolder = 1;
1.682     raeburn  4417:             }
1.510     raeburn  4418:         } else {
1.617     raeburn  4419:             my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
                   4420:                                                         'parameter_randompick'))[0];
                   4421:             my $randorder = ((&LONCAPA::map::getparameter($orderidx,
                   4422:                                               'parameter_randomorder'))[0]=~/^yes$/i);
                   4423:             my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
                   4424:                                               'parameter_hiddenresource'))[0]=~/^yes$/i);
                   4425:             my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
                   4426:                                               'parameter_encrypturl'))[0]=~/^yes$/i);
                   4427:             unless ($hiddenmap) {
1.620     raeburn  4428:                 if (ref($navmapref)) {
                   4429:                     unless (ref($$navmapref)) {
                   4430:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   4431:                     }
                   4432:                     if (ref($$navmapref)) {
                   4433:                         if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
                   4434:                             my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
                   4435:                             unless (@resources) {
                   4436:                                 $hiddenmap = 1;
                   4437:                                 unless ($env{'request.role.adv'}) {  
                   4438:                                     $url = '';
                   4439:                                     $hiddenfolder = 1;
                   4440:                                 }
1.617     raeburn  4441:                             }
1.615     raeburn  4442:                         }
                   4443:                     }
                   4444:                 }
                   4445:             }
1.617     raeburn  4446:             unless ($encryptmap) {
1.620     raeburn  4447:                 if ((ref($navmapref)) && (ref($$navmapref))) {
                   4448:                     if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
                   4449:                         $encryptmap = 1;
                   4450:                     }
1.617     raeburn  4451:                 }
                   4452:             }
1.630     raeburn  4453: 
1.617     raeburn  4454: # Append randompick number, hidden, and encrypted with ":" to foldername,
                   4455: # so it gets transferred between levels
                   4456: 	    $folderpath.=$containerarg.'&'.$foldername.
                   4457:                          ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615     raeburn  4458:             unless ($url eq '') {
1.612     raeburn  4459:                 $url.='folderpath='.&escape($folderpath);
                   4460:             }
1.510     raeburn  4461:             my $rpckchk;
                   4462:             if ($rpicknum) {
                   4463:                 $rpckchk = ' checked="checked"';
1.543     raeburn  4464:                 if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
                   4465:                     push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
                   4466:                 }
1.510     raeburn  4467:             }
1.537     raeburn  4468:             my $formname = 'edit_randompick_'.$orderidx;
1.510     raeburn  4469: 	    $rand_pick_text = 
1.478     raeburn  4470: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  4471: $form_param."\n".
1.478     raeburn  4472: $form_common."\n".
1.611     raeburn  4473: '<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  4474:             if ($rpicknum ne '') {
                   4475:                 $rand_pick_text .= ':&nbsp;<a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
                   4476:             }
1.537     raeburn  4477:             $rand_pick_text .= '</span></span>'.
                   4478:                                $form_end;
1.543     raeburn  4479:             my $ro_set;
1.617     raeburn  4480:             if ($randorder) {
1.543     raeburn  4481:                 $ro_set = 'checked="checked"';
                   4482:                 if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
                   4483:                     push(@{$filtersref->{'randomorder'}},$orderidx);
                   4484:                 }
                   4485:             }
1.564     raeburn  4486:             $formname = 'edit_rorder_'.$orderidx;
1.510     raeburn  4487: 	    $rand_order_text = 
1.537     raeburn  4488: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  4489: $form_param."\n".
1.537     raeburn  4490: $form_common."\n".
1.611     raeburn  4491: '<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  4492: $form_end; 
1.510     raeburn  4493:         }
1.509     raeburn  4494:     } elsif ($supplementalflag && !$allowed) {
1.598     raeburn  4495:         my $isexttool;
1.626     raeburn  4496:         if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4497:             $url='/adm/wrapper'.$url;
                   4498:             $isexttool = 1;
                   4499:         }
1.510     raeburn  4500:         $url .= ($url =~ /\?/) ? '&amp;':'?';
1.509     raeburn  4501:         $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510     raeburn  4502:         if ($title) {
1.687     raeburn  4503:             $url .= '&amp;title='.$encodedtitle;
1.510     raeburn  4504:         }
1.598     raeburn  4505:         if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510     raeburn  4506:             $url .= '&amp;idx='.$orderidx;
                   4507:         }
1.610     raeburn  4508:         if ($anchor ne '') {
                   4509:             $url .= '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   4510:         }
1.329     droeschl 4511:     }
1.519     raeburn  4512:     my ($tdalign,$tdwidth);
1.501     raeburn  4513:     if ($allowed) {
1.630     raeburn  4514:         my $fileloc =
1.501     raeburn  4515:             &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510     raeburn  4516:         if ($isexternal) {
1.630     raeburn  4517:             ($editlink,$extresform) =
1.611     raeburn  4518:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   4519:                                                      undef,undef,undef,undef,undef,undef,
                   4520:                                                      undef,$disabled);
1.626     raeburn  4521:         } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4522:             ($editlink,$extresform) =
                   4523:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   4524:                                                      undef,undef,undef,'tool',$coursedom,
1.611     raeburn  4525:                                                      $coursenum,$ltitoolsref,$disabled);
1.511     raeburn  4526:         } elsif (!$isfolder && !$ispage) {
1.503     raeburn  4527:             my ($cfile,$home,$switchserver,$forceedit,$forceview) = 
                   4528:                 &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511     raeburn  4529:             if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610     raeburn  4530:                 my $suppanchor;
                   4531:                 if ($supplementalflag) {
                   4532:                     $suppanchor = $anchor;
                   4533:                 }
1.630     raeburn  4534:                 my $jscall =
1.501     raeburn  4535:                     &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
                   4536:                                                             $switchserver,
1.503     raeburn  4537:                                                             $forceedit,
1.679     raeburn  4538:                                                             undef,$symb,$shownsymb,
1.511     raeburn  4539:                                                             &escape($env{'form.folderpath'}),
1.622     raeburn  4540:                                                             $renametitle,$hostname,
                   4541:                                                             '','',1,$suppanchor);
1.501     raeburn  4542:                 if ($jscall) {
1.518     raeburn  4543:                     $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
                   4544:                                 $jscall.'" >'.&mt('Edit').'</a>&nbsp;'."\n";
1.501     raeburn  4545:                 }
                   4546:             }
                   4547:         }
1.519     raeburn  4548:         $tdalign = ' align="right" valign="top"';
                   4549:         $tdwidth = ' width="80%"';
1.329     droeschl 4550:     }
1.408     raeburn  4551:     my $reinit;
                   4552:     if ($crstype eq 'Community') {
                   4553:         $reinit = &mt('(re-initialize community to access)');
                   4554:     } else {
                   4555:         $reinit = &mt('(re-initialize course to access)');
1.519     raeburn  4556:     }
                   4557:     $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650     raeburn  4558:     if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633     raeburn  4559:         $line.= '<br />';
                   4560:         if ($curralias ne '') {
                   4561:             $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   4562:                    $lt{'da'}.'</a></span>';
                   4563:         } else {
                   4564:             $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   4565:                    $lt{'sa'}.'</a></span>';
                   4566:         }
                   4567:     }
                   4568:     $line.='</td><td>';
1.685     raeburn  4569:     my ($link,$nolink);
1.472     raeburn  4570:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685     raeburn  4571:         if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
                   4572:             if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4573:                 $nolink = 1;
                   4574:             }
                   4575:         }
                   4576:         if ($nolink) {
                   4577:             $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
                   4578:         } else {
                   4579:             $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
                   4580:         }
1.469     www      4581:     } elsif ($url) {
1.610     raeburn  4582:        if ($anchor ne '') {
                   4583:            if ($supplementalflag) {
                   4584:                $anchor = '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   4585:            } else {
                   4586:                $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
                   4587:            }
                   4588:        }
1.622     raeburn  4589:        if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
                   4590:            $link = 'http://'.$hostname.$url;
                   4591:        } else {
                   4592:            $link = $url;
                   4593:        }
1.659     raeburn  4594:        $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.$anchor);
1.685     raeburn  4595:        if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
                   4596:            if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4597:                $nolink = 1;
                   4598:            }
                   4599:        }
                   4600:        if ($nolink) {
                   4601:            $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
                   4602:        } elsif ($nomodal) {
1.621     raeburn  4603:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   4604:                   '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
                   4605:        } else {
                   4606:            $line.=&Apache::loncommon::modal_link($link,
                   4607:                                                  '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
                   4608:        }
1.469     www      4609:     } else {
                   4610:        $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
                   4611:     }
1.519     raeburn  4612:     $line.='</span></td><td'.$tdwidth.'>';
1.472     raeburn  4613:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685     raeburn  4614:        if ($nolink) {
                   4615:            $line.=$title;
                   4616:        } else {
                   4617:            $line.='<a href="'.$url.'">'.$title.'</a>';
                   4618:        }
1.682     raeburn  4619:        if (!$allowed && $supplementalflag && $canedit && $isfolder) {
                   4620:            my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
                   4621:            my $editurl = $url;
                   4622:            $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;};
                   4623:            $line .= '&nbsp;'.'<a href="'.$editurl.'">'.
                   4624:                     '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
                   4625:                     '</a>';
                   4626:        }
                   4627:        if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag))  {
                   4628:            $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
                   4629:        }
1.469     www      4630:     } elsif ($url) {
1.685     raeburn  4631:        if ($nolink) {
                   4632:            $line.=$title;
                   4633:        } elsif ($nomodal) {
1.621     raeburn  4634:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   4635:                   $title.'</a>';
                   4636:        } else {
                   4637:            $line.=&Apache::loncommon::modal_link($link,$title,600,500);
                   4638:        }
1.617     raeburn  4639:     } elsif (($hiddenfolder) || ($hiddenres)) {
1.632     raeburn  4640:        $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469     www      4641:     } else {
                   4642:        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
                   4643:     }
1.633     raeburn  4644:     if (($allowed) && ($curralias ne '')) {
                   4645:         $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
                   4646:     } else {
                   4647:         $line .= $extresform;
                   4648:     }
                   4649:     $line .= '</td>';
1.478     raeburn  4650:     $rand_pick_text = '&nbsp;' if ($rand_pick_text eq '');
                   4651:     $rand_order_text = '&nbsp;' if ($rand_order_text eq '');
1.685     raeburn  4652:     if ($uploaded && $url && !$isfolder && !$ispage) {
                   4653:         if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
                   4654:             &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
                   4655:         }
                   4656:     }
1.682     raeburn  4657:     if ($allowed) {
                   4658:         my %lt=&Apache::lonlocal::texthash(
                   4659:                               'hd' => 'Hidden',
                   4660:                               'ec' => 'URL hidden');
                   4661:         my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543     raeburn  4662:         if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4663:             $hidtext = ' checked="checked"';
1.694     raeburn  4664:             if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543     raeburn  4665:                 push(@{$filtersref->{'hiddenresource'}},$orderidx);
                   4666:             }
                   4667:         }
1.682     raeburn  4668:         $formhidden = 'edit_hiddenresource_'.$orderidx;
                   4669:         $line.=(<<ENDPARMS);
1.329     droeschl 4670:   <td class="LC_docs_entry_parameter">
1.537     raeburn  4671:     <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538     raeburn  4672:     $form_param
1.478     raeburn  4673:     $form_common
1.611     raeburn  4674:     <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329     droeschl 4675:     $form_end
1.682     raeburn  4676: ENDPARMS
                   4677:         if ($folder =~/^supplemental/) {
                   4678:             $line.= "\n    <td>";
                   4679:         } else {
                   4680:             if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
                   4681:                 $enctext = ' checked="checked"';
                   4682:                 if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
                   4683:                     push(@{$filtersref->{'encrypturl'}},$orderidx);
                   4684:                 }
                   4685:             }
                   4686:             $formurlhidden = 'edit_encrypturl_'.$orderidx;
                   4687: 	    $line.=(<<ENDPARMS);
1.458     raeburn  4688:     <br />
1.537     raeburn  4689:     <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538     raeburn  4690:     $form_param
1.478     raeburn  4691:     $form_common
1.611     raeburn  4692:     <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329     droeschl 4693:     $form_end
                   4694:   </td>
1.478     raeburn  4695:   <td class="LC_docs_entry_parameter">$rand_pick_text<br />
                   4696:                                       $rand_order_text</td>
1.329     droeschl 4697: ENDPARMS
1.682     raeburn  4698:         }
1.329     droeschl 4699:     }
1.379     bisitz   4700:     $line.=&Apache::loncommon::end_data_table_row();
1.329     droeschl 4701:     return $line;
                   4702: }
                   4703: 
1.538     raeburn  4704: sub action_restrictions {
                   4705:     my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
                   4706:     my %denied = (
                   4707:                    cut    => 0,
                   4708:                    copy   => 0,
                   4709:                    remove => 0,
                   4710:                  );
                   4711:     if ($url=~ m{^/res/.+\.(page|sequence)$}) {
                   4712:         # no copy for published maps
                   4713:         $denied{'copy'} = 1;
1.597     raeburn  4714:     } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
                   4715:         unless ($1 eq 'simpleproblem') {
                   4716:             $denied{'copy'} = 1;
                   4717:         }
                   4718:         $denied{'cut'} = 1;
1.538     raeburn  4719:     } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
                   4720:         if ($folderpath =~ /^default&[^\&]+$/) {
                   4721:             if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
                   4722:                 $denied{'remove'} = 1;
                   4723:             }
                   4724:             $denied{'cut'} = 1;
                   4725:             $denied{'copy'} = 1;
                   4726:         }
                   4727:     } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
                   4728:         my $group = $1;
                   4729:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
                   4730:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   4731:                 $denied{'remove'} = 1;
                   4732:             }
                   4733:         }
                   4734:         $denied{'cut'} = 1;
                   4735:         $denied{'copy'} = 1;
                   4736:     } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
                   4737:         my $group = $1;
                   4738:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
                   4739:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   4740:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   4741:                 if (keys(%groupsettings) > 0) {
                   4742:                     $denied{'remove'} = 1;
                   4743:                 }
                   4744:                 $denied{'cut'} = 1;
                   4745:                 $denied{'copy'} = 1;
                   4746:             }
                   4747:         }
                   4748:     } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
                   4749:         my $group = $1;
                   4750:         if ($url =~ /group_boards_\Q$group\E/) {
                   4751:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   4752:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   4753:                 if (keys(%groupsettings) > 0) {
                   4754:                     if (ref($groupsettings{'functions'}) eq 'HASH') {
                   4755:                         if ($groupsettings{'functions'}{'discussion'} eq 'on') {
                   4756:                             $denied{'remove'} = 1;
                   4757:                         }
                   4758:                     }
                   4759:                 }
                   4760:                 $denied{'cut'} = 1;
                   4761:                 $denied{'copy'} = 1;
                   4762:             }
                   4763:         }
                   4764:     }
                   4765:     return %denied;
                   4766: }
                   4767: 
1.533     raeburn  4768: sub new_timebased_suffix {
1.538     raeburn  4769:     my ($dom,$num,$type,$area,$container) = @_;
1.533     raeburn  4770:     my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538     raeburn  4771:     if ($type eq 'paste') {
                   4772:         $prefix = $type;
                   4773:         $namespace = 'courseeditor';
1.587     raeburn  4774:         $idtype = 'addcode';
1.538     raeburn  4775:     } elsif ($type eq 'map') {
1.533     raeburn  4776:         $prefix = 'docs';
                   4777:         if ($area eq 'supplemental') {
                   4778:             $prefix = 'supp';
                   4779:         }
                   4780:         $prefix .= $container;
                   4781:         $namespace = 'uploadedmaps';
                   4782:     } else {
                   4783:         $prefix = $type;
                   4784:         $namespace = 'templated';
1.504     raeburn  4785:     }
                   4786:     my ($suffix,$freedlock,$error) =
1.587     raeburn  4787:         &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504     raeburn  4788:     if (!$suffix) {
1.538     raeburn  4789:         if ($type eq 'paste') {
                   4790:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
                   4791:         } elsif ($type eq 'map') {
1.533     raeburn  4792:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
                   4793:         } elsif ($type eq 'smppg') {
                   4794:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626     raeburn  4795:         } elsif ($type eq 'exttool') {
                   4796:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533     raeburn  4797:         } else {
1.565     bisitz   4798:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533     raeburn  4799:         }
1.504     raeburn  4800:         if ($error) {
                   4801:             $errtext .= '<br />'.$error;
                   4802:         }
                   4803:     }
                   4804:     if ($freedlock ne 'ok') {
1.630     raeburn  4805:         $locknotfreed =
1.533     raeburn  4806:             '<div class="LC_error">'.
                   4807:             &mt('There was a problem removing a lockfile.').' ';
1.538     raeburn  4808:         if ($type eq 'paste') {
1.591     raeburn  4809:             if ($freedlock eq 'nolock') {
                   4810:                 $locknotfreed =
                   4811:                     '<div class="LC_error">'.
                   4812:                     &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
                   4813:  
1.593     droeschl 4814:                     &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591     raeburn  4815:             } else { 
                   4816:                 $locknotfreed .=
                   4817:                     &mt('This will prevent addition of items to the clipboard until your next log-in.');
                   4818:             }
1.538     raeburn  4819:         } elsif ($type eq 'map') {
1.591     raeburn  4820:             $locknotfreed .=
                   4821:                 &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533     raeburn  4822:         } elsif ($type eq 'smppg') {
                   4823:             $locknotfreed .=
                   4824:                 &mt('This will prevent creation of additional simple pages in this course.');
1.626     raeburn  4825:         } elsif ($type eq 'exttool') {
                   4826:             $locknotfreed .=
                   4827:                 &mt('This will prevent creation of additional external tools in this course.');
1.533     raeburn  4828:         } else {
                   4829:             $locknotfreed .=
1.565     bisitz   4830:                 &mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  4831:         }
1.538     raeburn  4832:         unless ($type eq 'paste') {
                   4833:             $locknotfreed .=
1.560     raeburn  4834:                 ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   4835:                         '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538     raeburn  4836:         }
                   4837:         $locknotfreed .= '</div>';
1.504     raeburn  4838:     }
                   4839:     return ($suffix,$errtext,$locknotfreed);
                   4840: }
                   4841: 
1.329     droeschl 4842: =pod
                   4843: 
                   4844: =item tiehash()
                   4845: 
                   4846: tie the hash
                   4847: 
                   4848: =cut
                   4849: 
                   4850: sub tiehash {
                   4851:     my ($mode)=@_;
                   4852:     $hashtied=0;
                   4853:     if ($env{'request.course.fn'}) {
                   4854: 	if ($mode eq 'write') {
                   4855: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   4856: 		    &GDBM_WRCREAT(),0640)) {
                   4857:                 $hashtied=2;
                   4858: 	    }
                   4859: 	} else {
                   4860: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   4861: 		    &GDBM_READER(),0640)) {
                   4862:                 $hashtied=1;
                   4863: 	    }
                   4864: 	}
1.364     bisitz   4865:     }
1.329     droeschl 4866: }
                   4867: 
                   4868: sub untiehash {
                   4869:     if ($hashtied) { untie %hash; }
                   4870:     $hashtied=0;
                   4871:     return OK;
                   4872: }
                   4873: 
                   4874: 
                   4875: 
                   4876: 
                   4877: sub checkonthis {
1.637     raeburn  4878:     my ($r,$url,$level,$title,$checkstale)=@_;
1.329     droeschl 4879:     $url=&unescape($url);
                   4880:     $alreadyseen{$url}=1;
                   4881:     $r->rflush();
                   4882:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
                   4883:        $r->print("\n<br />");
                   4884:        if ($level==0) {
                   4885:            $r->print("<br />");
                   4886:        }
                   4887:        for (my $i=0;$i<=$level*5;$i++) {
                   4888:            $r->print('&nbsp;');
                   4889:        }
                   4890:        $r->print('<a href="'.$url.'" target="cat">'.
                   4891: 		 ($title?$title:$url).'</a> ');
                   4892:        if ($url=~/^\/res\//) {
1.637     raeburn  4893:           my $updated;
                   4894:           if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
                   4895:               ($url !~ /\.\d+\.\w+$/)) {
                   4896:               $updated = &Apache::lonnet::remove_stale_resfile($url);
                   4897:           }
1.329     droeschl 4898: 	  my $result=&Apache::lonnet::repcopy(
                   4899:                               &Apache::lonnet::filelocation('',$url));
                   4900:           if ($result eq 'ok') {
                   4901:              $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637     raeburn  4902:              if ($updated) {
                   4903:                  $r->print('<br />');
                   4904:                  for (my $i=0;$i<=$level*5;$i++) {
                   4905:                      $r->print('&nbsp;');
                   4906:                  }
                   4907:                  $r->print('- '.&mt('Outdated copy removed'));
                   4908:              }
1.329     droeschl 4909:              $r->rflush();
                   4910:              &Apache::lonnet::countacc($url);
                   4911:              $url=~/\.(\w+)$/;
                   4912:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                   4913: 		 $r->print('<br />');
                   4914:                  $r->rflush();
                   4915:                  for (my $i=0;$i<=$level*5;$i++) {
                   4916:                      $r->print('&nbsp;');
                   4917:                  }
                   4918:                  $r->print('- '.&mt('Rendering:').' ');
                   4919: 		 my ($errorcount,$warningcount)=split(/:/,
                   4920: 	       &Apache::lonnet::ssi_body($url,
                   4921: 			       ('grade_target'=>'web',
                   4922: 				'return_only_error_and_warning_counts' => 1)));
                   4923:                  if (($errorcount) ||
                   4924:                      ($warningcount)) {
                   4925: 		     if ($errorcount) {
1.369     bisitz   4926:                         $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329     droeschl 4927:                           &mt('[quant,_1,error]',$errorcount).'</span>');
                   4928:                      }
                   4929: 		     if ($warningcount) {
                   4930:                         $r->print('<span class="LC_warning">'.
                   4931:                           &mt('[quant,_1,warning]',$warningcount).'</span>');
                   4932:                      }
                   4933:                  } else {
                   4934:                      $r->print('<span class="LC_success">'.&mt('ok').'</span>');
                   4935:                  }
                   4936:                  $r->rflush();
                   4937:              }
                   4938: 	     my $dependencies=
                   4939:                 &Apache::lonnet::metadata($url,'dependencies');
                   4940:              foreach my $dep (split(/\,/,$dependencies)) {
                   4941: 		 if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637     raeburn  4942:                     &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329     droeschl 4943:                  }
                   4944:              }
                   4945:           } elsif ($result eq 'unavailable') {
                   4946:              $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
                   4947:           } elsif ($result eq 'not_found') {
                   4948: 	      unless ($url=~/\$/) {
1.521     bisitz   4949: 		  $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329     droeschl 4950: 	      } else {
1.366     bisitz   4951: 		  $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329     droeschl 4952: 	      }
                   4953:           } else {
                   4954:              $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
                   4955:           }
1.637     raeburn  4956:           if (($updated) && ($result ne 'ok')) {
                   4957:               $r->print('<br />'.&mt('Outdated copy removed'));
                   4958:           }
1.329     droeschl 4959:        }
                   4960:     }
                   4961: }
                   4962: 
                   4963: 
                   4964: 
                   4965: =pod
                   4966: 
                   4967: =item list_symbs()
                   4968: 
1.485     raeburn  4969: List Content Identifiers
1.329     droeschl 4970: 
                   4971: =cut
                   4972: 
                   4973: sub list_symbs {
                   4974:     my ($r) = @_;
                   4975: 
1.408     raeburn  4976:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  4977:     $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
                   4978:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
                   4979:     $r->print(&startContentScreen('tools'));
1.329     droeschl 4980:     my $navmap = Apache::lonnavmaps::navmap->new();
                   4981:     if (!defined($navmap)) {
                   4982:         $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
                   4983:                   '<div class="LC_error">'.
                   4984:                   &mt('Unable to retrieve information about course contents').
                   4985:                   '</div>');
1.408     raeburn  4986:         &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329     droeschl 4987:     } else {
1.484     raeburn  4988:         $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
                   4989:                   &Apache::loncommon::start_data_table().
                   4990:                   &Apache::loncommon::start_data_table_header_row().
                   4991:                   '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
                   4992:                   &Apache::loncommon::end_data_table_header_row()."\n");
                   4993:         my $count;
1.329     droeschl 4994:         foreach my $res ($navmap->retrieveResources()) {
1.484     raeburn  4995:             $r->print(&Apache::loncommon::start_data_table_row().
                   4996:                       '<td>'.$res->compTitle().'</td>'.
                   4997:                       '<td>'.$res->symb().'</td>'.
1.521     bisitz   4998:                       &Apache::loncommon::end_data_table_row());
1.484     raeburn  4999:             $count ++;
                   5000:         }
                   5001:         if (!$count) {
                   5002:             $r->print(&Apache::loncommon::start_data_table_row().
                   5003:                       '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
                   5004:                       &Apache::loncommon::end_data_table_row()); 
1.329     droeschl 5005:         }
1.484     raeburn  5006:         $r->print(&Apache::loncommon::end_data_table());
1.329     droeschl 5007:     }
1.521     bisitz   5008:     $r->print(&endContentScreen());
1.329     droeschl 5009: }
                   5010: 
1.651     raeburn  5011: sub short_urls {
                   5012:     my ($r,$canedit) = @_;
                   5013:     my $crstype = &Apache::loncommon::course_type();
                   5014:     my $formname = 'shortenurl';
                   5015:     $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
                   5016:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
                   5017:     $r->print(&startContentScreen('tools'));
                   5018:     my ($navmap,$errormsg) =
                   5019:         &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
                   5020:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   5021:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   5022:     my (%maps,%resources,%titles);
                   5023:     if (!ref($navmap)) {
                   5024:         $r->print($errormsg.
                   5025:                   &endContentScreen());
                   5026:         return '';
                   5027:     } else {
1.652     raeburn  5028:         $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651     raeburn  5029:         $r->rflush();
                   5030:         my $readonly;
                   5031:         if ($canedit) {
1.671     raeburn  5032:             my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651     raeburn  5033:             if ($numnew) {
                   5034:                 $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
                   5035:             }
                   5036:             if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
                   5037:                 $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
                   5038:                 foreach my $error (@{$errors}) {
                   5039:                     $r->print('<li>'.$error.'</li>');
                   5040:                 }
                   5041:                 $r->print('</ul><br />');
                   5042:             }
                   5043:         } else {
                   5044:             $readonly = 1;
                   5045:         }
                   5046:         my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
                   5047:         $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
                   5048:                                                              undef,undef,undef,undef,undef,\%currtiny,$readonly));
                   5049:     }
                   5050:     $r->print(&endContentScreen());
                   5051: }
                   5052: 
1.637     raeburn  5053: sub contentverifyform {
                   5054:     my ($r) = @_;
                   5055:     my $crstype = &Apache::loncommon::course_type();
                   5056:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   5057:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
                   5058:     $r->print(&startContentScreen('tools'));
                   5059:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
                   5060:     $r->print('<form method="post" action="/adm/coursedocs"><p>'.
                   5061:               &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
                   5062:               '&nbsp;<span class="LC_nobreak">'.
                   5063:               '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
                   5064:               &mt('No').'</label>'.('&nbsp;'x2).
                   5065:               '<label><input type="radio" name="checkstale" value="1" />'.
                   5066:               &mt('Yes').'</label></span></p><p>'.
1.674     raeburn  5067:               '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637     raeburn  5068:               '<input type="hidden" value="1" name="tools" />'.
                   5069:               '<input type="hidden" value="1" name="verify" /></p></form>');
                   5070:     $r->print(&endContentScreen());
                   5071:     return;
                   5072: }
1.329     droeschl 5073: 
                   5074: sub verifycontent {
1.637     raeburn  5075:     my ($r,$checkstale) = @_;
1.408     raeburn  5076:     my $crstype = &Apache::loncommon::course_type();
1.549     raeburn  5077:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   5078:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484     raeburn  5079:     $r->print(&startContentScreen('tools'));
                   5080:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>'); 
1.329     droeschl 5081:    $hashtied=0;
                   5082:    undef %alreadyseen;
                   5083:    %alreadyseen=();
                   5084:    &tiehash();
1.484     raeburn  5085:    
1.329     droeschl 5086:    foreach my $key (keys(%hash)) {
                   5087:        if ($hash{$key}=~/\.(page|sequence)$/) {
                   5088: 	   if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
                   5089: 	       $r->print('<hr /><span class="LC_error">'.
1.419     bisitz   5090: 			 &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329     droeschl 5091: 			 &unescape($hash{$key}).'</span><br />'.
1.419     bisitz   5092: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329     droeschl 5093: 	   }
                   5094:        }
                   5095:        if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637     raeburn  5096:            &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329     droeschl 5097:        }
                   5098:    }
                   5099:    &untiehash();
1.442     www      5100:    $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521     bisitz   5101:     $r->print(&endContentScreen());
1.329     droeschl 5102: }
                   5103: 
                   5104: sub devalidateversioncache {
                   5105:     my $src=shift;
                   5106:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
                   5107: 					  &Apache::lonnet::clutter($src));
                   5108: }
                   5109: 
                   5110: sub checkversions {
1.611     raeburn  5111:     my ($r,$canedit) = @_;
1.408     raeburn  5112:     my $crstype = &Apache::loncommon::course_type();
1.571     raeburn  5113:     $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
                   5114:     $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484     raeburn  5115:     $r->print(&startContentScreen('tools'));
1.442     www      5116: 
1.329     droeschl 5117:     my $header='';
                   5118:     my $startsel='';
                   5119:     my $monthsel='';
                   5120:     my $weeksel='';
                   5121:     my $daysel='';
                   5122:     my $allsel='';
                   5123:     my %changes=();
                   5124:     my $starttime=0;
                   5125:     my $haschanged=0;
                   5126:     my %setversions=&Apache::lonnet::dump('resourceversions',
                   5127: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   5128: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   5129: 
                   5130:     $hashtied=0;
                   5131:     &tiehash();
1.611     raeburn  5132:     if ($canedit) {
                   5133:         my %newsetversions=();
                   5134:         if ($env{'form.setmostrecent'}) {
                   5135: 	    $haschanged=1;
                   5136: 	    foreach my $key (keys(%hash)) {
                   5137: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   5138: 		    $newsetversions{$1}='mostrecent';
                   5139:                     &devalidateversioncache($1);
                   5140: 	        }
                   5141: 	    }
                   5142:         } elsif ($env{'form.setcurrent'}) {
                   5143: 	    $haschanged=1;
                   5144: 	    foreach my $key (keys(%hash)) {
                   5145: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   5146: 		    my $getvers=&Apache::lonnet::getversion($1);
                   5147: 		    if ($getvers>0) {
                   5148: 		        $newsetversions{$1}=$getvers;
                   5149: 		        &devalidateversioncache($1);
                   5150: 		    }
                   5151: 	        }
1.329     droeschl 5152: 	    }
1.611     raeburn  5153:         } elsif ($env{'form.setversions'}) {
                   5154: 	    $haschanged=1;
                   5155: 	    foreach my $key (keys(%env)) {
                   5156: 	        if ($key=~/^form\.set_version_(.+)$/) {
                   5157: 		    my $src=$1;
                   5158: 		    if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
                   5159: 		        $newsetversions{$src}=$env{$key};
                   5160: 		        &devalidateversioncache($src);
                   5161: 		    }
                   5162: 	        }
1.329     droeschl 5163: 	    }
1.611     raeburn  5164:         }
                   5165:         if ($haschanged) {
                   5166:             if (&Apache::lonnet::put('resourceversions',\%newsetversions,
                   5167: 			             $env{'course.'.$env{'request.course.id'}.'.domain'},
                   5168: 			             $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
                   5169: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   5170:                     &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
                   5171: 	    } else {
                   5172: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   5173:                     &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329     droeschl 5174: 	    }
1.611     raeburn  5175: 	    &mark_hash_old();
                   5176:         }
                   5177:         &changewarning($r,'');
1.329     droeschl 5178:     }
                   5179:     if ($env{'form.timerange'} eq 'all') {
                   5180: # show all documents
1.549     raeburn  5181: 	$header=&mt('All content in '.$crstype);
1.521     bisitz   5182: 	$allsel=' selected="selected"';
1.329     droeschl 5183: 	foreach my $key (keys(%hash)) {
                   5184: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   5185: 		my $src=$1;
                   5186: 		$changes{$src}=1;
                   5187: 	    }
                   5188: 	}
                   5189:     } else {
                   5190: # show documents which changed
                   5191: 	%changes=&Apache::lonnet::dump
                   5192: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
                   5193:                      $env{'course.'.$env{'request.course.id'}.'.num'});
                   5194: 	my $firstkey=(keys(%changes))[0];
                   5195: 	unless ($firstkey=~/^error\:/) {
                   5196: 	    unless ($env{'form.timerange'}) {
                   5197: 		$env{'form.timerange'}=604800;
                   5198: 	    }
                   5199: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
                   5200: 		.&mt('seconds');
                   5201: 	    if ($env{'form.timerange'}==-1) {
                   5202: 		$seltext='since start of course';
1.521     bisitz   5203: 		$startsel=' selected="selected"';
1.329     droeschl 5204: 		$env{'form.timerange'}=time;
                   5205: 	    }
                   5206: 	    $starttime=time-$env{'form.timerange'};
                   5207: 	    if ($env{'form.timerange'}==2592000) {
                   5208: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5209: 		$monthsel=' selected="selected"';
1.329     droeschl 5210: 	    } elsif ($env{'form.timerange'}==604800) {
                   5211: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5212: 		$weeksel=' selected="selected"';
1.329     droeschl 5213: 	    } elsif ($env{'form.timerange'}==86400) {
                   5214: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5215: 		$daysel=' selected="selected"';
1.329     droeschl 5216: 	    }
                   5217: 	    $header=&mt('Content changed').' '.$seltext;
                   5218: 	} else {
                   5219: 	    $header=&mt('No content modifications yet.');
                   5220: 	}
                   5221:     }
                   5222:     %setversions=&Apache::lonnet::dump('resourceversions',
                   5223: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   5224: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   5225:     my %lt=&Apache::lonlocal::texthash
1.408     raeburn  5226: 	      ('st' => 'Version changes since start of '.$crstype,
1.329     droeschl 5227: 	       'lm' => 'Version changes since last Month',
                   5228: 	       'lw' => 'Version changes since last Week',
                   5229: 	       'sy' => 'Version changes since Yesterday',
                   5230:                'al' => 'All Resources (possibly large output)',
1.484     raeburn  5231:                'cd' => 'Change display', 
1.329     droeschl 5232: 	       'sd' => 'Display',
                   5233: 	       'fi' => 'File',
                   5234: 	       'md' => 'Modification Date',
                   5235:                'mr' => 'Most recently published Version',
1.408     raeburn  5236: 	       've' => 'Version used in '.$crstype,
                   5237:                'vu' => 'Set Version to be used in '.$crstype,
                   5238: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329     droeschl 5239: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                   5240: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479     golterma 5241: 	       'di' => 'Differences',
1.484     raeburn  5242: 	       'save' => 'Save changes',
                   5243:                'vers' => 'Version choice(s) for specific resources', 
1.479     golterma 5244: 	       'act' => 'Actions');
1.611     raeburn  5245:     my ($disabled,$readonly);
                   5246:     unless ($canedit) {
                   5247:         $disabled = 'disabled="disabled"';
                   5248:         $readonly = 1;
                   5249:     }
1.329     droeschl 5250:     $r->print(<<ENDHEADERS);
1.484     raeburn  5251: <h4 class="LC_info">$header</h4>
1.329     droeschl 5252: <form action="/adm/coursedocs" method="post">
                   5253: <input type="hidden" name="versions" value="1" />
1.484     raeburn  5254: <div class="LC_left_float">
1.479     golterma 5255: <fieldset>
1.484     raeburn  5256: <legend>$lt{'cd'}</legend>
1.329     droeschl 5257: <select name="timerange">
1.521     bisitz   5258: <option value='all'$allsel>$lt{'al'}</option>
                   5259: <option value="-1"$startsel>$lt{'st'}</option>
                   5260: <option value="2592000"$monthsel>$lt{'lm'}</option>
                   5261: <option value="604800"$weeksel>$lt{'lw'}</option>
                   5262: <option value="86400"$daysel>$lt{'sy'}</option>
1.329     droeschl 5263: </select>
                   5264: <input type="submit" name="display" value="$lt{'sd'}" />
1.484     raeburn  5265: </fieldset>
                   5266: </div>
                   5267: <div class="LC_left_float">
                   5268: <fieldset>
                   5269: <legend>$lt{'act'}</legend>
1.611     raeburn  5270: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
                   5271: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484     raeburn  5272: </fieldset>
                   5273: </div>
                   5274: <br clear="all" />
                   5275: <hr />
                   5276: <h4>$lt{'vers'}</h4>
1.329     droeschl 5277: ENDHEADERS
1.479     golterma 5278:     #number of columns for version history
1.571     raeburn  5279:     my %changedbytime;
                   5280:     foreach my $key (keys(%changes)) {
                   5281:         #excludes not versionable problems from resource version history:
                   5282:         next if ($key =~ /^\/res\/lib\/templates/);
                   5283:         my $chg;
                   5284:         if ($env{'form.timerange'} eq 'all') {
                   5285:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   5286:             $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
                   5287:         } else {
                   5288:             $chg = $changes{$key};
                   5289:             next if ($chg < $starttime);
                   5290:         }
                   5291:         push(@{$changedbytime{$chg}},$key);
                   5292:     }
                   5293:     if (keys(%changedbytime) == 0) {
                   5294:         &untiehash();
                   5295:         $r->print(&mt('No content changes in imported content in specified time frame').
                   5296:                   &endContentScreen());
                   5297:         return;
                   5298:     }
1.479     golterma 5299:     $r->print(
1.611     raeburn  5300:        '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   5301:         &Apache::loncommon::start_data_table().
                   5302:         &Apache::loncommon::start_data_table_header_row().
                   5303:         '<th>'.&mt('Resources').'</th>'.
                   5304:         "<th>$lt{'mr'}</th>".
                   5305:         "<th>$lt{'ve'}</th>".
                   5306:         "<th>$lt{'vu'}</th>".
                   5307:         '<th>'.&mt('History').'</th>'.
                   5308:         &Apache::loncommon::end_data_table_header_row()
                   5309:     );
1.571     raeburn  5310:     foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
                   5311:         foreach my $key (sort(@{$changedbytime{$chg}})) {
                   5312:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   5313:             my $currentversion=&Apache::lonnet::getversion($key);
                   5314:             if ($currentversion<0) {
                   5315:                 $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
                   5316:             }
                   5317:             my $linkurl=&Apache::lonnet::clutter($key);
                   5318:             $r->print(
                   5319:                 &Apache::loncommon::start_data_table_row().
                   5320:                 '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
                   5321:                 '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
                   5322:                 '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
                   5323:                 &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
                   5324:                 '<td align="right">'
                   5325:             );
                   5326:             # Used in course
                   5327:             my $usedversion=$hash{'version_'.$linkurl};
                   5328:             if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521     bisitz   5329:                 if ($usedversion != $currentversion) {
1.479     golterma 5330:                     $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521     bisitz   5331:                 } else {
1.479     golterma 5332:                     $r->print($usedversion);
                   5333:                 }
1.329     droeschl 5334:             } else {
1.521     bisitz   5335:                 $r->print($currentversion);
1.329     droeschl 5336:             }
1.571     raeburn  5337:             $r->print('</td><td title="'.$lt{'vu'}.'">');
                   5338:             # Set version
                   5339:             $r->print(&Apache::loncommon::select_form(
                   5340:                       $setversions{$linkurl},
                   5341:                       'set_version_'.$linkurl,
                   5342:                       {'select_form_order' => ['',1..$currentversion,'mostrecent'],
                   5343:                       '' => '',
                   5344:                       'mostrecent' => &mt('most recent'),
1.611     raeburn  5345:                       map {$_,$_} (1..$currentversion)},'',$readonly));
1.571     raeburn  5346:             my $lastold=1;
                   5347:             for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                   5348:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   5349:                 if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
                   5350:                     $lastold=$prevvers;
                   5351:                 }
                   5352:             }
                   5353:             $r->print('</td>');
                   5354:             # List all available versions
                   5355:             $r->print('<td valign="top"><span class="LC_fontsize_medium">');
                   5356:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
                   5357:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   5358:                 $r->print(
                   5359:                     '<span class="LC_nobreak">'
                   5360:                    .'<a href="'.&Apache::lonnet::clutter($url).'">'
                   5361:                    .&mt('Version [_1]',$prevvers).'</a>'
                   5362:                    .' ('.&Apache::lonlocal::locallocaltime(
1.521     bisitz   5363:                          &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571     raeburn  5364:                    .')');
                   5365:                 if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
                   5366:                     $r->print(
                   5367:                         ' <a href="/adm/diff?filename='.
                   5368:                         &Apache::lonnet::clutter($root.'.'.$extension).
                   5369:                         &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
                   5370:                         '" target="diffs">'.&mt('Diffs').'</a>');
                   5371:                 }
                   5372:                 $r->print('</span><br />');
1.329     droeschl 5373:             }
1.571     raeburn  5374:             $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521     bisitz   5375:         }
1.329     droeschl 5376:     }
1.521     bisitz   5377:     $r->print(
                   5378:         &Apache::loncommon::end_data_table().
1.611     raeburn  5379:         '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   5380:         '</form>'
                   5381:     );
1.329     droeschl 5382: 
                   5383:     &untiehash();
1.521     bisitz   5384:     $r->print(&endContentScreen());
1.571     raeburn  5385:     return;
1.329     droeschl 5386: }
                   5387: 
                   5388: sub mark_hash_old {
                   5389:     my $retie_hash=0;
                   5390:     if ($hashtied) {
                   5391: 	$retie_hash=1;
                   5392: 	&untiehash();
                   5393:     }
                   5394:     &tiehash('write');
                   5395:     $hash{'old'}=1;
                   5396:     &untiehash();
                   5397:     if ($retie_hash) { &tiehash(); }
                   5398: }
                   5399: 
                   5400: sub is_hash_old {
                   5401:     my $untie_hash=0;
                   5402:     if (!$hashtied) {
                   5403: 	$untie_hash=1;
                   5404: 	&tiehash();
                   5405:     }
                   5406:     my $return=$hash{'old'};
                   5407:     if ($untie_hash) { &untiehash(); }
                   5408:     return $return;
                   5409: }
                   5410: 
                   5411: sub changewarning {
                   5412:     my ($r,$postexec,$message,$url)=@_;
                   5413:     if (!&is_hash_old()) { return; }
                   5414:     my $pathvar='folderpath';
                   5415:     my $path=&escape($env{'form.folderpath'});
                   5416:     if (!defined($url)) {
                   5417: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
                   5418:     }
                   5419:     my $course_type = &Apache::loncommon::course_type();
                   5420:     if (!defined($message)) {
                   5421: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
                   5422:     }
1.653     raeburn  5423:     my $windowname = 'loncapaclient';
                   5424:     if ($env{'request.lti.login'}) {
                   5425:         $windowname .= 'lti';
                   5426:     }
1.329     droeschl 5427:     $r->print("\n\n".
1.372     bisitz   5428: '<script type="text/javascript">'."\n".
                   5429: '// <![CDATA['."\n".
                   5430: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
                   5431: '// ]]>'."\n".
1.369     bisitz   5432: '</script>'."\n".
1.653     raeburn  5433: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329     droeschl 5434: '<input type="hidden" name="orgurl" value="'.$url.
1.372     bisitz   5435: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329     droeschl 5436: &mt($message,' <input type="hidden" name="'.
                   5437:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369     bisitz   5438:     &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372     bisitz   5439: $help{'Caching'}.'</p></form>'."\n\n");
1.329     droeschl 5440: }
                   5441: 
                   5442: 
                   5443: sub init_breadcrumbs {
1.571     raeburn  5444:     my ($form,$text,$help)=@_;
1.329     droeschl 5445:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484     raeburn  5446:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405     bisitz   5447: 					    text=>&Apache::loncommon::course_type().' Editor',
1.329     droeschl 5448: 					    faq=>273,
                   5449: 					    bug=>'Instructor Interface',
1.571     raeburn  5450:                                             help => $help});
1.329     droeschl 5451:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
                   5452: 					    text=>$text,
                   5453: 					    faq=>273,
                   5454: 					    bug=>'Instructor Interface'});
                   5455: }
                   5456: 
1.441     www      5457: # subroutine to list form elements
                   5458: sub create_list_elements {
                   5459:    my @formarr = @_;
                   5460:    my $list = '';
1.501     raeburn  5461:    foreach my $button (@formarr){
                   5462:         foreach my $picture (keys(%{$button})) {
                   5463:             $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441     www      5464:         }
                   5465:    }
                   5466:    return $list;
                   5467: }
1.329     droeschl 5468: 
1.441     www      5469: # subroutine to create ul from list elements
                   5470: sub create_form_ul {
                   5471:    my $list = shift;
                   5472:    my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
                   5473:    return $ul;
                   5474: }
1.329     droeschl 5475: 
1.442     www      5476: #
                   5477: # Start tabs
                   5478: #
                   5479: 
                   5480: sub startContentScreen {
1.484     raeburn  5481:     my ($mode) = @_;
                   5482:     my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472     raeburn  5483:     if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484     raeburn  5484:         $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";
                   5485:         $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";
                   5486:         $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";
                   5487:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
                   5488:     } else {
1.549     raeburn  5489:         $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  5490:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
                   5491:         $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";
                   5492:                    '><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>';
                   5493:     }
                   5494:     $output .= "\n".'</ul>'."\n";
                   5495:     $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
                   5496:                '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
                   5497:                '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
                   5498:     return $output;
1.442     www      5499: }
                   5500: 
                   5501: #
                   5502: # End tabs
                   5503: #
                   5504: 
                   5505: sub endContentScreen {
1.484     raeburn  5506:     return '</div></div></div>';
1.442     www      5507: }
1.329     droeschl 5508: 
1.446     www      5509: sub supplemental_base {
1.548     raeburn  5510:     return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446     www      5511: }
                   5512: 
1.329     droeschl 5513: sub handler {
                   5514:     my $r = shift;
                   5515:     &Apache::loncommon::content_type($r,'text/html');
                   5516:     $r->send_http_header;
                   5517:     return OK if $r->header_only;
1.484     raeburn  5518: 
                   5519: # get course data
1.408     raeburn  5520:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  5521:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   5522:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   5523: 
1.606     raeburn  5524: # get docroot
                   5525:     my $londocroot = $r->dir_config('lonDocRoot');
                   5526: 
1.484     raeburn  5527: # graphics settings
                   5528:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329     droeschl 5529: 
1.443     www      5530: #
1.329     droeschl 5531: # --------------------------------------------- Initialize help topics for this
                   5532:     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627     raeburn  5533: 	               'Adding_External_Resource','Adding_External_Tool',
                   5534:                        'Navigate_Content','Adding_Folders','Docs_Overview',
                   5535: 	               'Load_Map','Supplemental','Score_Upload_Form',
                   5536: 	               'Adding_Pages','Importing_LON-CAPA_Resource',
                   5537: 	               'Importing_IMS_Course','Uploading_From_Harddrive',
                   5538:                        'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329     droeschl 5539: 	$help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
                   5540:     }
                   5541:     # Composite help files
                   5542:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   5543: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   5544:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   5545: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
                   5546:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   5547: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347     weissno  5548:     $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329     droeschl 5549: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353     weissno  5550:     $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329     droeschl 5551:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534     raeburn  5552:  
1.611     raeburn  5553:     my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682     raeburn  5554: # does this user have privileges to modify content.
                   5555:     if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472     raeburn  5556: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682     raeburn  5557:         unless ($r->uri eq '/adm/supplemental') {
1.611     raeburn  5558:             $allowed = 1;
1.682     raeburn  5559:         }
                   5560:         $canedit = 1;
                   5561:         $canview = 1;
                   5562:     } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
                   5563: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
                   5564:         unless ($r->uri eq '/adm/supplemental') {
1.611     raeburn  5565:             $allowed = 1;
                   5566:         }
1.682     raeburn  5567:         $canview = 1;
1.611     raeburn  5568:     }
                   5569:     unless ($canedit) {
                   5570:         $disabled = ' disabled="disabled"';
1.472     raeburn  5571:     }
1.582     raeburn  5572:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635     raeburn  5573:     if ($env{'form.inhibitmenu'}) {
                   5574:         unless ($env{'form.inhibitmenu'} eq 'yes') {
                   5575:             delete($env{'form.inhibitmenu'});
                   5576:         }
                   5577:     }
                   5578: 
1.582     raeburn  5579:   if ($allowed && $env{'form.verify'}) {
1.571     raeburn  5580:       &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637     raeburn  5581:       if (!$canedit) {
                   5582:           &verifycontent($r);
                   5583:       } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
                   5584:           &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
                   5585:                                                   text=>'Results',
                   5586:                                                   faq=>273,
                   5587:                                                   bug=>'Instructor Interface'});
                   5588:           &verifycontent($r,$env{'form.checkstale'});
                   5589:       } else {
                   5590:           &contentverifyform($r);
                   5591:       }
1.329     droeschl 5592:   } elsif ($allowed && $env{'form.listsymbs'}) {
1.484     raeburn  5593:       &init_breadcrumbs('listsymbs','List Content IDs');
1.329     droeschl 5594:       &list_symbs($r);
1.651     raeburn  5595:   } elsif ($allowed && $env{'form.shorturls'}) {
                   5596:       &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
                   5597:       &short_urls($r,$canedit);
1.329     droeschl 5598:   } elsif ($allowed && $env{'form.docslog'}) {
                   5599:       &init_breadcrumbs('docslog','Show Log');
1.484     raeburn  5600:       my $folder = $env{'form.folder'};
                   5601:       if ($folder eq '') {
                   5602:           $folder='default';
                   5603:       }
1.611     raeburn  5604:       &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329     droeschl 5605:   } elsif ($allowed && $env{'form.versions'}) {
1.571     raeburn  5606:       &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611     raeburn  5607:       &checkversions($r,$canedit);
                   5608:   } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568     raeburn  5609:       &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329     droeschl 5610:       &dumpcourse($r);
1.611     raeburn  5611:   } elsif ($canedit && $env{'form.exportcourse'}) {
1.377     bisitz   5612:       &init_breadcrumbs('exportcourse','IMS Export');
1.475     raeburn  5613:       &Apache::imsexport::exportcourse($r);
1.329     droeschl 5614:   } else {
1.611     raeburn  5615:       if ($canedit && $env{'form.authorrole'}) {
1.606     raeburn  5616:           $noendpage = 1;
                   5617:           my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
                   5618:           if ($redirect) {
                   5619:               if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
                   5620:                   my $container = 'sequence'; 
                   5621:                   my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   5622:                       $is_random_order,$container) =
                   5623:                       &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   5624:                   my (@folders)=split('&',$env{'form.folderpath'});
                   5625:                   $env{'form.foldername'}=&unescape(pop(@folders));
                   5626:                   my $folder=pop(@folders);
                   5627:                   my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   5628:                                                   $folder.'.'.$container);
                   5629:                   my $warning;
                   5630:                   if ($fatal) {
                   5631:                       if ($container eq 'page') {
                   5632:                           $warning = &mt('An error occurred retrieving the contents of the current page.');
                   5633:                       } else {
                   5634:                           $warning = &mt('An error occurred retrieving the contents of the current folder.');
                   5635:                       }
                   5636:                   } else {
                   5637:                       my $url = $redirect;
                   5638:                       my $srcfile = $londocroot.$url;
                   5639:                       $url =~ s{^/priv/}{/res/};
                   5640:                       my $targetfile = $londocroot.$url;
                   5641:                       my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   5642:                       my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
                   5643:                       $env{'form.folder'} = $folder;
                   5644:                       &snapshotbefore();
                   5645:                       my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
                   5646:                       my $ext = 'false';
                   5647:                       my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   5648:                       $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   5649:                                                         ':'.$ext.':normal:res';
                   5650:                       push(@LONCAPA::map::order,$newidx);
                   5651:                       &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
                   5652:                                                    'string_yesno');
                   5653:                       &remember_parms($newidx,'hiddenresource','set','yes');
                   5654:                       ($errtext,$fatal) =
                   5655:                           &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
                   5656:                       &log_differences($plain);
                   5657:                       &mark_hash_old();
                   5658:                       $r->internal_redirect($redirect);
                   5659:                       return OK;
                   5660:                   }
1.654     raeburn  5661:               } else {
                   5662:                   $r->internal_redirect($redirect);
1.606     raeburn  5663:               }
                   5664:           }
                   5665:       }
1.445     www      5666: #
                   5667: # Done catching special calls
1.484     raeburn  5668: # The whole rest is for course and supplemental documents and utilities menu
1.445     www      5669: # Get the parameters that may be needed
                   5670: #
                   5671:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682     raeburn  5672:                                             ['folderpath','title',
1.519     raeburn  5673:                                              'forcesupplement','forcestandard',
1.510     raeburn  5674:                                              'tools','symb','command','supppath']);
1.445     www      5675: 
1.635     raeburn  5676:     foreach my $item ('forcesupplement','forcestandard','tools') {
                   5677:         next if ($env{'form.'.$item} eq '');
                   5678:         unless ($env{'form.'.$item} eq '1') {
                   5679:             delete($env{'form.'.$item});
                   5680:         }
                   5681:     }
                   5682: 
                   5683:     if ($env{'form.command'}) {
                   5684:         unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
                   5685:             delete($env{'form.command'});
                   5686:         }
                   5687:     }
                   5688: 
                   5689:     if ($env{'form.symb'}) {
                   5690:         my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   5691:         unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { 
                   5692:             delete($env{'form.symb'});
                   5693:         }
                   5694:     }
                   5695: 
1.445     www      5696: # standard=1: this is a "new-style" course with an uploaded map as top level
                   5697: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329     droeschl 5698: 
                   5699:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445     www      5700: 
1.484     raeburn  5701: # Decide whether this should display supplemental or main content or utilities
1.445     www      5702: # supplementalflag=1: show supplemental documents
                   5703: # supplementalflag=0: show standard documents
1.484     raeburn  5704: # toolsflag=1: show utilities
1.445     www      5705: 
1.561     raeburn  5706:     my $unesc_folderpath = &unescape($env{'form.folderpath'});
                   5707:     my $supplementalflag=($unesc_folderpath=~/^supplemental/);
                   5708:     if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445     www      5709:        $supplementalflag=0;
                   5710:     }
                   5711:     if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
                   5712:     if ($env{'form.forcestandard'})   { $supplementalflag=0; }
                   5713:     unless ($allowed) { $supplementalflag=1; }
                   5714:     unless ($standard) { $supplementalflag=1; }
1.484     raeburn  5715:     my $toolsflag=0;
                   5716:     if ($env{'form.tools'}) { $toolsflag=1; }
1.445     www      5717: 
1.635     raeburn  5718:     if ($env{'form.folderpath'} ne '') {
1.685     raeburn  5719:         &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635     raeburn  5720:     }
                   5721: 
1.685     raeburn  5722:     my $backto_supppath;
1.635     raeburn  5723:     if ($env{'form.supppath'} ne '') {
1.685     raeburn  5724:         if ($supplementalflag && $allowed) {
                   5725:             $backto_supppath = &validate_supppath($coursenum,$coursedom);
                   5726:         }
1.635     raeburn  5727:     }
                   5728: 
1.329     droeschl 5729:     my $script='';
                   5730:     my $showdoc=0;
1.457     raeburn  5731:     my $addentries = {};
1.475     raeburn  5732:     my $container;
1.329     droeschl 5733:     my $containertag;
1.508     raeburn  5734:     my $pathitem;
1.598     raeburn  5735:     my %ltitools;
1.699     raeburn  5736:     my $posslti;
1.617     raeburn  5737:     my $hiddentop;
1.615     raeburn  5738:     my $navmap;
1.617     raeburn  5739:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329     droeschl 5740: 
1.464     www      5741: # Do we directly jump somewhere?
1.525     raeburn  5742:    if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472     raeburn  5743:        if ($env{'form.symb'} ne '') {
1.522     raeburn  5744:            $env{'form.folderpath'}=
1.617     raeburn  5745:                &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530     raeburn  5746:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525     raeburn  5747:                $env{'form.command'}.'_'.$env{'form.symb'}});
1.685     raeburn  5748:        } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472     raeburn  5749:            $env{'form.folderpath'}=$env{'form.supppath'};
1.530     raeburn  5750:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685     raeburn  5751:                $env{'form.command'}.'_'.$backto_supppath});
1.466     www      5752:        }
1.472     raeburn  5753:    } elsif ($env{'form.command'} eq 'editdocs') {
1.617     raeburn  5754:        $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525     raeburn  5755:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472     raeburn  5756:    } elsif ($env{'form.command'} eq 'editsupp') {
1.617     raeburn  5757:        $env{'form.folderpath'} = &supplemental_base();
1.525     raeburn  5758:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
                   5759:    } elsif ($env{'form.command'} eq 'contents') {
                   5760:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
                   5761:    } elsif ($env{'form.command'} eq 'home') {
                   5762:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464     www      5763:    }
                   5764: 
1.525     raeburn  5765: 
1.445     www      5766: # Where do we store these for when we come back?
                   5767:     my $stored_folderpath='docs_folderpath';
                   5768:     if ($supplementalflag) {
                   5769:        $stored_folderpath='docs_sup_folderpath';
                   5770:     }
1.464     www      5771: 
1.519     raeburn  5772: # No folderpath, and in edit mode, see if we have something stored
                   5773:     if ((!$env{'form.folderpath'}) && $allowed) {
1.445     www      5774:         &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510     raeburn  5775:                                           {'folderpath' => 'scalar'});
1.615     raeburn  5776: 
                   5777:         if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
                   5778:             if ($supplementalflag) {
                   5779:                 undef($env{'form.folderpath'}) if ($1 eq 'default'); 
                   5780:             } else {
                   5781:                 undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
                   5782:             }
                   5783:         } else {
1.523     raeburn  5784:             undef($env{'form.folderpath'});
                   5785:         }
1.677     raeburn  5786:         if ($env{'form.folderpath'} ne '') {
1.685     raeburn  5787:             &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677     raeburn  5788:         }
1.329     droeschl 5789:     }
1.446     www      5790:    
                   5791: # If we are not allowed to make changes, all we can see are supplemental docs
1.409     raeburn  5792:     if (!$allowed) {
1.446     www      5793:         unless ($env{'form.folderpath'} =~ /^supplemental/) {
                   5794:             $env{'form.folderpath'} = &supplemental_base();
1.409     raeburn  5795:         }
                   5796:     }
1.446     www      5797: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329     droeschl 5798:     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446     www      5799:         $env{'form.folderpath'} = &supplemental_base()
                   5800:                                   .'&'.
1.329     droeschl 5801:                                   $env{'form.folderpath'};
                   5802:     }
1.685     raeburn  5803: # If allowed and user's role is not advanced check folderpath is not hidden
                   5804:     my $hidden_and_empty;
1.687     raeburn  5805:     if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685     raeburn  5806:         my ($folderurl,$foldername,$hiddenfolder);
1.615     raeburn  5807:         my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617     raeburn  5808:         my $folder = $pathitems[-2];
                   5809:         if ($folder eq '') {
                   5810:             undef($env{'form.folderpath'});
                   5811:         } else {
                   5812:             $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666     raeburn  5813:             if ((split(/\:/,$pathitems[-1]))[5]) {
1.615     raeburn  5814:                 $folderurl .= '.page';
                   5815:             } else {
                   5816:                 $folderurl .= '.sequence';
                   5817:             }
1.685     raeburn  5818:             if ($supplementalflag) {
                   5819:                 ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
                   5820:                 $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688     raeburn  5821:                 my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn  5822:                 if (ref($supplemental) eq 'HASH') {
                   5823:                     my ($suppmap,$suppmapnum);
                   5824:                     if ($folder eq 'supplemental') {
                   5825:                         $suppmap = 'default';
                   5826:                         $suppmapnum = 0;
                   5827:                     } elsif ($folder =~ /^supplemental_(\d+)$/) {
                   5828:                         $suppmap = $1;
                   5829:                         $suppmapnum = $suppmap;
                   5830:                     }
                   5831:                     if ($hiddenfolder) {
                   5832:                         my $hascontent;
                   5833:                         foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
                   5834:                             if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
                   5835:                                 $hascontent = 1;
                   5836:                             } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
                   5837:                                 foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
                   5838:                                     if ($id =~ /^$suppmapnum\:/) {
                   5839:                                         $hascontent = 1;
                   5840:                                         last;
                   5841:                                     }
                   5842:                                 }
                   5843:                             }
                   5844:                             last if ($hascontent);
                   5845:                         }
                   5846:                         unless ($hascontent) {
                   5847:                             if ($foldername ne '') {
                   5848:                                 $hidden_and_empty = $foldername;
                   5849:                             } else {
                   5850:                                 $hidden_and_empty = $folder;
                   5851:                             }
                   5852:                         }
                   5853:                     }
                   5854:                 }
                   5855:             } else {
                   5856:                 unless (ref($navmap)) {
                   5857:                     $navmap = Apache::lonnavmaps::navmap->new();
                   5858:                 }
                   5859:                 ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
                   5860:                 $foldername = &HTML::Entities::decode(&unescape($foldername));
                   5861:                 if (ref($navmap)) {
                   5862:                     if ($hiddenfolder ||
                   5863:                         (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
                   5864:                         my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
                   5865:                         unless (@resources) {
                   5866:                             if ($foldername ne '') {
                   5867:                                 $hidden_and_empty = $foldername;
                   5868:                             } else {
                   5869:                                 $hidden_and_empty = $folder;
                   5870:                             }
                   5871:                         }
                   5872:                     }
                   5873:                 }
1.617     raeburn  5874:             }
1.685     raeburn  5875:             if ($hidden_and_empty ne '') {
                   5876:                 splice(@pathitems,-2);
                   5877:                 if (@pathitems) {
                   5878:                     $env{'form.folderpath'} = join('&',@pathitems);
                   5879:                 } else {
                   5880:                     undef($env{'form.folderpath'});
1.615     raeburn  5881:                 }
                   5882:             }
                   5883:         }
                   5884:     }
                   5885: 
1.446     www      5886: # If after all of this, we still don't have any paths, make them
1.519     raeburn  5887:     unless ($env{'form.folderpath'}) {
1.446     www      5888:        if ($supplementalflag) {
                   5889:           $env{'form.folderpath'}=&supplemental_base();
1.617     raeburn  5890:        } elsif ($allowed) {
                   5891:           ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446     www      5892:        }
1.472     raeburn  5893:     }
1.446     www      5894: 
1.445     www      5895: # Store this
1.484     raeburn  5896:     unless ($toolsflag) {
1.615     raeburn  5897:         if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510     raeburn  5898:             &Apache::loncommon::store_course_settings($stored_folderpath,
1.519     raeburn  5899:                                                       {'folderpath' => 'scalar'});
1.510     raeburn  5900:         }
1.519     raeburn  5901:         my $folderpath;
1.484     raeburn  5902:         if ($env{'form.folderpath'}) {
1.519     raeburn  5903:             $folderpath = $env{'form.folderpath'};
                   5904: 	    my (@folders)=split('&',$env{'form.folderpath'});
                   5905: 	    $env{'form.foldername'}=&unescape(pop(@folders));
                   5906:             if ($env{'form.foldername'} =~ /\:1$/) {
                   5907:                 $container = 'page';
                   5908:             } else {
                   5909:                 $container = 'sequence';
                   5910:             }
                   5911: 	    $env{'form.folder'}=pop(@folders);
1.484     raeburn  5912:         } else {
1.519     raeburn  5913:             if ($env{'form.folder'} eq '' ||
                   5914:                 $env{'form.folder'} eq 'supplemental') {
1.617     raeburn  5915:                 if ($env{'form.folder'} eq 'supplemental') {
                   5916:                     $folderpath=&supplemental_base();
                   5917:                 } elsif (!$hiddentop) {
                   5918:                     $folderpath='default&'.
                   5919:                                  &escape(&mt('Main Content').':::::');
                   5920:                 }
1.484     raeburn  5921:             }
                   5922:         }
1.519     raeburn  5923:         $containertag = '<input type="hidden" name="folderpath" value="" />';
                   5924:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484     raeburn  5925:         if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
                   5926:            $showdoc='/'.$1;
                   5927:         }
                   5928:         if ($showdoc) { # got called in sequence from course
                   5929: 	    $allowed=0; 
                   5930:         } else {
1.611     raeburn  5931:             if ($canedit) {
1.484     raeburn  5932:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   5933:                 $script=&Apache::lonratedt::editscript('simple');
1.433     raeburn  5934:             }
                   5935:         }
1.329     droeschl 5936:     }
                   5937: 
1.344     bisitz   5938: # get personal data
1.329     droeschl 5939:     my $uname=$env{'user.name'};
                   5940:     my $udom=$env{'user.domain'};
                   5941:     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
                   5942: 
                   5943:     if ($allowed) {
1.484     raeburn  5944:         if ($toolsflag) {
                   5945:             $script .= &inject_data_js();
                   5946:             my ($home,$other,%outhash)=&authorhosts();
                   5947:             if (!$home && $other) {
                   5948:                 my @hosts;
                   5949:                 foreach my $aurole (keys(%outhash)) {
                   5950:                     unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   5951:                         push(@hosts,$outhash{$aurole});
                   5952:                     }
                   5953:                 }
                   5954:                 $script .= &dump_switchserver_js(@hosts); 
                   5955:             }
1.458     raeburn  5956:         } else {
1.570     raeburn  5957:             my $tid = 1;
1.484     raeburn  5958:             my @tabids;
                   5959:             if ($supplementalflag) {
1.655     raeburn  5960:                 @tabids = ('002','dd2','ee2','ff2');
1.570     raeburn  5961:                 $tid = 2;
1.484     raeburn  5962:             } else {
                   5963:                 @tabids = ('aa1','bb1','cc1','ff1');
1.519     raeburn  5964:                 unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484     raeburn  5965:                     unshift(@tabids,'001');
                   5966:                     push(@tabids,('dd1','ee1'));
                   5967:                 }
1.458     raeburn  5968:             }
1.484     raeburn  5969:             my $tabidstr = join("','",@tabids);
1.699     raeburn  5970:             my (%domtools,%crstools);
                   5971:             my %tooltypes = &Apache::loncommon::usable_exttools();
                   5972:             if ($tooltypes{'dom'}) {
                   5973:                 %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
                   5974:             }
                   5975:             if ($tooltypes{'crs'}) {
                   5976:                 %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
                   5977:             }
                   5978:             %ltitools = (
                   5979:                           dom => \%domtools,
                   5980:                           crs => \%crstools,
                   5981:                         );
                   5982:             $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622     raeburn  5983:             my $hostname = $r->hostname();
1.606     raeburn  5984: 	    $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622     raeburn  5985:                                    $londocroot,$canedit,$hostname,\$navmap).
1.484     raeburn  5986:                        &history_tab_js().
                   5987:                        &inject_data_js().
1.570     raeburn  5988:                        &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598     raeburn  5989:                        &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685     raeburn  5990:             my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
                   5991:             if ($hidden_and_empty ne '') {
                   5992:                 my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
                   5993:                                 $hidden_and_empty);
                   5994:                 $onload .= "javascript:alert('".&js_escape($alert)."');";
                   5995:             }
1.484     raeburn  5996:             $addentries = {
1.685     raeburn  5997:                             onload => $onload,
1.484     raeburn  5998:                           };
1.458     raeburn  5999:         }
1.538     raeburn  6000:         $script .= &paste_popup_js(); 
1.501     raeburn  6001:         my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
                   6002:                              &mt('Switch server?');
                   6003:         
                   6004: 
1.329     droeschl 6005:     }
                   6006: # -------------------------------------------------------------------- Body tag
1.369     bisitz   6007:     $script = '<script type="text/javascript">'."\n"
1.372     bisitz   6008:               .'// <![CDATA['."\n"
                   6009:               .$script."\n"
                   6010:               .'// ]]>'."\n"
1.595     musolffc 6011:               .'</script>'."\n"
                   6012:               .'<script type="text/javascript" 
                   6013:                 src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385     bisitz   6014: 
                   6015:     # Breadcrumbs
                   6016:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510     raeburn  6017: 
                   6018:     if ($showdoc) {
1.682     raeburn  6019:         my $args;
                   6020:         if ($supplementalflag) {
1.687     raeburn  6021:             my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
                   6022:             my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.682     raeburn  6023:             $args = {'bread_crumbs' => $brcrum};
                   6024:         } else {
                   6025:             $args = {'force_register' => $showdoc};
                   6026:         }
                   6027:         $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571     raeburn  6028:     } elsif ($toolsflag) {
1.611     raeburn  6029:         my ($breadtext,$breadtitle);
1.617     raeburn  6030:         $breadtext = "$crstype Editor";
1.611     raeburn  6031:         if ($canedit) {
                   6032:             $breadtitle = 'Editing '.$crstype.' Contents';
                   6033:         } else {
                   6034:             $breadtext .= ' (View-only mode)';
                   6035:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   6036:         }
1.571     raeburn  6037:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  6038:             href=>"/adm/coursedocs",text=>$breadtext});
1.571     raeburn  6039:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
                   6040:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   6041:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  6042:                      $breadtitle)
1.571     raeburn  6043:                  );
1.510     raeburn  6044:     } elsif ($r->uri eq '/adm/supplemental') {
1.682     raeburn  6045:         unless ($env{'request.role.adv'}) {
                   6046:             unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
                   6047:                 $r->internal_redirect('/adm/navmaps');
                   6048:                 return OK;
                   6049:             }
                   6050:         }
1.510     raeburn  6051:         my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
                   6052:         $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
                   6053:                                                 {'bread_crumbs' => $brcrum,}));
                   6054:     } else {
1.611     raeburn  6055:         my ($breadtext,$breadtitle,$helpitem);
1.617     raeburn  6056:         $breadtext = "$crstype Editor";
1.611     raeburn  6057:         if ($canedit) {
                   6058:             $breadtitle = 'Editing '.$crstype.' Contents';
                   6059:             $helpitem = 'Docs_Adding_Course_Doc';
                   6060:         } else {
                   6061:             $breadtext .= ' (View-only mode)';
                   6062:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   6063:             $helpitem = 'Docs_Viewing_Course_Doc';
                   6064:         }
1.392     raeburn  6065:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  6066:             href=>"/adm/coursedocs",text=>$breadtext});
1.446     www      6067:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510     raeburn  6068:                                                  {'add_entries'    => $addentries}
                   6069:                                                 )
1.392     raeburn  6070:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   6071:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  6072:                      $breadtitle,
                   6073:                      $helpitem)
1.392     raeburn  6074:         );
                   6075:     }
1.364     bisitz   6076: 
1.329     droeschl 6077:   my %allfiles = ();
                   6078:   my %codebase = ();
1.440     raeburn  6079:   my ($upload_result,$upload_output,$uploadphase);
1.611     raeburn  6080:   if ($canedit) {
1.684     raeburn  6081:       undef($suppchanges);
1.329     droeschl 6082:       if (($env{'form.uploaddoc.filename'}) &&
                   6083: 	  ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440     raeburn  6084:           my $context = $1; 
                   6085:           # Process file upload - phase one - upload and parse primary file.
1.329     droeschl 6086: 	  undef($hadchanges);
1.440     raeburn  6087:           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552     raeburn  6088:                                               \%allfiles,\%codebase,$context,$crstype);
1.638     raeburn  6089:           undef($navmap);
1.329     droeschl 6090: 	  if ($hadchanges) {
                   6091: 	      &mark_hash_old();
                   6092: 	  }
1.684     raeburn  6093:           if ($suppchanges) {
                   6094:               &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
                   6095:               undef($suppchanges);
                   6096:           }
1.440     raeburn  6097:           $r->print($upload_output);
                   6098:       } elsif ($env{'form.phase'} eq 'upload_embedded') {
                   6099:           # Process file upload - phase two - upload embedded objects 
                   6100:           $uploadphase = 'check_embedded';
                   6101:           my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');   
                   6102:           my $state = &embedded_form_elems($uploadphase,$primaryurl,
                   6103:                                            $env{'form.newidx'});
                   6104:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   6105:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   6106:           my ($destination,$dir_root) = &embedded_destination();
                   6107:           my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
                   6108:           my $actionurl = '/adm/coursedocs';
1.630     raeburn  6109:           my ($result,$flag) =
1.440     raeburn  6110:               &Apache::loncommon::upload_embedded('coursedoc',$destination,
                   6111:                   $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
                   6112:                   $actionurl);
                   6113:           $r->print($result.&return_to_editor());
                   6114:       } elsif ($env{'form.phase'} eq 'check_embedded') {
                   6115:           # Process file upload - phase three - modify references in HTML file
                   6116:           $uploadphase = 'modified_orightml';
                   6117:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   6118:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   6119:           my ($destination,$dir_root) = &embedded_destination();
1.630     raeburn  6120:           my $result =
1.482     raeburn  6121:               &Apache::loncommon::modify_html_refs('coursedoc',$destination,
                   6122:                                                    $docuname,$docudom,undef,
                   6123:                                                    $dir_root);
1.630     raeburn  6124:           $r->print($result.&return_to_editor());
1.476     raeburn  6125:       } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
                   6126:           $uploadphase = 'decompress_phase_one';
                   6127:           $r->print(&decompression_phase_one().
                   6128:                     &return_to_editor());
                   6129:       } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
                   6130:           $uploadphase = 'decompress_phase_two';
                   6131:           $r->print(&decompression_phase_two().
                   6132:                     &return_to_editor());
1.329     droeschl 6133:       }
                   6134:   }
                   6135: 
1.484     raeburn  6136:   if ($allowed && $toolsflag) {
                   6137:       $r->print(&startContentScreen('tools'));
1.611     raeburn  6138:       $r->print(&generate_admin_menu($crstype,$canedit));
1.484     raeburn  6139:       $r->print(&endContentScreen());
                   6140:   } elsif ((!$showdoc) && (!$uploadphase)) {
1.329     droeschl 6141: # -----------------------------------------------------------------------------
                   6142:        my %lt=&Apache::lonlocal::texthash(
                   6143: 		'copm' => 'All documents out of a published map into this folder',
1.501     raeburn  6144:                 'upfi' => 'Upload File',
1.553     raeburn  6145:                 'upld' => 'Upload Content',
1.329     droeschl 6146:                 'srch' => 'Search',
                   6147:                 'impo' => 'Import',
1.487     raeburn  6148: 		'lnks' => 'Import from Stored Links',
1.502     raeburn  6149:                 'impm' => 'Import from Assembled Map',
1.630     raeburn  6150:                 'imcr' => 'Import from Course Resources',
1.598     raeburn  6151:                 'extr' => 'External Resource',
                   6152:                 'extt' => 'External Tool',
1.329     droeschl 6153:                 'selm' => 'Select Map',
                   6154:                 'load' => 'Load Map',
                   6155:                 'newf' => 'New Folder',
                   6156:                 'newp' => 'New Composite Page',
                   6157:                 'syll' => 'Syllabus',
1.425     raeburn  6158:                 'navc' => 'Table of Contents',
1.343     biermanm 6159:                 'sipa' => 'Simple Course Page',
1.329     droeschl 6160:                 'sipr' => 'Simple Problem',
1.630     raeburn  6161:                 'webp' => 'Blank Web Page (editable)',
1.606     raeburn  6162:                 'stpr' => 'Standard Problem',
                   6163:                 'news' => 'New sub-directory',
                   6164:                 'crpr' => 'Create Problem',
1.689     raeburn  6165:                 'swit' => 'Switch Server',
1.329     droeschl 6166:                 'drbx' => 'Drop Box',
1.451     www      6167:                 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336     schafran 6168:                 'bull' => 'Discussion Board',
1.347     weissno  6169:                 'mypi' => 'My Personal Information Page',
1.353     weissno  6170:                 'grpo' => 'Group Portfolio',
1.329     droeschl 6171:                 'rost' => 'Course Roster',
1.528     raeburn  6172:                 'abou' => 'Personal Information Page for a User',
1.553     raeburn  6173:                 'imsf' => 'IMS Upload',
                   6174:                 'imsl' => 'Upload IMS package',
1.501     raeburn  6175:                 'cms'  => 'Origin of IMS package',
                   6176:                 'se'   => 'Select',
1.329     droeschl 6177:                 'file' =>  'File',
                   6178:                 'title' => 'Title',
1.606     raeburn  6179:                 'addp' => 'Add Placeholder to course?',
                   6180:                 'uste' => 'Use Template?',
                   6181:                 'fnam' => 'File Name:',
                   6182:                 'loca' => 'Location:',
                   6183:                 'dire' => 'Directory:',
                   6184:                 'cate' => 'Category:',
                   6185:                 'tmpl' => 'Template:',
1.698     raeburn  6186:                 'empd' => 'No resources found',
1.329     droeschl 6187:                 'comment' => 'Comment',
1.403     raeburn  6188:                 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577     bisitz   6189:                 'bb5'      => 'Blackboard 5',
                   6190:                 'bb6'      => 'Blackboard 6',
                   6191:                 'angel5'   => 'ANGEL 5.5',
                   6192:                 'webctce4' => 'WebCT 4 Campus Edition',
1.606     raeburn  6193:                 'yes'      => 'Yes',
                   6194:                 'no'       => 'No',
1.618     raeburn  6195:                 'er' => 'Editing rights unavailable for your current role.',
1.577     bisitz   6196:         );
1.329     droeschl 6197: # -----------------------------------------------------------------------------
1.595     musolffc 6198: 
                   6199:     # Calculate free quota space for a user or course. A javascript function checks
                   6200:     # file size to determine if upload should be allowed.
                   6201:     my $quotatype = 'unofficial';
                   6202:     if ($crstype eq 'Community') {
1.601     raeburn  6203:         $quotatype = 'community';
                   6204:     } elsif ($crstype eq 'Placement') {
                   6205:         $quotatype = 'placement';
1.595     musolffc 6206:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
                   6207:         $quotatype = 'official';
                   6208:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   6209:         $quotatype = 'textbook';
                   6210:     }
                   6211:     my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
                   6212:                      'course',$quotatype); # expressed in MB
                   6213:     my $current_disk_usage = 0;
                   6214:     foreach my $subdir ('docs','supplemental') {
                   6215:         $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
                   6216:                                "userfiles/$subdir",1); # expressed in kB
                   6217:     }
                   6218:     my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605     raeburn  6219:     my $usage = $current_disk_usage/1024; # in MB
                   6220:     my $quota = $disk_quota;
                   6221:     my $percent;
                   6222:     if ($disk_quota == 0) {
                   6223:         $percent = 100.0;
                   6224:     } else {
1.619     raeburn  6225:         $percent = 100*($usage/$disk_quota);
1.605     raeburn  6226:     }
                   6227:     $usage = sprintf("%.2f",$usage);
                   6228:     $quota = sprintf("%.2f",$quota);
                   6229:     $percent = sprintf("%.0f",$percent);
                   6230:     my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
                   6231:                               $percent.'%',$quota.' MB').'</p>';
1.595     musolffc 6232: 
1.329     droeschl 6233: 	my $fileupload=(<<FIUP);
1.605     raeburn  6234:         $quotainfo
1.329     droeschl 6235: 	$lt{'file'}:<br />
1.662     raeburn  6236: 	<input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663     raeburn  6237:         <input type="hidden" id="LC_free_space" value="$free_space" />
1.329     droeschl 6238: FIUP
                   6239: 
                   6240: 	my $checkbox=(<<CHBO);
                   6241: 	<!-- <label>$lt{'parse'}?
                   6242: 	<input type="checkbox" name="parserflag" />
                   6243: 	</label> -->
                   6244: 	<label>
1.611     raeburn  6245: 	<input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329     droeschl 6246: 	</label>
                   6247: CHBO
1.501     raeburn  6248:         my $imsfolder = $env{'form.folder'};
                   6249:         if ($imsfolder eq '') {
                   6250:             $imsfolder = 'default';  
                   6251:         }
                   6252:         my $imspform=(<<IMSFORM);
                   6253:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
                   6254:         $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
                   6255:         <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516     raeburn  6256:         <fieldset id="uploadimsform" style="display: none;">
1.501     raeburn  6257:         <legend>$lt{'imsf'}</legend>
                   6258:         $fileupload
                   6259:         <br />
                   6260:         <p>
                   6261:         $lt{'cms'}:&nbsp; 
1.611     raeburn  6262:         <select name="source" $disabled>
1.501     raeburn  6263:         <option value="-1" selected="selected">$lt{'se'}</option>
1.577     bisitz   6264:         <option value="bb5">$lt{'bb5'}</option>
                   6265:         <option value="bb6">$lt{'bb6'}</option>
                   6266:         <option value="angel5">$lt{'angel5'}</option>
                   6267:         <option value="webctce4">$lt{'webctce4'}</option>
1.501     raeburn  6268:         </select>
                   6269:         <input type="hidden" name="folder" value="$imsfolder" />
                   6270:         </p>
                   6271:         <input type="hidden" name="phase" value="one" />
1.611     raeburn  6272:         <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501     raeburn  6273:         </fieldset>
                   6274:         </form>
                   6275: IMSFORM
1.329     droeschl 6276: 
                   6277: 	my $fileuploadform=(<<FUFORM);
1.501     raeburn  6278:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
                   6279:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
                   6280:         <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516     raeburn  6281:         <fieldset id="uploaddocform" style="display: none;">
1.501     raeburn  6282:         <legend>$lt{'upfi'}</legend>
1.371     tempelho 6283: 	<input type="hidden" name="active" value="aa" />
1.595     musolffc 6284:     $fileupload
1.329     droeschl 6285: 	<br />
                   6286: 	$lt{'title'}:<br />
1.611     raeburn  6287: 	<input type="text" size="60" name="comment" $disabled />
1.508     raeburn  6288: 	$pathitem
1.329     droeschl 6289: 	<input type="hidden" name="cmd" value="upload_default" />
                   6290: 	<br />
1.458     raeburn  6291: 	<span class="LC_nobreak" style="float:left">
1.329     droeschl 6292: 	$checkbox
                   6293: 	</span>
1.501     raeburn  6294:         <br clear="all" />
1.611     raeburn  6295:         <input type="submit" value="$lt{'upld'}" $disabled />
1.501     raeburn  6296:         </fieldset>
                   6297:         </form>
1.383     tempelho 6298: FUFORM
1.329     droeschl 6299: 
1.611     raeburn  6300:         my $mapimportjs;
                   6301:         if ($canedit) {
                   6302:             $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');"; 
                   6303:         } else {
                   6304:             $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
                   6305:         }
1.502     raeburn  6306: 	my $importpubform=(<<SEDFFORM);
1.514     raeburn  6307:         <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502     raeburn  6308:         $lt{'impm'}</a>$help{'Load_Map'}
                   6309: 	<form action="/adm/coursedocs" method="post" name="mapimportform">
1.516     raeburn  6310:         <fieldset id="importmapform" style="display: none;">
1.502     raeburn  6311:         <legend>$lt{'impm'}</legend>
1.371     tempelho 6312: 	<input type="hidden" name="active" value="bb" />
1.502     raeburn  6313:         $lt{'copm'}<br />
                   6314:         <span class="LC_nobreak">
                   6315:         <input type="text" name="importmap" size="40" value="" 
1.611     raeburn  6316:         onfocus="this.blur();$mapimportjs" $disabled />
                   6317:         &nbsp;<a href="$mapimportjs">$lt{'selm'}</a></span><br />
                   6318:         <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502     raeburn  6319:         </fieldset>
                   6320:         </form>
                   6321: 
1.383     tempelho 6322: SEDFFORM
1.606     raeburn  6323:         my $importcrsresform;
1.608     raeburn  6324:         my ($numdirs,$pickfile) = 
1.690     raeburn  6325:             &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
1.608     raeburn  6326:                                                       "resize_scrollbox('contentscroll','1','0');",
                   6327:                                                       undef,'res');
1.606     raeburn  6328:         if ($pickfile) {
                   6329:             $importcrsresform=(<<CRSFORM);
1.690     raeburn  6330:         <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606     raeburn  6331:         $lt{'imcr'}</a>$help{'Course_Resources'}
                   6332:         <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
                   6333:         <fieldset id="importcrsresform" style="display: none;">
                   6334:         <legend>$lt{'imcr'}</legend>
1.698     raeburn  6335:         <div id="importcrsrescontent" style="display: none;">
1.606     raeburn  6336:         <input type="hidden" name="active" value="bb" />
                   6337:         $pickfile
                   6338:         <p>
1.699     raeburn  6339:         $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606     raeburn  6340:         </p>
                   6341:         <input type="hidden" name="importdetail" value="" />
1.690     raeburn  6342:         <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698     raeburn  6343:         </div>
                   6344:         <div id="importcrsresempty" style="display: none;">
                   6345:         <p>
                   6346:         $lt{'empd'}
                   6347:         </p>
                   6348:         </div>
1.606     raeburn  6349:         </fieldset>
                   6350:         </form>
                   6351: CRSFORM
                   6352:         }
                   6353: 
1.611     raeburn  6354:         my $fromstoredjs;
                   6355:         if ($canedit) {
                   6356:             $fromstoredjs = 'open_StoredLinks_Import()'; 
                   6357:         } else {
                   6358:             $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
                   6359:         }
                   6360: 
1.502     raeburn  6361: 	my @importpubforma = (
1.508     raeburn  6362: 	{ '<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    6363: 	{ '<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  6364: 	{ '<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  6365:         { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
                   6366:         );
                   6367:         if ($pickfile) {
1.690     raeburn  6368:             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  6369: 	}
1.502     raeburn  6370: 	$importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510     raeburn  6371:         my $extresourcesform =
                   6372:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611     raeburn  6373:                                                  $help{'Adding_External_Resource'},
                   6374:                                                  undef,undef,undef,undef,undef,undef,$disabled);
1.598     raeburn  6375:         my $exttoolform =
                   6376:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
                   6377:                                                  $help{'Adding_External_Tool'},undef,
                   6378:                                                  undef,'tool',$coursedom,$coursenum,
1.611     raeburn  6379:                                                  \%ltitools,$disabled);
1.329     droeschl 6380:     if ($allowed) {
1.492     raeburn  6381:         my $folder = $env{'form.folder'};
                   6382:         if ($folder eq '') {
                   6383:             $folder='default';
                   6384:         }
1.615     raeburn  6385:         if ($canedit) {
                   6386: 	    my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
                   6387:             if ($output) {
                   6388:                 $r->print($output);
                   6389:             }
1.538     raeburn  6390:         }
1.337     ehlerst  6391: 	$r->print(<<HIDDENFORM);
                   6392: 	<form name="renameform" method="post" action="/adm/coursedocs">
                   6393:    <input type="hidden" name="title" />
                   6394:    <input type="hidden" name="cmd" />
                   6395:    <input type="hidden" name="markcopy" />
                   6396:    <input type="hidden" name="copyfolder" />
                   6397:    $containertag
                   6398:  </form>
1.633     raeburn  6399:  <form name="aliasform" method="post" action="/adm/coursedocs">
                   6400:    <input type="hidden" name="alias" />
                   6401:    <input type="hidden" name="cmd" />
                   6402:    $containertag
                   6403:  </form>
1.484     raeburn  6404: 
1.337     ehlerst  6405: HIDDENFORM
1.508     raeburn  6406:         $r->print(&makesimpleeditform($pathitem)."\n".
                   6407:                   &makedocslogform($pathitem."\n".
1.484     raeburn  6408:                                    '<input type="hidden" name="folder" value="'.
                   6409:                                    $env{'form.folder'}.'" />'."\n"));
1.329     droeschl 6410:     }
1.442     www      6411: 
                   6412: # Generate the tabs
1.510     raeburn  6413:     my ($mode,$needs_end);
1.472     raeburn  6414:     if (($supplementalflag) && (!$allowed)) {
1.510     raeburn  6415:         my @folders = split('&',$env{'form.folderpath'});
                   6416:         unless (@folders > 2) {
                   6417:             &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
                   6418:             $needs_end = 1;
                   6419:         }
1.472     raeburn  6420:     } else {
1.484     raeburn  6421:         $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510     raeburn  6422:         $needs_end = 1;
1.472     raeburn  6423:     }
1.443     www      6424: 
1.442     www      6425: #
1.622     raeburn  6426:     my $hostname = $r->hostname();
1.442     www      6427:     my $savefolderpath;
                   6428: 
1.395     raeburn  6429:     if ($allowed) {
1.329     droeschl 6430:        my $folder=$env{'form.folder'};
1.615     raeburn  6431:        if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329     droeschl 6432:            $folder='default';
1.356     tempelho 6433: 	   $savefolderpath = $env{'form.folderpath'};
1.548     raeburn  6434: 	   $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508     raeburn  6435:            $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329     droeschl 6436: 	       &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
                   6437:        }
                   6438:        my $postexec='';
                   6439:        if ($folder eq 'default') {
1.653     raeburn  6440:            my $windowname = 'loncapaclient';
                   6441:            if ($env{'request.lti.login'}) {
                   6442:                $windowname .= 'lti';
                   6443:            }
1.372     bisitz   6444:            $r->print('<script type="text/javascript">'."\n"
                   6445:                     .'// <![CDATA['."\n"
1.653     raeburn  6446:                     .'this.window.name="'.$windowname.'";'."\n"
1.372     bisitz   6447:                     .'// ]]>'."\n"
                   6448:                     .'</script>'."\n"
1.369     bisitz   6449:        );
1.329     droeschl 6450:        } else {
                   6451:            #$postexec='self.close();';
                   6452:        }
1.504     raeburn  6453:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
                   6454:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329     droeschl 6455: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
                   6456: 
                   6457: 	my $newnavform=(<<NNFORM);
                   6458: 	<form action="/adm/coursedocs" method="post" name="newnav">
1.655     raeburn  6459: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6460: 	$pathitem
1.329     droeschl 6461: 	<input type="hidden" name="importdetail" 
                   6462: 	value="$lt{'navc'}=/adm/navmaps" />
1.611     raeburn  6463: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329     droeschl 6464: 	$help{'Navigate_Content'}
                   6465: 	</form>
                   6466: NNFORM
                   6467: 	my $newsmppageform=(<<NSPFORM);
                   6468: 	<form action="/adm/coursedocs" method="post" name="newsmppg">
1.655     raeburn  6469: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6470: 	$pathitem
1.329     droeschl 6471: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6472: 	<a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383     tempelho 6473: 	$help{'Simple Page'}
1.329     droeschl 6474: 	</form>
                   6475: NSPFORM
                   6476: 
                   6477: 	my $newsmpproblemform=(<<NSPROBFORM);
                   6478: 	<form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655     raeburn  6479: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6480: 	$pathitem
1.329     droeschl 6481: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6482: 	<a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572     raeburn  6483: 	$help{'Simple_Problem'}
1.329     droeschl 6484: 	</form>
                   6485: 
                   6486: NSPROBFORM
                   6487: 
                   6488: 	my $newdropboxform=(<<NDBFORM);
                   6489: 	<form action="/adm/coursedocs" method="post" name="newdropbox">
1.655     raeburn  6490: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6491: 	$pathitem
1.329     droeschl 6492: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6493: 	<a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554     raeburn  6494:         $help{'Dropbox'}
1.344     bisitz   6495: 	</form>
1.329     droeschl 6496: NDBFORM
                   6497: 
                   6498: 	my $newexuploadform=(<<NEXUFORM);
                   6499: 	<form action="/adm/coursedocs" method="post" name="newexamupload">
1.655     raeburn  6500: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6501: 	$pathitem
1.329     droeschl 6502: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6503: 	<a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329     droeschl 6504: 	$help{'Score_Upload_Form'}
                   6505: 	</form>
                   6506: NEXUFORM
                   6507: 
                   6508: 	my $newbulform=(<<NBFORM);
                   6509: 	<form action="/adm/coursedocs" method="post" name="newbul">
1.655     raeburn  6510: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6511: 	$pathitem
1.329     droeschl 6512: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6513: 	<a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329     droeschl 6514: 	$help{'Bulletin Board'}
                   6515: 	</form>
                   6516: NBFORM
                   6517: 
                   6518: 	my $newaboutmeform=(<<NAMFORM);
                   6519: 	<form action="/adm/coursedocs" method="post" name="newaboutme">
1.655     raeburn  6520: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6521: 	$pathitem
1.329     droeschl 6522: 	<input type="hidden" name="importdetail" 
                   6523: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  6524: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347     weissno  6525: 	$help{'My Personal Information Page'}
1.329     droeschl 6526: 	</form>
                   6527: NAMFORM
                   6528: 
                   6529: 	my $newaboutsomeoneform=(<<NASOFORM);
                   6530: 	<form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655     raeburn  6531: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6532: 	$pathitem
1.329     droeschl 6533: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6534: 	<a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329     droeschl 6535: 	</form>
                   6536: NASOFORM
                   6537: 
                   6538: 	my $newrosterform=(<<NROSTFORM);
                   6539: 	<form action="/adm/coursedocs" method="post" name="newroster">
1.655     raeburn  6540: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6541: 	$pathitem
1.329     droeschl 6542: 	<input type="hidden" name="importdetail" 
                   6543: 	value="$lt{'rost'}=/adm/viewclasslist" />
1.611     raeburn  6544: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556     raeburn  6545: 	$help{'Course_Roster'}
1.329     droeschl 6546: 	</form>
                   6547: NROSTFORM
                   6548: 
1.534     raeburn  6549:         my $newwebpage;
                   6550:         if ($folder =~ /^default_?(\d*)$/) {
                   6551:             $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
                   6552:             if ($1) {
                   6553:                 $newwebpage .= $1;
                   6554:             } else {
                   6555:                 $newwebpage .= 'default';
                   6556:             }
                   6557:             $newwebpage .= '/new.html';
                   6558:         }
                   6559:         my $newwebpageform =(<<NWEBFORM);
                   6560:         <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655     raeburn  6561:         <input type="hidden" name="active" value="ff" />
1.534     raeburn  6562:         $pathitem
                   6563:         <input type="hidden" name="importdetail" value="$newwebpage" />
                   6564:         <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556     raeburn  6565:         $help{'Web_Page'}
1.534     raeburn  6566:         </form>
                   6567: NWEBFORM
1.604     raeburn  6568: 
1.606     raeburn  6569:         my @ids=&Apache::lonnet::current_machine_ids();
1.691     raeburn  6570:         my $machines_str = "'".join("','",@ids)."'";
                   6571:         my (%is_home,%toppath,$rolehomes);
1.606     raeburn  6572:         if ($env{'user.author'}) {
                   6573:             if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691     raeburn  6574:                 $is_home{'author'} = 1;
1.606     raeburn  6575:             }
1.691     raeburn  6576:             $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606     raeburn  6577:         }
                   6578:         my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
                   6579:                                                       ['active'],['ca','aa']);
1.691     raeburn  6580:         my %by_roletype;
1.606     raeburn  6581:         if (keys(%roleshash)) {
                   6582:             foreach my $entry (keys(%roleshash)) {
                   6583:                 my ($auname,$audom,$roletype) = split(/:/,$entry);
                   6584:                 my $key = $entry;
                   6585:                 $key =~ s/:/___/g;
1.691     raeburn  6586:                 my $author = $auname.'___'.$audom;
                   6587:                 $by_roletype{$roletype}{$author} = 1;
1.606     raeburn  6588:                 my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691     raeburn  6589:                 $toppath{$author} = "/priv/$audom/$auname";
                   6590:                 if (grep(/^\Q$rolehome\E$/,@ids)) {
                   6591:                     $is_home{$author} = 1;
1.606     raeburn  6592:                 }
1.691     raeburn  6593:                 $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
                   6594:                               'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606     raeburn  6595:             }
1.691     raeburn  6596:         }
                   6597:         my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   6598:         if (grep(/^\Q$crshome\E$/,@ids)) {
                   6599:             $is_home{'course'} = 1;
                   6600:         }
                   6601:         $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
                   6602:         my $pickdir = $lt{'loca'}.
                   6603:                    '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
                   6604:                    '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
                   6605:         if ($env{'user.author'}) {
                   6606:             $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
                   6607:         }
                   6608:         if (keys(%by_roletype)) {
                   6609:             foreach my $possrole ('ca','aa') {
                   6610:                 if (ref($by_roletype{$possrole}) eq 'HASH') {
                   6611:                     my $roletitle = &Apache::lonnet::plaintext($possrole);
                   6612:                     foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
                   6613:                         my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
                   6614:                         $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
                   6615:                                      $roletitle." ($audom/$auname)</option>\n";
1.606     raeburn  6616:                     }
                   6617:                 }
                   6618:             }
                   6619:         }
1.691     raeburn  6620:         $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n".
                   6621:                     '</select><br />'."\n".
                   6622:                     $lt{'dire'}.
                   6623:                     '<select name="authorpath" onchange="toggleCrsResTitle();">'.
                   6624:                     '<option value=""></option>'.
                   6625:                     '</select><br />'."\n";
1.606     raeburn  6626: 
                   6627:         my %seltemplate_menus;
                   6628:         my @files = &Apache::lonhomework::get_template_list('problem');
                   6629:         my @noexamplelink = ('blank.problem','blank.library','script.library');
                   6630:         my $currentcategory = '';
                   6631:         my @ordered = ('');
                   6632:         my %templatehelp;
                   6633:         my $defcategory = '';
                   6634:         my @catorder = ($defcategory);
                   6635:         $seltemplate_menus{$defcategory}->{'order'} = [''];
                   6636:         $seltemplate_menus{$defcategory}->{'text'} = '';
                   6637:         foreach my $file (@files) {
                   6638:             if (ref($file) eq 'ARRAY') {
                   6639:                 my ($path,$title,$category,$help) = @{$file};
                   6640:                 next if ($title !~ /\S/);
                   6641:                 if (&js_escape($category) ne $currentcategory) {
                   6642:                     $currentcategory = &js_escape($category);
                   6643:                     push(@catorder,&js_escape($currentcategory));
                   6644:                     $seltemplate_menus{$currentcategory}->{'text'} = $category;
                   6645:                     $seltemplate_menus{$currentcategory}->{'default'} = '';
                   6646:                     $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
                   6647:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
                   6648:                 }
                   6649:                 if ($path) {
                   6650:                     $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
                   6651:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
                   6652:                     if ($help) {
                   6653:                         $templatehelp{$path} = $help;
                   6654:                     }
                   6655:                 }
                   6656:             }
                   6657:         }
                   6658: 
                   6659:         my $templates = $lt{'cate'}.' '.
                   6660:                         &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
                   6661:                                                                 $defcategory,'tempcategory','template',
                   6662:                                                                 \%seltemplate_menus,\@catorder,
                   6663:                                                                 "resize_scrollbox('contentscroll','1','0');",
                   6664:                                                                 "toggleExampleText();",'template').'<br />';
                   6665:         my $templatepreview =  '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true);  return false;">'.
                   6666:                                '<span id="newresexample">'.&mt('Example').'<span></a>';
                   6667:         my $crsresform=(<<RESFORM);
1.691     raeburn  6668:         <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.606     raeburn  6669:         $lt{'stpr'}</a>$help{'Course_Resource'}
                   6670:         <form action="/adm/coursedocs" method="post" name="courseresform">
                   6671:         <fieldset id="crsresform" style="display:none;">
                   6672:         <legend>$lt{'stpr'}</legend>
1.655     raeburn  6673:         <input type="hidden" name="active" value="bb" />
1.606     raeburn  6674:         <p>
                   6675:         $pickdir
1.691     raeburn  6676:         <div id="newstdproblem" style="display:none;">
1.606     raeburn  6677:         <span class="LC_nobreak">$lt{'news'}?&nbsp;
1.611     raeburn  6678:         <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606     raeburn  6679:         &nbsp;
1.611     raeburn  6680:         <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606     raeburn  6681:         </span><span id="newsubdir"></span>
                   6682:         <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.699     raeburn  6683:         </div>
1.606     raeburn  6684:         </p>
                   6685:         $lt{'fnam'}
1.611     raeburn  6686:         <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606     raeburn  6687:         <p>
1.691     raeburn  6688:         <div id="newresource" style="display:none">
1.606     raeburn  6689:         $lt{'addp'}
1.611     raeburn  6690:         <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  6691:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  6692:         <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  6693:         $lt{'yes'}</label>
                   6694:         <span id="newrestitle"></span>
1.611     raeburn  6695:         <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606     raeburn  6696:         </div>
                   6697:         </p>
                   6698:         <p>
                   6699:         $lt{'uste'}
1.611     raeburn  6700:         <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  6701:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  6702:         <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  6703:         $lt{'yes'}</label>
                   6704:         <div id="newrestemplate" style="display:none">
                   6705:         $templates
                   6706:         $templatepreview
                   6707:         </div>
                   6708:         </p>
                   6709:         <span class="LC_nobreak">
                   6710:         <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611     raeburn  6711:         <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606     raeburn  6712:         </span>
1.689     raeburn  6713:         </div>
1.691     raeburn  6714:         <div id="stdprobswitch" style="display:none;">
1.689     raeburn  6715:         $rolehomes
                   6716:         <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
                   6717:         </div>
1.606     raeburn  6718:         </fieldset>
                   6719:         </form>
                   6720: 
                   6721: RESFORM
1.534     raeburn  6722: 
1.342     ehlerst  6723: my $specialdocumentsform;
1.383     tempelho 6724: my @specialdocumentsforma;
1.451     www      6725: my $gradingform;
                   6726: my @gradingforma;
                   6727: my $communityform;
                   6728: my @communityforma;
1.351     ehlerst  6729: my $newfolderform;
1.390     tempelho 6730: my $newfolderb;
1.342     ehlerst  6731: 
1.451     www      6732: 	my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383     tempelho 6733: 	
1.329     droeschl 6734: 	my $newpageform=(<<NPFORM);
                   6735: 	<form action="/adm/coursedocs" method="post" name="newpage">
                   6736: 	<input type="hidden" name="folderpath" value="$path" />
                   6737: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  6738: 	<input type="hidden" name="active" value="ee" />
1.423     onken    6739: 	<a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383     tempelho 6740: 	$help{'Adding_Pages'}
1.329     droeschl 6741: 	</form>
                   6742: NPFORM
1.390     tempelho 6743: 
                   6744: 
1.351     ehlerst  6745: 	$newfolderform=(<<NFFORM);
1.329     droeschl 6746: 	<form action="/adm/coursedocs" method="post" name="newfolder">
1.508     raeburn  6747: 	$pathitem
1.329     droeschl 6748: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  6749: 	<input type="hidden" name="active" value="" />
1.422     onken    6750: 	<a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329     droeschl 6751: 	</form>
                   6752: NFFORM
                   6753: 
                   6754: 	my $newsylform=(<<NSYLFORM);
                   6755: 	<form action="/adm/coursedocs" method="post" name="newsyl">
1.570     raeburn  6756: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6757: 	$pathitem
1.329     droeschl 6758: 	<input type="hidden" name="importdetail" 
                   6759: 	value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  6760: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329     droeschl 6761: 	$help{'Syllabus'}
1.383     tempelho 6762: 
1.329     droeschl 6763: 	</form>
                   6764: NSYLFORM
1.364     bisitz   6765: 
1.329     droeschl 6766: 	my $newgroupfileform=(<<NGFFORM);
                   6767: 	<form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655     raeburn  6768: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6769: 	$pathitem
1.329     droeschl 6770: 	<input type="hidden" name="importdetail"
                   6771: 	value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611     raeburn  6772: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353     weissno  6773: 	$help{'Group Portfolio'}
1.329     droeschl 6774: 	</form>
                   6775: NGFFORM
1.672     raeburn  6776:         if ($container eq 'page') {
                   6777:             @specialdocumentsforma=(
                   6778:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
                   6779:             );
                   6780:         } else {
                   6781: 	    @specialdocumentsforma=(
1.421     onken    6782: 	{'<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  6783: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611     raeburn  6784: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451     www      6785:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534     raeburn  6786:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672     raeburn  6787:             );
                   6788:         }
1.451     www      6789:         $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
                   6790: 
1.655     raeburn  6791:         my @external = (
                   6792:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519     raeburn  6793:         );
1.699     raeburn  6794:         if ($posslti) {
1.655     raeburn  6795:             push(@external,
                   6796:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
                   6797:             );
1.598     raeburn  6798:         }
1.655     raeburn  6799:         my $externalform = &create_form_ul(&create_list_elements(@external));
                   6800: 
                   6801:         my @importdoc = ();
1.519     raeburn  6802:         unless ($container eq 'page') {
                   6803:             push(@importdoc,
                   6804:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
                   6805:             );
                   6806:         }
                   6807:         push(@importdoc,
1.558     raeburn  6808:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519     raeburn  6809:         );
1.501     raeburn  6810:         $fileuploadform =  &create_form_ul(&create_list_elements(@importdoc));
1.434     raeburn  6811: 
1.451     www      6812:         @gradingforma=(
                   6813:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
                   6814:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
                   6815:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.691     raeburn  6816:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform},
1.451     www      6817:         );
                   6818:         $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
                   6819: 
                   6820:         @communityforma=(
                   6821:        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
                   6822:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
                   6823:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611     raeburn  6824:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
                   6825:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451     www      6826:         );
                   6827:         $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383     tempelho 6828: 
1.330     tempelho 6829: my %orderhash = (
1.553     raeburn  6830:                 'aa' => ['Upload',$fileuploadform],
                   6831:                 'bb' => ['Import',$importpubform],
1.655     raeburn  6832:                 'cc' => ['External',$externalform],
                   6833:                 'dd' => ['Grading',$gradingform],
1.673     raeburn  6834:                 'ff' => ['Other',$specialdocumentsform],
1.330     tempelho 6835:                 );
1.519     raeburn  6836: unless ($container eq 'page') {
1.434     raeburn  6837:     $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655     raeburn  6838:     $orderhash{'ee'} = ['Collaboration',$communityform];
1.434     raeburn  6839: }
                   6840: 
1.341     ehlerst  6841:  $hadchanges=0;
1.484     raeburn  6842:        unless (($supplementalflag || $toolsflag)) {
1.458     raeburn  6843:           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615     raeburn  6844:                               $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622     raeburn  6845:                               \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617     raeburn  6846:           undef($navmap);
1.443     www      6847:           if ($error) {
                   6848:              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   6849:           }
1.639     raeburn  6850:           if ($hadchanges) {
                   6851:               unless (&is_hash_old()) {
1.638     raeburn  6852:                   &mark_hash_old();
                   6853:               }
                   6854: 	  }
1.341     ehlerst  6855: 
1.443     www      6856:           &changewarning($r,'');
                   6857:         }
1.458     raeburn  6858:     }
1.442     www      6859: 
1.443     www      6860: # Supplemental documents start here
                   6861: 
1.329     droeschl 6862:        my $folder=$env{'form.folder'};
1.443     www      6863:        unless ($supplementalflag) {
1.329     droeschl 6864: 	   $folder='supplemental';
                   6865:        }
1.685     raeburn  6866:        if (($folder eq 'supplemental') &&
1.329     droeschl 6867: 	   (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446     www      6868:           $env{'form.folderpath'} = &supplemental_base();
1.393     raeburn  6869:        } elsif ($allowed) {
1.356     tempelho 6870: 	  $env{'form.folderpath'} = $savefolderpath;
1.329     droeschl 6871:        }
1.508     raeburn  6872:        $pathitem = '<input type="hidden" name="folderpath" value="'.
                   6873:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329     droeschl 6874:        if ($allowed) {
                   6875: 	   my $folderseq=
1.504     raeburn  6876: 	       '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329     droeschl 6877: 
                   6878: 	my $supupdocform=(<<SUPDOCFORM);
1.501     raeburn  6879:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
                   6880:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383     tempelho 6881: 	<form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516     raeburn  6882:         <fieldset id="uploadsuppdocform" style="display: none;">
1.501     raeburn  6883:         <legend>$lt{'upfi'}</legend>
1.630     raeburn  6884: 	<input type="hidden" name="active" value="ee" />
1.329     droeschl 6885: 	$fileupload
                   6886: 	<br />
                   6887: 	<br />
                   6888: 	<span class="LC_nobreak">
                   6889: 	$checkbox
                   6890: 	</span>
                   6891: 	<br /><br />
                   6892: 	$lt{'comment'}:<br />
1.383     tempelho 6893: 	<textarea cols="50" rows="4" name="comment"></textarea>
1.329     droeschl 6894: 	<br />
1.508     raeburn  6895: 	$pathitem
1.329     droeschl 6896: 	<input type="hidden" name="cmd" value="upload_supplemental" />
1.501     raeburn  6897:         <input type='submit' value="$lt{'upld'}" />
1.700   ! raeburn  6898:         </fieldset>
1.501     raeburn  6899:         </form>
1.329     droeschl 6900: SUPDOCFORM
                   6901: 
                   6902: 	my $supnewfolderform=(<<SNFFORM);
                   6903: 	<form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570     raeburn  6904: 	<input type="hidden" name="active" value="" />
1.508     raeburn  6905:         $pathitem
1.329     droeschl 6906: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6907: 	<a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a> 
1.383     tempelho 6908: 	$help{'Adding_Folders'}
1.329     droeschl 6909: 	</form>
                   6910: SNFFORM
1.383     tempelho 6911: 	
1.510     raeburn  6912:         my $supextform =
                   6913:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611     raeburn  6914:                                                  $help{'Adding_External_Resource'},
                   6915:                                                  undef,undef,undef,undef,undef,undef,
                   6916:                                                  $disabled);
1.329     droeschl 6917: 
1.598     raeburn  6918:         my $supexttoolform =
                   6919:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
                   6920:                                                  $help{'Adding_External_Tool'},
                   6921:                                                  undef,undef,'tool',$coursedom,
1.611     raeburn  6922:                                                  $coursenum,\%ltitools,$disabled);
1.598     raeburn  6923: 
1.329     droeschl 6924: 	my $supnewsylform=(<<SNSFORM);
                   6925: 	<form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371     tempelho 6926: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6927:         $pathitem
1.329     droeschl 6928: 	<input type="hidden" name="importdetail" 
                   6929: 	value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  6930: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329     droeschl 6931: 	$help{'Syllabus'}
                   6932: 	</form>
                   6933: SNSFORM
                   6934: 
                   6935: 	my $supnewaboutmeform=(<<SNAMFORM);
1.383     tempelho 6936: 	<form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371     tempelho 6937: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6938:         $pathitem
1.329     droeschl 6939: 	<input type="hidden" name="importdetail" 
                   6940: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  6941: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347     weissno  6942: 	$help{'My Personal Information Page'}
1.329     droeschl 6943: 	</form>
                   6944: SNAMFORM
                   6945: 
1.534     raeburn  6946:         my $supwebpage;
                   6947:         if ($folder =~ /^supplemental_?(\d*)$/) {
                   6948:             $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
                   6949:             if ($1) {
                   6950:                 $supwebpage .= $1;
                   6951:             } else {
                   6952:                 $supwebpage .= 'default';
                   6953:             }
                   6954:             $supwebpage .= '/new.html';
                   6955:         }
                   6956:         my $supwebpageform =(<<SWEBFORM);
                   6957:         <form action="/adm/coursedocs" method="post" name="supwebpage">
                   6958:         <input type="hidden" name="active" value="cc" />
                   6959:         $pathitem
                   6960:         <input type="hidden" name="importdetail" value="$supwebpage" />
                   6961:         <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556     raeburn  6962:         $help{'Web_Page'}
1.534     raeburn  6963:         </form>
                   6964: SWEBFORM
                   6965: 
1.333     muellerd 6966: 
1.383     tempelho 6967: my @specialdocs = (
1.618     raeburn  6968: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417     droeschl 6969:             =>$supnewsylform},
1.611     raeburn  6970: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417     droeschl 6971:             =>$supnewaboutmeform},
1.534     raeburn  6972:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
                   6973: 
1.383     tempelho 6974: 		);
1.655     raeburn  6975:         my @supexternal = (
                   6976:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
                   6977:              =>$supextform});
1.699     raeburn  6978:         if ($posslti) {
1.655     raeburn  6979:             push(@supexternal,
                   6980:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598     raeburn  6981:             =>$supexttoolform});
                   6982:         }
1.655     raeburn  6983:         my @supimportdoc = (
1.598     raeburn  6984:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501     raeburn  6985:             =>$supupdocform},
1.598     raeburn  6986:         );
1.501     raeburn  6987: 
                   6988: $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc));
1.333     muellerd 6989: my %suporderhash = (
1.390     tempelho 6990: 		'00' => ['Supnewfolder', $supnewfolderform],
1.655     raeburn  6991:                 'dd' => ['Upload',$supupdocform],
                   6992:                 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553     raeburn  6993:                 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333     muellerd 6994:                 );
1.443     www      6995:         if ($supplementalflag) {
1.682     raeburn  6996:             $suppchanges = 0;
                   6997:             my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
                   6998:                                 $supplementalflag,\%suporderhash,$iconpath,$pathitem,
                   6999:                                 \%ltitools,$canedit,$hostname);
                   7000:             if ($error) {
                   7001:                 $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   7002:             }
                   7003:             if ($suppchanges) {
1.684     raeburn  7004:                 &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682     raeburn  7005:                 undef($suppchanges);
                   7006:             }
1.393     raeburn  7007:         }
1.443     www      7008:     } elsif ($supplementalflag) {
1.458     raeburn  7009:         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682     raeburn  7010:                             $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
                   7011:                             $hostname);
1.393     raeburn  7012:         if ($error) {
                   7013:             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383     tempelho 7014:         }
1.393     raeburn  7015:     }
1.389     tempelho 7016: 
1.510     raeburn  7017:     if ($needs_end) {
                   7018:         $r->print(&endContentScreen());
                   7019:     }
1.383     tempelho 7020: 
1.329     droeschl 7021:     if ($allowed) {
                   7022: 	$r->print('
                   7023: <form method="post" name="extimport" action="/adm/coursedocs">
                   7024:   <input type="hidden" name="title" />
                   7025:   <input type="hidden" name="url" />
                   7026:   <input type="hidden" name="useform" />
                   7027:   <input type="hidden" name="residx" />
                   7028: </form>');
                   7029:     }
1.484     raeburn  7030:   } elsif ($showdoc) {
1.329     droeschl 7031: # -------------------------------------------------------- This is showdoc mode
1.484     raeburn  7032:       $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498     bisitz   7033: 		&Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329     droeschl 7034: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484     raeburn  7035:                 &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329     droeschl 7036:   }
                   7037:  }
1.630     raeburn  7038:  unless ($noendpage) {
1.606     raeburn  7039:      $r->print(&Apache::loncommon::end_page());
                   7040:  }
1.329     droeschl 7041:  return OK;
1.364     bisitz   7042: }
1.329     droeschl 7043: 
1.440     raeburn  7044: sub embedded_form_elems {
                   7045:     my ($phase,$primaryurl,$newidx) = @_;
                   7046:     my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634     raeburn  7047:     $newidx =~s /\D+//g;
1.440     raeburn  7048:     return <<STATE;
                   7049:     <input type="hidden" name="folderpath" value="$folderpath" />
                   7050:     <input type="hidden" name="cmd" value="upload_embedded" />
                   7051:     <input type="hidden" name="newidx" value="$newidx" />
                   7052:     <input type="hidden" name="phase" value="$phase" />
                   7053:     <input type="hidden" name="primaryurl" value="$primaryurl" />
                   7054: STATE
                   7055: }
                   7056: 
                   7057: sub embedded_destination {
                   7058:     my $folder=$env{'form.folder'};
                   7059:     my $destination = 'docs/';
                   7060:     if ($folder =~ /^supplemental/) {
                   7061:         $destination = 'supplemental/';
                   7062:     }
                   7063:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   7064:         $destination .= 'default/';
                   7065:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   7066:         $destination .=  $2.'/';
                   7067:     }
1.634     raeburn  7068:     my $newidx = $env{'form.newidx'};
                   7069:     $newidx =~s /\D+//g;
                   7070:     if ($newidx) {
                   7071:         $destination .= $newidx;
                   7072:     }
1.440     raeburn  7073:     my $dir_root = '/userfiles';
                   7074:     return ($destination,$dir_root);
                   7075: }
                   7076: 
                   7077: sub return_to_editor {
                   7078:     my $actionurl = '/adm/coursedocs';
                   7079:     return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n". 
                   7080:            '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
                   7081:            '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
                   7082:            '</a></p>';
                   7083: }
                   7084: 
1.476     raeburn  7085: sub decompression_info {
                   7086:     my ($destination,$dir_root) = &embedded_destination();
                   7087:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                   7088:     my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   7089:     my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   7090:     my $container='sequence';
1.480     raeburn  7091:     my ($pathitem,$hiddenelem);
1.583     raeburn  7092:     my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519     raeburn  7093:     if ($env{'form.folderpath'} =~ /\:1$/) {
1.476     raeburn  7094:         $container='page';
                   7095:     }
1.480     raeburn  7096:     unshift(@hiddens,$pathitem);
                   7097:     foreach my $item (@hiddens) {
1.634     raeburn  7098:         if ($item eq 'newidx') {
                   7099:             next if ($env{'form.'.$item} =~ /\D/);
                   7100:         }
1.480     raeburn  7101:         if ($env{'form.'.$item}) {
                   7102:             $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583     raeburn  7103:                            &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480     raeburn  7104:         }
1.477     raeburn  7105:     }
1.476     raeburn  7106:     return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
                   7107:             $hiddenelem);
                   7108: }
                   7109: 
                   7110: sub decompression_phase_one {
                   7111:     my ($dir,$file,$warning,$error,$output);
                   7112:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   7113:         &decompression_info();
1.490     raeburn  7114:     if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476     raeburn  7115:         $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
                   7116:     } else {
                   7117:         my $file = $1;
1.630     raeburn  7118:         $output =
1.481     raeburn  7119:             &Apache::loncommon::process_decompression($docudom,$docuname,$file,
                   7120:                                                       $destination,$dir_root,
                   7121:                                                       $hiddenelem);
                   7122:         if ($env{'form.autoextract_camtasia'}) {
                   7123:             $output .= &remove_archive($docudom,$docuname,$container);
                   7124:         }
1.476     raeburn  7125:     }
                   7126:     if ($error) {
                   7127:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   7128:                    $error.'</p>'."\n";
                   7129:     }
                   7130:     if ($warning) {
                   7131:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   7132:     }
                   7133:     return $output;
                   7134: }
                   7135: 
                   7136: sub decompression_phase_two {
                   7137:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   7138:         &decompression_info();
1.481     raeburn  7139:     my $output;
1.480     raeburn  7140:     if ($env{'form.archivedelete'}) {
1.481     raeburn  7141:         $output = &remove_archive($docudom,$docuname,$container);
1.480     raeburn  7142:     }
                   7143:     $output .= 
1.481     raeburn  7144:         &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476     raeburn  7145:                                                     $destination,$dir_root,$hiddenelem);
                   7146:     return $output;
                   7147: }
                   7148: 
1.480     raeburn  7149: sub remove_archive {
                   7150:     my ($docudom,$docuname,$container) = @_;
                   7151:     my $map = $env{'form.folder'}.'.'.$container;
1.481     raeburn  7152:     my ($output,$delwarning,$delresult,$url);
1.480     raeburn  7153:     my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
                   7154:     if ($fatal) {
                   7155:         if ($container eq 'page') {
                   7156:             $delwarning = &mt('An error occurred retrieving the contents of the current page.');
                   7157:         } else {
                   7158:             $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
                   7159:         }
1.583     raeburn  7160:         $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  7161:     } else {
                   7162:         my $currcmd = $env{'form.cmd'};
                   7163:         my $position = $env{'form.position'};
1.583     raeburn  7164:         my $archiveidx = $position;
1.563     raeburn  7165:         if ($position > 0) {
1.583     raeburn  7166:             if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
                   7167:                 $archiveidx = $position-1;
                   7168:             }
                   7169:             $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584     raeburn  7170:             my ($title,$url,@rrest) =
1.583     raeburn  7171:                 split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
                   7172:             if ($url eq $env{'form.archiveurl'}) {
                   7173:                 if (&handle_edit_cmd($docuname,$docudom)) {
                   7174:                     ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684     raeburn  7175:                     if ($suppchanges) {
                   7176:                         &Apache::lonnet::update_supp_caches($docudom,$docuname);
                   7177:                         undef($suppchanges);
                   7178:                     }
1.583     raeburn  7179:                     if ($fatal) {
                   7180:                         if ($container eq 'page') {
                   7181:                             $delwarning = &mt('An error occurred updating the contents of the current page.');
                   7182:                         } else {
                   7183:                             $delwarning = &mt('An error occurred updating the contents of the current folder.');
                   7184:                         }
1.480     raeburn  7185:                     } else {
1.583     raeburn  7186:                         $delresult = &mt('Archive file removed.');
1.480     raeburn  7187:                     }
                   7188:                 }
1.583     raeburn  7189:             } else {
                   7190:                 $delwarning .=  &mt('Archive file had unexpected item number in folder.').
                   7191:                                 ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  7192:             }
                   7193:         }
                   7194:         $env{'form.cmd'} = $currcmd;
                   7195:     }
                   7196:     if ($delwarning) {
                   7197:         $output = '<p class="LC_warning">'.
                   7198:                    $delwarning.
                   7199:                    '</p>';
                   7200:     }
                   7201:     if ($delresult) {
                   7202:         $output .= '<p class="LC_info">'.
                   7203:                    $delresult.
                   7204:                    '</p>';
                   7205:     }
1.481     raeburn  7206:     return $output;
1.480     raeburn  7207: }
                   7208: 
1.484     raeburn  7209: sub generate_admin_menu {
1.611     raeburn  7210:     my ($crstype,$canedit) = @_;
1.484     raeburn  7211:     my $lc_crstype = lc($crstype);
                   7212:     my ($home,$other,%outhash)=&authorhosts();
1.562     bisitz   7213:     my %lt= ( # do not translate here
1.484     raeburn  7214:                                          'vc'   => 'Verify Content',
                   7215:                                          'cv'   => 'Check/Set Resource Versions',
                   7216:                                          'ls'   => 'List Resource Identifiers',
1.651     raeburn  7217:                                          'ct'   => 'Display/Set Shortened URLs for Deep-linking',
1.484     raeburn  7218:                                          'imse' => 'Export contents to IMS Archive',
1.568     raeburn  7219:                                          'dcd'  => "Copy $crstype Content to Authoring Space",
1.562     bisitz   7220:             );
1.484     raeburn  7221:     my ($candump,$dumpurl);
                   7222:     if ($home + $other > 0) {
                   7223:         $candump = 'F';
                   7224:         if ($home) {
                   7225:             $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
                   7226:         } else {
                   7227:             my @hosts;
                   7228:             foreach my $aurole (keys(%outhash)) {
                   7229:                 unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   7230:                     push(@hosts,$outhash{$aurole});
1.538     raeburn  7231:                 }
1.484     raeburn  7232:             }
                   7233:             if (@hosts == 1) {
                   7234:                 my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
                   7235:                                '&amp;role='.
                   7236:                                &HTML::Entities::encode($env{'request.role'},'"<>&').'&amp;origurl='.
                   7237:                                &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
                   7238:                 $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
                   7239:             } else {
                   7240:                 $dumpurl = "javascript:choose_switchserver_window()";
                   7241:             }
                   7242:         }
                   7243:     }
                   7244:     my @menu=
                   7245:         ({  categorytitle=>'Administration',
                   7246:             items =>[
                   7247:                 {   linktext   => $lt{'vc'},
                   7248:                     url        => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
                   7249:                     permission => 'F',
1.571     raeburn  7250:                     help       => 'Docs_Verify_Content',
1.484     raeburn  7251:                     icon       => 'verify.png',
                   7252:                     linktitle  => 'Verify contents can be retrieved/rendered',
                   7253:                 },
                   7254:                 {   linktext => $lt{'cv'},
                   7255:                     url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
                   7256:                     permission => 'F',
1.571     raeburn  7257:                     help       => 'Docs_Check_Resource_Versions',
1.484     raeburn  7258:                     icon       => 'resversion.png',
                   7259:                     linktitle  => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
                   7260:                 },
                   7261:                 {   linktext   => $lt{'ls'},
                   7262:                     url        => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
                   7263:                     permission => 'F',
                   7264:                     #help => '',
                   7265:                     icon       => 'symbs.png',
                   7266:                     linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"
                   7267:                 },
1.651     raeburn  7268:                 {   linktext   => $lt{'ct'},
                   7269:                     url        => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
                   7270:                     permission => 'F',
                   7271:                     help       => 'Docs_Short_URLs',
                   7272:                     icon       => 'shorturls.png',
                   7273:                     linktitle  => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
                   7274:                 },
1.484     raeburn  7275:                 ]
1.611     raeburn  7276:         });
                   7277:     if ($canedit) {
                   7278:         push(@menu,
1.484     raeburn  7279:         {   categorytitle=>'Export',
                   7280:             items =>[
                   7281:                 {   linktext   => $lt{'imse'},
                   7282:                     url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
                   7283:                     permission => 'F',
                   7284:                     help       => 'Docs_Export_Course_Docs',
                   7285:                     icon       => 'imsexport.png',
                   7286:                     linktitle  => $lt{'imse'},
                   7287:                 },
                   7288:                 {   linktext   => $lt{'dcd'},
                   7289:                     url        => $dumpurl,
                   7290:                     permission => $candump,
1.571     raeburn  7291:                     help       => 'Docs_Dump_Course_Docs',
1.484     raeburn  7292:                     icon       => 'dump.png',
                   7293:                     linktitle  => $lt{'dcd'},
                   7294:                 },
                   7295:                 ]
                   7296:         });
1.611     raeburn  7297:     }
1.484     raeburn  7298:     return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
                   7299:            '<input type="hidden" id="dummy" />'."\n".
                   7300:            &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
                   7301:            '</form>';
1.329     droeschl 7302: }
                   7303: 
                   7304: sub generate_edit_table {
1.538     raeburn  7305:     my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611     raeburn  7306:         $need_save,$copyfolder,$canedit) = @_;
1.406     raeburn  7307:     return unless(ref($orderhash_ref) eq 'HASH');
1.342     ehlerst  7308:     my %orderhash = %{$orderhash_ref};
1.611     raeburn  7309:     my ($form, $activetab, $active, $disabled);
1.570     raeburn  7310:     if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371     tempelho 7311:         $activetab = $env{'form.active'};
                   7312:     }
1.611     raeburn  7313:     unless ($canedit) {
                   7314:         $disabled = ' disabled="disabled"';
                   7315:     }
1.472     raeburn  7316:     my $backicon = $iconpath.'clickhere.gif';
1.525     raeburn  7317:     my $backtext = &mt('Exit Editor');
1.458     raeburn  7318:     $form = '<div class="LC_Box" style="margin:0;">'.
1.488     raeburn  7319:             '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
                   7320:             '<li class="goback">'.
1.546     raeburn  7321:             '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488     raeburn  7322:             '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
                   7323:             '  alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
                   7324:             '<li>'.
                   7325:             '<a href="javascript:groupopen('."'$readfile'".',1);">'.
                   7326:             &mt('Undo Delete').'</a></li>'."\n";
                   7327:     if ($env{'form.docslog'}) {
                   7328:         $form .= '<li class="active">';
                   7329:     } else {
                   7330:         $form .= '<li>';
                   7331:     }
                   7332:     $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
                   7333:              &mt('History').'</a></li>'."\n";
                   7334:     if ($env{'form.docslog'}) {
                   7335:         $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
                   7336:                  &mt('Edit').'</a></li>'."\n";
1.484     raeburn  7337:     }
1.458     raeburn  7338:     foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390     tempelho 7339:         if($name ne '00'){
1.371     tempelho 7340:             if($activetab eq '' || $activetab ne $name){
                   7341:                $active = '';
                   7342:             }elsif($activetab eq $name){
                   7343:                $active = 'class="active"';
                   7344:             }
1.458     raeburn  7345:             $form .= '<li style="float:right" '.$active
1.484     raeburn  7346:                 .' 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 7347:         } else {
1.570     raeburn  7348: 	    $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390     tempelho 7349: 
                   7350: 	}
1.329     droeschl 7351:     }
1.484     raeburn  7352:     $form .= '</ul>'."\n";
                   7353:     $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458     raeburn  7354: 
                   7355:     if ($to_show ne '') {
1.538     raeburn  7356:         my $saveform;
                   7357:         if ($need_save) {
                   7358:             my $button = &mt('Make changes');
                   7359:             my $path;
                   7360:             if ($env{'form.folderpath'}) {
                   7361:                 $path =
                   7362:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   7363:             }
                   7364:             $saveform = <<"END";
                   7365: <div id="multisave" style="display:none; clear:both;" >
                   7366: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
                   7367: <input type="hidden" name="folderpath" value="$path" />
                   7368: <input type="hidden" name="symb" value="$env{'form.symb'}" />
                   7369: <input type="hidden" name="allhiddenresource" value="" />
                   7370: <input type="hidden" name="allencrypturl" value="" />
                   7371: <input type="hidden" name="allrandompick" value="" />
                   7372: <input type="hidden" name="allrandomorder" value="" />
                   7373: <input type="hidden" name="changeparms" value="" />
                   7374: <input type="hidden" name="multiremove" value="" />
                   7375: <input type="hidden" name="multicut" value="" />
                   7376: <input type="hidden" name="multicopy" value="" />
                   7377: <input type="hidden" name="multichange" value="" />
                   7378: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611     raeburn  7379: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538     raeburn  7380: </form>
                   7381: </div>
                   7382: END
                   7383:         }
                   7384:         $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458     raeburn  7385:     }
1.363     ehlerst  7386:     foreach my $field (keys(%orderhash)){
1.390     tempelho 7387: 	if($field ne '00'){
1.422     onken    7388:             if($activetab eq '' || $activetab ne $field){
1.458     raeburn  7389:                 $active = 'style="display: none;float:left"';
1.422     onken    7390:             }elsif($activetab eq $field){
1.458     raeburn  7391:                 $active = 'style="display:block;float:left"';
1.422     onken    7392:             }
                   7393:             $form .= '<div id="'.$field.$tid.'"'
                   7394:                     .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484     raeburn  7395:                     .'</div>'."\n";
1.363     ehlerst  7396:         }
                   7397:     }
1.484     raeburn  7398:     unless ($env{'form.docslog'}) {
                   7399:         $form .= '</div></div>'."\n";
                   7400:     }
1.329     droeschl 7401:     return $form;
                   7402: }
                   7403: 
                   7404: sub editing_js {
1.622     raeburn  7405:     my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
                   7406:         $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594     damieng  7407:     my %js_lt = &Apache::lonlocal::texthash(
1.329     droeschl 7408:                                           p_mnf => 'Name of New Folder',
                   7409:                                           t_mnf => 'New Folder',
                   7410:                                           p_mnp => 'Name of New Page',
                   7411:                                           t_mnp => 'New Page',
1.451     www      7412:                                           p_mxu => 'Title for the External Score',
1.349     biermanm 7413:                                           p_msp => 'Name of Simple Course Page',
1.329     droeschl 7414:                                           p_msb => 'Title for the Problem',
                   7415:                                           p_mdb => 'Title for the Drop Box',
1.336     schafran 7416:                                           p_mbb => 'Title for the Discussion Board',
1.604     raeburn  7417:                                           p_mwp => 'Title for Web Page',
1.606     raeburn  7418:                                           p_mnr => 'Title for the Resource',
1.348     weissno  7419:                                           p_mab => "Enter user:domain for User's Personal Information Page",
1.352     bisitz   7420:                                           p_mab2 => 'Personal Information Page of ',
1.329     droeschl 7421:                                           p_mab_alrt1 => 'Not a valid user:domain',
                   7422:                                           p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
                   7423:                                           p_chn => 'New Title',
                   7424:                                           p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603     raeburn  7425:                                           p_rmr2a => 'Remove',
                   7426:                                           p_rmr2b => '?',
                   7427:                                           p_rmr3a => 'Remove those',
                   7428:                                           p_rmr3b => 'items?',
                   7429:                                           p_rmr4  => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
                   7430:                                           p_rmr5  => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329     droeschl 7431:                                           p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
                   7432:                                           p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603     raeburn  7433:                                           p_ctr2a => 'Cut',
                   7434:                                           p_ctr2b => '?',
                   7435:                                           p_ctr3a => 'Cut those',
                   7436:                                           p_ctr3b => 'items?',
1.633     raeburn  7437:                                           setal   => 'Enter a (unique) alias',
                   7438:                                           delal   => 'Are you sure you want to eliminate the alias?',
1.478     raeburn  7439:                                           rpck    => 'Enter number to pick (e.g., 3)',
1.501     raeburn  7440:                                           imsfile => 'You must choose an IMS package for import',
                   7441:                                           imscms  => 'You must select which Course Management System was the source of the IMS package',
                   7442:                                           invurl  => 'Invalid URL',
                   7443:                                           titbl   => 'Title is blank',
1.538     raeburn  7444:                                           more    => '(More ...)',
                   7445:                                           less    => '(Less ...)',
1.543     raeburn  7446:                                           noor    => 'No actions selected or changes to settings specified.',
                   7447:                                           noch    => 'No changes to settings specified.',
                   7448:                                           noac    => 'No actions selected.',
1.606     raeburn  7449:                                           nofi    => 'No file selected',
                   7450:                                           tinc    => 'Title in course',
                   7451:                                           sunm    => 'Sub-directory name',
1.618     raeburn  7452:                                           edri    => 'Editing rights unavailable for your current role.',
1.691     raeburn  7453:                                           sele    => 'Select',
                   7454:                                           swit    => 'Switch server required',
1.329     droeschl 7455:                                         );
1.594     damieng  7456:     &js_escape(\%js_lt);
1.433     raeburn  7457:     my $crstype = &Apache::loncommon::course_type();
1.434     raeburn  7458:     my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
                   7459:     my $main_container_page;
1.519     raeburn  7460:     if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
                   7461:         $main_container_page = 1;
1.434     raeburn  7462:     }
1.617     raeburn  7463:     my $backtourl;
                   7464:     my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446     www      7465:     my $toplevelsupp = &supplemental_base();
1.690     raeburn  7466:     my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691     raeburn  7467:     my @ids=&Apache::lonnet::current_machine_ids();
                   7468:     my $machines_str = "'".join("','",@ids)."'";
1.530     raeburn  7469:     if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
                   7470:         my $caller = $1;
1.525     raeburn  7471:         if ($caller =~ /^supplemental/) {
                   7472:             $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
                   7473:         } else {
                   7474:             my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
                   7475:             $res = &Apache::lonnet::clutter($res);
                   7476:             if (&Apache::lonnet::is_on_map($res)) {
1.609     raeburn  7477:                 my ($url,$anchor);
                   7478:                 if ($res =~ /^([^#]+)#([^#]+)$/) {
                   7479:                     $url = $1;
                   7480:                     $anchor = $2;
                   7481:                     if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
                   7482:                         $caller = $1.&escape('#').$anchor;
                   7483:                     }
1.614     raeburn  7484:                 } else {
                   7485:                     $url = $res;
1.609     raeburn  7486:                 }
1.640     raeburn  7487:                 $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
                   7488:                 if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
                   7489:                     $backtourl .= '?navmap=1';
                   7490:                 } else {
                   7491:                     $backtourl .= '?symb='.
                   7492:                                   &HTML::Entities::encode($caller,'<>&"');
                   7493:                 }
1.622     raeburn  7494:                 if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   7495:                     if (($ENV{'SERVER_PORT'} == 443) &&
                   7496:                         ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  7497:                         unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  7498:                             if ($hostname ne '') {
                   7499:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   7500:                             }
                   7501:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  7502:                         }
                   7503:                     }
1.623     raeburn  7504:                 } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
                   7505:                     if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678     raeburn  7506:                         unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658     raeburn  7507:                             if ($hostname ne '') {
                   7508:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   7509:                             }
                   7510:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.657     raeburn  7511:                         }
1.623     raeburn  7512:                     }
1.622     raeburn  7513:                 }
1.609     raeburn  7514:                 if ($anchor ne '') {
                   7515:                     $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
                   7516:                 }
1.590     raeburn  7517:                 $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544     raeburn  7518:             } else {
                   7519:                 $backtourl = '/adm/navmaps';
1.525     raeburn  7520:             }
                   7521:         }
                   7522:     } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
                   7523:         $backtourl = '/adm/menu';
                   7524:     } elsif ($supplementalflag) {
1.682     raeburn  7525:         if (($env{'request.role.adv'}) ||
                   7526:             (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
                   7527:             $backtourl = '/adm/supplemental';
                   7528:         } else {
                   7529:             $backtourl = '/adm/navmaps';
                   7530:         }
1.525     raeburn  7531:     } else {
                   7532:         $backtourl = '/adm/navmaps';
1.472     raeburn  7533:     }
                   7534: 
1.655     raeburn  7535:     my $fieldsets = "'doc'";
1.519     raeburn  7536:     unless ($main_container_page) {
                   7537:         $fieldsets .=",'ims'";
                   7538:     }
1.655     raeburn  7539:     my $extfieldsets = "'ext'";
                   7540:     if ($posslti) {
                   7541:         $extfieldsets .= ",'tool'";
                   7542:     }
1.501     raeburn  7543:     if ($supplementalflag) {
1.655     raeburn  7544:         $fieldsets = "'suppdoc'";
                   7545:         $extfieldsets = "'suppext'";
1.600     raeburn  7546:         if ($posslti) {
1.655     raeburn  7547:             $extfieldsets .= ",'supptool'";
1.600     raeburn  7548:         }
1.501     raeburn  7549:     }
1.655     raeburn  7550: 
1.611     raeburn  7551:     my $jsmakefunctions;
                   7552:     if ($canedit) {
                   7553:         $jsmakefunctions = <<ENDNEWSCRIPT;
1.329     droeschl 7554: function makenewfolder(targetform,folderseq) {
1.594     damieng  7555:     var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329     droeschl 7556:     if (foldername) {
1.676     raeburn  7557:        targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329     droeschl 7558:         targetform.submit();
                   7559:     }
                   7560: }
                   7561: 
                   7562: function makenewpage(targetform,folderseq) {
1.594     damieng  7563:     var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329     droeschl 7564:     if (pagename) {
1.676     raeburn  7565:         targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329     droeschl 7566:         targetform.submit();
                   7567:     }
                   7568: }
                   7569: 
                   7570: function makeexamupload() {
1.594     damieng  7571:    var title=prompt('$js_lt{"p_mxu"}');
1.344     bisitz   7572:    if (title) {
1.329     droeschl 7573:     this.document.forms.newexamupload.importdetail.value=
1.676     raeburn  7574: 	encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329     droeschl 7575:     this.document.forms.newexamupload.submit();
                   7576:    }
                   7577: }
                   7578: 
                   7579: function makesmppage() {
1.594     damieng  7580:    var title=prompt('$js_lt{"p_msp"}');
1.344     bisitz   7581:    if (title) {
1.329     droeschl 7582:     this.document.forms.newsmppg.importdetail.value=
1.676     raeburn  7583: 	encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329     droeschl 7584:     this.document.forms.newsmppg.submit();
                   7585:    }
                   7586: }
                   7587: 
1.534     raeburn  7588: function makewebpage(type) {
1.594     damieng  7589:    var title=prompt('$js_lt{"p_mwp"}');
1.534     raeburn  7590:    var formname;
                   7591:    if (type == 'supp') {
                   7592:        formname = this.document.forms.supwebpage;
                   7593:    } else {
                   7594:        formname = this.document.forms.newwebpage;
                   7595:    }
                   7596:    if (title) {
                   7597:        var webpage = formname.importdetail.value; 
1.675     raeburn  7598:        formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534     raeburn  7599:        formname.submit();
                   7600:    }
                   7601: }
                   7602: 
1.329     droeschl 7603: function makesmpproblem() {
1.594     damieng  7604:    var title=prompt('$js_lt{"p_msb"}');
1.344     bisitz   7605:    if (title) {
1.329     droeschl 7606:     this.document.forms.newsmpproblem.importdetail.value=
1.676     raeburn  7607: 	encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329     droeschl 7608:     this.document.forms.newsmpproblem.submit();
                   7609:    }
                   7610: }
                   7611: 
                   7612: function makedropbox() {
1.594     damieng  7613:    var title=prompt('$js_lt{"p_mdb"}');
1.344     bisitz   7614:    if (title) {
1.329     droeschl 7615:     this.document.forms.newdropbox.importdetail.value=
1.676     raeburn  7616:         encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329     droeschl 7617:     this.document.forms.newdropbox.submit();
                   7618:    }
                   7619: }
                   7620: 
                   7621: function makebulboard() {
1.594     damieng  7622:    var title=prompt('$js_lt{"p_mbb"}');
1.329     droeschl 7623:    if (title) {
                   7624:     this.document.forms.newbul.importdetail.value=
1.676     raeburn  7625: 	encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329     droeschl 7626:     this.document.forms.newbul.submit();
                   7627:    }
                   7628: }
                   7629: 
                   7630: function makeabout() {
1.594     damieng  7631:    var user=prompt("$js_lt{'p_mab'}");
1.329     droeschl 7632:    if (user) {
                   7633:        var comp=new Array();
                   7634:        comp=user.split(':');
                   7635:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   7636: 	   if ((comp[0]) && (comp[1])) {
                   7637: 	       this.document.forms.newaboutsomeone.importdetail.value=
1.594     damieng  7638: 		   '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611     raeburn  7639:                this.document.forms.newaboutsomeone.submit();
                   7640:            } else {
                   7641:                alert("$js_lt{'p_mab_alrt1'}");
                   7642:            }
                   7643:        } else {
                   7644:            alert("$js_lt{'p_mab_alrt2'}");
                   7645:        }
                   7646:     }
                   7647: }
                   7648: 
                   7649: function makenew(targetform) {
                   7650:     targetform.submit();
                   7651: }
                   7652: 
                   7653: function changename(folderpath,index,oldtitle) {
                   7654:     var title=prompt('$js_lt{"p_chn"}',oldtitle);
                   7655:     if (title) {
                   7656:         this.document.forms.renameform.markcopy.value='';
                   7657:         this.document.forms.renameform.title.value=title;
                   7658:         this.document.forms.renameform.cmd.value='rename_'+index;
                   7659:         this.document.forms.renameform.folderpath.value=folderpath;
                   7660:         this.document.forms.renameform.submit();
                   7661:     }
                   7662: }
                   7663: 
1.633     raeburn  7664: function setalias(folderpath,index) {
                   7665:     var alias = prompt('$js_lt{"setal"}');
                   7666:     if ((alias != null) && (alias != '')) {
                   7667:         this.document.forms.aliasform.alias.value=alias;
                   7668:         this.document.forms.aliasform.cmd.value='setalias_'+index;
                   7669:         this.document.forms.aliasform.folderpath.value=folderpath;
                   7670:         this.document.forms.aliasform.submit();
                   7671:     }
                   7672: }
                   7673: 
                   7674: function delalias(folderpath,index) {
                   7675:     if (confirm('$js_lt{"delal"}')) {
                   7676:         this.document.forms.aliasform.cmd.value='delalias_'+index;
                   7677:         this.document.forms.aliasform.folderpath.value=folderpath;
                   7678:         this.document.forms.aliasform.submit();
                   7679:     }
                   7680: }
                   7681: 
1.611     raeburn  7682: ENDNEWSCRIPT
                   7683:     } else {
                   7684:         $jsmakefunctions = <<ENDNEWSCRIPT;
                   7685: 
                   7686: function makenewfolder() {
                   7687:     alert("$js_lt{'edri'}");
                   7688: }
                   7689: 
                   7690: function makenewpage() {
                   7691:     alert("$js_lt{'edri'}");
                   7692: }
                   7693: 
                   7694: function makeexamupload() {
                   7695:     alert("$js_lt{'edri'}");
                   7696: }
                   7697: 
                   7698: function makesmppage() {
                   7699:     alert("$js_lt{'edri'}");
                   7700: }
                   7701: 
                   7702: function makewebpage(type) {
                   7703:     alert("$js_lt{'edri'}");
                   7704: }
                   7705: 
                   7706: function makesmpproblem() {
                   7707:     alert("$js_lt{'edri'}");
                   7708: }
                   7709: 
                   7710: function makedropbox() {
                   7711:     alert("$js_lt{'edri'}");
                   7712: }
                   7713: 
                   7714: function makebulboard() {
                   7715:     alert("$js_lt{'edri'}");
                   7716: }
                   7717: 
                   7718: function makeabout() {
                   7719:     alert("$js_lt{'edri'}");
                   7720: }
                   7721: 
                   7722: function changename() {
                   7723:     alert("$js_lt{'edri'}");
                   7724: }
                   7725: 
1.633     raeburn  7726: function setalias() {
                   7727:     alert("$js_lt{'edri'}");
                   7728: }
                   7729: 
                   7730: function delalias() {
                   7731:     alert("$js_lt{'edri'}");
                   7732: }
                   7733: 
1.611     raeburn  7734: function makenew() {
                   7735:     alert("$js_lt{'edri'}");
                   7736: }
                   7737: 
                   7738: function groupimport() {
                   7739:     alert("$js_lt{'edri'}");
1.335     ehlerst  7740: }
1.611     raeburn  7741: 
                   7742: function groupsearch() {
                   7743:     alert("$js_lt{'edri'}");
1.335     ehlerst  7744: }
1.611     raeburn  7745: 
                   7746: function groupopen(url,recover) {
                   7747:    var options="scrollbars=1,resizable=1,menubar=0";
                   7748:    idxflag=1;
                   7749:    idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
                   7750:    idx.focus();
1.329     droeschl 7751: }
                   7752: 
1.611     raeburn  7753: ENDNEWSCRIPT
                   7754: 
                   7755:     }
                   7756:     return <<ENDSCRIPT;
                   7757: 
                   7758: $jsmakefunctions
                   7759: 
1.501     raeburn  7760: function toggleUpload(caller) {
                   7761:     var blocks = Array($fieldsets);
                   7762:     for (var i=0; i<blocks.length; i++) {
                   7763:         var disp = 'none';
                   7764:         if (caller == blocks[i]) {
                   7765:             var curr = document.getElementById('upload'+caller+'form').style.display;
                   7766:             if (curr == 'none') {
                   7767:                 disp='block';
                   7768:             }
                   7769:         }
                   7770:         document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655     raeburn  7771:     }
                   7772:     resize_scrollbox('contentscroll','1','1');
                   7773:     return;
                   7774: }
                   7775: 
                   7776: function toggleExternal(caller) {
                   7777:     var blocks = Array($extfieldsets);
                   7778:     for (var i=0; i<blocks.length; i++) {
                   7779:         var disp = 'none';
                   7780:         if (caller == blocks[i]) {
                   7781:             var curr = document.getElementById('external'+caller+'form').style.display;
                   7782:             if (curr == 'none') {
                   7783:                 disp='block';
                   7784:             }
                   7785:         }
                   7786:         document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598     raeburn  7787:         if ((caller == 'tool') || (caller == 'supptool')) {
                   7788:             if (disp == 'block') {
1.655     raeburn  7789:                 if (document.getElementById('LC_exttoolid')) {
                   7790:                     var toolselector = document.getElementById('LC_exttoolid');
1.598     raeburn  7791:                     var suppflag = 0;
                   7792:                     if (caller == 'supptool') {
                   7793:                         suppflag = 1;
                   7794:                     }
                   7795:                     currForm = document.getElementById('new'+caller);
1.655     raeburn  7796:                     updateExttool(toolselector,currForm,suppflag);
1.598     raeburn  7797:                 }
                   7798:             }
                   7799:         }
1.501     raeburn  7800:     }
1.502     raeburn  7801:     resize_scrollbox('contentscroll','1','1');
                   7802:     return;
                   7803: }
                   7804: 
1.514     raeburn  7805: function toggleMap(caller) {
1.502     raeburn  7806:     var disp = 'none';
1.510     raeburn  7807:     if (document.getElementById('importmapform')) {
1.514     raeburn  7808:         if (caller == 'map') {
                   7809:             var curr = document.getElementById('importmapform').style.display;
                   7810:             if (curr == 'none') {
                   7811:                 disp='block';
                   7812:             }
1.510     raeburn  7813:         }
                   7814:         document.getElementById('importmapform').style.display=disp;
                   7815:         resize_scrollbox('contentscroll','1','1');
1.502     raeburn  7816:     }
1.501     raeburn  7817:     return;
1.329     droeschl 7818: }
                   7819: 
1.691     raeburn  7820: function toggleCrsRes(caller) {
1.606     raeburn  7821:     var disp = 'none';
                   7822:     if (document.getElementById('crsresform')) {
                   7823:         if (caller == 'res') {
1.691     raeburn  7824:             var form = document.getElementById('crsresform');
                   7825:             var curr = form.style.display;
1.606     raeburn  7826:             if (curr == 'none') {
                   7827:                 disp='block';
1.691     raeburn  7828:                 document.courseresform.authorrole.selectedIndex = 0;
                   7829:                 document.courseresform.authorpath.selectedIndex = 0;
                   7830:                 document.courseresform.newresourceadd.selectedIndex = 0;
                   7831:                 populateDirSelects(form,'authorrole','authorpath',1,0,0);
                   7832:                 toggleNewInCourse(document.courseresform);
                   7833:                 if (document.getElementById('newresource')) {
                   7834:                     document.getElementById('newresource').style.display = 'none';
1.606     raeburn  7835:                 }
                   7836:                 if (document.courseresform.newresusetemp.length) {
                   7837:                     document.courseresform.newresusetemp[0].checked = true;
                   7838:                     toggleWithTemplate(document.courseresform);
                   7839:                 }
                   7840:                 document.courseresform.newresourcename.value = ''; 
                   7841:             }
                   7842:         }
                   7843:         if (document.courseresform.newsubdir.length) {
                   7844:             for (var j=0; j<document.courseresform.newsubdir.length; j++) {
                   7845:                 if (document.courseresform.newsubdir[j].value == 0) {
                   7846:                     document.courseresform.newsubdir[j].checked = true;
                   7847:                 }
                   7848:                 break;
                   7849:             }
                   7850:             if (document.getElementById('newsubdirname')) {
                   7851:                 document.getElementById('newsubdirname').type = "hidden";
                   7852:                 document.getElementById('newsubdirname').value = "";
                   7853:             }
                   7854:             if (document.getElementById('newsubdir')) {
                   7855:                 document.getElementById('newsubdir').innerHTML = "";
                   7856:             }
                   7857:         }
                   7858:         document.getElementById('crsresform').style.display=disp;
                   7859:         resize_scrollbox('contentscroll','1','0');
                   7860:     }
                   7861:     return;
                   7862: }
                   7863: 
                   7864: function toggleNewsubdir(form) {
                   7865:     if (form.newsubdir.length) {
                   7866:         for (var j=0; j<form.newsubdir.length; j++) {
                   7867:             if (form.newsubdir[j].checked) {
                   7868:                 if (document.getElementById('newsubdirname')) {
                   7869:                     if (form.newsubdir[j].value == '1') {
                   7870:                         document.getElementById('newsubdirname').type = "text"; 
                   7871:                         if (document.getElementById('newsubdir')) {
                   7872:                             document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
                   7873:                         }
                   7874:                     } else {
                   7875:                         document.getElementById('newsubdirname').type = "hidden";
                   7876:                         document.getElementById('newsubdirname').value = "";
                   7877:                         document.getElementById('newsubdir').innerHTML = "";
                   7878:                     }
                   7879:                 }
                   7880:                 break;
                   7881:             }
                   7882:         }
                   7883:     }
                   7884: }
                   7885: 
                   7886: function toggleCrsResTitle() {
                   7887:     if (document.getElementById('newresource')) {
1.691     raeburn  7888:         var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
                   7889:         if (selloc == 'course') {
1.606     raeburn  7890:             document.getElementById('newresource').style.display = 'inline';
                   7891:             document.courseresform.newresourceadd[0].checked = true;
                   7892:             toggleNewInCourse(document.courseresform);
                   7893:         } else {
                   7894:             document.getElementById('newresource').style.display = 'none';
                   7895:         }
1.689     raeburn  7896:     }
                   7897:     if (document.getElementById('newstdproblem')) {
                   7898:         if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
                   7899:             document.getElementById('newstdproblem').style.display = 'none'; 
                   7900:             if (document.getElementById('stdprobswitch')) {
                   7901:                 document.getElementById('stdprobswitch').style.display = 'block'; 
                   7902:             }
                   7903:         } else {
                   7904:             document.getElementById('newstdproblem').style.display = 'block';
                   7905:             if (document.getElementById('stdprobswitch')) {
                   7906:                 document.getElementById('stdprobswitch').style.display = 'none';
                   7907:             }
                   7908:         }
                   7909:     }
1.606     raeburn  7910: }
                   7911: 
                   7912: function toggleNewInCourse(form) {
                   7913:     if (form.newresourceadd.length) {
                   7914:         for (var i=0; i<form.newresourceadd.length; i++) {
                   7915:             if (form.newresourceadd[i].checked) {
                   7916:                 if (document.getElementById('newresourcetitle')) {
                   7917:                     if (form.newresourceadd[i].value == '1') {
                   7918:                         document.getElementById('newresourcetitle').type = 'text';
                   7919:                         if (document.getElementById('newrestitle')) {
                   7920:                             document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
                   7921:                         }
                   7922:                     } else {
                   7923:                         document.getElementById('newresourcetitle').type = 'hidden';
                   7924:                         document.getElementById('newresourcetitle').value = '';
                   7925:                         if (document.getElementById('newrestitle')) { 
                   7926:                             document.getElementById('newrestitle').innerHTML = '';
                   7927:                         }
                   7928:                     }
                   7929:                 }
                   7930:                 break;
                   7931:             }
                   7932:         }
                   7933:     }
                   7934: }
                   7935: 
                   7936: function toggleWithTemplate(form) {
                   7937:     if (form.newresusetemp.length) {
                   7938:         for (var i=0; i<form.newresusetemp.length; i++) {
                   7939:             if (form.newresusetemp[i].checked) {
                   7940:                 if (document.getElementById('newrestemplate')) { 
                   7941:                     if (form.newresusetemp[i].value == '1') {
                   7942:                         document.getElementById('newrestemplate').style.display = 'inline';
                   7943:                         toggleExampleText();
                   7944:                     } else {
                   7945:                         form.tempcategory.selectedIndex = 0;
                   7946:                         select1template_changed();
                   7947:                         document.getElementById('newrestemplate').style.display = 'none';
                   7948:                     }
                   7949:                 }
                   7950:             }
                   7951:         }
                   7952:     }
                   7953: }
                   7954: 
                   7955: function toggleExampleText() {
                   7956:     if (document.getElementById('newresexample')) {
                   7957:         var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   7958:         if (url == '') {
                   7959:             document.getElementById('newresexample').style.fontWeight = 'normal';
                   7960:         } else {
                   7961:             document.getElementById('newresexample').style.fontWeight = 'bold';
                   7962:         }
                   7963:     }
                   7964: }
                   7965: 
                   7966: function getExample(width,height,scrolling,transparency) {
                   7967:     var url;
                   7968:     if (document.courseresform.newresusetemp.length) {
                   7969:         for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
                   7970:             if (document.courseresform.newresusetemp[i].checked) {
                   7971:                 if (document.courseresform.newresusetemp[i].value == '1') {
                   7972:                     var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   7973:                     if (url == '') {
                   7974:                         alert('Pick a category and template');
                   7975:                     } else {
                   7976:                         url = url.replace("$londocroot",""); 
                   7977:                         url += '?inhibitmenu=yes';
                   7978:                     }
                   7979:                 }
                   7980:                 break;
                   7981:             }
                   7982:         }
                   7983:     }
                   7984:     if (url != '') {
                   7985:         openMyModal(url,width,height,scrolling,transparency,'');
                   7986:     }
                   7987: }
                   7988: 
1.690     raeburn  7989: function toggleImportCrsres(caller) {
1.606     raeburn  7990:     var disp = 'none';
                   7991:     if (document.getElementById('importcrsresform')) {
                   7992:         if (caller == 'res') {
                   7993:             var curr = document.getElementById('importcrsresform').style.display;
                   7994:             if (curr == 'none') {
                   7995:                 disp='block';
1.698     raeburn  7996:                 populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
                   7997:                 if ((document.getElementById('importcrsrescontent')) &&
                   7998:                     (document.getElementById('importcrsresempty'))) {
                   7999:                     var selelem = document.crsresimportform.elements['coursepath'];
                   8000:                     var numdirs = 0;
                   8001:                     if (selelem.options.length) {
                   8002:                         numdirs = selelem.options.length - 1;
                   8003:                     }
                   8004:                     if (numdirs) {
                   8005:                         document.getElementById('importcrsrescontent').style.display='block';
                   8006:                         document.getElementById('importcrsresempty').style.display='none';
                   8007:                     } else {
                   8008:                         document.getElementById('importcrsrescontent').style.display='none';
                   8009:                         document.getElementById('importcrsresempty').style.display='block';
                   8010:                     }
                   8011:                 }
1.606     raeburn  8012:             }
                   8013:         }
                   8014:         document.getElementById('importcrsresform').style.display=disp;
                   8015:         resize_scrollbox('contentscroll','1','0');
                   8016:     }
                   8017:     return;
                   8018: }
                   8019: 
1.690     raeburn  8020: $showfile_js
                   8021: 
1.691     raeburn  8022: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
                   8023:     var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
                   8024:     if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
                   8025:         var selelem = form.elements[dirsel];
                   8026:         var i, numfiles = selelem.options.length -1;
                   8027:         if (numfiles >=0) {
                   8028:             for (i = numfiles; i >= 0; i--) {
                   8029:                 selelem.remove(i);
                   8030:             }
                   8031:         }
                   8032:         if ((location == '') || (location == null) || (location == 'undefined')) {
                   8033:              if (selelem.options.length == 0) {
                   8034:                  selelem.options[selelem.options.length] = new Option('','');
                   8035:                  selelem.selectedIndex = 0;
                   8036:              }
                   8037:              if (document.getElementById('newstdproblem')) {
                   8038:                  document.getElementById('newstdproblem').style.display = 'none';
                   8039:              }
                   8040:              return;
                   8041:         }
                   8042:         var machineIds = new Array($machines_str);
                   8043:         var athome = 0;
                   8044:         var role = location;
                   8045:         if ((location == 'author') || (location == 'course')) {
                   8046:             if (document.getElementById('rolehome_'+location)) {
                   8047:                 var currhome = document.getElementById('rolehome_'+location).value;
                   8048:                 if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
                   8049:                     if (machineIds.includes(currhome)) {
                   8050:                         athome = 1;
                   8051:                     }
                   8052:                 }
                   8053:             }
                   8054:         } else {
                   8055:             const roleinfo = location.split('___');
                   8056:             role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
                   8057:             if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
                   8058:                 var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
                   8059:                 if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
                   8060:                     if (machineIds.includes(currhome)) {
                   8061:                         athome = 1;
                   8062:                     }
                   8063:                 }
                   8064:             }
                   8065:         }
                   8066:         if (athome) {
                   8067:             if (document.getElementById('stdprobswitch')) {
                   8068:                 document.getElementById('stdprobswitch').style.display = 'none';
                   8069:             }
                   8070:             if (document.getElementById('newstdproblem')) {
                   8071:                 document.getElementById('newstdproblem').style.display = 'none';
                   8072:             }
                   8073:             var http = new XMLHttpRequest();
                   8074:             var url = "/adm/courseauthor";
1.698     raeburn  8075:             var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691     raeburn  8076:             http.open("POST", url, true);
                   8077:             http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                   8078:             http.onreadystatechange = function() {
                   8079:                 if (http.readyState == 4 && http.status == 200) {
                   8080:                     var data = JSON.parse(http.responseText);
                   8081:                     if (Array.isArray(data.dirs)) {
                   8082:                         var len = data.dirs.length;
                   8083:                         if (len) {
                   8084:                             if (len > 1) {
                   8085:                                 selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
                   8086:                             }
                   8087:                         }
                   8088:                         if (len) {
                   8089:                             var j;
                   8090:                             for (j = 0; j < len; j++) {
                   8091:                                 selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
                   8092:                             }
                   8093:                             selelem.selectedIndex = 0;
1.697     raeburn  8094:                             if (len == 1) {
                   8095:                                 toggleCrsResTitle();
                   8096:                             }
1.691     raeburn  8097:                         }
                   8098:                     }
                   8099:                 }
                   8100:             }
                   8101:             http.send(params);
                   8102:         } else {
                   8103:             selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
                   8104:             selelem.selectedIndex = 0;
                   8105:             if (document.getElementById('stdprobswitch')) {
                   8106:                 document.getElementById('stdprobswitch').style.display = 'block';
                   8107:             }
                   8108:             if (document.getElementById('newstdproblem')) {
                   8109:                 document.getElementById('newstdproblem').style.display = 'none';
                   8110:             }
                   8111:         }
                   8112:     }
                   8113:     return;
                   8114: }
                   8115: 
1.689     raeburn  8116: function switchForProb() {
                   8117:     if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
                   8118:         var url = '/adm/switchserver?otherserver=';
                   8119:         var newhostid = '';
                   8120:         var role = '';
                   8121:         var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
                   8122:         if (selloc == 'author') {
                   8123:             newhostid = document.courseresform.rolehome_author.value;
                   8124:             role = "au./&js_escape($env{'user.domain'})/";
                   8125:         } else if (selloc == 'course') {
                   8126:             newhostid = document.courseresform.rolehome_course.value;
                   8127:             role = "&js_escape($env{'request.role'})";
                   8128:         } else {
                   8129:             var items = new Array();
                   8130:             items = selloc.split('___');
                   8131:             var len = document.courseresform.rolehome_coauthor.length;
                   8132:             if (null == len) {
                   8133:                 var currval = document.courseresform.rolehome_coauthor.value;
                   8134:                 if (null != currval) {
                   8135:                     var info = new Array();
                   8136:                     info = currval.split('=');
                   8137:                     newhostid = info[2];
                   8138:                     role = info[0]+'./'+info[1];
                   8139:                 }
                   8140:             } else {
                   8141:                 for (var i=0; i<len; i++) {
                   8142:                     var currval = document.courseresform.rolehome_coauthor[i].value;
                   8143:                     if (null != currval) {
                   8144:                         var info = new Array();
                   8145:                         info = currval.split('=');
                   8146:                         if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
                   8147:                             newhostid = info[2];
                   8148:                             role = info[0]+'./'+info[1];
                   8149:                             break;
                   8150:                         }
                   8151:                     }
                   8152:                 }
                   8153:             }
                   8154:         }
                   8155:         if (newhostid != '') {
                   8156:             url += newhostid;
                   8157:             if (role != '') {
                   8158:                 url += '&role='+role;
                   8159:             }
                   8160:             document.location.href = url;
                   8161:         }
                   8162:     }
                   8163:     return;
                   8164: }
                   8165: 
1.501     raeburn  8166: function makeims(imsform) {
                   8167:     if ((imsform.uploaddoc.value == '')  || (!imsform.uploaddoc.value)) {
1.594     damieng  8168:         alert("$js_lt{'imsfile'}");
1.501     raeburn  8169:         return;
                   8170:     }
                   8171:     if (imsform.source.selectedIndex == 0) {
1.594     damieng  8172:         alert("$js_lt{'imscms'}");
1.501     raeburn  8173:         return;
                   8174:     }
                   8175:     newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
                   8176:     imsform.submit();
                   8177: }
                   8178: 
1.478     raeburn  8179: function updatePick(targetform,index,caller) {
1.537     raeburn  8180:     var pickitem;
                   8181:     var picknumitem;
                   8182:     var picknumtext;
                   8183:     if (index == 'all') {
                   8184:         pickitem = document.getElementById('randompickall');
                   8185:         picknumitem = document.getElementById('rpicknumall');
                   8186:         picknumtext = document.getElementById('rpicktextall');
                   8187:     } else {
                   8188:         pickitem = document.getElementById('randompick_'+index);
                   8189:         picknumitem = document.getElementById('rpicknum_'+index);
                   8190:         picknumtext = document.getElementById('randompicknum_'+index);
                   8191:     }
1.478     raeburn  8192:     if (pickitem.checked) {
1.594     damieng  8193:         var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478     raeburn  8194:         if (picknum == '' || picknum == null) {
                   8195:             if (caller == 'check') {
                   8196:                 pickitem.checked=false;
1.537     raeburn  8197:                 if (index == 'all') {
                   8198:                     picknumtext.innerHTML = '';
                   8199:                     if (caller == 'link') {
                   8200:                         propagateState(targetform,'rpicknum');
                   8201:                     }
                   8202:                 } else {
1.538     raeburn  8203:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8204:                 }
1.478     raeburn  8205:             }
                   8206:         } else {
                   8207:             picknum.toString();
                   8208:             var regexdigit=/^\\d+\$/;
                   8209:             if (regexdigit.test(picknum)) {
                   8210:                 picknumitem.value = picknum;
1.537     raeburn  8211:                 if (index == 'all') {
1.538     raeburn  8212:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537     raeburn  8213:                     if (caller == 'link') {
                   8214:                         propagateState(targetform,'rpicknum');
                   8215:                     }
                   8216:                 } else {
                   8217:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538     raeburn  8218:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8219:                 }
1.478     raeburn  8220:             } else {
                   8221:                 if (caller == 'check') {
1.537     raeburn  8222:                     if (index == 'all') {
                   8223:                         picknumtext.innerHTML = '';
                   8224:                         if (caller == 'link') {
                   8225:                             propagateState(targetform,'rpicknum');
                   8226:                         }
                   8227:                     } else {
                   8228:                         pickitem.checked=false;
1.538     raeburn  8229:                         checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8230:                     }
1.478     raeburn  8231:                 }
                   8232:                 return;
                   8233:             }
                   8234:         }
                   8235:     } else {
1.537     raeburn  8236:         picknumitem.value = '';
                   8237:         picknumtext.innerHTML = '';
                   8238:         if (index == 'all') {
                   8239:             if (caller == 'link') {
                   8240:                 propagateState(targetform,'rpicknum');
                   8241:             }
                   8242:         } else {
1.538     raeburn  8243:             checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8244:         }
                   8245:     }
                   8246: }
                   8247: 
                   8248: function propagateState(form,param) {
                   8249:     if (document.getElementById(param+'all')) {
                   8250:         var setcheck = 0;
                   8251:         var rpick = 0;
                   8252:         if (param == 'rpicknum') {
                   8253:             if (document.getElementById('randompickall')) {
                   8254:                 if (document.getElementById('randompickall').checked) {
                   8255:                     if (document.getElementById('rpicknumall')) {
                   8256:                         rpick = document.getElementById('rpicknumall').value;
                   8257:                     }
                   8258:                 }
                   8259:             }
                   8260:         } else {
                   8261:             if (document.getElementById(param+'all').checked) {
                   8262:                 setcheck = 1;
                   8263:             }
                   8264:         }
1.538     raeburn  8265:         var allidxlist;
                   8266:         if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   8267:             if (document.getElementById('all'+param+'idx')) {
                   8268:                 allidxlist = document.getElementById('all'+param+'idx').value;
                   8269:             }
                   8270:             var actions = new Array ('remove','cut','copy');
                   8271:             for (var i=0; i<actions.length; i++) {
                   8272:                 if (actions[i] != param) {
                   8273:                     if (document.getElementById(actions[i]+'all')) {
                   8274:                         document.getElementById(actions[i]+'all').checked = false; 
                   8275:                     }
                   8276:                 }
                   8277:             }
                   8278:         }
1.537     raeburn  8279:         if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538     raeburn  8280:             allidxlist = form.allidx.value;
                   8281:         }
                   8282:         if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
                   8283:             allidxlist = form.allmapidx.value;
                   8284:         }
                   8285:         if ((allidxlist != '') && (allidxlist != null)) {
                   8286:             var allidxs = allidxlist.split(',');
                   8287:             if (allidxs.length > 1) {
                   8288:                 for (var i=0; i<allidxs.length; i++) {
                   8289:                     if (document.getElementById(param+'_'+allidxs[i])) {
                   8290:                         if (param == 'rpicknum') {
                   8291:                             if (document.getElementById('randompick_'+allidxs[i])) {
                   8292:                                 if (document.getElementById('randompick_'+allidxs[i]).checked) {
                   8293:                                     document.getElementById(param+'_'+allidxs[i]).value = rpick;
                   8294:                                     if (rpick > 0) {
                   8295:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ':&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
                   8296:                                     } else {
                   8297:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   8298:                                     }
                   8299:                                 }
                   8300:                             }
                   8301:                         } else {
1.537     raeburn  8302:                             if (setcheck == 1) {
                   8303:                                 document.getElementById(param+'_'+allidxs[i]).checked = true;
                   8304:                             } else {
                   8305:                                 document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538     raeburn  8306:                                 if (param == 'randompick') {
                   8307:                                     document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   8308:                                 }
1.537     raeburn  8309:                             }
                   8310:                         }
                   8311:                     }
                   8312:                 }
1.538     raeburn  8313:                 if (setcheck == 1) {
                   8314:                     if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   8315:                         var actions = new Array('copy','cut','remove');
                   8316:                         for (var i=0; i<actions.length; i++) {
                   8317:                             var otheractions;
                   8318:                             var otheridxs;
                   8319:                             if (actions[i] === param) {
                   8320:                                 continue;
                   8321:                             } else {
                   8322:                                 if (document.getElementById('all'+actions[i]+'idx')) {
                   8323:                                     otheractions = document.getElementById('all'+actions[i]+'idx').value;
                   8324:                                     otheridxs = otheractions.split(',');
                   8325:                                     if (otheridxs.length > 1) {
                   8326:                                         for (var j=0; j<otheridxs.length; j++) {
                   8327:                                             if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
                   8328:                                                 document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
                   8329:                                             }
1.537     raeburn  8330:                                         }
                   8331:                                     }
                   8332:                                 }
1.538     raeburn  8333:                             }
                   8334:                         } 
                   8335:                     }
                   8336:                 }
                   8337:             }
                   8338:         }
                   8339:     }
                   8340:     return;
                   8341: }
                   8342: 
1.603     raeburn  8343: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611     raeburn  8344:     var canedit = '$canedit';
                   8345:     if (canedit == '') {
                   8346:         alert("$js_lt{'edri'}");
                   8347:         return;
                   8348:     }
1.539     raeburn  8349:     var dosettings;
                   8350:     var doaction;
1.538     raeburn  8351:     var control = document.togglemultsettings;
                   8352:     if (context == 'actions') {
                   8353:         control = document.togglemultactions;
1.539     raeburn  8354:         doaction = 1; 
                   8355:     } else {
                   8356:         dosettings = 1;
1.538     raeburn  8357:     }
1.539     raeburn  8358:     if (control) {
                   8359:         if (control.showmultpick.length) {
                   8360:             for (var i=0; i<control.showmultpick.length; i++) {
                   8361:                 if (control.showmultpick[i].checked) {
                   8362:                     if (control.showmultpick[i].value == 1) {
                   8363:                         if (context == 'settings') {
                   8364:                             dosettings = 0;
                   8365:                         } else {
                   8366:                             doaction = 0;
1.538     raeburn  8367:                         }
                   8368:                     }
                   8369:                 }
1.537     raeburn  8370:             }
                   8371:         }
1.539     raeburn  8372:     }
                   8373:     if (context == 'settings') {
                   8374:         if (dosettings == 1) {
1.538     raeburn  8375:             targetform.changeparms.value=param;
                   8376:             targetform.submit();
                   8377:         }
1.537     raeburn  8378:     }
1.539     raeburn  8379:     if (context == 'actions') {
                   8380:         if (doaction == 1) {
                   8381:             targetform.cmd.value=param+'_'+index;
                   8382:             targetform.folderpath.value=folderpath;
                   8383:             targetform.markcopy.value=idx+':'+param;
                   8384:             targetform.copyfolder.value=folder+'.'+container;
                   8385:             if (param == 'remove') {
1.603     raeburn  8386:                 var doremove = 0;
                   8387:                 if (skip_confirm) {
                   8388:                     if (confirm_removal) {
                   8389:                         if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
                   8390:                             doremove = 1;
                   8391:                         }
                   8392:                     } else {
                   8393:                         doremove = 1;
                   8394:                     }
                   8395:                 } else {
                   8396:                     if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
                   8397:                         doremove = 1;
                   8398:                     }
                   8399:                 }
                   8400:                 if (doremove) {
1.539     raeburn  8401:                     targetform.markcopy.value='';
                   8402:                     targetform.copyfolder.value='';
                   8403:                     targetform.submit();
                   8404:                 }
                   8405:             }
                   8406:             if (param == 'cut') {
1.594     damieng  8407:                 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  8408:                     targetform.submit();
                   8409:                     return;
                   8410:                 }
                   8411:             }
                   8412:             if (param == 'copy') {
                   8413:                 targetform.submit();
                   8414:                 return;
                   8415:             }
                   8416:             targetform.markcopy.value='';
                   8417:             targetform.copyfolder.value='';
                   8418:             targetform.cmd.value='';
                   8419:             targetform.folderpath.value='';
                   8420:             return;
                   8421:         } else {
                   8422:             if (document.getElementById(param+'_'+idx)) {
                   8423:                 item = document.getElementById(param+'_'+idx);
                   8424:                 if (item.type == 'checkbox') {
                   8425:                     if (item.checked) {
                   8426:                         item.checked = false;
                   8427:                     } else {
                   8428:                         item.checked = true;
                   8429:                         singleCheck(item,idx,param);
                   8430:                     }
                   8431:                 }
                   8432:             }
                   8433:         }
                   8434:     }
1.537     raeburn  8435:     return;
                   8436: }
                   8437: 
1.538     raeburn  8438: function singleCheck(caller,idx,action) {
                   8439:     actions = new Array('cut','copy','remove');
                   8440:     if (caller.checked) {
                   8441:         for (var i=0; i<actions.length; i++) {
                   8442:             if (actions[i] != action) {
                   8443:                 if (document.getElementById(actions[i]+'_'+idx)) {
                   8444:                     if (document.getElementById(actions[i]+'_'+idx).checked) {
                   8445:                         document.getElementById(actions[i]+'_'+idx).checked = false;
                   8446:                     }
1.537     raeburn  8447:                 }
                   8448:             }
                   8449:         }
1.478     raeburn  8450:     }
1.537     raeburn  8451:     return;
1.478     raeburn  8452: }
                   8453: 
1.334     muellerd 8454: function unselectInactive(nav) {
1.335     ehlerst  8455: currentNav = document.getElementById(nav);
                   8456: currentLis = currentNav.getElementsByTagName('LI');
                   8457: for (i = 0; i < currentLis.length; i++) {
1.472     raeburn  8458:         if (currentLis[i].className == 'goback') {
                   8459:             currentLis[i].className = 'goback';
                   8460:         } else {
                   8461: 	    if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374     tempelho 8462: 		currentLis[i].className = 'right';
1.472     raeburn  8463: 	    } else {
1.374     tempelho 8464: 		currentLis[i].className = 'i';
1.472     raeburn  8465: 	    }
                   8466:         }
1.335     ehlerst  8467: }
1.332     tempelho 8468: }
                   8469: 
1.334     muellerd 8470: function hideAll(current, nav, data) {
1.335     ehlerst  8471: unselectInactive(nav);
1.570     raeburn  8472: if (current) { 
                   8473:     if (current.className == 'right'){
                   8474:         current.className = 'right active'
                   8475:     } else {
                   8476:         current.className = 'active';
                   8477:     }
1.374     tempelho 8478: }
1.335     ehlerst  8479: currentData = document.getElementById(data);
                   8480: currentDivs = currentData.getElementsByTagName('DIV');
                   8481: for (i = 0; i < currentDivs.length; i++) {
                   8482: 	if(currentDivs[i].className == 'LC_ContentBox'){
1.333     muellerd 8483: 		currentDivs[i].style.display = 'none';
1.330     tempelho 8484: 	}
                   8485: }
1.335     ehlerst  8486: }
1.330     tempelho 8487: 
1.374     tempelho 8488: function openTabs(pageId) {
                   8489: 	tabnav = document.getElementById(pageId).getElementsByTagName('UL');	
1.383     tempelho 8490: 	if(tabnav.length > 2 ){
1.389     tempelho 8491: 		currentNav = document.getElementById(tabnav[1].id);
1.374     tempelho 8492: 		currentLis = currentNav.getElementsByTagName('LI');
                   8493: 		for(i = 0; i< currentLis.length; i++){
                   8494: 			if(currentLis[i].className == 'active') {
1.375     tempelho 8495: 				funcString = currentLis[i].onclick.toString();
                   8496: 				tab = funcString.split('"');
1.420     onken    8497:                                 if(tab.length < 2) {
                   8498:                                    tab = funcString.split("'");
                   8499:                                 }
1.375     tempelho 8500: 				currentData = document.getElementById(tab[1]);
                   8501:         			currentData.style.display = 'block';
1.374     tempelho 8502: 			}	
                   8503: 		}
                   8504: 	}
                   8505: }
                   8506: 
1.334     muellerd 8507: function showPage(current, pageId, nav, data) {
1.570     raeburn  8508:         currstate = current.className;
1.334     muellerd 8509: 	hideAll(current, nav, data);
1.375     tempelho 8510: 	openTabs(pageId);
1.334     muellerd 8511: 	unselectInactive(nav);
1.570     raeburn  8512:         if ((currstate == 'active') || (currstate == 'right active')) {
                   8513:             if (currstate == 'active') {
                   8514: 	        current.className = '';
                   8515:             } else {
                   8516:                 current.className = 'right';
                   8517:             }
                   8518:             activeTab = ''; 
1.656     raeburn  8519:             toggleExternal();
1.570     raeburn  8520:             toggleUpload();
                   8521:             toggleMap();
1.606     raeburn  8522:             toggleCrsRes();
                   8523:             toggleImportCrsres();
1.570     raeburn  8524:             resize_scrollbox('contentscroll','1','0');
                   8525:             return;
                   8526:         } else {
                   8527:             current.className = 'active';
                   8528:         }
1.330     tempelho 8529: 	currentData = document.getElementById(pageId);
                   8530: 	currentData.style.display = 'block';
1.458     raeburn  8531:         activeTab = pageId;
1.656     raeburn  8532:         toggleExternal();
1.501     raeburn  8533:         toggleUpload();
1.503     raeburn  8534:         toggleMap();
1.606     raeburn  8535:         toggleCrsRes();
                   8536:         toggleImportCrsres();
1.433     raeburn  8537:         if (nav == 'mainnav') {
                   8538:             var storedpath = "$docs_folderpath";
1.434     raeburn  8539:             var storedpage = "$main_container_page";
1.433     raeburn  8540:             var reg = new RegExp("^supplemental");
                   8541:             if (pageId == 'mainCourseDocuments') {
1.434     raeburn  8542:                 if (storedpage == 1) {
                   8543:                     document.simpleedit.folderpath.value = '';
                   8544:                     document.uploaddocument.folderpath.value = '';
                   8545:                 } else {
                   8546:                     if (reg.test(storedpath)) {
                   8547:                         document.simpleedit.folderpath.value = '$toplevelmain';
                   8548:                         document.uploaddocument.folderpath.value = '$toplevelmain';
                   8549:                         document.newext.folderpath.value = '$toplevelmain';
                   8550:                     } else {
                   8551:                         document.simpleedit.folderpath.value = storedpath;
                   8552:                         document.uploaddocument.folderpath.value = storedpath;
                   8553:                         document.newext.folderpath.value = storedpath;
                   8554:                     }
1.433     raeburn  8555:                 }
                   8556:             } else {
1.434     raeburn  8557:                 if (reg.test(storedpath)) {
                   8558:                     document.simpleedit.folderpath.value = storedpath;
                   8559:                     document.supuploaddocument.folderpath.value = storedpath;
                   8560:                     document.supnewext.folderpath.value = storedpath;
                   8561:                 } else {
1.433     raeburn  8562:                     document.simpleedit.folderpath.value = '$toplevelsupp';
                   8563:                     document.supuploaddocument.folderpath.value = '$toplevelsupp';
                   8564:                     document.supnewext.folderpath.value = '$toplevelsupp';
                   8565:                 }
                   8566:             }
                   8567:         }
1.485     raeburn  8568:         resize_scrollbox('contentscroll','1','0');
1.330     tempelho 8569: 	return false;
                   8570: }
1.329     droeschl 8571: 
1.472     raeburn  8572: function toContents(jumpto) {
                   8573:     var newurl = '$backtourl';
1.525     raeburn  8574:     if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472     raeburn  8575:         newurl = newurl+'?postdata='+jumpto;
                   8576:     }
                   8577:     location.href=newurl;
                   8578: }
                   8579: 
1.538     raeburn  8580: function togglePick(caller,value) {
                   8581:     var disp = 'none';
                   8582:     if (document.getElementById('multi'+caller)) {
                   8583:         var curr = document.getElementById('multi'+caller).style.display;
                   8584:         if (value == 1) {
                   8585:             disp='block';
                   8586:         }
                   8587:         if (curr == disp) {
                   8588:             return; 
                   8589:         }
                   8590:         document.getElementById('multi'+caller).style.display=disp;
                   8591:         if (value == 1) {
1.594     damieng  8592:             document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>'; 
1.538     raeburn  8593:         } else {
                   8594:             document.getElementById('more'+caller).innerHTML = '';
                   8595:         }
                   8596:         if (caller == 'actions') { 
                   8597:             setClass(value);
                   8598:             setBoxes(value);
                   8599:         }
                   8600:     }
                   8601:     var showButton = multiSettings();
                   8602:     if (showButton != 1) {
                   8603:         showButton = multiActions();
                   8604:     }
                   8605:     if (document.getElementById('multisave')) {
                   8606:         if (showButton == 1) {
                   8607:             document.getElementById('multisave').style.display='block';
                   8608:         } else {
                   8609:             document.getElementById('multisave').style.display='none';
                   8610:         }
                   8611:     }
                   8612:     resize_scrollbox('contentscroll','1','1');
                   8613:     return;
                   8614: }
                   8615: 
                   8616: function toggleCheckUncheck(caller,more) {
                   8617:     if (more == 1) {
1.594     damieng  8618:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538     raeburn  8619:         document.getElementById('allfields'+caller).style.display='block';
                   8620:     } else {
1.594     damieng  8621:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538     raeburn  8622:         document.getElementById('allfields'+caller).style.display='none';
                   8623:     }
                   8624:     resize_scrollbox('contentscroll','1','1');
                   8625: }
                   8626: 
                   8627: function multiSettings() {
                   8628:     var inuse = 0;
                   8629:     var settingsform = document.togglemultsettings;
                   8630:     if (settingsform.showmultpick.length > 1) {
                   8631:         for (var i=0; i<settingsform.showmultpick.length; i++) {
                   8632:             if (settingsform.showmultpick[i].checked) {
                   8633:                 if (settingsform.showmultpick[i].value == 1) {
                   8634:                     inuse = 1;  
                   8635:                 }
                   8636:             }
                   8637:         }
                   8638:     }
                   8639:     return inuse;
                   8640: }
                   8641: 
                   8642: function multiActions() {
                   8643:     var inuse = 0;
                   8644:     var actionsform = document.togglemultactions;
                   8645:     if (actionsform.showmultpick.length > 1) {
                   8646:         for (var i=0; i<actionsform.showmultpick.length; i++) {
                   8647:             if (actionsform.showmultpick[i].checked) {
                   8648:                 if (actionsform.showmultpick[i].value == 1) {
                   8649:                     inuse = 1;
                   8650:                 }
                   8651:             }
                   8652:         }
                   8653:     }
                   8654:     return inuse;
                   8655: } 
                   8656: 
                   8657: function checkSubmits() {
                   8658:     var numchanges = 0;
                   8659:     var form = document.saveactions;
                   8660:     var doactions = multiActions();
1.542     raeburn  8661:     var cutwarnings = 0;
                   8662:     var remwarnings = 0;
1.603     raeburn  8663:     var removalinfo = 0;
1.538     raeburn  8664:     if (doactions == 1) {
                   8665:         var remidxlist = document.cumulativeactions.allremoveidx.value;
                   8666:         if ((remidxlist != '') && (remidxlist != null)) {
                   8667:             var remidxs = remidxlist.split(',');
                   8668:             for (var i=0; i<remidxs.length; i++) {
                   8669:                 if (document.getElementById('remove_'+remidxs[i])) {
                   8670:                     if (document.getElementById('remove_'+remidxs[i]).checked) {
                   8671:                         form.multiremove.value += remidxs[i]+',';
                   8672:                         numchanges ++;
1.542     raeburn  8673:                         if (document.getElementById('skip_remove_'+remidxs[i])) {
                   8674:                             if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
                   8675:                                 remwarnings ++;
                   8676:                             }
                   8677:                         }
1.603     raeburn  8678:                         if (document.getElementById('confirm_removal_'+remidxs[i])) {
                   8679:                             if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
                   8680:                                 removalinfo ++;
                   8681:                             }
                   8682:                         }
1.537     raeburn  8683:                     }
                   8684:                 }
1.538     raeburn  8685:             }
                   8686:         }
                   8687:         var cutidxlist = document.cumulativeactions.allcutidx.value;
                   8688:         if ((cutidxlist != '') && (cutidxlist != null)) {
                   8689:             var cutidxs = cutidxlist.split(',');
                   8690:             for (var i=0; i<cutidxs.length; i++) {
                   8691:                 if (document.getElementById('cut_'+cutidxs[i])) {
                   8692:                     if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
                   8693:                         form.multicut.value += cutidxs[i]+',';
                   8694:                         numchanges ++;
1.542     raeburn  8695:                         if (document.getElementById('skip_cut_'+cutidxs[i])) {
                   8696:                             if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
                   8697:                                 cutwarnings ++;
                   8698:                             }
                   8699:                         }
1.537     raeburn  8700:                     }
                   8701:                 }
                   8702:             }
                   8703:         }
1.538     raeburn  8704:         var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   8705:         if ((copyidxlist != '') && (copyidxlist != null)) {
                   8706:             var copyidxs = copyidxlist.split(',');
                   8707:             for (var i=0; i<copyidxs.length; i++) {
                   8708:                 if (document.getElementById('copy_'+copyidxs[i])) {
                   8709:                     if (document.getElementById('copy_'+copyidxs[i]).checked) {
                   8710:                         form.multicopy.value += copyidxs[i]+',';
                   8711:                         numchanges ++;
                   8712:                     }
                   8713:                 }
                   8714:             }
                   8715:         }
                   8716:         if (numchanges > 0) {
                   8717:             form.multichange.value = numchanges;
                   8718:         }
1.537     raeburn  8719:     }
1.538     raeburn  8720:     var dosettings = multiSettings();
1.543     raeburn  8721:     var haschanges = 0;
1.538     raeburn  8722:     if (dosettings == 1) {
                   8723:         form.allencrypturl.value = '';
                   8724:         form.allhiddenresource.value = '';
1.543     raeburn  8725:         form.changeparms.value = 'all';
                   8726:         var patt=new RegExp(",\$");
1.538     raeburn  8727:         var allidxlist = document.cumulativesettings.allidx.value;
                   8728:         if ((allidxlist != '') && (allidxlist != null)) {
                   8729:             var allidxs = allidxlist.split(',');
                   8730:             if (allidxs.length > 1) {
                   8731:                 for (var i=0; i<allidxs.length; i++) {
                   8732:                     if (document.getElementById('hiddenresource_'+allidxs[i])) {
                   8733:                         if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
                   8734:                             form.allhiddenresource.value += allidxs[i]+',';
                   8735:                         }
                   8736:                     }
                   8737:                     if (document.getElementById('encrypturl_'+allidxs[i])) {
                   8738:                         if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
                   8739:                             form.allencrypturl.value += allidxs[i]+',';
                   8740:                         }
                   8741:                     }
                   8742:                 }
1.543     raeburn  8743:                 form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
                   8744:                 form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537     raeburn  8745:             }
1.538     raeburn  8746:         }
                   8747:         form.allrandompick.value = '';
                   8748:         form.allrandomorder.value = '';
                   8749:         var allmapidxlist = document.cumulativesettings.allmapidx.value;
                   8750:         if ((allmapidxlist != '') && (allmapidxlist != null)) {
                   8751:             var allmapidxs = allmapidxlist.split(',');
                   8752:             for (var i=0; i<allmapidxs.length; i++) {
                   8753:                 var randompick = document.getElementById('randompick_'+allmapidxs[i]);
                   8754:                 var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
                   8755:                 var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
                   8756:                 if ((randompick.checked) && (rpicknum.value != '')) {
                   8757:                     form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
                   8758:                 }
                   8759:                 if (randorder.checked) {
                   8760:                     form.allrandomorder.value += allmapidxs[i]+',';
                   8761:                 }
1.537     raeburn  8762:             }
1.543     raeburn  8763:             form.allrandompick.value = form.allrandompick.value.replace(patt,"");
                   8764:             form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
                   8765:         }
                   8766:         if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
                   8767:             haschanges = 1;
                   8768:         }
                   8769:         if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
                   8770:             haschanges = 1;
                   8771:         }
                   8772:         if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
                   8773:             haschanges = 1;
                   8774:         }
                   8775:         if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
                   8776:             haschanges = 1;
1.537     raeburn  8777:         }
                   8778:     }
1.543     raeburn  8779:     if (doactions == 1) {
1.542     raeburn  8780:         if (numchanges > 0) {
1.603     raeburn  8781:             if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542     raeburn  8782:                 if (remwarnings > 0) {
1.594     damieng  8783:                     if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542     raeburn  8784:                         return false;
                   8785:                     }
                   8786:                 }
1.603     raeburn  8787:                 if (removalinfo > 0) {
                   8788:                     if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
                   8789:                         return false;
                   8790:                     }
                   8791:                 }
1.542     raeburn  8792:                 if (cutwarnings > 0) {
1.594     damieng  8793:                     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  8794:                         return false;
                   8795:                     }
                   8796:                 }
                   8797:             }
                   8798:             form.submit();
                   8799:             return true;
1.543     raeburn  8800:         }
                   8801:     }
                   8802:     if (dosettings == 1) {
                   8803:         if (haschanges == 1) {
1.542     raeburn  8804:             form.submit();
                   8805:             return true;
                   8806:         }
1.543     raeburn  8807:     }
                   8808:     if ((dosettings == 1) && (doactions == 1)) {
1.594     damieng  8809:         alert("$js_lt{'noor'}");
1.543     raeburn  8810:     } else {
                   8811:         if (dosettings == 1) {
1.594     damieng  8812:             alert("$js_lt{'noch'}");
1.543     raeburn  8813:         } else {
1.594     damieng  8814:             alert("$js_lt{'noac'}");
1.543     raeburn  8815:         }
                   8816:     }
1.538     raeburn  8817:     return false;
                   8818: }
                   8819: 
                   8820: function setClass(value) {
                   8821:     var cutclass = 'LC_docs_cut';
                   8822:     var copyclass = 'LC_docs_copy';
                   8823:     var removeclass = 'LC_docs_remove';
                   8824:     var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
                   8825:     var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
                   8826:     var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
                   8827:     var links = document.getElementsByTagName('a');
                   8828:     for (var i=0; i<links.length; i++) {
                   8829:         var classes = links[i].className;
                   8830:         if (cutreg.test(classes)) {
                   8831:             links[i].className = cutclass;
                   8832:             if (value == 1) {
                   8833:                 links[i].className += " LC_menubuttons_link";
                   8834:             }
                   8835:         } else {
                   8836:             if (copyreg.test(classes)) {
                   8837:                 links[i].className = copyclass;
                   8838:                 if (value == 1) {
                   8839:                     links[i].className += " LC_menubuttons_link";
                   8840:                 } 
                   8841:             } else {
                   8842:                 if (removereg.test(classes)) {
                   8843:                     links[i].className = removeclass;
                   8844:                     if (value == 1) {
                   8845:                         links[i].className += " LC_menubuttons_link";
                   8846:                     }
                   8847:                 }
                   8848:             }
                   8849:         }
                   8850:     }
                   8851:     return;
1.537     raeburn  8852: }
                   8853: 
1.538     raeburn  8854: function setBoxes(value) {
                   8855:     var remidxlist = document.cumulativeactions.allremoveidx.value;
                   8856:     if ((remidxlist != '') && (remidxlist != null)) {
                   8857:         var remidxs = remidxlist.split(',');
                   8858:         for (var i=0; i<remidxs.length; i++) {
                   8859:             if (document.getElementById('remove_'+remidxs[i])) {
                   8860:                 var item = document.getElementById('remove_'+remidxs[i]);
                   8861:                 if (value == 1) {
                   8862:                     item.className = 'LC_docs_remove';
                   8863:                 } else {
                   8864:                     item.className = 'LC_hidden';
                   8865:                 }
                   8866:             }
                   8867:         }
                   8868:     }
                   8869:     var cutidxlist = document.cumulativeactions.allcutidx.value;
                   8870:     if ((cutidxlist != '') && (cutidxlist != null)) {
                   8871:         var cutidxs = cutidxlist.split(',');
                   8872:         for (var i=0; i<cutidxs.length; i++) {
                   8873:             if (document.getElementById('cut_'+cutidxs[i])) {
                   8874:                 var item = document.getElementById('cut_'+cutidxs[i]);
                   8875:                 if (value == 1) {
                   8876:                     item.className = 'LC_docs_cut';
                   8877:                 } else {
                   8878:                     item.className = 'LC_hidden';
                   8879:                 }
                   8880:             }
1.537     raeburn  8881:         }
                   8882:     }
1.538     raeburn  8883:     var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   8884:     if ((copyidxlist != '') && (copyidxlist != null)) {
                   8885:         var copyidxs = copyidxlist.split(',');
                   8886:         for (var i=0; i<copyidxs.length; i++) {
                   8887:             if (document.getElementById('copy_'+copyidxs[i])) {
                   8888:                 var item = document.getElementById('copy_'+copyidxs[i]);
                   8889:                 if (value == 1) {
                   8890:                     item.className = 'LC_docs_copy';
                   8891:                 } else {
                   8892:                     item.className = 'LC_hidden';
                   8893:                 }
                   8894:             }
1.537     raeburn  8895:         }
                   8896:     }
                   8897:     return;
                   8898: }
                   8899: 
1.606     raeburn  8900: function validImportCrsRes() {
                   8901:     var path =  document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
                   8902:     var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
                   8903:     if ((fname == '') || (fname == null)) {
                   8904:         alert("$js_lt{'nofi'}");
                   8905:         return false;
                   8906:     }
                   8907:     var url = '/res/$coursedom/$coursenum/';
                   8908:     if (path && path != '/') {
                   8909:         url += path+'/';
                   8910:     }
                   8911:     if (fname != '') {
                   8912:         url += fname;
                   8913:     }
                   8914:     var title = document.crsresimportform.crsrestitle.value;
1.676     raeburn  8915:     document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606     raeburn  8916:     return true;
                   8917: }
                   8918: 
                   8919: function validateNewRes(caller) {
                   8920:     if (caller == 'single') {
                   8921:         var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value; 
                   8922:         var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
                   8923:         var resname = document.courseresform.newresourcename.value;
                   8924:     }
                   8925: }
                   8926: 
1.611     raeburn  8927: ENDSCRIPT
1.329     droeschl 8928: }
1.457     raeburn  8929: 
1.483     raeburn  8930: sub history_tab_js {
                   8931:     return <<"ENDHIST";
                   8932: function toggleHistoryDisp(choice) {
                   8933:     document.docslogform.docslog.value = choice;
                   8934:     document.docslogform.submit();
                   8935:     return;
                   8936: }
                   8937: 
                   8938: ENDHIST
                   8939: }
                   8940: 
1.484     raeburn  8941: sub inject_data_js {
                   8942:     return <<ENDINJECT;
                   8943: 
                   8944: function injectData(current, hiddenField, name, value) {
                   8945:         currentElement = document.getElementById(hiddenField);
                   8946:         currentElement.name = name;
                   8947:         currentElement.value = value;
                   8948:         current.submit();
                   8949: }
                   8950: 
                   8951: ENDINJECT
                   8952: }
                   8953: 
                   8954: sub dump_switchserver_js {
                   8955:     my @hosts = @_;
1.594     damieng  8956:     my %js_lt = &Apache::lonlocal::texthash(
1.574     raeburn  8957:         dump => 'Copying content to Authoring Space requires switching server.',
1.484     raeburn  8958:         swit => 'Switch server?',
1.594     damieng  8959:     );
                   8960:     my %html_js_lt = &Apache::lonlocal::texthash(
                   8961:         swit => 'Switch server?',
1.568     raeburn  8962:         duco => 'Copying Content to Authoring Space',
1.484     raeburn  8963:         yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
                   8964:         chos => 'Choose server',
                   8965:     );
1.594     damieng  8966:     &js_escape(\%js_lt);
                   8967:     &html_escape(\%html_js_lt);
                   8968:     &js_escape(\%html_js_lt);
1.484     raeburn  8969:     my $role = $env{'request.role'};
                   8970:     my $js = <<"ENDSWJS";
                   8971: <script type="text/javascript">
                   8972: function write_switchserver() {
                   8973:     var server;
                   8974:     if (document.setserver.posshosts.length > 0) {
                   8975:         for (var i=0; i<document.setserver.posshosts.length; i++) {
                   8976:             if (document.setserver.posshosts[i].checked) {
                   8977:                 server = document.setserver.posshosts[i].value;
                   8978:             }
                   8979:        }
                   8980:        opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
                   8981:     }
                   8982:     window.close();
                   8983: }
                   8984: </script>
                   8985: 
                   8986: ENDSWJS
                   8987: 
                   8988:     my $startpage = &Apache::loncommon::start_page('Choose server',$js,
                   8989:                                                    {'only_body' => 1,
                   8990:                                                     'js_ready'  => 1,});
                   8991:     my $endpage = &Apache::loncommon::end_page({'js_ready'  => 1});
                   8992: 
                   8993:     my $hostpicker;
                   8994:     my $count = 0;
                   8995:     foreach my $host (sort(@hosts)) {
                   8996:         my $checked;
                   8997:         if ($count == 0) {
                   8998:             $checked = ' checked="checked"';
                   8999:         }
                   9000:         $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
                   9001:                        $host.'"'.$checked.' />'.$host.'</label>&nbsp;&nbsp;';
                   9002:         $count++;
                   9003:     }
                   9004:     
                   9005:     return <<"ENDSWITCHJS";
                   9006: 
                   9007: function dump_needs_switchserver(url) {
                   9008:     if (url!='' && url!= null) {
1.594     damieng  9009:         if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484     raeburn  9010:             go(url);
                   9011:         }
                   9012:     }
                   9013:     return;
                   9014: }
                   9015: 
                   9016: function choose_switchserver_window() {
                   9017:     newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
                   9018:     newWindow.document.open();
                   9019:     newWindow.document.writeln('$startpage');
1.594     damieng  9020:     newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
                   9021:        '<p>$html_js_lt{'yone'}<\\/p>\\n'+
                   9022:        '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484     raeburn  9023:        '<form name="setserver" method="post" action="" \\/>\\n'+
                   9024:        '$hostpicker\\n'+
                   9025:        '<br \\/><br \\/>\\n'+
1.594     damieng  9026:        '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484     raeburn  9027:        'onclick="write_switchserver();" \\/>\\n'+
                   9028:        '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
                   9029:     newWindow.document.writeln('$endpage');
                   9030:     newWindow.document.close();
                   9031:     newWindow.focus();
                   9032: }
                   9033: 
                   9034: ENDSWITCHJS
                   9035: }
                   9036: 
                   9037: sub makedocslogform {
                   9038:     my ($formelems,$docslog) = @_;
                   9039:     return <<"LOGSFORM";
                   9040:  <form action="/adm/coursedocs" method="post" name="docslogform">
                   9041:    <input type="hidden" name="docslog" value="$docslog" />
                   9042:    $formelems
                   9043:  </form>
                   9044: LOGSFORM
                   9045: }
                   9046: 
                   9047: sub makesimpleeditform {
                   9048:     my ($formelems) = @_;
                   9049:     return <<"SIMPFORM";
                   9050:  <form name="simpleedit" method="post" action="/adm/coursedocs">
                   9051:    <input type="hidden" name="importdetail" value="" />
                   9052:    $formelems
                   9053:  </form>
                   9054: SIMPFORM
                   9055: }
                   9056: 
1.606     raeburn  9057: sub makenewproblem {
                   9058:     my ($r,$coursedom,$coursenum) = @_;
                   9059: # Creating a new problem
                   9060:     my ($redirect,$error);
                   9061:     if ($env{'form.authorrole'}) {
                   9062:         my ($newsubdir,$filename);
                   9063:         if ($env{'form.newsubdir'}) {
                   9064:             if ($env{'form.newsubdirname'} ne '') {
                   9065:                 $newsubdir = $env{'form.newsubdirname'};
1.654     raeburn  9066:             }
1.606     raeburn  9067:         }
                   9068:         if ($env{'form.newresourcename'}) {
                   9069:             $filename = $env{'form.newresourcename'};
                   9070:             $filename =~ s/\.(\d+)(\.\w+)$/$2/;
                   9071:             $filename =~ s/`//g;
                   9072:             $filename =~ s{/\.\./}{_}g;
                   9073:             $filename =~ s/\.+/./g;
                   9074:             $filename =~ s{/+}{_}g;
                   9075:             if ($filename ne '') {
                   9076:                 my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
                   9077:                 if (($ext) && ($ext ne '.problem')) {
                   9078:                     $filename = $name.'.problem';
                   9079:                 } elsif ($ext eq '') {
                   9080:                     $filename .= '.problem';
                   9081:                 }
                   9082:                 my $docroot = $r->dir_config('lonDocRoot');
                   9083:                 my @ids=&Apache::lonnet::current_machine_ids();
                   9084:                 if ($env{'form.authorrole'} eq 'author') {
                   9085:                     if ($env{'user.author'}) {
                   9086:                         if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
                   9087:                             my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
                   9088:                             my $path = $docroot.$url;
                   9089:                             my $subdir = $env{'form.authorpath'};
                   9090:                             $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   9091:                         }
                   9092:                     }
                   9093:                 } elsif ($env{'form.authorrole'} eq 'course') {
                   9094:                     my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   9095:                     if ($chome && grep(/^\Q$chome\E$/,@ids)) {
                   9096:                         my $url = "/priv/$coursedom/$coursenum";
                   9097:                         my $path=$docroot.$url;
                   9098:                         my $subdir = $env{'form.authorpath'};
                   9099:                         $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   9100:                         if ($redirect) {
                   9101:                             my $rightsfile = 'default.rights';
                   9102:                             my $sourcerights = "$path/$rightsfile";
                   9103:                             my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
                   9104:                             my $now = time;
                   9105:                             if (!-e $sourcerights) {
                   9106:                                 my $cid = $coursedom.'_'.$coursenum;
                   9107:                                 if (open(my $fh,">$sourcerights")) {
                   9108:                                     print $fh <<END;
                   9109: <accessrule effect="deny" realm="" type="course" role="" />
                   9110: <accessrule effect="allow" realm="$cid" type="course" role="" />
                   9111: END
                   9112:                                     close($fh);
                   9113:                                 }
                   9114:                             }
                   9115:                             if (!-e "$sourcerights.meta") {
                   9116:                                 if (open(my $fh,">$sourcerights.meta")) {
                   9117:                                     my $author=$env{'environment.firstname'}.' '.
                   9118:                                                $env{'environment.middlename'}.' '.
                   9119:                                                $env{'environment.lastname'}.' '.
                   9120:                                                $env{'environment.generation'};
                   9121:                                     $author =~ s/\s+$//;
                   9122:                                     print $fh <<"END";
                   9123: 
                   9124: <abstract></abstract>
                   9125: <author>$author</author>
                   9126: <authorspace>$coursenum:$coursedom</authorspace>
                   9127: <copyright>private</copyright>
                   9128: <creationdate>$now</creationdate>
                   9129: <customdistributionfile></customdistributionfile>
                   9130: <dependencies></dependencies>
                   9131: <domain>$coursedom</domain>
                   9132: <highestgradelevel>0</highestgradelevel>
                   9133: <keywords></keywords>
                   9134: <language>notset </language>
                   9135: <lastrevisiondate>$now</lastrevisiondate>
                   9136: <lowestgradelevel>0</lowestgradelevel>
                   9137: <mime>rights</mime>
                   9138: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
                   9139: <notes></notes>
                   9140: <obsolete></obsolete>
                   9141: <obsoletereplacement></obsoletereplacement>
                   9142: <owner>$coursenum:$coursedom</owner>
                   9143: <rule>deny:::course,allow:$cid::course</rule>
                   9144: <sourceavail></sourceavail>
                   9145: <standards></standards>
                   9146: <subject></subject>
                   9147: <title></title>
                   9148: END
1.654     raeburn  9149:                                     close($fh);
                   9150:                                 }
                   9151:                             }
                   9152:                             if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
                   9153:                                 if (!-e "$docroot/res/$coursedom") {
                   9154:                                     mkdir("$docroot/res/$coursedom",0755);
1.606     raeburn  9155:                                 }
1.654     raeburn  9156:                                 if (!-e "$docroot/res/$coursedom/$coursenum") {
                   9157:                                     mkdir("$docroot/res/$coursedom/$coursenum",0755);
                   9158:                                 }
                   9159:                                 if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
                   9160:                                     my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   9161:                                     my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606     raeburn  9162:                                 }
                   9163:                             }
1.654     raeburn  9164:                             my $source = $docroot.$redirect;
                   9165:                             if (!-e "$source.meta") {
                   9166:                                 my $cid = $coursedom.'_'.$coursenum;
                   9167:                                 my $now = time;
                   9168:                                 if (open(my $fh,">$source.meta")) {
                   9169:                                     my $author=$env{'environment.firstname'}.' '.
                   9170:                                                $env{'environment.middlename'}.' '.
                   9171:                                                $env{'environment.lastname'}.' '.
                   9172:                                                $env{'environment.generation'};
                   9173:                                     $author =~ s/\s+$//;
                   9174:                                     my $title = $env{'form.newresourcetitle'};
                   9175:                                     $title =~ s/^\s+|\s+$//g;
                   9176:                                     print $fh <<END;
1.606     raeburn  9177: 
                   9178: <abstract></abstract>
                   9179: <author>$author</author>
                   9180: <authorspace>$coursenum:$coursedom</authorspace>
                   9181: <copyright>custom</copyright>
                   9182: <creationdate>$now</creationdate>
                   9183: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
                   9184: <dependencies></dependencies>
                   9185: <domain>$coursedom</domain>
                   9186: <highestgradelevel>0</highestgradelevel>
                   9187: <keywords></keywords>
                   9188: <language>notset </language>
                   9189: <lastrevisiondate>$now</lastrevisiondate>
                   9190: <lowestgradelevel>0</lowestgradelevel>
                   9191: <mime>problem</mime>
                   9192: <modifyinguser>$coursenum:$coursedom</modifyinguser>
                   9193: <notes></notes>
                   9194: <obsolete></obsolete>
                   9195: <obsoletereplacement></obsoletereplacement>
                   9196: <owner>$coursenum:$coursedom</owner>
                   9197: <sourceavail></sourceavail>
                   9198: <standards></standards>
                   9199: <subject></subject>
                   9200: <title>$title</title>
                   9201: END
1.654     raeburn  9202:                                     close($fh);
1.606     raeburn  9203:                                 }
                   9204:                             }
                   9205:                         }
                   9206:                     }
                   9207:                 } else {
                   9208:                     my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
                   9209:                     my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
                   9210:                     if (grep(/^\Q$rolehome\E$/,@ids)) {
                   9211:                         my $now = time;
                   9212:                         if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
                   9213:                             my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
                   9214:                             if (($start <= $now) && (($end == 0) || ($end >= $now))) { 
                   9215:                                 my $url = "/priv/$audom/$auname";  
                   9216:                                 my $path = $r->dir_config('lonDocRoot').$url;
                   9217:                                 my $subdir = $env{'form.authorpath'};
                   9218:                                 $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   9219:                             }
                   9220:                         }
                   9221:                     }
                   9222:                 }
                   9223:             }
                   9224:         }
                   9225:     }
                   9226:     return ($redirect,$error);
                   9227: }
                   9228: 
                   9229: sub finishnewprob {
1.654     raeburn  9230:     my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607     raeburn  9231:     unless (-d $path) {
                   9232:         unless (mkdir($path,02770)) {
                   9233:             return;
                   9234:         }
                   9235:     }
1.606     raeburn  9236:     my $redirect;
                   9237:     if ($subdir ne '/') {
                   9238:         $subdir = &cleandir($subdir);
                   9239:         if (($subdir ne '') && (-d "$path/$subdir")) {
                   9240:             $path .= "/$subdir";
                   9241:             $url .= "/$subdir";
                   9242:         }
                   9243:     }
                   9244:     my $dest;
                   9245:     if ($newsubdir ne '') {
                   9246:         $newsubdir = &cleandir($newsubdir);
                   9247:     }
                   9248:     if ($newsubdir ne '') {
                   9249:         if (-d "$path/$newsubdir") {
                   9250:             $dest = "$path/$newsubdir/$filename";
                   9251:         } else {
                   9252:             my $dirok;
                   9253:             unless (-e "$path/$newsubdir") {
                   9254:                 if (mkdir("$path/$newsubdir",02770)) {
                   9255:                     if (chmod(02770,"$path/$newsubdir")) {
                   9256:                         $dirok = 1;
                   9257:                     }
                   9258:                 }
                   9259:             }
                   9260:             if ($dirok) {
                   9261:                 $dest = "$path/$newsubdir/$filename";
                   9262:             }
                   9263:         }
                   9264:         if (($dest ne '') && (!-e $dest)) {
                   9265:             $redirect = "$url/$newsubdir/$filename";
                   9266:         }
                   9267:     } else {
                   9268:         $dest = "$path/$filename";
                   9269:         if (($dest ne '') && (!-e $dest)) {
                   9270:             $redirect = "$url/$filename";
                   9271:         }
                   9272:     }
1.654     raeburn  9273:     if ((!-e $dest) && ($context ne 'upload')) {
                   9274:         my $template = $env{'form.template'};
                   9275:         my $copyfrom;
                   9276:         if ($template ne '') {
                   9277:             my %templates;
                   9278:             my @files = &Apache::lonhomework::get_template_list('problem');
                   9279:             foreach my $poss (@files) {
                   9280:                 if (ref($poss) eq 'ARRAY') {
                   9281:                     if ($template eq $poss->[0]) {
                   9282:                         $templates{$template} = 1;
                   9283:                         last;
                   9284:                     }
                   9285:                 }
                   9286:             }
                   9287:             if ($templates{$template}) {
                   9288:                 $copyfrom = $template;
                   9289:             }
                   9290:         }
                   9291:         if ($filename =~ /\.problem$/) {
                   9292:             unless ($copyfrom) {
                   9293:                 $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
                   9294:             }
                   9295:             &File::Copy::copy($copyfrom,$dest);
                   9296:         }
                   9297:     }
1.606     raeburn  9298:     return $redirect;
                   9299: }
                   9300: 
                   9301: sub cleandir {
                   9302:     my ($dir) = @_;
                   9303:     $dir =~ s/^\s+//;
                   9304:     $dir =~ s/\s+$//;
                   9305:     $dir =~ s/\.+//g;
                   9306:     $dir =~ s/[\#\?&%\":]//g;
                   9307:     return $dir;
                   9308: }
                   9309: 
1.329     droeschl 9310: 1;
                   9311: __END__
                   9312: 
                   9313: 
                   9314: =head1 NAME
                   9315: 
                   9316: Apache::londocs.pm
                   9317: 
                   9318: =head1 SYNOPSIS
                   9319: 
                   9320: This is part of the LearningOnline Network with CAPA project
                   9321: described at http://www.lon-capa.org.
                   9322: 
                   9323: =head1 SUBROUTINES
                   9324: 
                   9325: =over
                   9326: 
                   9327: =item %help=()
                   9328: 
                   9329: Available help topics
                   9330: 
                   9331: =item mapread()
                   9332: 
1.344     bisitz   9333: Mapread read maps into LONCAPA::map:: global arrays
1.329     droeschl 9334: @order and @resources, determines status
                   9335: sets @order - pointer to resources in right order
                   9336: sets @resources - array with the resources with correct idx
                   9337: 
                   9338: =item authorhosts()
                   9339: 
                   9340: Return hash with valid author names
                   9341: 
                   9342: =item clean()
                   9343: 
                   9344: =item dumpcourse()
                   9345: 
                   9346:     Actually dump course
                   9347: 
                   9348: =item group_import()
                   9349: 
                   9350:     Imports the given (name, url) resources into the course
                   9351:     coursenum, coursedom, and folder must precede the list
                   9352: 
                   9353: =item breadcrumbs()
                   9354: 
                   9355: =item log_docs()
                   9356: 
                   9357: =item docs_change_log()
                   9358: 
                   9359: =item update_paste_buffer()
                   9360: 
                   9361: =item print_paste_buffer()
                   9362: 
                   9363: =item do_paste_from_buffer()
                   9364: 
1.538     raeburn  9365: =item do_buffer_empty() 
                   9366: 
                   9367: =item clear_from_buffer()
                   9368: 
1.492     raeburn  9369: =item get_newmap_url()
                   9370: 
                   9371: =item dbcopy()
                   9372: 
                   9373: =item uniqueness_check()
                   9374: 
                   9375: =item contained_map_check()
                   9376: 
                   9377: =item url_paste_fixups()
                   9378: 
                   9379: =item apply_fixups()
                   9380: 
                   9381: =item copy_dependencies()
                   9382: 
1.329     droeschl 9383: =item update_parameter()
                   9384: 
                   9385: =item handle_edit_cmd()
                   9386: 
                   9387: =item editor()
                   9388: 
                   9389: =item process_file_upload()
                   9390: 
                   9391: =item process_secondary_uploads()
                   9392: 
                   9393: =item is_supplemental_title()
                   9394: 
                   9395: =item entryline()
                   9396: 
                   9397: =item tiehash()
                   9398: 
                   9399: =item untiehash()
                   9400: 
                   9401: =item checkonthis()
                   9402: 
                   9403: check on this
                   9404: 
                   9405: =item verifycontent()
                   9406: 
                   9407: Verify Content
                   9408: 
1.636     raeburn  9409: =item devalidateversioncache() 
                   9410: 
                   9411: =item checkversions()
1.329     droeschl 9412: 
                   9413: Check Versions
                   9414: 
                   9415: =item mark_hash_old()
                   9416: 
                   9417: =item is_hash_old()
                   9418: 
                   9419: =item changewarning()
                   9420: 
                   9421: =item init_breadcrumbs()
                   9422: 
                   9423: Breadcrumbs for special functions
                   9424: 
1.484     raeburn  9425: =item create_list_elements()
                   9426: 
                   9427: =item create_form_ul()
                   9428: 
                   9429: =item startContentScreen() 
                   9430: 
                   9431: =item endContentScreen()
                   9432: 
                   9433: =item supplemental_base()
                   9434: 
                   9435: =item embedded_form_elems()
                   9436: 
                   9437: =item embedded_destination()
                   9438: 
                   9439: =item return_to_editor()
                   9440: 
                   9441: =item decompression_info()
                   9442: 
                   9443: =item decompression_phase_one()
                   9444: 
                   9445: =item decompression_phase_two()
                   9446: 
                   9447: =item remove_archive()
                   9448: 
                   9449: =item generate_admin_menu()
                   9450: 
                   9451: =item generate_edit_table()
                   9452: 
                   9453: =item editing_js()
                   9454: 
                   9455: =item history_tab_js()
                   9456: 
                   9457: =item inject_data_js()
                   9458: 
                   9459: =item dump_switchserver_js()
                   9460: 
1.485     raeburn  9461: =item resize_scrollbox_js()
1.484     raeburn  9462: 
                   9463: =item makedocslogform()
                   9464: 
1.485     raeburn  9465: =item makesimpleeditform()
                   9466: 
1.329     droeschl 9467: =back
                   9468: 
                   9469: =cut

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