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

1.329     droeschl    1: # The LearningOnline Network
                      2: # Documents
                      3: #
1.488   ! raeburn     4: # $Id: londocs.pm,v 1.487 2012/05/15 01:41:27 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.488   ! raeburn    43: use Apache::lonuserstate();
1.329     droeschl   44: use HTML::Entities;
1.488   ! raeburn    45: use HTML::TokeParser;
1.329     droeschl   46: use GDBM_File;
                     47: use Apache::lonlocal;
                     48: use Cwd;
                     49: use LONCAPA qw(:DEFAULT :match);
                     50: 
                     51: my $iconpath;
                     52: 
                     53: my %hash;
                     54: 
                     55: my $hashtied;
                     56: my %alreadyseen=();
                     57: 
                     58: my $hadchanges;
                     59: 
                     60: 
                     61: my %help=();
                     62: 
                     63: 
                     64: sub mapread {
                     65:     my ($coursenum,$coursedom,$map)=@_;
                     66:     return
                     67:       &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                     68: 			     $map);
                     69: }
                     70: 
                     71: sub storemap {
                     72:     my ($coursenum,$coursedom,$map)=@_;
                     73:     my ($outtext,$errtext)=
                     74:       &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                     75: 			      $map,1);
                     76:     if ($errtext) { return ($errtext,2); }
1.364     bisitz     77: 
1.329     droeschl   78:     $hadchanges=1;
                     79:     return ($errtext,0);
                     80: }
                     81: 
                     82: 
                     83: 
                     84: sub authorhosts {
                     85:     my %outhash=();
                     86:     my $home=0;
                     87:     my $other=0;
                     88:     foreach my $key (keys(%env)) {
                     89: 	if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
                     90: 	    my $role=$1;
                     91: 	    my $realm=$2;
                     92: 	    my ($start,$end)=split(/\./,$env{$key});
                     93: 	    if (($start) && ($start>time)) { next; }
                     94: 	    if (($end) && (time>$end)) { next; }
                     95: 	    my ($ca,$cd);
                     96: 	    if ($1 eq 'au') {
                     97: 		$ca=$env{'user.name'};
                     98: 		$cd=$env{'user.domain'};
                     99: 	    } else {
                    100: 		($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
                    101: 	    }
                    102: 	    my $allowed=0;
                    103: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
                    104: 	    my @ids=&Apache::lonnet::current_machine_ids();
1.484     raeburn   105: 	    foreach my $id (@ids) {
                    106:                 if ($id eq $myhome) {
                    107:                     $allowed=1;
                    108:                     last;
                    109:                 }
                    110:             }
1.329     droeschl  111: 	    if ($allowed) {
                    112: 		$home++;
1.484     raeburn   113: 		$outhash{'home_'.$ca.':'.$cd}=1;
1.329     droeschl  114: 	    } else {
1.484     raeburn   115: 		$outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329     droeschl  116: 		$other++;
                    117: 	    }
                    118: 	}
                    119:     }
                    120:     return ($home,$other,%outhash);
                    121: }
                    122: 
                    123: 
                    124: sub clean {
                    125:     my ($title)=@_;
                    126:     $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344     bisitz    127:     return $title;
1.329     droeschl  128: }
                    129: 
                    130: 
                    131: 
                    132: sub dumpcourse {
                    133:     my ($r) = @_;
1.408     raeburn   134:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn   135:     $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Content to Authoring Space')."\n".
                    136:               &Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Content to Authoring Space')."\n");
                    137:     $r->print(&startContentScreen('tools'));
1.329     droeschl  138:     my ($home,$other,%outhash)=&authorhosts();
1.484     raeburn   139:     unless ($home) {
                    140:         $r->print(&endContentScreen());
                    141:         return '';
                    142:     }
1.329     droeschl  143:     my $origcrsid=$env{'request.course.id'};
                    144:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    145:     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
                    146: # Do the dumping
1.484     raeburn   147: 	unless ($outhash{'home_'.$env{'form.authorspace'}}) {
                    148:             $r->print(&endContentScreen());
                    149:             return '';
                    150:         }
1.329     droeschl  151: 	my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
                    152: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
                    153: 	my $title=$env{'form.authorfolder'};
                    154: 	$title=&clean($title);
                    155: 	my %replacehash=();
                    156: 	foreach my $key (keys(%env)) {
                    157: 	    if ($key=~/^form\.namefor\_(.+)/) {
                    158: 		$replacehash{$1}=$env{$key};
                    159: 	    }
                    160: 	}
                    161: 	my $crs='/uploaded/'.$env{'request.course.id'}.'/';
                    162: 	$crs=~s/\_/\//g;
                    163: 	foreach my $item (keys(%replacehash)) {
                    164: 	    my $newfilename=$title.'/'.$replacehash{$item};
                    165: 	    $newfilename=~s/\.(\w+)$//;
                    166: 	    my $ext=$1;
                    167: 	    $newfilename=&clean($newfilename);
                    168: 	    $newfilename.='.'.$ext;
                    169: 	    my @dirs=split(/\//,$newfilename);
1.462     raeburn   170: 	    my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
1.329     droeschl  171: 	    my $makepath=$path;
                    172: 	    my $fail=0;
                    173: 	    for (my $i=0;$i<$#dirs;$i++) {
                    174: 		$makepath.='/'.$dirs[$i];
1.344     bisitz    175: 		unless (-e $makepath) {
                    176: 		    unless(mkdir($makepath,0777)) { $fail=1; }
1.329     droeschl  177: 		}
                    178: 	    }
                    179: 	    $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
                    180: 	    if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
                    181: 		if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
                    182: 		    print $fh &Apache::lonclonecourse::rewritefile(
                    183:          &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                    184: 				     (%replacehash,$crs => '')
                    185: 								    );
                    186: 		} else {
                    187: 		    print $fh
                    188:          &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
                    189: 		       }
                    190: 		$fh->close();
                    191: 	    } else {
                    192: 		$fail=1;
                    193: 	    }
                    194: 	    if ($fail) {
                    195: 		$r->print('<span class="LC_error">'.&mt('fail').'</span>');
                    196: 	    } else {
                    197: 		$r->print('<span class="LC_success">'.&mt('ok').'</span>');
                    198: 	    }
                    199: 	}
                    200:     } else {
1.484     raeburn   201:         $r->print(&mt('Searching ...').'<br />');
                    202:         $r->rflush();
1.329     droeschl  203: # Input form
1.484     raeburn   204:         $r->print('<form name="dumpdoc" action="" method="post">'."\n");
1.329     droeschl  205: 	unless ($home==1) {
1.484     raeburn   206: 	    $r->print('<div class="LC_left_float">'.
                    207: 		      '<fieldset><legend>'.
                    208:                       &mt('Select the Authoring Space').
                    209:                       '</legend><select name="authorspace">');
1.329     droeschl  210: 	}
                    211: 	foreach my $key (sort(keys(%outhash))) {
                    212: 	    if ($key=~/^home_(.+)$/) {
                    213: 		if ($home==1) {
                    214: 		    $r->print(
                    215: 		  '<input type="hidden" name="authorspace" value="'.$1.'" />');
                    216: 		} else {
                    217: 		    $r->print('<option value="'.$1.'">'.$1.' - '.
1.484     raeburn   218: 			      &Apache::loncommon::plainname(split(/\:/,$1)).'</option>');
1.329     droeschl  219: 		}
                    220: 	    }
                    221: 	}
                    222: 	unless ($home==1) {
1.484     raeburn   223: 	    $r->print('</select></fieldset></div>'."\n");
1.329     droeschl  224: 	}
                    225: 	my $title=$origcrsdata{'description'};
                    226: 	$title=~s/[\/\s]+/\_/gs;
                    227: 	$title=&clean($title);
1.484     raeburn   228: 	$r->print('<div class="LC_left_float">'.
                    229:                   '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
                    230:                   '<input type="text" size="50" name="authorfolder" value="'.
                    231:                   $title.'" />'.
                    232:                   '</fieldset></div><br clear="all" />'."\n");
1.329     droeschl  233: 	&tiehash();
1.484     raeburn   234: 	$r->print('<h4>'.&mt('Filenames in Authoring Space').'</h4>'
1.329     droeschl  235:                  .&Apache::loncommon::start_data_table()
                    236:                  .&Apache::loncommon::start_data_table_header_row()
                    237:                  .'<th>'.&mt('Internal Filename').'</th>'
                    238:                  .'<th>'.&mt('Title').'</th>'
                    239:                  .'<th>'.&mt('Save as ...').'</th>'
                    240:                  .&Apache::loncommon::end_data_table_header_row());
                    241: 	foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
                    242: 	    $r->print(&Apache::loncommon::start_data_table_row()
                    243:                      .'<td>'.$file.'</td>');
                    244: 	    my ($ext)=($file=~/\.(\w+)$/);
                    245: 	    my $title=$hash{'title_'.$hash{
                    246: 		'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
                    247: 	    $r->print('<td>'.($title?$title:'&nbsp;').'</td>');
                    248: 	    if (!$title) {
                    249: 		$title=$file;
                    250: 	    } else {
                    251: 		$title=~s|/|_|g;
                    252: 	    }
                    253: 	    $title=~s/\.(\w+)$//;
                    254: 	    $title=&clean($title);
                    255: 	    $title.='.'.$ext;
                    256: 	    $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
                    257:                      .&Apache::loncommon::end_data_table_row());
                    258: 	}
                    259: 	$r->print(&Apache::loncommon::end_data_table());
                    260: 	&untiehash();
                    261: 	$r->print(
1.484     raeburn   262:   '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype Content").'" /></p></form>');
1.329     droeschl  263:     }
1.484     raeburn   264:     $r->print(&endContentScreen());
1.329     droeschl  265: }
                    266: 
                    267: sub group_import {
                    268:     my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
                    269: 
                    270:     while (@files) {
                    271: 	my ($name, $url, $residx) = @{ shift(@files) };
1.344     bisitz    272:         if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329     droeschl  273: 	     && ($caller eq 'londocs')
                    274: 	     && (!&Apache::lonnet::stat_file($url))) {
1.364     bisitz    275: 
1.329     droeschl  276:             my $errtext = '';
                    277:             my $fatal = 0;
                    278:             my $newmapstr = '<map>'."\n".
                    279:                             '<resource id="1" src="" type="start"></resource>'."\n".
                    280:                             '<link from="1" to="2" index="1"></link>'."\n".
                    281:                             '<resource id="2" src="" type="finish"></resource>'."\n".
                    282:                             '</map>';
                    283:             $env{'form.output'}=$newmapstr;
                    284:             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                    285:                                                 'output',$1.$2);
                    286:             if ($result != m|^/uploaded/|) {
                    287:                 $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
                    288:                 $fatal = 2;
                    289:             }
                    290:             if ($fatal) {
                    291:                 return ($errtext,$fatal);
                    292:             }
                    293:         }
                    294: 	if ($url) {
1.344     bisitz    295: 	    if (!$residx
1.329     droeschl  296: 		|| defined($LONCAPA::map::zombies[$residx])) {
                    297: 		$residx = &LONCAPA::map::getresidx($url,$residx);
                    298: 		push(@LONCAPA::map::order, $residx);
                    299: 	    }
                    300: 	    my $ext = 'false';
                    301: 	    if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
                    302: 	    $url  = &LONCAPA::map::qtunescape($url);
                    303: 	    $name = &LONCAPA::map::qtunescape($name);
1.344     bisitz    304: 	    $LONCAPA::map::resources[$residx] =
1.329     droeschl  305: 		join(':', ($name, $url, $ext, 'normal', 'res'));
                    306: 	}
                    307:     }
                    308:     return &storemap($coursenum, $coursedom, $folder.'.'.$container);
                    309: }
                    310: 
                    311: sub breadcrumbs {
1.408     raeburn   312:     my ($allowed,$crstype)=@_;
1.329     droeschl  313:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    314:     my (@folders);
                    315:     if ($env{'form.pagepath'}) {
                    316:         @folders = split('&',$env{'form.pagepath'});
                    317:     } else {
                    318:         @folders=split('&',$env{'form.folderpath'});
                    319:     }
                    320:     my $folderpath;
                    321:     my $cpinfo='';
                    322:     my $plain='';
                    323:     my $randompick=-1;
                    324:     my $isencrypted=0;
                    325:     my $ishidden=0;
                    326:     my $is_random_order=0;
                    327:     while (@folders) {
                    328: 	my $folder=shift(@folders);
                    329:     	my $foldername=shift(@folders);
                    330: 	if ($folderpath) {$folderpath.='&';}
                    331: 	$folderpath.=$folder.'&'.$foldername;
1.472     raeburn   332:         my $url;
                    333:         if ($allowed) {
                    334:             $url = '/adm/coursedocs?folderpath=';
                    335:         } else {
                    336:             $url = '/adm/supplemental?folderpath=';
                    337:         }
                    338: 	$url .= &escape($folderpath);
                    339: 	my $name=&unescape($foldername);
1.344     bisitz    340: # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
1.472     raeburn   341:  	$name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
                    342: 	if ($1 ne '') {
                    343:            $randompick=$1;
                    344:         } else {
                    345:            $randompick=-1;
                    346:         }
                    347:         if ($2) { $ishidden=1; }
                    348:         if ($3) { $isencrypted=1; }
                    349: 	if ($4 ne '') { $is_random_order = 1; }
                    350:         if ($folder eq 'supplemental') {
                    351:             $name = &mt('Supplemental '.$crstype.' Content');
                    352:         }
                    353: 	&Apache::lonhtmlcommon::add_breadcrumb(
1.329     droeschl  354: 		      {'href'=>$url.$cpinfo,
                    355: 		       'title'=>$name,
1.367     droeschl  356: 		       'text'=>$name,
1.329     droeschl  357: 		       'no_mt'=>1,
                    358: 		       });
                    359: 	$plain.=$name.' &gt; ';
                    360:     }
                    361:     $plain=~s/\&gt\;\s*$//;
                    362:     return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
1.472     raeburn   363: 					       undef, undef, 1 ),$randompick,$ishidden,
                    364:                                                $isencrypted,$plain,$is_random_order);
1.329     droeschl  365: }
                    366: 
                    367: sub log_docs {
                    368:     return &Apache::lonnet::instructor_log('docslog',@_);
                    369: }
                    370: 
                    371: {
                    372:     my @oldresources=();
                    373:     my @oldorder=();
                    374:     my $parmidx;
                    375:     my %parmaction=();
                    376:     my %parmvalue=();
                    377:     my $changedflag;
                    378: 
                    379:     sub snapshotbefore {
                    380:         @oldresources=@LONCAPA::map::resources;
                    381:         @oldorder=@LONCAPA::map::order;
                    382:         $parmidx=undef;
                    383:         %parmaction=();
                    384:         %parmvalue=();
                    385:         $changedflag=0;
                    386:     }
                    387: 
                    388:     sub remember_parms {
                    389:         my ($idx,$parameter,$action,$value)=@_;
                    390:         $parmidx=$idx;
                    391:         $parmaction{$parameter}=$action;
                    392:         $parmvalue{$parameter}=$value;
                    393:         $changedflag=1;
                    394:     }
                    395: 
                    396:     sub log_differences {
                    397:         my ($plain)=@_;
                    398:         my %storehash=('folder' => $plain,
                    399:                        'currentfolder' => $env{'form.folder'});
                    400:         if ($parmidx) {
                    401:            $storehash{'parameter_res'}=$oldresources[$parmidx];
                    402:            foreach my $parm (keys(%parmaction)) {
                    403:               $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
                    404:               $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
                    405:            }
                    406:         }
                    407:         my $maxidx=$#oldresources;
                    408:         if ($#LONCAPA::map::resources>$#oldresources) {
                    409:            $maxidx=$#LONCAPA::map::resources;
                    410:         }
                    411:         for (my $idx=0; $idx<=$maxidx; $idx++) {
                    412:            if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
                    413:               $storehash{'before_resources_'.$idx}=$oldresources[$idx];
                    414:               $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
                    415:               $changedflag=1;
                    416:            }
                    417:            if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
                    418:               $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
                    419:               $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                    420:               $changedflag=1;
                    421:            }
                    422:         }
                    423: 	$storehash{'maxidx'}=$maxidx;
                    424:         if ($changedflag) { &log_docs(\%storehash); }
                    425:     }
                    426: }
                    427: 
                    428: sub docs_change_log {
1.484     raeburn   429:     my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
1.486     raeburn   430:     my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.483     raeburn   431:     my $js = '<script type="text/javascript">'."\n".
                    432:              '// <![CDATA['."\n".
                    433:              &Apache::loncommon::display_filter_js('docslog')."\n".
1.486     raeburn   434:              &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag)."\n".
1.483     raeburn   435:              &history_tab_js()."\n".
1.484     raeburn   436:              &Apache::lonratedt::editscript('simple')."\n".
1.483     raeburn   437:              '// ]]>'."\n".
                    438:              '</script>'."\n";
1.484     raeburn   439:     $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
                    440:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
                    441:     $r->print(&startContentScreen('docs'));
                    442:     my %orderhash;
                    443:     my $container='sequence';
                    444:     my $pathitem;
                    445:     if ($env{'form.pagepath'}) {
                    446:         $container='page';
                    447:         $pathitem = '<input type="hidden" name="pagepath" value="'.
                    448:                     &HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />';
                    449:     } else {
                    450:         my $folderpath=$env{'form.folderpath'};
                    451:         if ($folderpath eq '') {
                    452:             $folderpath = 'default&'.&escape(&mt('Main '.$crstype.' Documents'));
                    453:         }
                    454:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
                    455:     }
                    456:     my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
                    457:     my $jumpto = $readfile;
                    458:     $jumpto =~ s{^/}{};
                    459:     my $tid = 1;
                    460:     my ($breadcrumbtrail) = &breadcrumbs($allowed,$crstype);
                    461:     $r->print($breadcrumbtrail.
                    462:               &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
                    463:               $readfile));
1.329     droeschl  464:     my %docslog=&Apache::lonnet::dump('nohist_docslog',
                    465:                                       $env{'course.'.$env{'request.course.id'}.'.domain'},
                    466:                                       $env{'course.'.$env{'request.course.id'}.'.num'});
                    467: 
                    468:     if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
                    469: 
                    470:     my %saveable_parameters = ('show' => 'scalar',);
                    471:     &Apache::loncommon::store_course_settings('docs_log',
                    472:                                               \%saveable_parameters);
                    473:     &Apache::loncommon::restore_course_settings('docs_log',
                    474:                                                 \%saveable_parameters);
                    475:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452     www       476: # FIXME: internationalization seems wrong here
1.329     droeschl  477:     my %lt=('hiddenresource' => 'Resources hidden',
                    478: 	    'encrypturl'     => 'URL hidden',
                    479: 	    'randompick'     => 'Randomly pick',
                    480: 	    'randomorder'    => 'Randomly ordered',
                    481: 	    'set'            => 'set to',
                    482: 	    'del'            => 'deleted');
1.484     raeburn   483:     my $filter = &Apache::loncommon::display_filter('docslog')."\n".
                    484:                  $pathitem."\n".
                    485:                  '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
                    486:                  ('&nbsp;'x2).'<input type="submit" value="'.&mt('Display').'" />';
                    487:     $r->print('<div class="LC_left_float">'.
                    488:               '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
                    489:               &makedocslogform($filter,1).
                    490:               '</fieldset></div><br clear="all" />');
1.329     droeschl  491:     $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
                    492:               '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
                    493:               &mt('After').'</th>'.
                    494:               &Apache::loncommon::end_data_table_header_row());
                    495:     my $shown=0;
                    496:     foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
                    497: 	if ($env{'form.displayfilter'} eq 'currentfolder') {
                    498: 	    if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
                    499: 	}
                    500:         my @changes=keys(%{$docslog{$id}{'logentry'}});
                    501:         if ($env{'form.displayfilter'} eq 'containing') {
                    502: 	    my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
                    503: 		&Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
                    504: 	    foreach my $key (@changes) {
                    505: 		$wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
                    506: 	    }
1.344     bisitz    507: 	    if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329     droeschl  508: 	}
                    509:         my $count = 0;
                    510:         my $time =
                    511:             &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
                    512:         my $plainname =
                    513:             &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
                    514:                                           $docslog{$id}{'exe_udom'});
                    515:         my $about_me_link =
                    516:             &Apache::loncommon::aboutmewrapper($plainname,
                    517:                                                $docslog{$id}{'exe_uname'},
                    518:                                                $docslog{$id}{'exe_udom'});
                    519:         my $send_msg_link='';
                    520:         if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
                    521:              || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
                    522:             $send_msg_link ='<br />'.
                    523:                 &Apache::loncommon::messagewrapper(&mt('Send message'),
                    524:                                                    $docslog{$id}{'exe_uname'},
                    525:                                                    $docslog{$id}{'exe_udom'});
                    526:         }
                    527:         $r->print(&Apache::loncommon::start_data_table_row());
                    528:         $r->print('<td>'.$time.'</td>
                    529:                        <td>'.$about_me_link.
                    530:                   '<br /><tt>'.$docslog{$id}{'exe_uname'}.
                    531:                                   ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
                    532:                   $send_msg_link.'</td><td>'.
                    533:                   $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488   ! raeburn   534:         my $is_supp = 0; 
        !           535:         if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
        !           536:             $is_supp = 1;
        !           537:         }
1.329     droeschl  538: # Before
                    539: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                    540: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                    541: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                    542: 	    if ($oldname ne $newname) {
1.488   ! raeburn   543:                 my $shown = &LONCAPA::map::qtescape($oldname);
        !           544:                 if ($is_supp) {
        !           545:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
        !           546:                 }
        !           547:                 $r->print($shown);
1.329     droeschl  548: 	    }
                    549: 	}
                    550: 	$r->print('<ul>');
                    551: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                    552:             if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488   ! raeburn   553:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
        !           554:                 if ($is_supp) {
        !           555:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
        !           556:                 }
        !           557: 		$r->print('<li>'.$shown.'</li>');
1.329     droeschl  558: 	    }
                    559: 	}
                    560: 	$r->print('</ul>');
                    561: # After
                    562:         $r->print('</td><td>');
                    563: 
                    564: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                    565: 	    my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
                    566: 	    my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
                    567: 	    if ($oldname ne '' && $oldname ne $newname) {
1.488   ! raeburn   568:                 my $shown = &LONCAPA::map::qtescape($newname);
        !           569:                 if ($is_supp) {
        !           570:                     $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
        !           571:                 }
        !           572:                 $r->print($shown);
1.329     droeschl  573: 	    }
1.364     bisitz    574: 	}
1.329     droeschl  575: 	$r->print('<ul>');
                    576: 	for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
                    577:             if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488   ! raeburn   578:                 my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
        !           579:                 if ($is_supp) {
        !           580:                     $shown = &Apache::loncommon::parse_supplemental_title($shown);
        !           581:                 }
        !           582:                 $r->print('<li>'.$shown.'</li>');
1.329     droeschl  583: 	    }
                    584: 	}
                    585: 	$r->print('</ul>');
                    586: 	if ($docslog{$id}{'logentry'}{'parameter_res'}) {
                    587: 	    $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
                    588: 	    foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
                    589: 		if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452     www       590: # FIXME: internationalization seems wrong here
1.329     droeschl  591: 		    $r->print('<li>'.
                    592: 			      &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
                    593: 				  $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
                    594: 			      .'</li>');
                    595: 		}
                    596: 	    }
                    597: 	    $r->print('</ul>');
                    598: 	}
                    599: # End
                    600:         $r->print('</td>'.&Apache::loncommon::end_data_table_row());
                    601:         $shown++;
                    602:         if (!($env{'form.show'} eq &mt('all')
                    603:               || $shown<=$env{'form.show'})) { last; }
                    604:     }
