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

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

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