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

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

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