1.484     raeburn   605:     $r->print(&Apache::loncommon::end_data_table()."\n".
                    606:               &makesimpleeditform($pathitem)."\n".
                    607:               '</div></div>');
                    608:     $r->print(&endContentScreen());
1.329     droeschl  609: }
                    610: 
                    611: sub update_paste_buffer {
                    612:     my ($coursenum,$coursedom) = @_;
                    613: 
                    614:     return if (!defined($env{'form.markcopy'}));
                    615:     return if (!defined($env{'form.copyfolder'}));
                    616:     return if ($env{'form.markcopy'} < 0);
                    617: 
                    618:     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                    619: 				    $env{'form.copyfolder'});
1.364     bisitz    620: 
1.329     droeschl  621:     return if ($fatal);
                    622: 
                    623: # Mark for copying
                    624:     my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
                    625:     if (&is_supplemental_title($title)) {
                    626:         &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
1.488   ! raeburn   627: 	($title) = &Apache::loncommon::parse_supplemental_title($title);
1.329     droeschl  628:     } elsif ($env{'docs.markedcopy_supplemental'}) {
1.346     raeburn   629:         &Apache::lonnet::delenv('docs.markedcopy_supplemental');
1.329     droeschl  630:     }
                    631:     $url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
                    632: 
                    633:     &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,
                    634: 			    'docs.markedcopy_url'   => $url});
                    635:     delete($env{'form.markcopy'});
                    636: }
                    637: 
                    638: sub print_paste_buffer {
1.488   ! raeburn   639:     my ($r,$container,$folder) = @_;
1.329     droeschl  640:     return if (!defined($env{'docs.markedcopy_url'}));
                    641: 
1.488   ! raeburn   642:     my $is_external;
        !           643:     my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
        !           644:     if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//} ) {
        !           645:         $is_external = 1;
        !           646:     }
        !           647: 
        !           648:     my $canpaste;
        !           649:     if ($folder =~ /^supplemental/) {
        !           650:         $canpaste = &supp_pasteable($env{'docs.markedcopy_url'}); 
        !           651:     } else {
        !           652:         $canpaste = 1;
        !           653:     }
        !           654: 
        !           655:     my $pasteinfo;
        !           656:     if ($canpaste) {
        !           657:         $pasteinfo = '<form name="pasteform" action="/adm/coursedocs" method="post">'
        !           658:                     .'<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> ';
        !           659:     } else {
        !           660:         $pasteinfo = &mt('Paste buffer contains:').' ';
        !           661:     }
        !           662: 
1.381     bisitz    663:     $r->print('<fieldset>'
                    664:              .'<legend>'.&mt('Clipboard').'</legend>'
1.488   ! raeburn   665:              .$pasteinfo
        !           666:              );
1.329     droeschl  667: 
                    668:     my $type;
1.488   ! raeburn   669:     if ($is_external) {
1.329     droeschl  670: 	$type = &mt('External Resource');
                    671: 	$r->print($type.': '.
                    672: 		  &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
                    673: 		  &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
                    674:     }  else {
                    675: 	my $icon = &Apache::loncommon::icon($extension);
                    676: 	if ($extension eq 'sequence' &&
                    677: 	    $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
                    678: 	    $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1.380     bisitz    679: 	    $icon .= '/navmap.folder.closed.gif';
1.329     droeschl  680: 	}
                    681: 	$icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
1.488   ! raeburn   682: 	$r->print($icon.$type.': '.  &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
1.329     droeschl  683:     }
1.488   ! raeburn   684:     if ($canpaste) {
        !           685:         if ($container eq 'page') {
        !           686: 	    $r->print('
1.329     droeschl  687: 	<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />
                    688: 	<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />
                    689: ');
1.488   ! raeburn   690:         } else {
        !           691: 	    $r->print('
1.329     droeschl  692:         <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
                    693: ');
1.488   ! raeburn   694:         }
        !           695:         $r->print('</form>');
        !           696:     } else {
        !           697:         $r->print('<br /><p class="LC_info">'.&mt('Paste into Supplemental Content unavailable for this type of content.').'</p>');
1.329     droeschl  698:     }
1.488   ! raeburn   699:     $r->print('</fieldset>');
        !           700: }
        !           701: 
        !           702: sub supp_pasteable {
        !           703:     my ($url) = @_;
        !           704:     if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?:&colon;|:))//}) ||
        !           705:         (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
        !           706:         ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
        !           707:         ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
        !           708:         ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
        !           709:         return 1;
        !           710:     }
        !           711:     return;
1.329     droeschl  712: }
                    713: 
                    714: sub do_paste_from_buffer {
                    715:     my ($coursenum,$coursedom,$folder) = @_;
                    716: 
                    717:     if (!$env{'form.pastemarked'}) {
                    718:         return;
                    719:     }
                    720: 
1.488   ! raeburn   721: # Supplemental content may only include certain types of content
        !           722:     if ($folder =~ /^supplemental/) {
        !           723:         unless (&supp_pasteable($env{'docs.markedcopy_url'})) {
        !           724:             return &mt('Paste failed: content type is not supported within Supplemental Content'); 
        !           725:         }
        !           726:     }
        !           727: 
1.329     droeschl  728: # paste resource to end of list
                    729:     my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
                    730:     my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
                    731: # Maps need to be copied first
1.488   ! raeburn   732:     my ($oldurl,%removefrommap,%addedmaps,%rewrites,%copies,%dbcopies,%zombies,%params);
        !           733:     if ($url=~/\.(page|sequence)$/) {
        !           734:         # If pasting a map, check if map contains other maps
        !           735:         &contained_map_check($url,$folder,\%removefrommap,\%addedmaps);
        !           736:         if (keys(%addedmaps) > 0) {
        !           737:             &reinit_role($coursedom,$coursenum,$env{"course.$env{'request.course.id'}.home"});
        !           738:         }
        !           739:         my %allmaps;
        !           740:         my $navmap = Apache::lonnavmaps::navmap->new();
        !           741:         if (defined($navmap)) {
        !           742:             foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
        !           743:                 $allmaps{$res->src()} = 1;
        !           744:             }
        !           745:         }
        !           746:         if ($url=~ m{^/uploaded/}) {
        !           747: 	    $title=&mt('Copy of').' '.$title;
        !           748:         }
1.329     droeschl  749: 	my $newid=$$.int(rand(100)).time;
                    750: 	my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1.488   ! raeburn   751:         if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1.329     droeschl  752:             my $path = $1;
                    753:             my $prefix = $2;
                    754:             my $ancestor = $3;
                    755:             if (length($ancestor) > 10) {
                    756:                 $ancestor = substr($ancestor,-10,10);
                    757:             }
                    758:             $oldid = $path.$prefix.$ancestor;
1.488   ! raeburn   759:             my $counter = 0;
        !           760:             my $newurl=$oldid.$newid.'.'.$ext;
        !           761:             my $is_unique = &uniqueness_check($newurl);
        !           762:             if ($allmaps{$newurl}) {
        !           763:                 $is_unique = 0;
        !           764:             }
        !           765:             while (!$is_unique && $allmaps{$newurl} && $counter < 100) {
        !           766:                 $counter ++;
        !           767:                 $newid ++;
        !           768:                 $newurl = $oldid.$newid;
        !           769:                 $is_unique = &uniqueness_check($newurl);
        !           770:             }
        !           771:             if ($is_unique) {
        !           772:                 if ($path =~ m{^/uploaded/($match_domain)/($match_courseid)/$}) {
        !           773:                     my $srcdom = $1;
        !           774:                     my $srcnum = $2;
        !           775:                     if (($srcdom ne $coursedom) && ($srcnum ne $coursenum)) {
        !           776:                         if (&Apache::lonnet::allowed('mdc',$srcdom.'_'.$srcnum)) {
        !           777:                             &url_paste_fixups($oldid,$ext,$coursedom,$coursenum,
        !           778:                                               \%allmaps, \%rewrites,\%copies,\%dbcopies,\%zombies,\%params);
        !           779:                         } else {
        !           780:                             return &mt('Paste failed: Item is from a different course which you do not have rights to edit');
        !           781:                         }
        !           782:                     }
        !           783:                 }
1.329     droeschl  784:             } else {
1.488   ! raeburn   785:                 if ($url=~/\.page$/) {
        !           786:                     return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
        !           787:                 } else {
        !           788:                     return &mt('Paste failed: an error occurred creating a unique URL for the folder');
        !           789:                 }
1.329     droeschl  790:             }
1.488   ! raeburn   791: 	    my $storefn=$newurl;
        !           792: 	    $storefn=~s{^/\w+/$match_domain/$match_username/}{};
        !           793: 	    my $paste_map_result =
        !           794:                 &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
        !           795: 					           &Apache::lonnet::getfile($url));
        !           796:             if ($paste_map_result eq '/adm/notfound.html') {
        !           797:                 if ($url=~/\.page$/) {
        !           798:                     return &mt('Paste failed: an error occurred saving the composite page');
        !           799:                 } else {
        !           800:                     return &mt('Paste failed: an error occurred saving the folder');
        !           801:                 }
        !           802:             }
        !           803: 	    $url = $newurl;
        !           804:         } elsif ($url=~m {^/res/}) {
        !           805: # published maps can only exists once, so remove it from paste buffer when done
        !           806:             &Apache::lonnet::delenv('docs.markedcopy');
        !           807:             if ($allmaps{$url}) {
        !           808:                 return &mt('Paste failed: only one instance of a particular published sequence or page is allowed within each course.');
1.329     droeschl  809:             }
                    810:         }
                    811:     }
                    812:     if ($url=~ m{/smppg$}) {
                    813: 	my $db_name = &Apache::lonsimplepage::get_db_name($url);
                    814: 	if ($db_name =~ /^smppage_/) {
                    815: 	    #simple pages, need to copy the db contents to a new one.
                    816: 	    my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
                    817: 	    my $now = time();
                    818: 	    $db_name =~ s{_\d*$ }{_$now}x;
                    819: 	    my $result=&Apache::lonnet::put($db_name,\%contents,
                    820: 					    $coursedom,$coursenum);
1.344     bisitz    821: 	    $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
1.329     droeschl  822: 	    $title=&mt('Copy of').' '.$title;
                    823: 	}
                    824:     }
                    825:     $title = &LONCAPA::map::qtunescape($title);
                    826:     my $ext='false';
                    827:     if ($url=~m{^http(|s)://}) { $ext='true'; }
                    828:     $url       = &LONCAPA::map::qtunescape($url);
                    829: # Now insert the URL at the bottom
                    830:     my $newidx = &LONCAPA::map::getresidx($url);
1.488   ! raeburn   831:     my $relpath;
        !           832:     if (($folder =~ /^supplemental/) && 
        !           833:         ($url =~ m{^/uploaded/$coursedom/$coursenum/docs/(.+)})) {
        !           834:         $relpath = $1;
        !           835:     } elsif (($folder =~ /^default/) &&
        !           836:              ($url =~ m{^/uploaded/$coursedom/$coursenum/supplemental/(.+)})) {
        !           837:         $relpath = $1;
        !           838:     }
        !           839:     if ($relpath ne '') {
        !           840:         my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
        !           841:         my ($newloc,$newsubdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
        !           842:         my $newprefix = $newloc;
        !           843:         if ($newloc eq 'default') {
        !           844:             $newprefix = 'docs';
        !           845:         }
        !           846:         if ($newsubdir eq '') {
        !           847:             $newsubdir = 'default';
        !           848:         }
        !           849:         my $newpath = "$newprefix/$newsubdir/$newidx/$rem";
        !           850:         $url =
        !           851:             &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
        !           852:                                                &Apache::lonnet::getfile($url));
        !           853:         if ($url eq '/adm/notfound.html') {
        !           854:             return &mt('Paste failed: an error occurred saving the file.');
        !           855:         }
        !           856:     }
        !           857:     my $noparams = 0;
        !           858:     if ((ref($params{$oldurl}) eq 'HASH') && ($relpath ne '') && ($folder =~ /^supplemental/)) {
        !           859:         $noparams = 1;
        !           860:     }
        !           861:     &apply_fixups($coursedom,$coursenum,$oldurl,$url,$noparams,\%rewrites,\%copies,\%dbcopies,\%zombies,\%params);
1.329     droeschl  862:     if ($env{'docs.markedcopy_supplemental'}) {
                    863:         if ($folder =~ /^supplemental/) {
                    864:             $title = $env{'docs.markedcopy_supplemental'};
                    865:         } else {
1.344     bisitz    866:             (undef,undef,$title) =
1.488   ! raeburn   867:                 &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental'});
1.329     droeschl  868:         }
                    869:     } else {
                    870:         if ($folder=~/^supplemental/) {
                    871:            $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                    872:                   $env{'user.domain'}.'___&&&___'.$title;
                    873:         }
                    874:     }
                    875: 
                    876:     $LONCAPA::map::resources[$newidx]= 	$title.':'.$url.':'.$ext.':normal:res';
                    877:     push(@LONCAPA::map::order, $newidx);
                    878:     return 'ok';
                    879: # Store the result
                    880: }
                    881: 
1.488   ! raeburn   882: sub dbcopy {
        !           883:     my ($url,$coursedom,$coursenum) = @_;
        !           884:     if ($url=~ m{/smppg$}) {
        !           885:         my $db_name = &Apache::lonsimplepage::get_db_name($url);
        !           886:         if ($db_name =~ /^smppage_/) {
        !           887:             #simple pages, need to copy the db contents to a new one.
        !           888:             my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
        !           889:             my $now = time();
        !           890:             $db_name =~ s{_\d*$ }{_$now}x;
        !           891:             my $result=&Apache::lonnet::put($db_name,\%contents,
        !           892:                                             $coursedom,$coursenum);
        !           893:             $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
        !           894:         }
        !           895:     }
        !           896:     return $url;
        !           897: }
        !           898: 
1.329     droeschl  899: sub uniqueness_check {
                    900:     my ($newurl) = @_;
                    901:     my $unique = 1;
                    902:     foreach my $res (@LONCAPA::map::order) {
                    903:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                    904:         $url=&LONCAPA::map::qtescape($url);
                    905:         if ($newurl eq $url) {
                    906:             $unique = 0;
1.344     bisitz    907:             last;
1.329     droeschl  908:         }
                    909:     }
                    910:     return $unique;
                    911: }
                    912: 
1.488   ! raeburn   913: sub contained_map_check {
        !           914:     my ($url,$folder,$removefrommap,$addedmaps) = @_;
        !           915:     my $content = &Apache::lonnet::getfile($url);
        !           916:     unless ($content eq '-1') {
        !           917:         my $parser = HTML::TokeParser->new(\$content);
        !           918:         $parser->attr_encoded(1);
        !           919:         while (my $token = $parser->get_token) {
        !           920:             next if ($token->[0] ne 'S');
        !           921:             if ($token->[1] eq 'resource') {
        !           922:                 next if ($token->[2]->{'type'} eq 'zombie');
        !           923:                 my $ressrc = $token->[2]->{'src'};
        !           924:                 if ($folder =~ /^supplemental/) {
        !           925:                     unless (&supp_pasteable($ressrc)) {
        !           926:                         $removefrommap->{$url}{$token->[2]->{'id'}};
        !           927:                         next;
        !           928:                     }
        !           929:                 }
        !           930:                 if ($ressrc =~ /\.(sequence|page)$/) {
        !           931:                     if (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
        !           932:                         push(@{$addedmaps->{$ressrc}},$url);
        !           933:                     } else {
        !           934:                         $addedmaps->{$ressrc} = [$url];
        !           935:                     }
        !           936:                     &contained_map_check($ressrc,$folder,$removefrommap,$addedmaps);
        !           937:                 }
        !           938:             } elsif ($token->[1] !~ /^resource|map|link$/) {
        !           939:                 if ($folder =~ /^supplemental/) {
        !           940:                     $removefrommap->{$url}{$token->[1]};
        !           941:                 }
        !           942:             }
        !           943:         }
        !           944:     }
        !           945:     return;
        !           946: }
        !           947: 
        !           948: sub reinit_role {
        !           949:     my ($cdom,$cnum,$chome) = @_;
        !           950:     my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
        !           951:     unless ($ferr) {
        !           952:         &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
        !           953:     }
        !           954:     return;
        !           955: }
        !           956: 
        !           957: sub url_paste_fixups {
        !           958:     my ($oldurl,$ext,$cdom,$cnum,$allmaps,$rewrites,$copies,$dbcopies,$zombies,$params) = @_;
        !           959:     my $file = &Apache::lonnet::getfile("$oldurl.$ext");
        !           960:     return if ($file eq '-1');
        !           961:     my $parser = HTML::TokeParser->new(\$file);
        !           962:     $parser->attr_encoded(1);
        !           963:     while (my $token = $parser->get_token) {
        !           964:         next if ($token->[0] ne 'S');
        !           965:         if ($token->[1] eq 'resource') {
        !           966:             my $ressrc = $token->[2]->{'src'};
        !           967:             next if ($ressrc eq '');
        !           968:             next if ($token->[2]->{'type'} eq 'external');
        !           969:             my $id = $token->[2]->{'id'};
        !           970:             if ($token->[2]->{'type'} eq 'zombie') {
        !           971:                 $zombies->{$oldurl}{$ressrc} = $id;
        !           972:             } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)}) {
        !           973:                 my $srccdom = $1;
        !           974:                 my $srccnum = $2;
        !           975:                 my $rem = $3;
        !           976:                 if (($srccdom ne $cdom) || ($srccnum ne $cnum)) {
        !           977:                     if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
        !           978:                         $rewrites->{$oldurl}{$ressrc} = $id;
        !           979:                         &url_paste_fixups($ressrc,$3,$cdom,$cnum,$allmaps,$rewrites,$copies,$dbcopies,$zombies,$params);
        !           980:                     } else {
        !           981:                         $copies->{$oldurl}{$ressrc} = $id;
        !           982:                     }
        !           983:                 }
        !           984:             } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
        !           985:                 my $srccdom = $1;
        !           986:                 my $srccnum = $2;
        !           987:                 if (($srccdom ne $cdom) || ($srccnum ne $cnum)) {
        !           988:                     $rewrites->{$oldurl}{$ressrc} = $id;
        !           989:                     $dbcopies->{$oldurl}{$ressrc} = $id;
        !           990:                 }
        !           991:             } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
        !           992:                 my $srccdom = $1;
        !           993:                 my $srccnum = $2;
        !           994:                 if (($srccdom ne $cdom) || ($srccnum ne $cnum)) {
        !           995:                     $rewrites->{$oldurl}{$ressrc} = $id;
        !           996:                     $dbcopies->{$oldurl}{$ressrc} = $id;
        !           997:                 }
        !           998:             }
        !           999:         } elsif ($token->[1] eq 'param') {
        !          1000:             my $to = $token->[2]->{'to'}; 
        !          1001:             if ($to ne '') {
        !          1002:                 if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
        !          1003:                     push (@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
        !          1004:                 } else {
        !          1005:                     @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
        !          1006:                 }
        !          1007:             }
        !          1008:         }
        !          1009:     }
        !          1010:     return;
        !          1011: }
        !          1012: 
        !          1013: sub apply_fixups {
        !          1014:     my ($cdom,$cnum,$oldurl,$url,$noparams,$rewrites,$copies,$dbcopies,$zombies,$params) = @_;
        !          1015:     my (%newdb,%newdoc);
        !          1016:     if (ref($dbcopies->{$oldurl}) eq 'HASH') {
        !          1017:         foreach my $item (keys(%{$dbcopies->{$oldurl}})) {
        !          1018:             $newdb{$item} = &dbcopy($item);
        !          1019:         }
        !          1020:     }
        !          1021:     if (ref($copies->{$oldurl}) eq 'HASH') {
        !          1022:         foreach my $item (keys(%{$copies->{$oldurl}})) {
        !          1023:             my $content = &Apache::lonnet::getfile($item);
        !          1024:             my $newcontent;
        !          1025:             unless ($content eq '-1') {
        !          1026:                 my $mm = new File::MMagic;
        !          1027:                 my $mimetype = $mm->checktype_contents($content);
        !          1028:                 if ($mimetype eq 'text/html') {
        !          1029:                     my (%allfiles,%codebase,$state);
        !          1030:                     my ($embedded,$num,$delnum) =
        !          1031:                         &Apache::loncommon::ask_for_embedded_content(
        !          1032:                             '/adm/dependencies',$state,\%allfiles,\%codebase,
        !          1033:                             {'error_on_invalid_names'   => 1,
        !          1034:                              'ignore_remote_references' => 1,
        !          1035:                              'docs_url'                 => $oldurl});
        !          1036:                     if ($embedded) {
        !          1037:                         #FIXME Need to check for dependencies and copy and update refs.
        !          1038:                     }
        !          1039:                     $newcontent = $content;
        !          1040:                 } else {
        !          1041:                     $newcontent = $content;
        !          1042:                 }
        !          1043:                 my $storefn=$item;
        !          1044:                 $storefn=~s{^/\w+/$match_domain/$match_courseid/}{};
        !          1045:                 $newdoc{$item} = &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,$newcontent); 
        !          1046:             }
        !          1047:         }
        !          1048:     }
        !          1049:     if (((ref($rewrites->{$oldurl}) eq 'HASH') || (ref($zombies->{$oldurl}) eq 'HASH')) || 
        !          1050:         ($noparams) || (keys(%newdb) > 0) || (keys(%newdoc) > 0)) {
        !          1051:         my $map = &Apache::lonnet::getfile($url);
        !          1052:         my $newcontent;
        !          1053:         unless ($map eq '-1') {
        !          1054:             my $parser = HTML::TokeParser->new(\$map);
        !          1055:             $parser->attr_encoded(1);
        !          1056:             while (my $token = $parser->get_token) {
        !          1057:                 if ($token->[0] eq 'S') {
        !          1058:                     next if ($token->[2]->{'type'} eq 'zombie');
        !          1059:                     next if (($token->[1] eq 'param') && $noparams);
        !          1060:                     if ($token->[1] eq 'resource') {
        !          1061:                         my $src = $token->[2]->{'src'};
        !          1062:                         my $id = $token->[2]->{'id'};
        !          1063:                         if (($rewrites->{$oldurl}{$src} eq $id) || ($newdb{$src} ne '')
        !          1064:                             || ($newdoc{$src} ne '')) {
        !          1065:                             if (ref($rewrites->{$oldurl}) eq 'HASH') {
        !          1066:                                 if ($rewrites->{$oldurl}{$src} eq $id) {
        !          1067:                                     $token->[2]->{'src'} =~ s{^(/uploaded|adm|public)/$match_domain/$match_courseid/}{$1/$cdom/$cnum};
        !          1068:                                 }
        !          1069:                             } elsif ($newdb{$src} ne '') {
        !          1070:                                 $token->[2]->{'src'} = $newdb{$src};
        !          1071:                             }
        !          1072:                             $newcontent .= "<$token->[1] "; 
        !          1073:                             foreach my $attr (@{$token->[3]}) {
        !          1074:                                 $newcontent .=  ' '.$attr.'="'.$token->[2]->{$attr},'"'
        !          1075:                             }
        !          1076:                             $newcontent .= ' />';
        !          1077:                         } else {
        !          1078:                             $newcontent .= $token->[4]."\n";
        !          1079:                         }
        !          1080:                     }
        !          1081:                 } elsif ($token->[0] eq 'E') {
        !          1082:                     $newcontent .= $token->[2]."\n";
        !          1083:                 }
        !          1084:             }
        !          1085:         }
        !          1086:         my $storefn=$url;
        !          1087:         $storefn=~s{^/\w+/$match_domain/$match_courseid/}{};
        !          1088:         my $storeres =
        !          1089:             &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
        !          1090:                                                $newcontent);
        !          1091:     }
        !          1092:     return;
        !          1093: }
        !          1094: 
