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

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

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