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

1.329     droeschl    1: # The LearningOnline Network
                      2: # Documents
                      3: #
1.709   ! raeburn     4: # $Id: londocs.pm,v 1.708 2024/01/08 18:17:50 raeburn Exp $
1.329     droeschl    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: package Apache::londocs;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common :http);
                     33: use Apache::imsexport;
                     34: use Apache::lonnet;
                     35: use Apache::loncommon;
1.383     tempelho   36: use Apache::lonhtmlcommon;
1.329     droeschl   37: use LONCAPA::map();
                     38: use Apache::lonratedt();
                     39: use Apache::lonxml;
                     40: use Apache::lonclonecourse;
                     41: use Apache::lonnavmaps;
1.472     raeburn    42: use Apache::lonnavdisplay();
1.510     raeburn    43: use Apache::lonextresedit();
1.567     raeburn    44: use Apache::lontemplate();
                     45: use Apache::lonsimplepage();
1.606     raeburn    46: use Apache::lonhomework();
                     47: use Apache::lonpublisher();
1.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;
1.709   ! raeburn   105:     my @ids=&Apache::lonnet::current_machine_ids();
1.329     droeschl  106:     foreach my $key (keys(%env)) {
                    107: 	if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
                    108: 	    my $role=$1;
                    109: 	    my $realm=$2;
                    110: 	    my ($start,$end)=split(/\./,$env{$key});
                    111: 	    if (($start) && ($start>time)) { next; }
                    112: 	    if (($end) && (time>$end)) { next; }
                    113: 	    my ($ca,$cd);
                    114: 	    if ($1 eq 'au') {
                    115: 		$ca=$env{'user.name'};
                    116: 		$cd=$env{'user.domain'};
                    117: 	    } else {
                    118: 		($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
                    119: 	    }
                    120: 	    my $allowed=0;
                    121: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
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.709   ! raeburn   266:     $r->print(&Apache::loncommon::start_page('Copy uploaded content to Authoring Space',$js,$starthash)."\n".
        !           267:               &Apache::lonhtmlcommon::breadcrumbs('Copy uploaded 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'});
1.704     raeburn  1422:     my ($pasteitems,@pasteable,$same_institution,$checkedsameinst);
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.704     raeburn  1435:                 $canpaste,$nopaste,$othercrs,$areachange,$is_exttool,$toolcdom,
                   1436:                 $toolcnum,$marker);
1.538     raeburn  1437:             my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
                   1438:             if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
                   1439:                 $is_external = 1;
1.704     raeburn  1440:             } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                   1441:                 ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
1.598     raeburn  1442:                 $is_exttool = 1;
1.538     raeburn  1443:             }
                   1444:             if ($folder =~ /^supplemental/) {
                   1445:                 $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
                   1446:                 unless ($canpaste) {
                   1447:                     $nopaste = &mt('Paste into Supplemental Content unavailable.');
                   1448:                 }
                   1449:             } else {
                   1450:                 $canpaste = 1;
                   1451:             }
                   1452:             if ($canpaste) {
                   1453:                 if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
                   1454:                     my $srcdom = $1;
                   1455:                     my $srcnum = $2;
                   1456:                     my $rem = $3;
                   1457:                     if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
                   1458:                         $othercourse = 1;
                   1459:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596     raeburn  1460:                             $othercrs = '<br />'.&mt('(from another course)');
1.538     raeburn  1461:                         } else {
                   1462:                             $canpaste = 0;
                   1463:                             $nopaste = &mt('Paste from another course unavailable.'); 
                   1464:                         }
                   1465:                     }
                   1466:                     if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
                   1467:                         my $prefix = $1;
                   1468:                         $parent = $2;
                   1469:                         if ($folder !~ /^\Q$prefix\E/) {
                   1470:                             $areachange = 1;
                   1471:                         }
                   1472:                         $is_uploaded_map = 1;
1.492     raeburn  1473:                     }
1.597     raeburn  1474:                 } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627     raeburn  1475:                          ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596     raeburn  1476:                     if ($cid ne $env{'request.course.id'}) {
                   1477:                         my ($srcdom,$srcnum) = split(/_/,$cid);
                   1478:                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.704     raeburn  1479:                             if ($is_exttool) {
                   1480:                                 if ($toolcdom ne $coursedom) {
                   1481:                                     $canpaste = 0;
                   1482:                                     $nopaste = &mt('Paste from another domain unavailable.');
                   1483:                                 } elsif ($toolcnum ne $coursenum) {
                   1484:                                     my %toolsettings =
                   1485:                                         &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
                   1486:                                     my %tooltypes = &Apache::loncommon::usable_exttools();
                   1487:                                     if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                   1488:                                         (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                   1489:                                         $canpaste = 0;
                   1490:                                         $nopaste = &mt('Paste from another course unavailable.');
                   1491:                                     } elsif ($toolsettings{'id'} =~ /^c\d+$/) {
                   1492:                                         unless ($checkedsameinst) {
                   1493:                                             my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
                   1494:                                             my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   1495:                                             if ($intdom ne '') {
                   1496:                                                 my $internet_names =
                   1497:                                                     &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   1498:                                                 if (ref($internet_names) eq 'ARRAY') {
                   1499:                                                     if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   1500:                                                         $same_institution = 1;
                   1501:                                                     }
                   1502:                                                 }
                   1503:                                             }
                   1504:                                             $checkedsameinst = 1;
                   1505:                                         }
                   1506:                                         if ($same_institution) {
                   1507:                                             $othercrs = '<br />'.&mt('(from another course)');
                   1508:                                         } else {
                   1509:                                             $nopaste = &mt('Paste from another course unavailable.');
                   1510:                                         }
                   1511:                                     } else {
                   1512:                                         $othercrs = '<br />'.&mt('(from another course)');
                   1513:                                     }
                   1514:                                 }
1.627     raeburn  1515:                             }
1.596     raeburn  1516:                         } else {
                   1517:                             $canpaste = 0;
                   1518:                             $nopaste = &mt('Paste from another course unavailable.');
1.629     raeburn  1519:                         }
1.596     raeburn  1520:                     }
1.703     raeburn  1521:                 } elsif ($url =~ m{/res/($match_domain)/($match_username)/}) {
                   1522:                     my ($audom,$auname) = ($1,$2);
                   1523:                     unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
                   1524:                         if (&Apache::lonnet::is_course($audom,$auname)) {
                   1525:                             $canpaste = 0;
                   1526:                             $nopaste = &mt('Paste from another course unavailable.');
                   1527:                         }
                   1528:                     }
1.492     raeburn  1529:                 }
1.596     raeburn  1530:                 if ($canpaste) {
                   1531:                     push(@pasteable,$suffix);
1.629     raeburn  1532:                 }
1.538     raeburn  1533:             }
                   1534:             my $buffer;
1.627     raeburn  1535:             if ($is_external) {
1.538     raeburn  1536:                 $buffer = &mt('External Resource').': '.
                   1537:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
                   1538:                     &LONCAPA::map::qtescape($url).')';
1.627     raeburn  1539:             } elsif ($is_exttool) {
                   1540:                 $buffer = &mt('External Tool').': '.
                   1541:                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538     raeburn  1542:             } else {
                   1543:                 my $icon = &Apache::loncommon::icon($extension);
                   1544:                 if ($extension eq 'sequence' &&
                   1545:                     $url =~ m{/default_\d+\.sequence$}x) {
                   1546:                     $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
                   1547:                     $icon .= '/navmap.folder.closed.gif';
                   1548:                 }
1.589     raeburn  1549:                 my $title = $env{'docs.markedcopy_title_'.$suffix};
                   1550:                 if ($title eq '') {
                   1551:                     ($title) = ($url =~ m{/([^/]+)$});
                   1552:                 }
1.538     raeburn  1553:                 $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
                   1554:                           ': '.
                   1555:                           &Apache::loncommon::parse_supplemental_title(
1.589     raeburn  1556:                              &LONCAPA::map::qtescape($title));
1.538     raeburn  1557:             }
                   1558:             $pasteitems .= '<div class="LC_left_float">';
                   1559:             my ($options,$onclick);
                   1560:             if (($canpaste) && (!$areachange) && (!$othercourse) &&
                   1561:                 ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
                   1562:                 if (($is_uploaded_map) ||
                   1563:                     ($url =~ /(bulletinboard|smppg)$/) ||
                   1564:                     ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
                   1565:                     $options = &paste_options($suffix,$is_uploaded_map,$parent);
                   1566:                     $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
                   1567:                 }
                   1568:             }
                   1569:             $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
                   1570:             if ($nopaste) {
1.681     raeburn  1571:                  $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';   
1.538     raeburn  1572:             } else {
                   1573:                 if ($othercrs) {
                   1574:                     $pasteitems .= $othercrs;
                   1575:                 }
                   1576:                 if ($options) {
                   1577:                     $pasteitems .= $options;
1.492     raeburn  1578:                 }
                   1579:             }
1.538     raeburn  1580:             $pasteitems .= '</div>';
                   1581:         }
                   1582:     }
                   1583:     if ($pasteitems eq '') {
                   1584:         &Apache::lonnet::delenv('docs.markedcopies');
                   1585:     }
                   1586:     my ($pasteform,$form_start,$buttons,$form_end);
                   1587:     if ($pasteitems) {
                   1588:         $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541     raeburn  1589:         $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538     raeburn  1590:         if (@pasteable) {
1.575     raeburn  1591:             my $value = &mt('Paste to current folder');
                   1592:             if ($container eq 'page') {
                   1593:                 $value = &mt('Paste to current page');
                   1594:             } 
                   1595:             $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.('&nbsp;'x2);
                   1596:         }
                   1597:         $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.('&nbsp;'x2);
                   1598:         if ($clipboardcount > 1) {
                   1599:             $buttons .=
                   1600:                 '<span style="text-decoration:line-through">'.('&nbsp;'x20).'</span>'.('&nbsp;'x2).
                   1601:                 '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
                   1602:                 ('&nbsp;'x2).
                   1603:                 '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
                   1604:                 ('&nbsp;'x2);
1.492     raeburn  1605:         }
1.575     raeburn  1606:         $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
                   1607:                     '</form>';
1.538     raeburn  1608:     } else {
                   1609:         $pasteitems = &mt('Clipboard is empty');
1.488     raeburn  1610:     }
1.538     raeburn  1611:     $r->print($form_start
                   1612:              .'<fieldset>'
                   1613:              .'<legend>'.&mt('Clipboard').('&nbsp;' x2).$buttons.'</legend>'
                   1614:              .$pasteitems
                   1615:              .'</fieldset>'
                   1616:              .$form_end);
                   1617: }
                   1618: 
                   1619: sub paste_options {
                   1620:     my ($suffix,$is_uploaded_map,$parent) = @_;
                   1621:     my ($copytext,$movetext);
                   1622:     if ($is_uploaded_map) {
                   1623:         $copytext = &mt('Copy to new folder');
                   1624:         $movetext = &mt('Move old');
                   1625:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
                   1626:         $copytext = &mt('Copy to new board');
                   1627:         $movetext = &mt('Move (not posts)');
                   1628:     } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
                   1629:         $copytext = &mt('Copy to new page');
                   1630:         $movetext = &mt('Move');
1.533     raeburn  1631:     } else {
1.538     raeburn  1632:         $copytext = &mt('Copy to new file');
                   1633:         $movetext = &mt('Move');
                   1634:     }
                   1635:     my $output = '<br />'.
                   1636:                  '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
                   1637:                  '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.('&nbsp;'x 4).
                   1638:                  '<label>'.
                   1639:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
                   1640:                  $copytext.'</label></span>'.('&nbsp;'x2).' '.
                   1641:                  '<span class="LC_nobreak"><label>'.
                   1642:                  '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
                   1643:                  $movetext.'</label></span>';
                   1644:     if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
                   1645:         $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
                   1646:                    '</legend><table border="0">';
                   1647:         my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   1648:         my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
                   1649:         my $lastdir = $parent;
                   1650:         my %depths = (
                   1651:                        $lastdir => 0,
                   1652:                      );
                   1653:         my (%display,%deps);
                   1654:         for (my $i=0; $i<@pastemaps; $i++) {
                   1655:             ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
                   1656:             my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
                   1657:             my @subfolders = split(/,/,$subfolderstr);
                   1658:             $deps{$lastdir} = \@subfolders;
                   1659:             my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
                   1660:             my $depth = $depths{$lastdir} + 1;
                   1661:             my $offset = int($depth * 4);
                   1662:             my $indent = ('&nbsp;' x $offset);
                   1663:             for (my $j=0; $j<@subfolders; $j++) {
                   1664:                 $depths{$subfolders[$j]} = $depth;
                   1665:                 $display{$subfolders[$j]} =
                   1666:                     '<tr><td>'.$indent.$subfoldertitles[$j].'&nbsp;</td>'.
                   1667:                     '<td><label>'.
                   1668:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.('&nbsp;' x2).
                   1669:                     '<label>'.
                   1670:                     '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
                   1671:                     &mt('Move old').'</label>'.
                   1672:                     '</td></tr>';
                   1673:              }
1.492     raeburn  1674:         }
1.538     raeburn  1675:         &recurse_print(\$output,$parent,\%deps,\%display);
                   1676:         $output .= '</table></fieldset>';
1.329     droeschl 1677:     }
1.538     raeburn  1678:     $output .= '</div>';
                   1679:     return $output;
1.488     raeburn  1680: }
                   1681: 
1.492     raeburn  1682: sub recurse_print {
1.538     raeburn  1683:     my ($outputref,$dir,$deps,$display) = @_;
                   1684:     $$outputref .= $display->{$dir}."\n";
1.492     raeburn  1685:     if (ref($deps->{$dir}) eq 'ARRAY') {
                   1686:         foreach my $subdir (@{$deps->{$dir}}) {
1.538     raeburn  1687:             &recurse_print($outputref,$subdir,$deps,$display);
1.492     raeburn  1688:         }
                   1689:     }
                   1690: }
                   1691: 
1.488     raeburn  1692: sub supp_pasteable {
                   1693:     my ($url) = @_;
                   1694:     if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//}) ||
                   1695:         (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
                   1696:         ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
                   1697:         ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598     raeburn  1698:         ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626     raeburn  1699:         ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488     raeburn  1700:         return 1;
                   1701:     }
                   1702:     return;
1.329     droeschl 1703: }
                   1704: 
1.492     raeburn  1705: sub paste_popup_js {
1.594     damieng  1706:     my %html_js_lt = &Apache::lonlocal::texthash(
1.538     raeburn  1707:                                           show => 'Show Options',
                   1708:                                           hide => 'Hide Options',
1.594     damieng  1709:                                         );
                   1710:     my %js_lt = &Apache::lonlocal::texthash(
1.541     raeburn  1711:                                           none => 'No items selected from clipboard.',
1.492     raeburn  1712:                                         );
1.594     damieng  1713:     &html_escape(\%html_js_lt);
                   1714:     &js_escape(\%html_js_lt);
                   1715:     &js_escape(\%js_lt);
1.492     raeburn  1716:     return <<"END";
                   1717: 
1.538     raeburn  1718: function showPasteOptions(suffix) {
                   1719:     document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594     damieng  1720:     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  1721:     return;
                   1722: }
                   1723: 
1.538     raeburn  1724: function hidePasteOptions(suffix) {
                   1725:     document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594     damieng  1726:     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  1727:     return;
                   1728: }
                   1729: 
                   1730: function showOptions(caller,suffix) {
                   1731:     if (document.getElementById('pasteoptionstext_'+suffix)) {
                   1732:         if (caller.checked) {
1.594     damieng  1733:             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  1734:         } else {
                   1735:             document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
                   1736:         }
                   1737:         if (document.getElementById('pasteoptions_'+suffix)) {
                   1738:             document.getElementById('pasteoptions_'+suffix).style.display='none';
                   1739:         }
                   1740:     }
1.492     raeburn  1741:     return;
                   1742: }
                   1743: 
1.541     raeburn  1744: function validateClipboard() {
                   1745:     var numchk = 0;
                   1746:     if (document.pasteform.pasting.length > 1) {
                   1747:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1748:             if (document.pasteform.pasting[i].checked) {
                   1749:                 numchk ++;
                   1750:             }
                   1751:         }
                   1752:     } else {
                   1753:         if (document.pasteform.pasting.type == 'checkbox') {
                   1754:             if (document.pasteform.pasting.checked) {
                   1755:                 numchk ++; 
                   1756:             } 
                   1757:         }
                   1758:     }
                   1759:     if (numchk > 0) { 
                   1760:         return true;
                   1761:     } else {
1.594     damieng  1762:         alert("$js_lt{'none'}");
1.541     raeburn  1763:         return false;
                   1764:     }
                   1765: }
                   1766: 
1.575     raeburn  1767: function checkClipboard() {
                   1768:     if (document.pasteform.pasting.length > 1) {
                   1769:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1770:             document.pasteform.pasting[i].checked = true;
                   1771:         } 
                   1772:     }
                   1773:     return;
                   1774: }
                   1775: 
                   1776: function uncheckClipboard() {
                   1777:     if (document.pasteform.pasting.length >1) {
                   1778:         for (var i=0; i<document.pasteform.pasting.length; i++) {
                   1779:             document.pasteform.pasting[i].checked = false;
                   1780:         }
                   1781:     }
                   1782:     return;
                   1783: }
                   1784: 
1.492     raeburn  1785: END
                   1786: 
                   1787: }
                   1788: 
1.329     droeschl 1789: sub do_paste_from_buffer {
1.492     raeburn  1790:     my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329     droeschl 1791: 
1.538     raeburn  1792: # Array of items in paste buffer
                   1793:     my (@currpaste,%pastebuffer,%allerrors);
                   1794:     @currpaste = split(/,/,$env{'docs.markedcopies'});
                   1795: 
1.492     raeburn  1796: # Early out if paste buffer is empty
1.538     raeburn  1797:     if (@currpaste == 0) {
1.492     raeburn  1798:         return ();
1.538     raeburn  1799:     } 
                   1800:     map { $pastebuffer{$_} = 1; } @currpaste;
                   1801: 
                   1802: # Array of items selected items to paste
                   1803:     my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
                   1804: 
                   1805: # Early out if nothing selected to paste
                   1806:     if (@reqpaste == 0) {
                   1807:         return();
                   1808:     }
                   1809:     my @topaste;
                   1810:     foreach my $suffix (@reqpaste) {
                   1811:         next if ($suffix =~ /\D/);
                   1812:         next unless (exists($pastebuffer{$suffix}));
                   1813:         push(@topaste,$suffix);
                   1814:     }
                   1815: 
                   1816: # Early out if nothing available to paste
                   1817:     if (@topaste == 0) {
                   1818:         return();
1.329     droeschl 1819:     }
                   1820: 
1.704     raeburn  1821:     my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,
                   1822:         %othcrstool,%othcrsres,%duplicate,%prefixchg,%srcdom,%srcnum,%srcmapidx,
                   1823:         %marktomove,$save_err,$lockerrors,$allresult,%currcrsltitools,
                   1824:         %currltititles,$currltimax,$gotcrsltitools);
                   1825:     $currltimax = 0;
                   1826:     $gotcrsltitools = 0;
1.538     raeburn  1827:     foreach my $suffix (@topaste) {
                   1828:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596     raeburn  1829:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597     raeburn  1830:         my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix}); 
1.492     raeburn  1831: # Supplemental content may only include certain types of content
                   1832: # Early out if pasted content is not supported in Supplemental area
1.538     raeburn  1833:         if ($folder =~ /^supplemental/) {
                   1834:             unless (&supp_pasteable($url)) {
                   1835:                 $notinsupp{$suffix} = 1;
                   1836:                 next;
                   1837:             }
1.492     raeburn  1838:         }
1.538     raeburn  1839:         if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
                   1840:             my $srcd = $1;
                   1841:             my $srcn = $2;
1.492     raeburn  1842: # When paste buffer was populated using an active role in a different course
1.538     raeburn  1843: # check for mdc privilege in the course from which the resource was pasted
                   1844:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   1845:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   1846:                     $notincrs{$suffix} = 1;
                   1847:                     next;
                   1848:                 }
1.491     raeburn  1849:             }
1.538     raeburn  1850:             $srcdom{$suffix} = $srcd;
                   1851:             $srcnum{$suffix} = $srcn;
1.597     raeburn  1852:         } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632     raeburn  1853:                  ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
                   1854:                  ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596     raeburn  1855:             my ($srcd,$srcn) = split(/_/,$cid);
                   1856: # When paste buffer was populated using an active role in a different course
                   1857: # check for mdc privilege in the course from which the resource was pasted
                   1858:             if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   1859:                 unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                   1860:                     $notincrs{$suffix} = 1;
                   1861:                     next;
                   1862:                 }
                   1863:             }
1.632     raeburn  1864: # When buffer was populated using an active role in a different course
1.704     raeburn  1865: # disallow pasting of External Tool if course is in a different domain,
                   1866: # or if External Tool use is not permitted in this course.
                   1867:             if ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                   1868:                 my ($toolcdom,$toolcnum,$marker) = ($1,$2,$3);
                   1869:                 if ($toolcdom ne $coursedom) {
                   1870:                     $notindom{$suffix} = 1;
                   1871:                     next;
                   1872:                 } elsif ($toolcnum ne $coursenum) {
                   1873:                     my %toolsettings =
                   1874:                         &Apache::lonnet::dump('exttool_'.$marker,$toolcdom,$toolcnum);
                   1875:                     my %tooltypes = &Apache::loncommon::usable_exttools();
                   1876:                     if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                   1877:                         (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                   1878:                         $othcrstool{$suffix} = 1;
                   1879:                         next;
                   1880:                     }
                   1881:                     if ($toolsettings{'id'} =~ /^c\d+$/) {
                   1882:                         unless ($gotcrsltitools) {
                   1883:                             %currcrsltitools =
                   1884:                                 &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
                   1885:                             foreach my $item (sort(keys(%currcrsltitools))) {
                   1886:                                 if (ref($currcrsltitools{$item}) eq 'HASH') {
                   1887:                                     $currltimax ++;
                   1888:                                     if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
                   1889:                                         push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
                   1890:                                     } else {
                   1891:                                         $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
                   1892:                                     }
                   1893:                                 }
                   1894:                             }
                   1895:                             $gotcrsltitools = 1;
                   1896:                         }
                   1897:                     }
                   1898:                 }
1.627     raeburn  1899:             }
1.596     raeburn  1900:             $srcdom{$suffix} = $srcd;
                   1901:             $srcnum{$suffix} = $srcn;
1.703     raeburn  1902:         } elsif ($url =~ m{^/res/($match_domain)/($match_courseid)/}) {
                   1903:             my ($audom,$auname) = ($1,$2);
                   1904: # When buffer was populated using an active role in a different course
                   1905: # disallow pasting of published resources from Course Authoring Space
                   1906:             unless (($auname eq $coursenum) && ($audom eq $coursedom)) {
                   1907:                 if (&Apache::lonnet::is_course($audom,$auname)) {
                   1908:                     $othcrsres{$suffix} = 1;
                   1909:                     next;
                   1910:                 }
                   1911:             }
1.491     raeburn  1912:         }
1.597     raeburn  1913:         $srcmapidx{$suffix} = $mapidx;
1.538     raeburn  1914:         push(@dopaste,$suffix);
                   1915:         if ($url=~/\.(page|sequence)$/) {
                   1916:             $is_map{$suffix} = 1; 
                   1917:         }
                   1918:         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
                   1919:             my $oldprefix = $1;
1.492     raeburn  1920: # When pasting content from Main Content to Supplemental Content and vice versa 
                   1921: # URLs will contain different paths (which depend on whether pasted item is
1.597     raeburn  1922: # a folder/page or a document).
1.538     raeburn  1923:             if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
                   1924:                 $prefixchg{$suffix} = 'docstosupp';
                   1925:             } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
                   1926:                 $prefixchg{$suffix} = 'supptodocs';
                   1927:             }
1.491     raeburn  1928: 
1.492     raeburn  1929: # If pasting an uploaded map, get list of contained uploaded maps.
1.538     raeburn  1930:             if ($env{'docs.markedcopy_nested_'.$suffix}) {
                   1931:                 my @nested;
                   1932:                 my ($type) = ($oldprefix =~ /^(default|supplemental)/);
                   1933:                 my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
                   1934:                 my @deps = map { /\d+:([\d,]+$)/ } @items;
                   1935:                 foreach my $dep (@deps) {
                   1936:                     if ($dep =~ /,/) {
                   1937:                         push(@nested,split(/,/,$dep));
                   1938:                     } else {
                   1939:                         push(@nested,$dep);
                   1940:                     }
1.492     raeburn  1941:                 }
1.538     raeburn  1942:                 foreach my $item (@nested) {
                   1943:                     if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
                   1944:                         push(@{$marktomove{$suffix}},$type.'_'.$item);
                   1945:                     }
1.492     raeburn  1946:                 }
                   1947:             }
1.488     raeburn  1948:         }
                   1949:     }
                   1950: 
1.538     raeburn  1951: # Early out if nothing available to paste
                   1952:     if (@dopaste == 0) {
                   1953:         return ();
                   1954:     }
                   1955: 
                   1956: # Populate message hash and hashes used for main content <=> supplemental content
                   1957: # changes    
                   1958: 
                   1959:     %msgs = &Apache::lonlocal::texthash (
                   1960:                 notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
                   1961:                 notincrs  => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661     raeburn  1962:                 notindom  => 'Paste failed: Item is an external tool from a course in a different domain.',
1.704     raeburn  1963:                 othcrstool => 'Paste failed: Item is an external tool from a different course, for which use is not allowed in this course.',
1.703     raeburn  1964:                 othcrsres => 'Paste failed: Item is a course-authored resource from a different course',
1.538     raeburn  1965:                 duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
                   1966:             );
                   1967: 
                   1968:     %before = (
                   1969:                  docstosupp => {
                   1970:                                    map => 'default',
                   1971:                                    doc => 'docs',
                   1972:                                },
                   1973:                  supptodocs => {
                   1974:                                    map => 'supplemental',
                   1975:                                    doc => 'supplemental',
                   1976:                                },
                   1977:               );
                   1978: 
                   1979:     %after = (
                   1980:                  docstosupp => {
                   1981:                                    map => 'supplemental',
                   1982:                                    doc => 'supplemental'
                   1983:                                },
                   1984:                  supptodocs => {
                   1985:                                    map => 'default',
                   1986:                                    doc => 'docs',
                   1987:                                },
                   1988:              );
                   1989: 
                   1990: # Retrieve information about all course maps in main content area 
                   1991: 
                   1992:     my $allmaps = {};
1.704     raeburn  1993:     my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk,
                   1994:         @updatetoolsenc,$updatetoolscache,$checkedsameinst,
                   1995:         $same_institution);
1.538     raeburn  1996: 
                   1997: # Loop over the items to paste
                   1998:     foreach my $suffix (@dopaste) {
1.329     droeschl 1999: # Maps need to be copied first
1.538     raeburn  2000:         my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
                   2001:             %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597     raeburn  2002:             %newurls,%tomove,%resdatacopy);
1.538     raeburn  2003:         if (ref($marktomove{$suffix}) eq 'ARRAY') {
                   2004:             map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
                   2005:         }
                   2006:         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
                   2007:         my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596     raeburn  2008:         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); 
1.538     raeburn  2009:         my $oldurl = $url;
                   2010:         if ($is_map{$suffix}) {
1.491     raeburn  2011: # If pasting a map, check if map contains other maps
1.538     raeburn  2012:             my (%hierarchy,%titles);
1.660     raeburn  2013:             if (($folder =~ /^default/) && (!$donechk)) {
                   2014:                 $allmaps =
                   2015:                     &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                   2016:                                                          $env{"course.$env{'request.course.id'}.home"},
                   2017:                                                          $env{'request.course.id'});
                   2018:                 $donechk = 1;
                   2019:             }
1.627     raeburn  2020:             &contained_map_check($url,$folder,$coursenum,$coursedom,
                   2021:                                  \%removefrommap,\%removeparam,\%addedmaps,
                   2022:                                  \%hierarchy,\%titles,$allmaps);
1.538     raeburn  2023:             if ($url=~ m{^/uploaded/}) {
                   2024:                 my $newurl;
                   2025:                 unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   2026:                     ($newurl,my $error) = 
                   2027:                         &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
                   2028:                                         $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   2029:                                         \$title,$allmaps,\%newurls);
                   2030:                     if ($error) {
                   2031:                         $allerrors{$suffix} = $error;
                   2032:                         next;
                   2033:                     }
                   2034:                     if ($newurl ne '') {
                   2035:                         if ($newurl ne $url) {
                   2036:                             if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
                   2037:                                 $newsubdir{$url} = $1;
                   2038:                             }
                   2039:                             $mapchanges{$url} = 1;
1.492     raeburn  2040:                         }
1.538     raeburn  2041:                     }
                   2042:                 }
                   2043:                 if (($srcdom{$suffix} ne $coursedom) ||
                   2044:                     ($srcnum{$suffix} ne $coursenum) ||
                   2045:                     ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
                   2046:                     unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
                   2047:                                               $coursedom,$coursenum,$srcdom{$suffix},
                   2048:                                               $srcnum{$suffix},$allmaps,\%rewrites,
                   2049:                                               \%retitles,\%copies,\%dbcopies,
                   2050:                                               \%zombies,\%params,\%mapmoves,
                   2051:                                               \%mapchanges,\%tomove,\%newsubdir,
1.597     raeburn  2052:                                               \%newurls,\%resdatacopy)) {
1.538     raeburn  2053:                         $mapmoves{$url} = 1;
                   2054:                     }
                   2055:                     $url = $newurl;
                   2056:                 } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
                   2057:                     &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
                   2058:                                       $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                   2059:                                       $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
                   2060:                                       \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597     raeburn  2061:                                       \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538     raeburn  2062:                 }
                   2063:             } elsif ($url=~m {^/res/}) {
1.597     raeburn  2064: # published map can only exist once, so remove from paste buffer when done
1.538     raeburn  2065:                 push(@toclear,$suffix);
                   2066: # if pasting published map (main content area only) check map not already in course
                   2067:                 if ($folder =~ /^default/) {
                   2068:                     if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
                   2069:                         $duplicate{$suffix} = 1; 
                   2070:                         next;
1.492     raeburn  2071:                     }
1.491     raeburn  2072:                 }
                   2073:             }
1.538     raeburn  2074:         }
1.627     raeburn  2075:         if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538     raeburn  2076:             my $prefix = $1;
1.648     raeburn  2077:             my $fromothercrs;
1.538     raeburn  2078:             #need to copy the db contents to a new one, unless this is a move.
                   2079:             my %info = (
                   2080:                          src  => $url,
                   2081:                          cdom => $coursedom,
                   2082:                          cnum => $coursenum,
1.596     raeburn  2083:                        );
1.649     raeburn  2084:             if ($prefix eq 'ext.tool') {
1.655     raeburn  2085:                 if ($prefixchg{$suffix} eq 'docstosupp') {
1.649     raeburn  2086:                     $info{'delgradable'} = 1;
                   2087:                 }
                   2088:             }
1.596     raeburn  2089:             if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
                   2090:                 unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
                   2091:                     $fromothercrs = 1;
                   2092:                     $info{'cdom'} = $srcdom{$suffix};
                   2093:                     $info{'cnum'} = $srcnum{$suffix};
1.704     raeburn  2094:                     unless ($checkedsameinst) {
                   2095:                         my $primary_id = &Apache::lonnet::domain($coursedom,'primary');
                   2096:                         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   2097:                         if ($intdom ne '') {
                   2098:                             my $internet_names =
                   2099:                                 &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   2100:                             if (ref($internet_names) eq 'ARRAY') {
                   2101:                                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   2102:                                     $same_institution = 1;
                   2103:                                 }
                   2104:                             }
                   2105:                         }
                   2106:                         $checkedsameinst = 1;
                   2107:                     }
1.596     raeburn  2108:                 }
                   2109:             }
                   2110:             unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630     raeburn  2111:                 my (%lockerr,$msg);
1.538     raeburn  2112:                 my ($newurl,$result,$errtext) =
1.704     raeburn  2113:                     &dbcopy(\%info,$coursedom,$coursenum,\%lockerr,\%currltititles,
                   2114:                             \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.538     raeburn  2115:                 if ($result eq 'ok') {
                   2116:                     $url = $newurl;
                   2117:                     $title=&mt('Copy of').' '.$title;
                   2118:                 } else {
                   2119:                     if ($prefix eq 'smppg') {
                   2120:                         $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
                   2121:                     } elsif ($prefix eq 'bulletinboard') {
1.565     bisitz   2122:                         $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627     raeburn  2123:                     } elsif ($prefix eq 'ext.tool') {
                   2124:                         $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538     raeburn  2125:                     }
                   2126:                     $results{$suffix} = $result;
                   2127:                     $msgerrs{$suffix} = $msg;
                   2128:                     $lockerrs{$suffix} = $lockerr{$prefix}; 
                   2129:                     next;
                   2130: 	        }
                   2131:                 if ($lockerr{$prefix}) {
                   2132:                     $lockerrs{$suffix} = $lockerr{$prefix};  
1.491     raeburn  2133:                 }
1.489     raeburn  2134:             }
                   2135:         }
1.538     raeburn  2136:         $title = &LONCAPA::map::qtunescape($title);
                   2137:         my $ext='false';
                   2138:         if ($url=~m{^http(|s)://}) { $ext='true'; }
                   2139:         if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
                   2140:             if ($folder !~ /^supplemental/) {
                   2141:                 (undef,undef,$title) =
                   2142:                     &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
                   2143:             }
                   2144:         } else {
                   2145:             if ($folder=~/^supplemental/) {
                   2146:                 $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   2147:                        $env{'user.domain'}.'___&&&___'.$title;
1.491     raeburn  2148:             }
1.533     raeburn  2149:         }
1.491     raeburn  2150: 
                   2151: # For uploaded files (excluding pages/sequences) path in copied file is changed
                   2152: # if paste is from Main to Supplemental (or vice versa), or if pasting between
                   2153: # courses.
                   2154: 
1.538     raeburn  2155:         unless ($is_map{$suffix}) {
                   2156:             my $newidx;
1.492     raeburn  2157: # Now insert the URL at the bottom
1.538     raeburn  2158:             $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   2159:             if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
                   2160:                 my $relpath = $1;
                   2161:                 if ($relpath ne '') {
                   2162:                     my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
                   2163:                     my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
                   2164:                     my $newprefix = $newloc;
                   2165:                     if ($newloc eq 'default') {
                   2166:                         $newprefix = 'docs';
                   2167:                     }
                   2168:                     if ($newdocsdir eq '') {
                   2169:                         $newdocsdir = 'default';
                   2170:                     }
1.630     raeburn  2171:                     if (($prefixchg{$suffix}) ||
                   2172:                         ($srcdom{$suffix} ne $coursedom) ||
1.538     raeburn  2173:                         ($srcnum{$suffix} ne $coursenum) ||
                   2174:                         ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
                   2175:                         my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
                   2176:                         $url =
                   2177:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
                   2178:                                                                &Apache::lonnet::getfile($oldurl));
                   2179:                         if ($url eq '/adm/notfound.html') {
                   2180:                             $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
                   2181:                             next;
                   2182:                         } else {
                   2183:                             my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
                   2184:                             $newsubpath =~ s{/+$}{/};
                   2185:                             $docmoves{$oldurl} = $newsubpath;
                   2186:                         }
1.491     raeburn  2187:                     }
                   2188:                 }
1.597     raeburn  2189:             } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   2190:                 my $template = $1;
                   2191:                 if ($newidx) {
                   2192:                     &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
                   2193:                                           $coursedom,$coursenum,$template,$newidx,"$folder.$container");
                   2194:                 }
1.649     raeburn  2195:             } elsif ($url =~ /ext\.tool$/) {
1.655     raeburn  2196:                 if (($newidx) && ($folder=~/^default/)) {
1.649     raeburn  2197:                     my $marker = (split(m{/},$url))[4];
                   2198:                     my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
                   2199:                     my $val = 'no';
                   2200:                     if ($toolsettings{'gradable'}) {
                   2201:                         $val = 'yes';
                   2202:                     }
                   2203:                     &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
                   2204:                                                   'string_yesno');
                   2205:                     &remember_parms($newidx,'gradable','set',$val);
                   2206:                 }
1.491     raeburn  2207:             }
1.538     raeburn  2208:             $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   2209:                                               ':'.$ext.':normal:res';
                   2210:             push(@LONCAPA::map::order,$newidx);
                   2211: # Store the result
                   2212:             my ($errtext,$fatal) =
                   2213:                 &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   2214:             if ($fatal) {
                   2215:                 $save_err .= $errtext;
                   2216:                 $allresult = 'fail';
                   2217:             }
1.488     raeburn  2218:         }
1.538     raeburn  2219: 
1.597     raeburn  2220: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
                   2221: # resourcedata for simpleproblems copied from another course 
1.538     raeburn  2222:         unless ($allresult eq 'fail') {
                   2223:             my %updated = (
                   2224:                             rewrites      => \%rewrites,
                   2225:                             zombies       => \%zombies,
                   2226:                             removefrommap => \%removefrommap,
                   2227:                             removeparam   => \%removeparam,
                   2228:                             dbcopies      => \%dbcopies,
1.597     raeburn  2229:                             resdatacopy   => \%resdatacopy,
1.538     raeburn  2230:                             retitles      => \%retitles,
                   2231:                           );
                   2232:             my %info = (
                   2233:                            newsubdir => \%newsubdir,
                   2234:                            params    => \%params,
                   2235:                        );
                   2236:             if ($prefixchg{$suffix}) {
                   2237:                 $info{'before'} = $before{$prefixchg{$suffix}};
                   2238:                 $info{'after'} = $after{$prefixchg{$suffix}};
                   2239:             }
                   2240:             my %moves = (
                   2241:                            copies   => \%copies,
                   2242:                            docmoves => \%docmoves,
                   2243:                            mapmoves => \%mapmoves,
                   2244:                         );
                   2245:             (my $result,$msgs{$suffix},my $lockerror) =
                   2246:                 &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
                   2247:                               \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
                   2248:                               $url,'paste');
                   2249:             $lockerrors .= $lockerror;
                   2250:             if ($result eq 'ok') {
                   2251:                 if ($is_map{$suffix}) {
                   2252:                     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   2253:                                                     $folder.'.'.$container);
                   2254:                     if ($fatal) {
                   2255:                         $allresult = 'failread';
                   2256:                     } else {
                   2257:                         if ($#LONCAPA::map::order<1) {
                   2258:                             my $idx=&LONCAPA::map::getresidx();
                   2259:                             if ($idx<=0) { $idx=1; }
                   2260:                             $LONCAPA::map::order[0]=$idx;
                   2261:                             $LONCAPA::map::resources[$idx]='';
                   2262:                         }
                   2263:                         my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   2264:                         $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   2265:                                                           ':'.$ext.':normal:res';
                   2266:                         push(@LONCAPA::map::order,$newidx);
1.492     raeburn  2267: 
                   2268: # Store the result
1.538     raeburn  2269:                         my ($errtext,$fatal) = 
                   2270:                             &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   2271:                         if ($fatal) {
                   2272:                             $save_err .= $errtext;
                   2273:                             $allresult = 'failstore';
                   2274:                         }
                   2275:                     } 
                   2276:                 }
                   2277:                 if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
                   2278:                      push(@toclear,$suffix);
                   2279:                 }
                   2280:             }
1.492     raeburn  2281:         }
                   2282:     }
1.704     raeburn  2283:     if (($updatetoolscache) || (@updatetoolsenc)) {
                   2284:         &update_ltitools_caches($coursedom,$coursenum,$updatetoolscache,
                   2285:                                 \@updatetoolsenc);
                   2286:     }
1.538     raeburn  2287:     &clear_from_buffer(\@toclear,\@currpaste);
                   2288:     my $msgsarray;
                   2289:     foreach my $suffix (keys(%msgs)) {
                   2290:          if (ref($msgs{$suffix}) eq 'ARRAY') {
                   2291:              $msgsarray .= join(',',@{$msgs{$suffix}});
                   2292:          }
                   2293:     }
                   2294:     return ($allresult,$save_err,$msgsarray,$lockerrors);
                   2295: }
1.533     raeburn  2296: 
1.538     raeburn  2297: sub do_buffer_empty {
                   2298:     my @currpaste = split(/,/,$env{'docs.markedcopies'});
                   2299:     if (@currpaste == 0) {
                   2300:         return &mt('Clipboard is already empty');
                   2301:     }
                   2302:     my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
                   2303:     if (@toclear == 0) {
                   2304:         return &mt('Nothing selected to clear from clipboard');
                   2305:     }
                   2306:     my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
                   2307:     if ($numdel) {
                   2308:         return &mt('[quant,_1,item] cleared from clipboard',$numdel);
                   2309:     } else {
                   2310:         return &mt('Clipboard unchanged');
1.492     raeburn  2311:     }
1.538     raeburn  2312:     return;
                   2313: }
                   2314: 
                   2315: sub clear_from_buffer {
                   2316:     my ($toclear,$currpaste) = @_;
                   2317:     return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
                   2318:     my %pastebuffer;
                   2319:     map { $pastebuffer{$_} = 1; } @{$currpaste};
                   2320:     my $numdel = 0;
                   2321:     foreach my $suffix (@{$toclear}) {
                   2322:         next if ($suffix =~ /\D/);
                   2323:         next unless (exists($pastebuffer{$suffix}));
                   2324:         my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
                   2325:         if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
                   2326:             delete($pastebuffer{$suffix});
                   2327:             $numdel ++;
                   2328:         }
                   2329:     }
                   2330:     my $newbuffer = join(',',sort(keys(%pastebuffer)));
                   2331:     &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
                   2332:     return $numdel;
1.492     raeburn  2333: }
                   2334: 
1.704     raeburn  2335: sub update_ltitools_caches {
                   2336:     my ($coursedom,$coursenum,$updatetoolscache,$updatetoolsenc) = @_;
                   2337:     my $hashid=$coursedom.'_'.$coursenum;
                   2338:     if ($updatetoolscache) {
                   2339:         &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
                   2340:     }
                   2341:     if ((ref($updatetoolsenc) eq 'ARRAY') &&
                   2342:         (@{$updatetoolsenc})) {
                   2343:         my @ids=&Apache::lonnet::current_machine_ids();
                   2344:         my $updatedone;
                   2345:         foreach my $lonhost (@{$updatetoolsenc}) {
                   2346:             if (grep(/^\Q$lonhost\E$/,@ids)) {
                   2347:                 unless ($updatedone) {
                   2348:                     &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
                   2349:                 }
                   2350:                 $updatedone = 1;
                   2351:             } else {
                   2352:                 &Apache::lonnet::remote_devalidate_cache($lonhost,["crsltitoolsenc:$hashid"]);
                   2353:             }
                   2354:         }
                   2355:     }
                   2356:     return;
                   2357: }
                   2358: 
1.492     raeburn  2359: sub get_newmap_url {
                   2360:     my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
                   2361:         $titleref,$allmaps,$newurls) = @_;
                   2362:     my $newurl;
                   2363:     if ($url=~ m{^/uploaded/}) {
                   2364:         $$titleref=&mt('Copy of').' '.$$titleref;
                   2365:     }
                   2366:     my $now = time;
                   2367:     my $suffix=$$.int(rand(100)).$now;
                   2368:     my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
                   2369:     if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
                   2370:         my $path = $1;
                   2371:         my $prefix = $2;
                   2372:         my $ancestor = $3;
                   2373:         if (length($ancestor) > 10) {
                   2374:             $ancestor = substr($ancestor,-10,10);
                   2375:         }
                   2376:         my $newid;
                   2377:         if ($prefixchg) {
                   2378:             if ($folder =~ /^supplemental/) {
                   2379:                 $prefix =~ s/^default/supplemental/;
                   2380:             } else {
                   2381:                 $prefix =~ s/^supplemental/default/;
                   2382:             }
                   2383:         }
                   2384:         if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   2385:             $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   2386:         } else {
                   2387:             $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
                   2388:         }
                   2389:         my $counter = 0;
                   2390:         my $is_unique = &uniqueness_check($newurl);
                   2391:         if ($folder =~ /^default/) {
                   2392:             if ($allmaps->{$newurl}) {
                   2393:                 $is_unique = 0;
                   2394:             }
                   2395:         }
                   2396:         while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
                   2397:             $counter ++;
                   2398:             $suffix ++;
                   2399:             if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
                   2400:                 $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
                   2401:             } else {
                   2402:                 $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
                   2403:             }
                   2404:             $is_unique = &uniqueness_check($newurl);
                   2405:         }
                   2406:         if ($is_unique) {
                   2407:             $newurls->{$newurl} = 1;
                   2408:         } else {
                   2409:             if ($url=~/\.page$/) {
                   2410:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
                   2411:             } else {
                   2412:                 return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
                   2413:             }
                   2414:         }
1.329     droeschl 2415:     }
1.492     raeburn  2416:     return ($newurl);
1.329     droeschl 2417: }
                   2418: 
1.488     raeburn  2419: sub dbcopy {
1.704     raeburn  2420:     my ($dbref,$coursedom,$coursenum,$lockerrorsref,$currltititles,
                   2421:         $currltimax,$updatetoolsenc,$updatetoolscache,$same_institution) = @_;
1.533     raeburn  2422:     my ($url,$result,$errtext);
                   2423:     if (ref($dbref) eq 'HASH') {
1.596     raeburn  2424:         $url = $dbref->{'src'};
1.627     raeburn  2425:         if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533     raeburn  2426:             my $prefix = $1;
1.627     raeburn  2427:             if ($prefix eq 'ext.tool') {
                   2428:                 $prefix = 'exttool';
                   2429:             }
1.533     raeburn  2430:             if (($dbref->{'cdom'} =~ /^$match_domain$/) && 
                   2431:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   2432:                 my $db_name;
                   2433:                 my $marker = (split(m{/},$url))[4];
                   2434:                 $marker=~s/\D//g;
                   2435:                 if ($dbref->{'src'} =~ m{/smppg$}) {
                   2436:                     $db_name =
                   2437:                         &Apache::lonsimplepage::get_db_name($url,$marker,
                   2438:                                                             $dbref->{'cdom'},
                   2439:                                                             $dbref->{'cnum'});
1.627     raeburn  2440:                 } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
                   2441:                     $db_name = 'exttool_'.$marker;
1.533     raeburn  2442:                 } else {
                   2443:                     $db_name = 'bulletinpage_'.$marker;
                   2444:                 }
                   2445:                 my ($suffix,$freedlock,$error) =
                   2446:                     &Apache::lonnet::get_timebased_id($prefix,'num','templated',
                   2447:                                                       $coursedom,$coursenum,
                   2448:                                                       'concat');
                   2449:                 if (!$suffix) {
                   2450:                     if ($prefix eq 'smppg') {
                   2451:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631     raeburn  2452:                     } elsif ($prefix eq 'exttool') {
                   2453:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533     raeburn  2454:                     } else {
1.565     bisitz   2455:                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533     raeburn  2456:                     }
                   2457:                     if ($error) {
                   2458:                         $errtext .= '<br />'.$error;
                   2459:                     }
                   2460:                 } else {
                   2461:                     #need to copy the db contents to a new one.
                   2462:                     my %contents=&Apache::lonnet::dump($db_name,
                   2463:                                                        $dbref->{'cdom'},
                   2464:                                                        $dbref->{'cnum'});
1.704     raeburn  2465:                     my ($toolcopyerror,$toolpassback,$toolroster,%toolinfo,$oldtoolid,$defincrs);
                   2466:                     if ($url eq '/adm/'.$dbref->{'cdom'}.'/'.$dbref->{'cnum'}."/$marker/ext.tool") {
                   2467:                         if ($contents{'id'} =~ /^(|c)(\d+)$/) {
                   2468:                             $oldtoolid = $2;
                   2469:                             if ($1 eq 'c') {
                   2470:                                 $defincrs = 1;
                   2471:                                 %toolinfo =
                   2472:                                     &Apache::lonnet::get('ltitools',[$oldtoolid],$dbref->{'cdom'},$dbref->{'cnum'});
                   2473:                             } else {
                   2474:                                 %toolinfo= &Apache::lonnet::get_domain_lti($dbref->{'cdom'},'consumer');
                   2475:                             }
                   2476:                             if (ref($toolinfo{$oldtoolid}) eq 'HASH') {
                   2477:                                 if ($toolinfo{$oldtoolid}{'passback'}) {
                   2478:                                     $toolpassback = 1;
                   2479:                                 }
                   2480:                                 if ($toolinfo{$oldtoolid}{'roster'}) {
                   2481:                                     $toolroster = 1;
                   2482:                                 }
                   2483:                             } else {
                   2484:                                 $toolcopyerror = 1;
                   2485:                                 $errtext = &mt('Could not retrieve original settings for pasted external tool.');
                   2486:                             }
                   2487:                         }
                   2488:                         unless (($dbref->{'cnum'} eq $coursenum) && ($dbref->{'cdom'} eq $coursedom)) {
                   2489:                             $url = "/adm/$coursedom/$coursenum/$marker/ext.tool";
                   2490:                             if ($contents{'crstitle'} ne '') {
                   2491:                                 $contents{'crstitle'} = $env{'course.'.$coursedom.'_'.$coursenum.'.description'};
                   2492:                             }
                   2493:                             if (($defincrs) && (!$toolcopyerror)) {
                   2494:                                 my %newtool;
                   2495:                                 my $oldcdom = $dbref->{'cdom'};
                   2496:                                 my $oldcnum = $dbref->{'cnum'};
                   2497:                                 my $title = $toolinfo{$oldtoolid}{'title'};
                   2498:                                 if (ref($currltititles) eq 'HASH') {
                   2499:                                     if (exists($currltititles->{$title})) {
                   2500:                                         $title .= ' (copied from another course)';
                   2501:                                     }
                   2502:                                 }
                   2503:                                 my ($newid,$iderror) =
                   2504:                                     &Apache::lonnet::get_ltitools_id('course',$coursedom,$coursenum,$title);
                   2505:                                 if ($newid =~ /^\d+$/) {
                   2506:                                     %{$newtool{$newid}} = %{$toolinfo{$oldtoolid}};
                   2507:                                     $newtool{$newid}{'title'} = $title;
                   2508:                                     if (ref($currltimax)) {
                   2509:                                         $newtool{$newid}{'order'} = $$currltimax;
                   2510:                                     }
                   2511:                                     if ($newtool{$newid}{'image'} =~ m{^\Q/uploaded/$oldcdom/$oldcnum/toollogo/$oldtoolid/\E([^/]+)$}) {
                   2512:                                         my $fname = $1;
                   2513:                                         my $content = &Apache::lonnet::getfile($newtool{$newid}{'image'});
                   2514:                                         if ($content eq '-1') {
                   2515:                                             delete($newtool{$newid}{'image'});
                   2516:                                         } else {
                   2517:                                             $env{'form.'.$suffix.'.image'} = $content;
                   2518:                                             my $newlogo =
                   2519:                                                 &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.image',"toollogo/$newid/$fname");
                   2520:                                             delete($env{'form.'.$suffix.'.image'});
                   2521:                                             if ($newlogo =~ m{^/uploaded/}) {
                   2522:                                                 $newtool{$newid}{'image'} = $newlogo;
                   2523:                                             } else {
                   2524:                                                 delete($newtool{$newid}{'image'});
                   2525:                                             }
                   2526:                                         }
                   2527:                                     }
                   2528:                                     my $newusable;
                   2529:                                     if ($same_institution) {
                   2530:                                         my %oldtoolsenc = &Apache::lonnet::eget('nohist_toolsenc',[$oldtoolid],$oldcdom,$oldcnum);
                   2531:                                         if (ref($oldtoolsenc{$oldtoolid}) eq 'HASH') {
                   2532:                                             my %newtoolsenc;
                   2533:                                             %{$newtoolsenc{$newid}} = %{$oldtoolsenc{$oldtoolid}};
                   2534:                                             my $putres = &Apache::lonnet::put('nohist_toolsenc',\%newtoolsenc,$coursedom,$coursenum,1);
                   2535:                                             if ($putres eq 'ok') {
                   2536:                                                 if (ref($updatetoolsenc) eq 'ARRAY') {
                   2537:                                                     my $newhome = &Apache::lonnet::homeserver($coursenum,$coursedom);
                   2538:                                                     unless (grep(/^\Q$newhome\E$/,@{$updatetoolsenc})) {
                   2539:                                                         push(@{$updatetoolsenc},$newhome);
                   2540:                                                     }
                   2541:                                                 }
                   2542:                                                 $newusable = 1;
                   2543:                                             }
                   2544:                                         }
                   2545:                                     }
                   2546:                                     if ($newtool{$newid}{'usable'}) {
                   2547:                                         unless ($newusable) {
                   2548:                                             delete($newtool{$newid}{'usable'});
                   2549:                                         }
                   2550:                                     }
                   2551:                                     my $putres = &Apache::lonnet::put('ltitools',\%newtool,$coursedom,$coursenum);
                   2552:                                     if ($putres eq 'ok') {
                   2553:                                         $contents{'id'} = "c$newid";
                   2554:                                         if (ref($updatetoolscache)) {
                   2555:                                             $$updatetoolscache ++;
                   2556:                                         }
                   2557:                                         if (ref($currltititles->{$title}) eq 'ARRAY') {
                   2558:                                             push(@{$currltititles->{$title}},$newid);
                   2559:                                         } else {
                   2560:                                             $currltititles->{$title} = [$newid];
                   2561:                                         }
                   2562:                                         if (ref($currltimax)) {
                   2563:                                             $$currltimax ++;
                   2564:                                         }
                   2565:                                     } else {
                   2566:                                         $toolcopyerror = 1;
                   2567:                                         $errtext = &mt('Unable to save external tool definition in Course Settings.');
                   2568:                                     }
                   2569:                                 } else {
                   2570:                                     $toolcopyerror = 1;
                   2571:                                     $errtext = &mt('Unable to retrieve new tool ID when adding external tool definition to Course Settings.');
                   2572:                                 }
                   2573:                             }
                   2574:                         }
                   2575:                     }
1.533     raeburn  2576:                     if (exists($contents{'uploaded.photourl'})) {
                   2577:                         my $photo = $contents{'uploaded.photourl'};
                   2578:                         my ($subdir,$fname) =
                   2579:                             ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596     raeburn  2580:                         my $newphoto;
1.533     raeburn  2581:                         if ($fname ne '') {
                   2582:                             my $content = &Apache::lonnet::getfile($photo);
                   2583:                             unless ($content eq '-1') {
                   2584:                                 $env{'form.'.$suffix.'.photourl'} = $content;
                   2585:                                 $newphoto = 
                   2586:                                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
                   2587:                                 delete($env{'form.'.$suffix.'.photourl'});
                   2588:                             }
                   2589:                         }
                   2590:                         if ($newphoto =~ m{^/uploaded/}) {
                   2591:                             $contents{'uploaded.photourl'} = $newphoto;
                   2592:                         }
                   2593:                     }
                   2594:                     $db_name =~ s{_\d*$ }{_$suffix}x;
1.704     raeburn  2595:                     if ($prefix eq 'exttool') {
                   2596:                         unless ($toolcopyerror) {
                   2597:                             foreach my $key ('oldgradesecret','gradesecret','gradesecretdate','oldrostersecret','rostersecret','rostersecretdate') {
                   2598:                                 if (exists($contents{$key})) {
                   2599:                                     delete($contents{$key});
                   2600:                                 }
                   2601:                             }
                   2602:                             if ($dbref->{'delgradable'}) {
                   2603:                                 if (exists($contents{'gradable'})) {
                   2604:                                     delete($contents{'gradable'});
                   2605:                                 }
                   2606:                             }
                   2607:                             if ($toolpassback) {
                   2608:                                 if ($contents{'gradable'}) {
                   2609:                                     my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                   2610:                                     $contents{'gradesecret'} = $gradesecret;
                   2611:                                     $contents{'gradesecretdate'} = time;
                   2612:                                 }
                   2613:                             }
                   2614:                             if ($toolroster) {
                   2615:                                 my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                   2616:                                 $contents{'rostersecret'} = $rostersecret;
                   2617:                                 $contents{'rostersecretdate'} = time;
                   2618:                             }
                   2619:                         }
1.649     raeburn  2620:                     }
1.704     raeburn  2621:                     if (($prefix eq 'exttool') && ($toolcopyerror)) {
                   2622:                         $result = 'error';
                   2623:                     } else {
                   2624:                         $result=&Apache::lonnet::put($db_name,\%contents,
                   2625:                                                      $coursedom,$coursenum);
                   2626:                         if ($result eq 'ok') {
                   2627:                             $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
                   2628:                         }
1.533     raeburn  2629:                     }
                   2630:                 }
                   2631:                 if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559     raeburn  2632:                     $lockerrorsref->{$prefix} =
1.533     raeburn  2633:                         '<div class="LC_error">'.
                   2634:                         &mt('There was a problem removing a lockfile.');
                   2635:                     if ($prefix eq 'smppg') {
1.560     raeburn  2636:                         $lockerrorsref->{$prefix} .=
1.559     raeburn  2637:                             ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627     raeburn  2638:                     } elsif ($prefix eq 'exttool') {
                   2639:                         $lockerrorsref->{$prefix} .=
                   2640:                             ' '.&mt('This will prevent addition of more external tools to this course.');
1.533     raeburn  2641:                     } else {
1.565     bisitz   2642:                         $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  2643:                     }
1.560     raeburn  2644:                     $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   2645:                                                      '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
                   2646:                                                  '</div>';
1.533     raeburn  2647:                 }
                   2648:             }
                   2649:         } elsif ($url =~ m{/syllabus$}) {
                   2650:             if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
                   2651:                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                   2652:                 if (($dbref->{'cdom'} ne $coursedom) ||
                   2653:                     ($dbref->{'cnum'} ne $coursenum)) {
                   2654:                     my %contents=&Apache::lonnet::dump('syllabus',
                   2655:                                                        $dbref->{'cdom'},
                   2656:                                                        $dbref->{'cnum'});
                   2657:                     $result=&Apache::lonnet::put('syllabus',\%contents,
                   2658:                                                  $coursedom,$coursenum);
                   2659:                 }
                   2660:             }
1.488     raeburn  2661:         }
                   2662:     }
1.533     raeburn  2663:     return ($url,$result,$errtext);
1.488     raeburn  2664: }
                   2665: 
1.597     raeburn  2666: sub copy_templated_files {
                   2667:     my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
                   2668:     my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
                   2669:     my $srccontainer = 'sequence';
                   2670:     if ($srcwaspage) {
                   2671:         $srccontainer = 'page';
                   2672:     }
                   2673:     my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
                   2674:                   '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
                   2675:     my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
                   2676:     my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
                   2677:     my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
                   2678:                   $template.'.problem';
                   2679:     my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
                   2680:     if ($template eq 'simpleproblem') {
                   2681:         $srcprefix .= '.0.';
                   2682:         my $weightprefix = $newprefix;
                   2683:         $newprefix .= '.0.';
                   2684:         my @simpleprobqtypes = qw(radio option string essay numerical);
                   2685:         my $qtype=$srcparms{$srcprefix.'questiontype'};
                   2686:         if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665     raeburn  2687:             my %newdata = (
                   2688:                 $newprefix.'questiontype' => $qtype,
                   2689:             );
1.597     raeburn  2690:             foreach my $type (@simpleprobqtypes) {
                   2691:                 if ($type eq $qtype) {
                   2692:                     $newdata{"$weightprefix.$type.weight"}=1;
                   2693:                 } else {
                   2694:                     $newdata{"$weightprefix.$type.weight"}=0;
                   2695:                 }
                   2696:             }
                   2697:             $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
                   2698:             $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
                   2699:             $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
                   2700:             if ($qtype eq 'numerical') {
                   2701:                 $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
                   2702:                 $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
                   2703:                 $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
                   2704:                 $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
                   2705:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   2706:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   2707:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   2708:                     unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   2709:                         if ($maxfoils<=0) { $maxfoils=10; }
                   2710:                             my $randomize=$srcparms{$srcprefix.'randomize'};
                   2711:                             unless (defined($randomize)) { $randomize='yes'; }
                   2712:                             unless ($randomize eq 'no') { $randomize='yes'; }
                   2713:                             $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   2714:                             $newdata{$newprefix.'randomize'} = $randomize;
                   2715:                             if ($qtype eq 'option') {
                   2716:                                 $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   2717:                             }
                   2718:                             for (my $i=1; $i<=10; $i++) {
                   2719:                                 $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   2720:                                 $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   2721:                                 $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   2722:                             }
                   2723: 
                   2724:             } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   2725:                 my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   2726:                 unless (defined($maxfoils)) { $maxfoils=10; }
                   2727:                 unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   2728:                 if ($maxfoils<=0) { $maxfoils=10; }
                   2729:                 my $randomize=$srcparms{$srcprefix.'randomize'};
                   2730:                 unless (defined($randomize)) { $randomize='yes'; }
                   2731:                 unless ($randomize eq 'no') { $randomize='yes'; }
                   2732:                 $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   2733:                 $newdata{$newprefix.'randomize'} = $randomize;
                   2734:                 if ($qtype eq 'option') {
                   2735:                     $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   2736:                 }
                   2737:                 for (my $i=1; $i<=10; $i++) {
                   2738:                     $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                   2739:                     $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                   2740:                     $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   2741:                 }
                   2742:             } elsif ($qtype eq 'string') {
                   2743:                 $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
                   2744:                 $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
                   2745:             }
                   2746:             if (keys(%newdata)) {
                   2747:                 my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
                   2748:                                                    $coursenum);
                   2749:                 if ($putres eq 'ok') {
                   2750:                     &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
                   2751:                 }
                   2752:             }
                   2753:         }
                   2754:     }
                   2755: }
                   2756: 
1.329     droeschl 2757: sub uniqueness_check {
                   2758:     my ($newurl) = @_;
                   2759:     my $unique = 1;
                   2760:     foreach my $res (@LONCAPA::map::order) {
                   2761:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   2762:         $url=&LONCAPA::map::qtescape($url);
                   2763:         if ($newurl eq $url) {
                   2764:             $unique = 0;
1.344     bisitz   2765:             last;
1.329     droeschl 2766:         }
                   2767:     }
                   2768:     return $unique;
                   2769: }
                   2770: 
1.488     raeburn  2771: sub contained_map_check {
1.627     raeburn  2772:     my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
                   2773:         $hierarchy,$titles,$allmaps) = @_;
1.488     raeburn  2774:     my $content = &Apache::lonnet::getfile($url);
                   2775:     unless ($content eq '-1') {
                   2776:         my $parser = HTML::TokeParser->new(\$content);
                   2777:         $parser->attr_encoded(1);
                   2778:         while (my $token = $parser->get_token) {
                   2779:             next if ($token->[0] ne 'S');
                   2780:             if ($token->[1] eq 'resource') {
                   2781:                 next if ($token->[2]->{'type'} eq 'zombie');
                   2782:                 my $ressrc = $token->[2]->{'src'};
1.704     raeburn  2783:                 if ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
                   2784:                     my ($srcdom,$srcnum,$marker) = ($1,$2,$3);
1.627     raeburn  2785:                     unless ($srcdom eq $coursedom) {
                   2786:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2787:                         next;
                   2788:                     }
1.704     raeburn  2789:                     unless ($srcnum eq $coursenum) {
                   2790:                         my %toolsettings =
                   2791:                             &Apache::lonnet::dump('exttool_'.$marker,$srcdom,$srcnum);
                   2792:                         my %tooltypes = &Apache::loncommon::usable_exttools();
                   2793:                         if ((($toolsettings{'id'} =~ /^c\d+$/) && (!$tooltypes{'crs'})) ||
                   2794:                             (($toolsettings{'id'} =~ /^\d+$/) && (!$tooltypes{'dom'}))) {
                   2795:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2796:                             next;
                   2797:                         }
                   2798:                     }
1.627     raeburn  2799:                 } elsif ($folder =~ /^supplemental/) {
1.488     raeburn  2800:                     unless (&supp_pasteable($ressrc)) {
1.492     raeburn  2801:                         $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488     raeburn  2802:                         next;
                   2803:                     }
                   2804:                 }
1.703     raeburn  2805:                 if ($ressrc =~ m{^/res/($match_domain)/($match_courseid)/}) {
                   2806:                     my ($srcdom,$srcnum) = ($1,$2);
                   2807:                     unless (($srcnum eq $coursenum) && ($srcdom eq $coursedom)) {
                   2808:                         if (&Apache::lonnet::is_course($srcdom,$srcnum)) {
                   2809:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2810:                             next;
                   2811:                         }
                   2812:                     }
                   2813:                 }
1.492     raeburn  2814:                 if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
                   2815:                     if ($1 eq 'uploaded') {
                   2816:                         $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2817:                         $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488     raeburn  2818:                     } else {
1.492     raeburn  2819:                         if ($allmaps->{$ressrc}) {
1.529     raeburn  2820:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492     raeburn  2821:                         } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
                   2822:                             $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
                   2823:                         } else {
                   2824:                             $addedmaps->{$ressrc} = [$url];
                   2825:                         }
1.488     raeburn  2826:                     }
1.627     raeburn  2827:                     &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
                   2828:                                          $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488     raeburn  2829:                 }
1.492     raeburn  2830:             } elsif ($token->[1] eq 'param') {
1.488     raeburn  2831:                 if ($folder =~ /^supplemental/) {
1.492     raeburn  2832:                     if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
                   2833:                         push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
                   2834:                     } else {
                   2835:                         $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}]; 
                   2836:                     }
1.488     raeburn  2837:                 }
                   2838:             }
                   2839:         }
                   2840:     }
                   2841:     return;
                   2842: }
                   2843: 
                   2844: sub url_paste_fixups {
1.533     raeburn  2845:     my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
                   2846:         $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597     raeburn  2847:         $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491     raeburn  2848:     my $checktitle;
                   2849:     if (($prefixchg) &&
1.492     raeburn  2850:         ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491     raeburn  2851:         $checktitle = 1;
                   2852:     }
1.492     raeburn  2853:     my $skip;
                   2854:     if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
                   2855:         my $mapid = $1.$2;
                   2856:         if ($tomove->{$mapid}) {
                   2857:             $skip = 1;
                   2858:         }
                   2859:     }
1.491     raeburn  2860:     my $file = &Apache::lonnet::getfile($oldurl);
1.488     raeburn  2861:     return if ($file eq '-1');
                   2862:     my $parser = HTML::TokeParser->new(\$file);
                   2863:     $parser->attr_encoded(1);
1.491     raeburn  2864:     my $changed = 0;
1.488     raeburn  2865:     while (my $token = $parser->get_token) {
                   2866:         next if ($token->[0] ne 'S');
                   2867:         if ($token->[1] eq 'resource') {
                   2868:             my $ressrc = $token->[2]->{'src'};
                   2869:             next if ($ressrc eq '');
1.491     raeburn  2870:             my $id = $token->[2]->{'id'};
1.492     raeburn  2871:             my $title = $token->[2]->{'title'};
1.491     raeburn  2872:             if ($checktitle) {
                   2873:                 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  2874:                     $retitles->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2875:                 }
                   2876:             }
1.488     raeburn  2877:             next if ($token->[2]->{'type'} eq 'external');
                   2878:             if ($token->[2]->{'type'} eq 'zombie') {
1.492     raeburn  2879:                 next if ($skip);  
1.532     raeburn  2880:                 $zombies->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2881:                 $changed = 1;
                   2882:             } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  2883:                 my $srcdom = $1;
                   2884:                 my $srcnum = $2;
1.488     raeburn  2885:                 my $rem = $3;
1.492     raeburn  2886:                 my $newurl;
                   2887:                 my $mapname;
                   2888:                 if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
                   2889:                     my $prefix = $1;
                   2890:                     $mapname = $prefix.$2;
                   2891:                     if ($tomove->{$mapname}) {
1.533     raeburn  2892:                         &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   2893:                                           $srcdom,$srcnum,$allmaps,$rewrites,
                   2894:                                           $retitles,$copies,$dbcopies,$zombies,
                   2895:                                           $params,$mapmoves,$mapchanges,$tomove,
1.597     raeburn  2896:                                           $newsubdir,$newurls,$resdatacopy);
1.492     raeburn  2897:                         next;
                   2898:                     } else {
                   2899:                         ($newurl,my $error) =
                   2900:                             &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
                   2901:                                             $srcdom,$srcnum,\$title,$allmaps,$newurls);
                   2902:                         if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
                   2903:                             $newsubdir->{$ressrc} = $1;
                   2904:                         }
                   2905:                         if ($error) {
                   2906:                             next;
                   2907:                         }
                   2908:                     }
                   2909:                 }
                   2910:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
                   2911:                     ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
                   2912:                    
1.488     raeburn  2913:                     if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532     raeburn  2914:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.491     raeburn  2915:                         $mapchanges->{$ressrc} = 1;
1.533     raeburn  2916:                         unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
                   2917:                                                   $cnum,$srcdom,$srcnum,$allmaps,
                   2918:                                                   $rewrites,$retitles,$copies,$dbcopies,
                   2919:                                                   $zombies,$params,$mapmoves,$mapchanges,
1.597     raeburn  2920:                                                   $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491     raeburn  2921:                             $mapmoves->{$ressrc} = 1;
                   2922:                         }
                   2923:                         $changed = 1;
1.488     raeburn  2924:                     } else {
1.532     raeburn  2925:                         $rewrites->{$oldurl}{$id} = $ressrc;
1.488     raeburn  2926:                         $copies->{$oldurl}{$ressrc} = $id;
1.491     raeburn  2927:                         $changed = 1;
1.488     raeburn  2928:                     }
                   2929:                 }
1.649     raeburn  2930:             } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533     raeburn  2931:                 next if ($skip);
1.492     raeburn  2932:                 my $srcdom = $1;
                   2933:                 my $srcnum = $2;
1.649     raeburn  2934:                 my $rem = $3;
                   2935:                 my ($is_exttool,$exttoolchg);
                   2936:                 if ($rem =~ m{\d+/ext\.tool$}) {
1.655     raeburn  2937:                     $is_exttool = 1;
1.649     raeburn  2938:                 }
1.492     raeburn  2939:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532     raeburn  2940:                     $rewrites->{$oldurl}{$id} = $ressrc;
1.533     raeburn  2941:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2942:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2943:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   2944:                     $changed = 1;
1.649     raeburn  2945:                     if ($is_exttool) {
                   2946:                         $exttoolchg = 1;
                   2947:                     }
1.700     raeburn  2948:                 } elsif (($is_exttool) &&
1.649     raeburn  2949:                          ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   2950:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2951:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2952:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                   2953:                     $changed = 1;
                   2954:                     $exttoolchg = 1;
                   2955:                 }
                   2956:                 if (($is_exttool) && ($prefixchg)) {
                   2957:                     if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
                   2958:                         if ($exttoolchg) {
                   2959:                             $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
                   2960:                         }
                   2961:                     }
1.533     raeburn  2962:                 }
                   2963:             } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
                   2964:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
                   2965:                     ($env{'form.docs.markedcopy_options'} ne 'move')) {
                   2966:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2967:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   2968:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491     raeburn  2969:                     $changed = 1;
1.488     raeburn  2970:                 }
1.597     raeburn  2971:             } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
                   2972:                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
                   2973:                     $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
                   2974:                     $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
                   2975:                     $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
                   2976:                 }
1.488     raeburn  2977:             } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492     raeburn  2978:                 next if ($skip);
                   2979:                 my $srcdom = $1;
                   2980:                 my $srcnum = $2;
                   2981:                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533     raeburn  2982:                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                   2983:                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                   2984:                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491     raeburn  2985:                     $changed = 1;
1.488     raeburn  2986:                 }
                   2987:             }
                   2988:         } elsif ($token->[1] eq 'param') {
1.492     raeburn  2989:             next if ($skip);
1.488     raeburn  2990:             my $to = $token->[2]->{'to'}; 
                   2991:             if ($to ne '') {
                   2992:                 if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492     raeburn  2993:                     push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488     raeburn  2994:                 } else {
                   2995:                     @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
                   2996:                 }
                   2997:             }
                   2998:         }
                   2999:     }
1.491     raeburn  3000:     return $changed;
1.488     raeburn  3001: }
                   3002: 
                   3003: sub apply_fixups {
1.529     raeburn  3004:     my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
                   3005:         $oldurl,$url,$caller) = @_;
                   3006:     my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533     raeburn  3007:         %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.704     raeburn  3008:         %resdatacopy,%lockerrors,$lockmsg,%currcrsltitools,$gotcrsltitools,
                   3009:         %currltititles,$currltimax);
                   3010:     $currltimax = 0;
1.529     raeburn  3011:     if (ref($updated) eq 'HASH') {
                   3012:         if (ref($updated->{'rewrites'}) eq 'HASH') {
                   3013:             %rewrites = %{$updated->{'rewrites'}};
                   3014:         }
                   3015:         if (ref($updated->{'zombies'}) eq 'HASH') {
                   3016:             %zombies = %{$updated->{'zombies'}};
                   3017:         }
                   3018:         if (ref($updated->{'removefrommap'}) eq 'HASH') {
                   3019:             %removefrommap = %{$updated->{'removefrommap'}};
                   3020:         }
                   3021:         if (ref($updated->{'removeparam'}) eq 'HASH') {
                   3022:             %removeparam = %{$updated->{'removeparam'}};
                   3023:         }
                   3024:         if (ref($updated->{'dbcopies'}) eq 'HASH') {
                   3025:             %dbcopies = %{$updated->{'dbcopies'}};
                   3026:         }
                   3027:         if (ref($updated->{'retitles'}) eq 'HASH') {
                   3028:             %retitles = %{$updated->{'retitles'}};
                   3029:         }
1.597     raeburn  3030:         if (ref($updated->{'resdatacopy'}) eq 'HASH') {
                   3031:             %resdatacopy = %{$updated->{'resdatacopy'}};
                   3032:         }
1.529     raeburn  3033:     }
                   3034:     if (ref($info) eq 'HASH') {
                   3035:         if (ref($info->{'newsubdir'}) eq 'HASH') {
                   3036:             %newsubdir = %{$info->{'newsubdir'}};
                   3037:         }
                   3038:         if (ref($info->{'params'}) eq 'HASH') {
                   3039:             %params = %{$info->{'params'}};
                   3040:         }
                   3041:         if (ref($info->{'before'}) eq 'HASH') {
                   3042:             %before = %{$info->{'before'}};
                   3043:         }
                   3044:         if (ref($info->{'after'}) eq 'HASH') {
                   3045:             %after = %{$info->{'after'}};
                   3046:         }
                   3047:     }
                   3048:     if (ref($moves) eq 'HASH') {
                   3049:         if (ref($moves->{'copies'}) eq 'HASH') {
                   3050:             %copies = %{$moves->{'copies'}};
                   3051:         }
                   3052:         if (ref($moves->{'docmoves'}) eq 'HASH') {
                   3053:             %docmoves = %{$moves->{'docmoves'}};
                   3054:         }
                   3055:         if (ref($moves->{'mapmoves'}) eq 'HASH') {
                   3056:             %mapmoves = %{$moves->{'mapmoves'}};
                   3057:         }
                   3058:     }
                   3059:     foreach my $key (keys(%copies),keys(%docmoves)) {
1.491     raeburn  3060:         my @allcopies;
1.529     raeburn  3061:         if (exists($copies{$key})) {
                   3062:             if (ref($copies{$key}) eq 'HASH') {
                   3063:                 my %added;
                   3064:                 foreach my $innerkey (keys(%{$copies{$key}})) {
                   3065:                     if (($innerkey ne '') && (!$added{$innerkey})) {
                   3066:                         push(@allcopies,$innerkey);
                   3067:                         $added{$innerkey} = 1;
                   3068:                     }
1.491     raeburn  3069:                 }
1.529     raeburn  3070:                 undef(%added);
1.491     raeburn  3071:             }
                   3072:         }
                   3073:         if ($key eq $oldurl) {
1.529     raeburn  3074:             if ((exists($docmoves{$key}))) {
1.532     raeburn  3075:                 unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491     raeburn  3076:                     push(@allcopies,$oldurl);
                   3077:                 }
                   3078:             }
                   3079:         }
                   3080:         if (@allcopies > 0) {
                   3081:             foreach my $item (@allcopies) {
1.492     raeburn  3082:                 my ($relpath,$oldsubdir,$fname) = 
                   3083:                     ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491     raeburn  3084:                 if ($fname ne '') {
                   3085:                     my $content = &Apache::lonnet::getfile($item);
                   3086:                     unless ($content eq '-1') {
                   3087:                         my $storefn;
1.529     raeburn  3088:                         if (($key eq $oldurl) && (exists($docmoves{$key}))) {
                   3089:                             $storefn = $docmoves{$key};
1.491     raeburn  3090:                         } else {
                   3091:                             $storefn = $relpath;
                   3092:                             $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  3093:                             if ($prefixchg && $before{'doc'} && $after{'doc'}) {
                   3094:                                 $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491     raeburn  3095:                             }
1.529     raeburn  3096:                             if ($newsubdir{$key}) {
1.532     raeburn  3097:                                 $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491     raeburn  3098:                             }
                   3099:                         }
                   3100:                         &copy_dependencies($item,$storefn,$relpath,$errors,\$content);
                   3101:                         my $copyurl = 
                   3102:                             &Apache::lonclonecourse::writefile($env{'request.course.id'},
                   3103:                                                                $storefn.$fname,$content);
                   3104:                         if ($copyurl eq '/adm/notfound.html') {
1.529     raeburn  3105:                             if (exists($docmoves{$oldurl})) {
1.491     raeburn  3106:                                 return &mt('Paste failed: an error occurred copying the file.');
                   3107:                             } elsif (ref($errors) eq 'HASH') {
                   3108:                                 $errors->{$item} = 1;
1.489     raeburn  3109:                             }
                   3110:                         }
1.488     raeburn  3111:                     }
                   3112:                 }
1.491     raeburn  3113:             }
                   3114:         }
                   3115:     }
1.529     raeburn  3116:     foreach my $key (keys(%mapmoves)) {
1.491     raeburn  3117:         my $storefn=$key;
                   3118:         $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  3119:         if ($prefixchg && $before{'map'} && $after{'map'}) {
                   3120:             $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  3121:         }
1.529     raeburn  3122:         if ($newsubdir{$key}) {
                   3123:             $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  3124:         }
1.491     raeburn  3125:         my $mapcontent = &Apache::lonnet::getfile($key);
1.681     raeburn  3126:         if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
                   3127:             ($after{'map'} eq 'default') &&
                   3128:             ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
                   3129:             $mapcontent = '<map>'."\n".
                   3130:                           '<resource id="1" src="" type="start" />'."\n".
                   3131:                           '<link from="1" to="2" index="1" />'."\n".
                   3132:                           '<resource id="2" src="" type="finish" />'."\n".
                   3133:                           '</map>';
                   3134:         }
1.491     raeburn  3135:         if ($mapcontent eq '-1') {
                   3136:             if (ref($errors) eq 'HASH') {
                   3137:                 $errors->{$key} = 1;
                   3138:             }
                   3139:         } else {
                   3140:             my $newmap =
                   3141:                 &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
                   3142:                                                    $mapcontent);
                   3143:             if ($newmap eq '/adm/notfound.html') {
                   3144:                 if (ref($errors) eq 'HASH') {
                   3145:                     $errors->{$key} = 1;
1.489     raeburn  3146:                 }
1.488     raeburn  3147:             }
                   3148:         }
                   3149:     }
1.491     raeburn  3150:     my %updates;
                   3151:     if ($is_map) {
1.529     raeburn  3152:         if (ref($updated) eq 'HASH') {
                   3153:             foreach my $type (keys(%{$updated})) {
                   3154:                 if (ref($updated->{$type}) eq 'HASH') {
                   3155:                     foreach my $key (keys(%{$updated->{$type}})) {
                   3156:                         $updates{$key} = 1;
                   3157:                     }
                   3158:                 }
                   3159:             }
1.491     raeburn  3160:         }
1.704     raeburn  3161:         my ($updatetoolscache,@updatetoolsenc,$same_institution,$checkedsameinst);
1.491     raeburn  3162:         foreach my $key (keys(%updates)) {
1.492     raeburn  3163:             my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529     raeburn  3164:             if (ref($rewrites{$key}) eq 'HASH') {
                   3165:                 %torewrite = %{$rewrites{$key}};
1.491     raeburn  3166:             }
1.529     raeburn  3167:             if (ref($retitles{$key}) eq 'HASH') {
                   3168:                 %toretitle = %{$retitles{$key}};
1.491     raeburn  3169:             }
1.529     raeburn  3170:             if (ref($removefrommap{$key}) eq 'HASH') {
                   3171:                 %toremove = %{$removefrommap{$key}};
1.491     raeburn  3172:             }
1.529     raeburn  3173:             if (ref($removeparam{$key}) eq 'HASH') {
                   3174:                 %remparam = %{$removeparam{$key}};
1.492     raeburn  3175:             }
1.529     raeburn  3176:             if (ref($zombies{$key}) eq 'HASH') {
                   3177:                 %zombie = %{$zombies{$key}};
1.491     raeburn  3178:             }
1.529     raeburn  3179:             if (ref($dbcopies{$key}) eq 'HASH') {
1.533     raeburn  3180:                 foreach my $idx (keys(%{$dbcopies{$key}})) {
                   3181:                     if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1.704     raeburn  3182:                         my $oldurl = $dbcopies{$key}{$idx}{'src'};
                   3183:                         my $oldcdom = $dbcopies{$key}{$idx}{'cdom'};
                   3184:                         my $oldcnum = $dbcopies{$key}{$idx}{'cnum'};
                   3185:                         my $oldmarker;
                   3186:                         if ($oldurl =~ m{^\Q/adm/$oldcdom/$oldcnum/\E(\d+)/ext\.tool$}) {
                   3187:                             $oldmarker = $1;
                   3188:                             unless (($gotcrsltitools) ||
                   3189:                                     (($oldcnum eq $cnum) && ($oldcdom eq $cdom))) {
                   3190:                                 my %oldtoolsettings=&Apache::lonnet::dump('exttool_'.$oldmarker,$oldcdom,$oldcnum);
                   3191:                                 if ($oldtoolsettings{'id'} =~ /^c\d+$/) {
                   3192:                                     unless ($gotcrsltitools) {
                   3193:                                         %currcrsltitools =
                   3194:                                             &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
                   3195:                                         foreach my $item (sort(keys(%currcrsltitools))) {
                   3196:                                             if (ref($currcrsltitools{$item}) eq 'HASH') {
                   3197:                                                 $currltimax ++;
                   3198:                                                 if (ref($currltititles{$currcrsltitools{$item}{'title'}}) eq 'ARRAY') {
                   3199:                                                     push(@{$currltititles{$currcrsltitools{$item}{'title'}}},$item);
                   3200:                                                 } else {
                   3201:                                                     $currltititles{$currcrsltitools{$item}{'title'}} = [$item];
                   3202:                                                 }
                   3203:                                             }
                   3204:                                         }
                   3205:                                         $gotcrsltitools = 1;
                   3206:                                     }
                   3207:                                     unless ($checkedsameinst) {
                   3208:                                         my $primary_id = &Apache::lonnet::domain($cdom,'primary');
                   3209:                                         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   3210:                                         if ($intdom ne '') {
                   3211:                                             my $internet_names =
                   3212:                                                 &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   3213:                                             if (ref($internet_names) eq 'ARRAY') {
                   3214:                                                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   3215:                                                     $same_institution = 1;
                   3216:                                                 }
                   3217:                                             }
                   3218:                                         }
                   3219:                                         $checkedsameinst = 1;
                   3220:                                     }
                   3221:                                 }
                   3222:                             }
                   3223:                         }
1.533     raeburn  3224:                         my ($newurl,$result,$errtext) =
1.704     raeburn  3225:                             &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors,\%currltititles,
                   3226:                                     \$currltimax,\@updatetoolsenc,\$updatetoolscache,$same_institution);
1.533     raeburn  3227:                         if ($result eq 'ok') {
                   3228:                             $newdb{$idx} = $newurl;
1.704     raeburn  3229:                             if ($newurl =~ /ext\.tool$/) {
                   3230:                                 if ($torewrite{$idx} eq "/adm/$oldcdom/$oldcnum/$oldmarker/ext.tool") {
                   3231:                                     if ($newurl =~ m{^\Q/adm/$cdom/$cnum/\E(\d+)/ext.tool$}) {
                   3232:                                         my $newmarker = $1;
                   3233:                                         unless ($oldmarker eq $newmarker) {
                   3234:                                             $torewrite{$idx} = "/adm/$oldcdom/$oldcnum/$newmarker/ext.tool";
                   3235:                                         }
                   3236:                                     }
                   3237:                                 }
                   3238:                             }
1.533     raeburn  3239:                         } elsif (ref($errors) eq 'HASH') {
                   3240:                             $errors->{$key} = 1;
                   3241:                         }
                   3242:                         push(@msgs,$errtext);
                   3243:                     }
1.491     raeburn  3244:                 }
                   3245:             }
1.597     raeburn  3246:             if (ref($resdatacopy{$key}) eq 'HASH') {
1.664     raeburn  3247:                 my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597     raeburn  3248:                 foreach my $idx (keys(%{$resdatacopy{$key}})) {
                   3249:                     if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
                   3250:                         my $srcurl = $resdatacopy{$key}{$idx}{'src'};
                   3251:                         if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   3252:                             my $template = $1;
                   3253:                             if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
                   3254:                                 ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
                   3255:                                 my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
                   3256:                                 my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664     raeburn  3257:                                 unless ($gotnewmapname) {
                   3258:                                     ($newmapname) = ($key =~ m{/([^/]+)$});
                   3259:                                     ($srcfolder,$srccontainer) = split(/\./,$newmapname);
                   3260:                                     if ($newsubdir{$key}) {
                   3261:                                         $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
                   3262:                                     }
                   3263:                                     $gotnewmapname = 1;
                   3264:                                 }
1.597     raeburn  3265:                                 my $srcmapinfo = $srcfolder.':'.$idx;
                   3266:                                 if ($srccontainer eq 'page') {
                   3267:                                     $srcmapinfo .= ':1';
                   3268:                                 }
                   3269:                                 &copy_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
                   3270:                                                       $cnum,$template,$idx,$newmapname);
                   3271:                             }
                   3272:                         }
                   3273:                     }
                   3274:                 }
                   3275:             }
1.529     raeburn  3276:             if (ref($params{$key}) eq 'HASH') {
                   3277:                 %currparam = %{$params{$key}};
1.492     raeburn  3278:             }
                   3279:             my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
                   3280:             if ($fatal) {
1.533     raeburn  3281:                 return ($errtext);
1.492     raeburn  3282:             }
                   3283:             for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
                   3284:                 if (defined($LONCAPA::map::zombies[$i])) {
                   3285:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532     raeburn  3286:                     if ($zombie{$i} eq $src) {
1.492     raeburn  3287:                         undef($LONCAPA::map::zombies[$i]);
                   3288:                     }
                   3289:                 }
                   3290:             }
1.646     raeburn  3291:             my $total = scalar(@LONCAPA::map::order) - 1;
                   3292:             for (my $i=$total; $i>=0; $i--) {
1.529     raeburn  3293:                 my $idx = $LONCAPA::map::order[$i];
                   3294:                 if (defined($LONCAPA::map::resources[$idx])) {
1.492     raeburn  3295:                     my $changed;
1.529     raeburn  3296:                     my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538     raeburn  3297:                     if ((exists($toremove{$idx})) && 
                   3298:                         ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492     raeburn  3299:                         splice(@LONCAPA::map::order,$i,1);
1.529     raeburn  3300:                         if (ref($currparam{$idx}) eq 'ARRAY') {
                   3301:                             foreach my $name (@{$currparam{$idx}}) {
1.647     raeburn  3302:                                 &LONCAPA::map::delparameter($idx,$name);
1.492     raeburn  3303:                             }
                   3304:                         }
                   3305:                         next;
                   3306:                     }
                   3307:                     my $origsrc = $src;
1.532     raeburn  3308:                     if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492     raeburn  3309:                         if ($title =~ m{^\d+\Q___&amp;&amp;&amp;___\E$match_username\Q___&amp;&amp;&amp;___\E$match_domain\Q___&amp;&amp;&amp;___\E(.+)$}) {
                   3310:                             $changed = 1;
1.491     raeburn  3311:                         }
1.492     raeburn  3312:                     }
1.532     raeburn  3313:                     if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492     raeburn  3314:                         $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
                   3315:                         if ($origsrc =~ m{^/uploaded/}) {
1.529     raeburn  3316:                             if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492     raeburn  3317:                                 if ($src =~ /\.(page|sequence)$/) {
1.529     raeburn  3318:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492     raeburn  3319:                                 } else {
1.529     raeburn  3320:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488     raeburn  3321:                                 }
1.491     raeburn  3322:                             }
1.532     raeburn  3323:                             if ($origsrc =~ /\.(page|sequence)$/) {
                   3324:                                 if ($newsubdir{$origsrc}) {
1.529     raeburn  3325:                                     $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491     raeburn  3326:                                 }
1.532     raeburn  3327:                             } elsif ($newsubdir{$key}) {
                   3328:                                 $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488     raeburn  3329:                             }
                   3330:                         }
1.492     raeburn  3331:                         $changed = 1;
1.533     raeburn  3332:                     } elsif ($newdb{$idx} ne '') {
                   3333:                         $src = $newdb{$idx};
1.492     raeburn  3334:                         $changed = 1;
                   3335:                     }
                   3336:                     if ($changed) {
1.538     raeburn  3337:                         $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492     raeburn  3338:                     }
                   3339:                 }
                   3340:             }
                   3341:             foreach my $idx (keys(%remparam)) {
                   3342:                 if (ref($remparam{$idx}) eq 'ARRAY') {
                   3343:                     foreach my $name (@{$remparam{$idx}}) {   
1.647     raeburn  3344:                         &LONCAPA::map::delparameter($idx,$name);
1.491     raeburn  3345:                     }
                   3346:                 }
                   3347:             }
1.533     raeburn  3348:             if (values(%lockerrors) > 0) {
                   3349:                 $lockmsg = join('<br />',values(%lockerrors));
                   3350:             }
1.491     raeburn  3351:             my $storefn;
                   3352:             if ($key eq $oldurl) {
                   3353:                 $storefn = $url;
                   3354:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
                   3355:             } else {
                   3356:                 $storefn = $key;
                   3357:                 $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529     raeburn  3358:                 if ($prefixchg && $before{'map'} && $after{'map'}) {
                   3359:                     $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491     raeburn  3360:                 }
1.529     raeburn  3361:                 if ($newsubdir{$key}) {
                   3362:                     $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492     raeburn  3363:                 }
1.491     raeburn  3364:             }
1.492     raeburn  3365:             my $report;
                   3366:             if ($folder !~ /^supplemental/) {
                   3367:                 $report = 1;
                   3368:             }
1.527     raeburn  3369:             (my $outtext,$errtext) =
1.492     raeburn  3370:                 &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
                   3371:             if ($errtext) {
1.529     raeburn  3372:                 if ($caller eq 'paste') {
1.533     raeburn  3373:                     return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529     raeburn  3374:                 }
1.491     raeburn  3375:             }
                   3376:         }
1.704     raeburn  3377:         if (($updatetoolscache) || (@updatetoolsenc)) {
                   3378:             &update_ltitools_caches($cdom,$cnum,$updatetoolscache,
                   3379:                                     \@updatetoolsenc);
                   3380:         }
1.491     raeburn  3381:     }
1.533     raeburn  3382:     return ('ok',\@msgs,$lockmsg);
1.491     raeburn  3383: }
                   3384: 
                   3385: sub copy_dependencies {
                   3386:     my ($item,$storefn,$relpath,$errors,$contentref) = @_;
                   3387:     my $content;
                   3388:     if (ref($contentref)) {
                   3389:         $content = $$contentref;
                   3390:     } else {
                   3391:         $content = &Apache::lonnet::getfile($item);
                   3392:     }
                   3393:     unless ($content eq '-1') {
                   3394:         my $mm = new File::MMagic;
                   3395:         my $mimetype = $mm->checktype_contents($content);
                   3396:         if ($mimetype eq 'text/html') {
                   3397:             my (%allfiles,%codebase,$state);
                   3398:             my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
                   3399:             if ($res eq 'ok') {
                   3400:                 my ($numexisting,$numpathchanges,$existing);
                   3401:                 (undef,$numexisting,$numpathchanges,$existing) =
                   3402:                     &Apache::loncommon::ask_for_embedded_content(
                   3403:                         '/adm/coursedocs',$state,\%allfiles,\%codebase,
                   3404:                         {'error_on_invalid_names'   => 1,
                   3405:                          'ignore_remote_references' => 1,
                   3406:                          'docs_url'                 => $item,
                   3407:                          'context'                  => 'paste'});
                   3408:                 if ($numexisting > 0) {
                   3409:                     if (ref($existing) eq 'HASH') {
                   3410:                         foreach my $dep (keys(%{$existing})) {
                   3411:                             my $depfile = $dep;
                   3412:                             unless ($depfile =~ m{^\Q$relpath\E}) {
                   3413:                                 $depfile = $relpath.$dep;
                   3414:                             }
                   3415:                             my $depcontent = &Apache::lonnet::getfile($depfile);
                   3416:                             unless ($depcontent eq '-1') {
                   3417:                                 my $storedep = $dep;
                   3418:                                 $storedep =~ s{^\Q$relpath\E}{};
                   3419:                                 my $dep_url =
                   3420:                                     &Apache::lonclonecourse::writefile(
                   3421:                                         $env{'request.course.id'},
                   3422:                                         $storefn.$storedep,$depcontent);
                   3423:                                 if ($dep_url eq '/adm/notfound.html') {
                   3424:                                     if (ref($errors) eq 'HASH') {
                   3425:                                         $errors->{$depfile} = 1;
                   3426:                                     }
                   3427:                                 } else {
                   3428:                                     &copy_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
                   3429:                                 }
                   3430:                             }
                   3431:                         }
1.488     raeburn  3432:                     }
                   3433:                 }
                   3434:             }
                   3435:         }
                   3436:     }
                   3437:     return;
                   3438: }
                   3439: 
1.329     droeschl 3440: my %parameter_type = ( 'randompick'     => 'int_pos',
                   3441: 		       'hiddenresource' => 'string_yesno',
                   3442: 		       'encrypturl'     => 'string_yesno',
                   3443: 		       'randomorder'    => 'string_yesno',);
                   3444: my $valid_parameters_re = join('|',keys(%parameter_type));
                   3445: # set parameters
                   3446: sub update_parameter {
1.537     raeburn  3447:     if ($env{'form.changeparms'} eq 'all') {
                   3448:         my (@allidx,@allmapidx,%allchecked,%currchecked);
                   3449:         %allchecked = (
                   3450:                          'hiddenresource' => {},
                   3451:                          'encrypturl'     => {},
                   3452:                          'randompick'     => {},
                   3453:                          'randomorder'    => {},
                   3454:                       );
                   3455:         foreach my $which (keys(%allchecked)) {
1.630     raeburn  3456:             $env{'form.all'.$which} =~ s/,$//;
1.537     raeburn  3457:             if ($which eq 'randompick') {
                   3458:                 foreach my $item (split(/,/,$env{'form.all'.$which})) {
                   3459:                     my ($res,$value) = split(/:/,$item);
                   3460:                     if ($value =~ /^\d+$/) {
                   3461:                         $allchecked{$which}{$res} = $value;
                   3462:                     }
                   3463:                 }
                   3464:             } else {
1.539     raeburn  3465:                 if ($env{'form.all'.$which}) {
                   3466:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
                   3467:                 }
1.537     raeburn  3468:             }
                   3469:         }
                   3470:         my $haschanges = 0;
                   3471:         foreach my $res (@LONCAPA::map::order) {
                   3472:             my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3473:             $name=&LONCAPA::map::qtescape($name);
                   3474:             $url=&LONCAPA::map::qtescape($url);
1.692     raeburn  3475:             next unless $url;
1.537     raeburn  3476:             my $is_map;
                   3477:             if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   3478:                 $is_map = 1;
                   3479:             }
                   3480:             foreach my $which (keys(%allchecked)) {
                   3481:                 if (($which eq 'randompick' || $which eq 'randomorder')) {
                   3482:                     next if (!$is_map);
                   3483:                 } 
                   3484:                 my $oldvalue = 0;
                   3485:                 my $newvalue = 0;
                   3486:                 if ($allchecked{$which}{$res}) {
                   3487:                     $newvalue = $allchecked{$which}{$res};
                   3488:                 }
                   3489:                 my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
                   3490:                 if ($which eq 'randompick') {
                   3491:                     if ($current =~ /^(\d+)$/) {
                   3492:                         $oldvalue = $1;
                   3493:                     }
                   3494:                 } else {
                   3495:                     if ($current =~ /^yes$/i) {
                   3496:                         $oldvalue = 1;
                   3497:                     }
                   3498:                 }
                   3499:                 if ($oldvalue ne $newvalue) {
                   3500:                     $haschanges = 1;
                   3501:                     if ($newvalue) {
                   3502:                         my $storeval = 'yes';
                   3503:                         if ($which eq 'randompick') {
                   3504:                             $storeval = $newvalue;
                   3505:                         }
                   3506:                         &LONCAPA::map::storeparameter($res,'parameter_'.$which,
                   3507:                                                       $storeval,
                   3508:                                                       $parameter_type{$which});
                   3509:                         &remember_parms($res,$which,'set',$storeval);
                   3510:                     } elsif ($oldvalue) {
                   3511:                         &LONCAPA::map::delparameter($res,'parameter_'.$which);
                   3512:                         &remember_parms($res,$which,'del');
                   3513:                     }
                   3514:                 }
                   3515:             }
                   3516:         }
                   3517:         return $haschanges;
                   3518:     } else {
1.588     raeburn  3519:         my $haschanges = 0;
                   3520:         return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329     droeschl 3521: 
1.537     raeburn  3522:         my $which = $env{'form.changeparms'};
                   3523:         my $idx = $env{'form.setparms'};
1.588     raeburn  3524:         my $oldvalue = 0;
                   3525:         my $newvalue = 0;
                   3526:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
                   3527:         if ($which eq 'randompick') {
                   3528:             if ($current =~ /^(\d+)$/) {
                   3529:                 $oldvalue = $1;
                   3530:             }
                   3531:         } elsif ($current =~ /^yes$/i) {
                   3532:             $oldvalue = 1;
                   3533:         }
1.537     raeburn  3534:         if ($env{'form.'.$which.'_'.$idx}) {
1.588     raeburn  3535: 	    $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
                   3536: 	                                         : 1;
                   3537:         }
                   3538:         if ($oldvalue ne $newvalue) {
                   3539:             $haschanges = 1;
                   3540:             if ($newvalue) {
                   3541:                 my $storeval = 'yes';
                   3542:                 if ($which eq 'randompick') {
                   3543:                     $storeval = $newvalue;
                   3544:                 }
                   3545: 	        &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
                   3546: 				              $parameter_type{$which});
                   3547: 	        &remember_parms($idx,$which,'set',$storeval);
                   3548:             } else {
                   3549: 	        &LONCAPA::map::delparameter($idx,'parameter_'.$which);
                   3550: 	        &remember_parms($idx,$which,'del');
                   3551:             }
1.537     raeburn  3552:         }
1.588     raeburn  3553:         return $haschanges;
1.329     droeschl 3554:     }
                   3555: }
                   3556: 
                   3557: sub handle_edit_cmd {
                   3558:     my ($coursenum,$coursedom) =@_;
1.633     raeburn  3559:     my $haschanges = 0;
1.543     raeburn  3560:     if ($env{'form.cmd'} eq '') {
1.633     raeburn  3561:         return $haschanges; 
1.543     raeburn  3562:     }
1.329     droeschl 3563:     my ($cmd,$idx)=split('_',$env{'form.cmd'});
                   3564: 
                   3565:     my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                   3566:     my ($title, $url, @rrest) = split(':', $ratstr);
                   3567: 
1.538     raeburn  3568:     if ($cmd eq 'remove') {
1.329     droeschl 3569: 	if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463     www      3570: 	    ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329     droeschl 3571: 	    &Apache::lonnet::removeuploadedurl($url);
                   3572: 	} else {
                   3573: 	    &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   3574: 	}
                   3575: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  3576:         $haschanges = 1;
1.329     droeschl 3577:     } elsif ($cmd eq 'cut') {
                   3578: 	&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   3579: 	splice(@LONCAPA::map::order, $idx, 1);
1.633     raeburn  3580:         $haschanges = 1;
1.344     bisitz   3581:     } elsif ($cmd eq 'up'
1.329     droeschl 3582: 	     && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
                   3583: 	@LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633     raeburn  3584:         $haschanges = 1;
1.329     droeschl 3585:     } elsif ($cmd eq 'down'
                   3586: 	     && defined($LONCAPA::map::order[$idx+1])) {
                   3587: 	@LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633     raeburn  3588:         $haschanges = 1;
1.329     droeschl 3589:     } elsif ($cmd eq 'rename') {
                   3590: 	my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
                   3591: 	if ($comment=~/\S/) {
                   3592: 	    $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
                   3593: 		$comment.':'.join(':', $url, @rrest);
                   3594: 	}
                   3595: # Devalidate title cache
                   3596: 	my $renamed_url=&LONCAPA::map::qtescape($url);
                   3597: 	&Apache::lonnet::devalidate_title_cache($renamed_url);
1.633     raeburn  3598:         $haschanges = 1;
                   3599:     } elsif ($cmd eq 'setalias') {
                   3600:         my $newvalue = $env{'form.alias'};
                   3601:         if ($newvalue ne '') {
                   3602:             unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
                   3603:                 &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
                   3604:                                               'string');
                   3605:                 &remember_parms($idx,'mapalias','set',$newvalue);
                   3606:                 $haschanges = 1;
                   3607:             }
                   3608:         }
                   3609:     } elsif ($cmd eq 'delalias') {
                   3610:         my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];  
                   3611:         if ($current ne '') {
                   3612:             &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
                   3613:             &remember_parms($idx,'mapalias','del');
                   3614:             $haschanges = 1;
                   3615:         }
1.329     droeschl 3616:     }
1.633     raeburn  3617:     return $haschanges;
1.329     droeschl 3618: }
                   3619: 
                   3620: sub editor {
1.458     raeburn  3621:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615     raeburn  3622:         $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622     raeburn  3623:         $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519     raeburn  3624:     my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510     raeburn  3625:     if ($allowed) {
1.519     raeburn  3626:         (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   3627:          $is_random_order,$container) =
1.510     raeburn  3628:             &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   3629:         $r->print($breadcrumbtrail);
1.519     raeburn  3630:     } elsif ($env{'form.folderpath'} =~ /\:1$/) {
                   3631:         $container = 'page'; 
                   3632:     } else {
                   3633:         $container = 'sequence';
1.510     raeburn  3634:     }
1.484     raeburn  3635: 
1.525     raeburn  3636:     my $jumpto;
                   3637: 
                   3638:     unless ($supplementalflag) {
1.546     raeburn  3639:         $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525     raeburn  3640:     }
1.484     raeburn  3641: 
                   3642:     unless ($allowed) {
                   3643:         $randompick = -1;
                   3644:     }
                   3645: 
1.615     raeburn  3646:     my ($errtext,$fatal);
                   3647:     if (($folder eq '') && (!$supplementalflag)) {
                   3648:         if (@LONCAPA::map::order) {
                   3649:             undef(@LONCAPA::map::order);
                   3650:             undef(@LONCAPA::map::resources);
                   3651:             undef(@LONCAPA::map::resparms);
                   3652:             undef(@LONCAPA::map::zombies);
                   3653:         }
                   3654:         $folder = 'default';
                   3655:         $container = 'sequence'; 
                   3656:     } else {
                   3657:         ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   3658: 				     $folder.'.'.$container);
                   3659:         return $errtext if ($fatal);
                   3660:     }
1.329     droeschl 3661: 
                   3662:     if ($#LONCAPA::map::order<1) {
                   3663: 	my $idx=&LONCAPA::map::getresidx();
                   3664: 	if ($idx<=0) { $idx=1; }
                   3665:        	$LONCAPA::map::order[0]=$idx;
                   3666:         $LONCAPA::map::resources[$idx]='';
                   3667:     }
1.364     bisitz   3668: 
1.329     droeschl 3669: # ------------------------------------------------------------ Process commands
                   3670: 
                   3671: # ---------------- if they are for this folder and user allowed to make changes
1.611     raeburn  3672:     if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329     droeschl 3673: # set parameters and change order
                   3674: 	&snapshotbefore();
                   3675: 
                   3676: 	if (&update_parameter()) {
1.588     raeburn  3677: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329     droeschl 3678: 	    return $errtext if ($fatal);
                   3679: 	}
                   3680: 
                   3681: 	if ($env{'form.newpos'} && $env{'form.currentpos'}) {
                   3682: # change order
                   3683: 	    my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
                   3684: 	    splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
                   3685: 
                   3686: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
                   3687: 	    return $errtext if ($fatal);
                   3688: 	}
1.364     bisitz   3689: 
1.329     droeschl 3690: 	if ($env{'form.pastemarked'}) {
1.491     raeburn  3691:             my %paste_errors;
1.533     raeburn  3692:             my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492     raeburn  3693:                 &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
                   3694:                                       \%paste_errors);
1.541     raeburn  3695:             if (ref($pastemsgarray) eq 'ARRAY') {
                   3696:                 if (@{$pastemsgarray} > 0) {
                   3697:                     $r->print('<p class="LC_info">'.
                   3698:                               join('<br />',@{$pastemsgarray}).
1.533     raeburn  3699:                               '</p>');
                   3700:                 }
1.541     raeburn  3701:             }
                   3702:             if ($lockerror) {
                   3703:                 $r->print('<p class="LC_error">'.
                   3704:                           $lockerror.
                   3705:                           '</p>');
                   3706:             }
                   3707:             if ($save_error ne '') {
                   3708:                 return $save_error; 
                   3709:             }
                   3710:             if ($paste_res) {
                   3711:                 my %errortext = &Apache::lonlocal::texthash (
                   3712:                                     fail      => 'Storage of folder contents failed',
                   3713:                                     failread  => 'Reading folder contents failed',
                   3714:                                     failstore => 'Storage of folder contents failed',
                   3715:                                 );
                   3716:                 if ($errortext{$paste_res}) {
                   3717:                     $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492     raeburn  3718:                 }
1.329     droeschl 3719:             }
1.491     raeburn  3720:             if (keys(%paste_errors) > 0) {
1.538     raeburn  3721:                 $r->print('<p class="LC_warning">'."\n".
1.491     raeburn  3722:                           &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".
                   3723:                           '<ul>'."\n");
                   3724:                 foreach my $key (sort(keys(%paste_errors))) {
                   3725:                     $r->print('<li>'.$key.'</li>'."\n");
                   3726:                 }
                   3727:                 $r->print('</ul></p>'."\n");
                   3728:             }
1.538     raeburn  3729: 	} elsif ($env{'form.clearmarked'}) {
                   3730:             my $output = &do_buffer_empty();
                   3731:             if ($output) {
                   3732:                 $r->print('<p class="LC_info">'.$output.'</p>');
                   3733:             }
                   3734:         }
1.329     droeschl 3735: 
                   3736: 	$r->print($upload_output);
                   3737: 
1.538     raeburn  3738: # Rename, cut, copy or remove a single resource
1.602     raeburn  3739: 	if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492     raeburn  3740:             my $contentchg;
1.633     raeburn  3741:             if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492     raeburn  3742:                 $contentchg = 1;
                   3743:             }
                   3744: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329     droeschl 3745: 	    return $errtext if ($fatal);
                   3746: 	}
1.538     raeburn  3747: 
                   3748: # Cut, copy and/or remove multiple resources
                   3749:         if ($env{'form.multichange'}) {
                   3750:             my %allchecked = (
                   3751:                                cut     => {},
                   3752:                                remove  => {},
                   3753:                              );
                   3754:             my $needsupdate;
                   3755:             foreach my $which (keys(%allchecked)) {
                   3756:                 $env{'form.multi'.$which} =~ s/,$//;
                   3757:                 if ($env{'form.multi'.$which}) {
                   3758:                     map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
                   3759:                     if (ref($allchecked{$which}) eq 'HASH') {
                   3760:                         $needsupdate += scalar(keys(%{$allchecked{$which}}));
                   3761:                     }
                   3762:                 }
                   3763:             }
                   3764:             if ($needsupdate) {
                   3765:                 my $haschanges = 0;
                   3766:                 my %curr_groups = &Apache::longroup::coursegroups();
                   3767:                 my $total = scalar(@LONCAPA::map::order) - 1; 
                   3768:                 for (my $i=$total; $i>=0; $i--) {
                   3769:                     my $res = $LONCAPA::map::order[$i];
                   3770:                     my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3771:                     $name=&LONCAPA::map::qtescape($name);
                   3772:                     $url=&LONCAPA::map::qtescape($url);
1.586     droeschl 3773:                     next unless $url;
1.538     raeburn  3774:                     my %denied =
                   3775:                         &action_restrictions($coursenum,$coursedom,$url,
                   3776:                                              $env{'form.folderpath'},\%curr_groups);
                   3777:                     foreach my $which (keys(%allchecked)) {
                   3778:                         next if ($denied{$which});
                   3779:                         next unless ($allchecked{$which}{$res});
                   3780:                         if ($which eq 'remove') {
                   3781:                             if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   3782:                                 ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   3783:                                 &Apache::lonnet::removeuploadedurl($url);
                   3784:                             } else {
                   3785:                                 &LONCAPA::map::makezombie($res);
                   3786:                             }
                   3787:                             splice(@LONCAPA::map::order,$i,1);
                   3788:                             $haschanges ++;
                   3789:                         } elsif ($which eq 'cut') {
                   3790:                             &LONCAPA::map::makezombie($res);
                   3791:                             splice(@LONCAPA::map::order,$i,1);
                   3792:                             $haschanges ++;
                   3793:                         }
                   3794:                     }
                   3795:                 }
                   3796:                 if ($haschanges) {
                   3797:                     ($errtext,$fatal) = 
                   3798:                         &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
                   3799:                     return $errtext if ($fatal);
                   3800:                 }
                   3801:             }
                   3802:         }
                   3803: 
1.329     droeschl 3804: # Group import/search
                   3805: 	if ($env{'form.importdetail'}) {
                   3806: 	    my @imports;
                   3807: 	    foreach my $item (split(/\&/,$env{'form.importdetail'})) {
                   3808: 		if (defined($item)) {
                   3809: 		    my ($name,$url,$residx)=
1.533     raeburn  3810: 			map { &unescape($_); } split(/\=/,$item);
                   3811:                     if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
                   3812:                         my ($suffix,$errortxt,$locknotfreed) =
                   3813:                             &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504     raeburn  3814:                         if ($locknotfreed) {
                   3815:                             $r->print($locknotfreed);
                   3816:                         }
                   3817:                         if ($suffix) {
                   3818:                             $url =~ s/_new\./_$suffix./; 
                   3819:                         } else {
                   3820:                             return $errortxt;
                   3821:                         }
1.533     raeburn  3822:                     } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
                   3823:                         my $type = $1;
                   3824:                         my ($suffix,$errortxt,$locknotfreed) =
                   3825:                             &new_timebased_suffix($coursedom,$coursenum,$type);
                   3826:                         if ($locknotfreed) {
                   3827:                             $r->print($locknotfreed);
                   3828:                         }
                   3829:                         if ($suffix) {
                   3830:                             $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
                   3831:                         } else {
                   3832:                             return $errortxt;
                   3833:                         }
1.626     raeburn  3834:                     } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598     raeburn  3835:                         my ($suffix,$errortxt,$locknotfreed) =
                   3836:                             &new_timebased_suffix($coursedom,$coursenum,'exttool');
                   3837:                         if ($locknotfreed) {
                   3838:                             $r->print($locknotfreed);
                   3839:                         }
                   3840:                         if ($suffix) {
                   3841:                             $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
                   3842:                         } else {
                   3843:                             return $errortxt;
                   3844:                         }
1.534     raeburn  3845:                     } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
                   3846:                         if ($supplementalflag) {
                   3847:                             next unless ($1 eq 'supplemental');
                   3848:                             if ($folder eq 'supplemental') {
                   3849:                                 next unless ($2 eq 'default');
                   3850:                             } else {
                   3851:                                 next unless ($folder eq 'supplemental_'.$2);
                   3852:                             }
                   3853:                         } else {
                   3854:                             next unless ($1 eq 'docs');
                   3855:                             if ($folder eq 'default') {
                   3856:                                 next unless ($2 eq 'default');
                   3857:                             } else {
                   3858:                                 next unless ($folder eq 'default_'.$2);
                   3859:                             }
                   3860:                         }
1.504     raeburn  3861:                     }
1.329     droeschl 3862: 		    push(@imports, [$name, $url, $residx]);
                   3863: 		}
                   3864: 	    }
1.530     raeburn  3865:             ($errtext,$fatal,my $fixuperrors) =
1.529     raeburn  3866:                 &group_import($coursenum, $coursedom, $folder,$container,
1.598     raeburn  3867:                               'londocs',$ltitoolsref,@imports);
1.329     droeschl 3868: 	    return $errtext if ($fatal);
1.529     raeburn  3869:             if ($fixuperrors) {
                   3870:                 $r->print($fixuperrors);
                   3871:             }
1.329     droeschl 3872: 	}
                   3873: # Loading a complete map
                   3874: 	if ($env{'form.loadmap'}) {
                   3875: 	    if ($env{'form.importmap'}=~/\w/) {
                   3876: 		foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
                   3877: 		    my ($title,$url,$ext,$type)=split(/\:/,$res);
                   3878: 		    my $idx=&LONCAPA::map::getresidx($url);
                   3879: 		    $LONCAPA::map::resources[$idx]=$res;
                   3880: 		    $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
                   3881: 		}
                   3882: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  3883: 					    $folder.'.'.$container,1);
1.329     droeschl 3884: 		return $errtext if ($fatal);
                   3885: 	    } else {
                   3886: 		$r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364     bisitz   3887: 
1.329     droeschl 3888: 	    }
                   3889: 	}
                   3890: 	&log_differences($plain);
                   3891:     }
                   3892: # ---------------------------------------------------------------- End commands
                   3893: # ---------------------------------------------------------------- Print screen
                   3894:     my $idx=0;
                   3895:     my $shown=0;
                   3896:     if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381     bisitz   3897: 	$r->print('<div class="LC_Box">'.
1.432     raeburn  3898:           '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
                   3899: 		  ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
                   3900: 		  ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
                   3901: 		  ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
                   3902: 		  ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431     raeburn  3903: 		  '</ol>');
1.381     bisitz   3904:         if ($randompick>=0) {
                   3905:             $r->print('<p class="LC_warning">'
                   3906:                  .&mt('Caution: this folder is set to randomly pick a subset'
                   3907:                      .' of resources. Adding or removing resources from this'
                   3908:                      .' folder will change the set of resources that the'
                   3909:                      .' students see, resulting in spurious or missing credit'
                   3910:                      .' for completed problems, not limited to ones you'
                   3911:                      .' modify. Do not modify the contents of this folder if'
                   3912:                      .' it is in active student use.')
                   3913:                  .'</p>'
                   3914:             );
                   3915:         }
                   3916:         if ($is_random_order) {
                   3917:             $r->print('<p class="LC_warning">'
                   3918:                  .&mt('Caution: this folder is set to randomly order its'
                   3919:                      .' contents. Adding or removing resources from this folder'
                   3920:                      .' will change the order of resources shown.')
                   3921:                  .'</p>'
                   3922:             );
                   3923:         }
                   3924:         $r->print('</div>');
1.364     bisitz   3925:     }
1.381     bisitz   3926: 
1.685     raeburn  3927:     if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688     raeburn  3928:         my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn  3929:         if (ref($supplemental) eq 'HASH') {
                   3930:             if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
                   3931:                 (ref($supplemental->{'ids'}) eq 'HASH')) {
                   3932:                 if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
                   3933:                     my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
                   3934:                     if ($supplemental->{'hidden'}->{$mapnum}) {
                   3935:                         $ishidden = 1;
                   3936:                     }
                   3937:                 }
                   3938:             }
                   3939:         }
                   3940:     }
                   3941: 
1.538     raeburn  3942:     my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
                   3943:     %filters =  (
1.543     raeburn  3944:                   canremove      => [],
                   3945:                   cancut         => [],
                   3946:                   cancopy        => [],
                   3947:                   hiddenresource => [],
                   3948:                   encrypturl     => [],
                   3949:                   randomorder    => [],
                   3950:                   randompick     => [],
1.538     raeburn  3951:                 );
                   3952:     %curr_groups = &Apache::longroup::coursegroups();
1.424     onken    3953:     &Apache::loncommon::start_data_table_count(); #setup a row counter 
1.381     bisitz   3954:     foreach my $res (@LONCAPA::map::order) {
                   3955:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   3956:         $name=&LONCAPA::map::qtescape($name);
                   3957:         $url=&LONCAPA::map::qtescape($url);
                   3958:         unless ($name) {  $name=(split(/\//,$url))[-1]; }
                   3959:         unless ($name) { $idx++; next; }
1.537     raeburn  3960:         push(@allidx,$res);
                   3961:         if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
                   3962:             push(@allmapidx,$res);
                   3963:         }
1.617     raeburn  3964: 
1.682     raeburn  3965:         if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685     raeburn  3966:             if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
                   3967:                 $idx++;
                   3968:                 next;
                   3969:             }
1.682     raeburn  3970:         }
1.381     bisitz   3971:         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501     raeburn  3972:                               $coursenum,$coursedom,$crstype,
1.538     raeburn  3973:                               $pathitem,$supplementalflag,$container,
1.620     raeburn  3974:                               \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685     raeburn  3975:                               $isencrypted,$ishidden,$navmapref,$hostname);
1.381     bisitz   3976:         $idx++;
                   3977:         $shown++;
1.329     droeschl 3978:     }
1.424     onken    3979:     &Apache::loncommon::end_data_table_count();
1.510     raeburn  3980: 
1.538     raeburn  3981:     my $need_save;
1.611     raeburn  3982:     if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544     raeburn  3983:         my $toolslink;
1.682     raeburn  3984:         if ($allowed || $canedit) {
                   3985:             my $helpitem = 'Navigation_Screen';
                   3986:             if (!$allowed) {
                   3987:                 $helpitem = 'Supplemental_Navigation';
                   3988:             }
1.544     raeburn  3989:             $toolslink = '<table><tr><td>'
1.520     raeburn  3990:                        .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682     raeburn  3991:                                                            $helpitem,undef,'RAT')
1.520     raeburn  3992:                        .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
                   3993:                        .'<td align="left"><ul id="LC_toolbar">'
1.525     raeburn  3994:                        .'<li><a href="/adm/coursedocs?forcesupplement=1&amp;command=editsupp" '
1.520     raeburn  3995:                        .'id="LC_content_toolbar_edittoplevel" '
                   3996:                        .'class="LC_toolbarItem" '
                   3997:                        .'title="'.&mt('Supplemental Content Editor').'">'
                   3998:                        .'</a></li></ul></td></tr></table><br />';
1.544     raeburn  3999:         }
1.510     raeburn  4000:         if ($shown) {
                   4001:             if ($allowed) {
                   4002:                 $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
                   4003:                           .&Apache::loncommon::start_data_table(undef,'contentlist')
                   4004:                           .&Apache::loncommon::start_data_table_header_row()
                   4005:                           .'<th colspan="2">'.&mt('Move').'</th>'
1.633     raeburn  4006:                           .'<th colspan="3">'.&mt('Actions').'</th>'
1.682     raeburn  4007:                           .'<th>'.&mt('Document').'</th>'
                   4008:                           .'<th colspan="2">'.&mt('Settings').'</th>'
                   4009:                           .&Apache::loncommon::end_data_table_header_row();
1.537     raeburn  4010:                 if ($folder !~ /^supplemental/) {
1.538     raeburn  4011:                     $lists{'canhide'} = join(',',@allidx);
                   4012:                     $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543     raeburn  4013:                     my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
                   4014:                                        'randomorder','randompick');
                   4015:                     foreach my $item (@possfilters) {
1.538     raeburn  4016:                         if (ref($filters{$item}) eq 'ARRAY') {
1.543     raeburn  4017:                             if (@{$filters{$item}} > 0) {
                   4018:                                 $lists{$item} = join(',',@{$filters{$item}});
                   4019:                             }
1.538     raeburn  4020:                         }
                   4021:                     }
1.537     raeburn  4022:                     if (@allidx > 0) {
                   4023:                         my $path;
                   4024:                         if ($env{'form.folderpath'}) {
1.630     raeburn  4025:                             $path =
1.537     raeburn  4026:                                 &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   4027:                         }
1.538     raeburn  4028:                         if (@allidx > 1) {
1.630     raeburn  4029:                             $to_show .=
1.538     raeburn  4030:                                 &Apache::loncommon::continue_data_table_row().
                   4031:                                 '<td colspan="2">&nbsp;</td>'.
                   4032:                                 '<td>'.
1.611     raeburn  4033:                                 &multiple_check_form('actions',\%lists,$canedit).
1.538     raeburn  4034:                                 '</td>'.
1.633     raeburn  4035:                                 '<td colspan="3">&nbsp;</td>'.
                   4036:                                 '<td colspan="2">'.
1.611     raeburn  4037:                                 &multiple_check_form('settings',\%lists,$canedit).
1.538     raeburn  4038:                                 '</td>'.
                   4039:                                 &Apache::loncommon::end_data_table_row();
                   4040:                              $need_save = 1;
                   4041:                         }
1.537     raeburn  4042:                     }
                   4043:                 }
                   4044:                 $to_show .= $output.' '
1.510     raeburn  4045:                            .&Apache::loncommon::end_data_table()
                   4046:                            .'<br style="line-height:2px;" />'
                   4047:                            .&Apache::loncommon::end_scrollbox();
                   4048:             } else {
1.520     raeburn  4049:                 $to_show .= $toolslink
1.510     raeburn  4050:                            .&Apache::loncommon::start_data_table('LC_tableOfContent')
                   4051:                            .$output.' '
                   4052:                            .&Apache::loncommon::end_data_table();
1.393     raeburn  4053:             }
1.510     raeburn  4054:         } else {
1.520     raeburn  4055:             if (!$allowed) {
                   4056:                 $to_show .= $toolslink;
                   4057:             }
1.615     raeburn  4058:             my $noresmsg;
                   4059:             if ($allowed && $hiddentop && !$supplementalflag) {
                   4060:                 $noresmsg = &mt('Main Content Hidden'); 
                   4061:             } else {
                   4062:                 $noresmsg = &mt('Currently empty');
                   4063:             }
1.510     raeburn  4064:             $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
                   4065:                        .'<div class="LC_info" id="contentlist">'
1.615     raeburn  4066:                        .$noresmsg
1.510     raeburn  4067:                        .'</div>'
                   4068:                        .&Apache::loncommon::end_scrollbox();
1.393     raeburn  4069:         }
                   4070:     } else {
1.510     raeburn  4071:         if ($shown) {
                   4072:             $to_show = '<div>'
                   4073:                       .&Apache::loncommon::start_data_table('LC_tableOfContent')
                   4074:                       .$output
                   4075:                       .&Apache::loncommon::end_data_table()
                   4076:                       .'</div>';
                   4077:         } else {
                   4078:             $to_show = '<div class="LC_info" id="contentlist">'
1.550     raeburn  4079:                       .&mt('Currently empty')
1.510     raeburn  4080:                       .'</div>'
                   4081:         }
1.458     raeburn  4082:     }
                   4083:     my $tid = 1;
                   4084:     if ($supplementalflag) {
                   4085:         $tid = 2;
1.329     droeschl 4086:     }
                   4087:     if ($allowed) {
1.484     raeburn  4088:         my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538     raeburn  4089:         $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611     raeburn  4090:                                        $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
                   4091:         if ($canedit) {
                   4092:             &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
                   4093:         }
1.460     raeburn  4094:     } else {
                   4095:         $r->print($to_show);
1.329     droeschl 4096:     }
                   4097:     return;
                   4098: }
                   4099: 
1.538     raeburn  4100: sub multiple_check_form {
1.611     raeburn  4101:     my ($caller,$listsref,$canedit) = @_;
1.538     raeburn  4102:     return unless (ref($listsref) eq 'HASH');
1.611     raeburn  4103:     my $disabled;
                   4104:     unless ($canedit) {
1.700     raeburn  4105:         $disabled = ' disabled="disabled"';
1.611     raeburn  4106:     }
1.538     raeburn  4107:     my $output =
                   4108:     '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
                   4109:     '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
                   4110:     '<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>'.
                   4111:     '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
                   4112:     '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
                   4113:     '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
                   4114:     if ($caller eq 'settings') {
                   4115:         $output .= 
                   4116:             '<table><tr>'.
                   4117:             '<td class="LC_docs_entry_parameter">'.
                   4118:             '<span class="LC_nobreak"><label>'.
1.611     raeburn  4119:             '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538     raeburn  4120:             '</label></span></td>'.
                   4121:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  4122:             '<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  4123:             '</span></td>'.
                   4124:             '</tr>'."\n".
                   4125:             '<tr>'.
                   4126:             '<td class="LC_docs_entry_parameter">'.
1.611     raeburn  4127:             '<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  4128:             '</label></span>'.
                   4129:             '</td></tr></table>'."\n";
                   4130:     } else {
                   4131:         $output .=
                   4132:             '<table><tr>'.
                   4133:             '<td class="LC_docs_entry_parameter">'.
                   4134:             '<span class="LC_nobreak LC_docs_remove">'.
1.611     raeburn  4135:             '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538     raeburn  4136:             '</label></span></td>'.
                   4137:             '<td class="LC_docs_entry_parameter">'.
                   4138:             '<span class="LC_nobreak LC_docs_cut">'.
1.611     raeburn  4139:             '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538     raeburn  4140:             '</label></span></td>'."\n".
                   4141:             '<td class="LC_docs_entry_parameter">'.
                   4142:             '<span class="LC_nobreak LC_docs_copy">'.
1.700     raeburn  4143:             '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.538     raeburn  4144:             '</label></span></td>'.
                   4145:             '</tr></table>'."\n";
                   4146:     }
                   4147:     $output .= 
                   4148:         '</fieldset>'.
                   4149:         '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
                   4150:     if ($caller eq 'settings') {
                   4151:         $output .= 
1.543     raeburn  4152:         '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
                   4153:         '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
                   4154:         '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
                   4155:         '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
                   4156:         '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538     raeburn  4157:     } elsif ($caller eq 'actions') {
                   4158:         $output .=
                   4159:         '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
                   4160:         '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
                   4161:         '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
                   4162:     }
                   4163:     $output .= 
                   4164:         '</form>'.
                   4165:         '</div>';
                   4166:     return $output;
                   4167: }
                   4168: 
1.329     droeschl 4169: sub process_file_upload {
1.552     raeburn  4170:     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329     droeschl 4171: # upload a file, if present
1.552     raeburn  4172:     my $filesize = length($env{'form.uploaddoc'});
                   4173:     if (!$filesize) {
                   4174:         $$upload_output = '<div class="LC_error">'.
                   4175:                            &mt('Unable to upload [_1]. (size = [_2] bytes)',
                   4176:                           '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
                   4177:                           $filesize).'<br />'.
                   4178:                           &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
                   4179:                           '</div>';
                   4180:         return;
                   4181:     }
                   4182:     my $quotatype = 'unofficial';
                   4183:     if ($crstype eq 'Community') {
1.601     raeburn  4184:         $quotatype = 'community';
                   4185:     } elsif ($crstype eq 'Placement') {
                   4186:         $quotatype = 'placement';
1.580     raeburn  4187:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552     raeburn  4188:         $quotatype = 'official';
1.573     raeburn  4189:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   4190:         $quotatype = 'textbook';
1.552     raeburn  4191:     }
                   4192:     if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
                   4193:         $filesize = int($filesize/1000); #expressed in kb
                   4194:         $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579     raeburn  4195:                                                                       $env{'form.uploaddoc.filename'},$filesize,
                   4196:                                                                       'upload',$quotatype);
1.552     raeburn  4197:         return if ($$upload_output);
                   4198:     }
1.440     raeburn  4199:     my ($parseaction,$showupload,$nextphase,$mimetype);
                   4200:     if ($env{'form.parserflag'}) {
1.329     droeschl 4201:         $parseaction = 'parse';
                   4202:     }
                   4203:     my $folder=$env{'form.folder'};
                   4204:     if ($folder eq '') {
                   4205:         $folder='default';
                   4206:     }
                   4207:     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
                   4208:         my $errtext='';
                   4209:         my $fatal=0;
                   4210:         my $container='sequence';
1.519     raeburn  4211:         if ($env{'form.folderpath'} =~ /:1$/) {
1.329     droeschl 4212:             $container='page';
                   4213:         }
                   4214:         ($errtext,$fatal)=
1.534     raeburn  4215:             &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329     droeschl 4216:         if ($#LONCAPA::map::order<1) {
                   4217:             $LONCAPA::map::order[0]=1;
                   4218:             $LONCAPA::map::resources[1]='';
                   4219:         }
                   4220:         my $destination = 'docs/';
                   4221:         if ($folder =~ /^supplemental/) {
                   4222:             $destination = 'supplemental/';
                   4223:         }
                   4224:         if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   4225:             $destination .= 'default/';
                   4226:         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   4227:             $destination .=  $2.'/';
                   4228:         }
1.534     raeburn  4229:         if ($fatal) {
                   4230:             $$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>';
                   4231:             return;
                   4232:         }
1.440     raeburn  4233: # this is for a course, not a user, so set context to coursedoc.
1.329     droeschl 4234:         my $newidx=&LONCAPA::map::getresidx();
                   4235:         $destination .= $newidx;
1.439     raeburn  4236:         my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329     droeschl 4237: 						$parseaction,$allfiles,
1.440     raeburn  4238: 						$codebase,undef,undef,undef,undef,
                   4239:                                                 undef,undef,\$mimetype);
                   4240:         if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
                   4241:             my $stored = $1;
                   4242:             $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   4243:                           $stored.'</span>').'</p>';
                   4244:         } else {
                   4245:             my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
                   4246:             
1.457     raeburn  4247:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440     raeburn  4248:             return;
                   4249:         }
1.329     droeschl 4250:         my $ext='false';
                   4251:         if ($url=~m{^http://}) { $ext='true'; }
                   4252: 	$url     = &LONCAPA::map::qtunescape($url);
                   4253:         my $comment=$env{'form.comment'};
                   4254: 	$comment = &LONCAPA::map::qtunescape($comment);
                   4255:         if ($folder=~/^supplemental/) {
                   4256:               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   4257:                   $env{'user.domain'}.'___&&&___'.$comment;
                   4258:         }
                   4259: 
                   4260:         $LONCAPA::map::resources[$newidx]=
                   4261: 	    $comment.':'.$url.':'.$ext.':normal:res';
                   4262:         $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
                   4263:         ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492     raeburn  4264: 				    $folder.'.'.$container,1);
1.329     droeschl 4265:         if ($fatal) {
1.457     raeburn  4266:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440     raeburn  4267:             return;
1.329     droeschl 4268:         } else {
1.440     raeburn  4269:             if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
                   4270:                 $$upload_output = $showupload;
1.384     raeburn  4271:                 my $total_embedded = scalar(keys(%{$allfiles}));
1.329     droeschl 4272:                 if ($total_embedded > 0) {
1.440     raeburn  4273:                     my $uploadphase = 'upload_embedded';
                   4274:                     my $primaryurl = &HTML::Entities::encode($url,'<>&"');
                   4275: 		    my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx); 
1.630     raeburn  4276:                     my ($embedded,$num) =
1.440     raeburn  4277:                         &Apache::loncommon::ask_for_embedded_content(
                   4278:                             '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
                   4279:                     if ($embedded) {
                   4280:                         if ($num) {
                   4281:                             $$upload_output .=
                   4282: 			         '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
                   4283:                             $nextphase = $uploadphase;
                   4284:                         } else {
                   4285:                             $$upload_output .= $embedded;
                   4286:                         }
                   4287:                     } else {
                   4288:                         $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
                   4289:                     }
1.329     droeschl 4290:                 } else {
1.440     raeburn  4291:                     $$upload_output .= &mt('No embedded items identified').'<br />';
1.329     droeschl 4292:                 }
1.457     raeburn  4293:                 $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578     raeburn  4294:             } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
                   4295:                      ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476     raeburn  4296:                 $nextphase = 'decompress_uploaded';
                   4297:                 my $position = scalar(@LONCAPA::map::order)-1;
                   4298:                 my $noextract = &return_to_editor();
                   4299:                 my $archiveurl = &HTML::Entities::encode($url,'<>&"');
                   4300:                 my %archiveitems = (
                   4301:                     folderpath => $env{'form.folderpath'},
                   4302:                     cmd        => $nextphase,
                   4303:                     newidx     => $newidx,
                   4304:                     position   => $position,
                   4305:                     phase      => $nextphase,
1.477     raeburn  4306:                     comment    => $comment,
1.480     raeburn  4307:                 );
                   4308:                 my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
                   4309:                 my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx); 
1.476     raeburn  4310:                 $$upload_output = $showupload.
                   4311:                                   &Apache::loncommon::decompress_form($mimetype,
                   4312:                                       $archiveurl,'/adm/coursedocs',$noextract,
1.480     raeburn  4313:                                       \%archiveitems,\@current);
1.329     droeschl 4314:             }
                   4315:         }
                   4316:     }
1.440     raeburn  4317:     return $nextphase;
1.329     droeschl 4318: }
                   4319: 
1.480     raeburn  4320: sub get_dir_list {
                   4321:     my ($url,$coursenum,$coursedom,$newidx) = @_;
                   4322:     my ($destination,$dir_root) = &embedded_destination();
                   4323:     my ($dirlistref,$listerror) =  
                   4324:         &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
                   4325:     my @dir_lines;
                   4326:     my $dirptr=16384;
                   4327:     if (ref($dirlistref) eq 'ARRAY') {
                   4328:         foreach my $dir_line (sort
                   4329:                           {
                   4330:                               my ($afile)=split('&',$a,2);
                   4331:                               my ($bfile)=split('&',$b,2);
                   4332:                               return (lc($afile) cmp lc($bfile));
                   4333:                           } (@{$dirlistref})) {
                   4334:             my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
                   4335:             $filename =~ s/\s+$//;
                   4336:             next if ($filename =~ /^\.\.?$/); 
                   4337:             my $isdir = 0;
                   4338:             if ($dirptr&$testdir) {
                   4339:                 $isdir = 1;
                   4340:             }
                   4341:             push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
                   4342:         }
                   4343:     }
                   4344:     return @dir_lines;
                   4345: }
                   4346: 
1.329     droeschl 4347: sub is_supplemental_title {
                   4348:     my ($title) = @_;
                   4349:     return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
                   4350: }
                   4351: 
                   4352: # --------------------------------------------------------------- An entry line
                   4353: 
                   4354: sub entryline {
1.501     raeburn  4355:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598     raeburn  4356:         $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685     raeburn  4357:         $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687     raeburn  4358:     my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329     droeschl 4359:     if (&is_supplemental_title($title)) {
1.488     raeburn  4360: 	($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687     raeburn  4361:         $encodedtitle=$title;
1.329     droeschl 4362:     } else {
                   4363: 	$title=&HTML::Entities::encode($title,'"<>&\'');
1.687     raeburn  4364:         $encodedtitle=$title;
1.329     droeschl 4365: 	$renametitle=$title;
                   4366: 	$foldertitle=$title;
                   4367:     }
                   4368: 
1.611     raeburn  4369:     my ($disabled,$readonly,$js_lt);
                   4370:     unless ($canedit) {
                   4371:         $disabled = 'disabled="disabled"';
                   4372:         $readonly = 1;
                   4373:     }
                   4374: 
1.329     droeschl 4375:     my $orderidx=$LONCAPA::map::order[$index];
1.364     bisitz   4376: 
1.329     droeschl 4377:     $renametitle=~s/\\/\\\\/g;
                   4378:     $renametitle=~s/\&quot\;/\\\"/g;
1.585     raeburn  4379:     $renametitle=~s/"/%22/g;
1.581     raeburn  4380:     $renametitle=~s/ /%20/g;
                   4381:     $oldtitle = $renametitle;
1.576     raeburn  4382:     $renametitle=~s/\&#39;/\\\'/g;
1.379     bisitz   4383:     my $line=&Apache::loncommon::start_data_table_row();
1.538     raeburn  4384:     my ($form_start,$form_end,$form_common,$form_param);
1.329     droeschl 4385: # Edit commands
1.679     raeburn  4386:     my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329     droeschl 4387:     if ($env{'form.folderpath'}) {
                   4388: 	$esc_path=&escape($env{'form.folderpath'});
                   4389: 	$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   4390: 	# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
                   4391:     }
1.505     raeburn  4392:     my $isexternal;
1.510     raeburn  4393:     if ($residx) {
1.501     raeburn  4394:         my $currurl = $url;
                   4395:         $currurl =~ s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
1.505     raeburn  4396:         if ($currurl =~ m{^/adm/wrapper/ext/}) {
                   4397:             $isexternal = 1;
                   4398:         }
1.510     raeburn  4399:         if (!$supplementalflag) {
                   4400:             my $path = 'uploaded/'.
                   4401:                        $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   4402:                        $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
                   4403:             $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
                   4404:                                                  $residx,
                   4405:                                                  &Apache::lonnet::declutter($currurl));
                   4406:         }
1.501     raeburn  4407:     }
1.538     raeburn  4408:     my ($renamelink,%lt,$ishash);
                   4409:     if (ref($filtersref) eq 'HASH') {
                   4410:         $ishash = 1;
                   4411:     }
                   4412: 
1.329     droeschl 4413:     if ($allowed) {
1.538     raeburn  4414:         $form_start = '
                   4415:    <form action="/adm/coursedocs" method="post">
                   4416: ';
                   4417:         $form_common=(<<END);
                   4418:    <input type="hidden" name="folderpath" value="$path" />
                   4419:    <input type="hidden" name="symb" value="$symb" />
                   4420: END
                   4421:         $form_param=(<<END);
                   4422:    <input type="hidden" name="setparms" value="$orderidx" />
                   4423:    <input type="hidden" name="changeparms" value="0" />
                   4424: END
                   4425:         $form_end = '</form>';
                   4426: 
1.329     droeschl 4427: 	my $incindex=$index+1;
                   4428: 	my $selectbox='';
1.471     raeburn  4429: 	if (($#LONCAPA::map::order>0) &&
1.329     droeschl 4430: 	    ((split(/\:/,
1.344     bisitz   4431: 	     $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
                   4432: 	     ne '') &&
1.329     droeschl 4433: 	    ((split(/\:/,
1.344     bisitz   4434: 	     $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329     droeschl 4435: 	     ne '')) {
                   4436: 	    $selectbox=
                   4437: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611     raeburn  4438: 		'<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329     droeschl 4439: 	    for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
                   4440: 		if ($i==$incindex) {
1.358     bisitz   4441: 		    $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329     droeschl 4442: 		} else {
                   4443: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
                   4444: 		}
                   4445: 	    }
                   4446: 	    $selectbox.='</select>';
                   4447: 	}
1.501     raeburn  4448: 	%lt=&Apache::lonlocal::texthash(
1.329     droeschl 4449:                 'up' => 'Move Up',
                   4450: 		'dw' => 'Move Down',
                   4451: 		'rm' => 'Remove',
                   4452:                 'ct' => 'Cut',
                   4453: 		'rn' => 'Rename',
1.501     raeburn  4454: 		'cp' => 'Copy',
1.633     raeburn  4455:                 'da' => 'Unset alias', 
                   4456:                 'sa' => 'Set alias',
1.501     raeburn  4457:                 'ex' => 'External Resource',
1.598     raeburn  4458:                 'et' => 'External Tool',
1.501     raeburn  4459:                 'ed' => 'Edit',
                   4460:                 'pr' => 'Preview',
                   4461:                 'sv' => 'Save',
                   4462:                 'ul' => 'URL',
1.611     raeburn  4463:                 'ti' => 'Title',
1.618     raeburn  4464:                 'er' => 'Editing rights unavailable for your current role.', 
1.501     raeburn  4465:                 );
1.538     raeburn  4466: 	my %denied = &action_restrictions($coursenum,$coursedom,$url,
                   4467:                                           $env{'form.folderpath'},
                   4468:                                           $currgroups);
1.517     raeburn  4469:         my ($copylink,$cutlink,$removelink);
1.329     droeschl 4470: 	my $skip_confirm = 0;
1.603     raeburn  4471:         my $confirm_removal = 0;
1.329     droeschl 4472: 	if ( $folder =~ /^supplemental/
                   4473: 	     || ($url =~ m{( /smppg$
                   4474: 			    |/syllabus$
                   4475: 			    |/aboutme$
                   4476: 			    |/navmaps$
                   4477: 			    |/bulletinboard$
1.626     raeburn  4478:                             |/ext\.tool$
1.505     raeburn  4479: 			    |\.html$)}x)
                   4480:              || $isexternal) {
1.329     droeschl 4481: 	    $skip_confirm = 1;
                   4482: 	}
1.603     raeburn  4483:         if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   4484:             ($url!~/$LONCAPA::assess_page_seq_re/)) {
                   4485:             $confirm_removal = 1;
                   4486:         }
1.633     raeburn  4487:         if ($url =~ /$LONCAPA::assess_re/) {
                   4488:             $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
                   4489:         }
1.329     droeschl 4490: 
1.538     raeburn  4491: 	if ($denied{'copy'}) {
1.543     raeburn  4492:             $copylink=(<<ENDCOPY)
1.507     raeburn  4493: <span style="visibility: hidden;">$lt{'cp'}</span>
                   4494: ENDCOPY
                   4495:         } else {
1.538     raeburn  4496:             my $formname = 'edit_copy_'.$orderidx;
                   4497:             my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 4498: 	    $copylink=(<<ENDCOPY);
1.538     raeburn  4499: <form name="$formname" method="post" action="/adm/coursedocs">
                   4500: $form_common
1.611     raeburn  4501: <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  4502: $form_end
1.329     droeschl 4503: ENDCOPY
1.538     raeburn  4504:             if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
                   4505:                 push(@{$filtersref->{'cancopy'}},$orderidx);
                   4506:             }
1.329     droeschl 4507:         }
1.538     raeburn  4508: 	if ($denied{'cut'}) {
1.507     raeburn  4509:             $cutlink=(<<ENDCUT);
                   4510: <span style="visibility: hidden;">$lt{'ct'}</span>
                   4511: ENDCUT
                   4512:         } else {
1.538     raeburn  4513:             my $formname = 'edit_cut_'.$orderidx;
                   4514:             my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329     droeschl 4515: 	    $cutlink=(<<ENDCUT);
1.538     raeburn  4516: <form name="$formname" method="post" action="/adm/coursedocs">
                   4517: $form_common
1.542     raeburn  4518: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611     raeburn  4519: <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  4520: $form_end
1.329     droeschl 4521: ENDCUT
1.538     raeburn  4522:             if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
                   4523:                 push(@{$filtersref->{'cancut'}},$orderidx);
                   4524:             }
1.329     droeschl 4525:         }
1.538     raeburn  4526:         if ($denied{'remove'}) {
1.507     raeburn  4527:             $removelink=(<<ENDREM);
                   4528: <span style="visibility: hidden;">$lt{'rm'}</a>
                   4529: ENDREM
                   4530:         } else {
1.538     raeburn  4531:             my $formname = 'edit_remove_'.$orderidx;
1.603     raeburn  4532:             my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497     raeburn  4533:             $removelink=(<<ENDREM);
1.538     raeburn  4534: <form name="$formname" method="post" action="/adm/coursedocs">
                   4535: $form_common
1.542     raeburn  4536: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603     raeburn  4537: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611     raeburn  4538: <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  4539: $form_end
1.497     raeburn  4540: ENDREM
1.538     raeburn  4541:             if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
                   4542:                 push(@{$filtersref->{'canremove'}},$orderidx);
                   4543:             }
1.497     raeburn  4544:         }
1.551     raeburn  4545:         $renamelink=(<<ENDREN);
1.581     raeburn  4546: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507     raeburn  4547: ENDREN
1.611     raeburn  4548:         my ($uplink,$downlink);
                   4549:         if ($canedit) {
                   4550:             $uplink = "/adm/coursedocs?cmd=up_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   4551:             $downlink = "/adm/coursedocs?cmd=down_$index&amp;folderpath=$esc_path&amp;symb=$symb";
                   4552:         } else {
                   4553:             $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
                   4554:             $downlink = $uplink;
                   4555:         }
1.329     droeschl 4556: 	$line.=(<<END);
                   4557: <td>
1.379     bisitz   4558: <div class="LC_docs_entry_move">
1.611     raeburn  4559:   <a href="$uplink">
1.501     raeburn  4560:     <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379     bisitz   4561:   </a>
                   4562: </div>
                   4563: <div class="LC_docs_entry_move">
1.611     raeburn  4564:   <a href="$downlink">
1.501     raeburn  4565:     <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379     bisitz   4566:   </a>
                   4567: </div>
1.329     droeschl 4568: </td>
                   4569: <td>
                   4570:    $form_start
1.538     raeburn  4571:    $form_param
1.478     raeburn  4572:    $form_common
1.329     droeschl 4573:    $selectbox
                   4574:    $form_end
                   4575: </td>
1.540     raeburn  4576: <td class="LC_docs_entry_commands LC_nobreak">
1.497     raeburn  4577: $removelink
1.329     droeschl 4578: $cutlink
                   4579: $copylink
                   4580: </td>
                   4581: END
                   4582:     }
                   4583: # Figure out what kind of a resource this is
                   4584:     my ($extension)=($url=~/\.(\w+)$/);
                   4585:     my $uploaded=($url=~/^\/*uploaded\//);
                   4586:     my $icon=&Apache::loncommon::icon($url);
1.519     raeburn  4587:     my $isfolder;
                   4588:     my $ispage;
                   4589:     my $containerarg;
1.615     raeburn  4590:     my $folderurl;
1.685     raeburn  4591:     my $plainurl;
1.329     droeschl 4592:     if ($uploaded) {
1.472     raeburn  4593:         if (($extension eq 'sequence') || ($extension eq 'page')) {
                   4594:             $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519     raeburn  4595:             $containerarg = $1;
1.472     raeburn  4596: 	    if ($extension eq 'sequence') {
                   4597: 	        $icon=$iconpath.'navmap.folder.closed.gif';
                   4598:                 $isfolder=1;
                   4599:             } else {
                   4600:                 $icon=$iconpath.'page.gif';
                   4601:                 $ispage=1;
                   4602:             }
1.615     raeburn  4603:             $folderurl = &Apache::lonnet::declutter($url);
1.472     raeburn  4604:             if ($allowed) {
                   4605:                 $url='/adm/coursedocs?';
                   4606:             } else {
                   4607:                 $url='/adm/supplemental?';
                   4608:             }
1.329     droeschl 4609: 	} else {
1.685     raeburn  4610: 	    $plainurl = $url;
1.329     droeschl 4611: 	}
                   4612:     }
1.364     bisitz   4613: 
1.621     raeburn  4614:     my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329     droeschl 4615:     my $orig_url = $url;
1.340     raeburn  4616:     $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.668     raeburn  4617:     if ($container eq 'page') {
                   4618:         $url=~s{^http(|s)(&colon;|:)//}{/ext/};
                   4619:     } else {
                   4620:         $url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/};
                   4621:     }
1.501     raeburn  4622:     if (!$supplementalflag && $residx && $symb) {
                   4623:         if ((!$isfolder) && (!$ispage)) {
                   4624: 	    (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668     raeburn  4625:             if (($url =~ m{^ext/}) && ($container eq 'page')) {
                   4626:                 $url=&Apache::lonnet::clutter_with_no_wrapper($url);
                   4627:             } else {
                   4628:                 $url=&Apache::lonnet::clutter($url);
                   4629:             } 
1.501     raeburn  4630: 	    if ($url=~/^\/*uploaded\//) {
                   4631: 	        $url=~/\.(\w+)$/;
                   4632: 	        my $embstyle=&Apache::loncommon::fileembstyle($1);
                   4633: 	        if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                   4634: 		    $url='/adm/wrapper'.$url;
                   4635: 	        } elsif ($embstyle eq 'ssi') {
                   4636: 		    #do nothing with these
                   4637: 	        } elsif ($url!~/\.(sequence|page)$/) {
                   4638: 		    $url='/adm/coursedocs/showdoc'.$url;
                   4639: 	        }
1.623     raeburn  4640: 	    } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
                   4641:                 my $wrapped = $1;
                   4642:                 my $exturl = $2;
1.668     raeburn  4643:                 if (($wrapped eq '') && ($container ne 'page')) { 
1.623     raeburn  4644:                     $url='/adm/wrapper'.$url;
                   4645:                 }
                   4646:                 if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
                   4647:                     $nomodal = 1;
                   4648:                 }
1.626     raeburn  4649: 	    } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4650: 		$url='/adm/wrapper'.$url;
1.621     raeburn  4651:             } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
                   4652:                 if (($ENV{'SERVER_PORT'} == 443) &&
                   4653:                     ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  4654:                     unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  4655:                         $url .= '?usehttp=1';
                   4656:                     }
1.621     raeburn  4657:                     $nomodal = 1;
                   4658:                 }
1.598     raeburn  4659:             }
1.696     raeburn  4660:             my $checkencrypt;
1.680     raeburn  4661:             if (!$env{'request.role.adv'}) {
1.615     raeburn  4662:                 if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680     raeburn  4663:                     ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615     raeburn  4664:                     $checkencrypt = 1;
1.620     raeburn  4665:                 } elsif (ref($navmapref)) {
1.615     raeburn  4666:                     unless (ref($$navmapref)) {
                   4667:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   4668:                     }
                   4669:                     if (ref($$navmapref)) {
                   4670:                         if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680     raeburn  4671:                             $checkencrypt = 1;
1.615     raeburn  4672:                         }
                   4673:                     }
                   4674:                 }
1.680     raeburn  4675:             }
                   4676:             if ($checkencrypt) {
                   4677:                 my $currenc = $env{'request.enc'};
                   4678:                 $env{'request.enc'} = 1;
                   4679:                 $shownsymb = &Apache::lonenc::encrypted($symb);
1.696     raeburn  4680:                 my $shownurl = &Apache::lonenc::encrypted($url);
1.680     raeburn  4681:                 if (&Apache::lonnet::symbverify($symb,$url)) {
                   4682:                     $url = $shownurl;
                   4683:                 } else {
                   4684:                     $url = '';
                   4685:                 }
                   4686:                 $env{'request.enc'} = $currenc;
                   4687:             } elsif (&Apache::lonnet::symbverify($symb,$url)) {
                   4688:                 $shownsymb = $symb;
                   4689:                 if ($isexternal) {
                   4690:                     $url =~ s/\#[^#]+$//;
                   4691:                     if ($container eq 'page') {
                   4692:                         $url = &Apache::lonnet::clutter($url);
1.613     raeburn  4693:                     }
1.612     raeburn  4694:                 }
1.696     raeburn  4695:             } else {
                   4696:                 $url = '';
1.680     raeburn  4697:             }
                   4698:             unless ($env{'request.role.adv'}) {
                   4699:                 if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4700:                     $url = '';
                   4701:                 }
                   4702:                 if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
                   4703:                     $url = '';
                   4704:                     $hiddenres = 1;
                   4705:                 }
                   4706:             }
1.696     raeburn  4707:             if (($url ne '') && ($shownsymb ne '')) {
                   4708:                 $url .= (($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501     raeburn  4709:             }
1.329     droeschl 4710: 	}
1.621     raeburn  4711:     } elsif ($supplementalflag) {
1.610     raeburn  4712:         if ($isexternal) {
                   4713:             if ($url =~ /^([^#]+)#([^#]+)$/) {
                   4714:                 $url = $1;
                   4715:                 $anchor = $2;
1.623     raeburn  4716:                 if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678     raeburn  4717:                     unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  4718:                         if ($hostname ne '') {
                   4719:                             $url = 'http://'.$hostname.$url;
                   4720:                         }
                   4721:                         $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.623     raeburn  4722:                     }
                   4723:                     $nomodal = 1;
                   4724:                 }
1.610     raeburn  4725:             }
1.621     raeburn  4726:         } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   4727:             if (($ENV{'SERVER_PORT'} == 443) &&
                   4728:                 ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  4729:                 unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  4730:                     if ($hostname ne '') {
                   4731:                         $url = 'http://'.$hostname.$url;
                   4732:                     }
                   4733:                     $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  4734:                 }
1.621     raeburn  4735:                 $nomodal = 1;
                   4736:             }
1.705     raeburn  4737:         } elsif (($uploaded) && ($url ne '/adm/supplemental?') && ($url ne '/adm/coursedocs?')) {
1.686     raeburn  4738:             my $embstyle=&Apache::loncommon::fileembstyle($extension);
                   4739:             unless ($embstyle eq 'ssi') {
                   4740:                 if (($embstyle eq 'img')
                   4741:                  || ($embstyle eq 'emb')
                   4742:                  || ($embstyle eq 'wrp')) {
                   4743:                     $url='/adm/wrapper'.$url;
                   4744:                 } elsif ($url !~ /\.(sequence|page)$/) {
                   4745:                     $url='/adm/coursedocs/showdoc'.$url;
                   4746:                 }
                   4747:             }
1.610     raeburn  4748:         }
1.685     raeburn  4749:         unless ($allowed && $env{'request.role.adv'}) {
                   4750:             if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4751:                 $hiddenres = 1;
                   4752:             }
                   4753:         }
1.329     droeschl 4754:     }
1.615     raeburn  4755:     my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617     raeburn  4756:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519     raeburn  4757:     if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329     droeschl 4758: 	my $foldername=&escape($foldertitle);
                   4759: 	my $folderpath=$env{'form.folderpath'};
                   4760: 	if ($folderpath) { $folderpath.='&' };
1.510     raeburn  4761:         if (!$allowed && $supplementalflag) {
1.519     raeburn  4762:             $folderpath.=$containerarg.'&'.$foldername;
1.510     raeburn  4763:             $url.='folderpath='.&escape($folderpath);
1.685     raeburn  4764:             if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4765:                 $hiddenfolder = 1;
1.682     raeburn  4766:             }
1.510     raeburn  4767:         } else {
1.617     raeburn  4768:             my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
                   4769:                                                         'parameter_randompick'))[0];
                   4770:             my $randorder = ((&LONCAPA::map::getparameter($orderidx,
                   4771:                                               'parameter_randomorder'))[0]=~/^yes$/i);
                   4772:             my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
                   4773:                                               'parameter_hiddenresource'))[0]=~/^yes$/i);
                   4774:             my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
                   4775:                                               'parameter_encrypturl'))[0]=~/^yes$/i);
                   4776:             unless ($hiddenmap) {
1.620     raeburn  4777:                 if (ref($navmapref)) {
                   4778:                     unless (ref($$navmapref)) {
                   4779:                         $$navmapref = Apache::lonnavmaps::navmap->new();
                   4780:                     }
                   4781:                     if (ref($$navmapref)) {
                   4782:                         if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
                   4783:                             my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
                   4784:                             unless (@resources) {
                   4785:                                 $hiddenmap = 1;
                   4786:                                 unless ($env{'request.role.adv'}) {  
                   4787:                                     $url = '';
                   4788:                                     $hiddenfolder = 1;
                   4789:                                 }
1.617     raeburn  4790:                             }
1.615     raeburn  4791:                         }
                   4792:                     }
                   4793:                 }
                   4794:             }
1.617     raeburn  4795:             unless ($encryptmap) {
1.620     raeburn  4796:                 if ((ref($navmapref)) && (ref($$navmapref))) {
                   4797:                     if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
                   4798:                         $encryptmap = 1;
                   4799:                     }
1.617     raeburn  4800:                 }
                   4801:             }
1.630     raeburn  4802: 
1.617     raeburn  4803: # Append randompick number, hidden, and encrypted with ":" to foldername,
                   4804: # so it gets transferred between levels
                   4805: 	    $folderpath.=$containerarg.'&'.$foldername.
                   4806:                          ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615     raeburn  4807:             unless ($url eq '') {
1.612     raeburn  4808:                 $url.='folderpath='.&escape($folderpath);
                   4809:             }
1.510     raeburn  4810:             my $rpckchk;
                   4811:             if ($rpicknum) {
                   4812:                 $rpckchk = ' checked="checked"';
1.543     raeburn  4813:                 if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
                   4814:                     push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
                   4815:                 }
1.510     raeburn  4816:             }
1.537     raeburn  4817:             my $formname = 'edit_randompick_'.$orderidx;
1.510     raeburn  4818: 	    $rand_pick_text = 
1.478     raeburn  4819: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  4820: $form_param."\n".
1.478     raeburn  4821: $form_common."\n".
1.611     raeburn  4822: '<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  4823:             if ($rpicknum ne '') {
                   4824:                 $rand_pick_text .= ':&nbsp;<a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
                   4825:             }
1.537     raeburn  4826:             $rand_pick_text .= '</span></span>'.
                   4827:                                $form_end;
1.543     raeburn  4828:             my $ro_set;
1.617     raeburn  4829:             if ($randorder) {
1.543     raeburn  4830:                 $ro_set = 'checked="checked"';
                   4831:                 if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
                   4832:                     push(@{$filtersref->{'randomorder'}},$orderidx);
                   4833:                 }
                   4834:             }
1.564     raeburn  4835:             $formname = 'edit_rorder_'.$orderidx;
1.510     raeburn  4836: 	    $rand_order_text = 
1.537     raeburn  4837: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538     raeburn  4838: $form_param."\n".
1.537     raeburn  4839: $form_common."\n".
1.611     raeburn  4840: '<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  4841: $form_end; 
1.510     raeburn  4842:         }
1.705     raeburn  4843:     } elsif ($supplementalflag) {
1.598     raeburn  4844:         my $isexttool;
1.626     raeburn  4845:         if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4846:             $url='/adm/wrapper'.$url;
                   4847:             $isexttool = 1;
                   4848:         }
1.510     raeburn  4849:         $url .= ($url =~ /\?/) ? '&amp;':'?';
1.509     raeburn  4850:         $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510     raeburn  4851:         if ($title) {
1.687     raeburn  4852:             $url .= '&amp;title='.$encodedtitle;
1.510     raeburn  4853:         }
1.598     raeburn  4854:         if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510     raeburn  4855:             $url .= '&amp;idx='.$orderidx;
                   4856:         }
1.610     raeburn  4857:         if ($anchor ne '') {
                   4858:             $url .= '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   4859:         }
1.329     droeschl 4860:     }
1.519     raeburn  4861:     my ($tdalign,$tdwidth);
1.501     raeburn  4862:     if ($allowed) {
1.630     raeburn  4863:         my $fileloc =
1.501     raeburn  4864:             &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510     raeburn  4865:         if ($isexternal) {
1.630     raeburn  4866:             ($editlink,$extresform) =
1.611     raeburn  4867:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   4868:                                                      undef,undef,undef,undef,undef,undef,
                   4869:                                                      undef,$disabled);
1.626     raeburn  4870:         } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598     raeburn  4871:             ($editlink,$extresform) =
                   4872:                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                   4873:                                                      undef,undef,undef,'tool',$coursedom,
1.611     raeburn  4874:                                                      $coursenum,$ltitoolsref,$disabled);
1.511     raeburn  4875:         } elsif (!$isfolder && !$ispage) {
1.503     raeburn  4876:             my ($cfile,$home,$switchserver,$forceedit,$forceview) = 
                   4877:                 &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511     raeburn  4878:             if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610     raeburn  4879:                 my $suppanchor;
                   4880:                 if ($supplementalflag) {
                   4881:                     $suppanchor = $anchor;
                   4882:                 }
1.630     raeburn  4883:                 my $jscall =
1.501     raeburn  4884:                     &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
                   4885:                                                             $switchserver,
1.503     raeburn  4886:                                                             $forceedit,
1.679     raeburn  4887:                                                             undef,$symb,$shownsymb,
1.511     raeburn  4888:                                                             &escape($env{'form.folderpath'}),
1.622     raeburn  4889:                                                             $renametitle,$hostname,
                   4890:                                                             '','',1,$suppanchor);
1.501     raeburn  4891:                 if ($jscall) {
1.518     raeburn  4892:                     $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
                   4893:                                 $jscall.'" >'.&mt('Edit').'</a>&nbsp;'."\n";
1.501     raeburn  4894:                 }
                   4895:             }
                   4896:         }
1.519     raeburn  4897:         $tdalign = ' align="right" valign="top"';
                   4898:         $tdwidth = ' width="80%"';
1.329     droeschl 4899:     }
1.408     raeburn  4900:     my $reinit;
                   4901:     if ($crstype eq 'Community') {
                   4902:         $reinit = &mt('(re-initialize community to access)');
                   4903:     } else {
                   4904:         $reinit = &mt('(re-initialize course to access)');
1.519     raeburn  4905:     }
1.702     raeburn  4906:     $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink.'</span>';
1.650     raeburn  4907:     if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633     raeburn  4908:         $line.= '<br />';
                   4909:         if ($curralias ne '') {
                   4910:             $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   4911:                    $lt{'da'}.'</a></span>';
                   4912:         } else {
                   4913:             $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                   4914:                    $lt{'sa'}.'</a></span>';
                   4915:         }
                   4916:     }
1.701     raeburn  4917:     $line.='</td><td><span class="LC_nobreak">';
1.685     raeburn  4918:     my ($link,$nolink);
1.472     raeburn  4919:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685     raeburn  4920:         if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
                   4921:             if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4922:                 $nolink = 1;
                   4923:             }
                   4924:         }
                   4925:         if ($nolink) {
                   4926:             $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
                   4927:         } else {
                   4928:             $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
                   4929:         }
1.469     www      4930:     } elsif ($url) {
1.610     raeburn  4931:        if ($anchor ne '') {
                   4932:            if ($supplementalflag) {
                   4933:                $anchor = '&amp;anchor='.&HTML::Entities::encode($anchor,'"<>&');
                   4934:            } else {
                   4935:                $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
                   4936:            }
                   4937:        }
1.705     raeburn  4938:        if (($nomodal) && ($hostname ne '')) {
1.622     raeburn  4939:            $link = 'http://'.$hostname.$url;
                   4940:        } else {
                   4941:            $link = $url;
                   4942:        }
1.705     raeburn  4943:        my $inhibitmenu;
                   4944:        if ((($supplementalflag) && ($allowed) && ($url =~ m{^/adm/wrapper/})) ||
                   4945:            (($allowed) && (($url =~ m{^/adm/(viewclasslist|$match_domain/$match_username/aboutme)(\?|$)}) ||
                   4946:                            ($url =~ m{^/public/$match_domain/$match_courseid/syllabus(\?|$)})))) {
                   4947:            $inhibitmenu = 'only_body=1';
                   4948:        } else {
                   4949:            $inhibitmenu = 'inhibitmenu=yes';
                   4950:        }
                   4951:        $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').$inhibitmenu.$anchor);
1.685     raeburn  4952:        if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
                   4953:            if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   4954:                $nolink = 1;
                   4955:            }
                   4956:        }
                   4957:        if ($nolink) {
                   4958:            $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
                   4959:        } elsif ($nomodal) {
1.621     raeburn  4960:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   4961:                   '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
                   4962:        } else {
                   4963:            $line.=&Apache::loncommon::modal_link($link,
                   4964:                                                  '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
                   4965:        }
1.469     www      4966:     } else {
                   4967:        $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
                   4968:     }
1.519     raeburn  4969:     $line.='</span></td><td'.$tdwidth.'>';
1.472     raeburn  4970:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685     raeburn  4971:        if ($nolink) {
                   4972:            $line.=$title;
                   4973:        } else {
                   4974:            $line.='<a href="'.$url.'">'.$title.'</a>';
                   4975:        }
1.682     raeburn  4976:        if (!$allowed && $supplementalflag && $canedit && $isfolder) {
                   4977:            my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
                   4978:            my $editurl = $url;
                   4979:            $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&amp;forcesupplement=1&amp;};
                   4980:            $line .= '&nbsp;'.'<a href="'.$editurl.'">'.
                   4981:                     '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
                   4982:                     '</a>';
                   4983:        }
                   4984:        if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag))  {
                   4985:            $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
                   4986:        }
1.469     www      4987:     } elsif ($url) {
1.685     raeburn  4988:        if ($nolink) {
                   4989:            $line.=$title;
                   4990:        } elsif ($nomodal) {
1.621     raeburn  4991:            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   4992:                   $title.'</a>';
                   4993:        } else {
                   4994:            $line.=&Apache::loncommon::modal_link($link,$title,600,500);
                   4995:        }
1.617     raeburn  4996:     } elsif (($hiddenfolder) || ($hiddenres)) {
1.632     raeburn  4997:        $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469     www      4998:     } else {
                   4999:        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
                   5000:     }
1.633     raeburn  5001:     if (($allowed) && ($curralias ne '')) {
                   5002:         $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
                   5003:     } else {
                   5004:         $line .= $extresform;
                   5005:     }
                   5006:     $line .= '</td>';
1.478     raeburn  5007:     $rand_pick_text = '&nbsp;' if ($rand_pick_text eq '');
                   5008:     $rand_order_text = '&nbsp;' if ($rand_order_text eq '');
1.685     raeburn  5009:     if ($uploaded && $url && !$isfolder && !$ispage) {
                   5010:         if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
                   5011:             &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
                   5012:         }
                   5013:     }
1.682     raeburn  5014:     if ($allowed) {
                   5015:         my %lt=&Apache::lonlocal::texthash(
                   5016:                               'hd' => 'Hidden',
                   5017:                               'ec' => 'URL hidden');
                   5018:         my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543     raeburn  5019:         if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
                   5020:             $hidtext = ' checked="checked"';
1.694     raeburn  5021:             if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543     raeburn  5022:                 push(@{$filtersref->{'hiddenresource'}},$orderidx);
                   5023:             }
                   5024:         }
1.682     raeburn  5025:         $formhidden = 'edit_hiddenresource_'.$orderidx;
                   5026:         $line.=(<<ENDPARMS);
1.329     droeschl 5027:   <td class="LC_docs_entry_parameter">
1.537     raeburn  5028:     <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538     raeburn  5029:     $form_param
1.478     raeburn  5030:     $form_common
1.611     raeburn  5031:     <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329     droeschl 5032:     $form_end
1.682     raeburn  5033: ENDPARMS
                   5034:         if ($folder =~/^supplemental/) {
                   5035:             $line.= "\n    <td>";
                   5036:         } else {
                   5037:             if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
                   5038:                 $enctext = ' checked="checked"';
                   5039:                 if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
                   5040:                     push(@{$filtersref->{'encrypturl'}},$orderidx);
                   5041:                 }
                   5042:             }
                   5043:             $formurlhidden = 'edit_encrypturl_'.$orderidx;
                   5044: 	    $line.=(<<ENDPARMS);
1.458     raeburn  5045:     <br />
1.537     raeburn  5046:     <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538     raeburn  5047:     $form_param
1.478     raeburn  5048:     $form_common
1.611     raeburn  5049:     <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329     droeschl 5050:     $form_end
                   5051:   </td>
1.478     raeburn  5052:   <td class="LC_docs_entry_parameter">$rand_pick_text<br />
                   5053:                                       $rand_order_text</td>
1.329     droeschl 5054: ENDPARMS
1.682     raeburn  5055:         }
1.329     droeschl 5056:     }
1.379     bisitz   5057:     $line.=&Apache::loncommon::end_data_table_row();
1.329     droeschl 5058:     return $line;
                   5059: }
                   5060: 
1.538     raeburn  5061: sub action_restrictions {
                   5062:     my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
                   5063:     my %denied = (
                   5064:                    cut    => 0,
                   5065:                    copy   => 0,
                   5066:                    remove => 0,
                   5067:                  );
                   5068:     if ($url=~ m{^/res/.+\.(page|sequence)$}) {
                   5069:         # no copy for published maps
                   5070:         $denied{'copy'} = 1;
1.597     raeburn  5071:     } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
                   5072:         unless ($1 eq 'simpleproblem') {
                   5073:             $denied{'copy'} = 1;
                   5074:         }
                   5075:         $denied{'cut'} = 1;
1.538     raeburn  5076:     } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
                   5077:         if ($folderpath =~ /^default&[^\&]+$/) {
                   5078:             if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
                   5079:                 $denied{'remove'} = 1;
                   5080:             }
                   5081:             $denied{'cut'} = 1;
                   5082:             $denied{'copy'} = 1;
                   5083:         }
                   5084:     } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
                   5085:         my $group = $1;
                   5086:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
                   5087:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   5088:                 $denied{'remove'} = 1;
                   5089:             }
                   5090:         }
                   5091:         $denied{'cut'} = 1;
                   5092:         $denied{'copy'} = 1;
                   5093:     } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
                   5094:         my $group = $1;
                   5095:         if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
                   5096:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   5097:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   5098:                 if (keys(%groupsettings) > 0) {
                   5099:                     $denied{'remove'} = 1;
                   5100:                 }
                   5101:                 $denied{'cut'} = 1;
                   5102:                 $denied{'copy'} = 1;
                   5103:             }
                   5104:         }
                   5105:     } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
                   5106:         my $group = $1;
                   5107:         if ($url =~ /group_boards_\Q$group\E/) {
                   5108:             if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
                   5109:                 my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
                   5110:                 if (keys(%groupsettings) > 0) {
                   5111:                     if (ref($groupsettings{'functions'}) eq 'HASH') {
                   5112:                         if ($groupsettings{'functions'}{'discussion'} eq 'on') {
                   5113:                             $denied{'remove'} = 1;
                   5114:                         }
                   5115:                     }
                   5116:                 }
                   5117:                 $denied{'cut'} = 1;
                   5118:                 $denied{'copy'} = 1;
                   5119:             }
                   5120:         }
                   5121:     }
                   5122:     return %denied;
                   5123: }
                   5124: 
1.533     raeburn  5125: sub new_timebased_suffix {
1.538     raeburn  5126:     my ($dom,$num,$type,$area,$container) = @_;
1.533     raeburn  5127:     my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538     raeburn  5128:     if ($type eq 'paste') {
                   5129:         $prefix = $type;
                   5130:         $namespace = 'courseeditor';
1.587     raeburn  5131:         $idtype = 'addcode';
1.538     raeburn  5132:     } elsif ($type eq 'map') {
1.533     raeburn  5133:         $prefix = 'docs';
                   5134:         if ($area eq 'supplemental') {
                   5135:             $prefix = 'supp';
                   5136:         }
                   5137:         $prefix .= $container;
                   5138:         $namespace = 'uploadedmaps';
                   5139:     } else {
                   5140:         $prefix = $type;
                   5141:         $namespace = 'templated';
1.504     raeburn  5142:     }
                   5143:     my ($suffix,$freedlock,$error) =
1.587     raeburn  5144:         &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504     raeburn  5145:     if (!$suffix) {
1.538     raeburn  5146:         if ($type eq 'paste') {
                   5147:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
                   5148:         } elsif ($type eq 'map') {
1.533     raeburn  5149:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
                   5150:         } elsif ($type eq 'smppg') {
                   5151:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626     raeburn  5152:         } elsif ($type eq 'exttool') {
                   5153:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533     raeburn  5154:         } else {
1.565     bisitz   5155:             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533     raeburn  5156:         }
1.504     raeburn  5157:         if ($error) {
                   5158:             $errtext .= '<br />'.$error;
                   5159:         }
                   5160:     }
                   5161:     if ($freedlock ne 'ok') {
1.630     raeburn  5162:         $locknotfreed =
1.533     raeburn  5163:             '<div class="LC_error">'.
                   5164:             &mt('There was a problem removing a lockfile.').' ';
1.538     raeburn  5165:         if ($type eq 'paste') {
1.591     raeburn  5166:             if ($freedlock eq 'nolock') {
                   5167:                 $locknotfreed =
                   5168:                     '<div class="LC_error">'.
                   5169:                     &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
                   5170:  
1.593     droeschl 5171:                     &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591     raeburn  5172:             } else { 
                   5173:                 $locknotfreed .=
                   5174:                     &mt('This will prevent addition of items to the clipboard until your next log-in.');
                   5175:             }
1.538     raeburn  5176:         } elsif ($type eq 'map') {
1.591     raeburn  5177:             $locknotfreed .=
                   5178:                 &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533     raeburn  5179:         } elsif ($type eq 'smppg') {
                   5180:             $locknotfreed .=
                   5181:                 &mt('This will prevent creation of additional simple pages in this course.');
1.626     raeburn  5182:         } elsif ($type eq 'exttool') {
                   5183:             $locknotfreed .=
                   5184:                 &mt('This will prevent creation of additional external tools in this course.');
1.533     raeburn  5185:         } else {
                   5186:             $locknotfreed .=
1.565     bisitz   5187:                 &mt('This will prevent creation of additional discussion boards in this course.');
1.533     raeburn  5188:         }
1.538     raeburn  5189:         unless ($type eq 'paste') {
                   5190:             $locknotfreed .=
1.560     raeburn  5191:                 ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                   5192:                         '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538     raeburn  5193:         }
                   5194:         $locknotfreed .= '</div>';
1.504     raeburn  5195:     }
                   5196:     return ($suffix,$errtext,$locknotfreed);
                   5197: }
                   5198: 
1.329     droeschl 5199: =pod
                   5200: 
                   5201: =item tiehash()
                   5202: 
                   5203: tie the hash
                   5204: 
                   5205: =cut
                   5206: 
                   5207: sub tiehash {
                   5208:     my ($mode)=@_;
                   5209:     $hashtied=0;
                   5210:     if ($env{'request.course.fn'}) {
                   5211: 	if ($mode eq 'write') {
                   5212: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   5213: 		    &GDBM_WRCREAT(),0640)) {
                   5214:                 $hashtied=2;
                   5215: 	    }
                   5216: 	} else {
                   5217: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   5218: 		    &GDBM_READER(),0640)) {
                   5219:                 $hashtied=1;
                   5220: 	    }
                   5221: 	}
1.364     bisitz   5222:     }
1.329     droeschl 5223: }
                   5224: 
                   5225: sub untiehash {
                   5226:     if ($hashtied) { untie %hash; }
                   5227:     $hashtied=0;
                   5228:     return OK;
                   5229: }
                   5230: 
                   5231: 
                   5232: 
                   5233: 
                   5234: sub checkonthis {
1.637     raeburn  5235:     my ($r,$url,$level,$title,$checkstale)=@_;
1.329     droeschl 5236:     $url=&unescape($url);
                   5237:     $alreadyseen{$url}=1;
                   5238:     $r->rflush();
                   5239:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
                   5240:        $r->print("\n<br />");
                   5241:        if ($level==0) {
                   5242:            $r->print("<br />");
                   5243:        }
                   5244:        for (my $i=0;$i<=$level*5;$i++) {
                   5245:            $r->print('&nbsp;');
                   5246:        }
                   5247:        $r->print('<a href="'.$url.'" target="cat">'.
                   5248: 		 ($title?$title:$url).'</a> ');
                   5249:        if ($url=~/^\/res\//) {
1.637     raeburn  5250:           my $updated;
                   5251:           if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
                   5252:               ($url !~ /\.\d+\.\w+$/)) {
                   5253:               $updated = &Apache::lonnet::remove_stale_resfile($url);
                   5254:           }
1.329     droeschl 5255: 	  my $result=&Apache::lonnet::repcopy(
                   5256:                               &Apache::lonnet::filelocation('',$url));
                   5257:           if ($result eq 'ok') {
                   5258:              $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637     raeburn  5259:              if ($updated) {
                   5260:                  $r->print('<br />');
                   5261:                  for (my $i=0;$i<=$level*5;$i++) {
                   5262:                      $r->print('&nbsp;');
                   5263:                  }
                   5264:                  $r->print('- '.&mt('Outdated copy removed'));
                   5265:              }
1.329     droeschl 5266:              $r->rflush();
                   5267:              &Apache::lonnet::countacc($url);
                   5268:              $url=~/\.(\w+)$/;
                   5269:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                   5270: 		 $r->print('<br />');
                   5271:                  $r->rflush();
                   5272:                  for (my $i=0;$i<=$level*5;$i++) {
                   5273:                      $r->print('&nbsp;');
                   5274:                  }
                   5275:                  $r->print('- '.&mt('Rendering:').' ');
                   5276: 		 my ($errorcount,$warningcount)=split(/:/,
                   5277: 	       &Apache::lonnet::ssi_body($url,
                   5278: 			       ('grade_target'=>'web',
                   5279: 				'return_only_error_and_warning_counts' => 1)));
                   5280:                  if (($errorcount) ||
                   5281:                      ($warningcount)) {
                   5282: 		     if ($errorcount) {
1.369     bisitz   5283:                         $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329     droeschl 5284:                           &mt('[quant,_1,error]',$errorcount).'</span>');
                   5285:                      }
                   5286: 		     if ($warningcount) {
                   5287:                         $r->print('<span class="LC_warning">'.
                   5288:                           &mt('[quant,_1,warning]',$warningcount).'</span>');
                   5289:                      }
                   5290:                  } else {
                   5291:                      $r->print('<span class="LC_success">'.&mt('ok').'</span>');
                   5292:                  }
                   5293:                  $r->rflush();
                   5294:              }
                   5295: 	     my $dependencies=
                   5296:                 &Apache::lonnet::metadata($url,'dependencies');
                   5297:              foreach my $dep (split(/\,/,$dependencies)) {
                   5298: 		 if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637     raeburn  5299:                     &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329     droeschl 5300:                  }
                   5301:              }
                   5302:           } elsif ($result eq 'unavailable') {
                   5303:              $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
                   5304:           } elsif ($result eq 'not_found') {
                   5305: 	      unless ($url=~/\$/) {
1.521     bisitz   5306: 		  $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329     droeschl 5307: 	      } else {
1.366     bisitz   5308: 		  $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329     droeschl 5309: 	      }
                   5310:           } else {
                   5311:              $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
                   5312:           }
1.637     raeburn  5313:           if (($updated) && ($result ne 'ok')) {
                   5314:               $r->print('<br />'.&mt('Outdated copy removed'));
                   5315:           }
1.329     droeschl 5316:        }
                   5317:     }
                   5318: }
                   5319: 
                   5320: 
                   5321: 
                   5322: =pod
                   5323: 
                   5324: =item list_symbs()
                   5325: 
1.485     raeburn  5326: List Content Identifiers
1.329     droeschl 5327: 
                   5328: =cut
                   5329: 
                   5330: sub list_symbs {
                   5331:     my ($r) = @_;
                   5332: 
1.408     raeburn  5333:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  5334:     $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
                   5335:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
                   5336:     $r->print(&startContentScreen('tools'));
1.329     droeschl 5337:     my $navmap = Apache::lonnavmaps::navmap->new();
                   5338:     if (!defined($navmap)) {
                   5339:         $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
                   5340:                   '<div class="LC_error">'.
                   5341:                   &mt('Unable to retrieve information about course contents').
                   5342:                   '</div>');
1.408     raeburn  5343:         &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329     droeschl 5344:     } else {
1.484     raeburn  5345:         $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
                   5346:                   &Apache::loncommon::start_data_table().
                   5347:                   &Apache::loncommon::start_data_table_header_row().
                   5348:                   '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
                   5349:                   &Apache::loncommon::end_data_table_header_row()."\n");
                   5350:         my $count;
1.329     droeschl 5351:         foreach my $res ($navmap->retrieveResources()) {
1.484     raeburn  5352:             $r->print(&Apache::loncommon::start_data_table_row().
                   5353:                       '<td>'.$res->compTitle().'</td>'.
                   5354:                       '<td>'.$res->symb().'</td>'.
1.521     bisitz   5355:                       &Apache::loncommon::end_data_table_row());
1.484     raeburn  5356:             $count ++;
                   5357:         }
                   5358:         if (!$count) {
                   5359:             $r->print(&Apache::loncommon::start_data_table_row().
                   5360:                       '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
                   5361:                       &Apache::loncommon::end_data_table_row()); 
1.329     droeschl 5362:         }
1.484     raeburn  5363:         $r->print(&Apache::loncommon::end_data_table());
1.329     droeschl 5364:     }
1.521     bisitz   5365:     $r->print(&endContentScreen());
1.329     droeschl 5366: }
                   5367: 
1.651     raeburn  5368: sub short_urls {
                   5369:     my ($r,$canedit) = @_;
                   5370:     my $crstype = &Apache::loncommon::course_type();
                   5371:     my $formname = 'shortenurl';
                   5372:     $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
                   5373:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
                   5374:     $r->print(&startContentScreen('tools'));
                   5375:     my ($navmap,$errormsg) =
                   5376:         &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
                   5377:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   5378:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   5379:     my (%maps,%resources,%titles);
                   5380:     if (!ref($navmap)) {
                   5381:         $r->print($errormsg.
                   5382:                   &endContentScreen());
                   5383:         return '';
                   5384:     } else {
1.652     raeburn  5385:         $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651     raeburn  5386:         $r->rflush();
                   5387:         my $readonly;
                   5388:         if ($canedit) {
1.671     raeburn  5389:             my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651     raeburn  5390:             if ($numnew) {
                   5391:                 $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
                   5392:             }
                   5393:             if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
                   5394:                 $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
                   5395:                 foreach my $error (@{$errors}) {
                   5396:                     $r->print('<li>'.$error.'</li>');
                   5397:                 }
                   5398:                 $r->print('</ul><br />');
                   5399:             }
                   5400:         } else {
                   5401:             $readonly = 1;
                   5402:         }
                   5403:         my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
                   5404:         $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
                   5405:                                                              undef,undef,undef,undef,undef,\%currtiny,$readonly));
                   5406:     }
                   5407:     $r->print(&endContentScreen());
                   5408: }
                   5409: 
1.637     raeburn  5410: sub contentverifyform {
                   5411:     my ($r) = @_;
                   5412:     my $crstype = &Apache::loncommon::course_type();
                   5413:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   5414:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
                   5415:     $r->print(&startContentScreen('tools'));
                   5416:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
                   5417:     $r->print('<form method="post" action="/adm/coursedocs"><p>'.
                   5418:               &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
                   5419:               '&nbsp;<span class="LC_nobreak">'.
                   5420:               '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
                   5421:               &mt('No').'</label>'.('&nbsp;'x2).
                   5422:               '<label><input type="radio" name="checkstale" value="1" />'.
                   5423:               &mt('Yes').'</label></span></p><p>'.
1.674     raeburn  5424:               '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637     raeburn  5425:               '<input type="hidden" value="1" name="tools" />'.
                   5426:               '<input type="hidden" value="1" name="verify" /></p></form>');
                   5427:     $r->print(&endContentScreen());
                   5428:     return;
                   5429: }
1.329     droeschl 5430: 
                   5431: sub verifycontent {
1.637     raeburn  5432:     my ($r,$checkstale) = @_;
1.408     raeburn  5433:     my $crstype = &Apache::loncommon::course_type();
1.549     raeburn  5434:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
                   5435:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484     raeburn  5436:     $r->print(&startContentScreen('tools'));
                   5437:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>'); 
1.329     droeschl 5438:    $hashtied=0;
                   5439:    undef %alreadyseen;
                   5440:    %alreadyseen=();
                   5441:    &tiehash();
1.484     raeburn  5442:    
1.329     droeschl 5443:    foreach my $key (keys(%hash)) {
                   5444:        if ($hash{$key}=~/\.(page|sequence)$/) {
                   5445: 	   if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
                   5446: 	       $r->print('<hr /><span class="LC_error">'.
1.419     bisitz   5447: 			 &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329     droeschl 5448: 			 &unescape($hash{$key}).'</span><br />'.
1.419     bisitz   5449: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329     droeschl 5450: 	   }
                   5451:        }
                   5452:        if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637     raeburn  5453:            &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329     droeschl 5454:        }
                   5455:    }
                   5456:    &untiehash();
1.442     www      5457:    $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521     bisitz   5458:     $r->print(&endContentScreen());
1.329     droeschl 5459: }
                   5460: 
                   5461: sub devalidateversioncache {
                   5462:     my $src=shift;
                   5463:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
                   5464: 					  &Apache::lonnet::clutter($src));
                   5465: }
                   5466: 
                   5467: sub checkversions {
1.611     raeburn  5468:     my ($r,$canedit) = @_;
1.408     raeburn  5469:     my $crstype = &Apache::loncommon::course_type();
1.571     raeburn  5470:     $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
                   5471:     $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484     raeburn  5472:     $r->print(&startContentScreen('tools'));
1.442     www      5473: 
1.329     droeschl 5474:     my $header='';
                   5475:     my $startsel='';
                   5476:     my $monthsel='';
                   5477:     my $weeksel='';
                   5478:     my $daysel='';
                   5479:     my $allsel='';
                   5480:     my %changes=();
                   5481:     my $starttime=0;
                   5482:     my $haschanged=0;
                   5483:     my %setversions=&Apache::lonnet::dump('resourceversions',
                   5484: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   5485: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   5486: 
                   5487:     $hashtied=0;
                   5488:     &tiehash();
1.611     raeburn  5489:     if ($canedit) {
                   5490:         my %newsetversions=();
                   5491:         if ($env{'form.setmostrecent'}) {
                   5492: 	    $haschanged=1;
                   5493: 	    foreach my $key (keys(%hash)) {
                   5494: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   5495: 		    $newsetversions{$1}='mostrecent';
                   5496:                     &devalidateversioncache($1);
                   5497: 	        }
                   5498: 	    }
                   5499:         } elsif ($env{'form.setcurrent'}) {
                   5500: 	    $haschanged=1;
                   5501: 	    foreach my $key (keys(%hash)) {
                   5502: 	        if ($key=~/^ids\_(\/res\/.+)$/) {
                   5503: 		    my $getvers=&Apache::lonnet::getversion($1);
                   5504: 		    if ($getvers>0) {
                   5505: 		        $newsetversions{$1}=$getvers;
                   5506: 		        &devalidateversioncache($1);
                   5507: 		    }
                   5508: 	        }
1.329     droeschl 5509: 	    }
1.611     raeburn  5510:         } elsif ($env{'form.setversions'}) {
                   5511: 	    $haschanged=1;
                   5512: 	    foreach my $key (keys(%env)) {
                   5513: 	        if ($key=~/^form\.set_version_(.+)$/) {
                   5514: 		    my $src=$1;
                   5515: 		    if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
                   5516: 		        $newsetversions{$src}=$env{$key};
                   5517: 		        &devalidateversioncache($src);
                   5518: 		    }
                   5519: 	        }
1.329     droeschl 5520: 	    }
1.611     raeburn  5521:         }
                   5522:         if ($haschanged) {
                   5523:             if (&Apache::lonnet::put('resourceversions',\%newsetversions,
                   5524: 			             $env{'course.'.$env{'request.course.id'}.'.domain'},
                   5525: 			             $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
                   5526: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   5527:                     &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
                   5528: 	    } else {
                   5529: 	        $r->print(&Apache::loncommon::confirmwrapper(
                   5530:                     &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329     droeschl 5531: 	    }
1.611     raeburn  5532: 	    &mark_hash_old();
                   5533:         }
                   5534:         &changewarning($r,'');
1.329     droeschl 5535:     }
                   5536:     if ($env{'form.timerange'} eq 'all') {
                   5537: # show all documents
1.549     raeburn  5538: 	$header=&mt('All content in '.$crstype);
1.521     bisitz   5539: 	$allsel=' selected="selected"';
1.329     droeschl 5540: 	foreach my $key (keys(%hash)) {
                   5541: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   5542: 		my $src=$1;
                   5543: 		$changes{$src}=1;
                   5544: 	    }
                   5545: 	}
                   5546:     } else {
                   5547: # show documents which changed
                   5548: 	%changes=&Apache::lonnet::dump
                   5549: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
                   5550:                      $env{'course.'.$env{'request.course.id'}.'.num'});
                   5551: 	my $firstkey=(keys(%changes))[0];
                   5552: 	unless ($firstkey=~/^error\:/) {
                   5553: 	    unless ($env{'form.timerange'}) {
                   5554: 		$env{'form.timerange'}=604800;
                   5555: 	    }
                   5556: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
                   5557: 		.&mt('seconds');
                   5558: 	    if ($env{'form.timerange'}==-1) {
                   5559: 		$seltext='since start of course';
1.521     bisitz   5560: 		$startsel=' selected="selected"';
1.329     droeschl 5561: 		$env{'form.timerange'}=time;
                   5562: 	    }
                   5563: 	    $starttime=time-$env{'form.timerange'};
                   5564: 	    if ($env{'form.timerange'}==2592000) {
                   5565: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5566: 		$monthsel=' selected="selected"';
1.329     droeschl 5567: 	    } elsif ($env{'form.timerange'}==604800) {
                   5568: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5569: 		$weeksel=' selected="selected"';
1.329     droeschl 5570: 	    } elsif ($env{'form.timerange'}==86400) {
                   5571: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521     bisitz   5572: 		$daysel=' selected="selected"';
1.329     droeschl 5573: 	    }
                   5574: 	    $header=&mt('Content changed').' '.$seltext;
                   5575: 	} else {
                   5576: 	    $header=&mt('No content modifications yet.');
                   5577: 	}
                   5578:     }
                   5579:     %setversions=&Apache::lonnet::dump('resourceversions',
                   5580: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   5581: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   5582:     my %lt=&Apache::lonlocal::texthash
1.408     raeburn  5583: 	      ('st' => 'Version changes since start of '.$crstype,
1.329     droeschl 5584: 	       'lm' => 'Version changes since last Month',
                   5585: 	       'lw' => 'Version changes since last Week',
                   5586: 	       'sy' => 'Version changes since Yesterday',
                   5587:                'al' => 'All Resources (possibly large output)',
1.484     raeburn  5588:                'cd' => 'Change display', 
1.329     droeschl 5589: 	       'sd' => 'Display',
                   5590: 	       'fi' => 'File',
                   5591: 	       'md' => 'Modification Date',
                   5592:                'mr' => 'Most recently published Version',
1.408     raeburn  5593: 	       've' => 'Version used in '.$crstype,
                   5594:                'vu' => 'Set Version to be used in '.$crstype,
                   5595: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329     droeschl 5596: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                   5597: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479     golterma 5598: 	       'di' => 'Differences',
1.484     raeburn  5599: 	       'save' => 'Save changes',
                   5600:                'vers' => 'Version choice(s) for specific resources', 
1.479     golterma 5601: 	       'act' => 'Actions');
1.611     raeburn  5602:     my ($disabled,$readonly);
                   5603:     unless ($canedit) {
                   5604:         $disabled = 'disabled="disabled"';
                   5605:         $readonly = 1;
                   5606:     }
1.329     droeschl 5607:     $r->print(<<ENDHEADERS);
1.484     raeburn  5608: <h4 class="LC_info">$header</h4>
1.329     droeschl 5609: <form action="/adm/coursedocs" method="post">
                   5610: <input type="hidden" name="versions" value="1" />
1.484     raeburn  5611: <div class="LC_left_float">
1.479     golterma 5612: <fieldset>
1.484     raeburn  5613: <legend>$lt{'cd'}</legend>
1.329     droeschl 5614: <select name="timerange">
1.521     bisitz   5615: <option value='all'$allsel>$lt{'al'}</option>
                   5616: <option value="-1"$startsel>$lt{'st'}</option>
                   5617: <option value="2592000"$monthsel>$lt{'lm'}</option>
                   5618: <option value="604800"$weeksel>$lt{'lw'}</option>
                   5619: <option value="86400"$daysel>$lt{'sy'}</option>
1.329     droeschl 5620: </select>
                   5621: <input type="submit" name="display" value="$lt{'sd'}" />
1.484     raeburn  5622: </fieldset>
                   5623: </div>
                   5624: <div class="LC_left_float">
                   5625: <fieldset>
                   5626: <legend>$lt{'act'}</legend>
1.611     raeburn  5627: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
                   5628: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484     raeburn  5629: </fieldset>
                   5630: </div>
                   5631: <br clear="all" />
                   5632: <hr />
                   5633: <h4>$lt{'vers'}</h4>
1.329     droeschl 5634: ENDHEADERS
1.479     golterma 5635:     #number of columns for version history
1.571     raeburn  5636:     my %changedbytime;
                   5637:     foreach my $key (keys(%changes)) {
                   5638:         #excludes not versionable problems from resource version history:
                   5639:         next if ($key =~ /^\/res\/lib\/templates/);
                   5640:         my $chg;
                   5641:         if ($env{'form.timerange'} eq 'all') {
                   5642:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   5643:             $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
                   5644:         } else {
                   5645:             $chg = $changes{$key};
                   5646:             next if ($chg < $starttime);
                   5647:         }
                   5648:         push(@{$changedbytime{$chg}},$key);
                   5649:     }
                   5650:     if (keys(%changedbytime) == 0) {
                   5651:         &untiehash();
                   5652:         $r->print(&mt('No content changes in imported content in specified time frame').
                   5653:                   &endContentScreen());
                   5654:         return;
                   5655:     }
1.479     golterma 5656:     $r->print(
1.611     raeburn  5657:        '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   5658:         &Apache::loncommon::start_data_table().
                   5659:         &Apache::loncommon::start_data_table_header_row().
                   5660:         '<th>'.&mt('Resources').'</th>'.
                   5661:         "<th>$lt{'mr'}</th>".
                   5662:         "<th>$lt{'ve'}</th>".
                   5663:         "<th>$lt{'vu'}</th>".
                   5664:         '<th>'.&mt('History').'</th>'.
                   5665:         &Apache::loncommon::end_data_table_header_row()
                   5666:     );
1.571     raeburn  5667:     foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
                   5668:         foreach my $key (sort(@{$changedbytime{$chg}})) {
                   5669:             my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   5670:             my $currentversion=&Apache::lonnet::getversion($key);
                   5671:             if ($currentversion<0) {
                   5672:                 $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
                   5673:             }
                   5674:             my $linkurl=&Apache::lonnet::clutter($key);
                   5675:             $r->print(
                   5676:                 &Apache::loncommon::start_data_table_row().
                   5677:                 '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
                   5678:                 '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
                   5679:                 '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
                   5680:                 &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
                   5681:                 '<td align="right">'
                   5682:             );
                   5683:             # Used in course
                   5684:             my $usedversion=$hash{'version_'.$linkurl};
                   5685:             if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521     bisitz   5686:                 if ($usedversion != $currentversion) {
1.479     golterma 5687:                     $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521     bisitz   5688:                 } else {
1.479     golterma 5689:                     $r->print($usedversion);
                   5690:                 }
1.329     droeschl 5691:             } else {
1.521     bisitz   5692:                 $r->print($currentversion);
1.329     droeschl 5693:             }
1.571     raeburn  5694:             $r->print('</td><td title="'.$lt{'vu'}.'">');
                   5695:             # Set version
                   5696:             $r->print(&Apache::loncommon::select_form(
                   5697:                       $setversions{$linkurl},
                   5698:                       'set_version_'.$linkurl,
                   5699:                       {'select_form_order' => ['',1..$currentversion,'mostrecent'],
                   5700:                       '' => '',
                   5701:                       'mostrecent' => &mt('most recent'),
1.611     raeburn  5702:                       map {$_,$_} (1..$currentversion)},'',$readonly));
1.571     raeburn  5703:             my $lastold=1;
                   5704:             for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                   5705:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   5706:                 if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
                   5707:                     $lastold=$prevvers;
                   5708:                 }
                   5709:             }
                   5710:             $r->print('</td>');
                   5711:             # List all available versions
                   5712:             $r->print('<td valign="top"><span class="LC_fontsize_medium">');
                   5713:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
                   5714:                 my $url=$root.'.'.$prevvers.'.'.$extension;
                   5715:                 $r->print(
                   5716:                     '<span class="LC_nobreak">'
                   5717:                    .'<a href="'.&Apache::lonnet::clutter($url).'">'
                   5718:                    .&mt('Version [_1]',$prevvers).'</a>'
                   5719:                    .' ('.&Apache::lonlocal::locallocaltime(
1.521     bisitz   5720:                          &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571     raeburn  5721:                    .')');
                   5722:                 if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
                   5723:                     $r->print(
                   5724:                         ' <a href="/adm/diff?filename='.
                   5725:                         &Apache::lonnet::clutter($root.'.'.$extension).
                   5726:                         &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
                   5727:                         '" target="diffs">'.&mt('Diffs').'</a>');
                   5728:                 }
                   5729:                 $r->print('</span><br />');
1.329     droeschl 5730:             }
1.571     raeburn  5731:             $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521     bisitz   5732:         }
1.329     droeschl 5733:     }
1.521     bisitz   5734:     $r->print(
                   5735:         &Apache::loncommon::end_data_table().
1.611     raeburn  5736:         '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521     bisitz   5737:         '</form>'
                   5738:     );
1.329     droeschl 5739: 
                   5740:     &untiehash();
1.521     bisitz   5741:     $r->print(&endContentScreen());
1.571     raeburn  5742:     return;
1.329     droeschl 5743: }
                   5744: 
                   5745: sub mark_hash_old {
                   5746:     my $retie_hash=0;
                   5747:     if ($hashtied) {
                   5748: 	$retie_hash=1;
                   5749: 	&untiehash();
                   5750:     }
                   5751:     &tiehash('write');
                   5752:     $hash{'old'}=1;
                   5753:     &untiehash();
                   5754:     if ($retie_hash) { &tiehash(); }
                   5755: }
                   5756: 
                   5757: sub is_hash_old {
                   5758:     my $untie_hash=0;
                   5759:     if (!$hashtied) {
                   5760: 	$untie_hash=1;
                   5761: 	&tiehash();
                   5762:     }
                   5763:     my $return=$hash{'old'};
                   5764:     if ($untie_hash) { &untiehash(); }
                   5765:     return $return;
                   5766: }
                   5767: 
                   5768: sub changewarning {
                   5769:     my ($r,$postexec,$message,$url)=@_;
                   5770:     if (!&is_hash_old()) { return; }
                   5771:     my $pathvar='folderpath';
                   5772:     my $path=&escape($env{'form.folderpath'});
                   5773:     if (!defined($url)) {
                   5774: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
                   5775:     }
                   5776:     my $course_type = &Apache::loncommon::course_type();
                   5777:     if (!defined($message)) {
                   5778: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
                   5779:     }
1.653     raeburn  5780:     my $windowname = 'loncapaclient';
                   5781:     if ($env{'request.lti.login'}) {
                   5782:         $windowname .= 'lti';
                   5783:     }
1.329     droeschl 5784:     $r->print("\n\n".
1.372     bisitz   5785: '<script type="text/javascript">'."\n".
                   5786: '// <![CDATA['."\n".
                   5787: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
                   5788: '// ]]>'."\n".
1.369     bisitz   5789: '</script>'."\n".
1.653     raeburn  5790: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329     droeschl 5791: '<input type="hidden" name="orgurl" value="'.$url.
1.372     bisitz   5792: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329     droeschl 5793: &mt($message,' <input type="hidden" name="'.
                   5794:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369     bisitz   5795:     &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372     bisitz   5796: $help{'Caching'}.'</p></form>'."\n\n");
1.329     droeschl 5797: }
                   5798: 
                   5799: 
                   5800: sub init_breadcrumbs {
1.571     raeburn  5801:     my ($form,$text,$help)=@_;
1.329     droeschl 5802:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484     raeburn  5803:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405     bisitz   5804: 					    text=>&Apache::loncommon::course_type().' Editor',
1.329     droeschl 5805: 					    faq=>273,
                   5806: 					    bug=>'Instructor Interface',
1.571     raeburn  5807:                                             help => $help});
1.329     droeschl 5808:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
                   5809: 					    text=>$text,
                   5810: 					    faq=>273,
                   5811: 					    bug=>'Instructor Interface'});
                   5812: }
                   5813: 
1.441     www      5814: # subroutine to list form elements
                   5815: sub create_list_elements {
                   5816:    my @formarr = @_;
                   5817:    my $list = '';
1.501     raeburn  5818:    foreach my $button (@formarr){
                   5819:         foreach my $picture (keys(%{$button})) {
                   5820:             $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441     www      5821:         }
                   5822:    }
                   5823:    return $list;
                   5824: }
1.329     droeschl 5825: 
1.441     www      5826: # subroutine to create ul from list elements
                   5827: sub create_form_ul {
                   5828:    my $list = shift;
                   5829:    my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
                   5830:    return $ul;
                   5831: }
1.329     droeschl 5832: 
1.442     www      5833: #
                   5834: # Start tabs
                   5835: #
                   5836: 
                   5837: sub startContentScreen {
1.484     raeburn  5838:     my ($mode) = @_;
                   5839:     my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472     raeburn  5840:     if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484     raeburn  5841:         $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";
                   5842:         $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";
                   5843:         $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";
                   5844:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
                   5845:     } else {
1.549     raeburn  5846:         $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  5847:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
                   5848:         $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";
                   5849:                    '><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>';
                   5850:     }
                   5851:     $output .= "\n".'</ul>'."\n";
                   5852:     $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
                   5853:                '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
                   5854:                '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
                   5855:     return $output;
1.442     www      5856: }
                   5857: 
                   5858: #
                   5859: # End tabs
                   5860: #
                   5861: 
                   5862: sub endContentScreen {
1.484     raeburn  5863:     return '</div></div></div>';
1.442     www      5864: }
1.329     droeschl 5865: 
1.446     www      5866: sub supplemental_base {
1.548     raeburn  5867:     return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446     www      5868: }
                   5869: 
1.329     droeschl 5870: sub handler {
                   5871:     my $r = shift;
                   5872:     &Apache::loncommon::content_type($r,'text/html');
                   5873:     $r->send_http_header;
                   5874:     return OK if $r->header_only;
1.484     raeburn  5875: 
                   5876: # get course data
1.408     raeburn  5877:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  5878:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   5879:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   5880: 
1.606     raeburn  5881: # get docroot
                   5882:     my $londocroot = $r->dir_config('lonDocRoot');
                   5883: 
1.484     raeburn  5884: # graphics settings
                   5885:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329     droeschl 5886: 
1.443     www      5887: #
1.329     droeschl 5888: # --------------------------------------------- Initialize help topics for this
                   5889:     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627     raeburn  5890: 	               'Adding_External_Resource','Adding_External_Tool',
                   5891:                        'Navigate_Content','Adding_Folders','Docs_Overview',
                   5892: 	               'Load_Map','Supplemental','Score_Upload_Form',
                   5893: 	               'Adding_Pages','Importing_LON-CAPA_Resource',
                   5894: 	               'Importing_IMS_Course','Uploading_From_Harddrive',
1.706     raeburn  5895:                        'Course_Roster','Web_Page','Dropbox','Simple_Problem',
                   5896:                        'Standard_Problem','Course_Resources',
                   5897:                        'Search_LON-CAPA_Resource','Import_Stored_Links') {
1.329     droeschl 5898: 	$help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
                   5899:     }
                   5900:     # Composite help files
                   5901:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   5902: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   5903:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   5904: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
                   5905:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   5906: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347     weissno  5907:     $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329     droeschl 5908: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353     weissno  5909:     $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329     droeschl 5910:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534     raeburn  5911:  
1.611     raeburn  5912:     my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682     raeburn  5913: # does this user have privileges to modify content.
                   5914:     if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472     raeburn  5915: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682     raeburn  5916:         unless ($r->uri eq '/adm/supplemental') {
1.611     raeburn  5917:             $allowed = 1;
1.682     raeburn  5918:         }
                   5919:         $canedit = 1;
                   5920:         $canview = 1;
                   5921:     } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
                   5922: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
                   5923:         unless ($r->uri eq '/adm/supplemental') {
1.611     raeburn  5924:             $allowed = 1;
                   5925:         }
1.682     raeburn  5926:         $canview = 1;
1.611     raeburn  5927:     }
                   5928:     unless ($canedit) {
                   5929:         $disabled = ' disabled="disabled"';
1.472     raeburn  5930:     }
1.582     raeburn  5931:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635     raeburn  5932:     if ($env{'form.inhibitmenu'}) {
                   5933:         unless ($env{'form.inhibitmenu'} eq 'yes') {
                   5934:             delete($env{'form.inhibitmenu'});
                   5935:         }
                   5936:     }
                   5937: 
1.582     raeburn  5938:   if ($allowed && $env{'form.verify'}) {
1.571     raeburn  5939:       &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637     raeburn  5940:       if (!$canedit) {
                   5941:           &verifycontent($r);
                   5942:       } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
                   5943:           &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
                   5944:                                                   text=>'Results',
                   5945:                                                   faq=>273,
                   5946:                                                   bug=>'Instructor Interface'});
                   5947:           &verifycontent($r,$env{'form.checkstale'});
                   5948:       } else {
                   5949:           &contentverifyform($r);
                   5950:       }
1.329     droeschl 5951:   } elsif ($allowed && $env{'form.listsymbs'}) {
1.484     raeburn  5952:       &init_breadcrumbs('listsymbs','List Content IDs');
1.329     droeschl 5953:       &list_symbs($r);
1.651     raeburn  5954:   } elsif ($allowed && $env{'form.shorturls'}) {
                   5955:       &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
                   5956:       &short_urls($r,$canedit);
1.329     droeschl 5957:   } elsif ($allowed && $env{'form.docslog'}) {
                   5958:       &init_breadcrumbs('docslog','Show Log');
1.484     raeburn  5959:       my $folder = $env{'form.folder'};
                   5960:       if ($folder eq '') {
                   5961:           $folder='default';
                   5962:       }
1.611     raeburn  5963:       &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329     droeschl 5964:   } elsif ($allowed && $env{'form.versions'}) {
1.571     raeburn  5965:       &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611     raeburn  5966:       &checkversions($r,$canedit);
                   5967:   } elsif ($canedit && $env{'form.dumpcourse'}) {
1.709   ! raeburn  5968:       &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
1.329     droeschl 5969:       &dumpcourse($r);
1.611     raeburn  5970:   } elsif ($canedit && $env{'form.exportcourse'}) {
1.377     bisitz   5971:       &init_breadcrumbs('exportcourse','IMS Export');
1.475     raeburn  5972:       &Apache::imsexport::exportcourse($r);
1.329     droeschl 5973:   } else {
1.611     raeburn  5974:       if ($canedit && $env{'form.authorrole'}) {
1.606     raeburn  5975:           $noendpage = 1;
                   5976:           my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
                   5977:           if ($redirect) {
                   5978:               if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
                   5979:                   my $container = 'sequence'; 
                   5980:                   my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
                   5981:                       $is_random_order,$container) =
                   5982:                       &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
                   5983:                   my (@folders)=split('&',$env{'form.folderpath'});
                   5984:                   $env{'form.foldername'}=&unescape(pop(@folders));
                   5985:                   my $folder=pop(@folders);
                   5986:                   my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   5987:                                                   $folder.'.'.$container);
                   5988:                   my $warning;
                   5989:                   if ($fatal) {
                   5990:                       if ($container eq 'page') {
                   5991:                           $warning = &mt('An error occurred retrieving the contents of the current page.');
                   5992:                       } else {
                   5993:                           $warning = &mt('An error occurred retrieving the contents of the current folder.');
                   5994:                       }
                   5995:                   } else {
                   5996:                       my $url = $redirect;
                   5997:                       my $srcfile = $londocroot.$url;
                   5998:                       $url =~ s{^/priv/}{/res/};
                   5999:                       my $targetfile = $londocroot.$url;
                   6000:                       my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   6001:                       my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
                   6002:                       $env{'form.folder'} = $folder;
                   6003:                       &snapshotbefore();
                   6004:                       my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
                   6005:                       my $ext = 'false';
                   6006:                       my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
                   6007:                       $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                   6008:                                                         ':'.$ext.':normal:res';
                   6009:                       push(@LONCAPA::map::order,$newidx);
                   6010:                       &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
                   6011:                                                    'string_yesno');
                   6012:                       &remember_parms($newidx,'hiddenresource','set','yes');
                   6013:                       ($errtext,$fatal) =
                   6014:                           &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
                   6015:                       &log_differences($plain);
                   6016:                       &mark_hash_old();
                   6017:                       $r->internal_redirect($redirect);
                   6018:                       return OK;
                   6019:                   }
1.654     raeburn  6020:               } else {
                   6021:                   $r->internal_redirect($redirect);
1.606     raeburn  6022:               }
                   6023:           }
                   6024:       }
1.445     www      6025: #
                   6026: # Done catching special calls
1.484     raeburn  6027: # The whole rest is for course and supplemental documents and utilities menu
1.445     www      6028: # Get the parameters that may be needed
                   6029: #
                   6030:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682     raeburn  6031:                                             ['folderpath','title',
1.519     raeburn  6032:                                              'forcesupplement','forcestandard',
1.510     raeburn  6033:                                              'tools','symb','command','supppath']);
1.445     www      6034: 
1.635     raeburn  6035:     foreach my $item ('forcesupplement','forcestandard','tools') {
                   6036:         next if ($env{'form.'.$item} eq '');
                   6037:         unless ($env{'form.'.$item} eq '1') {
                   6038:             delete($env{'form.'.$item});
                   6039:         }
                   6040:     }
                   6041: 
                   6042:     if ($env{'form.command'}) {
                   6043:         unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
                   6044:             delete($env{'form.command'});
                   6045:         }
                   6046:     }
                   6047: 
                   6048:     if ($env{'form.symb'}) {
                   6049:         my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   6050:         unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) { 
                   6051:             delete($env{'form.symb'});
                   6052:         }
                   6053:     }
                   6054: 
1.445     www      6055: # standard=1: this is a "new-style" course with an uploaded map as top level
                   6056: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329     droeschl 6057: 
                   6058:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445     www      6059: 
1.484     raeburn  6060: # Decide whether this should display supplemental or main content or utilities
1.445     www      6061: # supplementalflag=1: show supplemental documents
                   6062: # supplementalflag=0: show standard documents
1.484     raeburn  6063: # toolsflag=1: show utilities
1.445     www      6064: 
1.561     raeburn  6065:     my $unesc_folderpath = &unescape($env{'form.folderpath'});
                   6066:     my $supplementalflag=($unesc_folderpath=~/^supplemental/);
                   6067:     if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445     www      6068:        $supplementalflag=0;
                   6069:     }
                   6070:     if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
                   6071:     if ($env{'form.forcestandard'})   { $supplementalflag=0; }
1.705     raeburn  6072:     unless (($supplementalflag) ||
                   6073:             ($r->uri =~ m{^/adm/coursedocs/showdoc/uploaded/\Q$coursedom\E/\Q$coursenum\E/docs/})) {
                   6074:         unless ($allowed) { $supplementalflag=1; }
                   6075:         unless ($standard) { $supplementalflag=1; }
                   6076:     }
1.484     raeburn  6077:     my $toolsflag=0;
                   6078:     if ($env{'form.tools'}) { $toolsflag=1; }
1.445     www      6079: 
1.635     raeburn  6080:     if ($env{'form.folderpath'} ne '') {
1.685     raeburn  6081:         &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635     raeburn  6082:     }
                   6083: 
1.685     raeburn  6084:     my $backto_supppath;
1.635     raeburn  6085:     if ($env{'form.supppath'} ne '') {
1.685     raeburn  6086:         if ($supplementalflag && $allowed) {
                   6087:             $backto_supppath = &validate_supppath($coursenum,$coursedom);
                   6088:         }
1.635     raeburn  6089:     }
                   6090: 
1.329     droeschl 6091:     my $script='';
                   6092:     my $showdoc=0;
1.457     raeburn  6093:     my $addentries = {};
1.475     raeburn  6094:     my $container;
1.329     droeschl 6095:     my $containertag;
1.508     raeburn  6096:     my $pathitem;
1.598     raeburn  6097:     my %ltitools;
1.699     raeburn  6098:     my $posslti;
1.617     raeburn  6099:     my $hiddentop;
1.615     raeburn  6100:     my $navmap;
1.617     raeburn  6101:     my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329     droeschl 6102: 
1.464     www      6103: # Do we directly jump somewhere?
1.525     raeburn  6104:    if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472     raeburn  6105:        if ($env{'form.symb'} ne '') {
1.522     raeburn  6106:            $env{'form.folderpath'}=
1.617     raeburn  6107:                &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530     raeburn  6108:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525     raeburn  6109:                $env{'form.command'}.'_'.$env{'form.symb'}});
1.685     raeburn  6110:        } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472     raeburn  6111:            $env{'form.folderpath'}=$env{'form.supppath'};
1.530     raeburn  6112:            &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685     raeburn  6113:                $env{'form.command'}.'_'.$backto_supppath});
1.466     www      6114:        }
1.472     raeburn  6115:    } elsif ($env{'form.command'} eq 'editdocs') {
1.617     raeburn  6116:        $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525     raeburn  6117:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472     raeburn  6118:    } elsif ($env{'form.command'} eq 'editsupp') {
1.617     raeburn  6119:        $env{'form.folderpath'} = &supplemental_base();
1.525     raeburn  6120:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
                   6121:    } elsif ($env{'form.command'} eq 'contents') {
                   6122:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
                   6123:    } elsif ($env{'form.command'} eq 'home') {
                   6124:        &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464     www      6125:    }
                   6126: 
1.525     raeburn  6127: 
1.445     www      6128: # Where do we store these for when we come back?
                   6129:     my $stored_folderpath='docs_folderpath';
                   6130:     if ($supplementalflag) {
                   6131:        $stored_folderpath='docs_sup_folderpath';
                   6132:     }
1.464     www      6133: 
1.519     raeburn  6134: # No folderpath, and in edit mode, see if we have something stored
                   6135:     if ((!$env{'form.folderpath'}) && $allowed) {
1.445     www      6136:         &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510     raeburn  6137:                                           {'folderpath' => 'scalar'});
1.615     raeburn  6138: 
                   6139:         if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
                   6140:             if ($supplementalflag) {
                   6141:                 undef($env{'form.folderpath'}) if ($1 eq 'default'); 
                   6142:             } else {
                   6143:                 undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
                   6144:             }
                   6145:         } else {
1.523     raeburn  6146:             undef($env{'form.folderpath'});
                   6147:         }
1.677     raeburn  6148:         if ($env{'form.folderpath'} ne '') {
1.685     raeburn  6149:             &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677     raeburn  6150:         }
1.329     droeschl 6151:     }
1.706     raeburn  6152: 
                   6153: # Set folderpath if we are not allowed to make changes and this is supplemental content
1.705     raeburn  6154:     if ((!$allowed) && ($supplementalflag)) {
1.446     www      6155:         unless ($env{'form.folderpath'} =~ /^supplemental/) {
                   6156:             $env{'form.folderpath'} = &supplemental_base();
1.409     raeburn  6157:         }
                   6158:     }
1.446     www      6159: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329     droeschl 6160:     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446     www      6161:         $env{'form.folderpath'} = &supplemental_base()
                   6162:                                   .'&'.
1.329     droeschl 6163:                                   $env{'form.folderpath'};
                   6164:     }
1.685     raeburn  6165: # If allowed and user's role is not advanced check folderpath is not hidden
                   6166:     my $hidden_and_empty;
1.687     raeburn  6167:     if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685     raeburn  6168:         my ($folderurl,$foldername,$hiddenfolder);
1.615     raeburn  6169:         my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617     raeburn  6170:         my $folder = $pathitems[-2];
                   6171:         if ($folder eq '') {
                   6172:             undef($env{'form.folderpath'});
                   6173:         } else {
                   6174:             $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666     raeburn  6175:             if ((split(/\:/,$pathitems[-1]))[5]) {
1.615     raeburn  6176:                 $folderurl .= '.page';
                   6177:             } else {
                   6178:                 $folderurl .= '.sequence';
                   6179:             }
1.685     raeburn  6180:             if ($supplementalflag) {
                   6181:                 ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
                   6182:                 $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688     raeburn  6183:                 my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685     raeburn  6184:                 if (ref($supplemental) eq 'HASH') {
                   6185:                     my ($suppmap,$suppmapnum);
                   6186:                     if ($folder eq 'supplemental') {
                   6187:                         $suppmap = 'default';
                   6188:                         $suppmapnum = 0;
                   6189:                     } elsif ($folder =~ /^supplemental_(\d+)$/) {
                   6190:                         $suppmap = $1;
                   6191:                         $suppmapnum = $suppmap;
                   6192:                     }
                   6193:                     if ($hiddenfolder) {
                   6194:                         my $hascontent;
                   6195:                         foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
                   6196:                             if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
                   6197:                                 $hascontent = 1;
                   6198:                             } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
                   6199:                                 foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
                   6200:                                     if ($id =~ /^$suppmapnum\:/) {
                   6201:                                         $hascontent = 1;
                   6202:                                         last;
                   6203:                                     }
                   6204:                                 }
                   6205:                             }
                   6206:                             last if ($hascontent);
                   6207:                         }
                   6208:                         unless ($hascontent) {
                   6209:                             if ($foldername ne '') {
                   6210:                                 $hidden_and_empty = $foldername;
                   6211:                             } else {
                   6212:                                 $hidden_and_empty = $folder;
                   6213:                             }
                   6214:                         }
                   6215:                     }
                   6216:                 }
                   6217:             } else {
                   6218:                 unless (ref($navmap)) {
                   6219:                     $navmap = Apache::lonnavmaps::navmap->new();
                   6220:                 }
                   6221:                 ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
                   6222:                 $foldername = &HTML::Entities::decode(&unescape($foldername));
                   6223:                 if (ref($navmap)) {
                   6224:                     if ($hiddenfolder ||
                   6225:                         (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
                   6226:                         my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
                   6227:                         unless (@resources) {
                   6228:                             if ($foldername ne '') {
                   6229:                                 $hidden_and_empty = $foldername;
                   6230:                             } else {
                   6231:                                 $hidden_and_empty = $folder;
                   6232:                             }
                   6233:                         }
                   6234:                     }
                   6235:                 }
1.617     raeburn  6236:             }
1.685     raeburn  6237:             if ($hidden_and_empty ne '') {
                   6238:                 splice(@pathitems,-2);
                   6239:                 if (@pathitems) {
                   6240:                     $env{'form.folderpath'} = join('&',@pathitems);
                   6241:                 } else {
                   6242:                     undef($env{'form.folderpath'});
1.615     raeburn  6243:                 }
                   6244:             }
                   6245:         }
                   6246:     }
                   6247: 
1.446     www      6248: # If after all of this, we still don't have any paths, make them
1.519     raeburn  6249:     unless ($env{'form.folderpath'}) {
1.446     www      6250:        if ($supplementalflag) {
                   6251:           $env{'form.folderpath'}=&supplemental_base();
1.617     raeburn  6252:        } elsif ($allowed) {
                   6253:           ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446     www      6254:        }
1.472     raeburn  6255:     }
1.446     www      6256: 
1.445     www      6257: # Store this
1.484     raeburn  6258:     unless ($toolsflag) {
1.615     raeburn  6259:         if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510     raeburn  6260:             &Apache::loncommon::store_course_settings($stored_folderpath,
1.519     raeburn  6261:                                                       {'folderpath' => 'scalar'});
1.510     raeburn  6262:         }
1.519     raeburn  6263:         my $folderpath;
1.484     raeburn  6264:         if ($env{'form.folderpath'}) {
1.519     raeburn  6265:             $folderpath = $env{'form.folderpath'};
                   6266: 	    my (@folders)=split('&',$env{'form.folderpath'});
                   6267: 	    $env{'form.foldername'}=&unescape(pop(@folders));
                   6268:             if ($env{'form.foldername'} =~ /\:1$/) {
                   6269:                 $container = 'page';
                   6270:             } else {
                   6271:                 $container = 'sequence';
                   6272:             }
                   6273: 	    $env{'form.folder'}=pop(@folders);
1.484     raeburn  6274:         } else {
1.519     raeburn  6275:             if ($env{'form.folder'} eq '' ||
                   6276:                 $env{'form.folder'} eq 'supplemental') {
1.617     raeburn  6277:                 if ($env{'form.folder'} eq 'supplemental') {
                   6278:                     $folderpath=&supplemental_base();
                   6279:                 } elsif (!$hiddentop) {
                   6280:                     $folderpath='default&'.
                   6281:                                  &escape(&mt('Main Content').':::::');
                   6282:                 }
1.484     raeburn  6283:             }
                   6284:         }
1.519     raeburn  6285:         $containertag = '<input type="hidden" name="folderpath" value="" />';
                   6286:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484     raeburn  6287:         if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
                   6288:            $showdoc='/'.$1;
                   6289:         }
                   6290:         if ($showdoc) { # got called in sequence from course
                   6291: 	    $allowed=0; 
                   6292:         } else {
1.611     raeburn  6293:             if ($canedit) {
1.484     raeburn  6294:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   6295:                 $script=&Apache::lonratedt::editscript('simple');
1.433     raeburn  6296:             }
                   6297:         }
1.329     droeschl 6298:     }
                   6299: 
1.344     bisitz   6300: # get personal data
1.329     droeschl 6301:     my $uname=$env{'user.name'};
                   6302:     my $udom=$env{'user.domain'};
                   6303:     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
                   6304: 
                   6305:     if ($allowed) {
1.484     raeburn  6306:         if ($toolsflag) {
                   6307:             $script .= &inject_data_js();
                   6308:             my ($home,$other,%outhash)=&authorhosts();
                   6309:             if (!$home && $other) {
                   6310:                 my @hosts;
                   6311:                 foreach my $aurole (keys(%outhash)) {
                   6312:                     unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   6313:                         push(@hosts,$outhash{$aurole});
                   6314:                     }
                   6315:                 }
                   6316:                 $script .= &dump_switchserver_js(@hosts); 
                   6317:             }
1.458     raeburn  6318:         } else {
1.570     raeburn  6319:             my $tid = 1;
1.484     raeburn  6320:             my @tabids;
                   6321:             if ($supplementalflag) {
1.655     raeburn  6322:                 @tabids = ('002','dd2','ee2','ff2');
1.570     raeburn  6323:                 $tid = 2;
1.484     raeburn  6324:             } else {
                   6325:                 @tabids = ('aa1','bb1','cc1','ff1');
1.519     raeburn  6326:                 unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484     raeburn  6327:                     unshift(@tabids,'001');
                   6328:                     push(@tabids,('dd1','ee1'));
                   6329:                 }
1.458     raeburn  6330:             }
1.484     raeburn  6331:             my $tabidstr = join("','",@tabids);
1.699     raeburn  6332:             my (%domtools,%crstools);
                   6333:             my %tooltypes = &Apache::loncommon::usable_exttools();
                   6334:             if ($tooltypes{'dom'}) {
                   6335:                 %domtools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
                   6336:             }
                   6337:             if ($tooltypes{'crs'}) {
                   6338:                 %crstools = &Apache::lonnet::get_course_lti($coursenum,$coursedom,'consumer');
                   6339:             }
                   6340:             %ltitools = (
                   6341:                           dom => \%domtools,
                   6342:                           crs => \%crstools,
                   6343:                         );
                   6344:             $posslti = scalar(keys(%domtools)) + scalar(keys(%crstools));
1.622     raeburn  6345:             my $hostname = $r->hostname();
1.606     raeburn  6346: 	    $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622     raeburn  6347:                                    $londocroot,$canedit,$hostname,\$navmap).
1.484     raeburn  6348:                        &history_tab_js().
                   6349:                        &inject_data_js().
1.570     raeburn  6350:                        &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598     raeburn  6351:                        &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685     raeburn  6352:             my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
                   6353:             if ($hidden_and_empty ne '') {
                   6354:                 my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
                   6355:                                 $hidden_and_empty);
                   6356:                 $onload .= "javascript:alert('".&js_escape($alert)."');";
                   6357:             }
1.484     raeburn  6358:             $addentries = {
1.685     raeburn  6359:                             onload => $onload,
1.484     raeburn  6360:                           };
1.458     raeburn  6361:         }
1.538     raeburn  6362:         $script .= &paste_popup_js(); 
1.501     raeburn  6363:         my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
                   6364:                              &mt('Switch server?');
                   6365:         
                   6366: 
1.329     droeschl 6367:     }
                   6368: # -------------------------------------------------------------------- Body tag
1.369     bisitz   6369:     $script = '<script type="text/javascript">'."\n"
1.372     bisitz   6370:               .'// <![CDATA['."\n"
                   6371:               .$script."\n"
                   6372:               .'// ]]>'."\n"
1.595     musolffc 6373:               .'</script>'."\n"
                   6374:               .'<script type="text/javascript" 
                   6375:                 src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385     bisitz   6376: 
                   6377:     # Breadcrumbs
                   6378:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510     raeburn  6379: 
                   6380:     if ($showdoc) {
1.682     raeburn  6381:         my $args;
                   6382:         if ($supplementalflag) {
1.687     raeburn  6383:             my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
                   6384:             my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.705     raeburn  6385:             $args = {'bread_crumbs' => $brcrum,
                   6386:                      'bread_crumbs_nomenu' => 1};
1.682     raeburn  6387:         } else {
                   6388:             $args = {'force_register' => $showdoc};
                   6389:         }
                   6390:         $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571     raeburn  6391:     } elsif ($toolsflag) {
1.611     raeburn  6392:         my ($breadtext,$breadtitle);
1.617     raeburn  6393:         $breadtext = "$crstype Editor";
1.611     raeburn  6394:         if ($canedit) {
                   6395:             $breadtitle = 'Editing '.$crstype.' Contents';
                   6396:         } else {
                   6397:             $breadtext .= ' (View-only mode)';
                   6398:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   6399:         }
1.571     raeburn  6400:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  6401:             href=>"/adm/coursedocs",text=>$breadtext});
1.571     raeburn  6402:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
                   6403:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   6404:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  6405:                      $breadtitle)
1.571     raeburn  6406:                  );
1.510     raeburn  6407:     } elsif ($r->uri eq '/adm/supplemental') {
1.682     raeburn  6408:         unless ($env{'request.role.adv'}) {
                   6409:             unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
                   6410:                 $r->internal_redirect('/adm/navmaps');
                   6411:                 return OK;
                   6412:             }
                   6413:         }
1.510     raeburn  6414:         my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
1.705     raeburn  6415:         my $args = {'bread_crumbs' => $brcrum};
                   6416:         unless (($env{'form.folderpath'} eq '') ||
                   6417:                 ($env{'form.folder'} eq 'supplemental')) {
                   6418:             $args->{'bread_crumbs_nomenu'} = 1;
                   6419:         }
1.510     raeburn  6420:         $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
1.705     raeburn  6421:                                                  $args));
1.510     raeburn  6422:     } else {
1.611     raeburn  6423:         my ($breadtext,$breadtitle,$helpitem);
1.617     raeburn  6424:         $breadtext = "$crstype Editor";
1.611     raeburn  6425:         if ($canedit) {
                   6426:             $breadtitle = 'Editing '.$crstype.' Contents';
                   6427:             $helpitem = 'Docs_Adding_Course_Doc';
                   6428:         } else {
                   6429:             $breadtext .= ' (View-only mode)';
                   6430:             $breadtitle = 'Viewing '.$crstype.' Contents';
                   6431:             $helpitem = 'Docs_Viewing_Course_Doc';
                   6432:         }
1.392     raeburn  6433:         &Apache::lonhtmlcommon::add_breadcrumb({
1.611     raeburn  6434:             href=>"/adm/coursedocs",text=>$breadtext});
1.446     www      6435:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510     raeburn  6436:                                                  {'add_entries'    => $addentries}
                   6437:                                                 )
1.392     raeburn  6438:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   6439:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.611     raeburn  6440:                      $breadtitle,
                   6441:                      $helpitem)
1.392     raeburn  6442:         );
                   6443:     }
1.364     bisitz   6444: 
1.329     droeschl 6445:   my %allfiles = ();
                   6446:   my %codebase = ();
1.440     raeburn  6447:   my ($upload_result,$upload_output,$uploadphase);
1.611     raeburn  6448:   if ($canedit) {
1.684     raeburn  6449:       undef($suppchanges);
1.329     droeschl 6450:       if (($env{'form.uploaddoc.filename'}) &&
                   6451: 	  ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440     raeburn  6452:           my $context = $1; 
                   6453:           # Process file upload - phase one - upload and parse primary file.
1.329     droeschl 6454: 	  undef($hadchanges);
1.440     raeburn  6455:           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552     raeburn  6456:                                               \%allfiles,\%codebase,$context,$crstype);
1.638     raeburn  6457:           undef($navmap);
1.329     droeschl 6458: 	  if ($hadchanges) {
                   6459: 	      &mark_hash_old();
                   6460: 	  }
1.684     raeburn  6461:           if ($suppchanges) {
                   6462:               &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
                   6463:               undef($suppchanges);
                   6464:           }
1.440     raeburn  6465:           $r->print($upload_output);
                   6466:       } elsif ($env{'form.phase'} eq 'upload_embedded') {
                   6467:           # Process file upload - phase two - upload embedded objects 
                   6468:           $uploadphase = 'check_embedded';
                   6469:           my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');   
                   6470:           my $state = &embedded_form_elems($uploadphase,$primaryurl,
                   6471:                                            $env{'form.newidx'});
                   6472:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   6473:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   6474:           my ($destination,$dir_root) = &embedded_destination();
                   6475:           my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
                   6476:           my $actionurl = '/adm/coursedocs';
1.630     raeburn  6477:           my ($result,$flag) =
1.440     raeburn  6478:               &Apache::loncommon::upload_embedded('coursedoc',$destination,
                   6479:                   $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
                   6480:                   $actionurl);
                   6481:           $r->print($result.&return_to_editor());
                   6482:       } elsif ($env{'form.phase'} eq 'check_embedded') {
                   6483:           # Process file upload - phase three - modify references in HTML file
                   6484:           $uploadphase = 'modified_orightml';
                   6485:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   6486:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   6487:           my ($destination,$dir_root) = &embedded_destination();
1.630     raeburn  6488:           my $result =
1.482     raeburn  6489:               &Apache::loncommon::modify_html_refs('coursedoc',$destination,
                   6490:                                                    $docuname,$docudom,undef,
                   6491:                                                    $dir_root);
1.630     raeburn  6492:           $r->print($result.&return_to_editor());
1.476     raeburn  6493:       } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
                   6494:           $uploadphase = 'decompress_phase_one';
                   6495:           $r->print(&decompression_phase_one().
                   6496:                     &return_to_editor());
                   6497:       } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
                   6498:           $uploadphase = 'decompress_phase_two';
                   6499:           $r->print(&decompression_phase_two().
                   6500:                     &return_to_editor());
1.329     droeschl 6501:       }
                   6502:   }
                   6503: 
1.484     raeburn  6504:   if ($allowed && $toolsflag) {
                   6505:       $r->print(&startContentScreen('tools'));
1.708     raeburn  6506:       $r->print(&generate_admin_menu($crstype,$canedit,$coursenum,$coursedom));
1.484     raeburn  6507:       $r->print(&endContentScreen());
                   6508:   } elsif ((!$showdoc) && (!$uploadphase)) {
1.329     droeschl 6509: # -----------------------------------------------------------------------------
                   6510:        my %lt=&Apache::lonlocal::texthash(
                   6511: 		'copm' => 'All documents out of a published map into this folder',
1.501     raeburn  6512:                 'upfi' => 'Upload File',
1.553     raeburn  6513:                 'upld' => 'Upload Content',
1.706     raeburn  6514:                 'srch' => 'Search Repository',
                   6515:                 'impo' => 'Import from Repository',
1.487     raeburn  6516: 		'lnks' => 'Import from Stored Links',
1.502     raeburn  6517:                 'impm' => 'Import from Assembled Map',
1.630     raeburn  6518:                 'imcr' => 'Import from Course Resources',
1.598     raeburn  6519:                 'extr' => 'External Resource',
                   6520:                 'extt' => 'External Tool',
1.329     droeschl 6521:                 'selm' => 'Select Map',
                   6522:                 'load' => 'Load Map',
                   6523:                 'newf' => 'New Folder',
                   6524:                 'newp' => 'New Composite Page',
                   6525:                 'syll' => 'Syllabus',
1.425     raeburn  6526:                 'navc' => 'Table of Contents',
1.343     biermanm 6527:                 'sipa' => 'Simple Course Page',
1.329     droeschl 6528:                 'sipr' => 'Simple Problem',
1.630     raeburn  6529:                 'webp' => 'Blank Web Page (editable)',
1.606     raeburn  6530:                 'stpr' => 'Standard Problem',
                   6531:                 'news' => 'New sub-directory',
                   6532:                 'crpr' => 'Create Problem',
1.689     raeburn  6533:                 'swit' => 'Switch Server',
1.329     droeschl 6534:                 'drbx' => 'Drop Box',
1.451     www      6535:                 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336     schafran 6536:                 'bull' => 'Discussion Board',
1.347     weissno  6537:                 'mypi' => 'My Personal Information Page',
1.353     weissno  6538:                 'grpo' => 'Group Portfolio',
1.329     droeschl 6539:                 'rost' => 'Course Roster',
1.528     raeburn  6540:                 'abou' => 'Personal Information Page for a User',
1.553     raeburn  6541:                 'imsf' => 'IMS Upload',
                   6542:                 'imsl' => 'Upload IMS package',
1.501     raeburn  6543:                 'cms'  => 'Origin of IMS package',
                   6544:                 'se'   => 'Select',
1.329     droeschl 6545:                 'file' =>  'File',
                   6546:                 'title' => 'Title',
1.606     raeburn  6547:                 'addp' => 'Add Placeholder to course?',
                   6548:                 'uste' => 'Use Template?',
                   6549:                 'fnam' => 'File Name:',
                   6550:                 'loca' => 'Location:',
                   6551:                 'dire' => 'Directory:',
                   6552:                 'cate' => 'Category:',
                   6553:                 'tmpl' => 'Template:',
1.698     raeburn  6554:                 'empd' => 'No resources found',
1.329     droeschl 6555:                 'comment' => 'Comment',
1.403     raeburn  6556:                 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577     bisitz   6557:                 'bb5'      => 'Blackboard 5',
                   6558:                 'bb6'      => 'Blackboard 6',
                   6559:                 'angel5'   => 'ANGEL 5.5',
                   6560:                 'webctce4' => 'WebCT 4 Campus Edition',
1.606     raeburn  6561:                 'yes'      => 'Yes',
                   6562:                 'no'       => 'No',
1.618     raeburn  6563:                 'er' => 'Editing rights unavailable for your current role.',
1.577     bisitz   6564:         );
1.329     droeschl 6565: # -----------------------------------------------------------------------------
1.595     musolffc 6566: 
                   6567:     # Calculate free quota space for a user or course. A javascript function checks
                   6568:     # file size to determine if upload should be allowed.
                   6569:     my $quotatype = 'unofficial';
                   6570:     if ($crstype eq 'Community') {
1.601     raeburn  6571:         $quotatype = 'community';
                   6572:     } elsif ($crstype eq 'Placement') {
                   6573:         $quotatype = 'placement';
1.595     musolffc 6574:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
                   6575:         $quotatype = 'official';
                   6576:     } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
                   6577:         $quotatype = 'textbook';
                   6578:     }
                   6579:     my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
                   6580:                      'course',$quotatype); # expressed in MB
                   6581:     my $current_disk_usage = 0;
                   6582:     foreach my $subdir ('docs','supplemental') {
                   6583:         $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
                   6584:                                "userfiles/$subdir",1); # expressed in kB
                   6585:     }
                   6586:     my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605     raeburn  6587:     my $usage = $current_disk_usage/1024; # in MB
                   6588:     my $quota = $disk_quota;
                   6589:     my $percent;
                   6590:     if ($disk_quota == 0) {
                   6591:         $percent = 100.0;
                   6592:     } else {
1.619     raeburn  6593:         $percent = 100*($usage/$disk_quota);
1.605     raeburn  6594:     }
                   6595:     $usage = sprintf("%.2f",$usage);
                   6596:     $quota = sprintf("%.2f",$quota);
                   6597:     $percent = sprintf("%.0f",$percent);
                   6598:     my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
                   6599:                               $percent.'%',$quota.' MB').'</p>';
1.595     musolffc 6600: 
1.329     droeschl 6601: 	my $fileupload=(<<FIUP);
1.605     raeburn  6602:         $quotainfo
1.329     droeschl 6603: 	$lt{'file'}:<br />
                   6604: FIUP
                   6605: 	my $checkbox=(<<CHBO);
                   6606: 	<!-- <label>$lt{'parse'}?
                   6607: 	<input type="checkbox" name="parserflag" />
                   6608: 	</label> -->
                   6609: 	<label>
1.611     raeburn  6610: 	<input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329     droeschl 6611: 	</label>
                   6612: CHBO
1.501     raeburn  6613:         my $imsfolder = $env{'form.folder'};
                   6614:         if ($imsfolder eq '') {
                   6615:             $imsfolder = 'default';  
                   6616:         }
                   6617:         my $imspform=(<<IMSFORM);
                   6618:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
                   6619:         $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
                   6620:         <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516     raeburn  6621:         <fieldset id="uploadimsform" style="display: none;">
1.501     raeburn  6622:         <legend>$lt{'imsf'}</legend>
                   6623:         $fileupload
1.702     raeburn  6624:         <input type="file" name="uploaddoc" id="uploaddocims" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
                   6625:         <input type="hidden" id="LC_free_space_ims" value="$free_space" />
1.501     raeburn  6626:         <br />
                   6627:         <p>
                   6628:         $lt{'cms'}:&nbsp; 
1.611     raeburn  6629:         <select name="source" $disabled>
1.501     raeburn  6630:         <option value="-1" selected="selected">$lt{'se'}</option>
1.577     bisitz   6631:         <option value="bb5">$lt{'bb5'}</option>
                   6632:         <option value="bb6">$lt{'bb6'}</option>
                   6633:         <option value="angel5">$lt{'angel5'}</option>
                   6634:         <option value="webctce4">$lt{'webctce4'}</option>
1.501     raeburn  6635:         </select>
                   6636:         <input type="hidden" name="folder" value="$imsfolder" />
                   6637:         </p>
                   6638:         <input type="hidden" name="phase" value="one" />
1.611     raeburn  6639:         <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501     raeburn  6640:         </fieldset>
                   6641:         </form>
                   6642: IMSFORM
1.329     droeschl 6643: 
                   6644: 	my $fileuploadform=(<<FUFORM);
1.501     raeburn  6645:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
                   6646:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
                   6647:         <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516     raeburn  6648:         <fieldset id="uploaddocform" style="display: none;">
1.501     raeburn  6649:         <legend>$lt{'upfi'}</legend>
1.371     tempelho 6650: 	<input type="hidden" name="active" value="aa" />
1.595     musolffc 6651:     $fileupload
1.702     raeburn  6652:         <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
                   6653:         <input type="hidden" id="LC_free_space" value="$free_space" />
1.329     droeschl 6654: 	<br />
                   6655: 	$lt{'title'}:<br />
1.611     raeburn  6656: 	<input type="text" size="60" name="comment" $disabled />
1.508     raeburn  6657: 	$pathitem
1.329     droeschl 6658: 	<input type="hidden" name="cmd" value="upload_default" />
                   6659: 	<br />
1.458     raeburn  6660: 	<span class="LC_nobreak" style="float:left">
1.329     droeschl 6661: 	$checkbox
                   6662: 	</span>
1.501     raeburn  6663:         <br clear="all" />
1.611     raeburn  6664:         <input type="submit" value="$lt{'upld'}" $disabled />
1.501     raeburn  6665:         </fieldset>
                   6666:         </form>
1.383     tempelho 6667: FUFORM
1.329     droeschl 6668: 
1.611     raeburn  6669:         my $mapimportjs;
                   6670:         if ($canedit) {
                   6671:             $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');"; 
                   6672:         } else {
                   6673:             $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
                   6674:         }
1.502     raeburn  6675: 	my $importpubform=(<<SEDFFORM);
1.514     raeburn  6676:         <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502     raeburn  6677:         $lt{'impm'}</a>$help{'Load_Map'}
                   6678: 	<form action="/adm/coursedocs" method="post" name="mapimportform">
1.516     raeburn  6679:         <fieldset id="importmapform" style="display: none;">
1.502     raeburn  6680:         <legend>$lt{'impm'}</legend>
1.371     tempelho 6681: 	<input type="hidden" name="active" value="bb" />
1.502     raeburn  6682:         $lt{'copm'}<br />
                   6683:         <span class="LC_nobreak">
                   6684:         <input type="text" name="importmap" size="40" value="" 
1.611     raeburn  6685:         onfocus="this.blur();$mapimportjs" $disabled />
                   6686:         &nbsp;<a href="$mapimportjs">$lt{'selm'}</a></span><br />
                   6687:         <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502     raeburn  6688:         </fieldset>
                   6689:         </form>
                   6690: 
1.383     tempelho 6691: SEDFFORM
1.706     raeburn  6692:         my ($importcrsresform,$checkcrsres);
                   6693:         if ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'}) {
                   6694:             $checkcrsres = 1;
                   6695:         } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.crsauthor'} ne '0') {
                   6696:             my %domdefs=&Apache::lonnet::get_domain_defaults($coursedom);
                   6697:             if ($domdefs{'crsauthor'}) {
                   6698:                 $checkcrsres = 1;
                   6699:             }
                   6700:         }
                   6701:         if ($checkcrsres) {
                   6702:             my ($numdirs,$pickfile) = 
                   6703:                 &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
                   6704:                                                           "resize_scrollbox('contentscroll','1','0');",
                   6705:                                                           undef,'res');
                   6706:             if ($pickfile) {
                   6707:                 $importcrsresform=(<<CRSFORM);
1.690     raeburn  6708:         <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606     raeburn  6709:         $lt{'imcr'}</a>$help{'Course_Resources'}
                   6710:         <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
                   6711:         <fieldset id="importcrsresform" style="display: none;">
                   6712:         <legend>$lt{'imcr'}</legend>
1.698     raeburn  6713:         <div id="importcrsrescontent" style="display: none;">
1.606     raeburn  6714:         <input type="hidden" name="active" value="bb" />
                   6715:         $pickfile
                   6716:         <p>
1.699     raeburn  6717:         $lt{'title'}: <input type="text" name="crsrestitle" value="" $disabled />
1.606     raeburn  6718:         </p>
                   6719:         <input type="hidden" name="importdetail" value="" />
1.690     raeburn  6720:         <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.698     raeburn  6721:         </div>
                   6722:         <div id="importcrsresempty" style="display: none;">
                   6723:         <p>
                   6724:         $lt{'empd'}
                   6725:         </p>
                   6726:         </div>
1.606     raeburn  6727:         </fieldset>
                   6728:         </form>
                   6729: CRSFORM
1.706     raeburn  6730:             }
1.606     raeburn  6731:         }
                   6732: 
1.611     raeburn  6733:         my $fromstoredjs;
                   6734:         if ($canedit) {
                   6735:             $fromstoredjs = 'open_StoredLinks_Import()'; 
                   6736:         } else {
                   6737:             $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
                   6738:         }
                   6739: 
1.502     raeburn  6740: 	my @importpubforma = (
1.706     raeburn  6741: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'"  onclick="javascript:groupsearch()" />' => $pathitem."<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>$help{'Search_LON-CAPA_Resource'}" },
1.423     onken    6742: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'"  onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
1.706     raeburn  6743: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:'.$fromstoredjs.';" />' => '<a class="LC_menubuttons_link" href="javascript:'.$fromstoredjs.';">'.$lt{'lnks'}.'</a>'.$help{'Import_Stored_Links'} },
1.606     raeburn  6744:         { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
                   6745:         );
1.706     raeburn  6746:         if ($importcrsresform) {
                   6747:             push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/impcrsau.png" alt="'.$lt{imcr}.'"  onclick="javascript:toggleImportCrsres(\'res\');" />' => $importcrsresform});
1.606     raeburn  6748: 	}
1.502     raeburn  6749: 	$importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510     raeburn  6750:         my $extresourcesform =
                   6751:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611     raeburn  6752:                                                  $help{'Adding_External_Resource'},
                   6753:                                                  undef,undef,undef,undef,undef,undef,$disabled);
1.598     raeburn  6754:         my $exttoolform =
                   6755:             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
                   6756:                                                  $help{'Adding_External_Tool'},undef,
                   6757:                                                  undef,'tool',$coursedom,$coursenum,
1.611     raeburn  6758:                                                  \%ltitools,$disabled);
1.329     droeschl 6759:     if ($allowed) {
1.492     raeburn  6760:         my $folder = $env{'form.folder'};
                   6761:         if ($folder eq '') {
                   6762:             $folder='default';
                   6763:         }
1.615     raeburn  6764:         if ($canedit) {
                   6765: 	    my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
                   6766:             if ($output) {
                   6767:                 $r->print($output);
                   6768:             }
1.538     raeburn  6769:         }
1.337     ehlerst  6770: 	$r->print(<<HIDDENFORM);
                   6771: 	<form name="renameform" method="post" action="/adm/coursedocs">
                   6772:    <input type="hidden" name="title" />
                   6773:    <input type="hidden" name="cmd" />
                   6774:    <input type="hidden" name="markcopy" />
                   6775:    <input type="hidden" name="copyfolder" />
                   6776:    $containertag
                   6777:  </form>
1.633     raeburn  6778:  <form name="aliasform" method="post" action="/adm/coursedocs">
                   6779:    <input type="hidden" name="alias" />
                   6780:    <input type="hidden" name="cmd" />
                   6781:    $containertag
                   6782:  </form>
1.484     raeburn  6783: 
1.337     ehlerst  6784: HIDDENFORM
1.508     raeburn  6785:         $r->print(&makesimpleeditform($pathitem)."\n".
                   6786:                   &makedocslogform($pathitem."\n".
1.484     raeburn  6787:                                    '<input type="hidden" name="folder" value="'.
                   6788:                                    $env{'form.folder'}.'" />'."\n"));
1.329     droeschl 6789:     }
1.442     www      6790: 
                   6791: # Generate the tabs
1.510     raeburn  6792:     my ($mode,$needs_end);
1.472     raeburn  6793:     if (($supplementalflag) && (!$allowed)) {
1.510     raeburn  6794:         my @folders = split('&',$env{'form.folderpath'});
                   6795:         unless (@folders > 2) {
                   6796:             &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
                   6797:             $needs_end = 1;
                   6798:         }
1.472     raeburn  6799:     } else {
1.484     raeburn  6800:         $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510     raeburn  6801:         $needs_end = 1;
1.472     raeburn  6802:     }
1.443     www      6803: 
1.442     www      6804: #
1.622     raeburn  6805:     my $hostname = $r->hostname();
1.442     www      6806:     my $savefolderpath;
                   6807: 
1.395     raeburn  6808:     if ($allowed) {
1.329     droeschl 6809:        my $folder=$env{'form.folder'};
1.615     raeburn  6810:        if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329     droeschl 6811:            $folder='default';
1.356     tempelho 6812: 	   $savefolderpath = $env{'form.folderpath'};
1.548     raeburn  6813: 	   $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508     raeburn  6814:            $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329     droeschl 6815: 	       &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
                   6816:        }
                   6817:        my $postexec='';
                   6818:        if ($folder eq 'default') {
1.653     raeburn  6819:            my $windowname = 'loncapaclient';
                   6820:            if ($env{'request.lti.login'}) {
                   6821:                $windowname .= 'lti';
                   6822:            }
1.372     bisitz   6823:            $r->print('<script type="text/javascript">'."\n"
                   6824:                     .'// <![CDATA['."\n"
1.653     raeburn  6825:                     .'this.window.name="'.$windowname.'";'."\n"
1.372     bisitz   6826:                     .'// ]]>'."\n"
                   6827:                     .'</script>'."\n"
1.369     bisitz   6828:        );
1.329     droeschl 6829:        } else {
                   6830:            #$postexec='self.close();';
                   6831:        }
1.504     raeburn  6832:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
                   6833:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329     droeschl 6834: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
                   6835: 
                   6836: 	my $newnavform=(<<NNFORM);
                   6837: 	<form action="/adm/coursedocs" method="post" name="newnav">
1.655     raeburn  6838: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6839: 	$pathitem
1.329     droeschl 6840: 	<input type="hidden" name="importdetail" 
                   6841: 	value="$lt{'navc'}=/adm/navmaps" />
1.611     raeburn  6842: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329     droeschl 6843: 	$help{'Navigate_Content'}
                   6844: 	</form>
                   6845: NNFORM
                   6846: 	my $newsmppageform=(<<NSPFORM);
                   6847: 	<form action="/adm/coursedocs" method="post" name="newsmppg">
1.655     raeburn  6848: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  6849: 	$pathitem
1.329     droeschl 6850: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6851: 	<a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383     tempelho 6852: 	$help{'Simple Page'}
1.329     droeschl 6853: 	</form>
                   6854: NSPFORM
                   6855: 
                   6856: 	my $newsmpproblemform=(<<NSPROBFORM);
                   6857: 	<form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655     raeburn  6858: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6859: 	$pathitem
1.329     droeschl 6860: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6861: 	<a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572     raeburn  6862: 	$help{'Simple_Problem'}
1.329     droeschl 6863: 	</form>
                   6864: 
                   6865: NSPROBFORM
                   6866: 
                   6867: 	my $newdropboxform=(<<NDBFORM);
                   6868: 	<form action="/adm/coursedocs" method="post" name="newdropbox">
1.655     raeburn  6869: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6870: 	$pathitem
1.329     droeschl 6871: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6872: 	<a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554     raeburn  6873:         $help{'Dropbox'}
1.344     bisitz   6874: 	</form>
1.329     droeschl 6875: NDBFORM
                   6876: 
                   6877: 	my $newexuploadform=(<<NEXUFORM);
                   6878: 	<form action="/adm/coursedocs" method="post" name="newexamupload">
1.655     raeburn  6879: 	<input type="hidden" name="active" value="dd" />
1.508     raeburn  6880: 	$pathitem
1.329     droeschl 6881: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6882: 	<a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329     droeschl 6883: 	$help{'Score_Upload_Form'}
                   6884: 	</form>
                   6885: NEXUFORM
                   6886: 
                   6887: 	my $newbulform=(<<NBFORM);
                   6888: 	<form action="/adm/coursedocs" method="post" name="newbul">
1.655     raeburn  6889: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6890: 	$pathitem
1.329     droeschl 6891: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6892: 	<a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329     droeschl 6893: 	$help{'Bulletin Board'}
                   6894: 	</form>
                   6895: NBFORM
                   6896: 
                   6897: 	my $newaboutmeform=(<<NAMFORM);
                   6898: 	<form action="/adm/coursedocs" method="post" name="newaboutme">
1.655     raeburn  6899: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6900: 	$pathitem
1.329     droeschl 6901: 	<input type="hidden" name="importdetail" 
                   6902: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  6903: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347     weissno  6904: 	$help{'My Personal Information Page'}
1.329     droeschl 6905: 	</form>
                   6906: NAMFORM
                   6907: 
                   6908: 	my $newaboutsomeoneform=(<<NASOFORM);
                   6909: 	<form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655     raeburn  6910: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6911: 	$pathitem
1.329     droeschl 6912: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    6913: 	<a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329     droeschl 6914: 	</form>
                   6915: NASOFORM
                   6916: 
                   6917: 	my $newrosterform=(<<NROSTFORM);
                   6918: 	<form action="/adm/coursedocs" method="post" name="newroster">
1.655     raeburn  6919: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  6920: 	$pathitem
1.329     droeschl 6921: 	<input type="hidden" name="importdetail" 
                   6922: 	value="$lt{'rost'}=/adm/viewclasslist" />
1.611     raeburn  6923: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556     raeburn  6924: 	$help{'Course_Roster'}
1.329     droeschl 6925: 	</form>
                   6926: NROSTFORM
                   6927: 
1.534     raeburn  6928:         my $newwebpage;
                   6929:         if ($folder =~ /^default_?(\d*)$/) {
                   6930:             $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
                   6931:             if ($1) {
                   6932:                 $newwebpage .= $1;
                   6933:             } else {
                   6934:                 $newwebpage .= 'default';
                   6935:             }
                   6936:             $newwebpage .= '/new.html';
                   6937:         }
                   6938:         my $newwebpageform =(<<NWEBFORM);
                   6939:         <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655     raeburn  6940:         <input type="hidden" name="active" value="ff" />
1.534     raeburn  6941:         $pathitem
                   6942:         <input type="hidden" name="importdetail" value="$newwebpage" />
                   6943:         <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556     raeburn  6944:         $help{'Web_Page'}
1.534     raeburn  6945:         </form>
                   6946: NWEBFORM
1.701     raeburn  6947:         my $showpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.606     raeburn  6948:         my @ids=&Apache::lonnet::current_machine_ids();
1.691     raeburn  6949:         my $machines_str = "'".join("','",@ids)."'";
                   6950:         my (%is_home,%toppath,$rolehomes);
1.606     raeburn  6951:         if ($env{'user.author'}) {
                   6952:             if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691     raeburn  6953:                 $is_home{'author'} = 1;
1.606     raeburn  6954:             }
1.691     raeburn  6955:             $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606     raeburn  6956:         }
                   6957:         my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
                   6958:                                                       ['active'],['ca','aa']);
1.691     raeburn  6959:         my %by_roletype;
1.606     raeburn  6960:         if (keys(%roleshash)) {
                   6961:             foreach my $entry (keys(%roleshash)) {
                   6962:                 my ($auname,$audom,$roletype) = split(/:/,$entry);
                   6963:                 my $key = $entry;
                   6964:                 $key =~ s/:/___/g;
1.691     raeburn  6965:                 my $author = $auname.'___'.$audom;
                   6966:                 $by_roletype{$roletype}{$author} = 1;
1.606     raeburn  6967:                 my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691     raeburn  6968:                 $toppath{$author} = "/priv/$audom/$auname";
                   6969:                 if (grep(/^\Q$rolehome\E$/,@ids)) {
                   6970:                     $is_home{$author} = 1;
1.606     raeburn  6971:                 }
1.691     raeburn  6972:                 $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
                   6973:                               'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606     raeburn  6974:             }
1.691     raeburn  6975:         }
                   6976:         my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   6977:         if (grep(/^\Q$crshome\E$/,@ids)) {
                   6978:             $is_home{'course'} = 1;
                   6979:         }
                   6980:         $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
                   6981:         my $pickdir = $lt{'loca'}.
                   6982:                    '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
                   6983:                    '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
                   6984:         if ($env{'user.author'}) {
                   6985:             $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
                   6986:         }
                   6987:         if (keys(%by_roletype)) {
                   6988:             foreach my $possrole ('ca','aa') {
                   6989:                 if (ref($by_roletype{$possrole}) eq 'HASH') {
                   6990:                     my $roletitle = &Apache::lonnet::plaintext($possrole);
                   6991:                     foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
                   6992:                         my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
                   6993:                         $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
                   6994:                                      $roletitle." ($audom/$auname)</option>\n";
1.606     raeburn  6995:                     }
                   6996:                 }
                   6997:             }
                   6998:         }
1.706     raeburn  6999:         if ($checkcrsres) {
                   7000:             $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n";
                   7001:         }
                   7002:         $pickdir .= '</select><br />'."\n".
1.691     raeburn  7003:                     $lt{'dire'}.
                   7004:                     '<select name="authorpath" onchange="toggleCrsResTitle();">'.
                   7005:                     '<option value=""></option>'.
                   7006:                     '</select><br />'."\n";
1.606     raeburn  7007:         my %seltemplate_menus;
                   7008:         my @files = &Apache::lonhomework::get_template_list('problem');
                   7009:         my @noexamplelink = ('blank.problem','blank.library','script.library');
                   7010:         my $currentcategory = '';
                   7011:         my @ordered = ('');
                   7012:         my %templatehelp;
                   7013:         my $defcategory = '';
                   7014:         my @catorder = ($defcategory);
                   7015:         $seltemplate_menus{$defcategory}->{'order'} = [''];
                   7016:         $seltemplate_menus{$defcategory}->{'text'} = '';
                   7017:         foreach my $file (@files) {
                   7018:             if (ref($file) eq 'ARRAY') {
                   7019:                 my ($path,$title,$category,$help) = @{$file};
                   7020:                 next if ($title !~ /\S/);
                   7021:                 if (&js_escape($category) ne $currentcategory) {
                   7022:                     $currentcategory = &js_escape($category);
                   7023:                     push(@catorder,&js_escape($currentcategory));
                   7024:                     $seltemplate_menus{$currentcategory}->{'text'} = $category;
                   7025:                     $seltemplate_menus{$currentcategory}->{'default'} = '';
                   7026:                     $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
                   7027:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
                   7028:                 }
                   7029:                 if ($path) {
                   7030:                     $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
                   7031:                     push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
                   7032:                     if ($help) {
                   7033:                         $templatehelp{$path} = $help;
                   7034:                     }
                   7035:                 }
                   7036:             }
                   7037:         }
                   7038: 
                   7039:         my $templates = $lt{'cate'}.' '.
                   7040:                         &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
                   7041:                                                                 $defcategory,'tempcategory','template',
                   7042:                                                                 \%seltemplate_menus,\@catorder,
                   7043:                                                                 "resize_scrollbox('contentscroll','1','0');",
                   7044:                                                                 "toggleExampleText();",'template').'<br />';
                   7045:         my $templatepreview =  '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true);  return false;">'.
1.701     raeburn  7046:                                '<span id="newresexample">'.&mt('Example').'</span></a>';
1.706     raeburn  7047:         my $crsresform;
                   7048:         if (($env{'user.author'}) || ($checkcrsres)) {
                   7049:             $crsresform=(<<RESFORM);
1.691     raeburn  7050:         <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.706     raeburn  7051:         $lt{'stpr'}</a>$help{'Standard_Problem'}
1.606     raeburn  7052:         <form action="/adm/coursedocs" method="post" name="courseresform">
                   7053:         <fieldset id="crsresform" style="display:none;">
                   7054:         <legend>$lt{'stpr'}</legend>
1.655     raeburn  7055:         <input type="hidden" name="active" value="bb" />
1.606     raeburn  7056:         <p>
                   7057:         $pickdir
1.701     raeburn  7058:         </p>
1.691     raeburn  7059:         <div id="newstdproblem" style="display:none;">
1.701     raeburn  7060:         <p>
1.606     raeburn  7061:         <span class="LC_nobreak">$lt{'news'}?&nbsp;
1.611     raeburn  7062:         <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606     raeburn  7063:         &nbsp;
1.611     raeburn  7064:         <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606     raeburn  7065:         </span><span id="newsubdir"></span>
                   7066:         <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
1.701     raeburn  7067:         </p>
1.699     raeburn  7068:         </div>
1.606     raeburn  7069:         $lt{'fnam'}
1.611     raeburn  7070:         <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.701     raeburn  7071:         <div id="newresource" style="display:none">
1.606     raeburn  7072:         <p>
                   7073:         $lt{'addp'}
1.611     raeburn  7074:         <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  7075:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  7076:         <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606     raeburn  7077:         $lt{'yes'}</label>
                   7078:         <span id="newrestitle"></span>
1.611     raeburn  7079:         <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.701     raeburn  7080:         </p>
1.606     raeburn  7081:         </div>
                   7082:         <p>
                   7083:         $lt{'uste'}
1.611     raeburn  7084:         <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  7085:         $lt{'no'}</label>&nbsp;&nbsp;
1.611     raeburn  7086:         <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606     raeburn  7087:         $lt{'yes'}</label>
1.701     raeburn  7088:         </p>
1.606     raeburn  7089:         <div id="newrestemplate" style="display:none">
                   7090:         $templates
                   7091:         $templatepreview
                   7092:         </div>
                   7093:         <span class="LC_nobreak">
1.701     raeburn  7094:         <input type="hidden" name="folderpath" value="$showpath" />
1.611     raeburn  7095:         <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606     raeburn  7096:         </span>
1.691     raeburn  7097:         <div id="stdprobswitch" style="display:none;">
1.689     raeburn  7098:         $rolehomes
                   7099:         <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
                   7100:         </div>
1.606     raeburn  7101:         </fieldset>
                   7102:         </form>
                   7103: 
                   7104: RESFORM
1.706     raeburn  7105:         }
1.534     raeburn  7106: 
1.342     ehlerst  7107: my $specialdocumentsform;
1.383     tempelho 7108: my @specialdocumentsforma;
1.451     www      7109: my $gradingform;
                   7110: my @gradingforma;
                   7111: my $communityform;
                   7112: my @communityforma;
1.351     ehlerst  7113: my $newfolderform;
1.390     tempelho 7114: my $newfolderb;
1.342     ehlerst  7115: 
1.451     www      7116: 	my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383     tempelho 7117: 	
1.329     droeschl 7118: 	my $newpageform=(<<NPFORM);
                   7119: 	<form action="/adm/coursedocs" method="post" name="newpage">
                   7120: 	<input type="hidden" name="folderpath" value="$path" />
                   7121: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  7122: 	<input type="hidden" name="active" value="ee" />
1.423     onken    7123: 	<a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383     tempelho 7124: 	$help{'Adding_Pages'}
1.329     droeschl 7125: 	</form>
                   7126: NPFORM
1.390     tempelho 7127: 
                   7128: 
1.351     ehlerst  7129: 	$newfolderform=(<<NFFORM);
1.329     droeschl 7130: 	<form action="/adm/coursedocs" method="post" name="newfolder">
1.508     raeburn  7131: 	$pathitem
1.329     droeschl 7132: 	<input type="hidden" name="importdetail" value="" />
1.570     raeburn  7133: 	<input type="hidden" name="active" value="" />
1.422     onken    7134: 	<a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329     droeschl 7135: 	</form>
                   7136: NFFORM
                   7137: 
                   7138: 	my $newsylform=(<<NSYLFORM);
                   7139: 	<form action="/adm/coursedocs" method="post" name="newsyl">
1.570     raeburn  7140: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  7141: 	$pathitem
1.329     droeschl 7142: 	<input type="hidden" name="importdetail" 
                   7143: 	value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  7144: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329     droeschl 7145: 	$help{'Syllabus'}
1.383     tempelho 7146: 
1.329     droeschl 7147: 	</form>
                   7148: NSYLFORM
1.364     bisitz   7149: 
1.329     droeschl 7150: 	my $newgroupfileform=(<<NGFFORM);
                   7151: 	<form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655     raeburn  7152: 	<input type="hidden" name="active" value="ee" />
1.508     raeburn  7153: 	$pathitem
1.329     droeschl 7154: 	<input type="hidden" name="importdetail"
                   7155: 	value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611     raeburn  7156: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353     weissno  7157: 	$help{'Group Portfolio'}
1.329     droeschl 7158: 	</form>
                   7159: NGFFORM
1.672     raeburn  7160:         if ($container eq 'page') {
                   7161:             @specialdocumentsforma=(
                   7162:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
                   7163:             );
                   7164:         } else {
                   7165: 	    @specialdocumentsforma=(
1.421     onken    7166: 	{'<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  7167: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611     raeburn  7168: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451     www      7169:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534     raeburn  7170:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672     raeburn  7171:             );
                   7172:         }
1.451     www      7173:         $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
                   7174: 
1.655     raeburn  7175:         my @external = (
                   7176:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519     raeburn  7177:         );
1.699     raeburn  7178:         if ($posslti) {
1.655     raeburn  7179:             push(@external,
                   7180:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
                   7181:             );
1.598     raeburn  7182:         }
1.655     raeburn  7183:         my $externalform = &create_form_ul(&create_list_elements(@external));
                   7184: 
                   7185:         my @importdoc = ();
1.519     raeburn  7186:         unless ($container eq 'page') {
                   7187:             push(@importdoc,
                   7188:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
                   7189:             );
                   7190:         }
                   7191:         push(@importdoc,
1.558     raeburn  7192:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519     raeburn  7193:         );
1.501     raeburn  7194:         $fileuploadform =  &create_form_ul(&create_list_elements(@importdoc));
1.434     raeburn  7195: 
1.451     www      7196:         @gradingforma=(
                   7197:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
                   7198:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
1.706     raeburn  7199:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.451     www      7200:         );
1.706     raeburn  7201:         if ($crsresform) {
                   7202:             push(@gradingforma,
                   7203:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform}
                   7204:             );
                   7205:         }
1.451     www      7206:         $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
                   7207: 
                   7208:         @communityforma=(
                   7209:        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
                   7210:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
                   7211:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611     raeburn  7212:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
                   7213:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451     www      7214:         );
                   7215:         $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383     tempelho 7216: 
1.330     tempelho 7217: my %orderhash = (
1.553     raeburn  7218:                 'aa' => ['Upload',$fileuploadform],
1.707     raeburn  7219:                 'bb' => ['External',$externalform],
                   7220:                 'cc' => ['Import',$importpubform],
1.701     raeburn  7221:                 'dd' => ['Assessment',$gradingform],
1.673     raeburn  7222:                 'ff' => ['Other',$specialdocumentsform],
1.330     tempelho 7223:                 );
1.519     raeburn  7224: unless ($container eq 'page') {
1.434     raeburn  7225:     $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655     raeburn  7226:     $orderhash{'ee'} = ['Collaboration',$communityform];
1.434     raeburn  7227: }
                   7228: 
1.341     ehlerst  7229:  $hadchanges=0;
1.484     raeburn  7230:        unless (($supplementalflag || $toolsflag)) {
1.458     raeburn  7231:           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615     raeburn  7232:                               $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622     raeburn  7233:                               \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617     raeburn  7234:           undef($navmap);
1.443     www      7235:           if ($error) {
                   7236:              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   7237:           }
1.639     raeburn  7238:           if ($hadchanges) {
                   7239:               unless (&is_hash_old()) {
1.638     raeburn  7240:                   &mark_hash_old();
                   7241:               }
                   7242: 	  }
1.341     ehlerst  7243: 
1.443     www      7244:           &changewarning($r,'');
                   7245:         }
1.458     raeburn  7246:     }
1.442     www      7247: 
1.443     www      7248: # Supplemental documents start here
                   7249: 
1.329     droeschl 7250:        my $folder=$env{'form.folder'};
1.443     www      7251:        unless ($supplementalflag) {
1.329     droeschl 7252: 	   $folder='supplemental';
                   7253:        }
1.685     raeburn  7254:        if (($folder eq 'supplemental') &&
1.329     droeschl 7255: 	   (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446     www      7256:           $env{'form.folderpath'} = &supplemental_base();
1.393     raeburn  7257:        } elsif ($allowed) {
1.356     tempelho 7258: 	  $env{'form.folderpath'} = $savefolderpath;
1.329     droeschl 7259:        }
1.508     raeburn  7260:        $pathitem = '<input type="hidden" name="folderpath" value="'.
                   7261:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329     droeschl 7262:        if ($allowed) {
                   7263: 	   my $folderseq=
1.504     raeburn  7264: 	       '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329     droeschl 7265: 
                   7266: 	my $supupdocform=(<<SUPDOCFORM);
1.501     raeburn  7267:         <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
                   7268:         $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383     tempelho 7269: 	<form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516     raeburn  7270:         <fieldset id="uploadsuppdocform" style="display: none;">
1.501     raeburn  7271:         <legend>$lt{'upfi'}</legend>
1.630     raeburn  7272: 	<input type="hidden" name="active" value="ee" />
1.329     droeschl 7273: 	$fileupload
1.702     raeburn  7274:         <input type="file" name="uploaddoc" id="uploaddocsupp" class="LC_flUpload LC_uploaddoc" size="40" $disabled />
                   7275:         <input type="hidden" id="LC_free_space_supp" value="$free_space" />
1.329     droeschl 7276: 	<br />
                   7277: 	<br />
                   7278: 	<span class="LC_nobreak">
                   7279: 	$checkbox
                   7280: 	</span>
                   7281: 	<br /><br />
                   7282: 	$lt{'comment'}:<br />
1.383     tempelho 7283: 	<textarea cols="50" rows="4" name="comment"></textarea>
1.329     droeschl 7284: 	<br />
1.508     raeburn  7285: 	$pathitem
1.329     droeschl 7286: 	<input type="hidden" name="cmd" value="upload_supplemental" />
1.501     raeburn  7287:         <input type='submit' value="$lt{'upld'}" />
1.700     raeburn  7288:         </fieldset>
1.501     raeburn  7289:         </form>
1.329     droeschl 7290: SUPDOCFORM
                   7291: 
                   7292: 	my $supnewfolderform=(<<SNFFORM);
                   7293: 	<form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570     raeburn  7294: 	<input type="hidden" name="active" value="" />
1.508     raeburn  7295:         $pathitem
1.329     droeschl 7296: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    7297: 	<a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a> 
1.383     tempelho 7298: 	$help{'Adding_Folders'}
1.329     droeschl 7299: 	</form>
                   7300: SNFFORM
1.383     tempelho 7301: 	
1.510     raeburn  7302:         my $supextform =
                   7303:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611     raeburn  7304:                                                  $help{'Adding_External_Resource'},
                   7305:                                                  undef,undef,undef,undef,undef,undef,
                   7306:                                                  $disabled);
1.329     droeschl 7307: 
1.598     raeburn  7308:         my $supexttoolform =
                   7309:             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
                   7310:                                                  $help{'Adding_External_Tool'},
                   7311:                                                  undef,undef,'tool',$coursedom,
1.611     raeburn  7312:                                                  $coursenum,\%ltitools,$disabled);
1.598     raeburn  7313: 
1.329     droeschl 7314: 	my $supnewsylform=(<<SNSFORM);
                   7315: 	<form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371     tempelho 7316: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  7317:         $pathitem
1.329     droeschl 7318: 	<input type="hidden" name="importdetail" 
                   7319: 	value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611     raeburn  7320: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329     droeschl 7321: 	$help{'Syllabus'}
                   7322: 	</form>
                   7323: SNSFORM
                   7324: 
                   7325: 	my $supnewaboutmeform=(<<SNAMFORM);
1.383     tempelho 7326: 	<form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371     tempelho 7327: 	<input type="hidden" name="active" value="ff" />
1.508     raeburn  7328:         $pathitem
1.329     droeschl 7329: 	<input type="hidden" name="importdetail" 
                   7330: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.611     raeburn  7331: 	<a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347     weissno  7332: 	$help{'My Personal Information Page'}
1.329     droeschl 7333: 	</form>
                   7334: SNAMFORM
                   7335: 
1.534     raeburn  7336:         my $supwebpage;
                   7337:         if ($folder =~ /^supplemental_?(\d*)$/) {
                   7338:             $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
                   7339:             if ($1) {
                   7340:                 $supwebpage .= $1;
                   7341:             } else {
                   7342:                 $supwebpage .= 'default';
                   7343:             }
                   7344:             $supwebpage .= '/new.html';
                   7345:         }
                   7346:         my $supwebpageform =(<<SWEBFORM);
                   7347:         <form action="/adm/coursedocs" method="post" name="supwebpage">
                   7348:         <input type="hidden" name="active" value="cc" />
                   7349:         $pathitem
                   7350:         <input type="hidden" name="importdetail" value="$supwebpage" />
                   7351:         <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556     raeburn  7352:         $help{'Web_Page'}
1.534     raeburn  7353:         </form>
                   7354: SWEBFORM
                   7355: 
1.333     muellerd 7356: 
1.383     tempelho 7357: my @specialdocs = (
1.618     raeburn  7358: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417     droeschl 7359:             =>$supnewsylform},
1.611     raeburn  7360: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417     droeschl 7361:             =>$supnewaboutmeform},
1.534     raeburn  7362:                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
                   7363: 
1.383     tempelho 7364: 		);
1.655     raeburn  7365:         my @supexternal = (
                   7366:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
                   7367:              =>$supextform});
1.699     raeburn  7368:         if ($posslti) {
1.655     raeburn  7369:             push(@supexternal,
                   7370:                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598     raeburn  7371:             =>$supexttoolform});
                   7372:         }
1.655     raeburn  7373:         my @supimportdoc = (
1.598     raeburn  7374:             {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501     raeburn  7375:             =>$supupdocform},
1.598     raeburn  7376:         );
1.501     raeburn  7377: 
                   7378: $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc));
1.333     muellerd 7379: my %suporderhash = (
1.390     tempelho 7380: 		'00' => ['Supnewfolder', $supnewfolderform],
1.655     raeburn  7381:                 'dd' => ['Upload',$supupdocform],
                   7382:                 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553     raeburn  7383:                 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333     muellerd 7384:                 );
1.443     www      7385:         if ($supplementalflag) {
1.682     raeburn  7386:             $suppchanges = 0;
                   7387:             my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
                   7388:                                 $supplementalflag,\%suporderhash,$iconpath,$pathitem,
                   7389:                                 \%ltitools,$canedit,$hostname);
                   7390:             if ($error) {
                   7391:                 $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   7392:             }
                   7393:             if ($suppchanges) {
1.684     raeburn  7394:                 &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682     raeburn  7395:                 undef($suppchanges);
                   7396:             }
1.393     raeburn  7397:         }
1.443     www      7398:     } elsif ($supplementalflag) {
1.458     raeburn  7399:         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682     raeburn  7400:                             $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
                   7401:                             $hostname);
1.393     raeburn  7402:         if ($error) {
                   7403:             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383     tempelho 7404:         }
1.393     raeburn  7405:     }
1.389     tempelho 7406: 
1.510     raeburn  7407:     if ($needs_end) {
                   7408:         $r->print(&endContentScreen());
                   7409:     }
1.383     tempelho 7410: 
1.329     droeschl 7411:     if ($allowed) {
                   7412: 	$r->print('
                   7413: <form method="post" name="extimport" action="/adm/coursedocs">
                   7414:   <input type="hidden" name="title" />
                   7415:   <input type="hidden" name="url" />
                   7416:   <input type="hidden" name="useform" />
                   7417:   <input type="hidden" name="residx" />
                   7418: </form>');
                   7419:     }
1.484     raeburn  7420:   } elsif ($showdoc) {
1.329     droeschl 7421: # -------------------------------------------------------- This is showdoc mode
1.484     raeburn  7422:       $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498     bisitz   7423: 		&Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329     droeschl 7424: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484     raeburn  7425:                 &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329     droeschl 7426:   }
                   7427:  }
1.630     raeburn  7428:  unless ($noendpage) {
1.606     raeburn  7429:      $r->print(&Apache::loncommon::end_page());
                   7430:  }
1.329     droeschl 7431:  return OK;
1.364     bisitz   7432: }
1.329     droeschl 7433: 
1.440     raeburn  7434: sub embedded_form_elems {
                   7435:     my ($phase,$primaryurl,$newidx) = @_;
                   7436:     my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634     raeburn  7437:     $newidx =~s /\D+//g;
1.440     raeburn  7438:     return <<STATE;
                   7439:     <input type="hidden" name="folderpath" value="$folderpath" />
                   7440:     <input type="hidden" name="cmd" value="upload_embedded" />
                   7441:     <input type="hidden" name="newidx" value="$newidx" />
                   7442:     <input type="hidden" name="phase" value="$phase" />
                   7443:     <input type="hidden" name="primaryurl" value="$primaryurl" />
                   7444: STATE
                   7445: }
                   7446: 
                   7447: sub embedded_destination {
                   7448:     my $folder=$env{'form.folder'};
                   7449:     my $destination = 'docs/';
                   7450:     if ($folder =~ /^supplemental/) {
                   7451:         $destination = 'supplemental/';
                   7452:     }
                   7453:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   7454:         $destination .= 'default/';
                   7455:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   7456:         $destination .=  $2.'/';
                   7457:     }
1.634     raeburn  7458:     my $newidx = $env{'form.newidx'};
                   7459:     $newidx =~s /\D+//g;
                   7460:     if ($newidx) {
                   7461:         $destination .= $newidx;
                   7462:     }
1.440     raeburn  7463:     my $dir_root = '/userfiles';
                   7464:     return ($destination,$dir_root);
                   7465: }
                   7466: 
                   7467: sub return_to_editor {
                   7468:     my $actionurl = '/adm/coursedocs';
                   7469:     return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n". 
                   7470:            '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
                   7471:            '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
                   7472:            '</a></p>';
                   7473: }
                   7474: 
1.476     raeburn  7475: sub decompression_info {
                   7476:     my ($destination,$dir_root) = &embedded_destination();
                   7477:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                   7478:     my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   7479:     my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   7480:     my $container='sequence';
1.480     raeburn  7481:     my ($pathitem,$hiddenelem);
1.583     raeburn  7482:     my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519     raeburn  7483:     if ($env{'form.folderpath'} =~ /\:1$/) {
1.476     raeburn  7484:         $container='page';
                   7485:     }
1.480     raeburn  7486:     unshift(@hiddens,$pathitem);
                   7487:     foreach my $item (@hiddens) {
1.634     raeburn  7488:         if ($item eq 'newidx') {
                   7489:             next if ($env{'form.'.$item} =~ /\D/);
                   7490:         }
1.480     raeburn  7491:         if ($env{'form.'.$item}) {
                   7492:             $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583     raeburn  7493:                            &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480     raeburn  7494:         }
1.477     raeburn  7495:     }
1.476     raeburn  7496:     return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
                   7497:             $hiddenelem);
                   7498: }
                   7499: 
                   7500: sub decompression_phase_one {
                   7501:     my ($dir,$file,$warning,$error,$output);
                   7502:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   7503:         &decompression_info();
1.490     raeburn  7504:     if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476     raeburn  7505:         $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
                   7506:     } else {
                   7507:         my $file = $1;
1.630     raeburn  7508:         $output =
1.481     raeburn  7509:             &Apache::loncommon::process_decompression($docudom,$docuname,$file,
                   7510:                                                       $destination,$dir_root,
                   7511:                                                       $hiddenelem);
                   7512:         if ($env{'form.autoextract_camtasia'}) {
                   7513:             $output .= &remove_archive($docudom,$docuname,$container);
                   7514:         }
1.476     raeburn  7515:     }
                   7516:     if ($error) {
                   7517:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   7518:                    $error.'</p>'."\n";
                   7519:     }
                   7520:     if ($warning) {
                   7521:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   7522:     }
                   7523:     return $output;
                   7524: }
                   7525: 
                   7526: sub decompression_phase_two {
                   7527:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   7528:         &decompression_info();
1.481     raeburn  7529:     my $output;
1.480     raeburn  7530:     if ($env{'form.archivedelete'}) {
1.481     raeburn  7531:         $output = &remove_archive($docudom,$docuname,$container);
1.480     raeburn  7532:     }
                   7533:     $output .= 
1.481     raeburn  7534:         &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476     raeburn  7535:                                                     $destination,$dir_root,$hiddenelem);
                   7536:     return $output;
                   7537: }
                   7538: 
1.480     raeburn  7539: sub remove_archive {
                   7540:     my ($docudom,$docuname,$container) = @_;
                   7541:     my $map = $env{'form.folder'}.'.'.$container;
1.481     raeburn  7542:     my ($output,$delwarning,$delresult,$url);
1.480     raeburn  7543:     my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
                   7544:     if ($fatal) {
                   7545:         if ($container eq 'page') {
                   7546:             $delwarning = &mt('An error occurred retrieving the contents of the current page.');
                   7547:         } else {
                   7548:             $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
                   7549:         }
1.583     raeburn  7550:         $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  7551:     } else {
                   7552:         my $currcmd = $env{'form.cmd'};
                   7553:         my $position = $env{'form.position'};
1.583     raeburn  7554:         my $archiveidx = $position;
1.563     raeburn  7555:         if ($position > 0) {
1.583     raeburn  7556:             if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
                   7557:                 $archiveidx = $position-1;
                   7558:             }
                   7559:             $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584     raeburn  7560:             my ($title,$url,@rrest) =
1.583     raeburn  7561:                 split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
                   7562:             if ($url eq $env{'form.archiveurl'}) {
                   7563:                 if (&handle_edit_cmd($docuname,$docudom)) {
                   7564:                     ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684     raeburn  7565:                     if ($suppchanges) {
                   7566:                         &Apache::lonnet::update_supp_caches($docudom,$docuname);
                   7567:                         undef($suppchanges);
                   7568:                     }
1.583     raeburn  7569:                     if ($fatal) {
                   7570:                         if ($container eq 'page') {
                   7571:                             $delwarning = &mt('An error occurred updating the contents of the current page.');
                   7572:                         } else {
                   7573:                             $delwarning = &mt('An error occurred updating the contents of the current folder.');
                   7574:                         }
1.480     raeburn  7575:                     } else {
1.583     raeburn  7576:                         $delresult = &mt('Archive file removed.');
1.480     raeburn  7577:                     }
                   7578:                 }
1.583     raeburn  7579:             } else {
                   7580:                 $delwarning .=  &mt('Archive file had unexpected item number in folder.').
                   7581:                                 ' '.&mt('As a result the archive file has not been removed.');
1.480     raeburn  7582:             }
                   7583:         }
                   7584:         $env{'form.cmd'} = $currcmd;
                   7585:     }
                   7586:     if ($delwarning) {
                   7587:         $output = '<p class="LC_warning">'.
                   7588:                    $delwarning.
                   7589:                    '</p>';
                   7590:     }
                   7591:     if ($delresult) {
                   7592:         $output .= '<p class="LC_info">'.
                   7593:                    $delresult.
                   7594:                    '</p>';
                   7595:     }
1.481     raeburn  7596:     return $output;
1.480     raeburn  7597: }
                   7598: 
1.484     raeburn  7599: sub generate_admin_menu {
1.708     raeburn  7600:     my ($crstype,$canedit,$coursenum,$coursedom) = @_;
1.484     raeburn  7601:     my $lc_crstype = lc($crstype);
                   7602:     my ($home,$other,%outhash)=&authorhosts();
1.562     bisitz   7603:     my %lt= ( # do not translate here
1.484     raeburn  7604:                                          'vc'   => 'Verify Content',
                   7605:                                          'cv'   => 'Check/Set Resource Versions',
                   7606:                                          'ls'   => 'List Resource Identifiers',
1.651     raeburn  7607:                                          'ct'   => 'Display/Set Shortened URLs for Deep-linking',
1.708     raeburn  7608:                                          'ca'   => "Enter $crstype Authoring Space",
1.484     raeburn  7609:                                          'imse' => 'Export contents to IMS Archive',
1.568     raeburn  7610:                                          'dcd'  => "Copy $crstype Content to Authoring Space",
1.562     bisitz   7611:             );
1.484     raeburn  7612:     my ($candump,$dumpurl);
                   7613:     if ($home + $other > 0) {
                   7614:         $candump = 'F';
                   7615:         if ($home) {
                   7616:             $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
                   7617:         } else {
                   7618:             my @hosts;
                   7619:             foreach my $aurole (keys(%outhash)) {
                   7620:                 unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   7621:                     push(@hosts,$outhash{$aurole});
1.538     raeburn  7622:                 }
1.484     raeburn  7623:             }
                   7624:             if (@hosts == 1) {
                   7625:                 my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
                   7626:                                '&amp;role='.
                   7627:                                &HTML::Entities::encode($env{'request.role'},'"<>&').'&amp;origurl='.
                   7628:                                &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
                   7629:                 $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
                   7630:             } else {
                   7631:                 $dumpurl = "javascript:choose_switchserver_window()";
                   7632:             }
                   7633:         }
                   7634:     }
                   7635:     my @menu=
                   7636:         ({  categorytitle=>'Administration',
                   7637:             items =>[
                   7638:                 {   linktext   => $lt{'vc'},
                   7639:                     url        => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
                   7640:                     permission => 'F',
1.571     raeburn  7641:                     help       => 'Docs_Verify_Content',
1.484     raeburn  7642:                     icon       => 'verify.png',
                   7643:                     linktitle  => 'Verify contents can be retrieved/rendered',
                   7644:                 },
                   7645:                 {   linktext => $lt{'cv'},
                   7646:                     url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
                   7647:                     permission => 'F',
1.571     raeburn  7648:                     help       => 'Docs_Check_Resource_Versions',
1.484     raeburn  7649:                     icon       => 'resversion.png',
                   7650:                     linktitle  => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
                   7651:                 },
                   7652:                 {   linktext   => $lt{'ls'},
                   7653:                     url        => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
                   7654:                     permission => 'F',
                   7655:                     #help => '',
                   7656:                     icon       => 'symbs.png',
                   7657:                     linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"
                   7658:                 },
1.651     raeburn  7659:                 {   linktext   => $lt{'ct'},
                   7660:                     url        => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
                   7661:                     permission => 'F',
                   7662:                     help       => 'Docs_Short_URLs',
                   7663:                     icon       => 'shorturls.png',
                   7664:                     linktitle  => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
                   7665:                 },
1.484     raeburn  7666:                 ]
1.611     raeburn  7667:         });
                   7668:     if ($canedit) {
1.708     raeburn  7669:         my ($crsauname,$crsaudom,$crshome);
                   7670:         if (($coursenum ne '') && ($coursedom ne '')) {
                   7671:             my $crsauthorurl = "/priv/$coursedom/$coursenum/";
                   7672:             ($crsauname,$crsaudom,$crshome) = &Apache::lonnet::constructaccess($crsauthorurl);
                   7673:             if (($crsauname eq $coursenum) && ($crsaudom eq $coursedom)) {
                   7674:                 my @ids=&Apache::lonnet::current_machine_ids();
                   7675:                 my $linkurl;
                   7676:                 if (grep(/^\Q$crshome\E$/,@ids)) {
                   7677:                     $linkurl = $crsauthorurl;
                   7678:                 } else {
                   7679:                     $linkurl =
                   7680:                         &Apache::lonhtmlcommon::jump_to_editres($crsauthorurl,$crshome,1);
                   7681:                 }
                   7682:                 if ((ref($menu[0]) eq 'HASH') && (ref($menu[0]->{'items'}) eq 'ARRAY')) {
                   7683:                      push(@{$menu[0]->{items}},
                   7684:                      {   linktext   => $lt{'ca'},
                   7685:                          url        => $linkurl,
                   7686:                          permission => 'F',
                   7687:                          help       => 'Docs_Course_Authorspace',
                   7688:                          icon       => 'impcrsau.png',
                   7689:                          linktitle  => $lt{'ca'},
                   7690:                      });
                   7691:                 }
                   7692:             }
                   7693:         }
1.611     raeburn  7694:         push(@menu,
1.484     raeburn  7695:         {   categorytitle=>'Export',
                   7696:             items =>[
                   7697:                 {   linktext   => $lt{'imse'},
                   7698:                     url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
                   7699:                     permission => 'F',
                   7700:                     help       => 'Docs_Export_Course_Docs',
                   7701:                     icon       => 'imsexport.png',
                   7702:                     linktitle  => $lt{'imse'},
                   7703:                 },
                   7704:                 {   linktext   => $lt{'dcd'},
                   7705:                     url        => $dumpurl,
                   7706:                     permission => $candump,
1.571     raeburn  7707:                     help       => 'Docs_Dump_Course_Docs',
1.484     raeburn  7708:                     icon       => 'dump.png',
                   7709:                     linktitle  => $lt{'dcd'},
                   7710:                 },
                   7711:                 ]
                   7712:         });
1.611     raeburn  7713:     }
1.484     raeburn  7714:     return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
                   7715:            '<input type="hidden" id="dummy" />'."\n".
                   7716:            &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
                   7717:            '</form>';
1.329     droeschl 7718: }
                   7719: 
                   7720: sub generate_edit_table {
1.538     raeburn  7721:     my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611     raeburn  7722:         $need_save,$copyfolder,$canedit) = @_;
1.406     raeburn  7723:     return unless(ref($orderhash_ref) eq 'HASH');
1.342     ehlerst  7724:     my %orderhash = %{$orderhash_ref};
1.611     raeburn  7725:     my ($form, $activetab, $active, $disabled);
1.570     raeburn  7726:     if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371     tempelho 7727:         $activetab = $env{'form.active'};
                   7728:     }
1.611     raeburn  7729:     unless ($canedit) {
                   7730:         $disabled = ' disabled="disabled"';
                   7731:     }
1.472     raeburn  7732:     my $backicon = $iconpath.'clickhere.gif';
1.525     raeburn  7733:     my $backtext = &mt('Exit Editor');
1.458     raeburn  7734:     $form = '<div class="LC_Box" style="margin:0;">'.
1.488     raeburn  7735:             '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
                   7736:             '<li class="goback">'.
1.546     raeburn  7737:             '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488     raeburn  7738:             '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
                   7739:             '  alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
                   7740:             '<li>'.
                   7741:             '<a href="javascript:groupopen('."'$readfile'".',1);">'.
                   7742:             &mt('Undo Delete').'</a></li>'."\n";
                   7743:     if ($env{'form.docslog'}) {
                   7744:         $form .= '<li class="active">';
                   7745:     } else {
                   7746:         $form .= '<li>';
                   7747:     }
                   7748:     $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
                   7749:              &mt('History').'</a></li>'."\n";
                   7750:     if ($env{'form.docslog'}) {
                   7751:         $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
                   7752:                  &mt('Edit').'</a></li>'."\n";
1.484     raeburn  7753:     }
1.458     raeburn  7754:     foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390     tempelho 7755:         if($name ne '00'){
1.371     tempelho 7756:             if($activetab eq '' || $activetab ne $name){
                   7757:                $active = '';
                   7758:             }elsif($activetab eq $name){
                   7759:                $active = 'class="active"';
                   7760:             }
1.458     raeburn  7761:             $form .= '<li style="float:right" '.$active
1.484     raeburn  7762:                 .' 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 7763:         } else {
1.570     raeburn  7764: 	    $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390     tempelho 7765: 
                   7766: 	}
1.329     droeschl 7767:     }
1.484     raeburn  7768:     $form .= '</ul>'."\n";
                   7769:     $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458     raeburn  7770: 
                   7771:     if ($to_show ne '') {
1.538     raeburn  7772:         my $saveform;
                   7773:         if ($need_save) {
                   7774:             my $button = &mt('Make changes');
                   7775:             my $path;
                   7776:             if ($env{'form.folderpath'}) {
                   7777:                 $path =
                   7778:                     &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   7779:             }
                   7780:             $saveform = <<"END";
                   7781: <div id="multisave" style="display:none; clear:both;" >
                   7782: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
                   7783: <input type="hidden" name="folderpath" value="$path" />
                   7784: <input type="hidden" name="symb" value="$env{'form.symb'}" />
                   7785: <input type="hidden" name="allhiddenresource" value="" />
                   7786: <input type="hidden" name="allencrypturl" value="" />
                   7787: <input type="hidden" name="allrandompick" value="" />
                   7788: <input type="hidden" name="allrandomorder" value="" />
                   7789: <input type="hidden" name="changeparms" value="" />
                   7790: <input type="hidden" name="multiremove" value="" />
                   7791: <input type="hidden" name="multicut" value="" />
                   7792: <input type="hidden" name="multicopy" value="" />
                   7793: <input type="hidden" name="multichange" value="" />
                   7794: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611     raeburn  7795: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538     raeburn  7796: </form>
                   7797: </div>
                   7798: END
                   7799:         }
                   7800:         $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458     raeburn  7801:     }
1.363     ehlerst  7802:     foreach my $field (keys(%orderhash)){
1.390     tempelho 7803: 	if($field ne '00'){
1.422     onken    7804:             if($activetab eq '' || $activetab ne $field){
1.458     raeburn  7805:                 $active = 'style="display: none;float:left"';
1.422     onken    7806:             }elsif($activetab eq $field){
1.458     raeburn  7807:                 $active = 'style="display:block;float:left"';
1.422     onken    7808:             }
                   7809:             $form .= '<div id="'.$field.$tid.'"'
                   7810:                     .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484     raeburn  7811:                     .'</div>'."\n";
1.363     ehlerst  7812:         }
                   7813:     }
1.484     raeburn  7814:     unless ($env{'form.docslog'}) {
                   7815:         $form .= '</div></div>'."\n";
                   7816:     }
1.329     droeschl 7817:     return $form;
                   7818: }
                   7819: 
                   7820: sub editing_js {
1.622     raeburn  7821:     my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
                   7822:         $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594     damieng  7823:     my %js_lt = &Apache::lonlocal::texthash(
1.329     droeschl 7824:                                           p_mnf => 'Name of New Folder',
                   7825:                                           t_mnf => 'New Folder',
                   7826:                                           p_mnp => 'Name of New Page',
                   7827:                                           t_mnp => 'New Page',
1.451     www      7828:                                           p_mxu => 'Title for the External Score',
1.349     biermanm 7829:                                           p_msp => 'Name of Simple Course Page',
1.329     droeschl 7830:                                           p_msb => 'Title for the Problem',
                   7831:                                           p_mdb => 'Title for the Drop Box',
1.336     schafran 7832:                                           p_mbb => 'Title for the Discussion Board',
1.604     raeburn  7833:                                           p_mwp => 'Title for Web Page',
1.606     raeburn  7834:                                           p_mnr => 'Title for the Resource',
1.348     weissno  7835:                                           p_mab => "Enter user:domain for User's Personal Information Page",
1.352     bisitz   7836:                                           p_mab2 => 'Personal Information Page of ',
1.329     droeschl 7837:                                           p_mab_alrt1 => 'Not a valid user:domain',
                   7838:                                           p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
                   7839:                                           p_chn => 'New Title',
                   7840:                                           p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603     raeburn  7841:                                           p_rmr2a => 'Remove',
                   7842:                                           p_rmr2b => '?',
                   7843:                                           p_rmr3a => 'Remove those',
                   7844:                                           p_rmr3b => 'items?',
                   7845:                                           p_rmr4  => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
                   7846:                                           p_rmr5  => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329     droeschl 7847:                                           p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
                   7848:                                           p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603     raeburn  7849:                                           p_ctr2a => 'Cut',
                   7850:                                           p_ctr2b => '?',
                   7851:                                           p_ctr3a => 'Cut those',
                   7852:                                           p_ctr3b => 'items?',
1.633     raeburn  7853:                                           setal   => 'Enter a (unique) alias',
                   7854:                                           delal   => 'Are you sure you want to eliminate the alias?',
1.478     raeburn  7855:                                           rpck    => 'Enter number to pick (e.g., 3)',
1.501     raeburn  7856:                                           imsfile => 'You must choose an IMS package for import',
                   7857:                                           imscms  => 'You must select which Course Management System was the source of the IMS package',
                   7858:                                           invurl  => 'Invalid URL',
                   7859:                                           titbl   => 'Title is blank',
1.538     raeburn  7860:                                           more    => '(More ...)',
                   7861:                                           less    => '(Less ...)',
1.543     raeburn  7862:                                           noor    => 'No actions selected or changes to settings specified.',
                   7863:                                           noch    => 'No changes to settings specified.',
                   7864:                                           noac    => 'No actions selected.',
1.606     raeburn  7865:                                           nofi    => 'No file selected',
                   7866:                                           tinc    => 'Title in course',
                   7867:                                           sunm    => 'Sub-directory name',
1.618     raeburn  7868:                                           edri    => 'Editing rights unavailable for your current role.',
1.691     raeburn  7869:                                           sele    => 'Select',
                   7870:                                           swit    => 'Switch server required',
1.329     droeschl 7871:                                         );
1.594     damieng  7872:     &js_escape(\%js_lt);
1.433     raeburn  7873:     my $crstype = &Apache::loncommon::course_type();
1.434     raeburn  7874:     my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
                   7875:     my $main_container_page;
1.519     raeburn  7876:     if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
                   7877:         $main_container_page = 1;
1.434     raeburn  7878:     }
1.617     raeburn  7879:     my $backtourl;
                   7880:     my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446     www      7881:     my $toplevelsupp = &supplemental_base();
1.690     raeburn  7882:     my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691     raeburn  7883:     my @ids=&Apache::lonnet::current_machine_ids();
                   7884:     my $machines_str = "'".join("','",@ids)."'";
1.530     raeburn  7885:     if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
                   7886:         my $caller = $1;
1.525     raeburn  7887:         if ($caller =~ /^supplemental/) {
                   7888:             $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
                   7889:         } else {
                   7890:             my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
                   7891:             $res = &Apache::lonnet::clutter($res);
                   7892:             if (&Apache::lonnet::is_on_map($res)) {
1.609     raeburn  7893:                 my ($url,$anchor);
                   7894:                 if ($res =~ /^([^#]+)#([^#]+)$/) {
                   7895:                     $url = $1;
                   7896:                     $anchor = $2;
                   7897:                     if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
                   7898:                         $caller = $1.&escape('#').$anchor;
                   7899:                     }
1.614     raeburn  7900:                 } else {
                   7901:                     $url = $res;
1.609     raeburn  7902:                 }
1.640     raeburn  7903:                 $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
                   7904:                 if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
                   7905:                     $backtourl .= '?navmap=1';
                   7906:                 } else {
                   7907:                     $backtourl .= '?symb='.
                   7908:                                   &HTML::Entities::encode($caller,'<>&"');
                   7909:                 }
1.622     raeburn  7910:                 if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
                   7911:                     if (($ENV{'SERVER_PORT'} == 443) &&
                   7912:                         ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678     raeburn  7913:                         unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657     raeburn  7914:                             if ($hostname ne '') {
                   7915:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   7916:                             }
                   7917:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.622     raeburn  7918:                         }
                   7919:                     }
1.623     raeburn  7920:                 } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
                   7921:                     if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678     raeburn  7922:                         unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658     raeburn  7923:                             if ($hostname ne '') {
                   7924:                                 $backtourl = 'http://'.$hostname.$backtourl;
                   7925:                             }
                   7926:                             $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
1.657     raeburn  7927:                         }
1.623     raeburn  7928:                     }
1.622     raeburn  7929:                 }
1.609     raeburn  7930:                 if ($anchor ne '') {
                   7931:                     $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
                   7932:                 }
1.590     raeburn  7933:                 $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544     raeburn  7934:             } else {
                   7935:                 $backtourl = '/adm/navmaps';
1.525     raeburn  7936:             }
                   7937:         }
                   7938:     } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
                   7939:         $backtourl = '/adm/menu';
                   7940:     } elsif ($supplementalflag) {
1.682     raeburn  7941:         if (($env{'request.role.adv'}) ||
                   7942:             (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
                   7943:             $backtourl = '/adm/supplemental';
                   7944:         } else {
                   7945:             $backtourl = '/adm/navmaps';
                   7946:         }
1.525     raeburn  7947:     } else {
                   7948:         $backtourl = '/adm/navmaps';
1.472     raeburn  7949:     }
                   7950: 
1.655     raeburn  7951:     my $fieldsets = "'doc'";
1.519     raeburn  7952:     unless ($main_container_page) {
                   7953:         $fieldsets .=",'ims'";
                   7954:     }
1.655     raeburn  7955:     my $extfieldsets = "'ext'";
                   7956:     if ($posslti) {
                   7957:         $extfieldsets .= ",'tool'";
                   7958:     }
1.501     raeburn  7959:     if ($supplementalflag) {
1.655     raeburn  7960:         $fieldsets = "'suppdoc'";
                   7961:         $extfieldsets = "'suppext'";
1.600     raeburn  7962:         if ($posslti) {
1.655     raeburn  7963:             $extfieldsets .= ",'supptool'";
1.600     raeburn  7964:         }
1.501     raeburn  7965:     }
1.655     raeburn  7966: 
1.611     raeburn  7967:     my $jsmakefunctions;
                   7968:     if ($canedit) {
                   7969:         $jsmakefunctions = <<ENDNEWSCRIPT;
1.329     droeschl 7970: function makenewfolder(targetform,folderseq) {
1.594     damieng  7971:     var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329     droeschl 7972:     if (foldername) {
1.676     raeburn  7973:        targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329     droeschl 7974:         targetform.submit();
                   7975:     }
                   7976: }
                   7977: 
                   7978: function makenewpage(targetform,folderseq) {
1.594     damieng  7979:     var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329     droeschl 7980:     if (pagename) {
1.676     raeburn  7981:         targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329     droeschl 7982:         targetform.submit();
                   7983:     }
                   7984: }
                   7985: 
                   7986: function makeexamupload() {
1.594     damieng  7987:    var title=prompt('$js_lt{"p_mxu"}');
1.344     bisitz   7988:    if (title) {
1.329     droeschl 7989:     this.document.forms.newexamupload.importdetail.value=
1.676     raeburn  7990: 	encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329     droeschl 7991:     this.document.forms.newexamupload.submit();
                   7992:    }
                   7993: }
                   7994: 
                   7995: function makesmppage() {
1.594     damieng  7996:    var title=prompt('$js_lt{"p_msp"}');
1.344     bisitz   7997:    if (title) {
1.329     droeschl 7998:     this.document.forms.newsmppg.importdetail.value=
1.676     raeburn  7999: 	encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329     droeschl 8000:     this.document.forms.newsmppg.submit();
                   8001:    }
                   8002: }
                   8003: 
1.534     raeburn  8004: function makewebpage(type) {
1.594     damieng  8005:    var title=prompt('$js_lt{"p_mwp"}');
1.534     raeburn  8006:    var formname;
                   8007:    if (type == 'supp') {
                   8008:        formname = this.document.forms.supwebpage;
                   8009:    } else {
                   8010:        formname = this.document.forms.newwebpage;
                   8011:    }
                   8012:    if (title) {
                   8013:        var webpage = formname.importdetail.value; 
1.675     raeburn  8014:        formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534     raeburn  8015:        formname.submit();
                   8016:    }
                   8017: }
                   8018: 
1.329     droeschl 8019: function makesmpproblem() {
1.594     damieng  8020:    var title=prompt('$js_lt{"p_msb"}');
1.344     bisitz   8021:    if (title) {
1.329     droeschl 8022:     this.document.forms.newsmpproblem.importdetail.value=
1.676     raeburn  8023: 	encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329     droeschl 8024:     this.document.forms.newsmpproblem.submit();
                   8025:    }
                   8026: }
                   8027: 
                   8028: function makedropbox() {
1.594     damieng  8029:    var title=prompt('$js_lt{"p_mdb"}');
1.344     bisitz   8030:    if (title) {
1.329     droeschl 8031:     this.document.forms.newdropbox.importdetail.value=
1.676     raeburn  8032:         encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329     droeschl 8033:     this.document.forms.newdropbox.submit();
                   8034:    }
                   8035: }
                   8036: 
                   8037: function makebulboard() {
1.594     damieng  8038:    var title=prompt('$js_lt{"p_mbb"}');
1.329     droeschl 8039:    if (title) {
                   8040:     this.document.forms.newbul.importdetail.value=
1.676     raeburn  8041: 	encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329     droeschl 8042:     this.document.forms.newbul.submit();
                   8043:    }
                   8044: }
                   8045: 
                   8046: function makeabout() {
1.594     damieng  8047:    var user=prompt("$js_lt{'p_mab'}");
1.329     droeschl 8048:    if (user) {
                   8049:        var comp=new Array();
                   8050:        comp=user.split(':');
                   8051:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   8052: 	   if ((comp[0]) && (comp[1])) {
                   8053: 	       this.document.forms.newaboutsomeone.importdetail.value=
1.594     damieng  8054: 		   '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611     raeburn  8055:                this.document.forms.newaboutsomeone.submit();
                   8056:            } else {
                   8057:                alert("$js_lt{'p_mab_alrt1'}");
                   8058:            }
                   8059:        } else {
                   8060:            alert("$js_lt{'p_mab_alrt2'}");
                   8061:        }
                   8062:     }
                   8063: }
                   8064: 
                   8065: function makenew(targetform) {
                   8066:     targetform.submit();
                   8067: }
                   8068: 
                   8069: function changename(folderpath,index,oldtitle) {
                   8070:     var title=prompt('$js_lt{"p_chn"}',oldtitle);
                   8071:     if (title) {
                   8072:         this.document.forms.renameform.markcopy.value='';
                   8073:         this.document.forms.renameform.title.value=title;
                   8074:         this.document.forms.renameform.cmd.value='rename_'+index;
                   8075:         this.document.forms.renameform.folderpath.value=folderpath;
                   8076:         this.document.forms.renameform.submit();
                   8077:     }
                   8078: }
                   8079: 
1.633     raeburn  8080: function setalias(folderpath,index) {
                   8081:     var alias = prompt('$js_lt{"setal"}');
                   8082:     if ((alias != null) && (alias != '')) {
                   8083:         this.document.forms.aliasform.alias.value=alias;
                   8084:         this.document.forms.aliasform.cmd.value='setalias_'+index;
                   8085:         this.document.forms.aliasform.folderpath.value=folderpath;
                   8086:         this.document.forms.aliasform.submit();
                   8087:     }
                   8088: }
                   8089: 
                   8090: function delalias(folderpath,index) {
                   8091:     if (confirm('$js_lt{"delal"}')) {
                   8092:         this.document.forms.aliasform.cmd.value='delalias_'+index;
                   8093:         this.document.forms.aliasform.folderpath.value=folderpath;
                   8094:         this.document.forms.aliasform.submit();
                   8095:     }
                   8096: }
                   8097: 
1.611     raeburn  8098: ENDNEWSCRIPT
                   8099:     } else {
                   8100:         $jsmakefunctions = <<ENDNEWSCRIPT;
                   8101: 
                   8102: function makenewfolder() {
                   8103:     alert("$js_lt{'edri'}");
                   8104: }
                   8105: 
                   8106: function makenewpage() {
                   8107:     alert("$js_lt{'edri'}");
                   8108: }
                   8109: 
                   8110: function makeexamupload() {
                   8111:     alert("$js_lt{'edri'}");
                   8112: }
                   8113: 
                   8114: function makesmppage() {
                   8115:     alert("$js_lt{'edri'}");
                   8116: }
                   8117: 
                   8118: function makewebpage(type) {
                   8119:     alert("$js_lt{'edri'}");
                   8120: }
                   8121: 
                   8122: function makesmpproblem() {
                   8123:     alert("$js_lt{'edri'}");
                   8124: }
                   8125: 
                   8126: function makedropbox() {
                   8127:     alert("$js_lt{'edri'}");
                   8128: }
                   8129: 
                   8130: function makebulboard() {
                   8131:     alert("$js_lt{'edri'}");
                   8132: }
                   8133: 
                   8134: function makeabout() {
                   8135:     alert("$js_lt{'edri'}");
                   8136: }
                   8137: 
                   8138: function changename() {
                   8139:     alert("$js_lt{'edri'}");
                   8140: }
                   8141: 
1.633     raeburn  8142: function setalias() {
                   8143:     alert("$js_lt{'edri'}");
                   8144: }
                   8145: 
                   8146: function delalias() {
                   8147:     alert("$js_lt{'edri'}");
                   8148: }
                   8149: 
1.611     raeburn  8150: function makenew() {
                   8151:     alert("$js_lt{'edri'}");
                   8152: }
                   8153: 
                   8154: function groupimport() {
                   8155:     alert("$js_lt{'edri'}");
1.335     ehlerst  8156: }
1.611     raeburn  8157: 
                   8158: function groupsearch() {
                   8159:     alert("$js_lt{'edri'}");
1.335     ehlerst  8160: }
1.611     raeburn  8161: 
                   8162: function groupopen(url,recover) {
                   8163:    var options="scrollbars=1,resizable=1,menubar=0";
                   8164:    idxflag=1;
                   8165:    idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
                   8166:    idx.focus();
1.329     droeschl 8167: }
                   8168: 
1.611     raeburn  8169: ENDNEWSCRIPT
                   8170: 
                   8171:     }
                   8172:     return <<ENDSCRIPT;
                   8173: 
                   8174: $jsmakefunctions
                   8175: 
1.501     raeburn  8176: function toggleUpload(caller) {
                   8177:     var blocks = Array($fieldsets);
                   8178:     for (var i=0; i<blocks.length; i++) {
                   8179:         var disp = 'none';
                   8180:         if (caller == blocks[i]) {
                   8181:             var curr = document.getElementById('upload'+caller+'form').style.display;
                   8182:             if (curr == 'none') {
                   8183:                 disp='block';
                   8184:             }
                   8185:         }
                   8186:         document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655     raeburn  8187:     }
                   8188:     resize_scrollbox('contentscroll','1','1');
                   8189:     return;
                   8190: }
                   8191: 
                   8192: function toggleExternal(caller) {
                   8193:     var blocks = Array($extfieldsets);
                   8194:     for (var i=0; i<blocks.length; i++) {
                   8195:         var disp = 'none';
                   8196:         if (caller == blocks[i]) {
                   8197:             var curr = document.getElementById('external'+caller+'form').style.display;
                   8198:             if (curr == 'none') {
                   8199:                 disp='block';
                   8200:             }
                   8201:         }
                   8202:         document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598     raeburn  8203:         if ((caller == 'tool') || (caller == 'supptool')) {
                   8204:             if (disp == 'block') {
1.655     raeburn  8205:                 if (document.getElementById('LC_exttoolid')) {
                   8206:                     var toolselector = document.getElementById('LC_exttoolid');
1.598     raeburn  8207:                     var suppflag = 0;
                   8208:                     if (caller == 'supptool') {
                   8209:                         suppflag = 1;
                   8210:                     }
                   8211:                     currForm = document.getElementById('new'+caller);
1.655     raeburn  8212:                     updateExttool(toolselector,currForm,suppflag);
1.598     raeburn  8213:                 }
                   8214:             }
                   8215:         }
1.501     raeburn  8216:     }
1.502     raeburn  8217:     resize_scrollbox('contentscroll','1','1');
                   8218:     return;
                   8219: }
                   8220: 
1.514     raeburn  8221: function toggleMap(caller) {
1.502     raeburn  8222:     var disp = 'none';
1.510     raeburn  8223:     if (document.getElementById('importmapform')) {
1.514     raeburn  8224:         if (caller == 'map') {
                   8225:             var curr = document.getElementById('importmapform').style.display;
                   8226:             if (curr == 'none') {
                   8227:                 disp='block';
                   8228:             }
1.510     raeburn  8229:         }
                   8230:         document.getElementById('importmapform').style.display=disp;
1.706     raeburn  8231:         if (disp == 'block') {
                   8232:             if (document.getElementById('importcrsresform')) {
                   8233:                 if (document.getElementById('importcrsresform').style.display == 'block') {
                   8234:                     document.getElementById('importcrsresform').style.display = 'none';
                   8235:                 }
                   8236:             }
                   8237:         }
1.510     raeburn  8238:         resize_scrollbox('contentscroll','1','1');
1.502     raeburn  8239:     }
1.501     raeburn  8240:     return;
1.329     droeschl 8241: }
                   8242: 
1.691     raeburn  8243: function toggleCrsRes(caller) {
1.606     raeburn  8244:     var disp = 'none';
                   8245:     if (document.getElementById('crsresform')) {
                   8246:         if (caller == 'res') {
1.691     raeburn  8247:             var form = document.getElementById('crsresform');
                   8248:             var curr = form.style.display;
1.606     raeburn  8249:             if (curr == 'none') {
                   8250:                 disp='block';
1.691     raeburn  8251:                 document.courseresform.authorrole.selectedIndex = 0;
                   8252:                 document.courseresform.authorpath.selectedIndex = 0;
                   8253:                 document.courseresform.newresourceadd.selectedIndex = 0;
                   8254:                 populateDirSelects(form,'authorrole','authorpath',1,0,0);
                   8255:                 toggleNewInCourse(document.courseresform);
                   8256:                 if (document.getElementById('newresource')) {
                   8257:                     document.getElementById('newresource').style.display = 'none';
1.606     raeburn  8258:                 }
                   8259:                 if (document.courseresform.newresusetemp.length) {
                   8260:                     document.courseresform.newresusetemp[0].checked = true;
                   8261:                     toggleWithTemplate(document.courseresform);
                   8262:                 }
                   8263:                 document.courseresform.newresourcename.value = ''; 
                   8264:             }
                   8265:         }
                   8266:         if (document.courseresform.newsubdir.length) {
                   8267:             for (var j=0; j<document.courseresform.newsubdir.length; j++) {
                   8268:                 if (document.courseresform.newsubdir[j].value == 0) {
                   8269:                     document.courseresform.newsubdir[j].checked = true;
                   8270:                 }
                   8271:                 break;
                   8272:             }
                   8273:             if (document.getElementById('newsubdirname')) {
                   8274:                 document.getElementById('newsubdirname').type = "hidden";
                   8275:                 document.getElementById('newsubdirname').value = "";
                   8276:             }
                   8277:             if (document.getElementById('newsubdir')) {
                   8278:                 document.getElementById('newsubdir').innerHTML = "";
                   8279:             }
                   8280:         }
                   8281:         document.getElementById('crsresform').style.display=disp;
                   8282:         resize_scrollbox('contentscroll','1','0');
                   8283:     }
                   8284:     return;
                   8285: }
                   8286: 
                   8287: function toggleNewsubdir(form) {
                   8288:     if (form.newsubdir.length) {
                   8289:         for (var j=0; j<form.newsubdir.length; j++) {
                   8290:             if (form.newsubdir[j].checked) {
                   8291:                 if (document.getElementById('newsubdirname')) {
                   8292:                     if (form.newsubdir[j].value == '1') {
                   8293:                         document.getElementById('newsubdirname').type = "text"; 
                   8294:                         if (document.getElementById('newsubdir')) {
                   8295:                             document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
                   8296:                         }
                   8297:                     } else {
                   8298:                         document.getElementById('newsubdirname').type = "hidden";
                   8299:                         document.getElementById('newsubdirname').value = "";
                   8300:                         document.getElementById('newsubdir').innerHTML = "";
                   8301:                     }
                   8302:                 }
                   8303:                 break;
                   8304:             }
                   8305:         }
                   8306:     }
                   8307: }
                   8308: 
                   8309: function toggleCrsResTitle() {
                   8310:     if (document.getElementById('newresource')) {
1.691     raeburn  8311:         var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
                   8312:         if (selloc == 'course') {
1.606     raeburn  8313:             document.getElementById('newresource').style.display = 'inline';
                   8314:             document.courseresform.newresourceadd[0].checked = true;
                   8315:             toggleNewInCourse(document.courseresform);
                   8316:         } else {
                   8317:             document.getElementById('newresource').style.display = 'none';
                   8318:         }
1.689     raeburn  8319:     }
                   8320:     if (document.getElementById('newstdproblem')) {
                   8321:         if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
                   8322:             document.getElementById('newstdproblem').style.display = 'none'; 
                   8323:             if (document.getElementById('stdprobswitch')) {
                   8324:                 document.getElementById('stdprobswitch').style.display = 'block'; 
                   8325:             }
                   8326:         } else {
                   8327:             document.getElementById('newstdproblem').style.display = 'block';
                   8328:             if (document.getElementById('stdprobswitch')) {
                   8329:                 document.getElementById('stdprobswitch').style.display = 'none';
                   8330:             }
                   8331:         }
                   8332:     }
1.606     raeburn  8333: }
                   8334: 
                   8335: function toggleNewInCourse(form) {
                   8336:     if (form.newresourceadd.length) {
                   8337:         for (var i=0; i<form.newresourceadd.length; i++) {
                   8338:             if (form.newresourceadd[i].checked) {
                   8339:                 if (document.getElementById('newresourcetitle')) {
                   8340:                     if (form.newresourceadd[i].value == '1') {
                   8341:                         document.getElementById('newresourcetitle').type = 'text';
                   8342:                         if (document.getElementById('newrestitle')) {
                   8343:                             document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
                   8344:                         }
                   8345:                     } else {
                   8346:                         document.getElementById('newresourcetitle').type = 'hidden';
                   8347:                         document.getElementById('newresourcetitle').value = '';
                   8348:                         if (document.getElementById('newrestitle')) { 
                   8349:                             document.getElementById('newrestitle').innerHTML = '';
                   8350:                         }
                   8351:                     }
                   8352:                 }
                   8353:                 break;
                   8354:             }
                   8355:         }
                   8356:     }
                   8357: }
                   8358: 
                   8359: function toggleWithTemplate(form) {
                   8360:     if (form.newresusetemp.length) {
                   8361:         for (var i=0; i<form.newresusetemp.length; i++) {
                   8362:             if (form.newresusetemp[i].checked) {
                   8363:                 if (document.getElementById('newrestemplate')) { 
                   8364:                     if (form.newresusetemp[i].value == '1') {
                   8365:                         document.getElementById('newrestemplate').style.display = 'inline';
                   8366:                         toggleExampleText();
                   8367:                     } else {
                   8368:                         form.tempcategory.selectedIndex = 0;
                   8369:                         select1template_changed();
                   8370:                         document.getElementById('newrestemplate').style.display = 'none';
                   8371:                     }
                   8372:                 }
                   8373:             }
                   8374:         }
                   8375:     }
                   8376: }
                   8377: 
                   8378: function toggleExampleText() {
                   8379:     if (document.getElementById('newresexample')) {
                   8380:         var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   8381:         if (url == '') {
                   8382:             document.getElementById('newresexample').style.fontWeight = 'normal';
                   8383:         } else {
                   8384:             document.getElementById('newresexample').style.fontWeight = 'bold';
                   8385:         }
                   8386:     }
                   8387: }
                   8388: 
                   8389: function getExample(width,height,scrolling,transparency) {
                   8390:     var url;
                   8391:     if (document.courseresform.newresusetemp.length) {
                   8392:         for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
                   8393:             if (document.courseresform.newresusetemp[i].checked) {
                   8394:                 if (document.courseresform.newresusetemp[i].value == '1') {
                   8395:                     var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
                   8396:                     if (url == '') {
                   8397:                         alert('Pick a category and template');
                   8398:                     } else {
                   8399:                         url = url.replace("$londocroot",""); 
                   8400:                         url += '?inhibitmenu=yes';
                   8401:                     }
                   8402:                 }
                   8403:                 break;
                   8404:             }
                   8405:         }
                   8406:     }
                   8407:     if (url != '') {
                   8408:         openMyModal(url,width,height,scrolling,transparency,'');
                   8409:     }
                   8410: }
                   8411: 
1.690     raeburn  8412: function toggleImportCrsres(caller) {
1.606     raeburn  8413:     var disp = 'none';
                   8414:     if (document.getElementById('importcrsresform')) {
                   8415:         if (caller == 'res') {
                   8416:             var curr = document.getElementById('importcrsresform').style.display;
                   8417:             if (curr == 'none') {
                   8418:                 disp='block';
1.698     raeburn  8419:                 populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1,0);
                   8420:                 if ((document.getElementById('importcrsrescontent')) &&
                   8421:                     (document.getElementById('importcrsresempty'))) {
                   8422:                     var selelem = document.crsresimportform.elements['coursepath'];
                   8423:                     var numdirs = 0;
                   8424:                     if (selelem.options.length) {
                   8425:                         numdirs = selelem.options.length - 1;
                   8426:                     }
                   8427:                     if (numdirs) {
                   8428:                         document.getElementById('importcrsrescontent').style.display='block';
                   8429:                         document.getElementById('importcrsresempty').style.display='none';
                   8430:                     } else {
                   8431:                         document.getElementById('importcrsrescontent').style.display='none';
                   8432:                         document.getElementById('importcrsresempty').style.display='block';
                   8433:                     }
                   8434:                 }
1.606     raeburn  8435:             }
                   8436:         }
                   8437:         document.getElementById('importcrsresform').style.display=disp;
1.706     raeburn  8438:         if (disp == 'block') {
                   8439:             if (document.getElementById('importmapform')) {
                   8440:                 if (document.getElementById('importmapform').style.display == 'block') {
                   8441:                     document.getElementById('importmapform').style.display = 'none';
                   8442:                 }
                   8443:             }
                   8444:         }
1.606     raeburn  8445:         resize_scrollbox('contentscroll','1','0');
                   8446:     }
                   8447:     return;
                   8448: }
                   8449: 
1.690     raeburn  8450: $showfile_js
                   8451: 
1.691     raeburn  8452: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
                   8453:     var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
                   8454:     if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
                   8455:         var selelem = form.elements[dirsel];
                   8456:         var i, numfiles = selelem.options.length -1;
                   8457:         if (numfiles >=0) {
                   8458:             for (i = numfiles; i >= 0; i--) {
                   8459:                 selelem.remove(i);
                   8460:             }
                   8461:         }
                   8462:         if ((location == '') || (location == null) || (location == 'undefined')) {
                   8463:              if (selelem.options.length == 0) {
                   8464:                  selelem.options[selelem.options.length] = new Option('','');
                   8465:                  selelem.selectedIndex = 0;
                   8466:              }
                   8467:              if (document.getElementById('newstdproblem')) {
                   8468:                  document.getElementById('newstdproblem').style.display = 'none';
                   8469:              }
                   8470:              return;
                   8471:         }
                   8472:         var machineIds = new Array($machines_str);
                   8473:         var athome = 0;
                   8474:         var role = location;
                   8475:         if ((location == 'author') || (location == 'course')) {
                   8476:             if (document.getElementById('rolehome_'+location)) {
                   8477:                 var currhome = document.getElementById('rolehome_'+location).value;
                   8478:                 if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
                   8479:                     if (machineIds.includes(currhome)) {
                   8480:                         athome = 1;
                   8481:                     }
                   8482:                 }
                   8483:             }
                   8484:         } else {
                   8485:             const roleinfo = location.split('___');
                   8486:             role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
                   8487:             if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
                   8488:                 var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
                   8489:                 if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
                   8490:                     if (machineIds.includes(currhome)) {
                   8491:                         athome = 1;
                   8492:                     }
                   8493:                 }
                   8494:             }
                   8495:         }
1.706     raeburn  8496:         var templateradio = document.courseresform.elements['newresusetemp'];
1.691     raeburn  8497:         if (athome) {
                   8498:             if (document.getElementById('stdprobswitch')) {
                   8499:                 document.getElementById('stdprobswitch').style.display = 'none';
                   8500:             }
                   8501:             if (document.getElementById('newstdproblem')) {
                   8502:                 document.getElementById('newstdproblem').style.display = 'none';
                   8503:             }
1.706     raeburn  8504:             var canedit = '$canedit';
                   8505:             if (canedit) {
                   8506:                 if (templateradio.length > 1) {
                   8507:                     for (var i=0; i<templateradio.length; i++) {
                   8508:                         templateradio[i].disabled = false;
                   8509:                     }
                   8510:                 }
                   8511:                 document.courseresform.newresourcename.disabled = false;
                   8512:                 document.courseresform.newcrs.disabled = false;
                   8513:             }
1.691     raeburn  8514:             var http = new XMLHttpRequest();
                   8515:             var url = "/adm/courseauthor";
1.698     raeburn  8516:             var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir+"&addtop=1";
1.691     raeburn  8517:             http.open("POST", url, true);
                   8518:             http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                   8519:             http.onreadystatechange = function() {
                   8520:                 if (http.readyState == 4 && http.status == 200) {
                   8521:                     var data = JSON.parse(http.responseText);
                   8522:                     if (Array.isArray(data.dirs)) {
                   8523:                         var len = data.dirs.length;
                   8524:                         if (len) {
                   8525:                             if (len > 1) {
                   8526:                                 selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
                   8527:                             }
                   8528:                         }
                   8529:                         if (len) {
                   8530:                             var j;
                   8531:                             for (j = 0; j < len; j++) {
                   8532:                                 selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
                   8533:                             }
                   8534:                             selelem.selectedIndex = 0;
1.697     raeburn  8535:                             if (len == 1) {
                   8536:                                 toggleCrsResTitle();
                   8537:                             }
1.691     raeburn  8538:                         }
                   8539:                     }
                   8540:                 }
                   8541:             }
                   8542:             http.send(params);
                   8543:         } else {
                   8544:             selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
                   8545:             selelem.selectedIndex = 0;
                   8546:             if (document.getElementById('stdprobswitch')) {
                   8547:                 document.getElementById('stdprobswitch').style.display = 'block';
                   8548:             }
                   8549:             if (document.getElementById('newstdproblem')) {
                   8550:                 document.getElementById('newstdproblem').style.display = 'none';
                   8551:             }
1.706     raeburn  8552:             if (templateradio.length > 1) {
                   8553:                 for (var i=0; i<templateradio.length; i++) {
                   8554:                     templateradio[i].disabled = true;
                   8555:                 }
                   8556:             }
                   8557:             document.courseresform.newresourcename.disabled = true;
                   8558:             document.courseresform.newcrs.disabled = true;
1.691     raeburn  8559:         }
                   8560:     }
                   8561:     return;
                   8562: }
                   8563: 
1.689     raeburn  8564: function switchForProb() {
                   8565:     if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
                   8566:         var url = '/adm/switchserver?otherserver=';
                   8567:         var newhostid = '';
                   8568:         var role = '';
                   8569:         var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
                   8570:         if (selloc == 'author') {
                   8571:             newhostid = document.courseresform.rolehome_author.value;
                   8572:             role = "au./&js_escape($env{'user.domain'})/";
                   8573:         } else if (selloc == 'course') {
                   8574:             newhostid = document.courseresform.rolehome_course.value;
                   8575:             role = "&js_escape($env{'request.role'})";
                   8576:         } else {
                   8577:             var items = new Array();
                   8578:             items = selloc.split('___');
                   8579:             var len = document.courseresform.rolehome_coauthor.length;
                   8580:             if (null == len) {
                   8581:                 var currval = document.courseresform.rolehome_coauthor.value;
                   8582:                 if (null != currval) {
                   8583:                     var info = new Array();
                   8584:                     info = currval.split('=');
                   8585:                     newhostid = info[2];
                   8586:                     role = info[0]+'./'+info[1];
                   8587:                 }
                   8588:             } else {
                   8589:                 for (var i=0; i<len; i++) {
                   8590:                     var currval = document.courseresform.rolehome_coauthor[i].value;
                   8591:                     if (null != currval) {
                   8592:                         var info = new Array();
                   8593:                         info = currval.split('=');
                   8594:                         if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
                   8595:                             newhostid = info[2];
                   8596:                             role = info[0]+'./'+info[1];
                   8597:                             break;
                   8598:                         }
                   8599:                     }
                   8600:                 }
                   8601:             }
                   8602:         }
                   8603:         if (newhostid != '') {
                   8604:             url += newhostid;
                   8605:             if (role != '') {
                   8606:                 url += '&role='+role;
                   8607:             }
                   8608:             document.location.href = url;
                   8609:         }
                   8610:     }
                   8611:     return;
                   8612: }
                   8613: 
1.501     raeburn  8614: function makeims(imsform) {
                   8615:     if ((imsform.uploaddoc.value == '')  || (!imsform.uploaddoc.value)) {
1.594     damieng  8616:         alert("$js_lt{'imsfile'}");
1.501     raeburn  8617:         return;
                   8618:     }
                   8619:     if (imsform.source.selectedIndex == 0) {
1.594     damieng  8620:         alert("$js_lt{'imscms'}");
1.501     raeburn  8621:         return;
                   8622:     }
                   8623:     newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
                   8624:     imsform.submit();
                   8625: }
                   8626: 
1.478     raeburn  8627: function updatePick(targetform,index,caller) {
1.537     raeburn  8628:     var pickitem;
                   8629:     var picknumitem;
                   8630:     var picknumtext;
                   8631:     if (index == 'all') {
                   8632:         pickitem = document.getElementById('randompickall');
                   8633:         picknumitem = document.getElementById('rpicknumall');
                   8634:         picknumtext = document.getElementById('rpicktextall');
                   8635:     } else {
                   8636:         pickitem = document.getElementById('randompick_'+index);
                   8637:         picknumitem = document.getElementById('rpicknum_'+index);
                   8638:         picknumtext = document.getElementById('randompicknum_'+index);
                   8639:     }
1.478     raeburn  8640:     if (pickitem.checked) {
1.594     damieng  8641:         var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478     raeburn  8642:         if (picknum == '' || picknum == null) {
                   8643:             if (caller == 'check') {
                   8644:                 pickitem.checked=false;
1.537     raeburn  8645:                 if (index == 'all') {
                   8646:                     picknumtext.innerHTML = '';
                   8647:                     if (caller == 'link') {
                   8648:                         propagateState(targetform,'rpicknum');
                   8649:                     }
                   8650:                 } else {
1.538     raeburn  8651:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8652:                 }
1.478     raeburn  8653:             }
                   8654:         } else {
                   8655:             picknum.toString();
                   8656:             var regexdigit=/^\\d+\$/;
                   8657:             if (regexdigit.test(picknum)) {
                   8658:                 picknumitem.value = picknum;
1.537     raeburn  8659:                 if (index == 'all') {
1.538     raeburn  8660:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537     raeburn  8661:                     if (caller == 'link') {
                   8662:                         propagateState(targetform,'rpicknum');
                   8663:                     }
                   8664:                 } else {
                   8665:                     picknumtext.innerHTML = '&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538     raeburn  8666:                     checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8667:                 }
1.478     raeburn  8668:             } else {
                   8669:                 if (caller == 'check') {
1.537     raeburn  8670:                     if (index == 'all') {
                   8671:                         picknumtext.innerHTML = '';
                   8672:                         if (caller == 'link') {
                   8673:                             propagateState(targetform,'rpicknum');
                   8674:                         }
                   8675:                     } else {
                   8676:                         pickitem.checked=false;
1.538     raeburn  8677:                         checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8678:                     }
1.478     raeburn  8679:                 }
                   8680:                 return;
                   8681:             }
                   8682:         }
                   8683:     } else {
1.537     raeburn  8684:         picknumitem.value = '';
                   8685:         picknumtext.innerHTML = '';
                   8686:         if (index == 'all') {
                   8687:             if (caller == 'link') {
                   8688:                 propagateState(targetform,'rpicknum');
                   8689:             }
                   8690:         } else {
1.538     raeburn  8691:             checkForSubmit(targetform,'randompick','settings');
1.537     raeburn  8692:         }
                   8693:     }
                   8694: }
                   8695: 
                   8696: function propagateState(form,param) {
                   8697:     if (document.getElementById(param+'all')) {
                   8698:         var setcheck = 0;
                   8699:         var rpick = 0;
                   8700:         if (param == 'rpicknum') {
                   8701:             if (document.getElementById('randompickall')) {
                   8702:                 if (document.getElementById('randompickall').checked) {
                   8703:                     if (document.getElementById('rpicknumall')) {
                   8704:                         rpick = document.getElementById('rpicknumall').value;
                   8705:                     }
                   8706:                 }
                   8707:             }
                   8708:         } else {
                   8709:             if (document.getElementById(param+'all').checked) {
                   8710:                 setcheck = 1;
                   8711:             }
                   8712:         }
1.538     raeburn  8713:         var allidxlist;
                   8714:         if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   8715:             if (document.getElementById('all'+param+'idx')) {
                   8716:                 allidxlist = document.getElementById('all'+param+'idx').value;
                   8717:             }
                   8718:             var actions = new Array ('remove','cut','copy');
                   8719:             for (var i=0; i<actions.length; i++) {
                   8720:                 if (actions[i] != param) {
                   8721:                     if (document.getElementById(actions[i]+'all')) {
                   8722:                         document.getElementById(actions[i]+'all').checked = false; 
                   8723:                     }
                   8724:                 }
                   8725:             }
                   8726:         }
1.537     raeburn  8727:         if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538     raeburn  8728:             allidxlist = form.allidx.value;
                   8729:         }
                   8730:         if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
                   8731:             allidxlist = form.allmapidx.value;
                   8732:         }
                   8733:         if ((allidxlist != '') && (allidxlist != null)) {
                   8734:             var allidxs = allidxlist.split(',');
                   8735:             if (allidxs.length > 1) {
                   8736:                 for (var i=0; i<allidxs.length; i++) {
                   8737:                     if (document.getElementById(param+'_'+allidxs[i])) {
                   8738:                         if (param == 'rpicknum') {
                   8739:                             if (document.getElementById('randompick_'+allidxs[i])) {
                   8740:                                 if (document.getElementById('randompick_'+allidxs[i]).checked) {
                   8741:                                     document.getElementById(param+'_'+allidxs[i]).value = rpick;
                   8742:                                     if (rpick > 0) {
                   8743:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ':&nbsp;<a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
                   8744:                                     } else {
                   8745:                                         document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   8746:                                     }
                   8747:                                 }
                   8748:                             }
                   8749:                         } else {
1.537     raeburn  8750:                             if (setcheck == 1) {
                   8751:                                 document.getElementById(param+'_'+allidxs[i]).checked = true;
                   8752:                             } else {
                   8753:                                 document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538     raeburn  8754:                                 if (param == 'randompick') {
                   8755:                                     document.getElementById('randompicknum_'+allidxs[i]).innerHTML =  '';
                   8756:                                 }
1.537     raeburn  8757:                             }
                   8758:                         }
                   8759:                     }
                   8760:                 }
1.538     raeburn  8761:                 if (setcheck == 1) {
                   8762:                     if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
                   8763:                         var actions = new Array('copy','cut','remove');
                   8764:                         for (var i=0; i<actions.length; i++) {
                   8765:                             var otheractions;
                   8766:                             var otheridxs;
                   8767:                             if (actions[i] === param) {
                   8768:                                 continue;
                   8769:                             } else {
                   8770:                                 if (document.getElementById('all'+actions[i]+'idx')) {
                   8771:                                     otheractions = document.getElementById('all'+actions[i]+'idx').value;
                   8772:                                     otheridxs = otheractions.split(',');
                   8773:                                     if (otheridxs.length > 1) {
                   8774:                                         for (var j=0; j<otheridxs.length; j++) {
                   8775:                                             if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
                   8776:                                                 document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
                   8777:                                             }
1.537     raeburn  8778:                                         }
                   8779:                                     }
                   8780:                                 }
1.538     raeburn  8781:                             }
                   8782:                         } 
                   8783:                     }
                   8784:                 }
                   8785:             }
                   8786:         }
                   8787:     }
                   8788:     return;
                   8789: }
                   8790: 
1.603     raeburn  8791: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611     raeburn  8792:     var canedit = '$canedit';
                   8793:     if (canedit == '') {
                   8794:         alert("$js_lt{'edri'}");
                   8795:         return;
                   8796:     }
1.539     raeburn  8797:     var dosettings;
                   8798:     var doaction;
1.538     raeburn  8799:     var control = document.togglemultsettings;
                   8800:     if (context == 'actions') {
                   8801:         control = document.togglemultactions;
1.539     raeburn  8802:         doaction = 1; 
                   8803:     } else {
                   8804:         dosettings = 1;
1.538     raeburn  8805:     }
1.539     raeburn  8806:     if (control) {
                   8807:         if (control.showmultpick.length) {
                   8808:             for (var i=0; i<control.showmultpick.length; i++) {
                   8809:                 if (control.showmultpick[i].checked) {
                   8810:                     if (control.showmultpick[i].value == 1) {
                   8811:                         if (context == 'settings') {
                   8812:                             dosettings = 0;
                   8813:                         } else {
                   8814:                             doaction = 0;
1.538     raeburn  8815:                         }
                   8816:                     }
                   8817:                 }
1.537     raeburn  8818:             }
                   8819:         }
1.539     raeburn  8820:     }
                   8821:     if (context == 'settings') {
                   8822:         if (dosettings == 1) {
1.538     raeburn  8823:             targetform.changeparms.value=param;
                   8824:             targetform.submit();
                   8825:         }
1.537     raeburn  8826:     }
1.539     raeburn  8827:     if (context == 'actions') {
                   8828:         if (doaction == 1) {
                   8829:             targetform.cmd.value=param+'_'+index;
                   8830:             targetform.folderpath.value=folderpath;
                   8831:             targetform.markcopy.value=idx+':'+param;
                   8832:             targetform.copyfolder.value=folder+'.'+container;
                   8833:             if (param == 'remove') {
1.603     raeburn  8834:                 var doremove = 0;
                   8835:                 if (skip_confirm) {
                   8836:                     if (confirm_removal) {
                   8837:                         if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
                   8838:                             doremove = 1;
                   8839:                         }
                   8840:                     } else {
                   8841:                         doremove = 1;
                   8842:                     }
                   8843:                 } else {
                   8844:                     if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
                   8845:                         doremove = 1;
                   8846:                     }
                   8847:                 }
                   8848:                 if (doremove) {
1.539     raeburn  8849:                     targetform.markcopy.value='';
                   8850:                     targetform.copyfolder.value='';
                   8851:                     targetform.submit();
                   8852:                 }
                   8853:             }
                   8854:             if (param == 'cut') {
1.594     damieng  8855:                 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  8856:                     targetform.submit();
                   8857:                     return;
                   8858:                 }
                   8859:             }
                   8860:             if (param == 'copy') {
                   8861:                 targetform.submit();
                   8862:                 return;
                   8863:             }
                   8864:             targetform.markcopy.value='';
                   8865:             targetform.copyfolder.value='';
                   8866:             targetform.cmd.value='';
                   8867:             targetform.folderpath.value='';
                   8868:             return;
                   8869:         } else {
                   8870:             if (document.getElementById(param+'_'+idx)) {
                   8871:                 item = document.getElementById(param+'_'+idx);
                   8872:                 if (item.type == 'checkbox') {
                   8873:                     if (item.checked) {
                   8874:                         item.checked = false;
                   8875:                     } else {
                   8876:                         item.checked = true;
                   8877:                         singleCheck(item,idx,param);
                   8878:                     }
                   8879:                 }
                   8880:             }
                   8881:         }
                   8882:     }
1.537     raeburn  8883:     return;
                   8884: }
                   8885: 
1.538     raeburn  8886: function singleCheck(caller,idx,action) {
                   8887:     actions = new Array('cut','copy','remove');
                   8888:     if (caller.checked) {
                   8889:         for (var i=0; i<actions.length; i++) {
                   8890:             if (actions[i] != action) {
                   8891:                 if (document.getElementById(actions[i]+'_'+idx)) {
                   8892:                     if (document.getElementById(actions[i]+'_'+idx).checked) {
                   8893:                         document.getElementById(actions[i]+'_'+idx).checked = false;
                   8894:                     }
1.537     raeburn  8895:                 }
                   8896:             }
                   8897:         }
1.478     raeburn  8898:     }
1.537     raeburn  8899:     return;
1.478     raeburn  8900: }
                   8901: 
1.334     muellerd 8902: function unselectInactive(nav) {
1.335     ehlerst  8903: currentNav = document.getElementById(nav);
                   8904: currentLis = currentNav.getElementsByTagName('LI');
                   8905: for (i = 0; i < currentLis.length; i++) {
1.472     raeburn  8906:         if (currentLis[i].className == 'goback') {
                   8907:             currentLis[i].className = 'goback';
                   8908:         } else {
                   8909: 	    if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374     tempelho 8910: 		currentLis[i].className = 'right';
1.472     raeburn  8911: 	    } else {
1.374     tempelho 8912: 		currentLis[i].className = 'i';
1.472     raeburn  8913: 	    }
                   8914:         }
1.335     ehlerst  8915: }
1.332     tempelho 8916: }
                   8917: 
1.334     muellerd 8918: function hideAll(current, nav, data) {
1.335     ehlerst  8919: unselectInactive(nav);
1.570     raeburn  8920: if (current) { 
                   8921:     if (current.className == 'right'){
                   8922:         current.className = 'right active'
                   8923:     } else {
                   8924:         current.className = 'active';
                   8925:     }
1.374     tempelho 8926: }
1.335     ehlerst  8927: currentData = document.getElementById(data);
                   8928: currentDivs = currentData.getElementsByTagName('DIV');
                   8929: for (i = 0; i < currentDivs.length; i++) {
                   8930: 	if(currentDivs[i].className == 'LC_ContentBox'){
1.333     muellerd 8931: 		currentDivs[i].style.display = 'none';
1.330     tempelho 8932: 	}
                   8933: }
1.335     ehlerst  8934: }
1.330     tempelho 8935: 
1.374     tempelho 8936: function openTabs(pageId) {
                   8937: 	tabnav = document.getElementById(pageId).getElementsByTagName('UL');	
1.383     tempelho 8938: 	if(tabnav.length > 2 ){
1.389     tempelho 8939: 		currentNav = document.getElementById(tabnav[1].id);
1.374     tempelho 8940: 		currentLis = currentNav.getElementsByTagName('LI');
                   8941: 		for(i = 0; i< currentLis.length; i++){
                   8942: 			if(currentLis[i].className == 'active') {
1.375     tempelho 8943: 				funcString = currentLis[i].onclick.toString();
                   8944: 				tab = funcString.split('"');
1.420     onken    8945:                                 if(tab.length < 2) {
                   8946:                                    tab = funcString.split("'");
                   8947:                                 }
1.375     tempelho 8948: 				currentData = document.getElementById(tab[1]);
                   8949:         			currentData.style.display = 'block';
1.374     tempelho 8950: 			}	
                   8951: 		}
                   8952: 	}
                   8953: }
                   8954: 
1.334     muellerd 8955: function showPage(current, pageId, nav, data) {
1.570     raeburn  8956:         currstate = current.className;
1.334     muellerd 8957: 	hideAll(current, nav, data);
1.375     tempelho 8958: 	openTabs(pageId);
1.334     muellerd 8959: 	unselectInactive(nav);
1.570     raeburn  8960:         if ((currstate == 'active') || (currstate == 'right active')) {
                   8961:             if (currstate == 'active') {
                   8962: 	        current.className = '';
                   8963:             } else {
                   8964:                 current.className = 'right';
                   8965:             }
                   8966:             activeTab = ''; 
1.656     raeburn  8967:             toggleExternal();
1.570     raeburn  8968:             toggleUpload();
                   8969:             toggleMap();
1.606     raeburn  8970:             toggleCrsRes();
                   8971:             toggleImportCrsres();
1.570     raeburn  8972:             resize_scrollbox('contentscroll','1','0');
                   8973:             return;
                   8974:         } else {
                   8975:             current.className = 'active';
                   8976:         }
1.330     tempelho 8977: 	currentData = document.getElementById(pageId);
                   8978: 	currentData.style.display = 'block';
1.458     raeburn  8979:         activeTab = pageId;
1.656     raeburn  8980:         toggleExternal();
1.501     raeburn  8981:         toggleUpload();
1.503     raeburn  8982:         toggleMap();
1.606     raeburn  8983:         toggleCrsRes();
                   8984:         toggleImportCrsres();
1.433     raeburn  8985:         if (nav == 'mainnav') {
                   8986:             var storedpath = "$docs_folderpath";
1.434     raeburn  8987:             var storedpage = "$main_container_page";
1.433     raeburn  8988:             var reg = new RegExp("^supplemental");
                   8989:             if (pageId == 'mainCourseDocuments') {
1.434     raeburn  8990:                 if (storedpage == 1) {
                   8991:                     document.simpleedit.folderpath.value = '';
                   8992:                     document.uploaddocument.folderpath.value = '';
                   8993:                 } else {
                   8994:                     if (reg.test(storedpath)) {
                   8995:                         document.simpleedit.folderpath.value = '$toplevelmain';
                   8996:                         document.uploaddocument.folderpath.value = '$toplevelmain';
                   8997:                         document.newext.folderpath.value = '$toplevelmain';
                   8998:                     } else {
                   8999:                         document.simpleedit.folderpath.value = storedpath;
                   9000:                         document.uploaddocument.folderpath.value = storedpath;
                   9001:                         document.newext.folderpath.value = storedpath;
                   9002:                     }
1.433     raeburn  9003:                 }
                   9004:             } else {
1.434     raeburn  9005:                 if (reg.test(storedpath)) {
                   9006:                     document.simpleedit.folderpath.value = storedpath;
                   9007:                     document.supuploaddocument.folderpath.value = storedpath;
                   9008:                     document.supnewext.folderpath.value = storedpath;
                   9009:                 } else {
1.433     raeburn  9010:                     document.simpleedit.folderpath.value = '$toplevelsupp';
                   9011:                     document.supuploaddocument.folderpath.value = '$toplevelsupp';
                   9012:                     document.supnewext.folderpath.value = '$toplevelsupp';
                   9013:                 }
                   9014:             }
                   9015:         }
1.485     raeburn  9016:         resize_scrollbox('contentscroll','1','0');
1.330     tempelho 9017: 	return false;
                   9018: }
1.329     droeschl 9019: 
1.472     raeburn  9020: function toContents(jumpto) {
                   9021:     var newurl = '$backtourl';
1.525     raeburn  9022:     if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472     raeburn  9023:         newurl = newurl+'?postdata='+jumpto;
                   9024:     }
                   9025:     location.href=newurl;
                   9026: }
                   9027: 
1.538     raeburn  9028: function togglePick(caller,value) {
                   9029:     var disp = 'none';
                   9030:     if (document.getElementById('multi'+caller)) {
                   9031:         var curr = document.getElementById('multi'+caller).style.display;
                   9032:         if (value == 1) {
                   9033:             disp='block';
                   9034:         }
                   9035:         if (curr == disp) {
                   9036:             return; 
                   9037:         }
                   9038:         document.getElementById('multi'+caller).style.display=disp;
                   9039:         if (value == 1) {
1.594     damieng  9040:             document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>'; 
1.538     raeburn  9041:         } else {
                   9042:             document.getElementById('more'+caller).innerHTML = '';
                   9043:         }
                   9044:         if (caller == 'actions') { 
                   9045:             setClass(value);
                   9046:             setBoxes(value);
                   9047:         }
                   9048:     }
                   9049:     var showButton = multiSettings();
                   9050:     if (showButton != 1) {
                   9051:         showButton = multiActions();
                   9052:     }
                   9053:     if (document.getElementById('multisave')) {
                   9054:         if (showButton == 1) {
                   9055:             document.getElementById('multisave').style.display='block';
                   9056:         } else {
                   9057:             document.getElementById('multisave').style.display='none';
                   9058:         }
                   9059:     }
                   9060:     resize_scrollbox('contentscroll','1','1');
                   9061:     return;
                   9062: }
                   9063: 
                   9064: function toggleCheckUncheck(caller,more) {
                   9065:     if (more == 1) {
1.594     damieng  9066:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538     raeburn  9067:         document.getElementById('allfields'+caller).style.display='block';
                   9068:     } else {
1.594     damieng  9069:         document.getElementById('more'+caller).innerHTML = '&nbsp;&nbsp;<a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538     raeburn  9070:         document.getElementById('allfields'+caller).style.display='none';
                   9071:     }
                   9072:     resize_scrollbox('contentscroll','1','1');
                   9073: }
                   9074: 
                   9075: function multiSettings() {
                   9076:     var inuse = 0;
                   9077:     var settingsform = document.togglemultsettings;
                   9078:     if (settingsform.showmultpick.length > 1) {
                   9079:         for (var i=0; i<settingsform.showmultpick.length; i++) {
                   9080:             if (settingsform.showmultpick[i].checked) {
                   9081:                 if (settingsform.showmultpick[i].value == 1) {
                   9082:                     inuse = 1;  
                   9083:                 }
                   9084:             }
                   9085:         }
                   9086:     }
                   9087:     return inuse;
                   9088: }
                   9089: 
                   9090: function multiActions() {
                   9091:     var inuse = 0;
                   9092:     var actionsform = document.togglemultactions;
                   9093:     if (actionsform.showmultpick.length > 1) {
                   9094:         for (var i=0; i<actionsform.showmultpick.length; i++) {
                   9095:             if (actionsform.showmultpick[i].checked) {
                   9096:                 if (actionsform.showmultpick[i].value == 1) {
                   9097:                     inuse = 1;
                   9098:                 }
                   9099:             }
                   9100:         }
                   9101:     }
                   9102:     return inuse;
                   9103: } 
                   9104: 
                   9105: function checkSubmits() {
                   9106:     var numchanges = 0;
                   9107:     var form = document.saveactions;
                   9108:     var doactions = multiActions();
1.542     raeburn  9109:     var cutwarnings = 0;
                   9110:     var remwarnings = 0;
1.603     raeburn  9111:     var removalinfo = 0;
1.538     raeburn  9112:     if (doactions == 1) {
                   9113:         var remidxlist = document.cumulativeactions.allremoveidx.value;
                   9114:         if ((remidxlist != '') && (remidxlist != null)) {
                   9115:             var remidxs = remidxlist.split(',');
                   9116:             for (var i=0; i<remidxs.length; i++) {
                   9117:                 if (document.getElementById('remove_'+remidxs[i])) {
                   9118:                     if (document.getElementById('remove_'+remidxs[i]).checked) {
                   9119:                         form.multiremove.value += remidxs[i]+',';
                   9120:                         numchanges ++;
1.542     raeburn  9121:                         if (document.getElementById('skip_remove_'+remidxs[i])) {
                   9122:                             if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
                   9123:                                 remwarnings ++;
                   9124:                             }
                   9125:                         }
1.603     raeburn  9126:                         if (document.getElementById('confirm_removal_'+remidxs[i])) {
                   9127:                             if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
                   9128:                                 removalinfo ++;
                   9129:                             }
                   9130:                         }
1.537     raeburn  9131:                     }
                   9132:                 }
1.538     raeburn  9133:             }
                   9134:         }
                   9135:         var cutidxlist = document.cumulativeactions.allcutidx.value;
                   9136:         if ((cutidxlist != '') && (cutidxlist != null)) {
                   9137:             var cutidxs = cutidxlist.split(',');
                   9138:             for (var i=0; i<cutidxs.length; i++) {
                   9139:                 if (document.getElementById('cut_'+cutidxs[i])) {
                   9140:                     if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
                   9141:                         form.multicut.value += cutidxs[i]+',';
                   9142:                         numchanges ++;
1.542     raeburn  9143:                         if (document.getElementById('skip_cut_'+cutidxs[i])) {
                   9144:                             if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
                   9145:                                 cutwarnings ++;
                   9146:                             }
                   9147:                         }
1.537     raeburn  9148:                     }
                   9149:                 }
                   9150:             }
                   9151:         }
1.538     raeburn  9152:         var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   9153:         if ((copyidxlist != '') && (copyidxlist != null)) {
                   9154:             var copyidxs = copyidxlist.split(',');
                   9155:             for (var i=0; i<copyidxs.length; i++) {
                   9156:                 if (document.getElementById('copy_'+copyidxs[i])) {
                   9157:                     if (document.getElementById('copy_'+copyidxs[i]).checked) {
                   9158:                         form.multicopy.value += copyidxs[i]+',';
                   9159:                         numchanges ++;
                   9160:                     }
                   9161:                 }
                   9162:             }
                   9163:         }
                   9164:         if (numchanges > 0) {
                   9165:             form.multichange.value = numchanges;
                   9166:         }
1.537     raeburn  9167:     }
1.538     raeburn  9168:     var dosettings = multiSettings();
1.543     raeburn  9169:     var haschanges = 0;
1.538     raeburn  9170:     if (dosettings == 1) {
                   9171:         form.allencrypturl.value = '';
                   9172:         form.allhiddenresource.value = '';
1.543     raeburn  9173:         form.changeparms.value = 'all';
                   9174:         var patt=new RegExp(",\$");
1.538     raeburn  9175:         var allidxlist = document.cumulativesettings.allidx.value;
                   9176:         if ((allidxlist != '') && (allidxlist != null)) {
                   9177:             var allidxs = allidxlist.split(',');
                   9178:             if (allidxs.length > 1) {
                   9179:                 for (var i=0; i<allidxs.length; i++) {
                   9180:                     if (document.getElementById('hiddenresource_'+allidxs[i])) {
                   9181:                         if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
                   9182:                             form.allhiddenresource.value += allidxs[i]+',';
                   9183:                         }
                   9184:                     }
                   9185:                     if (document.getElementById('encrypturl_'+allidxs[i])) {
                   9186:                         if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
                   9187:                             form.allencrypturl.value += allidxs[i]+',';
                   9188:                         }
                   9189:                     }
                   9190:                 }
1.543     raeburn  9191:                 form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
                   9192:                 form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537     raeburn  9193:             }
1.538     raeburn  9194:         }
                   9195:         form.allrandompick.value = '';
                   9196:         form.allrandomorder.value = '';
                   9197:         var allmapidxlist = document.cumulativesettings.allmapidx.value;
                   9198:         if ((allmapidxlist != '') && (allmapidxlist != null)) {
                   9199:             var allmapidxs = allmapidxlist.split(',');
                   9200:             for (var i=0; i<allmapidxs.length; i++) {
                   9201:                 var randompick = document.getElementById('randompick_'+allmapidxs[i]);
                   9202:                 var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
                   9203:                 var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
                   9204:                 if ((randompick.checked) && (rpicknum.value != '')) {
                   9205:                     form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
                   9206:                 }
                   9207:                 if (randorder.checked) {
                   9208:                     form.allrandomorder.value += allmapidxs[i]+',';
                   9209:                 }
1.537     raeburn  9210:             }
1.543     raeburn  9211:             form.allrandompick.value = form.allrandompick.value.replace(patt,"");
                   9212:             form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
                   9213:         }
                   9214:         if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
                   9215:             haschanges = 1;
                   9216:         }
                   9217:         if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
                   9218:             haschanges = 1;
                   9219:         }
                   9220:         if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
                   9221:             haschanges = 1;
                   9222:         }
                   9223:         if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
                   9224:             haschanges = 1;
1.537     raeburn  9225:         }
                   9226:     }
1.543     raeburn  9227:     if (doactions == 1) {
1.542     raeburn  9228:         if (numchanges > 0) {
1.603     raeburn  9229:             if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542     raeburn  9230:                 if (remwarnings > 0) {
1.594     damieng  9231:                     if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542     raeburn  9232:                         return false;
                   9233:                     }
                   9234:                 }
1.603     raeburn  9235:                 if (removalinfo > 0) {
                   9236:                     if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
                   9237:                         return false;
                   9238:                     }
                   9239:                 }
1.542     raeburn  9240:                 if (cutwarnings > 0) {
1.594     damieng  9241:                     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  9242:                         return false;
                   9243:                     }
                   9244:                 }
                   9245:             }
                   9246:             form.submit();
                   9247:             return true;
1.543     raeburn  9248:         }
                   9249:     }
                   9250:     if (dosettings == 1) {
                   9251:         if (haschanges == 1) {
1.542     raeburn  9252:             form.submit();
                   9253:             return true;
                   9254:         }
1.543     raeburn  9255:     }
                   9256:     if ((dosettings == 1) && (doactions == 1)) {
1.594     damieng  9257:         alert("$js_lt{'noor'}");
1.543     raeburn  9258:     } else {
                   9259:         if (dosettings == 1) {
1.594     damieng  9260:             alert("$js_lt{'noch'}");
1.543     raeburn  9261:         } else {
1.594     damieng  9262:             alert("$js_lt{'noac'}");
1.543     raeburn  9263:         }
                   9264:     }
1.538     raeburn  9265:     return false;
                   9266: }
                   9267: 
                   9268: function setClass(value) {
                   9269:     var cutclass = 'LC_docs_cut';
                   9270:     var copyclass = 'LC_docs_copy';
                   9271:     var removeclass = 'LC_docs_remove';
                   9272:     var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
                   9273:     var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
                   9274:     var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
                   9275:     var links = document.getElementsByTagName('a');
                   9276:     for (var i=0; i<links.length; i++) {
                   9277:         var classes = links[i].className;
                   9278:         if (cutreg.test(classes)) {
                   9279:             links[i].className = cutclass;
                   9280:             if (value == 1) {
                   9281:                 links[i].className += " LC_menubuttons_link";
                   9282:             }
                   9283:         } else {
                   9284:             if (copyreg.test(classes)) {
                   9285:                 links[i].className = copyclass;
                   9286:                 if (value == 1) {
                   9287:                     links[i].className += " LC_menubuttons_link";
                   9288:                 } 
                   9289:             } else {
                   9290:                 if (removereg.test(classes)) {
                   9291:                     links[i].className = removeclass;
                   9292:                     if (value == 1) {
                   9293:                         links[i].className += " LC_menubuttons_link";
                   9294:                     }
                   9295:                 }
                   9296:             }
                   9297:         }
                   9298:     }
                   9299:     return;
1.537     raeburn  9300: }
                   9301: 
1.538     raeburn  9302: function setBoxes(value) {
                   9303:     var remidxlist = document.cumulativeactions.allremoveidx.value;
                   9304:     if ((remidxlist != '') && (remidxlist != null)) {
                   9305:         var remidxs = remidxlist.split(',');
                   9306:         for (var i=0; i<remidxs.length; i++) {
                   9307:             if (document.getElementById('remove_'+remidxs[i])) {
                   9308:                 var item = document.getElementById('remove_'+remidxs[i]);
                   9309:                 if (value == 1) {
                   9310:                     item.className = 'LC_docs_remove';
                   9311:                 } else {
                   9312:                     item.className = 'LC_hidden';
                   9313:                 }
                   9314:             }
                   9315:         }
                   9316:     }
                   9317:     var cutidxlist = document.cumulativeactions.allcutidx.value;
                   9318:     if ((cutidxlist != '') && (cutidxlist != null)) {
                   9319:         var cutidxs = cutidxlist.split(',');
                   9320:         for (var i=0; i<cutidxs.length; i++) {
                   9321:             if (document.getElementById('cut_'+cutidxs[i])) {
                   9322:                 var item = document.getElementById('cut_'+cutidxs[i]);
                   9323:                 if (value == 1) {
                   9324:                     item.className = 'LC_docs_cut';
                   9325:                 } else {
                   9326:                     item.className = 'LC_hidden';
                   9327:                 }
                   9328:             }
1.537     raeburn  9329:         }
                   9330:     }
1.538     raeburn  9331:     var copyidxlist = document.cumulativeactions.allcopyidx.value;
                   9332:     if ((copyidxlist != '') && (copyidxlist != null)) {
                   9333:         var copyidxs = copyidxlist.split(',');
                   9334:         for (var i=0; i<copyidxs.length; i++) {
                   9335:             if (document.getElementById('copy_'+copyidxs[i])) {
                   9336:                 var item = document.getElementById('copy_'+copyidxs[i]);
                   9337:                 if (value == 1) {
                   9338:                     item.className = 'LC_docs_copy';
                   9339:                 } else {
                   9340:                     item.className = 'LC_hidden';
                   9341:                 }
                   9342:             }
1.537     raeburn  9343:         }
                   9344:     }
                   9345:     return;
                   9346: }
                   9347: 
1.606     raeburn  9348: function validImportCrsRes() {
                   9349:     var path =  document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
                   9350:     var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
                   9351:     if ((fname == '') || (fname == null)) {
                   9352:         alert("$js_lt{'nofi'}");
                   9353:         return false;
                   9354:     }
                   9355:     var url = '/res/$coursedom/$coursenum/';
                   9356:     if (path && path != '/') {
                   9357:         url += path+'/';
                   9358:     }
                   9359:     if (fname != '') {
                   9360:         url += fname;
                   9361:     }
                   9362:     var title = document.crsresimportform.crsrestitle.value;
1.676     raeburn  9363:     document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606     raeburn  9364:     return true;
                   9365: }
                   9366: 
                   9367: function validateNewRes(caller) {
                   9368:     if (caller == 'single') {
                   9369:         var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value; 
                   9370:         var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
                   9371:         var resname = document.courseresform.newresourcename.value;
                   9372:     }
                   9373: }
                   9374: 
1.611     raeburn  9375: ENDSCRIPT
1.329     droeschl 9376: }
1.457     raeburn  9377: 
1.483     raeburn  9378: sub history_tab_js {
                   9379:     return <<"ENDHIST";
                   9380: function toggleHistoryDisp(choice) {
                   9381:     document.docslogform.docslog.value = choice;
                   9382:     document.docslogform.submit();
                   9383:     return;
                   9384: }
                   9385: 
                   9386: ENDHIST
                   9387: }
                   9388: 
1.484     raeburn  9389: sub inject_data_js {
                   9390:     return <<ENDINJECT;
                   9391: 
                   9392: function injectData(current, hiddenField, name, value) {
                   9393:         currentElement = document.getElementById(hiddenField);
                   9394:         currentElement.name = name;
                   9395:         currentElement.value = value;
                   9396:         current.submit();
                   9397: }
                   9398: 
                   9399: ENDINJECT
                   9400: }
                   9401: 
                   9402: sub dump_switchserver_js {
                   9403:     my @hosts = @_;
1.594     damieng  9404:     my %js_lt = &Apache::lonlocal::texthash(
1.574     raeburn  9405:         dump => 'Copying content to Authoring Space requires switching server.',
1.484     raeburn  9406:         swit => 'Switch server?',
1.594     damieng  9407:     );
                   9408:     my %html_js_lt = &Apache::lonlocal::texthash(
                   9409:         swit => 'Switch server?',
1.709   ! raeburn  9410:         duco => 'Copying uploaded content to Authoring Space',
1.484     raeburn  9411:         yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
                   9412:         chos => 'Choose server',
                   9413:     );
1.594     damieng  9414:     &js_escape(\%js_lt);
                   9415:     &html_escape(\%html_js_lt);
                   9416:     &js_escape(\%html_js_lt);
1.484     raeburn  9417:     my $role = $env{'request.role'};
                   9418:     my $js = <<"ENDSWJS";
                   9419: <script type="text/javascript">
                   9420: function write_switchserver() {
                   9421:     var server;
                   9422:     if (document.setserver.posshosts.length > 0) {
                   9423:         for (var i=0; i<document.setserver.posshosts.length; i++) {
                   9424:             if (document.setserver.posshosts[i].checked) {
                   9425:                 server = document.setserver.posshosts[i].value;
                   9426:             }
                   9427:        }
                   9428:        opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
                   9429:     }
                   9430:     window.close();
                   9431: }
                   9432: </script>
                   9433: 
                   9434: ENDSWJS
                   9435: 
                   9436:     my $startpage = &Apache::loncommon::start_page('Choose server',$js,
                   9437:                                                    {'only_body' => 1,
                   9438:                                                     'js_ready'  => 1,});
                   9439:     my $endpage = &Apache::loncommon::end_page({'js_ready'  => 1});
                   9440: 
                   9441:     my $hostpicker;
                   9442:     my $count = 0;
                   9443:     foreach my $host (sort(@hosts)) {
                   9444:         my $checked;
                   9445:         if ($count == 0) {
                   9446:             $checked = ' checked="checked"';
                   9447:         }
                   9448:         $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
                   9449:                        $host.'"'.$checked.' />'.$host.'</label>&nbsp;&nbsp;';
                   9450:         $count++;
                   9451:     }
                   9452:     
                   9453:     return <<"ENDSWITCHJS";
                   9454: 
                   9455: function dump_needs_switchserver(url) {
                   9456:     if (url!='' && url!= null) {
1.594     damieng  9457:         if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484     raeburn  9458:             go(url);
                   9459:         }
                   9460:     }
                   9461:     return;
                   9462: }
                   9463: 
                   9464: function choose_switchserver_window() {
                   9465:     newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
                   9466:     newWindow.document.open();
                   9467:     newWindow.document.writeln('$startpage');
1.594     damieng  9468:     newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
                   9469:        '<p>$html_js_lt{'yone'}<\\/p>\\n'+
                   9470:        '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484     raeburn  9471:        '<form name="setserver" method="post" action="" \\/>\\n'+
                   9472:        '$hostpicker\\n'+
                   9473:        '<br \\/><br \\/>\\n'+
1.594     damieng  9474:        '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484     raeburn  9475:        'onclick="write_switchserver();" \\/>\\n'+
                   9476:        '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
                   9477:     newWindow.document.writeln('$endpage');
                   9478:     newWindow.document.close();
                   9479:     newWindow.focus();
                   9480: }
                   9481: 
                   9482: ENDSWITCHJS
                   9483: }
                   9484: 
                   9485: sub makedocslogform {
                   9486:     my ($formelems,$docslog) = @_;
                   9487:     return <<"LOGSFORM";
                   9488:  <form action="/adm/coursedocs" method="post" name="docslogform">
                   9489:    <input type="hidden" name="docslog" value="$docslog" />
                   9490:    $formelems
                   9491:  </form>
                   9492: LOGSFORM
                   9493: }
                   9494: 
                   9495: sub makesimpleeditform {
                   9496:     my ($formelems) = @_;
                   9497:     return <<"SIMPFORM";
                   9498:  <form name="simpleedit" method="post" action="/adm/coursedocs">
                   9499:    <input type="hidden" name="importdetail" value="" />
                   9500:    $formelems
                   9501:  </form>
                   9502: SIMPFORM
                   9503: }
                   9504: 
1.606     raeburn  9505: sub makenewproblem {
                   9506:     my ($r,$coursedom,$coursenum) = @_;
                   9507: # Creating a new problem
                   9508:     my ($redirect,$error);
                   9509:     if ($env{'form.authorrole'}) {
                   9510:         my ($newsubdir,$filename);
                   9511:         if ($env{'form.newsubdir'}) {
                   9512:             if ($env{'form.newsubdirname'} ne '') {
                   9513:                 $newsubdir = $env{'form.newsubdirname'};
1.654     raeburn  9514:             }
1.606     raeburn  9515:         }
                   9516:         if ($env{'form.newresourcename'}) {
                   9517:             $filename = $env{'form.newresourcename'};
                   9518:             $filename =~ s/\.(\d+)(\.\w+)$/$2/;
                   9519:             $filename =~ s/`//g;
                   9520:             $filename =~ s{/\.\./}{_}g;
                   9521:             $filename =~ s/\.+/./g;
                   9522:             $filename =~ s{/+}{_}g;
                   9523:             if ($filename ne '') {
                   9524:                 my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
                   9525:                 if (($ext) && ($ext ne '.problem')) {
                   9526:                     $filename = $name.'.problem';
                   9527:                 } elsif ($ext eq '') {
                   9528:                     $filename .= '.problem';
                   9529:                 }
                   9530:                 my $docroot = $r->dir_config('lonDocRoot');
                   9531:                 my @ids=&Apache::lonnet::current_machine_ids();
                   9532:                 if ($env{'form.authorrole'} eq 'author') {
                   9533:                     if ($env{'user.author'}) {
                   9534:                         if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
                   9535:                             my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
                   9536:                             my $path = $docroot.$url;
                   9537:                             my $subdir = $env{'form.authorpath'};
                   9538:                             $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   9539:                         }
                   9540:                     }
                   9541:                 } elsif ($env{'form.authorrole'} eq 'course') {
                   9542:                     my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
                   9543:                     if ($chome && grep(/^\Q$chome\E$/,@ids)) {
                   9544:                         my $url = "/priv/$coursedom/$coursenum";
                   9545:                         my $path=$docroot.$url;
                   9546:                         my $subdir = $env{'form.authorpath'};
                   9547:                         $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   9548:                         if ($redirect) {
                   9549:                             my $rightsfile = 'default.rights';
                   9550:                             my $sourcerights = "$path/$rightsfile";
1.709   ! raeburn  9551:                             &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
1.606     raeburn  9552:                             my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
1.654     raeburn  9553:                             if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
                   9554:                                 if (!-e "$docroot/res/$coursedom") {
                   9555:                                     mkdir("$docroot/res/$coursedom",0755);
1.606     raeburn  9556:                                 }
1.654     raeburn  9557:                                 if (!-e "$docroot/res/$coursedom/$coursenum") {
                   9558:                                     mkdir("$docroot/res/$coursedom/$coursenum",0755);
                   9559:                                 }
                   9560:                                 if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
                   9561:                                     my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                   9562:                                     my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606     raeburn  9563:                                 }
                   9564:                             }
1.654     raeburn  9565:                             my $source = $docroot.$redirect;
                   9566:                             if (!-e "$source.meta") {
                   9567:                                 my $cid = $coursedom.'_'.$coursenum;
                   9568:                                 my $now = time;
                   9569:                                 if (open(my $fh,">$source.meta")) {
                   9570:                                     my $author=$env{'environment.firstname'}.' '.
                   9571:                                                $env{'environment.middlename'}.' '.
                   9572:                                                $env{'environment.lastname'}.' '.
                   9573:                                                $env{'environment.generation'};
                   9574:                                     $author =~ s/\s+$//;
                   9575:                                     my $title = $env{'form.newresourcetitle'};
                   9576:                                     $title =~ s/^\s+|\s+$//g;
                   9577:                                     print $fh <<END;
1.606     raeburn  9578: 
                   9579: <abstract></abstract>
                   9580: <author>$author</author>
                   9581: <authorspace>$coursenum:$coursedom</authorspace>
                   9582: <copyright>custom</copyright>
                   9583: <creationdate>$now</creationdate>
                   9584: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
                   9585: <dependencies></dependencies>
                   9586: <domain>$coursedom</domain>
                   9587: <highestgradelevel>0</highestgradelevel>
                   9588: <keywords></keywords>
                   9589: <language>notset </language>
                   9590: <lastrevisiondate>$now</lastrevisiondate>
                   9591: <lowestgradelevel>0</lowestgradelevel>
                   9592: <mime>problem</mime>
                   9593: <modifyinguser>$coursenum:$coursedom</modifyinguser>
                   9594: <notes></notes>
                   9595: <obsolete></obsolete>
                   9596: <obsoletereplacement></obsoletereplacement>
                   9597: <owner>$coursenum:$coursedom</owner>
                   9598: <sourceavail></sourceavail>
                   9599: <standards></standards>
                   9600: <subject></subject>
                   9601: <title>$title</title>
                   9602: END
1.654     raeburn  9603:                                     close($fh);
1.606     raeburn  9604:                                 }
                   9605:                             }
                   9606:                         }
                   9607:                     }
                   9608:                 } else {
                   9609:                     my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
                   9610:                     my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
                   9611:                     if (grep(/^\Q$rolehome\E$/,@ids)) {
                   9612:                         my $now = time;
                   9613:                         if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
                   9614:                             my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
                   9615:                             if (($start <= $now) && (($end == 0) || ($end >= $now))) { 
                   9616:                                 my $url = "/priv/$audom/$auname";  
                   9617:                                 my $path = $r->dir_config('lonDocRoot').$url;
                   9618:                                 my $subdir = $env{'form.authorpath'};
                   9619:                                 $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
                   9620:                             }
                   9621:                         }
                   9622:                     }
                   9623:                 }
                   9624:             }
                   9625:         }
                   9626:     }
                   9627:     return ($redirect,$error);
                   9628: }
                   9629: 
                   9630: sub finishnewprob {
1.654     raeburn  9631:     my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607     raeburn  9632:     unless (-d $path) {
                   9633:         unless (mkdir($path,02770)) {
                   9634:             return;
                   9635:         }
                   9636:     }
1.606     raeburn  9637:     my $redirect;
                   9638:     if ($subdir ne '/') {
                   9639:         $subdir = &cleandir($subdir);
                   9640:         if (($subdir ne '') && (-d "$path/$subdir")) {
                   9641:             $path .= "/$subdir";
                   9642:             $url .= "/$subdir";
                   9643:         }
                   9644:     }
                   9645:     my $dest;
                   9646:     if ($newsubdir ne '') {
                   9647:         $newsubdir = &cleandir($newsubdir);
                   9648:     }
                   9649:     if ($newsubdir ne '') {
                   9650:         if (-d "$path/$newsubdir") {
                   9651:             $dest = "$path/$newsubdir/$filename";
                   9652:         } else {
                   9653:             my $dirok;
                   9654:             unless (-e "$path/$newsubdir") {
                   9655:                 if (mkdir("$path/$newsubdir",02770)) {
                   9656:                     if (chmod(02770,"$path/$newsubdir")) {
                   9657:                         $dirok = 1;
                   9658:                     }
                   9659:                 }
                   9660:             }
                   9661:             if ($dirok) {
                   9662:                 $dest = "$path/$newsubdir/$filename";
                   9663:             }
                   9664:         }
                   9665:         if (($dest ne '') && (!-e $dest)) {
                   9666:             $redirect = "$url/$newsubdir/$filename";
                   9667:         }
                   9668:     } else {
                   9669:         $dest = "$path/$filename";
                   9670:         if (($dest ne '') && (!-e $dest)) {
                   9671:             $redirect = "$url/$filename";
                   9672:         }
                   9673:     }
1.654     raeburn  9674:     if ((!-e $dest) && ($context ne 'upload')) {
                   9675:         my $template = $env{'form.template'};
                   9676:         my $copyfrom;
                   9677:         if ($template ne '') {
                   9678:             my %templates;
                   9679:             my @files = &Apache::lonhomework::get_template_list('problem');
                   9680:             foreach my $poss (@files) {
                   9681:                 if (ref($poss) eq 'ARRAY') {
                   9682:                     if ($template eq $poss->[0]) {
                   9683:                         $templates{$template} = 1;
                   9684:                         last;
                   9685:                     }
                   9686:                 }
                   9687:             }
                   9688:             if ($templates{$template}) {
                   9689:                 $copyfrom = $template;
                   9690:             }
                   9691:         }
                   9692:         if ($filename =~ /\.problem$/) {
                   9693:             unless ($copyfrom) {
                   9694:                 $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
                   9695:             }
                   9696:             &File::Copy::copy($copyfrom,$dest);
                   9697:         }
                   9698:     }
1.606     raeburn  9699:     return $redirect;
                   9700: }
                   9701: 
                   9702: sub cleandir {
                   9703:     my ($dir) = @_;
                   9704:     $dir =~ s/^\s+//;
                   9705:     $dir =~ s/\s+$//;
                   9706:     $dir =~ s/\.+//g;
                   9707:     $dir =~ s/[\#\?&%\":]//g;
                   9708:     return $dir;
                   9709: }
                   9710: 
1.329     droeschl 9711: 1;
                   9712: __END__
                   9713: 
                   9714: 
                   9715: =head1 NAME
                   9716: 
                   9717: Apache::londocs.pm
                   9718: 
                   9719: =head1 SYNOPSIS
                   9720: 
                   9721: This is part of the LearningOnline Network with CAPA project
                   9722: described at http://www.lon-capa.org.
                   9723: 
                   9724: =head1 SUBROUTINES
                   9725: 
                   9726: =over
                   9727: 
                   9728: =item %help=()
                   9729: 
                   9730: Available help topics
                   9731: 
                   9732: =item mapread()
                   9733: 
1.344     bisitz   9734: Mapread read maps into LONCAPA::map:: global arrays
1.329     droeschl 9735: @order and @resources, determines status
                   9736: sets @order - pointer to resources in right order
                   9737: sets @resources - array with the resources with correct idx
                   9738: 
                   9739: =item authorhosts()
                   9740: 
                   9741: Return hash with valid author names
                   9742: 
                   9743: =item clean()
                   9744: 
                   9745: =item dumpcourse()
                   9746: 
                   9747:     Actually dump course
                   9748: 
                   9749: =item group_import()
                   9750: 
                   9751:     Imports the given (name, url) resources into the course
                   9752:     coursenum, coursedom, and folder must precede the list
                   9753: 
                   9754: =item breadcrumbs()
                   9755: 
                   9756: =item log_docs()
                   9757: 
                   9758: =item docs_change_log()
                   9759: 
                   9760: =item update_paste_buffer()
                   9761: 
                   9762: =item print_paste_buffer()
                   9763: 
                   9764: =item do_paste_from_buffer()
                   9765: 
1.538     raeburn  9766: =item do_buffer_empty() 
                   9767: 
                   9768: =item clear_from_buffer()
                   9769: 
1.492     raeburn  9770: =item get_newmap_url()
                   9771: 
                   9772: =item dbcopy()
                   9773: 
                   9774: =item uniqueness_check()
                   9775: 
                   9776: =item contained_map_check()
                   9777: 
                   9778: =item url_paste_fixups()
                   9779: 
                   9780: =item apply_fixups()
                   9781: 
                   9782: =item copy_dependencies()
                   9783: 
1.329     droeschl 9784: =item update_parameter()
                   9785: 
                   9786: =item handle_edit_cmd()
                   9787: 
                   9788: =item editor()
                   9789: 
                   9790: =item process_file_upload()
                   9791: 
                   9792: =item process_secondary_uploads()
                   9793: 
                   9794: =item is_supplemental_title()
                   9795: 
                   9796: =item entryline()
                   9797: 
                   9798: =item tiehash()
                   9799: 
                   9800: =item untiehash()
                   9801: 
                   9802: =item checkonthis()
                   9803: 
                   9804: check on this
                   9805: 
                   9806: =item verifycontent()
                   9807: 
                   9808: Verify Content
                   9809: 
1.636     raeburn  9810: =item devalidateversioncache() 
                   9811: 
                   9812: =item checkversions()
1.329     droeschl 9813: 
                   9814: Check Versions
                   9815: 
                   9816: =item mark_hash_old()
                   9817: 
                   9818: =item is_hash_old()
                   9819: 
                   9820: =item changewarning()
                   9821: 
                   9822: =item init_breadcrumbs()
                   9823: 
                   9824: Breadcrumbs for special functions
                   9825: 
1.484     raeburn  9826: =item create_list_elements()
                   9827: 
                   9828: =item create_form_ul()
                   9829: 
                   9830: =item startContentScreen() 
                   9831: 
                   9832: =item endContentScreen()
                   9833: 
                   9834: =item supplemental_base()
                   9835: 
                   9836: =item embedded_form_elems()
                   9837: 
                   9838: =item embedded_destination()
                   9839: 
                   9840: =item return_to_editor()
                   9841: 
                   9842: =item decompression_info()
                   9843: 
                   9844: =item decompression_phase_one()
                   9845: 
                   9846: =item decompression_phase_two()
                   9847: 
                   9848: =item remove_archive()
                   9849: 
                   9850: =item generate_admin_menu()
                   9851: 
                   9852: =item generate_edit_table()
                   9853: 
                   9854: =item editing_js()
                   9855: 
                   9856: =item history_tab_js()
                   9857: 
                   9858: =item inject_data_js()
                   9859: 
                   9860: =item dump_switchserver_js()
                   9861: 
1.485     raeburn  9862: =item resize_scrollbox_js()
1.484     raeburn  9863: 
                   9864: =item makedocslogform()
                   9865: 
1.485     raeburn  9866: =item makesimpleeditform()
                   9867: 
1.329     droeschl 9868: =back
                   9869: 
                   9870: =cut

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