1.329     droeschl 1095: my %parameter_type = ( 'randompick'     => 'int_pos',
                   1096: 		       'hiddenresource' => 'string_yesno',
                   1097: 		       'encrypturl'     => 'string_yesno',
                   1098: 		       'randomorder'    => 'string_yesno',);
                   1099: my $valid_parameters_re = join('|',keys(%parameter_type));
                   1100: # set parameters
                   1101: sub update_parameter {
                   1102: 
                   1103:     return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
                   1104: 
                   1105:     my $which = $env{'form.changeparms'};
                   1106:     my $idx = $env{'form.setparms'};
                   1107:     if ($env{'form.'.$which.'_'.$idx}) {
                   1108: 	my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
                   1109: 	                                     : 'yes';
                   1110: 	&LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
                   1111: 				      $parameter_type{$which});
                   1112: 	&remember_parms($idx,$which,'set',$value);
                   1113:     } else {
                   1114: 	&LONCAPA::map::delparameter($idx,'parameter_'.$which);
1.364     bisitz   1115: 
1.329     droeschl 1116: 	&remember_parms($idx,$which,'del');
                   1117:     }
                   1118:     return 1;
                   1119: }
                   1120: 
                   1121: 
                   1122: sub handle_edit_cmd {
                   1123:     my ($coursenum,$coursedom) =@_;
                   1124:     my ($cmd,$idx)=split('_',$env{'form.cmd'});
                   1125: 
                   1126:     my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
                   1127:     my ($title, $url, @rrest) = split(':', $ratstr);
                   1128: 
                   1129:     if ($cmd eq 'del') {
                   1130: 	if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463     www      1131: 	    ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329     droeschl 1132: 	    &Apache::lonnet::removeuploadedurl($url);
                   1133: 	} else {
                   1134: 	    &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   1135: 	}
                   1136: 	splice(@LONCAPA::map::order, $idx, 1);
                   1137: 
                   1138:     } elsif ($cmd eq 'cut') {
                   1139: 	&LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
                   1140: 	splice(@LONCAPA::map::order, $idx, 1);
                   1141: 
1.344     bisitz   1142:     } elsif ($cmd eq 'up'
1.329     droeschl 1143: 	     && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
                   1144: 	@LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
                   1145: 
                   1146:     } elsif ($cmd eq 'down'
                   1147: 	     && defined($LONCAPA::map::order[$idx+1])) {
                   1148: 	@LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
                   1149: 
                   1150:     } elsif ($cmd eq 'rename') {
                   1151: 
                   1152: 	my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
                   1153: 	if ($comment=~/\S/) {
                   1154: 	    $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
                   1155: 		$comment.':'.join(':', $url, @rrest);
                   1156: 	}
                   1157: # Devalidate title cache
                   1158: 	my $renamed_url=&LONCAPA::map::qtescape($url);
                   1159: 	&Apache::lonnet::devalidate_title_cache($renamed_url);
                   1160:     } else {
                   1161: 	return 0;
                   1162:     }
                   1163:     return 1;
                   1164: }
                   1165: 
                   1166: sub editor {
1.458     raeburn  1167:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.472     raeburn  1168:         $supplementalflag,$orderhash,$iconpath)=@_;
1.329     droeschl 1169:     my $container= ($env{'form.pagepath'}) ? 'page'
                   1170: 		                           : 'sequence';
                   1171: 
1.484     raeburn  1172:     my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
                   1173:         &breadcrumbs($allowed,$crstype);
                   1174:     $r->print($breadcrumbtrail);
                   1175: 
                   1176:     my $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
                   1177: 
                   1178:     unless ($allowed) {
                   1179:         $randompick = -1;
                   1180:     }
                   1181: 
1.329     droeschl 1182:     my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                   1183: 				    $folder.'.'.$container);
                   1184:     return $errtext if ($fatal);
                   1185: 
                   1186:     if ($#LONCAPA::map::order<1) {
                   1187: 	my $idx=&LONCAPA::map::getresidx();
                   1188: 	if ($idx<=0) { $idx=1; }
                   1189:        	$LONCAPA::map::order[0]=$idx;
                   1190:         $LONCAPA::map::resources[$idx]='';
                   1191:     }
1.364     bisitz   1192: 
1.329     droeschl 1193: # ------------------------------------------------------------ Process commands
                   1194: 
                   1195: # ---------------- if they are for this folder and user allowed to make changes
                   1196:     if (($allowed) && ($env{'form.folder'} eq $folder)) {
                   1197: # set parameters and change order
                   1198: 	&snapshotbefore();
                   1199: 
                   1200: 	if (&update_parameter()) {
                   1201: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
                   1202: 	    return $errtext if ($fatal);
                   1203: 	}
                   1204: 
                   1205: 	if ($env{'form.newpos'} && $env{'form.currentpos'}) {
                   1206: # change order
                   1207: 	    my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
                   1208: 	    splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
                   1209: 
                   1210: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
                   1211: 	    return $errtext if ($fatal);
                   1212: 	}
1.364     bisitz   1213: 
1.329     droeschl 1214: 	if ($env{'form.pastemarked'}) {
1.344     bisitz   1215:             my $paste_res =
1.329     droeschl 1216:                 &do_paste_from_buffer($coursenum,$coursedom,$folder);
                   1217:             if ($paste_res eq 'ok') {
                   1218:                 ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
                   1219:                 return $errtext if ($fatal);
                   1220:             } elsif ($paste_res ne '') {
                   1221:                 $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
                   1222:             }
                   1223: 	}
                   1224: 
                   1225: 	$r->print($upload_output);
                   1226: 
                   1227: 	if (&handle_edit_cmd()) {
                   1228: 	    ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
                   1229: 	    return $errtext if ($fatal);
                   1230: 	}
                   1231: # Group import/search
                   1232: 	if ($env{'form.importdetail'}) {
                   1233: 	    my @imports;
                   1234: 	    foreach my $item (split(/\&/,$env{'form.importdetail'})) {
                   1235: 		if (defined($item)) {
                   1236: 		    my ($name,$url,$residx)=
                   1237: 			map {&unescape($_)} split(/\=/,$item);
                   1238: 		    push(@imports, [$name, $url, $residx]);
                   1239: 		}
                   1240: 	    }
                   1241: 	    ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
                   1242: 					    $container,'londocs',@imports);
                   1243: 	    return $errtext if ($fatal);
                   1244: 	}
                   1245: # Loading a complete map
                   1246: 	if ($env{'form.loadmap'}) {
                   1247: 	    if ($env{'form.importmap'}=~/\w/) {
                   1248: 		foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
                   1249: 		    my ($title,$url,$ext,$type)=split(/\:/,$res);
                   1250: 		    my $idx=&LONCAPA::map::getresidx($url);
                   1251: 		    $LONCAPA::map::resources[$idx]=$res;
                   1252: 		    $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
                   1253: 		}
                   1254: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
                   1255: 					    $folder.'.'.$container);
                   1256: 		return $errtext if ($fatal);
                   1257: 	    } else {
                   1258: 		$r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364     bisitz   1259: 
1.329     droeschl 1260: 	    }
                   1261: 	}
                   1262: 	&log_differences($plain);
                   1263:     }
                   1264: # ---------------------------------------------------------------- End commands
                   1265: # ---------------------------------------------------------------- Print screen
                   1266:     my $idx=0;
                   1267:     my $shown=0;
                   1268:     if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381     bisitz   1269: 	$r->print('<div class="LC_Box">'.
1.432     raeburn  1270:           '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
                   1271: 		  ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
                   1272: 		  ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
                   1273: 		  ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
                   1274: 		  ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431     raeburn  1275: 		  '</ol>');
1.381     bisitz   1276:         if ($randompick>=0) {
                   1277:             $r->print('<p class="LC_warning">'
                   1278:                  .&mt('Caution: this folder is set to randomly pick a subset'
                   1279:                      .' of resources. Adding or removing resources from this'
                   1280:                      .' folder will change the set of resources that the'
                   1281:                      .' students see, resulting in spurious or missing credit'
                   1282:                      .' for completed problems, not limited to ones you'
                   1283:                      .' modify. Do not modify the contents of this folder if'
                   1284:                      .' it is in active student use.')
                   1285:                  .'</p>'
                   1286:             );
                   1287:         }
                   1288:         if ($is_random_order) {
                   1289:             $r->print('<p class="LC_warning">'
                   1290:                  .&mt('Caution: this folder is set to randomly order its'
                   1291:                      .' contents. Adding or removing resources from this folder'
                   1292:                      .' will change the order of resources shown.')
                   1293:                  .'</p>'
                   1294:             );
                   1295:         }
                   1296:         $r->print('</div>');
1.364     bisitz   1297:     }
1.381     bisitz   1298: 
1.458     raeburn  1299:     my ($to_show,$output);
1.424     onken    1300: 
                   1301:     &Apache::loncommon::start_data_table_count(); #setup a row counter 
1.381     bisitz   1302:     foreach my $res (@LONCAPA::map::order) {
                   1303:         my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
                   1304:         $name=&LONCAPA::map::qtescape($name);
                   1305:         $url=&LONCAPA::map::qtescape($url);
                   1306:         unless ($name) {  $name=(split(/\//,$url))[-1]; }
                   1307:         unless ($name) { $idx++; next; }
                   1308:         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.408     raeburn  1309:                               $coursenum,$crstype);
1.381     bisitz   1310:         $idx++;
                   1311:         $shown++;
1.329     droeschl 1312:     }
1.424     onken    1313:     &Apache::loncommon::end_data_table_count();
                   1314:     
1.381     bisitz   1315:     if ($shown) {
1.458     raeburn  1316:         $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
                   1317:                   .&Apache::loncommon::start_data_table(undef,'contentlist');
1.393     raeburn  1318:         if ($allowed) {
1.458     raeburn  1319:             $to_show .= &Apache::loncommon::start_data_table_header_row()
1.393     raeburn  1320:                      .'<th colspan="2">'.&mt('Move').'</th>'
                   1321:                      .'<th>'.&mt('Actions').'</th>'
1.458     raeburn  1322:                      .'<th colspan="2">'.&mt('Document').'</th>';
1.393     raeburn  1323:             if ($folder !~ /^supplemental/) {
1.458     raeburn  1324:                 $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
1.393     raeburn  1325:             }
1.458     raeburn  1326:             $to_show .= &Apache::loncommon::end_data_table_header_row();
1.393     raeburn  1327:         }
1.458     raeburn  1328:         $to_show .= $output.' '
1.393     raeburn  1329:                  .&Apache::loncommon::end_data_table()
1.458     raeburn  1330:                  .'<br style="line-height:2px;" />'
                   1331:                  .&Apache::loncommon::end_scrollbox();
1.393     raeburn  1332:     } else {
1.458     raeburn  1333:         $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
                   1334:                  .'<div class="LC_info" id="contentlist">'
1.381     bisitz   1335:                  .&mt('Currently no documents.')
1.458     raeburn  1336:                  .'</div>'
                   1337:                  .&Apache::loncommon::end_scrollbox();
                   1338:     }
                   1339:     my $tid = 1;
                   1340:     if ($supplementalflag) {
                   1341:         $tid = 2;
1.329     droeschl 1342:     }
                   1343:     if ($allowed) {
1.484     raeburn  1344:         my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
                   1345:         $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,$jumpto,
                   1346:                                        $readfile));
1.488   ! raeburn  1347:         &print_paste_buffer($r,$container,$folder);
1.460     raeburn  1348:     } else {
1.472     raeburn  1349:         if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
                   1350:             #Function Box for Supplemental Content for users with mdc priv.
                   1351:             my $funcname = &mt('Folder Editor');
                   1352:             $r->print(
                   1353:                 &Apache::loncommon::head_subbox(
                   1354:                     &Apache::lonhtmlcommon::start_funclist().
                   1355:                     &Apache::lonhtmlcommon::add_item_funclist(
                   1356:                         '<a href="/adm/coursedocs?command=direct&forcesupplement=1&'.
                   1357:                         'supppath='.&HTML::Entities::encode($env{'form.folderpath'}).'">'.
                   1358:                         '<img src="/res/adm/pages/docs.png" alt="'.$funcname.'" class="LC_icon" />'.
                   1359:                         '<span class="LC_menubuttons_inline_text">'.$funcname.'</span></a>').
                   1360:                           &Apache::lonhtmlcommon::end_funclist()));
                   1361:         }
1.460     raeburn  1362:         $r->print($to_show);
1.329     droeschl 1363:     }
                   1364:     return;
                   1365: }
                   1366: 
                   1367: sub process_file_upload {
                   1368:     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
                   1369: # upload a file, if present
1.440     raeburn  1370:     my ($parseaction,$showupload,$nextphase,$mimetype);
                   1371:     if ($env{'form.parserflag'}) {
1.329     droeschl 1372:         $parseaction = 'parse';
                   1373:     }
                   1374:     my $folder=$env{'form.folder'};
                   1375:     if ($folder eq '') {
                   1376:         $folder='default';
                   1377:     }
                   1378:     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
                   1379:         my $errtext='';
                   1380:         my $fatal=0;
                   1381:         my $container='sequence';
                   1382:         if ($env{'form.pagepath'}) {
                   1383:             $container='page';
                   1384:         }
                   1385:         ($errtext,$fatal)=
                   1386:               &mapread($coursenum,$coursedom,$folder.'.'.$container);
                   1387:         if ($#LONCAPA::map::order<1) {
                   1388:             $LONCAPA::map::order[0]=1;
                   1389:             $LONCAPA::map::resources[1]='';
                   1390:         }
                   1391:         if ($fatal) {
1.457     raeburn  1392:             $$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>';
1.440     raeburn  1393:             return;
1.329     droeschl 1394:         }
                   1395:         my $destination = 'docs/';
                   1396:         if ($folder =~ /^supplemental/) {
                   1397:             $destination = 'supplemental/';
                   1398:         }
                   1399:         if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   1400:             $destination .= 'default/';
                   1401:         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   1402:             $destination .=  $2.'/';
                   1403:         }
1.440     raeburn  1404: # this is for a course, not a user, so set context to coursedoc.
1.329     droeschl 1405:         my $newidx=&LONCAPA::map::getresidx();
                   1406:         $destination .= $newidx;
1.439     raeburn  1407:         my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329     droeschl 1408: 						$parseaction,$allfiles,
1.440     raeburn  1409: 						$codebase,undef,undef,undef,undef,
                   1410:                                                 undef,undef,\$mimetype);
                   1411:         if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
                   1412:             my $stored = $1;
                   1413:             $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   1414:                           $stored.'</span>').'</p>';
                   1415:         } else {
                   1416:             my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
                   1417:             
1.457     raeburn  1418:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440     raeburn  1419:             return;
                   1420:         }
1.329     droeschl 1421:         my $ext='false';
                   1422:         if ($url=~m{^http://}) { $ext='true'; }
                   1423: 	$url     = &LONCAPA::map::qtunescape($url);
                   1424:         my $comment=$env{'form.comment'};
                   1425: 	$comment = &LONCAPA::map::qtunescape($comment);
                   1426:         if ($folder=~/^supplemental/) {
                   1427:               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   1428:                   $env{'user.domain'}.'___&&&___'.$comment;
                   1429:         }
                   1430: 
                   1431:         $LONCAPA::map::resources[$newidx]=
                   1432: 	    $comment.':'.$url.':'.$ext.':normal:res';
                   1433:         $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
                   1434:         ($errtext,$fatal)=&storemap($coursenum,$coursedom,
                   1435: 				    $folder.'.'.$container);
                   1436:         if ($fatal) {
1.457     raeburn  1437:             $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440     raeburn  1438:             return;
1.329     droeschl 1439:         } else {
1.440     raeburn  1440:             if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
                   1441:                 $$upload_output = $showupload;
1.384     raeburn  1442:                 my $total_embedded = scalar(keys(%{$allfiles}));
1.329     droeschl 1443:                 if ($total_embedded > 0) {
1.440     raeburn  1444:                     my $uploadphase = 'upload_embedded';
                   1445:                     my $primaryurl = &HTML::Entities::encode($url,'<>&"');
                   1446: 		    my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx); 
                   1447:                     my ($embedded,$num) = 
                   1448:                         &Apache::loncommon::ask_for_embedded_content(
                   1449:                             '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
                   1450:                     if ($embedded) {
                   1451:                         if ($num) {
                   1452:                             $$upload_output .=
                   1453: 			         '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
                   1454:                             $nextphase = $uploadphase;
                   1455:                         } else {
                   1456:                             $$upload_output .= $embedded;
                   1457:                         }
                   1458:                     } else {
                   1459:                         $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
                   1460:                     }
1.329     droeschl 1461:                 } else {
1.440     raeburn  1462:                     $$upload_output .= &mt('No embedded items identified').'<br />';
1.329     droeschl 1463:                 }
1.457     raeburn  1464:                 $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.476     raeburn  1465:             } elsif (&Apache::loncommon::is_archive_file($mimetype)) {
                   1466:                 $nextphase = 'decompress_uploaded';
                   1467:                 my $position = scalar(@LONCAPA::map::order)-1;
                   1468:                 my $noextract = &return_to_editor();
                   1469:                 my $archiveurl = &HTML::Entities::encode($url,'<>&"');
                   1470:                 my %archiveitems = (
                   1471:                     folderpath => $env{'form.folderpath'},
                   1472:                     pagepath   => $env{'form.pagepath'},
                   1473:                     cmd        => $nextphase,
                   1474:                     newidx     => $newidx,
                   1475:                     position   => $position,
                   1476:                     phase      => $nextphase,
1.477     raeburn  1477:                     comment    => $comment,
1.480     raeburn  1478:                 );
                   1479:                 my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
                   1480:                 my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx); 
1.476     raeburn  1481:                 $$upload_output = $showupload.
                   1482:                                   &Apache::loncommon::decompress_form($mimetype,
                   1483:                                       $archiveurl,'/adm/coursedocs',$noextract,
1.480     raeburn  1484:                                       \%archiveitems,\@current);
1.329     droeschl 1485:             }
                   1486:         }
                   1487:     }
1.440     raeburn  1488:     return $nextphase;
1.329     droeschl 1489: }
                   1490: 
1.480     raeburn  1491: sub get_dir_list {
                   1492:     my ($url,$coursenum,$coursedom,$newidx) = @_;
                   1493:     my ($destination,$dir_root) = &embedded_destination();
                   1494:     my ($dirlistref,$listerror) =  
                   1495:         &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
                   1496:     my @dir_lines;
                   1497:     my $dirptr=16384;
                   1498:     if (ref($dirlistref) eq 'ARRAY') {
                   1499:         foreach my $dir_line (sort
                   1500:                           {
                   1501:                               my ($afile)=split('&',$a,2);
                   1502:                               my ($bfile)=split('&',$b,2);
                   1503:                               return (lc($afile) cmp lc($bfile));
                   1504:                           } (@{$dirlistref})) {
                   1505:             my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
                   1506:             $filename =~ s/\s+$//;
                   1507:             next if ($filename =~ /^\.\.?$/); 
                   1508:             my $isdir = 0;
                   1509:             if ($dirptr&$testdir) {
                   1510:                 $isdir = 1;
                   1511:             }
                   1512:             push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
                   1513:         }
                   1514:     }
                   1515:     return @dir_lines;
                   1516: }
                   1517: 
