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

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

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