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

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

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