1.329     droeschl 1518: sub is_supplemental_title {
                   1519:     my ($title) = @_;
                   1520:     return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
                   1521: }
                   1522: 
                   1523: # --------------------------------------------------------------- An entry line
                   1524: 
                   1525: sub entryline {
1.408     raeburn  1526:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$crstype)=@_;
1.329     droeschl 1527:     my ($foldertitle,$pagetitle,$renametitle);
                   1528:     if (&is_supplemental_title($title)) {
1.488   ! raeburn  1529: 	($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329     droeschl 1530: 	$pagetitle = $foldertitle;
                   1531:     } else {
                   1532: 	$title=&HTML::Entities::encode($title,'"<>&\'');
                   1533: 	$renametitle=$title;
                   1534: 	$foldertitle=$title;
                   1535: 	$pagetitle=$title;
                   1536:     }
                   1537: 
                   1538:     my $orderidx=$LONCAPA::map::order[$index];
1.364     bisitz   1539: 
1.329     droeschl 1540: 
                   1541:     $renametitle=~s/\\/\\\\/g;
                   1542:     $renametitle=~s/\&quot\;/\\\"/g;
                   1543:     $renametitle=~s/ /%20/g;
1.379     bisitz   1544:     my $line=&Apache::loncommon::start_data_table_row();
1.478     raeburn  1545:     my ($form_start,$form_end,$form_common);
1.329     droeschl 1546: # Edit commands
                   1547:     my ($container, $type, $esc_path, $path, $symb);
                   1548:     if ($env{'form.folderpath'}) {
                   1549: 	$type = 'folder';
                   1550:         $container = 'sequence';
                   1551: 	$esc_path=&escape($env{'form.folderpath'});
                   1552: 	$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   1553: 	# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
                   1554:     }
                   1555:     if ($env{'form.pagepath'}) {
                   1556:         $type = $container = 'page';
1.440     raeburn  1557:         $esc_path=&escape($env{'form.pagepath'});
1.329     droeschl 1558: 	$path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
                   1559:         $symb=&escape($env{'form.pagesymb'});
                   1560:     }
                   1561:     my $cpinfo='';
                   1562:     if ($allowed) {
                   1563: 	my $incindex=$index+1;
                   1564: 	my $selectbox='';
1.471     raeburn  1565: 	if (($#LONCAPA::map::order>0) &&
1.329     droeschl 1566: 	    ((split(/\:/,
1.344     bisitz   1567: 	     $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
                   1568: 	     ne '') &&
1.329     droeschl 1569: 	    ((split(/\:/,
1.344     bisitz   1570: 	     $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329     droeschl 1571: 	     ne '')) {
                   1572: 	    $selectbox=
                   1573: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373     bisitz   1574: 		'<select name="newpos" onchange="this.form.submit()">';
1.329     droeschl 1575: 	    for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
                   1576: 		if ($i==$incindex) {
1.358     bisitz   1577: 		    $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329     droeschl 1578: 		} else {
                   1579: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
                   1580: 		}
                   1581: 	    }
                   1582: 	    $selectbox.='</select>';
                   1583: 	}
                   1584: 	my %lt=&Apache::lonlocal::texthash(
                   1585:                 'up' => 'Move Up',
                   1586: 		'dw' => 'Move Down',
                   1587: 		'rm' => 'Remove',
                   1588:                 'ct' => 'Cut',
                   1589: 		'rn' => 'Rename',
                   1590: 		'cp' => 'Copy');
                   1591: 	my $nocopy=0;
                   1592:         my $nocut=0;
                   1593:         if ($url=~/\.(page|sequence)$/) {
                   1594: 	    if ($url =~ m{/res/}) {
                   1595: 		# no copy for published maps
                   1596: 		$nocopy = 1;
                   1597: 	    } else {
                   1598: 		foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
                   1599: 		    my ($title,$url,$ext,$type)=split(/\:/,$item);
                   1600: 		    if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
                   1601: 			$nocopy=1;
                   1602: 			last;
                   1603: 		    }
                   1604: 		}
                   1605: 	    }
                   1606: 	}
1.344     bisitz   1607:         if ($url=~/^\/res\/lib\/templates\//) {
                   1608:            $nocopy=1;
1.329     droeschl 1609:            $nocut=1;
                   1610:         }
                   1611:         my $copylink='&nbsp;';
                   1612:         my $cutlink='&nbsp;';
1.364     bisitz   1613: 
1.329     droeschl 1614: 	my $skip_confirm = 0;
                   1615: 	if ( $folder =~ /^supplemental/
                   1616: 	     || ($url =~ m{( /smppg$
                   1617: 			    |/syllabus$
                   1618: 			    |/aboutme$
                   1619: 			    |/navmaps$
                   1620: 			    |/bulletinboard$
                   1621: 			    |\.html$
                   1622: 			    |^/adm/wrapper/ext)}x)) {
                   1623: 	    $skip_confirm = 1;
                   1624: 	}
                   1625: 
                   1626: 	if (!$nocopy) {
                   1627: 	    $copylink=(<<ENDCOPY);
1.484     raeburn  1628: <a href="javascript:markcopy('$esc_path','$index','$renametitle','$container','$symb','$folder');" class="LC_docs_copy">$lt{'cp'}</a>
1.329     droeschl 1629: ENDCOPY
                   1630:         }
                   1631: 	if (!$nocut) {
                   1632: 	    $cutlink=(<<ENDCUT);
1.484     raeburn  1633: <a href="javascript:cutres('$esc_path','$index','$renametitle','$container','$symb','$folder',$skip_confirm);" class="LC_docs_cut">$lt{'ct'}</a>
1.329     droeschl 1634: ENDCUT
                   1635:         }
1.478     raeburn  1636: 	$form_start = '
                   1637:    <form action="/adm/coursedocs" method="post">
                   1638: ';
                   1639:         $form_common=(<<END);
1.329     droeschl 1640:    <input type="hidden" name="${type}path" value="$path" />
                   1641:    <input type="hidden" name="${type}symb" value="$symb" />
                   1642:    <input type="hidden" name="setparms" value="$orderidx" />
                   1643:    <input type="hidden" name="changeparms" value="0" />
                   1644: END
                   1645:         $form_end = '</form>';
                   1646: 	$line.=(<<END);
                   1647: <td>
1.379     bisitz   1648: <div class="LC_docs_entry_move">
                   1649:   <a href='/adm/coursedocs?cmd=up_$index&amp;${type}path=$esc_path&amp;${type}symb=$symb$cpinfo'>
                   1650:     <img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" />
                   1651:   </a>
                   1652: </div>
                   1653: <div class="LC_docs_entry_move">
                   1654:   <a href='/adm/coursedocs?cmd=down_$index&amp;${type}path=$esc_path&amp;${type}symb=$symb$cpinfo'>
                   1655:     <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" />
                   1656:   </a>
                   1657: </div>
1.329     droeschl 1658: </td>
                   1659: <td>
                   1660:    $form_start
1.478     raeburn  1661:    $form_common
1.329     droeschl 1662:    $selectbox
                   1663:    $form_end
                   1664: </td>
                   1665: <td class="LC_docs_entry_commands">
                   1666:    <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
                   1667: $cutlink
                   1668:    <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
                   1669: $copylink
                   1670: </td>
                   1671: END
                   1672: 
                   1673:     }
                   1674: # Figure out what kind of a resource this is
                   1675:     my ($extension)=($url=~/\.(\w+)$/);
                   1676:     my $uploaded=($url=~/^\/*uploaded\//);
                   1677:     my $icon=&Apache::loncommon::icon($url);
                   1678:     my $isfolder=0;
                   1679:     my $ispage=0;
                   1680:     my $folderarg;
                   1681:     my $pagearg;
                   1682:     my $pagefile;
                   1683:     if ($uploaded) {
1.472     raeburn  1684:         if (($extension eq 'sequence') || ($extension eq 'page')) {
                   1685:             $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
                   1686:             my $containerarg = $1;
                   1687: 	    if ($extension eq 'sequence') {
                   1688: 	        $icon=$iconpath.'navmap.folder.closed.gif';
                   1689:                 $folderarg=$containerarg;
                   1690:                 $isfolder=1;
                   1691:             } else {
                   1692:                 $icon=$iconpath.'page.gif';
                   1693:                 $pagearg=$containerarg;
                   1694:                 $ispage=1;
                   1695:             }
                   1696:             if ($allowed) {
                   1697:                 $url='/adm/coursedocs?';
                   1698:             } else {
                   1699:                 $url='/adm/supplemental?';
                   1700:             }
1.329     droeschl 1701: 	} else {
                   1702: 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
                   1703: 	}
                   1704:     }
1.364     bisitz   1705: 
1.329     droeschl 1706:     my $orig_url = $url;
1.340     raeburn  1707:     $orig_url=~s{http(&colon;|:)//https(&colon;|:)//}{https$2//};
1.329     droeschl 1708:     my $external = ($url=~s{^http(|s)(&colon;|:)//}{/adm/wrapper/ext/});
                   1709:     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
                   1710: 	my $symb=&Apache::lonnet::symbclean(
                   1711:           &Apache::lonnet::declutter('uploaded/'.
                   1712:            $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   1713:            $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
                   1714:            '.sequence').
                   1715:            '___'.$residx.'___'.
                   1716: 	   &Apache::lonnet::declutter($url));
                   1717: 	(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
                   1718: 	$url=&Apache::lonnet::clutter($url);
                   1719: 	if ($url=~/^\/*uploaded\//) {
                   1720: 	    $url=~/\.(\w+)$/;
                   1721: 	    my $embstyle=&Apache::loncommon::fileembstyle($1);
                   1722: 	    if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                   1723: 		$url='/adm/wrapper'.$url;
                   1724: 	    } elsif ($embstyle eq 'ssi') {
                   1725: 		#do nothing with these
                   1726: 	    } elsif ($url!~/\.(sequence|page)$/) {
                   1727: 		$url='/adm/coursedocs/showdoc'.$url;
                   1728: 	    }
1.344     bisitz   1729: 	} elsif ($url=~m|^/ext/|) {
1.329     droeschl 1730: 	    $url='/adm/wrapper'.$url;
                   1731: 	    $external = 1;
                   1732: 	}
                   1733:         if (&Apache::lonnet::symbverify($symb,$url)) {
                   1734: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
                   1735:         } else {
                   1736:             $url='';
                   1737:         }
                   1738: 	if ($container eq 'page') {
                   1739: 	    my $symb=$env{'form.pagesymb'};
1.364     bisitz   1740: 
1.329     droeschl 1741: 	    $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   1742: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
                   1743: 	}
                   1744:     }
1.478     raeburn  1745:     my ($rand_pick_text,$rand_order_text);
1.329     droeschl 1746:     if ($isfolder || $extension eq 'sequence') {
                   1747: 	my $foldername=&escape($foldertitle);
                   1748: 	my $folderpath=$env{'form.folderpath'};
                   1749: 	if ($folderpath) { $folderpath.='&' };
1.344     bisitz   1750: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329     droeschl 1751: # so it gets transferred between levels
                   1752: 	$folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
                   1753:                                               'parameter_randompick'))[0]
                   1754:                                                .':'.((&LONCAPA::map::getparameter($orderidx,
                   1755:                                               'parameter_hiddenresource'))[0]=~/^yes$/i)
                   1756:                                                .':'.((&LONCAPA::map::getparameter($orderidx,
                   1757:                                               'parameter_encrypturl'))[0]=~/^yes$/i)
                   1758:                                                .':'.((&LONCAPA::map::getparameter($orderidx,
                   1759:                                               'parameter_randomorder'))[0]=~/^yes$/i);
                   1760: 	$url.='folderpath='.&escape($folderpath).$cpinfo;
1.478     raeburn  1761:         my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
                   1762:                                                    'parameter_randompick'))[0];
                   1763:         my $rpckchk;
                   1764:         if ($rpicknum) {
                   1765:             $rpckchk = ' checked="checked"';
                   1766:         }
                   1767:         my $formname = 'edit_rpick_'.$orderidx;
                   1768: 	$rand_pick_text = 
                   1769: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
                   1770: $form_common."\n".
                   1771: '<span class="LC_nobreak"><label><input type="checkbox" name="randpickon_'.$orderidx.'" id="rpick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="randompick_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" />';
                   1772:         if ($rpicknum ne '') {
                   1773:             $rand_pick_text .= ':&nbsp;<a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
                   1774:         }
                   1775:         $rand_pick_text .= '</span></form>';
1.329     droeschl 1776:     	my $ro_set=
                   1777: 	    ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
1.478     raeburn  1778: 	$rand_order_text = 
                   1779: $form_start.
                   1780: $form_common.'
                   1781: <span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onclick="'."this.form.changeparms.value='randomorder';this.form.submit()".'" '.$ro_set.' /> '.&mt('Random Order').' </label></span></form>';
1.329     droeschl 1782:     }
                   1783:     if ($ispage) {
                   1784:         my $pagename=&escape($pagetitle);
                   1785:         my $pagepath;
                   1786:         my $folderpath=$env{'form.folderpath'};
                   1787:         if ($folderpath) { $pagepath = $folderpath.'&' };
                   1788:         $pagepath.=$pagearg.'&'.$pagename;
                   1789: 	my $symb=$env{'form.pagesymb'};
                   1790: 	if (!$symb) {
                   1791: 	    my $path='uploaded/'.
                   1792: 		$env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   1793: 		$env{'course.'.$env{'request.course.id'}.'.num'}.'/';
                   1794: 	    $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
                   1795: 					       $residx,
                   1796: 					       $path.$pagearg.'.page');
                   1797: 	}
                   1798: 	$url.='pagepath='.&escape($pagepath).
                   1799: 	    '&amp;pagesymb='.&escape($symb).$cpinfo;
                   1800:     }
1.396     raeburn  1801:     if (($external) && ($allowed)) {
1.329     droeschl 1802: 	my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
                   1803: 	$external = '&nbsp;<a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
                   1804:     } else {
                   1805: 	undef($external);
                   1806:     }
1.408     raeburn  1807:     my $reinit;
                   1808:     if ($crstype eq 'Community') {
                   1809:         $reinit = &mt('(re-initialize community to access)');
                   1810:     } else {
                   1811:         $reinit = &mt('(re-initialize course to access)');
                   1812:     }  
1.469     www      1813:     $line.='<td>';
1.472     raeburn  1814:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469     www      1815:        $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
                   1816:     } elsif ($url) {
1.484     raeburn  1817:        $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes',
1.470     raeburn  1818:                                              '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469     www      1819:     } else {
                   1820:        $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
                   1821:     }
                   1822:     $line.='</td><td>';
1.472     raeburn  1823:     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469     www      1824:        $line.='<a href="'.$url.'">'.$title.'</a>';
                   1825:     } elsif ($url) {
1.484     raeburn  1826:        $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes',
1.470     raeburn  1827:                                              $title,600,500);
1.469     www      1828:     } else {
                   1829:        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
                   1830:     }
                   1831:     $line.=$external."</td>";
1.478     raeburn  1832:     $rand_pick_text = '&nbsp;' if ($rand_pick_text eq '');
                   1833:     $rand_order_text = '&nbsp;' if ($rand_order_text eq '');
1.329     droeschl 1834:     if (($allowed) && ($folder!~/^supplemental/)) {
                   1835:  	my %lt=&Apache::lonlocal::texthash(
                   1836:  			      'hd' => 'Hidden',
                   1837:  			      'ec' => 'URL hidden');
                   1838: 	my $enctext=
1.358     bisitz   1839: 	    ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
1.329     droeschl 1840: 	my $hidtext=
1.358     bisitz   1841: 	    ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
1.329     droeschl 1842: 	$line.=(<<ENDPARMS);
                   1843:   <td class="LC_docs_entry_parameter">
                   1844:     $form_start
1.478     raeburn  1845:     $form_common
1.369     bisitz   1846:     <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
1.329     droeschl 1847:     $form_end
1.458     raeburn  1848:     <br />
1.329     droeschl 1849:     $form_start
1.478     raeburn  1850:     $form_common
1.369     bisitz   1851:     <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
1.329     droeschl 1852:     $form_end
                   1853:   </td>
1.478     raeburn  1854:   <td class="LC_docs_entry_parameter">$rand_pick_text<br />
                   1855:                                       $rand_order_text</td>
1.329     droeschl 1856: ENDPARMS
                   1857:     }
1.379     bisitz   1858:     $line.=&Apache::loncommon::end_data_table_row();
1.329     droeschl 1859:     return $line;
                   1860: }
                   1861: 
                   1862: =pod
                   1863: 
                   1864: =item tiehash()
                   1865: 
                   1866: tie the hash
                   1867: 
                   1868: =cut
                   1869: 
                   1870: sub tiehash {
                   1871:     my ($mode)=@_;
                   1872:     $hashtied=0;
                   1873:     if ($env{'request.course.fn'}) {
                   1874: 	if ($mode eq 'write') {
                   1875: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   1876: 		    &GDBM_WRCREAT(),0640)) {
                   1877:                 $hashtied=2;
                   1878: 	    }
                   1879: 	} else {
                   1880: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
                   1881: 		    &GDBM_READER(),0640)) {
                   1882:                 $hashtied=1;
                   1883: 	    }
                   1884: 	}
1.364     bisitz   1885:     }
1.329     droeschl 1886: }
                   1887: 
                   1888: sub untiehash {
                   1889:     if ($hashtied) { untie %hash; }
                   1890:     $hashtied=0;
                   1891:     return OK;
                   1892: }
                   1893: 
                   1894: 
                   1895: 
                   1896: 
                   1897: sub checkonthis {
                   1898:     my ($r,$url,$level,$title)=@_;
                   1899:     $url=&unescape($url);
                   1900:     $alreadyseen{$url}=1;
                   1901:     $r->rflush();
                   1902:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
                   1903:        $r->print("\n<br />");
                   1904:        if ($level==0) {
                   1905:            $r->print("<br />");
                   1906:        }
                   1907:        for (my $i=0;$i<=$level*5;$i++) {
                   1908:            $r->print('&nbsp;');
                   1909:        }
                   1910:        $r->print('<a href="'.$url.'" target="cat">'.
                   1911: 		 ($title?$title:$url).'</a> ');
                   1912:        if ($url=~/^\/res\//) {
                   1913: 	  my $result=&Apache::lonnet::repcopy(
                   1914:                               &Apache::lonnet::filelocation('',$url));
                   1915:           if ($result eq 'ok') {
                   1916:              $r->print('<span class="LC_success">'.&mt('ok').'</span>');
                   1917:              $r->rflush();
                   1918:              &Apache::lonnet::countacc($url);
                   1919:              $url=~/\.(\w+)$/;
                   1920:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                   1921: 		 $r->print('<br />');
                   1922:                  $r->rflush();
                   1923:                  for (my $i=0;$i<=$level*5;$i++) {
                   1924:                      $r->print('&nbsp;');
                   1925:                  }
                   1926:                  $r->print('- '.&mt('Rendering:').' ');
                   1927: 		 my ($errorcount,$warningcount)=split(/:/,
                   1928: 	       &Apache::lonnet::ssi_body($url,
                   1929: 			       ('grade_target'=>'web',
                   1930: 				'return_only_error_and_warning_counts' => 1)));
                   1931:                  if (($errorcount) ||
                   1932:                      ($warningcount)) {
                   1933: 		     if ($errorcount) {
1.369     bisitz   1934:                         $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329     droeschl 1935:                           &mt('[quant,_1,error]',$errorcount).'</span>');
                   1936:                      }
                   1937: 		     if ($warningcount) {
                   1938:                         $r->print('<span class="LC_warning">'.
                   1939:                           &mt('[quant,_1,warning]',$warningcount).'</span>');
                   1940:                      }
                   1941:                  } else {
                   1942:                      $r->print('<span class="LC_success">'.&mt('ok').'</span>');
                   1943:                  }
                   1944:                  $r->rflush();
                   1945:              }
                   1946: 	     my $dependencies=
                   1947:                 &Apache::lonnet::metadata($url,'dependencies');
                   1948:              foreach my $dep (split(/\,/,$dependencies)) {
                   1949: 		 if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
                   1950:                     &checkonthis($r,$dep,$level+1);
                   1951:                  }
                   1952:              }
                   1953:           } elsif ($result eq 'unavailable') {
                   1954:              $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
                   1955:           } elsif ($result eq 'not_found') {
                   1956: 	      unless ($url=~/\$/) {
                   1957: 		  $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
                   1958: 	      } else {
1.366     bisitz   1959: 		  $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329     droeschl 1960: 	      }
                   1961:           } else {
                   1962:              $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
                   1963:           }
                   1964:        }
                   1965:     }
                   1966: }
                   1967: 
                   1968: 
                   1969: 
                   1970: =pod
                   1971: 
                   1972: =item list_symbs()
                   1973: 
1.485     raeburn  1974: List Content Identifiers
1.329     droeschl 1975: 
                   1976: =cut
                   1977: 
                   1978: sub list_symbs {
                   1979:     my ($r) = @_;
                   1980: 
1.408     raeburn  1981:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  1982:     $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
                   1983:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
                   1984:     $r->print(&startContentScreen('tools'));
1.329     droeschl 1985:     my $navmap = Apache::lonnavmaps::navmap->new();
                   1986:     if (!defined($navmap)) {
                   1987:         $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
                   1988:                   '<div class="LC_error">'.
                   1989:                   &mt('Unable to retrieve information about course contents').
                   1990:                   '</div>');
1.408     raeburn  1991:         &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329     droeschl 1992:     } else {
1.484     raeburn  1993:         $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
                   1994:                   &Apache::loncommon::start_data_table().
                   1995:                   &Apache::loncommon::start_data_table_header_row().
                   1996:                   '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
                   1997:                   &Apache::loncommon::end_data_table_header_row()."\n");
                   1998:         my $count;
1.329     droeschl 1999:         foreach my $res ($navmap->retrieveResources()) {
1.484     raeburn  2000:             $r->print(&Apache::loncommon::start_data_table_row().
                   2001:                       '<td>'.$res->compTitle().'</td>'.
                   2002:                       '<td>'.$res->symb().'</td>'.
                   2003:                       &Apache::loncommon::start_data_table_row());
                   2004:             $count ++;
                   2005:         }
                   2006:         if (!$count) {
                   2007:             $r->print(&Apache::loncommon::start_data_table_row().
                   2008:                       '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
                   2009:                       &Apache::loncommon::end_data_table_row()); 
1.329     droeschl 2010:         }
1.484     raeburn  2011:         $r->print(&Apache::loncommon::end_data_table());
1.329     droeschl 2012:     }
                   2013: }
                   2014: 
                   2015: 
                   2016: sub verifycontent {
                   2017:     my ($r) = @_;
1.408     raeburn  2018:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  2019:     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
                   2020:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
                   2021:     $r->print(&startContentScreen('tools'));
                   2022:     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>'); 
1.329     droeschl 2023:    $hashtied=0;
                   2024:    undef %alreadyseen;
                   2025:    %alreadyseen=();
                   2026:    &tiehash();
1.484     raeburn  2027:    
1.329     droeschl 2028:    foreach my $key (keys(%hash)) {
                   2029:        if ($hash{$key}=~/\.(page|sequence)$/) {
                   2030: 	   if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
                   2031: 	       $r->print('<hr /><span class="LC_error">'.
1.419     bisitz   2032: 			 &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329     droeschl 2033: 			 &unescape($hash{$key}).'</span><br />'.
1.419     bisitz   2034: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329     droeschl 2035: 	   }
                   2036:        }
                   2037:        if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
                   2038:            &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
                   2039:        }
                   2040:    }
                   2041:    &untiehash();
1.442     www      2042:    $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.329     droeschl 2043: }
                   2044: 
                   2045: 
                   2046: sub devalidateversioncache {
                   2047:     my $src=shift;
                   2048:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
                   2049: 					  &Apache::lonnet::clutter($src));
                   2050: }
                   2051: 
                   2052: sub checkversions {
                   2053:     my ($r) = @_;
1.408     raeburn  2054:     my $crstype = &Apache::loncommon::course_type();
                   2055:     $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
                   2056:     $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
1.484     raeburn  2057:     $r->print(&startContentScreen('tools'));
1.442     www      2058: 
1.329     droeschl 2059:     my $header='';
                   2060:     my $startsel='';
                   2061:     my $monthsel='';
                   2062:     my $weeksel='';
                   2063:     my $daysel='';
                   2064:     my $allsel='';
                   2065:     my %changes=();
                   2066:     my $starttime=0;
                   2067:     my $haschanged=0;
                   2068:     my %setversions=&Apache::lonnet::dump('resourceversions',
                   2069: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   2070: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   2071: 
                   2072:     $hashtied=0;
                   2073:     &tiehash();
                   2074:     my %newsetversions=();
                   2075:     if ($env{'form.setmostrecent'}) {
                   2076: 	$haschanged=1;
                   2077: 	foreach my $key (keys(%hash)) {
                   2078: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   2079: 		$newsetversions{$1}='mostrecent';
                   2080:                 &devalidateversioncache($1);
                   2081: 	    }
                   2082: 	}
                   2083:     } elsif ($env{'form.setcurrent'}) {
                   2084: 	$haschanged=1;
                   2085: 	foreach my $key (keys(%hash)) {
                   2086: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   2087: 		my $getvers=&Apache::lonnet::getversion($1);
                   2088: 		if ($getvers>0) {
                   2089: 		    $newsetversions{$1}=$getvers;
                   2090: 		    &devalidateversioncache($1);
                   2091: 		}
                   2092: 	    }
                   2093: 	}
                   2094:     } elsif ($env{'form.setversions'}) {
                   2095: 	$haschanged=1;
                   2096: 	foreach my $key (keys(%env)) {
                   2097: 	    if ($key=~/^form\.set_version_(.+)$/) {
                   2098: 		my $src=$1;
                   2099: 		if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
                   2100: 		    $newsetversions{$src}=$env{$key};
                   2101: 		    &devalidateversioncache($src);
                   2102: 		}
                   2103: 	    }
                   2104: 	}
                   2105:     }
                   2106:     if ($haschanged) {
                   2107:         if (&Apache::lonnet::put('resourceversions',\%newsetversions,
                   2108: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344     bisitz   2109: 			  $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.479     golterma 2110: 	    $r->print(&Apache::loncommon::confirmwrapper(
                   2111:                 &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1.329     droeschl 2112: 	} else {
1.479     golterma 2113: 	    $r->print(&Apache::loncommon::confirmwrapper(
                   2114:                 &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329     droeschl 2115: 	}
                   2116: 	&mark_hash_old();
                   2117:     }
                   2118:     &changewarning($r,'');
                   2119:     if ($env{'form.timerange'} eq 'all') {
                   2120: # show all documents
1.408     raeburn  2121: 	$header=&mt('All Documents in '.$crstype);
1.329     droeschl 2122: 	$allsel=1;
                   2123: 	foreach my $key (keys(%hash)) {
                   2124: 	    if ($key=~/^ids\_(\/res\/.+)$/) {
                   2125: 		my $src=$1;
                   2126: 		$changes{$src}=1;
                   2127: 	    }
                   2128: 	}
                   2129:     } else {
                   2130: # show documents which changed
                   2131: 	%changes=&Apache::lonnet::dump
                   2132: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
                   2133:                      $env{'course.'.$env{'request.course.id'}.'.num'});
                   2134: 	my $firstkey=(keys(%changes))[0];
                   2135: 	unless ($firstkey=~/^error\:/) {
                   2136: 	    unless ($env{'form.timerange'}) {
                   2137: 		$env{'form.timerange'}=604800;
                   2138: 	    }
                   2139: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
                   2140: 		.&mt('seconds');
                   2141: 	    if ($env{'form.timerange'}==-1) {
                   2142: 		$seltext='since start of course';
                   2143: 		$startsel='selected';
                   2144: 		$env{'form.timerange'}=time;
                   2145: 	    }
                   2146: 	    $starttime=time-$env{'form.timerange'};
                   2147: 	    if ($env{'form.timerange'}==2592000) {
                   2148: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   2149: 		$monthsel='selected';
                   2150: 	    } elsif ($env{'form.timerange'}==604800) {
                   2151: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   2152: 		$weeksel='selected';
                   2153: 	    } elsif ($env{'form.timerange'}==86400) {
                   2154: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   2155: 		$daysel='selected';
                   2156: 	    }
                   2157: 	    $header=&mt('Content changed').' '.$seltext;
                   2158: 	} else {
                   2159: 	    $header=&mt('No content modifications yet.');
                   2160: 	}
                   2161:     }
                   2162:     %setversions=&Apache::lonnet::dump('resourceversions',
                   2163: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   2164: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
                   2165:     my %lt=&Apache::lonlocal::texthash
1.408     raeburn  2166: 	      ('st' => 'Version changes since start of '.$crstype,
1.329     droeschl 2167: 	       'lm' => 'Version changes since last Month',
                   2168: 	       'lw' => 'Version changes since last Week',
                   2169: 	       'sy' => 'Version changes since Yesterday',
                   2170:                'al' => 'All Resources (possibly large output)',
1.484     raeburn  2171:                'cd' => 'Change display', 
1.329     droeschl 2172: 	       'sd' => 'Display',
                   2173: 	       'fi' => 'File',
                   2174: 	       'md' => 'Modification Date',
                   2175:                'mr' => 'Most recently published Version',
1.408     raeburn  2176: 	       've' => 'Version used in '.$crstype,
                   2177:                'vu' => 'Set Version to be used in '.$crstype,
                   2178: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329     droeschl 2179: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                   2180: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479     golterma 2181: 	       'di' => 'Differences',
1.484     raeburn  2182: 	       'save' => 'Save changes',
                   2183:                'vers' => 'Version choice(s) for specific resources', 
1.479     golterma 2184: 	       'act' => 'Actions');
1.329     droeschl 2185:     $r->print(<<ENDHEADERS);
1.484     raeburn  2186: <h4 class="LC_info">$header</h4>
1.329     droeschl 2187: <form action="/adm/coursedocs" method="post">
                   2188: <input type="hidden" name="versions" value="1" />
1.484     raeburn  2189: <div class="LC_left_float">
1.479     golterma 2190: <fieldset>
1.484     raeburn  2191: <legend>$lt{'cd'}</legend>
1.329     droeschl 2192: <select name="timerange">
                   2193: <option value='all' $allsel>$lt{'al'}</option>
                   2194: <option value="-1" $startsel>$lt{'st'}</option>
                   2195: <option value="2592000" $monthsel>$lt{'lm'}</option>
                   2196: <option value="604800" $weeksel>$lt{'lw'}</option>
                   2197: <option value="86400" $daysel>$lt{'sy'}</option>
                   2198: </select>
                   2199: <input type="submit" name="display" value="$lt{'sd'}" />
1.484     raeburn  2200: </fieldset>
                   2201: </div>
                   2202: <div class="LC_left_float">
                   2203: <fieldset>
                   2204: <legend>$lt{'act'}</legend>
                   2205: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
                   2206: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
                   2207: </fieldset>
                   2208: </div>
                   2209: <br clear="all" />
                   2210: <hr />
                   2211: <h4>$lt{'vers'}</h4>
1.479     golterma 2212: <input type="submit" name="setversions" value="$lt{'save'}" />
1.329     droeschl 2213: <table border="0">
                   2214: ENDHEADERS
1.479     golterma 2215:     #number of columns for version history
                   2216:     my $num_ver_col = 1;
                   2217:     $r->print(
                   2218:     &Apache::loncommon::start_data_table().
                   2219:     &Apache::loncommon::start_data_table_header_row().
                   2220:     '<th>'.&mt('Resources').'</th>'.
                   2221:     "<th>$lt{'mr'}</th>".
                   2222:     "<th>$lt{'ve'}</th>".
                   2223:     "<th>$lt{'vu'}</th>".
                   2224:     '<th colspan="'.$num_ver_col.'">'.&mt('History').'</th>'.
                   2225:     '</b>');
1.329     droeschl 2226:     foreach my $key (sort(keys(%changes))) {
                   2227: 	if ($changes{$key}>$starttime) {
                   2228: 	    my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
                   2229: 	    my $currentversion=&Apache::lonnet::getversion($key);
                   2230: 	    if ($currentversion<0) {
1.479     golterma 2231:                 $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
1.329     droeschl 2232: 	    }
                   2233: 	    my $linkurl=&Apache::lonnet::clutter($key);
1.479     golterma 2234:         $r->print(
                   2235:             &Apache::loncommon::end_data_table_header_row().
                   2236:             &Apache::loncommon::start_data_table_row().
                   2237:             '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br>'.
                   2238:             '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
                   2239:             '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br>('.
                   2240:             &Apache::lonlocal::locallocaltime(&Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate')).')</span></td>'.
                   2241:             '<td align="right">');
1.329     droeschl 2242: # Used in course
                   2243: 	    my $usedversion=$hash{'version_'.$linkurl};
                   2244: 	    if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.479     golterma 2245:                 if($usedversion != $currentversion){
                   2246:                     $r->print('<span class="LC_warning">'.$usedversion.'</span>');
                   2247:                 }else{
                   2248:                     $r->print($usedversion);
                   2249:                 }
1.329     droeschl 2250: 	    } else {
                   2251: 		$r->print($currentversion);
                   2252: 	    }
1.479     golterma 2253: 	    $r->print('</td><td title="'.$lt{'vu'}.'">');
1.329     droeschl 2254: # Set version
                   2255: 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
                   2256: 						      'set_version_'.$linkurl,
1.428     raeburn  2257: 						      {'select_form_order' =>
1.329     droeschl 2258: 						       ['',1..$currentversion,'mostrecent'],
                   2259: 						       '' => '',
1.411     bisitz   2260: 						       'mostrecent' => &mt('most recent'),
1.428     raeburn  2261: 						       map {$_,$_} (1..$currentversion)}));
1.329     droeschl 2262: 	    my $lastold=1;
                   2263: 	    for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                   2264: 		my $url=$root.'.'.$prevvers.'.'.$extension;
                   2265: 		if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
                   2266: 		    $starttime) {
                   2267: 		    $lastold=$prevvers;
                   2268: 		}
                   2269: 	    }
1.364     bisitz   2270:             #
1.329     droeschl 2271:             # Code to figure out how many version entries should go in
                   2272:             # each of the four columns
                   2273:             my $entries_per_col = 0;
                   2274:             my $num_entries = ($currentversion-$lastold);
1.479     golterma 2275:             if ($num_entries % $num_ver_col == 0) {
                   2276:                 $entries_per_col = $num_entries/$num_ver_col;
1.329     droeschl 2277:             } else {
1.479     golterma 2278:                 $entries_per_col = $num_entries/$num_ver_col + 1;
1.329     droeschl 2279:             }
                   2280:             my $entries_count = 0;
1.479     golterma 2281:             $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1.329     droeschl 2282:             my $cols_output = 1;
                   2283:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
                   2284: 		my $url=$root.'.'.$prevvers.'.'.$extension;
                   2285: 		$r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
                   2286: 			  '">'.&mt('Version').' '.$prevvers.'</a> ('.
                   2287: 			  &Apache::lonlocal::locallocaltime(
                   2288:                                 &Apache::lonnet::metadata($url,
                   2289:                                                           'lastrevisiondate')
                   2290:                                                             ).
                   2291: 			  ')');
                   2292: 		if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
                   2293:                     $r->print(' <a href="/adm/diff?filename='.
                   2294: 			      &Apache::lonnet::clutter($root.'.'.$extension).
                   2295: 			      '&versionone='.$prevvers.
1.462     raeburn  2296: 			      '" target="diffs">'.&mt('Diffs').'</a>');
1.329     droeschl 2297: 		}
                   2298: 		$r->print('</span><br />');
                   2299:                 if (++$entries_count % $entries_per_col == 0) {
1.479     golterma 2300:                     $r->print('</span></td>');
                   2301:                     if ($cols_output != $num_ver_col) {
                   2302:                         $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1.329     droeschl 2303:                         $cols_output++;
                   2304:                     }
                   2305:                 }
                   2306: 	    }
1.479     golterma 2307:             while($cols_output++ < $num_ver_col) {
                   2308:                 $r->print('</span></td><td>');
1.329     droeschl 2309:             }
                   2310: 	}
                   2311:     }
1.479     golterma 2312:     $r->print('</td>'.&Apache::loncommon::end_data_table_row().
                   2313:             &Apache::loncommon::end_data_table().
                   2314:             '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />');
1.329     droeschl 2315: 
                   2316:     &untiehash();
                   2317: }
                   2318: 
                   2319: sub mark_hash_old {
                   2320:     my $retie_hash=0;
                   2321:     if ($hashtied) {
                   2322: 	$retie_hash=1;
                   2323: 	&untiehash();
                   2324:     }
                   2325:     &tiehash('write');
                   2326:     $hash{'old'}=1;
                   2327:     &untiehash();
                   2328:     if ($retie_hash) { &tiehash(); }
                   2329: }
                   2330: 
                   2331: sub is_hash_old {
                   2332:     my $untie_hash=0;
                   2333:     if (!$hashtied) {
                   2334: 	$untie_hash=1;
                   2335: 	&tiehash();
                   2336:     }
                   2337:     my $return=$hash{'old'};
                   2338:     if ($untie_hash) { &untiehash(); }
                   2339:     return $return;
                   2340: }
                   2341: 
                   2342: sub changewarning {
                   2343:     my ($r,$postexec,$message,$url)=@_;
                   2344:     if (!&is_hash_old()) { return; }
                   2345:     my $pathvar='folderpath';
                   2346:     my $path=&escape($env{'form.folderpath'});
                   2347:     if (!defined($url)) {
                   2348: 	if (defined($env{'form.pagepath'})) {
                   2349: 	    $pathvar='pagepath';
                   2350: 	    $path=&escape($env{'form.pagepath'});
                   2351: 	    $path.='&amp;pagesymb='.&escape($env{'form.pagesymb'});
                   2352: 	}
                   2353: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
                   2354:     }
                   2355:     my $course_type = &Apache::loncommon::course_type();
                   2356:     if (!defined($message)) {
                   2357: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
                   2358:     }
                   2359:     $r->print("\n\n".
1.372     bisitz   2360: '<script type="text/javascript">'."\n".
                   2361: '// <![CDATA['."\n".
                   2362: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
                   2363: '// ]]>'."\n".
1.369     bisitz   2364: '</script>'."\n".
1.375     tempelho 2365: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329     droeschl 2366: '<input type="hidden" name="orgurl" value="'.$url.
1.372     bisitz   2367: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329     droeschl 2368: &mt($message,' <input type="hidden" name="'.
                   2369:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369     bisitz   2370:     &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372     bisitz   2371: $help{'Caching'}.'</p></form>'."\n\n");
1.329     droeschl 2372: }
                   2373: 
                   2374: 
                   2375: sub init_breadcrumbs {
                   2376:     my ($form,$text)=@_;
                   2377:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484     raeburn  2378:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405     bisitz   2379: 					    text=>&Apache::loncommon::course_type().' Editor',
1.329     droeschl 2380: 					    faq=>273,
                   2381: 					    bug=>'Instructor Interface',
                   2382:                                             help => 'Docs_Adding_Course_Doc'});
                   2383:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
                   2384: 					    text=>$text,
                   2385: 					    faq=>273,
                   2386: 					    bug=>'Instructor Interface'});
                   2387: }
                   2388: 
1.441     www      2389: # subroutine to list form elements
                   2390: sub create_list_elements {
                   2391:    my @formarr = @_;
                   2392:    my $list = '';
                   2393:    for my $button (@formarr){
                   2394:         for my $picture(keys %$button) {
                   2395:             $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
                   2396:         }
                   2397:    }
                   2398:    return $list;
                   2399: }
1.329     droeschl 2400: 
1.441     www      2401: # subroutine to create ul from list elements
                   2402: sub create_form_ul {
                   2403:    my $list = shift;
                   2404:    my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
                   2405:    return $ul;
                   2406: }
1.329     droeschl 2407: 
1.442     www      2408: #
                   2409: # Start tabs
                   2410: #
                   2411: 
                   2412: sub startContentScreen {
1.484     raeburn  2413:     my ($mode) = @_;
                   2414:     my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472     raeburn  2415:     if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484     raeburn  2416:         $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";
                   2417:         $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";
                   2418:         $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";
                   2419:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
                   2420:     } else {
                   2421:         $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Content Editor').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>'."\n";
                   2422:         $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
                   2423:         $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";
                   2424:                    '><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>';
                   2425:     }
                   2426:     $output .= "\n".'</ul>'."\n";
                   2427:     $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
                   2428:                '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
                   2429:                '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
                   2430:     return $output;
1.442     www      2431: }
                   2432: 
                   2433: #
                   2434: # End tabs
                   2435: #
                   2436: 
                   2437: sub endContentScreen {
1.484     raeburn  2438:     return '</div></div></div>';
1.442     www      2439: }
1.329     droeschl 2440: 
1.446     www      2441: sub supplemental_base {
1.472     raeburn  2442:     return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
1.446     www      2443: }
                   2444: 
1.329     droeschl 2445: sub handler {
                   2446:     my $r = shift;
                   2447:     &Apache::loncommon::content_type($r,'text/html');
                   2448:     $r->send_http_header;
                   2449:     return OK if $r->header_only;
1.484     raeburn  2450: 
                   2451: # get course data
1.408     raeburn  2452:     my $crstype = &Apache::loncommon::course_type();
1.484     raeburn  2453:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   2454:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   2455: 
                   2456: # graphics settings
                   2457:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329     droeschl 2458: 
1.443     www      2459: #
1.329     droeschl 2460: # --------------------------------------------- Initialize help topics for this
                   2461:     foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
                   2462: 	               'Adding_External_Resource','Navigate_Content',
                   2463: 	               'Adding_Folders','Docs_Overview', 'Load_Map',
                   2464: 	               'Supplemental','Score_Upload_Form','Adding_Pages',
                   2465: 	               'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
                   2466: 	               'Check_Resource_Versions','Verify_Content') {
                   2467: 	$help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
                   2468:     }
                   2469:     # Composite help files
                   2470:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   2471: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   2472:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   2473: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
                   2474:     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
                   2475: 		    'Option_Response_Simple');
                   2476:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   2477: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347     weissno  2478:     $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329     droeschl 2479: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353     weissno  2480:     $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329     droeschl 2481:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
                   2482: 
1.472     raeburn  2483:     
                   2484:     my $allowed;
                   2485: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
                   2486:     unless ($r->uri eq '/adm/supplemental') {
                   2487:         # does this user have privileges to modify content.  
                   2488:         $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                   2489:     }
                   2490: 
1.484     raeburn  2491:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
                   2492:                                             'inhibitmenu']);
                   2493:   if ($allowed && $env{'form.chooseserver'}) {
                   2494:       &choose_dump_server($r);
                   2495:       return OK;
                   2496:   } elsif ($allowed && $env{'form.verify'}) {
1.329     droeschl 2497:       &init_breadcrumbs('verify','Verify Content');
                   2498:       &verifycontent($r);
                   2499:   } elsif ($allowed && $env{'form.listsymbs'}) {
1.484     raeburn  2500:       &init_breadcrumbs('listsymbs','List Content IDs');
1.329     droeschl 2501:       &list_symbs($r);
                   2502:   } elsif ($allowed && $env{'form.docslog'}) {
                   2503:       &init_breadcrumbs('docslog','Show Log');
1.484     raeburn  2504:       my $folder = $env{'form.folder'};
                   2505:       if ($folder eq '') {
                   2506:           $folder='default';
                   2507:       }
                   2508:       &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329     droeschl 2509:   } elsif ($allowed && $env{'form.versions'}) {
                   2510:       &init_breadcrumbs('versions','Check/Set Resource Versions');
                   2511:       &checkversions($r);
                   2512:   } elsif ($allowed && $env{'form.dumpcourse'}) {
1.484     raeburn  2513:       &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329     droeschl 2514:       &dumpcourse($r);
                   2515:   } elsif ($allowed && $env{'form.exportcourse'}) {
1.377     bisitz   2516:       &init_breadcrumbs('exportcourse','IMS Export');
1.475     raeburn  2517:       &Apache::imsexport::exportcourse($r);
1.329     droeschl 2518:   } else {
1.445     www      2519: #
                   2520: # Done catching special calls
1.484     raeburn  2521: # The whole rest is for course and supplemental documents and utilities menu
1.445     www      2522: # Get the parameters that may be needed
                   2523: #
                   2524:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                   2525:                                             ['folderpath','pagepath',
1.466     www      2526:                                              'pagesymb','forcesupplement','forcestandard',
1.484     raeburn  2527:                                              'tools','symb','command']);
1.445     www      2528: 
                   2529: # standard=1: this is a "new-style" course with an uploaded map as top level
                   2530: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329     droeschl 2531: 
                   2532:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445     www      2533: 
1.484     raeburn  2534: # Decide whether this should display supplemental or main content or utilities
1.445     www      2535: # supplementalflag=1: show supplemental documents
                   2536: # supplementalflag=0: show standard documents
1.484     raeburn  2537: # toolsflag=1: show utilities
1.445     www      2538: 
                   2539: 
                   2540:     my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
                   2541:     if (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'} eq "" || ($env{'form.pagepath'})) {
                   2542:        $supplementalflag=0;
                   2543:     }
                   2544:     if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
                   2545:     if ($env{'form.forcestandard'})   { $supplementalflag=0; }
                   2546:     unless ($allowed) { $supplementalflag=1; }
                   2547:     unless ($standard) { $supplementalflag=1; }
1.484     raeburn  2548:     my $toolsflag=0;
                   2549:     if ($env{'form.tools'}) { $toolsflag=1; }
1.445     www      2550: 
1.329     droeschl 2551:     my $script='';
                   2552:     my $showdoc=0;
1.457     raeburn  2553:     my $addentries = {};
1.475     raeburn  2554:     my $container;
1.329     droeschl 2555:     my $containertag;
                   2556:     my $uploadtag;
                   2557: 
1.464     www      2558: # Do we directly jump somewhere?
1.466     www      2559: 
1.464     www      2560:    if ($env{'form.command'} eq 'direct') {
1.468     raeburn  2561:        my ($mapurl,$id,$resurl);
1.472     raeburn  2562:        if ($env{'form.symb'} ne '') {
1.468     raeburn  2563:            ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   2564:            if ($resurl=~/\.(sequence|page)$/) {
                   2565:                $mapurl=$resurl;
                   2566:            } elsif ($resurl eq 'adm/navmaps') {
                   2567:                $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
                   2568:            }
1.472     raeburn  2569:            my $mapresobj;
                   2570:            my $navmap = Apache::lonnavmaps::navmap->new();
                   2571:            if (ref($navmap)) {
                   2572:                $mapresobj = $navmap->getResourceByUrl($mapurl);
                   2573:            }
                   2574:            $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
                   2575:            my $type=$2;
                   2576:            my $path;
                   2577:            if (ref($mapresobj)) {
                   2578:                my $pcslist = $mapresobj->map_hierarchy();
                   2579:                if ($pcslist ne '') {
                   2580:                    foreach my $pc (split(/,/,$pcslist)) {
                   2581:                        next if ($pc <= 1);
                   2582:                        my $res = $navmap->getByMapPc($pc);
                   2583:                        if (ref($res)) {
                   2584:                            my $thisurl = $res->src();
                   2585:                            $thisurl=~s{^.*/([^/]+)\.\w+$}{$1}; 
                   2586:                            my $thistitle = $res->title();
                   2587:                            $path .= '&'.
                   2588:                                     &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
                   2589:                                     &Apache::lonhtmlcommon::entity_encode($thistitle).
                   2590:                                     ':'.$res->randompick().
                   2591:                                     ':'.$res->randomout().
                   2592:                                     ':'.$res->encrypted().
                   2593:                                     ':'.$res->randomorder();
                   2594:                        }
1.467     raeburn  2595:                    }
                   2596:                }
