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

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

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