1.472     raeburn  2597:                $path .= '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.467     raeburn  2598:                     &Apache::lonhtmlcommon::entity_encode($mapresobj->title()).
                   2599:                     ':'.$mapresobj->randompick().
                   2600:                     ':'.$mapresobj->randomout().
                   2601:                     ':'.$mapresobj->encrypted().
                   2602:                     ':'.$mapresobj->randomorder();
1.472     raeburn  2603:            } else {
                   2604:                my $maptitle = &Apache::lonnet::gettitle($mapurl);
                   2605:                $path = '&default&...::::'.
                   2606:                    '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
                   2607:                    &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
                   2608:            }
                   2609:            $path = 'default&'.
                   2610:                    &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
                   2611:                    $path;
                   2612:            if ($type eq 'sequence') {
                   2613:                $env{'form.folderpath'}=$path;
                   2614:                $env{'form.pagepath'}='';
                   2615:            } else {
                   2616:                $env{'form.pagepath'}=$path;
                   2617:                $env{'form.folderpath'}='';
                   2618:            }
                   2619:        } elsif ($env{'form.supppath'} ne '') {
                   2620:            $env{'form.folderpath'}=$env{'form.supppath'};
1.466     www      2621:        }
1.472     raeburn  2622:    } elsif ($env{'form.command'} eq 'editdocs') {
                   2623:         $env{'form.folderpath'} = 'default&'.
                   2624:                                   &Apache::lonhtmlcommon::entity_encode('Main Course Content');
                   2625:         $env{'form.pagepath'}='';
                   2626:    } elsif ($env{'form.command'} eq 'editsupp') {
                   2627:         $env{'form.folderpath'} = 'default&'.
                   2628:                                   &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
                   2629:         $env{'form.pagepath'}='';
1.464     www      2630:    }
                   2631: 
1.445     www      2632: # Where do we store these for when we come back?
                   2633:     my $stored_folderpath='docs_folderpath';
                   2634:     if ($supplementalflag) {
                   2635:        $stored_folderpath='docs_sup_folderpath';
                   2636:     }
1.464     www      2637: 
1.329     droeschl 2638: # No folderpath, no pagepath, see if we have something stored
                   2639:     if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
1.445     www      2640:         &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329     droeschl 2641:                                               {'folderpath' => 'scalar'});
                   2642:     }
1.446     www      2643:    
                   2644: # If we are not allowed to make changes, all we can see are supplemental docs
1.409     raeburn  2645:     if (!$allowed) {
1.446     www      2646:         $env{'form.pagepath'}='';
                   2647:         unless ($env{'form.folderpath'} =~ /^supplemental/) {
                   2648:             $env{'form.folderpath'} = &supplemental_base();
1.409     raeburn  2649:         }
                   2650:     }
1.446     www      2651: # If we still not have a folderpath, see if we can resurrect at pagepath
1.409     raeburn  2652:     if (!$env{'form.folderpath'} && $allowed) {
1.445     www      2653:         &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329     droeschl 2654:                                               {'pagepath' => 'scalar'});
                   2655:     }
1.446     www      2656: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329     droeschl 2657:     if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446     www      2658:         $env{'form.folderpath'} = &supplemental_base()
                   2659:                                   .'&'.
1.329     droeschl 2660:                                   $env{'form.folderpath'};
                   2661:     }
1.446     www      2662: # If after all of this, we still don't have any paths, make them
                   2663:     unless (($env{'form.pagepath'}) || ($env{'form.folderpath'})) {
                   2664:        if ($supplementalflag) {
                   2665:           $env{'form.folderpath'}=&supplemental_base();
                   2666:        } else {
                   2667:           $env{'form.folderpath'}='default';
                   2668:        }
1.472     raeburn  2669:     }
1.446     www      2670: 
1.445     www      2671: # Store this
1.484     raeburn  2672:     unless ($toolsflag) {
                   2673:         &Apache::loncommon::store_course_settings($stored_folderpath,
                   2674:                                                   {'pagepath' => 'scalar',
                   2675:                                                    'folderpath' => 'scalar'});
                   2676:         if ($env{'form.folderpath'}) {
                   2677: 	    my (@folderpath)=split('&',$env{'form.folderpath'});
                   2678: 	    $env{'form.foldername'}=&unescape(pop(@folderpath));
                   2679: 	    $env{'form.folder'}=pop(@folderpath);
                   2680:             $container='sequence';
                   2681:         }
                   2682:         if ($env{'form.pagepath'}) {
                   2683:             my (@pagepath)=split('&',$env{'form.pagepath'});
                   2684:             $env{'form.pagename'}=&unescape(pop(@pagepath));
                   2685:             $env{'form.folder'}=pop(@pagepath);
                   2686:             $container='page';
                   2687:             $containertag = '<input type="hidden" name="pagepath" value="" />'.
                   2688: 	                    '<input type="hidden" name="pagesymb" value="" />';
                   2689:             $uploadtag = 
                   2690:                 '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
                   2691: 	        '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />'.
                   2692:                 '<input type="hidden" name="folderpath" value="" />';
                   2693:         } else {
                   2694:             my $folderpath=$env{'form.folderpath'};
                   2695:             if (!$folderpath) {
                   2696:                 if ($env{'form.folder'} eq '' ||
                   2697:                     $env{'form.folder'} eq 'supplemental') {
                   2698:                     $folderpath='default&'.
                   2699:                         &escape(&mt('Main '.$crstype.' Documents'));
                   2700:                 }
                   2701:             }
                   2702:             $containertag = '<input type="hidden" name="folderpath" value="" />';
                   2703:             $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
                   2704:         }
                   2705:         if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
                   2706:            $showdoc='/'.$1;
                   2707:         }
                   2708:         if ($showdoc) { # got called in sequence from course
                   2709: 	    $allowed=0; 
                   2710:         } else {
                   2711:             if ($allowed) {
                   2712:                 &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   2713:                 $script=&Apache::lonratedt::editscript('simple');
1.433     raeburn  2714:             }
                   2715:         }
1.329     droeschl 2716:     }
                   2717: 
1.344     bisitz   2718: # get personal data
1.329     droeschl 2719:     my $uname=$env{'user.name'};
                   2720:     my $udom=$env{'user.domain'};
                   2721:     my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
                   2722: 
                   2723:     if ($allowed) {
1.484     raeburn  2724:         if ($toolsflag) {
                   2725:             $script .= &inject_data_js();
                   2726:             my ($home,$other,%outhash)=&authorhosts();
                   2727:             if (!$home && $other) {
                   2728:                 my @hosts;
                   2729:                 foreach my $aurole (keys(%outhash)) {
                   2730:                     unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   2731:                         push(@hosts,$outhash{$aurole});
                   2732:                     }
                   2733:                 }
                   2734:                 $script .= &dump_switchserver_js(@hosts); 
                   2735:             }
1.458     raeburn  2736:         } else {
1.484     raeburn  2737:             my @tabids;
                   2738:             if ($supplementalflag) {
                   2739:                 @tabids = ('002','ee2','ff2');
                   2740:             } else {
                   2741:                 @tabids = ('aa1','bb1','cc1','ff1');
                   2742:                 unless ($env{'form.pagepath'}) {
                   2743:                     unshift(@tabids,'001');
                   2744:                     push(@tabids,('dd1','ee1'));
                   2745:                 }
1.458     raeburn  2746:             }
1.484     raeburn  2747:             my $tabidstr = join("','",@tabids);
                   2748: 	    $script .= &editing_js($udom,$uname,$supplementalflag).
                   2749:                        &history_tab_js().
                   2750:                        &inject_data_js().
1.485     raeburn  2751:                        &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr);
1.484     raeburn  2752:             $addentries = {
1.485     raeburn  2753:                             onload   => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484     raeburn  2754:                           };
1.458     raeburn  2755:         }
1.329     droeschl 2756:     }
                   2757: # -------------------------------------------------------------------- Body tag
1.369     bisitz   2758:     $script = '<script type="text/javascript">'."\n"
1.372     bisitz   2759:               .'// <![CDATA['."\n"
                   2760:               .$script."\n"
                   2761:               .'// ]]>'."\n"
                   2762:               .'</script>'."\n";
1.385     bisitz   2763: 
                   2764:     # Breadcrumbs
                   2765:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.446     www      2766:     unless ($showdoc) {
1.392     raeburn  2767:         &Apache::lonhtmlcommon::add_breadcrumb({
1.446     www      2768:             href=>"/adm/coursedocs",text=>"$crstype Contents"});
1.392     raeburn  2769: 
1.446     www      2770:         $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.457     raeburn  2771:                                                  {'force_register' => $showdoc,
                   2772:                                                   'add_entries'    => $addentries,
                   2773:                                                  })
1.392     raeburn  2774:                  .&Apache::loncommon::help_open_menu('','',273,'RAT')
                   2775:                  .&Apache::lonhtmlcommon::breadcrumbs(
1.484     raeburn  2776:                      'Editing '.$crstype.' Contents',
1.392     raeburn  2777:                      'Docs_Adding_Course_Doc')
                   2778:         );
1.446     www      2779:     } else {
1.408     raeburn  2780:         $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
1.402     raeburn  2781:                                                 {'force_register' => $showdoc,}));
1.392     raeburn  2782:     }
1.364     bisitz   2783: 
1.329     droeschl 2784:   my %allfiles = ();
                   2785:   my %codebase = ();
1.440     raeburn  2786:   my ($upload_result,$upload_output,$uploadphase);
1.329     droeschl 2787:   if ($allowed) {
                   2788:       if (($env{'form.uploaddoc.filename'}) &&
                   2789: 	  ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440     raeburn  2790:           my $context = $1; 
                   2791:           # Process file upload - phase one - upload and parse primary file.
1.329     droeschl 2792: 	  undef($hadchanges);
1.440     raeburn  2793:           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
                   2794:                                               \%allfiles,\%codebase,$context);
1.329     droeschl 2795: 	  if ($hadchanges) {
                   2796: 	      &mark_hash_old();
                   2797: 	  }
1.440     raeburn  2798:           $r->print($upload_output);
                   2799:       } elsif ($env{'form.phase'} eq 'upload_embedded') {
                   2800:           # Process file upload - phase two - upload embedded objects 
                   2801:           $uploadphase = 'check_embedded';
                   2802:           my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');   
                   2803:           my $state = &embedded_form_elems($uploadphase,$primaryurl,
                   2804:                                            $env{'form.newidx'});
                   2805:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   2806:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   2807:           my ($destination,$dir_root) = &embedded_destination();
                   2808:           my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
                   2809:           my $actionurl = '/adm/coursedocs';
                   2810:           my ($result,$flag) = 
                   2811:               &Apache::loncommon::upload_embedded('coursedoc',$destination,
                   2812:                   $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
                   2813:                   $actionurl);
                   2814:           $r->print($result.&return_to_editor());
                   2815:       } elsif ($env{'form.phase'} eq 'check_embedded') {
                   2816:           # Process file upload - phase three - modify references in HTML file
                   2817:           $uploadphase = 'modified_orightml';
                   2818:           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   2819:           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   2820:           my ($destination,$dir_root) = &embedded_destination();
1.482     raeburn  2821:           my $result = 
                   2822:               &Apache::loncommon::modify_html_refs('coursedoc',$destination,
                   2823:                                                    $docuname,$docudom,undef,
                   2824:                                                    $dir_root);
                   2825:           $r->print($result.&return_to_editor());   
1.476     raeburn  2826:       } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
                   2827:           $uploadphase = 'decompress_phase_one';
                   2828:           $r->print(&decompression_phase_one().
                   2829:                     &return_to_editor());
                   2830:       } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
                   2831:           $uploadphase = 'decompress_phase_two';
                   2832:           $r->print(&decompression_phase_two().
                   2833:                     &return_to_editor());
1.329     droeschl 2834:       }
                   2835:   }
                   2836: 
1.484     raeburn  2837:   if ($allowed && $toolsflag) {
                   2838:       $r->print(&startContentScreen('tools'));
                   2839:       $r->print(&generate_admin_menu($crstype));
                   2840:       $r->print(&endContentScreen());
                   2841:   } elsif ((!$showdoc) && (!$uploadphase)) {
1.329     droeschl 2842: # -----------------------------------------------------------------------------
                   2843:        my %lt=&Apache::lonlocal::texthash(
1.408     raeburn  2844:                 'uplm' => 'Upload a new main '.lc($crstype).' document',
                   2845:                 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
1.329     droeschl 2846:                 'impp' => 'Import a document',
                   2847: 		'copm' => 'All documents out of a published map into this folder',
1.417     droeschl 2848:                 'upld' => 'Import Document',
1.329     droeschl 2849:                 'srch' => 'Search',
                   2850:                 'impo' => 'Import',
1.487     raeburn  2851: 		'lnks' => 'Import from Stored Links',
1.329     droeschl 2852:                 'selm' => 'Select Map',
                   2853:                 'load' => 'Load Map',
1.419     bisitz   2854:                 'reco' => 'Recover Deleted Documents',
1.329     droeschl 2855:                 'newf' => 'New Folder',
                   2856:                 'newp' => 'New Composite Page',
                   2857:                 'extr' => 'External Resource',
                   2858:                 'syll' => 'Syllabus',
1.425     raeburn  2859:                 'navc' => 'Table of Contents',
1.343     biermanm 2860:                 'sipa' => 'Simple Course Page',
1.329     droeschl 2861:                 'sipr' => 'Simple Problem',
                   2862:                 'drbx' => 'Drop Box',
1.451     www      2863:                 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336     schafran 2864:                 'bull' => 'Discussion Board',
1.347     weissno  2865:                 'mypi' => 'My Personal Information Page',
1.353     weissno  2866:                 'grpo' => 'Group Portfolio',
1.329     droeschl 2867:                 'rost' => 'Course Roster',
1.348     weissno  2868: 				'abou' => 'Personal Information Page for a User',
1.377     bisitz   2869:                 'imsf' => 'IMS Import',
                   2870:                 'imsl' => 'Import IMS package',
1.329     droeschl 2871:                 'file' =>  'File',
                   2872:                 'title' => 'Title',
                   2873:                 'comment' => 'Comment',
1.403     raeburn  2874:                 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.368     truskell 2875: 		'nd' => 'Upload Document',
1.329     droeschl 2876: 		'pm' => 'Published Map',
                   2877: 		'sd' => 'Special Document',
                   2878: 		'mo' => 'More Options',
                   2879: 					  );
                   2880: # -----------------------------------------------------------------------------
                   2881: 	my $fileupload=(<<FIUP);
                   2882: 	$lt{'file'}:<br />
                   2883: 	<input type="file" name="uploaddoc" size="40" />
                   2884: FIUP
                   2885: 
                   2886: 	my $checkbox=(<<CHBO);
                   2887: 	<!-- <label>$lt{'parse'}?
                   2888: 	<input type="checkbox" name="parserflag" />
                   2889: 	</label> -->
                   2890: 	<label>
                   2891: 	<input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
                   2892: 	</label>
                   2893: CHBO
                   2894: 
1.458     raeburn  2895:     my $fileuploada = "<br clear='all' /><input type='submit' value='".$lt{'upld'}."' /> $help{'Uploading_From_Harddrive'}";
1.329     droeschl 2896: 	my $fileuploadform=(<<FUFORM);
                   2897: 	<form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.371     tempelho 2898: 	<input type="hidden" name="active" value="aa" />
1.329     droeschl 2899: 	$fileupload
                   2900: 	<br />
                   2901: 	$lt{'title'}:<br />
1.458     raeburn  2902: 	<input type="text" size="60" name="comment" />
1.329     droeschl 2903: 	$uploadtag
                   2904: 	<input type="hidden" name="cmd" value="upload_default" />
                   2905: 	<br />
1.458     raeburn  2906: 	<span class="LC_nobreak" style="float:left">
1.329     droeschl 2907: 	$checkbox
                   2908: 	</span>
1.383     tempelho 2909: FUFORM
1.459     raeburn  2910:     $fileuploadform .= $fileuploada.'</form>';
1.329     droeschl 2911: 
                   2912: 	my $simpleeditdefaultform=(<<SEDFFORM);
                   2913: 	<form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.371     tempelho 2914: 	<input type="hidden" name="active" value="bb" />
1.383     tempelho 2915: SEDFFORM
                   2916: 	my @simpleeditdefaultforma = ( 
1.423     onken    2917: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'"  onclick="javascript:groupsearch()" />' => "$uploadtag<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>" },
                   2918: 	{ '<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.487     raeburn  2919: 	{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:open_StoredLinks_Import();" />' => "<a class='LC_menubuttons_link' href='javascript:open_StoredLinks_Import();'>$lt{'lnks'}</a>" },
1.383     tempelho 2920: 	);
1.443     www      2921: 	$simpleeditdefaultform .= &create_form_ul(&create_list_elements(@simpleeditdefaultforma));
1.383     tempelho 2922: 	$simpleeditdefaultform .=(<<SEDFFORM);
1.459     raeburn  2923: 	<hr id="bb_hrule" style="width:0px;text-align:left;margin-left:0" />
1.329     droeschl 2924: 	$lt{'copm'}<br />
                   2925: 	<input type="text" size="40" name="importmap" /><br />
1.458     raeburn  2926: 	<span class="LC_nobreak" style="float:left"><input type="button"
1.369     bisitz   2927: 	onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.329     droeschl 2928: 	value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
                   2929: 	$help{'Load_Map'}</span>
                   2930: 	</form>
                   2931: SEDFFORM
                   2932: 
1.442     www      2933:       my $extresourcesform=(<<ERFORM);
                   2934:       <form action="/adm/coursedocs" method="post" name="newext">
                   2935:       $uploadtag
                   2936:       <input type="hidden" name="importdetail" value="" />
                   2937:       <a class="LC_menubuttons_link" href="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
                   2938:       </form>
1.329     droeschl 2939: ERFORM
                   2940: 
1.442     www      2941: 
1.329     droeschl 2942:     if ($allowed) {
                   2943: 	&update_paste_buffer($coursenum,$coursedom);
1.337     ehlerst  2944: 	$r->print(<<HIDDENFORM);
                   2945: 	<form name="renameform" method="post" action="/adm/coursedocs">
                   2946:    <input type="hidden" name="title" />
                   2947:    <input type="hidden" name="cmd" />
                   2948:    <input type="hidden" name="markcopy" />
                   2949:    <input type="hidden" name="copyfolder" />
                   2950:    $containertag
                   2951:  </form>
1.484     raeburn  2952: 
1.337     ehlerst  2953: HIDDENFORM
1.484     raeburn  2954:         $r->print(&makesimpleeditform($uploadtag)."\n".
                   2955:                   &makedocslogform($uploadtag."\n".
                   2956:                                    '<input type="hidden" name="folder" value="'.
                   2957:                                    $env{'form.folder'}.'" />'."\n"));
1.329     droeschl 2958:     }
1.442     www      2959: 
                   2960: # Generate the tabs
1.472     raeburn  2961:     my $mode;
                   2962:     if (($supplementalflag) && (!$allowed)) {
                   2963:         &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
                   2964:     } else {
1.484     raeburn  2965:         $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.472     raeburn  2966:     }
1.443     www      2967: 
1.442     www      2968: #
                   2969: 
                   2970:     my $savefolderpath;
                   2971: 
1.395     raeburn  2972:     if ($allowed) {
1.329     droeschl 2973:        my $folder=$env{'form.folder'};
1.443     www      2974:        if ($folder eq '' || $supplementalflag) {
1.329     droeschl 2975:            $folder='default';
1.356     tempelho 2976: 	   $savefolderpath = $env{'form.folderpath'};
1.442     www      2977: 	   $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
1.329     droeschl 2978:            $uploadtag = '<input type="hidden" name="folderpath" value="'.
                   2979: 	       &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
                   2980:        }
                   2981:        my $postexec='';
                   2982:        if ($folder eq 'default') {
1.372     bisitz   2983:            $r->print('<script type="text/javascript">'."\n"
                   2984:                     .'// <![CDATA['."\n"
                   2985:                     .'this.window.name="loncapaclient";'."\n"
                   2986:                     .'// ]]>'."\n"
                   2987:                     .'</script>'."\n"
1.369     bisitz   2988:        );
1.329     droeschl 2989:        } else {
                   2990:            #$postexec='self.close();';
                   2991:        }
                   2992:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                   2993:                      '.sequence';
                   2994:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                   2995:                      '.page';
                   2996: 	my $container='sequence';
                   2997: 	if ($env{'form.pagepath'}) {
                   2998: 	    $container='page';
                   2999: 	}
                   3000: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
                   3001: 
                   3002: 	my $imspform=(<<IMSPFORM);
                   3003: 	<form action="/adm/imsimportdocs" method="post" name="ims">
                   3004: 	<input type="hidden" name="folder" value="$folder" />
1.423     onken    3005: 	<a class="LC_menubuttons_link" href="javascript:makeims();">$lt{'imsf'}</a>
1.329     droeschl 3006: 	</form>
                   3007: IMSPFORM
                   3008: 
                   3009: 	my $newnavform=(<<NNFORM);
                   3010: 	<form action="/adm/coursedocs" method="post" name="newnav">
1.371     tempelho 3011: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 3012: 	$uploadtag
                   3013: 	<input type="hidden" name="importdetail" 
                   3014: 	value="$lt{'navc'}=/adm/navmaps" />
1.423     onken    3015: 	<a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329     droeschl 3016: 	$help{'Navigate_Content'}
                   3017: 	</form>
                   3018: NNFORM
                   3019: 	my $newsmppageform=(<<NSPFORM);
                   3020: 	<form action="/adm/coursedocs" method="post" name="newsmppg">
1.371     tempelho 3021: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 3022: 	$uploadtag
                   3023: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    3024: 	<a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383     tempelho 3025: 	$help{'Simple Page'}
1.329     droeschl 3026: 	</form>
                   3027: NSPFORM
                   3028: 
                   3029: 	my $newsmpproblemform=(<<NSPROBFORM);
                   3030: 	<form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371     tempelho 3031: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 3032: 	$uploadtag
                   3033: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    3034: 	<a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.383     tempelho 3035: 	$help{'Simple Problem'}
1.329     droeschl 3036: 	</form>
                   3037: 
                   3038: NSPROBFORM
                   3039: 
                   3040: 	my $newdropboxform=(<<NDBFORM);
                   3041: 	<form action="/adm/coursedocs" method="post" name="newdropbox">
1.371     tempelho 3042: 	<input type="hidden" name="active" value="cc" />
1.344     bisitz   3043: 	$uploadtag
1.329     droeschl 3044: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    3045: 	<a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.344     bisitz   3046: 	</form>
1.329     droeschl 3047: NDBFORM
                   3048: 
                   3049: 	my $newexuploadform=(<<NEXUFORM);
                   3050: 	<form action="/adm/coursedocs" method="post" name="newexamupload">
1.371     tempelho 3051: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 3052: 	$uploadtag
                   3053: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    3054: 	<a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329     droeschl 3055: 	$help{'Score_Upload_Form'}
                   3056: 	</form>
                   3057: NEXUFORM
                   3058: 
                   3059: 	my $newbulform=(<<NBFORM);
                   3060: 	<form action="/adm/coursedocs" method="post" name="newbul">
1.371     tempelho 3061: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 3062: 	$uploadtag
                   3063: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    3064: 	<a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329     droeschl 3065: 	$help{'Bulletin Board'}
                   3066: 	</form>
                   3067: NBFORM
                   3068: 
                   3069: 	my $newaboutmeform=(<<NAMFORM);
                   3070: 	<form action="/adm/coursedocs" method="post" name="newaboutme">
1.371     tempelho 3071: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 3072: 	$uploadtag
                   3073: 	<input type="hidden" name="importdetail" 
                   3074: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.423     onken    3075: 	<a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347     weissno  3076: 	$help{'My Personal Information Page'}
1.329     droeschl 3077: 	</form>
                   3078: NAMFORM
                   3079: 
                   3080: 	my $newaboutsomeoneform=(<<NASOFORM);
                   3081: 	<form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371     tempelho 3082: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 3083: 	$uploadtag
                   3084: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    3085: 	<a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329     droeschl 3086: 	</form>
                   3087: NASOFORM
                   3088: 
                   3089: 
                   3090: 	my $newrosterform=(<<NROSTFORM);
                   3091: 	<form action="/adm/coursedocs" method="post" name="newroster">
1.371     tempelho 3092: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 3093: 	$uploadtag
                   3094: 	<input type="hidden" name="importdetail" 
                   3095: 	value="$lt{'rost'}=/adm/viewclasslist" />
1.423     onken    3096: 	<a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.329     droeschl 3097: 	$help{'Course Roster'}
                   3098: 	</form>
                   3099: NROSTFORM
                   3100: 
1.342     ehlerst  3101: my $specialdocumentsform;
1.383     tempelho 3102: my @specialdocumentsforma;
1.451     www      3103: my $gradingform;
                   3104: my @gradingforma;
                   3105: my $communityform;
                   3106: my @communityforma;
1.351     ehlerst  3107: my $newfolderform;
1.390     tempelho 3108: my $newfolderb;
1.342     ehlerst  3109: 
1.451     www      3110: 	my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383     tempelho 3111: 	
1.329     droeschl 3112: 	my $newpageform=(<<NPFORM);
                   3113: 	<form action="/adm/coursedocs" method="post" name="newpage">
                   3114: 	<input type="hidden" name="folderpath" value="$path" />
                   3115: 	<input type="hidden" name="importdetail" value="" />
1.371     tempelho 3116: 	<input type="hidden" name="active" value="cc" />
1.423     onken    3117: 	<a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383     tempelho 3118: 	$help{'Adding_Pages'}
1.329     droeschl 3119: 	</form>
                   3120: NPFORM
1.390     tempelho 3121: 
                   3122: 
1.351     ehlerst  3123: 	$newfolderform=(<<NFFORM);
1.329     droeschl 3124: 	<form action="/adm/coursedocs" method="post" name="newfolder">
                   3125: 	<input type="hidden" name="folderpath" value="$path" />
                   3126: 	<input type="hidden" name="importdetail" value="" />
1.371     tempelho 3127: 	<input type="hidden" name="active" value="aa" />
1.422     onken    3128: 	<a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329     droeschl 3129: 	</form>
                   3130: NFFORM
                   3131: 
                   3132: 	my $newsylform=(<<NSYLFORM);
                   3133: 	<form action="/adm/coursedocs" method="post" name="newsyl">
1.371     tempelho 3134: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 3135: 	$uploadtag
                   3136: 	<input type="hidden" name="importdetail" 
                   3137: 	value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423     onken    3138: 	<a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329     droeschl 3139: 	$help{'Syllabus'}
1.383     tempelho 3140: 
1.329     droeschl 3141: 	</form>
                   3142: NSYLFORM
1.364     bisitz   3143: 
1.329     droeschl 3144: 	my $newgroupfileform=(<<NGFFORM);
                   3145: 	<form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371     tempelho 3146: 	<input type="hidden" name="active" value="cc" />
1.329     droeschl 3147: 	$uploadtag
                   3148: 	<input type="hidden" name="importdetail"
                   3149: 	value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423     onken    3150: 	<a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353     weissno  3151: 	$help{'Group Portfolio'}
1.329     droeschl 3152: 	</form>
                   3153: NGFFORM
1.383     tempelho 3154: 	@specialdocumentsforma=(
1.421     onken    3155: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'"  onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.417     droeschl 3156: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451     www      3157: 	{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
                   3158:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
                   3159:         );
                   3160:         $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
                   3161: 
1.434     raeburn  3162: 
                   3163:         my @importdoc = (
                   3164:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'newext\');" />'=>$extresourcesform},
                   3165:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:makeims();" />'=>$imspform},);
1.459     raeburn  3166:         $fileuploadform =  &create_form_ul(&create_list_elements(@importdoc)) . '<hr id="cc_hrule" style="width:0px;text-align:left;margin-left:0" />' . $fileuploadform;
1.434     raeburn  3167: 
1.451     www      3168:         @gradingforma=(
                   3169:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
                   3170:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
                   3171:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
                   3172: 
                   3173:         );
                   3174:         $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
                   3175: 
                   3176:         @communityforma=(
                   3177:        {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
                   3178:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
                   3179:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
                   3180:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
                   3181:         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
                   3182:         );
                   3183:         $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383     tempelho 3184: 
1.330     tempelho 3185: my %orderhash = (
1.488   ! raeburn  3186:                 'aa' => ['Import Content',$fileuploadform],
        !          3187:                 'bb' => ['Published Content',$simpleeditdefaultform],
1.451     www      3188:                 'cc' => ['Grading Resources',$gradingform],
1.330     tempelho 3189:                 );
1.451     www      3190: unless ($env{'form.pagepath'}) {
1.434     raeburn  3191:     $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484     raeburn  3192:     $orderhash{'dd'} = ['Collaboration',$communityform];
1.451     www      3193:     $orderhash{'ee'} = ['Special Documents',$specialdocumentsform];
1.434     raeburn  3194: }
                   3195: 
1.341     ehlerst  3196:  $hadchanges=0;
1.484     raeburn  3197:        unless (($supplementalflag || $toolsflag)) {
1.458     raeburn  3198:           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472     raeburn  3199:                               $supplementalflag,\%orderhash,$iconpath);
1.443     www      3200:           if ($error) {
                   3201:              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   3202:           }
                   3203:           if ($hadchanges) {
                   3204:              &mark_hash_old();
                   3205:           }
1.341     ehlerst  3206: 
1.443     www      3207:           &changewarning($r,'');
                   3208:         }
1.458     raeburn  3209:     }
1.442     www      3210: 
1.443     www      3211: # Supplemental documents start here
                   3212: 
1.329     droeschl 3213:        my $folder=$env{'form.folder'};
1.443     www      3214:        unless ($supplementalflag) {
1.329     droeschl 3215: 	   $folder='supplemental';
                   3216:        }
                   3217:        if ($folder =~ /^supplemental$/ &&
                   3218: 	   (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446     www      3219:           $env{'form.folderpath'} = &supplemental_base();
1.393     raeburn  3220:        } elsif ($allowed) {
1.356     tempelho 3221: 	  $env{'form.folderpath'} = $savefolderpath;
1.329     droeschl 3222:        }
1.362     ehlerst  3223:        $env{'form.pagepath'} = '';
1.329     droeschl 3224:        if ($allowed) {
                   3225: 	   my $folderseq=
                   3226: 	       '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
                   3227: 	       '.sequence';
                   3228: 
                   3229: 	   my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   3230: 
1.400     droeschl 3231: 	my $supupdocformbtn = "<input type='submit' value='".$lt{'upld'}."' />$help{'Uploading_From_Harddrive'}";
1.329     droeschl 3232: 	my $supupdocform=(<<SUPDOCFORM);
1.383     tempelho 3233: 	<form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.371     tempelho 3234: 	<input type="hidden" name="active" value="ee" />	
1.329     droeschl 3235: 	$fileupload
                   3236: 	<br />
                   3237: 	<br />
                   3238: 	<span class="LC_nobreak">
                   3239: 	$checkbox
                   3240: 	</span>
                   3241: 	<br /><br />
                   3242: 	$lt{'comment'}:<br />
1.383     tempelho 3243: 	<textarea cols="50" rows="4" name="comment"></textarea>
1.329     droeschl 3244: 	<br />
                   3245: 	<input type="hidden" name="folderpath" value="$path" />
                   3246: 	<input type="hidden" name="cmd" value="upload_supplemental" />
                   3247: SUPDOCFORM
1.443     www      3248: 	$supupdocform .=  &create_form_ul(&Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."</form>";
1.329     droeschl 3249: 
                   3250: 	my $supnewfolderform=(<<SNFFORM);
                   3251: 	<form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371     tempelho 3252: 	<input type="hidden" name="active" value="ee" />
1.329     droeschl 3253: 	<input type="hidden" name="folderpath" value="$path" />
                   3254: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    3255: 	<a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a> 
1.383     tempelho 3256: 	$help{'Adding_Folders'}
1.329     droeschl 3257: 	</form>
                   3258: SNFFORM
1.383     tempelho 3259: 	
1.329     droeschl 3260: 
                   3261: 	my $supnewextform=(<<SNEFORM);
                   3262: 	<form action="/adm/coursedocs" method="post" name="supnewext">
1.371     tempelho 3263: 	<input type="hidden" name="active" value="ff" />
1.329     droeschl 3264: 	<input type="hidden" name="folderpath" value="$path" />
                   3265: 	<input type="hidden" name="importdetail" value="" />
1.423     onken    3266: 	<a class="LC_menubuttons_link" href="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
1.329     droeschl 3267: 	</form>
                   3268: SNEFORM
                   3269: 
                   3270: 	my $supnewsylform=(<<SNSFORM);
                   3271: 	<form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371     tempelho 3272: 	<input type="hidden" name="active" value="ff" />
1.329     droeschl 3273: 	<input type="hidden" name="folderpath" value="$path" />
                   3274: 	<input type="hidden" name="importdetail" 
                   3275: 	value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423     onken    3276: 	<a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329     droeschl 3277: 	$help{'Syllabus'}
                   3278: 	</form>
                   3279: SNSFORM
                   3280: 
                   3281: 	my $supnewaboutmeform=(<<SNAMFORM);
1.383     tempelho 3282: 	<form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371     tempelho 3283: 	<input type="hidden" name="active" value="ff" />
1.329     droeschl 3284: 	<input type="hidden" name="folderpath" value="$path" />
                   3285: 	<input type="hidden" name="importdetail" 
                   3286: 	value="$plainname=/adm/$udom/$uname/aboutme" />
1.423     onken    3287: 	<a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347     weissno  3288: 	$help{'My Personal Information Page'}
1.329     droeschl 3289: 	</form>
                   3290: SNAMFORM
                   3291: 
1.333     muellerd 3292: 
1.383     tempelho 3293: my @specialdocs = (
1.417     droeschl 3294: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
                   3295:             =>$supnewsylform},
                   3296: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
                   3297:             =>$supnewaboutmeform},
1.383     tempelho 3298: 		);
1.417     droeschl 3299: my @supimportdoc = (
                   3300: 		{'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'supnewext\');" />'
                   3301:             =>$supnewextform},
                   3302:         );
1.459     raeburn  3303: $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc)) . '<hr id="ee_hrule" style="width:0px;text-align:left;margin-left:0" />' . $supupdocform;
1.333     muellerd 3304: my %suporderhash = (
1.390     tempelho 3305: 		'00' => ['Supnewfolder', $supnewfolderform],
1.488   ! raeburn  3306:                 'ee' => ['Import Content',$supupdocform],
1.443     www      3307:                 'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))]
1.333     muellerd 3308:                 );
1.443     www      3309:         if ($supplementalflag) {
1.458     raeburn  3310:            my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472     raeburn  3311:                                $supplementalflag,\%suporderhash,$iconpath);
1.443     www      3312:            if ($error) {
                   3313:               $r->print('<p><span class="LC_error">'.$error.'</span></p>');
                   3314:            }
1.393     raeburn  3315:         }
1.443     www      3316:     } elsif ($supplementalflag) {
1.458     raeburn  3317:         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472     raeburn  3318:                             $supplementalflag,'',$iconpath);
1.393     raeburn  3319:         if ($error) {
                   3320:             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383     tempelho 3321:         }
1.393     raeburn  3322:     }
1.389     tempelho 3323: 
1.484     raeburn  3324:     $r->print(&endContentScreen());
1.383     tempelho 3325: 
1.329     droeschl 3326:     if ($allowed) {
                   3327: 	$r->print('
                   3328: <form method="post" name="extimport" action="/adm/coursedocs">
                   3329:   <input type="hidden" name="title" />
                   3330:   <input type="hidden" name="url" />
                   3331:   <input type="hidden" name="useform" />
                   3332:   <input type="hidden" name="residx" />
                   3333: </form>');
                   3334:     }
1.484     raeburn  3335:   } elsif ($showdoc) {
1.329     droeschl 3336: # -------------------------------------------------------- This is showdoc mode
1.484     raeburn  3337:       $r->print("<h1>".&mt('Uploaded Document').' - '.
1.329     droeschl 3338: 		&Apache::lonnet::gettitle($r->uri).'</h1><p>'.
                   3339: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484     raeburn  3340:                 &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329     droeschl 3341:   }
                   3342:  }
                   3343:  $r->print(&Apache::loncommon::end_page());
                   3344:  return OK;
1.364     bisitz   3345: }
1.329     droeschl 3346: 
1.440     raeburn  3347: sub embedded_form_elems {
                   3348:     my ($phase,$primaryurl,$newidx) = @_;
                   3349:     my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                   3350:     return <<STATE;
                   3351:     <input type="hidden" name="folderpath" value="$folderpath" />
                   3352:     <input type="hidden" name="cmd" value="upload_embedded" />
                   3353:     <input type="hidden" name="newidx" value="$newidx" />
                   3354:     <input type="hidden" name="phase" value="$phase" />
                   3355:     <input type="hidden" name="primaryurl" value="$primaryurl" />
                   3356: STATE
                   3357: }
                   3358: 
                   3359: sub embedded_destination {
                   3360:     my $folder=$env{'form.folder'};
                   3361:     my $destination = 'docs/';
                   3362:     if ($folder =~ /^supplemental/) {
                   3363:         $destination = 'supplemental/';
                   3364:     }
                   3365:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
                   3366:         $destination .= 'default/';
                   3367:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   3368:         $destination .=  $2.'/';
                   3369:     }
                   3370:     $destination .= $env{'form.newidx'};
                   3371:     my $dir_root = '/userfiles';
                   3372:     return ($destination,$dir_root);
                   3373: }
                   3374: 
                   3375: sub return_to_editor {
                   3376:     my $actionurl = '/adm/coursedocs';
                   3377:     return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n". 
                   3378:            '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
                   3379:            '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
                   3380:            '</a></p>';
                   3381: }
                   3382: 
1.476     raeburn  3383: sub decompression_info {
                   3384:     my ($destination,$dir_root) = &embedded_destination();
                   3385:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
                   3386:     my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
                   3387:     my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   3388:     my $container='sequence';
1.480     raeburn  3389:     my ($pathitem,$hiddenelem);
                   3390:     my @hiddens = ('newidx','comment','position');
1.476     raeburn  3391:     if ($env{'form.pagepath'}) {
                   3392:         $container='page';
1.480     raeburn  3393:         $pathitem = 'pagepath';
1.476     raeburn  3394:     } else {
1.480     raeburn  3395:         $pathitem = 'folderpath';
1.476     raeburn  3396:     }
1.480     raeburn  3397:     unshift(@hiddens,$pathitem);
                   3398:     foreach my $item (@hiddens) {
                   3399:         if ($env{'form.'.$item}) {
                   3400:             $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
                   3401:                            $env{'form.'.$item}.'" />'."\n";
                   3402:         }
1.477     raeburn  3403:     }
1.476     raeburn  3404:     return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
                   3405:             $hiddenelem);
                   3406: }
                   3407: 
                   3408: sub decompression_phase_one {
                   3409:     my ($dir,$file,$warning,$error,$output);
                   3410:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   3411:         &decompression_info();
                   3412:     if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/docs/\E(?:default|supplemental|\d+).*/([^/]+)$}) {
                   3413:         $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
                   3414:     } else {
                   3415:         my $file = $1;
1.481     raeburn  3416:         $output = 
                   3417:             &Apache::loncommon::process_decompression($docudom,$docuname,$file,
                   3418:                                                       $destination,$dir_root,
                   3419:                                                       $hiddenelem);
                   3420:         if ($env{'form.autoextract_camtasia'}) {
                   3421:             $output .= &remove_archive($docudom,$docuname,$container);
                   3422:         }
1.476     raeburn  3423:     }
                   3424:     if ($error) {
                   3425:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   3426:                    $error.'</p>'."\n";
                   3427:     }
                   3428:     if ($warning) {
                   3429:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   3430:     }
                   3431:     return $output;
                   3432: }
                   3433: 
                   3434: sub decompression_phase_two {
                   3435:     my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
                   3436:         &decompression_info();
1.481     raeburn  3437:     my $output;
1.480     raeburn  3438:     if ($env{'form.archivedelete'}) {
1.481     raeburn  3439:         $output = &remove_archive($docudom,$docuname,$container);
1.480     raeburn  3440:     }
                   3441:     $output .= 
1.481     raeburn  3442:         &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476     raeburn  3443:                                                     $destination,$dir_root,$hiddenelem);
                   3444:     return $output;
                   3445: }
                   3446: 
1.480     raeburn  3447: sub remove_archive {
                   3448:     my ($docudom,$docuname,$container) = @_;
                   3449:     my $map = $env{'form.folder'}.'.'.$container;
1.481     raeburn  3450:     my ($output,$delwarning,$delresult,$url);
1.480     raeburn  3451:     my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
                   3452:     if ($fatal) {
                   3453:         if ($container eq 'page') {
                   3454:             $delwarning = &mt('An error occurred retrieving the contents of the current page.');
                   3455:         } else {
                   3456:             $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
                   3457:         }
                   3458:         $delwarning .= &mt('As a result the archive file has not been removed.');
                   3459:     } else {
                   3460:         my $currcmd = $env{'form.cmd'};
                   3461:         my $position = $env{'form.position'};
                   3462:         if ($position > 0) { 
                   3463:             $env{'form.cmd'} = 'del_'.$position;
                   3464:             my ($title,$url,@rrest) = 
                   3465:                 split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
                   3466:             if (&handle_edit_cmd($docuname,$docudom)) {
                   3467:                 ($errtext,$fatal) = &storemap($docuname,$docudom,$map);
                   3468:                 if ($fatal) {
                   3469:                     if ($container eq 'page') {
                   3470:                         $delwarning = &mt('An error occurred updating the contents of the current page.');
                   3471:                     } else {
                   3472:                         $delwarning = &mt('An error occurred updating the contents of the current folder.');
                   3473:                     }
                   3474:                 } else {
1.481     raeburn  3475:                     $delresult = &mt('Archive file removed.');
1.480     raeburn  3476:                 }
                   3477:             }
                   3478:         }
                   3479:         $env{'form.cmd'} = $currcmd;
                   3480:     }
                   3481:     if ($delwarning) {
                   3482:         $output = '<p class="LC_warning">'.
                   3483:                    $delwarning.
                   3484:                    '</p>';
                   3485:     }
                   3486:     if ($delresult) {
                   3487:         $output .= '<p class="LC_info">'.
                   3488:                    $delresult.
                   3489:                    '</p>';
                   3490:     }
1.481     raeburn  3491:     return $output;
1.480     raeburn  3492: }
                   3493: 
1.484     raeburn  3494: sub generate_admin_menu {
                   3495:     my ($crstype) = @_;
                   3496:     my $lc_crstype = lc($crstype);
                   3497:     my ($home,$other,%outhash)=&authorhosts();
                   3498:     my %lt=&Apache::lonlocal::texthash (
                   3499:                                          'vc'   => 'Verify Content',
                   3500:                                          'cv'   => 'Check/Set Resource Versions',
                   3501:                                          'ls'   => 'List Resource Identifiers',
                   3502:                                          'imse' => 'Export contents to IMS Archive',
                   3503:                                          'dcd'  => "Dump $crstype Content to Authoring Space",
                   3504:                                        );
                   3505:     my ($candump,$dumpurl);
                   3506:     if ($home + $other > 0) {
                   3507:         $candump = 'F';
                   3508:         if ($home) {
                   3509:             $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
                   3510:         } else {
                   3511:             my @hosts;
                   3512:             foreach my $aurole (keys(%outhash)) {
                   3513:                 unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
                   3514:                     push(@hosts,$outhash{$aurole});
                   3515:                 }  
                   3516:             }
                   3517:             if (@hosts == 1) {
                   3518:                 my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
                   3519:                                '&amp;role='.
                   3520:                                &HTML::Entities::encode($env{'request.role'},'"<>&').'&amp;origurl='.
                   3521:                                &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
                   3522:                 $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
                   3523:             } else {
                   3524:                 $dumpurl = "javascript:choose_switchserver_window()";
                   3525:             }
                   3526:         }
                   3527:     }
                   3528:     my @menu=
                   3529:         ({  categorytitle=>'Administration',
                   3530:             items =>[
                   3531:                 {   linktext   => $lt{'vc'},
                   3532:                     url        => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
                   3533:                     permission => 'F',
                   3534:                     help       => 'Verify_Content',
                   3535:                     icon       => 'verify.png',
                   3536:                     linktitle  => 'Verify contents can be retrieved/rendered',
                   3537:                 },
                   3538:                 {   linktext => $lt{'cv'},
                   3539:                     url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
                   3540:                     permission => 'F',
                   3541:                     help       => 'Check_Resource_Versions',
                   3542:                     icon       => 'resversion.png',
                   3543:                     linktitle  => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
                   3544:                 },
                   3545:                 {   linktext   => $lt{'ls'},
                   3546:                     url        => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
                   3547:                     permission => 'F',
                   3548:                     #help => '',
                   3549:                     icon       => 'symbs.png',
                   3550:                     linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"
                   3551:                 },
                   3552:                 ]
                   3553:         },
                   3554:         {   categorytitle=>'Export',
                   3555:             items =>[
                   3556:                 {   linktext   => $lt{'imse'},
                   3557:                     url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
                   3558:                     permission => 'F',
                   3559:                     help       => 'Docs_Export_Course_Docs',
                   3560:                     icon       => 'imsexport.png',
                   3561:                     linktitle  => $lt{'imse'},
                   3562:                 },
                   3563:                 {   linktext   => $lt{'dcd'},
                   3564:                     url        => $dumpurl,
                   3565:                     permission => $candump,
                   3566:                     #help => '',
                   3567:                     icon       => 'dump.png',
                   3568:                     linktitle  => $lt{'dcd'},
                   3569:                 },
                   3570:                 ]
                   3571:         });
                   3572:     return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
                   3573:            '<input type="hidden" id="dummy" />'."\n".
                   3574:            &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
                   3575:            '</form>';
1.329     droeschl 3576: }
                   3577: 
                   3578: sub generate_edit_table {
1.484     raeburn  3579:     my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile) = @_;
1.406     raeburn  3580:     return unless(ref($orderhash_ref) eq 'HASH');
1.342     ehlerst  3581:     my %orderhash = %{$orderhash_ref};
1.344     bisitz   3582:     my $form;
1.371     tempelho 3583:     my $activetab;
                   3584:     my $active;
                   3585:     if($env{'form.active'} ne ''){
                   3586:         $activetab = $env{'form.active'};
                   3587:     }
1.472     raeburn  3588:     my $backicon = $iconpath.'clickhere.gif';
1.481     raeburn  3589:     my $backtext = &mt('To Overview');
1.458     raeburn  3590:     $form = '<div class="LC_Box" style="margin:0;">'.
1.488   ! raeburn  3591:             '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
        !          3592:             '<li class="goback">'.
        !          3593:             '<a href="javascript:toContents('."'$jumpto'".');">'.
        !          3594:             '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
        !          3595:             '  alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
        !          3596:             '<li>'.
        !          3597:             '<a href="javascript:groupopen('."'$readfile'".',1);">'.
        !          3598:             &mt('Undo Delete').'</a></li>'."\n";
        !          3599:     if ($env{'form.docslog'}) {
        !          3600:         $form .= '<li class="active">';
        !          3601:     } else {
        !          3602:         $form .= '<li>';
        !          3603:     }
        !          3604:     $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
        !          3605:              &mt('History').'</a></li>'."\n";
        !          3606:     if ($env{'form.docslog'}) {
        !          3607:         $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
        !          3608:                  &mt('Edit').'</a></li>'."\n";
1.484     raeburn  3609:     }
1.458     raeburn  3610:     foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390     tempelho 3611:         if($name ne '00'){
1.371     tempelho 3612:             if($activetab eq '' || $activetab ne $name){
                   3613:                $active = '';
                   3614:             }elsif($activetab eq $name){
                   3615:                $active = 'class="active"';
                   3616:             }
1.458     raeburn  3617:             $form .= '<li style="float:right" '.$active
1.429     droeschl 3618:                 .' onmouseover="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"'
1.484     raeburn  3619:                 .' 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 3620:         } else {
1.484     raeburn  3621: 	    $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390     tempelho 3622: 
                   3623: 	}
1.329     droeschl 3624:     }
1.484     raeburn  3625:     $form .= '</ul>'."\n";
                   3626:     $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458     raeburn  3627: 
                   3628:     if ($to_show ne '') {
1.484     raeburn  3629:         $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'."\n";
1.458     raeburn  3630:     }
1.363     ehlerst  3631:     foreach my $field (keys(%orderhash)){
1.390     tempelho 3632: 	if($field ne '00'){
1.422     onken    3633:             if($activetab eq '' || $activetab ne $field){
1.458     raeburn  3634:                 $active = 'style="display: none;float:left"';
1.422     onken    3635:             }elsif($activetab eq $field){
1.458     raeburn  3636:                 $active = 'style="display:block;float:left"';
1.422     onken    3637:             }
                   3638:             $form .= '<div id="'.$field.$tid.'"'
                   3639:                     .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484     raeburn  3640:                     .'</div>'."\n";
1.363     ehlerst  3641:         }
                   3642:     }
1.484     raeburn  3643:     unless ($env{'form.docslog'}) {
                   3644:         $form .= '</div></div>'."\n";
                   3645:     }
1.329     droeschl 3646:     return $form;
                   3647: }
                   3648: 
                   3649: sub editing_js {
1.472     raeburn  3650:     my ($udom,$uname,$supplementalflag) = @_;
1.329     droeschl 3651:     my $now = time();
                   3652:     my %lt = &Apache::lonlocal::texthash(
                   3653:                                           p_mnf => 'Name of New Folder',
                   3654:                                           t_mnf => 'New Folder',
                   3655:                                           p_mnp => 'Name of New Page',
                   3656:                                           t_mnp => 'New Page',
1.451     www      3657:                                           p_mxu => 'Title for the External Score',
1.349     biermanm 3658:                                           p_msp => 'Name of Simple Course Page',
1.329     droeschl 3659:                                           p_msb => 'Title for the Problem',
                   3660:                                           p_mdb => 'Title for the Drop Box',
1.336     schafran 3661:                                           p_mbb => 'Title for the Discussion Board',
1.348     weissno  3662:                                           p_mab => "Enter user:domain for User's Personal Information Page",
1.352     bisitz   3663:                                           p_mab2 => 'Personal Information Page of ',
1.329     droeschl 3664:                                           p_mab_alrt1 => 'Not a valid user:domain',
                   3665:                                           p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
                   3666:                                           p_chn => 'New Title',
                   3667:                                           p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
                   3668:                                           p_rmr2a => 'Remove[_99]',
                   3669:                                           p_rmr2b => '?[_99]',
                   3670:                                           p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
                   3671:                                           p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
                   3672:                                           p_ctr2a => 'Cut[_98]',
1.478     raeburn  3673:                                           p_ctr2b => '?[_98]',
                   3674:                                           rpck    => 'Enter number to pick (e.g., 3)',
1.329     droeschl 3675:                                         );
                   3676: 
1.433     raeburn  3677:     my $crstype = &Apache::loncommon::course_type();
1.434     raeburn  3678:     my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
                   3679:     my $docs_pagepath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.pagepath'},'<>&"');
                   3680:     my $main_container_page;
                   3681:     if ($docs_folderpath eq '') {
                   3682:         if ($docs_pagepath ne '') {
                   3683:             $main_container_page = 1;
                   3684:         }
                   3685:     }
1.433     raeburn  3686:     my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
1.446     www      3687:     my $toplevelsupp = &supplemental_base();
1.433     raeburn  3688: 
1.472     raeburn  3689:     my $backtourl = '/adm/navmaps';
                   3690:     if ($supplementalflag) {
                   3691:         $backtourl = '/adm/supplemental';
                   3692:     }
                   3693: 
1.329     droeschl 3694:     return <<ENDNEWSCRIPT;
                   3695: function makenewfolder(targetform,folderseq) {
                   3696:     var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
                   3697:     if (foldername) {
                   3698:        targetform.importdetail.value=escape(foldername)+"="+folderseq;
                   3699:         targetform.submit();
                   3700:     }
                   3701: }
                   3702: 
                   3703: function makenewpage(targetform,folderseq) {
                   3704:     var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
                   3705:     if (pagename) {
                   3706:         targetform.importdetail.value=escape(pagename)+"="+folderseq;
                   3707:         targetform.submit();
                   3708:     }
                   3709: }
                   3710: 
                   3711: function makenewext(targetname) {
                   3712:     this.document.forms.extimport.useform.value=targetname;
                   3713:     this.document.forms.extimport.title.value='';
                   3714:     this.document.forms.extimport.url.value='';
                   3715:     this.document.forms.extimport.residx.value='';
                   3716:     window.open('/adm/rat/extpickframe.html');
                   3717: }
                   3718: 
                   3719: function edittext(targetname,residx,title,url) {
                   3720:     this.document.forms.extimport.useform.value=targetname;
                   3721:     this.document.forms.extimport.residx.value=residx;
                   3722:     this.document.forms.extimport.url.value=url;
                   3723:     this.document.forms.extimport.title.value=title;
                   3724:     window.open('/adm/rat/extpickframe.html');
                   3725: }
                   3726: 
                   3727: function makeexamupload() {
                   3728:    var title=prompt('$lt{"p_mxu"}');
1.344     bisitz   3729:    if (title) {
1.329     droeschl 3730:     this.document.forms.newexamupload.importdetail.value=
                   3731: 	escape(title)+'=/res/lib/templates/examupload.problem';
                   3732:     this.document.forms.newexamupload.submit();
                   3733:    }
                   3734: }
                   3735: 
                   3736: function makesmppage() {
                   3737:    var title=prompt('$lt{"p_msp"}');
1.344     bisitz   3738:    if (title) {
1.329     droeschl 3739:     this.document.forms.newsmppg.importdetail.value=
                   3740: 	escape(title)+'=/adm/$udom/$uname/$now/smppg';
                   3741:     this.document.forms.newsmppg.submit();
                   3742:    }
                   3743: }
                   3744: 
                   3745: function makesmpproblem() {
                   3746:    var title=prompt('$lt{"p_msb"}');
1.344     bisitz   3747:    if (title) {
1.329     droeschl 3748:     this.document.forms.newsmpproblem.importdetail.value=
                   3749: 	escape(title)+'=/res/lib/templates/simpleproblem.problem';
                   3750:     this.document.forms.newsmpproblem.submit();
                   3751:    }
                   3752: }
                   3753: 
                   3754: function makedropbox() {
                   3755:    var title=prompt('$lt{"p_mdb"}');
1.344     bisitz   3756:    if (title) {
1.329     droeschl 3757:     this.document.forms.newdropbox.importdetail.value=
                   3758:         escape(title)+'=/res/lib/templates/DropBox.problem';
                   3759:     this.document.forms.newdropbox.submit();
                   3760:    }
                   3761: }
                   3762: 
                   3763: function makebulboard() {
                   3764:    var title=prompt('$lt{"p_mbb"}');
                   3765:    if (title) {
                   3766:     this.document.forms.newbul.importdetail.value=
                   3767: 	escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
                   3768:     this.document.forms.newbul.submit();
                   3769:    }
                   3770: }
                   3771: 
                   3772: function makeabout() {
                   3773:    var user=prompt("$lt{'p_mab'}");
                   3774:    if (user) {
                   3775:        var comp=new Array();
                   3776:        comp=user.split(':');
                   3777:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   3778: 	   if ((comp[0]) && (comp[1])) {
                   3779: 	       this.document.forms.newaboutsomeone.importdetail.value=
                   3780: 		   '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335     ehlerst  3781:        this.document.forms.newaboutsomeone.submit();
                   3782:    } else {
                   3783:        alert("$lt{'p_mab_alrt1'}");
1.329     droeschl 3784:    }
1.335     ehlerst  3785: } else {
                   3786:    alert("$lt{'p_mab_alrt2'}");
                   3787: }
                   3788: }
1.329     droeschl 3789: }
                   3790: 
                   3791: function makeims() {
1.335     ehlerst  3792: var caller = document.forms.ims.folder.value;
                   3793: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
                   3794: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
                   3795: newWindow.location.href = newlocation;
1.329     droeschl 3796: }
                   3797: 
                   3798: function finishpick() {
1.335     ehlerst  3799: var title=this.document.forms.extimport.title.value;
                   3800: var url=this.document.forms.extimport.url.value;
                   3801: var form=this.document.forms.extimport.useform.value;
                   3802: var residx=this.document.forms.extimport.residx.value;
                   3803: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
1.329     droeschl 3804: }
                   3805: 
                   3806: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335     ehlerst  3807: var title=prompt('$lt{"p_chn"}',oldtitle);
                   3808: if (title) {
                   3809: this.document.forms.renameform.markcopy.value=-1;
                   3810: this.document.forms.renameform.title.value=title;
                   3811: this.document.forms.renameform.cmd.value='rename_'+index;
                   3812: if (container == 'sequence') {
                   3813:     this.document.forms.renameform.folderpath.value=folderpath;
                   3814: }
                   3815: if (container == 'page') {
                   3816:     this.document.forms.renameform.pagepath.value=folderpath;
                   3817:     this.document.forms.renameform.pagesymb.value=pagesymb;
                   3818: }
                   3819: this.document.forms.renameform.submit();
                   3820: }
1.329     droeschl 3821: }
                   3822: 
                   3823: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335     ehlerst  3824: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
                   3825: this.document.forms.renameform.markcopy.value=-1;
                   3826: this.document.forms.renameform.cmd.value='del_'+index;
                   3827: if (container == 'sequence') {
                   3828:     this.document.forms.renameform.folderpath.value=folderpath;
                   3829: }
                   3830: if (container == 'page') {
                   3831:     this.document.forms.renameform.pagepath.value=folderpath;
                   3832:     this.document.forms.renameform.pagesymb.value=pagesymb;
                   3833: }
                   3834: this.document.forms.renameform.submit();
                   3835: }
1.329     droeschl 3836: }
                   3837: 
                   3838: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335     ehlerst  3839: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
                   3840: this.document.forms.renameform.cmd.value='cut_'+index;
                   3841: this.document.forms.renameform.markcopy.value=index;
                   3842: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
                   3843: if (container == 'sequence') {
                   3844:     this.document.forms.renameform.folderpath.value=folderpath;
                   3845: }
                   3846: if (container == 'page') {
                   3847:     this.document.forms.renameform.pagepath.value=folderpath;
                   3848:     this.document.forms.renameform.pagesymb.value=pagesymb;
                   3849: }
                   3850: this.document.forms.renameform.submit();
                   3851: }
1.329     droeschl 3852: }
                   3853: 
                   3854: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335     ehlerst  3855: this.document.forms.renameform.markcopy.value=index;
                   3856: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
                   3857: if (container == 'sequence') {
                   3858: this.document.forms.renameform.folderpath.value=folderpath;
                   3859: }
                   3860: if (container == 'page') {
                   3861: this.document.forms.renameform.pagepath.value=folderpath;
                   3862: this.document.forms.renameform.pagesymb.value=pagesymb;
                   3863: }
                   3864: this.document.forms.renameform.submit();
1.329     droeschl 3865: }
                   3866: 
1.478     raeburn  3867: function updatePick(targetform,index,caller) {
                   3868:     var pickitem = document.getElementById('rpick_'+index);
                   3869:     var picknumitem = document.getElementById('rpicknum_'+index);
                   3870:     if (pickitem.checked) {
                   3871:         var picknum=prompt('$lt{"rpck"}',picknumitem.value);
                   3872:         if (picknum == '' || picknum == null) {
                   3873:             if (caller == 'check') {
                   3874:                 pickitem.checked=false;
                   3875:                 return;
                   3876:             }
                   3877:         } else {
                   3878:             picknum.toString();
                   3879:             var regexdigit=/^\\d+\$/;
                   3880:             if (regexdigit.test(picknum)) {
                   3881:                 picknumitem.value = picknum;
                   3882:                 targetform.changeparms.value='randompick';
                   3883:                 targetform.submit();
                   3884:             } else {
                   3885:                 if (caller == 'check') {
                   3886:                     pickitem.checked=false;
                   3887:                 }
                   3888:                 return;
                   3889:             }
                   3890:         }
                   3891:     } else {
                   3892:         picknumitem.value = 0;
                   3893:         targetform.changeparms.value='randompick';
                   3894:         targetform.submit();
                   3895:     }
                   3896: }
                   3897: 
1.334     muellerd 3898: function unselectInactive(nav) {
1.335     ehlerst  3899: currentNav = document.getElementById(nav);
                   3900: currentLis = currentNav.getElementsByTagName('LI');
                   3901: for (i = 0; i < currentLis.length; i++) {
1.472     raeburn  3902:         if (currentLis[i].className == 'goback') {
                   3903:             currentLis[i].className = 'goback';
                   3904:         } else {
                   3905: 	    if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374     tempelho 3906: 		currentLis[i].className = 'right';
1.472     raeburn  3907: 	    } else {
1.374     tempelho 3908: 		currentLis[i].className = 'i';
1.472     raeburn  3909: 	    }
                   3910:         }
1.335     ehlerst  3911: }
1.332     tempelho 3912: }
                   3913: 
1.334     muellerd 3914: function hideAll(current, nav, data) {
1.335     ehlerst  3915: unselectInactive(nav);
1.374     tempelho 3916: if(current.className == 'right'){
                   3917: 	current.className = 'right active'
                   3918: 	}else{
                   3919: 	current.className = 'active';
                   3920: }
1.335     ehlerst  3921: currentData = document.getElementById(data);
                   3922: currentDivs = currentData.getElementsByTagName('DIV');
                   3923: for (i = 0; i < currentDivs.length; i++) {
                   3924: 	if(currentDivs[i].className == 'LC_ContentBox'){
1.333     muellerd 3925: 		currentDivs[i].style.display = 'none';
1.330     tempelho 3926: 	}
                   3927: }
1.335     ehlerst  3928: }
1.330     tempelho 3929: 
1.374     tempelho 3930: function openTabs(pageId) {
                   3931: 	tabnav = document.getElementById(pageId).getElementsByTagName('UL');	
1.383     tempelho 3932: 	if(tabnav.length > 2 ){
1.389     tempelho 3933: 		currentNav = document.getElementById(tabnav[1].id);
1.374     tempelho 3934: 		currentLis = currentNav.getElementsByTagName('LI');
                   3935: 		for(i = 0; i< currentLis.length; i++){
                   3936: 			if(currentLis[i].className == 'active') {
1.375     tempelho 3937: 				funcString = currentLis[i].onclick.toString();
                   3938: 				tab = funcString.split('"');
1.420     onken    3939:                                 if(tab.length < 2) {
                   3940:                                    tab = funcString.split("'");
                   3941:                                 }
1.375     tempelho 3942: 				currentData = document.getElementById(tab[1]);
                   3943:         			currentData.style.display = 'block';
1.374     tempelho 3944: 			}	
                   3945: 		}
                   3946: 	}
                   3947: }
                   3948: 
1.334     muellerd 3949: function showPage(current, pageId, nav, data) {
                   3950: 	hideAll(current, nav, data);
1.375     tempelho 3951: 	openTabs(pageId);
1.334     muellerd 3952: 	unselectInactive(nav);
1.330     tempelho 3953: 	current.className = 'active';
                   3954: 	currentData = document.getElementById(pageId);
                   3955: 	currentData.style.display = 'block';
1.458     raeburn  3956:         activeTab = pageId;
1.433     raeburn  3957:         if (nav == 'mainnav') {
                   3958:             var storedpath = "$docs_folderpath";
                   3959:             if (storedpath == '') {
                   3960:                 storedpath = "$docs_pagepath";
                   3961:             }
1.434     raeburn  3962:             var storedpage = "$main_container_page";
1.433     raeburn  3963:             var reg = new RegExp("^supplemental");
                   3964:             if (pageId == 'mainCourseDocuments') {
1.434     raeburn  3965:                 if (storedpage == 1) {
                   3966:                     document.simpleedit.folderpath.value = '';
                   3967:                     document.uploaddocument.folderpath.value = '';
                   3968:                 } else {
                   3969:                     if (reg.test(storedpath)) {
                   3970:                         document.simpleedit.folderpath.value = '$toplevelmain';
                   3971:                         document.uploaddocument.folderpath.value = '$toplevelmain';
                   3972:                         document.newext.folderpath.value = '$toplevelmain';
                   3973:                     } else {
                   3974:                         document.simpleedit.folderpath.value = storedpath;
                   3975:                         document.uploaddocument.folderpath.value = storedpath;
                   3976:                         document.newext.folderpath.value = storedpath;
                   3977:                     }
1.433     raeburn  3978:                 }
                   3979:             } else {
1.434     raeburn  3980:                 if (reg.test(storedpath)) {
                   3981:                     document.simpleedit.folderpath.value = storedpath;
                   3982:                     document.supuploaddocument.folderpath.value = storedpath;
                   3983:                     document.supnewext.folderpath.value = storedpath;
                   3984:                 } else {
1.433     raeburn  3985:                     document.simpleedit.folderpath.value = '$toplevelsupp';
                   3986:                     document.supuploaddocument.folderpath.value = '$toplevelsupp';
                   3987:                     document.supnewext.folderpath.value = '$toplevelsupp';
                   3988:                 }
                   3989:             }
                   3990:         }
1.485     raeburn  3991:         resize_scrollbox('contentscroll','1','0');
1.330     tempelho 3992: 	return false;
                   3993: }
1.329     droeschl 3994: 
1.472     raeburn  3995: function toContents(jumpto) {
                   3996:     var newurl = '$backtourl';
                   3997:     if (jumpto != '') {
                   3998:         newurl = newurl+'?postdata='+jumpto;
                   3999: ;
                   4000:     }
                   4001:     location.href=newurl;
                   4002: }
                   4003: 
1.329     droeschl 4004: ENDNEWSCRIPT
                   4005: }
1.457     raeburn  4006: 
1.483     raeburn  4007: sub history_tab_js {
                   4008:     return <<"ENDHIST";
                   4009: function toggleHistoryDisp(choice) {
                   4010:     document.docslogform.docslog.value = choice;
                   4011:     document.docslogform.submit();
                   4012:     return;
                   4013: }
                   4014: 
                   4015: ENDHIST
                   4016: }
                   4017: 
1.484     raeburn  4018: sub inject_data_js {
                   4019:     return <<ENDINJECT;
                   4020: 
                   4021: function injectData(current, hiddenField, name, value) {
                   4022:         currentElement = document.getElementById(hiddenField);
                   4023:         currentElement.name = name;
                   4024:         currentElement.value = value;
                   4025:         current.submit();
                   4026: }
                   4027: 
                   4028: ENDINJECT
                   4029: }
                   4030: 
                   4031: sub dump_switchserver_js {
                   4032:     my @hosts = @_;
                   4033:     my %lt = &Apache::lonlocal::texthash(
                   4034:         dump => 'Dumping to Authoring Space requires switching server.',
                   4035:         swit => 'Switch server?',
                   4036:         duco => 'Dump content to Authoring Space',
                   4037:         yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
                   4038:         chos => 'Choose server',
                   4039:     );
                   4040:     my $role = $env{'request.role'};
                   4041:     my $js = <<"ENDSWJS";
                   4042: <script type="text/javascript">
                   4043: function write_switchserver() {
                   4044:     var server;
                   4045:     if (document.setserver.posshosts.length > 0) {
                   4046:         for (var i=0; i<document.setserver.posshosts.length; i++) {
                   4047:             if (document.setserver.posshosts[i].checked) {
                   4048:                 server = document.setserver.posshosts[i].value;
                   4049:             }
                   4050:        }
                   4051:        opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
                   4052:     }
                   4053:     window.close();
                   4054: }
                   4055: </script>
                   4056: 
                   4057: ENDSWJS
                   4058: 
                   4059:     my $startpage = &Apache::loncommon::start_page('Choose server',$js,
                   4060:                                                    {'only_body' => 1,
                   4061:                                                     'js_ready'  => 1,});
                   4062:     my $endpage = &Apache::loncommon::end_page({'js_ready'  => 1});
                   4063: 
                   4064:     my $hostpicker;
                   4065:     my $count = 0;
                   4066:     foreach my $host (sort(@hosts)) {
                   4067:         my $checked;
                   4068:         if ($count == 0) {
                   4069:             $checked = ' checked="checked"';
                   4070:         }
                   4071:         $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
                   4072:                        $host.'"'.$checked.' />'.$host.'</label>&nbsp;&nbsp;';
                   4073:         $count++;
                   4074:     }
                   4075:     
                   4076:     return <<"ENDSWITCHJS";
                   4077: 
                   4078: function dump_needs_switchserver(url) {
                   4079:     if (url!='' && url!= null) {
                   4080:         if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
                   4081:             go(url);
                   4082:         }
                   4083:     }
                   4084:     return;
                   4085: }
                   4086: 
                   4087: function choose_switchserver_window() {
                   4088:     newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
                   4089:     newWindow.document.open();
                   4090:     newWindow.document.writeln('$startpage');
                   4091:     newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
                   4092:        '<p>$lt{'yone'}<\\/p>\\n'+
                   4093:        '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
                   4094:        '<form name="setserver" method="post" action="" \\/>\\n'+
                   4095:        '$hostpicker\\n'+
                   4096:        '<br \\/><br \\/>\\n'+
                   4097:        '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
                   4098:        'onclick="write_switchserver();" \\/>\\n'+
                   4099:        '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
                   4100:     newWindow.document.writeln('$endpage');
                   4101:     newWindow.document.close();
                   4102:     newWindow.focus();
                   4103: }
                   4104: 
                   4105: ENDSWITCHJS
                   4106: }
                   4107: 
                   4108: sub makedocslogform {
                   4109:     my ($formelems,$docslog) = @_;
                   4110:     return <<"LOGSFORM";
                   4111:  <form action="/adm/coursedocs" method="post" name="docslogform">
                   4112:    <input type="hidden" name="docslog" value="$docslog" />
                   4113:    $formelems
                   4114:  </form>
                   4115: LOGSFORM
                   4116: }
                   4117: 
                   4118: sub makesimpleeditform {
                   4119:     my ($formelems) = @_;
                   4120:     return <<"SIMPFORM";
                   4121:  <form name="simpleedit" method="post" action="/adm/coursedocs">
                   4122:    <input type="hidden" name="importdetail" value="" />
                   4123:    $formelems
                   4124:  </form>
                   4125: SIMPFORM
                   4126: }
                   4127: 
1.329     droeschl 4128: 1;
                   4129: __END__
                   4130: 
                   4131: 
                   4132: =head1 NAME
                   4133: 
                   4134: Apache::londocs.pm
                   4135: 
                   4136: =head1 SYNOPSIS
                   4137: 
                   4138: This is part of the LearningOnline Network with CAPA project
                   4139: described at http://www.lon-capa.org.
                   4140: 
                   4141: =head1 SUBROUTINES
                   4142: 
                   4143: =over
                   4144: 
                   4145: =item %help=()
                   4146: 
                   4147: Available help topics
                   4148: 
                   4149: =item mapread()
                   4150: 
1.344     bisitz   4151: Mapread read maps into LONCAPA::map:: global arrays
1.329     droeschl 4152: @order and @resources, determines status
                   4153: sets @order - pointer to resources in right order
                   4154: sets @resources - array with the resources with correct idx
                   4155: 
                   4156: =item authorhosts()
                   4157: 
                   4158: Return hash with valid author names
                   4159: 
                   4160: =item clean()
                   4161: 
                   4162: =item dumpcourse()
                   4163: 
                   4164:     Actually dump course
                   4165: 
                   4166: =item group_import()
                   4167: 
                   4168:     Imports the given (name, url) resources into the course
                   4169:     coursenum, coursedom, and folder must precede the list
                   4170: 
                   4171: =item breadcrumbs()
                   4172: 
                   4173: =item log_docs()
                   4174: 
                   4175: =item docs_change_log()
                   4176: 
                   4177: =item update_paste_buffer()
                   4178: 
                   4179: =item print_paste_buffer()
                   4180: 
                   4181: =item do_paste_from_buffer()
                   4182: 
                   4183: =item update_parameter()
                   4184: 
                   4185: =item handle_edit_cmd()
                   4186: 
                   4187: =item editor()
                   4188: 
                   4189: =item process_file_upload()
                   4190: 
                   4191: =item process_secondary_uploads()
                   4192: 
                   4193: =item is_supplemental_title()
                   4194: 
                   4195: =item entryline()
                   4196: 
                   4197: =item tiehash()
                   4198: 
                   4199: =item untiehash()
                   4200: 
                   4201: =item checkonthis()
                   4202: 
                   4203: check on this
                   4204: 
                   4205: =item verifycontent()
                   4206: 
                   4207: Verify Content
                   4208: 
                   4209: =item devalidateversioncache() & checkversions()
                   4210: 
                   4211: Check Versions
                   4212: 
                   4213: =item mark_hash_old()
                   4214: 
                   4215: =item is_hash_old()
                   4216: 
                   4217: =item changewarning()
                   4218: 
                   4219: =item init_breadcrumbs()
                   4220: 
                   4221: Breadcrumbs for special functions
                   4222: 
1.484     raeburn  4223: =item create_list_elements()
                   4224: 
                   4225: =item create_form_ul()
                   4226: 
                   4227: =item startContentScreen() 
                   4228: 
                   4229: =item endContentScreen()
                   4230: 
                   4231: =item supplemental_base()
                   4232: 
                   4233: =item embedded_form_elems()
                   4234: 
                   4235: =item embedded_destination()
                   4236: 
                   4237: =item return_to_editor()
                   4238: 
                   4239: =item decompression_info()
                   4240: 
                   4241: =item decompression_phase_one()
                   4242: 
                   4243: =item decompression_phase_two()
                   4244: 
                   4245: =item remove_archive()
                   4246: 
                   4247: =item generate_admin_menu()
                   4248: 
                   4249: =item generate_edit_table()
                   4250: 
                   4251: =item editing_js()
                   4252: 
                   4253: =item history_tab_js()
                   4254: 
                   4255: =item inject_data_js()
                   4256: 
                   4257: =item dump_switchserver_js()
                   4258: 
1.485     raeburn  4259: =item resize_scrollbox_js()
1.484     raeburn  4260: 
                   4261: =item makedocslogform()
                   4262: 
1.485     raeburn  4263: =item makesimpleeditform()
                   4264: 
1.329     droeschl 4265: =back
                   4266: 
                   4267: =cut

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