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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Documents
1.1       www         3: #
1.204   ! raeburn     4: # $Id: londocs.pm,v 1.203 2005/08/30 15:41:32 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.7       www        36: use Apache::lonratedt;
                     37: use Apache::lonratsrv;
1.15      www        38: use Apache::lonxml;
1.74      www        39: use Apache::loncreatecourse;
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.7       www        45: 
1.8       www        46: my $iconpath;
1.7       www        47: 
1.27      www        48: my %hash;
                     49: 
                     50: my $hashtied;
1.29      www        51: my %alreadyseen=();
1.27      www        52: 
1.40      www        53: my $hadchanges;
                     54: 
1.47      www        55: # Available help topics
                     56: 
                     57: my %help=();
                     58: 
1.7       www        59: # Mapread read maps into lonratedt::global arrays 
1.10      www        60: # @order and @resources, determines status
1.7       www        61: # sets @order - pointer to resources in right order
                     62: # sets @resources - array with the resources with correct idx
                     63: #
                     64: 
                     65: sub mapread {
                     66:     my ($coursenum,$coursedom,$map)=@_;
                     67:     return
                     68:       &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                     69:                                 $map);
                     70: }
                     71: 
                     72: sub storemap {
                     73:     my ($coursenum,$coursedom,$map)=@_;
1.104     albertel   74:     my ($outtext,$errtext)=
1.7       www        75:       &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.15      www        76:                                 $map,1);
1.104     albertel   77:     if ($errtext) { return ($errtext,2); }
                     78:     
                     79:     $hadchanges=1;
                     80:     return ($errtext,0);
1.7       www        81: }
                     82: 
1.74      www        83: # ----------------------------------------- Return hash with valid author names
                     84: 
                     85: sub authorhosts {
                     86:     my %outhash=();
                     87:     my $home=0;
                     88:     my $other=0;
1.174     albertel   89:     foreach (keys %env) {
1.74      www        90: 	if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
                     91: 	    my $role=$1;
                     92: 	    my $realm=$2;
1.174     albertel   93: 	    my ($start,$end)=split(/\./,$env{$_});
1.74      www        94: 	    if (($start) && ($start>time)) { next; }
                     95: 	    if (($end) && (time>$end)) { next; }
                     96: 	    my $ca; my $cd;
                     97: 	    if ($1 eq 'au') {
1.174     albertel   98: 		$ca=$env{'user.name'};
                     99: 		$cd=$env{'user.domain'};
1.74      www       100: 	    } else {
                    101: 		($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
                    102: 	    }
1.107     albertel  103: 	    my $allowed=0;
                    104: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
                    105: 	    my @ids=&Apache::lonnet::current_machine_ids();
                    106: 	    foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
                    107: 	    if ($allowed) {
1.74      www       108: 		$home++;
                    109: 		$outhash{'home_'.$ca.'@'.$cd}=1;
                    110: 	    } else {
1.107     albertel  111: 		$outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
1.74      www       112: 		$other++;
                    113: 	    }
                    114: 	}
                    115:     }
                    116:     return ($home,$other,%outhash);
                    117: }
                    118: # ------------------------------------------------------ Generate "dump" button
                    119: 
                    120: sub dumpbutton {
                    121:     my ($home,$other,%outhash)=&authorhosts();
                    122:     if ($home+$other==0) { return ''; }
                    123:     my $output='</td><td bgcolor="#DDDDCC">';
                    124:     if ($home) {
                    125: 	return '</td><td bgcolor="#DDDDCC">'.
1.81      www       126: 	    '<input type="submit" name="dumpcourse" value="'.
1.130     www       127: 	    &mt('Dump Course DOCS to Construction Space').'" />'.
                    128: 	    &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
1.74      www       129:     } else {
                    130: 	return'</td><td bgcolor="#DDDDCC">'.
1.81      www       131:      &mt('Dump Course DOCS to Construction Space: available on other servers');
1.74      www       132:     }
                    133: }
                    134: 
1.164     albertel  135: sub clean {
                    136:     my ($title)=@_;
                    137:     $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
                    138:     return $title;	
                    139: }
1.74      www       140: # -------------------------------------------------------- Actually dump course
                    141: 
                    142: sub dumpcourse {
1.75      www       143:     my $r=shift;
1.167     albertel  144:     my $html=&Apache::lonxml::xmlbegin();
                    145:     $r->print($html.'<head><title>Dump DOCS</title></head>'.
1.76      www       146:         &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
                    147: 	      '<form name="dumpdoc" method="post">');
1.74      www       148:     my ($home,$other,%outhash)=&authorhosts();
1.75      www       149:     unless ($home) { return ''; }
1.174     albertel  150:     my $origcrsid=$env{'request.course.id'};
1.76      www       151:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
1.174     albertel  152:     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
1.76      www       153: # Do the dumping
1.174     albertel  154: 	unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }
                    155: 	my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
1.87      www       156: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
1.174     albertel  157: 	my $title=$env{'form.authorfolder'};
1.201     albertel  158: 	my ($ext)=($title=~s/\.(\w+)$//);
1.164     albertel  159: 	$title=&clean($title);
1.201     albertel  160: 	$title.='.'.$ext;
1.79      www       161: 	my %replacehash=();
1.174     albertel  162: 	foreach (keys %env) {
1.79      www       163: 	    if ($_=~/^form\.namefor\_(.+)/) {
1.174     albertel  164: 		$replacehash{$1}=$env{$_};
1.79      www       165: 	    }
                    166: 	}
1.174     albertel  167: 	my $crs='/uploaded/'.$env{'request.course.id'}.'/';
1.79      www       168: 	$crs=~s/\_/\//g;
                    169: 	foreach (keys %replacehash) {
                    170: 	    my $newfilename=$title.'/'.$replacehash{$_};
1.164     albertel  171: 	    $newfilename=&clean($newfilename);
1.79      www       172: 	    my @dirs=split(/\//,$newfilename);
                    173: 	    my $path='/home/'.$ca.'/public_html';
                    174: 	    my $makepath=$path;
                    175: 	    my $fail=0;
                    176: 	    for (my $i=0;$i<$#dirs;$i++) {
                    177: 		$makepath.='/'.$dirs[$i];
                    178: 		unless (-e $makepath) { 
                    179: 		    unless(mkdir($makepath,0777)) { $fail=1; } 
                    180: 		}
                    181: 	    }
                    182: 	    $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
                    183: 	    if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
                    184: 		if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
                    185: 		    print $fh &Apache::loncreatecourse::rewritefile(
1.174     albertel  186:          &Apache::loncreatecourse::readfile($env{'request.course.id'},$_),
1.79      www       187: 				     (%replacehash,$crs => '')
                    188: 								    );
                    189: 		} else {
                    190: 		    print $fh
1.174     albertel  191:          &Apache::loncreatecourse::readfile($env{'request.course.id'},$_);
1.79      www       192: 		       }
                    193: 		$fh->close();
                    194: 	    } else {
                    195: 		$fail=1;
                    196: 	    }
                    197: 	    if ($fail) {
                    198: 		$r->print('<font color="red">fail</font>');
                    199: 	    } else {
                    200: 		$r->print('<font color="green">ok</font>');
                    201: 	    }
                    202: 	}
1.76      www       203:     } else {
                    204: # Input form
                    205: 	unless ($home==1) {
                    206: 	    $r->print(
1.81      www       207: 		      '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
1.76      www       208: 	}
                    209: 	foreach (sort keys %outhash) {
                    210: 	    if ($_=~/^home_(.+)$/) {
                    211: 		if ($home==1) {
                    212: 		    $r->print(
                    213: 		  '<input type="hidden" name="authorspace" value="'.$1.'" />');
                    214: 		} else {
1.133     www       215: 		    $r->print('<option value="'.$1.'">'.$1.' - '.
                    216: 			      &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
1.76      www       217: 		}
                    218: 	    }
                    219: 	}
                    220: 	unless ($home==1) {
                    221: 	    $r->print('</select>');
                    222: 	}
                    223: 	my $title=$origcrsdata{'description'};
                    224: 	$title=~s/\s+/\_/gs;
1.164     albertel  225: 	$title=&clean($title);
1.81      www       226: 	$r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
1.76      www       227: 	&tiehash();
1.81      www       228: 	$r->print('<h3>'.&mt('Filenames in Construction Space').'</h3><table border="2"><tr><th>'.&mt('Internal Filename').'</th><th>'.&mt('Title').'</th><th>'.&mt('Save as ...').'</th></tr>');
1.76      www       229: 	foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
1.78      www       230: 	    $r->print('<tr><td>'.$_.'</td>');
                    231: 	    my ($ext)=($_=~/\.(\w+)$/);
                    232: 	    my $title=$hash{'title_'.$hash{
                    233: 		'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
1.163     albertel  234: 	    $title=~s/&colon;/:/g;
1.78      www       235: 	    $r->print('<td>'.($title?$title:'&nbsp;').'</td>');
                    236: 	    unless ($title) {
                    237: 		$title=$_;
                    238: 	    }
                    239: 	    $title=~s/\.(\w+)$//;
1.164     albertel  240: 	    $title=&clean($title);
1.78      www       241: 	    $title.='.'.$ext;
1.79      www       242: 	    $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
1.76      www       243: 	}
1.78      www       244: 	$r->print("</table>\n");
1.76      www       245: 	&untiehash();
                    246: 	$r->print(
1.81      www       247:   '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump Course DOCS').'" /></p></form>');
1.75      www       248:     }
1.74      www       249: }
1.76      www       250: 
1.138     raeburn   251: # ------------------------------------------------------ Generate "export" button
                    252: 
                    253: sub exportbutton {
                    254:     return '</td><td bgcolor="#DDDDCC">'.
                    255:             '<input type="submit" name="exportcourse" value="'.
1.204   ! raeburn   256:             &mt('Export Course to IMS').'" />'.
1.203     raeburn   257:     &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
1.138     raeburn   258: }
                    259: 
                    260: sub exportcourse {
                    261:     my $r=shift;
                    262:     my %discussiontime = &Apache::lonnet::dump('discussiontimes',
1.174     albertel  263:                                                $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
1.138     raeburn   264:     my $numdisc = keys %discussiontime;
                    265:     my $navmap = Apache::lonnavmaps::navmap->new();
                    266:     my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
                    267:     my $curRes;
1.143     raeburn   268:     my $outcome;
1.138     raeburn   269: 
                    270:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    271:                                             ['finishexport']);
1.174     albertel  272:     if ($env{'form.finishexport'}) {
1.138     raeburn   273:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    274:                                             ['archive','discussion']);
                    275: 
1.175     albertel  276:         my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
                    277:         my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
1.143     raeburn   278:         if (@exportitems == 0 && @discussions == 0) {
                    279:             $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';
                    280:         } else {
                    281:             my $now = time;
                    282:             my %symbs;
                    283:             my $manifestok = 0;
                    284:             my $imsresources;
                    285:             my $tempexport;
                    286:             my $copyresult;
                    287:             my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
                    288:             if ($manifestok) {
1.157     raeburn   289:                 &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
1.143     raeburn   290:                 close($ims_manifest);
                    291: 
                    292: #Create zip file in prtspool
                    293:                 my $imszipfile = '/prtspool/'.
1.174     albertel  294:                 $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.143     raeburn   295:                    time.'_'.rand(1000000000).'.zip';
                    296:                 my $cwd = &Cwd::getcwd();
                    297:                 my $imszip = '/home/httpd/'.$imszipfile;
                    298:                 chdir $tempexport;
                    299:                 open(OUTPUT, "zip -r $imszip *  2> /dev/null |");
                    300:                 close(OUTPUT);
                    301:                 chdir $cwd;
                    302:                 $outcome .= 'Download the zip file from <a href="'.$imszipfile.'">IMS course archive</a><br />';
                    303:                 if ($copyresult) {
                    304:                     $outcome .= 'The following errors occurred during export - '.$copyresult;
1.138     raeburn   305:                 }
1.143     raeburn   306:             } else {
                    307:                 $outcome = '<br />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   308:             }
                    309:         }
1.167     albertel  310: 	my $html=&Apache::lonxml::xmlbegin();
                    311:         $r->print($html.'<head><title>Export Course</title></head>'.
1.158     raeburn   312:             &Apache::loncommon::bodytag('Export course to IMS content package'));
1.143     raeburn   313:         $r->print($outcome);
1.138     raeburn   314:         $r->print('</body></html>');
                    315:     } else {
                    316:         my $display;
                    317:         $display = '<form name="exportdoc" method="post">'."\n";
                    318:         $display .= 'Choose which items you wish to export from your course.<br /><br />';
                    319:         $display .= '<table border="0" cellspacing="0" cellpadding="3">'.
                    320:                     '<tr><td><fieldset><legend>&nbsp;<b>Content items</b></legend>'.
                    321:                     '<input type="button" value="check all" '.
                    322:                     'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
                    323:                     '&nbsp;&nbsp;<input type="button" value="uncheck all"'.
                    324:                     ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.
                    325:                     '<td>&nbsp;</td><td>&nbsp;</td>'.
                    326:                     '<td align="right"><fieldset><legend>&nbsp;<b>Discussion posts'.
                    327:                     '</b></legend><input type="button" value="check all"'.
                    328:                     ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
                    329:                     '&nbsp;&nbsp;<input type="button" value="uncheck all"'.
                    330:                     ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.
                    331:                     '</tr></table>';
                    332:         my $curRes;
                    333:         my $depth = 0;
                    334:         my $count = 0;
                    335:         my $boards = 0;
                    336:         my $startcount = 5;
                    337:         my %parent = ();
                    338:         my %children = ();
                    339:         my $lastcontainer = $startcount;
                    340:         my @bgcolors = ('#F6F6F6','#FFFFFF');
                    341:         $display .= '<table cellspacing="0"><tr>'.
                    342:             '<td><b>Export content item?<br /></b></td><td>&nbsp;</td><td align="right">'."\n";
                    343:         if ($numdisc > 0) {
                    344:             $display.='<b>Export&nbsp;discussion posts?</b>'."\n";
                    345:         }
                    346:         $display.='&nbsp;</td></tr>';
                    347:         while ($curRes = $it->next()) {
                    348:             if (ref($curRes)) {
                    349:                 $count ++;
                    350:             }
                    351:             if ($curRes == $it->BEGIN_MAP()) {
                    352:                 $depth++;
                    353:                 $parent{$depth} = $lastcontainer;
                    354:             }
                    355:             if ($curRes == $it->END_MAP()) {
                    356:                 $depth--;
                    357:                 $lastcontainer = $parent{$depth};
                    358:             }
                    359:             if (ref($curRes)) {
                    360:                 my $symb = $curRes->symb();
1.158     raeburn   361:                 my $ressymb = $symb;
                    362:                 if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {
                    363:                     unless ($ressymb =~ m|adm/wrapper/adm|) {
                    364:                         $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
                    365:                     }
                    366:                 }
1.138     raeburn   367:                 my $color = $count%2;
                    368:                 $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".
                    369:                     '<input type="checkbox" name="archive" value="'.$count.'" ';
                    370:                 if (($curRes->is_sequence()) || ($curRes->is_page())) {
                    371:                     my $checkitem = $count + $boards + $startcount;
                    372:                     $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';
                    373:                 }
                    374:                 $display .= ' />'."\n";
                    375:                 for (my $i=0; $i<$depth; $i++) {
                    376:                     $display .= '<img src="/adm/lonIcons/whitespace1.gif" width="25" height="1" alt="" border="0" /><img src="/adm/lonIcons/whitespace1.gif" width="25" height="1" alt="" border="0" />'."\n";
                    377:                 }
                    378:                 if ($curRes->is_sequence()) {
                    379:                     $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif">&nbsp;'."\n";
                    380:                     $lastcontainer = $count + $startcount + $boards;
                    381:                 } elsif ($curRes->is_page()) {
                    382:                     $display .= '<img src="/adm/lonIcons/navmap.page.open.gif">&nbsp;'."\n";
                    383:                     $lastcontainer = $count + $startcount + $boards;
                    384:                 }
                    385:                 my $currelem = $count+$boards+$startcount;
                    386:                 $children{$parent{$depth}} .= $currelem.':';
                    387:                 $display .= '&nbsp;'.$curRes->title().'</td>';
1.158     raeburn   388:                 if ($discussiontime{$ressymb} > 0) {
1.138     raeburn   389:                     $boards ++;
                    390:                     $currelem = $count+$boards+$startcount;
                    391:                     $display .= '<td>&nbsp;</td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" />&nbsp;</td>'."\n";
                    392:                 } else {
                    393:                     $display .= '<td colspan="2">&nbsp;</td>'."\n";
                    394:                 }
                    395:             }
                    396:         }
                    397:         my $scripttag = qq|
                    398: <script>
                    399: 
                    400: function checkAll(field) {
1.158     raeburn   401:     if (field.length > 0) {
                    402:         for (i = 0; i < field.length; i++) {
                    403:             field[i].checked = true ;
                    404:         }
                    405:     } else {
                    406:         field.checked = true
                    407:     }
1.138     raeburn   408: }
1.158     raeburn   409:                                                                                 
1.138     raeburn   410: function uncheckAll(field) {
1.158     raeburn   411:     if (field.length > 0) {
                    412:         for (i = 0; i < field.length; i++) {
                    413:             field[i].checked = false ;
                    414:         }
                    415:     } else {
                    416:         field.checked = false ;
                    417:     }
1.138     raeburn   418: }
                    419: 
                    420: function propagateCheck(item) {
                    421:     if (document.exportdoc.elements[item].checked == true) {
                    422:         containerCheck(item)
                    423:     }
                    424: } 
                    425: 
                    426: function containerCheck(item) {
                    427:     document.exportdoc.elements[item].checked = true
                    428:     var numitems = $count + $boards + $startcount
                    429:     var parents = new Array(numitems)
                    430:     for (var i=$startcount; i<numitems; i++) {
                    431:         parents[i] = new Array
                    432:     }
                    433:         |;
                    434: 
                    435:         foreach my $container (sort { $a <=> $b } keys %children) {
                    436:             my @contents = split/:/,$children{$container};
                    437:             for (my $i=0; $i<@contents; $i ++) {
                    438:                 $scripttag .= '    parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
                    439:             }
                    440:         }
                    441: 
                    442:         $scripttag .= qq|
                    443:     if (parents[item].length > 0) {
                    444:         for (var j=0; j<parents[item].length; j++) {
                    445:             containerCheck(parents[item][j])
                    446:         }
                    447:      }   
                    448: }
                    449: 
                    450: </script>
                    451:         |;
1.167     albertel  452: 	my $html=&Apache::lonxml::xmlbegin();
                    453:         $r->print($html.'<head><title>Export Course</title>'.$scripttag.'</head>'.
1.158     raeburn   454:             &Apache::loncommon::bodytag('Export course to IMS content package'
1.138     raeburn   455: ));
                    456: 
                    457:         $r->print($display.'</table>'.
                    458:                   '<p><input type="hidden" name="finishexport" value="1">'.
                    459:                   '<input type="submit" name="exportcourse" value="'.
                    460:                   &mt('Export Course DOCS').'" /></p></form></body></html>');
                    461:     }
                    462: }
                    463: 
1.143     raeburn   464: sub create_ims_store {
                    465:     my ($now,$manifestok,$outcome,$tempexport) = @_;
                    466:     $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
                    467:     my $ims_manifest;
                    468:     if (!-e $$tempexport) {
                    469:         mkdir($$tempexport,0700);
                    470:     }
                    471:     $$tempexport .= '/'.$now;
                    472:     if (!-e $$tempexport) {
                    473:         mkdir($$tempexport,0700);
                    474:     }
1.174     albertel  475:     $$tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
1.143     raeburn   476:     if (!-e $$tempexport) {
                    477:         mkdir($$tempexport,0700);
                    478:     }
1.159     raeburn   479:     if (!-e "$$tempexport/resources") {
                    480:         mkdir("$$tempexport/resources",0700);
                    481:     }
1.143     raeburn   482: # open manifest file
                    483:     my $manifest = '/imsmanifest.xml';
                    484:     my $manifestfilename = $$tempexport.$manifest;
                    485:     if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
                    486:         $$manifestok=1;
                    487:         print $ims_manifest
                    488: '<?xml version="1.0" encoding="UTF-8"?>'."\n".
                    489: '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
                    490: ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
                    491: ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
1.174     albertel  492: ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'.
1.143     raeburn   493: '  xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
                    494: '  http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
1.199     raeburn   495: '  <metadata>
                    496:     <schema></schema>
                    497:     <imsmd:lom>
                    498:       <imsmd:general>
                    499:         <imsmd:identifier>'.$env{'request.course.id'}.'</imsmd:identifier>
                    500:         <imsmd:title>
                    501:           <imsmd:langstring xml:lang="en">'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</imsmd:langstring>
                    502:         </imsmd:title>
                    503:       </imsmd:general>
                    504:     </imsmd:lom>
                    505:   </metadata>'."\n".
1.174     albertel  506: '  <organizations default="ORG-'.$env{'request.course.id'}.'-'.$now.'">'."\n".
                    507: '    <organization identifier="ORG-'.$env{'request.course.id'}.'-'.$now.'"'.
1.143     raeburn   508: ' structure="hierarchical">'."\n".
1.199     raeburn   509: '      <title>'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</title>'
1.143     raeburn   510:     } else {
                    511:         $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
                    512: ;
                    513:     }
                    514:     return $ims_manifest;
                    515: }
                    516: 
                    517: sub build_package {
                    518:     my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
                    519: # first iterator to look for dependencies
                    520:     my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
                    521:     my $curRes;
                    522:     my $count = 0;
                    523:     my $depth = 0;
                    524:     my $lastcontainer = 0;
                    525:     my %parent = ();
                    526:     my @dependencies = ();
1.174     albertel  527:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    528:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.143     raeburn   529:     while ($curRes = $it->next()) {
                    530:         if (ref($curRes)) {
                    531:             $count ++;
                    532:         }
                    533:         if ($curRes == $it->BEGIN_MAP()) {
                    534:             $depth++;
                    535:             $parent{$depth} = $lastcontainer;
                    536:         }
                    537:         if ($curRes == $it->END_MAP()) {
                    538:             $depth--;
                    539:             $lastcontainer = $parent{$depth};
                    540:         }
                    541:         if (ref($curRes)) {
                    542:             if ($curRes->is_sequence() || $curRes->is_page()) {
                    543:                 $lastcontainer = $count;
                    544:             }
                    545:             if (grep/^$count$/,@$exportitems) {
                    546:                 &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
                    547:             }
                    548:         }
                    549:     }
                    550: # second iterator to build manifest and store resources
                    551:     $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
                    552:     $depth = 0;
                    553:     my $prevdepth;
                    554:     $count = 0;
                    555:     my $imsresources;
                    556:     my $pkgdepth;
1.157     raeburn   557:     while ($curRes = $it->next()) {
                    558:         if ($curRes == $it->BEGIN_MAP()) {
                    559:             $prevdepth = $depth;
                    560:             $depth++;
                    561:         }
                    562:         if ($curRes == $it->END_MAP()) {
1.143     raeburn   563:             $prevdepth = $depth;
1.157     raeburn   564:             $depth--;
                    565:         }
                    566: 
                    567:         if (ref($curRes)) {
                    568:             $count ++;
                    569:             if ((grep/^$count$/,@$exportitems) || (grep/^$count$/,@dependencies)) {
                    570:                 my $symb = $curRes->symb();
                    571:                 my $isvisible = 'true';
                    572:                 my $resourceref;
                    573:                 if ($curRes->randomout()) {
                    574:                     $isvisible = 'false';
                    575:                 }
                    576:                 unless ($curRes->is_sequence()) {
1.174     albertel  577:                     $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"';
1.157     raeburn   578:                 }
1.199     raeburn   579:                 my $step = $prevdepth - $depth;
                    580:                 if (($step >= 0) && ($count > 1)) {
                    581:                     while ($step >= 0) {
                    582:                         print $ims_manifest "\n".'  </item>'."\n";
                    583:                         $step --;
                    584:                     }
1.157     raeburn   585:                 }
                    586:                 $prevdepth = $depth;
1.143     raeburn   587: 
1.157     raeburn   588:                 my $itementry =
1.174     albertel  589:               '<item identifier="ITEM-'.$env{'request.course.id'}.'-'.$count.
1.143     raeburn   590:               '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
                    591:               '<title>'.$curRes->title().'</title>';
1.157     raeburn   592:                 print $ims_manifest "\n".$itementry;
1.143     raeburn   593: 
1.157     raeburn   594:                 unless ($curRes->is_sequence()) {
                    595:                     my $content_file;
                    596:                     my @hrefs = ();
                    597:                     &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
                    598:                     if ($content_file) {
                    599:                         $imsresources .= "\n".
1.174     albertel  600:                      '   <resource identifier="RES-'.$env{'request.course.id'}.'-'.$count.
1.143     raeburn   601:                      '" type="webcontent" href="'.$content_file.'">'."\n".
                    602:                      '       <file href="'.$content_file.'" />'."\n";
1.157     raeburn   603:                         foreach (@hrefs) {
                    604:                             $imsresources .=
1.143     raeburn   605:                      '        <file href="'.$_.'" />'."\n";
1.157     raeburn   606:                         }
1.158     raeburn   607:                         if (grep/^$count$/,@$discussions) {
                    608:                             my $ressymb = $symb;
                    609:                             my $mode;
                    610:                             if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {
                    611:                                 unless ($ressymb =~ m|adm/wrapper/adm|) {
                    612:                                     $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
                    613:                                 }
                    614:                                 $mode = 'board';
                    615:                             }
                    616:                             my %extras = (
                    617:                                           caller => 'imsexport',
1.159     raeburn   618:                                           tempexport => $tempexport.'/resources',
1.158     raeburn   619:                                           count => $count
                    620:                                          );
                    621:                             my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
                    622:                         }
1.157     raeburn   623:                         $imsresources .= '    </resource>'."\n";
1.143     raeburn   624:                     }
                    625:                 }
1.157     raeburn   626:                 $pkgdepth = $depth;
1.143     raeburn   627:             }
                    628:         }
                    629:     }
1.157     raeburn   630:     while ($pkgdepth > 0) {
1.143     raeburn   631:         print $ims_manifest "    </item>\n";
                    632:         $pkgdepth --;
                    633:     }
                    634:     my $resource_text = qq|
                    635:     </organization>
                    636:   </organizations>
                    637:   <resources>
                    638:     $imsresources
                    639:   </resources>
                    640: </manifest>
                    641:     |;
                    642:     print $ims_manifest $resource_text;
                    643: }
                    644: 
                    645: sub get_dependencies {
                    646:     my ($exportitems,$parent,$depth,$dependencies) = @_;
                    647:     if ($depth > 1) {
1.157     raeburn   648:         if ((!grep/^$$parent{$depth}$/,@$exportitems) && (!grep/^$$parent{$depth}$/,@$dependencies)) {
1.143     raeburn   649:             push @$dependencies, $$parent{$depth};
                    650:             if ($depth > 2) {
                    651:                 &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
                    652:             }
                    653:         }
                    654:     }
                    655: }
                    656: 
                    657: sub process_content {
                    658:     my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
                    659:     my $content_type;
                    660:     my $message;
1.158     raeburn   661:     my @uploads = ();
1.157     raeburn   662:     if ($curRes->is_sequence()) {
                    663:         $content_type = 'sequence';
                    664:     } elsif ($curRes->is_page()) {
                    665:         $content_type = 'page'; # need to handle individual items in pages.
1.143     raeburn   666:     } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
                    667:         $content_type = 'syllabus';
1.158     raeburn   668:         my $contents = &Apache::imsexport::templatedpage($content_type);
                    669:         if ($contents) {
                    670:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    671:         }
1.157     raeburn   672:     } elsif ($symb =~ m-\.sequence___\d+___ext-) {
1.143     raeburn   673:         $content_type = 'external';
1.158     raeburn   674:         my $title = $curRes->title;
                    675:         my $contents =  &Apache::imsexport::external($symb,$title);
                    676:         if ($contents) {
                    677:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    678:         }
1.143     raeburn   679:     } elsif ($symb =~ m-adm/navmaps$-) {
                    680:         $content_type =  'navmap';
1.158     raeburn   681:     } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
1.143     raeburn   682:         $content_type = 'simplepage';
1.158     raeburn   683:         my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);
                    684:         if ($contents) {
                    685:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    686:         }
                    687:     } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {
1.143     raeburn   688:         $content_type = 'simpleproblem';
1.158     raeburn   689:         my $contents =  &Apache::imsexport::simpleproblem($symb);
                    690:         if ($contents) {
                    691:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    692:         }
1.188     raeburn   693:     } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {
1.158     raeburn   694:         $content_type = 'examupload';
                    695:     } elsif ($symb =~ m-adm/(\w+)/(\w+)/(\d+)/bulletinboard$-) {
1.143     raeburn   696:         $content_type = 'bulletinboard';
1.158     raeburn   697:         my $contents =  &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);
                    698:         if ($contents) {
                    699:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    700:         }
                    701:     } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {
1.143     raeburn   702:         $content_type = 'aboutme';
1.158     raeburn   703:         my $contents =  &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);
                    704:         if ($contents) {
                    705:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    706:         }
1.157     raeburn   707:     } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
                    708:         $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
1.162     raeburn   709:     } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
1.143     raeburn   710:         my $canedit = 0;
1.174     albertel  711:         if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'})  {
1.143     raeburn   712:             $canedit= 1;
                    713:         }
1.200     raeburn   714: # only include problem code where current user is author
1.143     raeburn   715:         if ($canedit) {
1.157     raeburn   716:             $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
1.143     raeburn   717:         } else {
1.157     raeburn   718:             $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
1.143     raeburn   719:         }
1.162     raeburn   720:     } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
                    721:         $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
1.143     raeburn   722:     }
1.158     raeburn   723:     if (@uploads > 0) {
                    724:         foreach my $item (@uploads) {
                    725:             my $uploadmsg = '';
1.159     raeburn   726:             &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
1.158     raeburn   727:             if ($uploadmsg) {
                    728:                 $$copyresult .= $uploadmsg."\n";
                    729:             }
                    730:         }
                    731:     }
1.157     raeburn   732:     if ($message) {
                    733:         $$copyresult .= $message."\n";
                    734:     }
1.143     raeburn   735: }
                    736: 
                    737: sub replicate_content {
1.157     raeburn   738:     my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
1.159     raeburn   739:     my ($map,$ind,$url);
                    740:     if ($caller eq 'templateupload') {
                    741:         $url = $symb;
                    742:         $url =~ s#//#/#g;
                    743:     } else { 
                    744:         ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                    745:     }
1.143     raeburn   746:     my $content;
                    747:     my $filename;
                    748:     my $repstatus;
1.157     raeburn   749:     my $content_name;
                    750:     if ($url =~ m-/([^/]+)$-) {
1.143     raeburn   751:         $filename = $1;
                    752:         if (!-e $tempexport.'/resources') {
                    753:             mkdir($tempexport.'/resources',0700);
                    754:         }
1.157     raeburn   755:         if (!-e $tempexport.'/resources/'.$count) {
1.143     raeburn   756:             mkdir($tempexport.'/resources/'.$count,0700);
                    757:         }
1.157     raeburn   758:         my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
1.143     raeburn   759:         my $copiedfile;
                    760:         if ($copiedfile = Apache::File->new('>'.$destination)) {
                    761:             my $content;
1.157     raeburn   762:             if ($caller eq 'resource') {
1.197     raeburn   763:                 my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
                    764:                 my $filepath = &Apache::lonnet::filelocation($respath,$url);
                    765:                 $content = &Apache::lonnet::getfile($filepath);
1.143     raeburn   766:                 if ($content eq -1) {
                    767:                     $$message = 'Could not copy file '.$filename;
                    768:                 } else {
1.197     raeburn   769:                     &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');
1.143     raeburn   770:                     $repstatus = 'ok';
                    771:                 }
1.162     raeburn   772:             } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
1.143     raeburn   773:                 my $rtncode;
1.157     raeburn   774:                 $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
                    775:                 if ($repstatus eq 'ok') {
                    776:                     if ($url =~ /\.html?$/i) {
1.197     raeburn   777:                         &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');
1.157     raeburn   778:                     }
                    779:                 } else {
1.197     raeburn   780:                     $$message = 'Could not render '.$url.' server message - '.$rtncode."<br />\n";
1.143     raeburn   781:                 }
1.162     raeburn   782:             } elsif ($caller eq 'noedit') {
                    783: # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this. 
                    784:                 $repstatus = 'ok';
                    785:                 $content = 'Not the owner of this resource'; 
1.143     raeburn   786:             }
                    787:             if ($repstatus eq 'ok') {
                    788:                 print $copiedfile $content;
                    789:             }
                    790:             close($copiedfile);
                    791:         } else {
1.197     raeburn   792:             $$message = 'Could not open destination file for '.$filename."<br />\n";
1.143     raeburn   793:         }
                    794:     } else {
1.197     raeburn   795:         $$message = 'Could not determine name of file for '.$symb."<br />\n";
1.143     raeburn   796:     }
1.157     raeburn   797:     if ($repstatus eq 'ok') {
1.198     raeburn   798:         $content_name = 'resources/'.$count.'/'.$filename;
1.157     raeburn   799:     }
                    800:     return $content_name;
                    801: }
                    802: 
                    803: sub extract_media {
1.197     raeburn   804:     my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
1.198     raeburn   805:     my ($dirpath,$container);
1.197     raeburn   806:     my %allfiles = ();
                    807:     my %codebase = ();
1.198     raeburn   808:     if ($url =~ m-(.*/)([^/]+)$-) {
                    809:         $dirpath = $1;
                    810:         $container = $2;
                    811:     } else {
                    812:         $dirpath = $url;
                    813:         $container = '';
                    814:     }
1.197     raeburn   815:     &Apache::lonnet::extract_embedded_items(undef,undef,\%allfiles,\%codebase,$content);
                    816:     foreach my $embed_file (keys(%allfiles)) {
                    817:         my $filename;
                    818:         if ($embed_file =~ m#([^/]+)$#) {
                    819:             $filename = $1;
                    820:         } else {
                    821:             $filename = $embed_file;
                    822:         }
                    823:         my $newname = 'res/'.$filename;
                    824:         my ($rtncode,$embed_content,$repstatus);
                    825:         my $embed_url;
                    826:         if ($embed_file =~ m-^/-) {
                    827:             $embed_url = $embed_file;           # points to absolute path
                    828:         } else {
                    829:             if ($embed_file =~ m-https?://-) {
                    830:                 next;                           # points to url
                    831:             } else {
1.198     raeburn   832:                 $embed_url = $dirpath.$embed_file;  # points to relative path
1.197     raeburn   833:             }
                    834:         }
                    835:         if ($caller eq 'resource') {
                    836:             my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';  
                    837:             my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url); 
                    838:             $embed_content = &Apache::lonnet::getfile($embed_path);
                    839:             unless ($embed_content eq -1) {
                    840:                 $repstatus = 'ok';
                    841:             }
                    842:         } elsif ($caller eq 'uploaded') {
                    843:             
                    844:             $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
                    845:         }
                    846:         if ($repstatus eq 'ok') {
                    847:             my $destination = $tempexport.'/resources/'.$count.'/res';
                    848:             if (!-e "$destination") {
                    849:                 mkdir($destination,0755);
                    850:             }
                    851:             $destination .= '/'.$filename;
                    852:             my $copiedfile;
                    853:             if ($copiedfile = Apache::File->new('>'.$destination)) {
                    854:                 print $copiedfile $embed_content;
1.198     raeburn   855:                 push @{$href}, 'resources/'.$count.'/res/'.$filename;
1.197     raeburn   856:                 my $attrib_regexp = '';
                    857:                 if (@{$allfiles{$embed_file}} > 1) {
                    858:                     $attrib_regexp = join('|',@{$allfiles{$embed_file}});
                    859:                 } else {
                    860:                     $attrib_regexp = $allfiles{$embed_file}[0];
                    861:                 }
                    862:                 $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
1.198     raeburn   863:                 if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {
1.197     raeburn   864:                     $$content =~ s#\Q$embed_file\E#$newname#gi;
                    865:                 }
                    866:             }
                    867:         } else {
                    868:             $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";
                    869:         }
                    870:     }
1.157     raeburn   871:     return;
1.143     raeburn   872: }
1.74      www       873: 
1.158     raeburn   874: sub store_template {
                    875:     my ($contents,$tempexport,$count,$content_type) = @_;
                    876:     if ($contents) {
1.159     raeburn   877:         if ($tempexport) {
                    878:             if (!-e $tempexport.'/resources') {
                    879:                 mkdir($tempexport.'/resources',0700);
                    880:             }
                    881:             if (!-e $tempexport.'/resources/'.$count) {
                    882:                 mkdir($tempexport.'/resources/'.$count,0700);
                    883:             }
                    884:             my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
                    885:             my $storetemplate;
                    886:             if ($storetemplate = Apache::File->new('>'.$destination)) {
                    887:                 print $storetemplate $contents;
                    888:                 close($storetemplate);
                    889:             }
                    890:             if ($content_type eq 'external') {
1.198     raeburn   891:                 return 'resources/'.$count.'/'.$content_type.'.html';
1.159     raeburn   892:             } else {
1.198     raeburn   893:                 return 'resources/'.$count.'/'.$content_type.'.xml';
1.159     raeburn   894:             }
1.158     raeburn   895:         }
                    896:     }
                    897: }
                    898: 
1.73      bowersj2  899: # Imports the given (name, url) resources into the course
                    900: # coursenum, coursedom, and folder must precede the list
                    901: sub group_import {
                    902:     my $coursenum = shift;
                    903:     my $coursedom = shift;
                    904:     my $folder = shift;
1.142     raeburn   905:     my $container = shift;
                    906:     my $caller = shift;
1.73      bowersj2  907:     while (@_) {
                    908: 	my $name = shift;
                    909: 	my $url = shift;
1.142     raeburn   910:         if (($url =~ m#^/uploaded/$coursedom/$coursenum/(default_\d+\.)(page|sequence)$#) && ($caller eq 'londocs')) {
                    911:             my $errtext = '';
                    912:             my $fatal = 0;
                    913:             my $newmapstr = '<map>'."\n".
                    914:                             '<resource id="1" src="" type="start"></resource>'."\n".
                    915:                             '<link from="1" to="2" index="1"></link>'."\n".
                    916:                             '<resource id="2" src="" type="finish"></resource>'."\n".
                    917:                             '</map>';
1.174     albertel  918:             $env{'form.output'}=$newmapstr;
1.189     albertel  919:             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1.142     raeburn   920:                                                 'output',$1.$2);
                    921:             if ($result != m|^/uploaded/|) {
                    922:                 $errtext.='Map not saved: A network error occured when trying to save the new map. ';
                    923:                 $fatal = 2;
                    924:             }
                    925:             if ($fatal) {
                    926:                 return ($errtext,$fatal);
                    927:             }
                    928:         }
1.73      bowersj2  929: 	if ($url) {
1.178     www       930: 	    my $idx = &Apache::lonratedt::getresidx($url);
1.73      bowersj2  931: 	    $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
                    932: 	    my $ext = 'false';
                    933: 	    if ($url=~/^http:\/\//) { $ext = 'true'; }
                    934: 	    $url =~ s/:/\&colon;/g;
                    935: 	    $name =~ s/:/\&colon;/g;
                    936: 	    $Apache::lonratedt::resources[$idx] = 
                    937: 		join ':', ($name, $url, $ext, 'normal', 'res');
                    938: 	}
                    939:     }
1.142     raeburn   940:     return &storemap($coursenum, $coursedom, $folder.'.'.$container);
1.73      bowersj2  941: }
                    942: 
1.114     albertel  943: sub breadcrumbs {
                    944:     my ($where)=@_;
                    945:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.142     raeburn   946:     my (@folders);
1.174     albertel  947:     if ($env{'form.pagepath'}) {
                    948:         @folders = split('&',$env{'form.pagepath'});
1.142     raeburn   949:     } else {
1.174     albertel  950:         @folders=split('&',$env{'form.folderpath'});
1.142     raeburn   951:     }
1.116     albertel  952:     my $folderpath;
1.168     www       953:     my $cpinfo='';
1.174     albertel  954:     if ($env{'form.markedcopy_url'}) {
                    955: 	&Apache::lonnet::logthis('Found '.$env{'form.markedcopy_url'});
1.168     www       956:        $cpinfo='&markedcopy_url='.
1.174     albertel  957:                &Apache::lonnet::escape($env{'form.markedcopy_url'}).
1.168     www       958:                '&markedcopy_title='.
1.174     albertel  959:                &Apache::lonnet::escape($env{'form.markedcopy_title'});
1.168     www       960:     }
1.116     albertel  961:     while (@folders) {
                    962: 	my $folder=shift(@folders);
                    963: 	my $foldername=shift(@folders);
                    964: 	if ($folderpath) {$folderpath.='&';}
                    965: 	$folderpath.=$folder.'&'.$foldername;
                    966: 	my $url='/adm/coursedocs?folderpath='.
                    967: 	    &Apache::lonnet::escape($folderpath);
1.114     albertel  968: 	    &Apache::lonhtmlcommon::add_breadcrumb(
1.168     www       969: 		      {'href'=>$url.$cpinfo,
1.114     albertel  970: 		       'title'=>&Apache::lonnet::unescape($foldername),
1.117     albertel  971: 		       'text'=>'<font size="+1">'.
                    972: 			   &Apache::lonnet::unescape($foldername).'</font>'
                    973: 		       });
1.114     albertel  974: 		       
                    975: 						 
                    976:     }
1.137     albertel  977:     return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,
                    978: 					       0,'nohelp');
1.114     albertel  979: }
                    980: 
1.7       www       981: sub editor {
1.188     raeburn   982:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output)=@_;
1.10      www       983:     my $errtext='';
                    984:     my $fatal=0;
1.142     raeburn   985:     my $container='sequence';
1.174     albertel  986:     if ($env{'form.pagepath'}) {
1.142     raeburn   987:         $container='page';
                    988:     }
1.10      www       989:     ($errtext,$fatal)=
1.142     raeburn   990:               &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.17      www       991:     if ($#Apache::lonratedt::order<1) {
1.178     www       992: 	my $idx=&Apache::lonratedt::getresidx();
                    993: 	if ($idx<=0) { $idx=1; }
                    994:        	$Apache::lonratedt::order[0]=$idx;
                    995:         $Apache::lonratedt::resources[$idx]='';
1.17      www       996:     }
1.174     albertel  997:     if (defined($env{'form.markcopy'})) {
1.168     www       998: # Mark for copying
1.174     albertel  999: 	my ($title,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$env{'form.markcopy'}]]);
                   1000: 	$env{'form.markedcopy_title'}=$title;
                   1001: 	$env{'form.markedcopy_url'}=$url;
1.168     www      1002:     }
                   1003:     $r->print(&breadcrumbs($folder));
1.7       www      1004:     if ($fatal) {
                   1005: 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1006:     } else {
                   1007: # ------------------------------------------------------------ Process commands
1.121     www      1008: 
1.16      www      1009: # ---------------- if they are for this folder and user allowed to make changes
1.174     albertel 1010: 	if (($allowed) && ($env{'form.folder'} eq $folder)) {
1.123     www      1011: # set parameters and change order
1.174     albertel 1012: 	    if (defined($env{'form.setparms'})) {
                   1013: 		my $idx=$env{'form.setparms'};
1.123     www      1014: # set parameters
1.174     albertel 1015: 		if ($env{'form.randpick_'.$idx}) {
                   1016: 		    &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos');
1.121     www      1017: 		} else {
1.122     www      1018: 		    &Apache::lonratedt::delparameter($idx,'parameter_randompick');
1.121     www      1019: 		}
1.174     albertel 1020: 		if ($env{'form.hidprs_'.$idx}) {
1.122     www      1021: 		    &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
1.121     www      1022: 		} else {
1.122     www      1023: 		    &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
1.121     www      1024: 		}
1.174     albertel 1025: 		if ($env{'form.encprs_'.$idx}) {
1.122     www      1026: 		    &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
1.121     www      1027: 		} else {
1.122     www      1028: 		    &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
1.121     www      1029: 		}
                   1030: 
1.174     albertel 1031: 		if ($env{'form.newpos'}) {
1.123     www      1032: # change order
                   1033: 
1.174     albertel 1034: 		    my $newpos=$env{'form.newpos'}-1;
                   1035: 		    my $currentpos=$env{'form.currentpos'}-1;
1.125     www      1036: 		    my $i;
                   1037: 		    my @neworder=();
                   1038: 		    if ($newpos>$currentpos) {
                   1039: # moving stuff up
                   1040: 			for ($i=0;$i<$currentpos;$i++) {
                   1041: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                   1042: 			}
                   1043: 			for ($i=$currentpos;$i<$newpos;$i++) {
                   1044: 			    $neworder[$i]=$Apache::lonratedt::order[$i+1];
                   1045: 			}
                   1046:                         $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
                   1047: 			for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
                   1048: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                   1049: 			}
                   1050: 		    } else {
                   1051: # moving stuff down
                   1052: 			for ($i=0;$i<$newpos;$i++) {
                   1053: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                   1054: 			}
                   1055: 			$neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
                   1056: 			for ($i=$newpos+1;$i<$currentpos+1;$i++) {
                   1057: 			    $neworder[$i]=$Apache::lonratedt::order[$i-1];
                   1058: 			}
                   1059: 			for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
                   1060: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                   1061: 			}
                   1062: 		    }
                   1063: 		    @Apache::lonratedt::order=@neworder;
1.124     www      1064: 		}
                   1065: # store the changed version
1.123     www      1066: 
1.142     raeburn  1067: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1.124     www      1068: 		if ($fatal) {
                   1069: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1070: 		    return;
1.123     www      1071: 		}
1.124     www      1072: 		
                   1073: 	    }
1.174     albertel 1074: 	    if ($env{'form.pastemarked'}) {
1.168     www      1075: # paste resource to end of list
1.174     albertel 1076:                 my $url=$env{'form.markedcopy_url'};
                   1077: 		my $title=$env{'form.markedcopy_title'};
1.168     www      1078: # Maps need to be copied first
                   1079: 		if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) {
                   1080: 		    $title=&mt('Copy of').' '.$title;
                   1081:                     my $newid=$$.time;
                   1082: 		    $url=~/^(.+)\.(\w+)$/;
                   1083: 		    my $newurl=$1.$newid.'.'.$2;
                   1084: 		    my $storefn=$newurl;
                   1085:                     $storefn=~s/^\/\w+\/\w+\/\w+\///;
                   1086: 		    &Apache::loncreatecourse::writefile
1.174     albertel 1087: 			($env{'request.course.id'},$storefn,
1.168     www      1088: 			 &Apache::lonnet::getfile($url));
                   1089: 		    $url=$newurl;
                   1090: 		}
                   1091: 		$title=~s/\</\&lt\;/g;
                   1092: 		$title=~s/\>/\&gt\;/g;
                   1093: 		$title=~s/\:/\&colon;/g;
                   1094: 		my $ext='false';
                   1095: 		if ($url=~/^http\:\/\//) { $ext='true'; }
                   1096: 		$url=~s/\:/\&colon;/g;
                   1097: # Now insert the URL at the bottom
1.179     www      1098:                 my $newidx=&Apache::lonratedt::getresidx($url);
1.168     www      1099: 		$Apache::lonratedt::resources[$newidx]=
                   1100: 		    $title.':'.$url.':'.$ext.':normal:res';
                   1101: 		$Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
                   1102: # Store the result
                   1103: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
                   1104: 		if ($fatal) {
                   1105: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1106: 		    return;
                   1107: 		}
1.123     www      1108: 
1.168     www      1109: 	    }
1.188     raeburn  1110:             $r->print($upload_output);
1.174     albertel 1111: 	    if ($env{'form.cmd'}) {
                   1112:                 my ($cmd,$idx)=split(/\_/,$env{'form.cmd'});
1.10      www      1113:                 if ($cmd eq 'del') {
1.128     albertel 1114: 		    my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
1.187     www      1115: 		    if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
                   1116: 			($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library)$/)) {
                   1117: 			&Apache::lonnet::removeuploadedurl($url);
                   1118: 		    } else {
                   1119: 			&Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]);
1.128     albertel 1120: 		    }
1.10      www      1121: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
                   1122:                         $Apache::lonratedt::order[$i]=
                   1123:                           $Apache::lonratedt::order[$i+1];
                   1124:                     }
                   1125:                     $#Apache::lonratedt::order--;
1.171     www      1126:                 } elsif ($cmd eq 'cut') {
                   1127: 		    my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
1.179     www      1128: 		    &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]);
1.171     www      1129: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
                   1130:                         $Apache::lonratedt::order[$i]=
                   1131:                           $Apache::lonratedt::order[$i+1];
                   1132:                     }
                   1133:                     $#Apache::lonratedt::order--;
1.10      www      1134:                 } elsif ($cmd eq 'up') {
1.38      www      1135: 		  if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
1.10      www      1136:                     my $i=$Apache::lonratedt::order[$idx-1];
                   1137:                     $Apache::lonratedt::order[$idx-1]=
                   1138: 			$Apache::lonratedt::order[$idx];
                   1139:                     $Apache::lonratedt::order[$idx]=$i;
1.38      www      1140: 		   }
1.10      www      1141:                 } elsif ($cmd eq 'down') {
1.38      www      1142: 		   if (defined($Apache::lonratedt::order[$idx+1])) {
1.10      www      1143:                     my $i=$Apache::lonratedt::order[$idx+1];
                   1144:                     $Apache::lonratedt::order[$idx+1]=
                   1145: 			$Apache::lonratedt::order[$idx];
                   1146:                     $Apache::lonratedt::order[$idx]=$i;
1.38      www      1147: 		   }
1.36      www      1148:                 } elsif ($cmd eq 'rename') {
1.142     raeburn  1149:                     my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]];
1.36      www      1150:                     my ($rtitle,@rrest)=split(/\:/,
                   1151:                        $Apache::lonratedt::resources[
                   1152: 				       $Apache::lonratedt::order[$idx]]);
1.38      www      1153:                     my $comment=
1.174     albertel 1154:                      &HTML::Entities::decode($env{'form.title'});
1.36      www      1155:                     $comment=~s/\</\&lt\;/g;
                   1156:                     $comment=~s/\>/\&gt\;/g;
                   1157:                     $comment=~s/\:/\&colon;/g;
1.144     albertel 1158: 		    if ($comment=~/\S/) {
                   1159: 			$Apache::lonratedt::resources[
1.36      www      1160: 				       $Apache::lonratedt::order[$idx]]=
1.144     albertel 1161: 				            $comment.':'.join(':',@rrest);
                   1162: 		    }
1.10      www      1163:                 }
                   1164: # Store the changed version
1.104     albertel 1165: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142     raeburn  1166: 					    $folder.'.'.$container);
1.104     albertel 1167: 		if ($fatal) {
                   1168: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1169: 		    return;
                   1170: 		}
1.8       www      1171:             }
1.11      www      1172: # Group import/search
1.174     albertel 1173: 	    if ($env{'form.importdetail'}) {
1.73      bowersj2 1174: 		my @imports;
1.174     albertel 1175: 		foreach (split(/\&/,$env{'form.importdetail'})) {
1.73      bowersj2 1176: 		    if (defined($_)) {
                   1177: 			my ($name,$url)=split(/\=/,$_);
                   1178: 			$name=&Apache::lonnet::unescape($name);
                   1179: 			$url=&Apache::lonnet::unescape($url);
                   1180: 			push @imports, $name, $url;
                   1181: 		    }
                   1182: 		}
1.11      www      1183: # Store the changed version
1.104     albertel 1184: 		($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
1.142     raeburn  1185: 					       $container,'londocs',@imports);
1.104     albertel 1186: 		if ($fatal) {
                   1187: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1188: 		    return;
                   1189: 		}
1.11      www      1190:             }
1.53      www      1191: # Loading a complete map
1.174     albertel 1192: 	   if (($env{'form.importmap'}) && ($env{'form.loadmap'})) {
                   1193: 	       foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1.181     www      1194: 		   my ($title,$url,$ext,$type)=split(/\:/,$_);
                   1195:                    my $idx=&Apache::lonratedt::getresidx($url);
1.53      www      1196:                    $Apache::lonratedt::resources[$idx]=$_;
                   1197:                    $Apache::lonratedt::order
1.104     albertel 1198: 		       [$#Apache::lonratedt::order+1]=$idx;
                   1199: 	       }
1.53      www      1200: 
                   1201: # Store the changed version
1.104     albertel 1202: 	       ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142     raeburn  1203: 					   $folder.'.'.$container);
1.104     albertel 1204: 	       if ($fatal) {
                   1205: 		   $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1206: 		   return;
                   1207: 	       }
1.53      www      1208:            }
1.16      www      1209:        }
                   1210: # ---------------------------------------------------------------- End commands
1.7       www      1211: # ---------------------------------------------------------------- Print screen
1.10      www      1212:         my $idx=0;
1.148     www      1213: 	my $shown=0;
1.10      www      1214:         $r->print('<table>');
                   1215:         foreach (@Apache::lonratedt::order) {
                   1216:            my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
                   1217:            unless ($name) {  $name=(split(/\//,$url))[-1]; }
1.148     www      1218:            unless ($name) { $idx++; next; }
1.112     raeburn  1219:            $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
1.10      www      1220:            $idx++;
1.148     www      1221: 	   $shown++;
1.10      www      1222:         }
1.148     www      1223: 	unless ($shown) {
1.131     www      1224: 	    $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
                   1225: 	}
1.168     www      1226:         $r->print("\n</table>\n");
1.174     albertel 1227: 	if ($env{'form.markedcopy_url'}) {
1.168     www      1228: 	    $r->print(<<ENDPASTE);
                   1229: <p><form name="pasteform" action="/adm/coursedocs" method="post">
1.174     albertel 1230: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
                   1231: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1.168     www      1232: ENDPASTE
                   1233:             $r->print(
                   1234: 	   '<input type="submit" name="pastemarked" value="'.&mt('Paste').
                   1235: 		      '" /> '.&Apache::loncommon::filedescription(
1.174     albertel 1236: 		(split(/\./,$env{'form.markedcopy_url'}))[-1]).': '.
                   1237: 		      $env{'form.markedcopy_title'});
1.168     www      1238:             if ($container eq 'page') {
                   1239: 		$r->print(<<PAGEINFO);
1.174     albertel 1240: <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />
                   1241: <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />
1.168     www      1242: PAGEINFO
                   1243:             } else {
                   1244: 		$r->print(<<FOLDERINFO);
1.174     albertel 1245: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.168     www      1246: FOLDERINFO
                   1247: 	    }
                   1248: 	    $r->print('</form></p>');
                   1249: 	}
1.7       www      1250:     }
                   1251: }
1.1       www      1252: 
1.188     raeburn  1253: sub process_file_upload {
1.194     raeburn  1254:     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1.188     raeburn  1255: # upload a file, if present
                   1256:     my $parseaction;
1.190     albertel 1257:    if ($env{'form.parserflag'}) {
1.188     raeburn  1258:         $parseaction = 'parse';
                   1259:     }
                   1260:     my $phase_status;
                   1261:     my $folder=$env{'form.folder'};
1.194     raeburn  1262:     if ($folder eq '') {
1.188     raeburn  1263:         $folder='default';
                   1264:     }
1.194     raeburn  1265:     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1.188     raeburn  1266:         my $errtext='';
                   1267:         my $fatal=0;
                   1268:         my $container='sequence';
                   1269:         if ($env{'form.pagepath'}) {
                   1270:             $container='page';
                   1271:         }
                   1272:         ($errtext,$fatal)=
                   1273:               &mapread($coursenum,$coursedom,$folder.'.'.$container);
                   1274:         if ($#Apache::lonratedt::order<1) {
                   1275:             $Apache::lonratedt::order[0]=1;
                   1276:             $Apache::lonratedt::resources[1]='';
                   1277:         }
                   1278:         if ($fatal) {
                   1279:             return 'failed';
                   1280:         }
                   1281:         my $destination = 'docs/';
1.194     raeburn  1282:         if ($folder =~ /^supplemental/) {
                   1283:             $destination = 'supplemental/';
                   1284:         }
                   1285:         if (($folder eq 'default') || ($folder eq 'supplemental')) {
1.188     raeburn  1286:             $destination .= 'default/';
1.194     raeburn  1287:         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   1288:             $destination .=  $2.'/';
1.188     raeburn  1289:         }
                   1290: # this is for a course, not a user, so set coursedoc flag
                   1291: # probably the only place in the system where this should be "1"
                   1292:         my $newidx=&Apache::lonratedt::getresidx();
                   1293:         $destination .= $newidx;
1.190     albertel 1294:         my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
                   1295: 						$parseaction,$allfiles,
                   1296: 						$codebase);
1.188     raeburn  1297:         my $ext='false';
                   1298:         if ($url=~/^http\:\/\//) { $ext='true'; }
                   1299:         $url=~s/\:/\&colon;/g;
                   1300:         my $comment=$env{'form.comment'};
                   1301:         $comment=~s/\</\&lt\;/g;
                   1302:         $comment=~s/\>/\&gt\;/g;
                   1303:         $comment=~s/\:/\&colon;/g;
                   1304:         if ($folder=~/^supplemental/) {
                   1305:               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   1306:                   $env{'user.domain'}.'___&&&___'.$comment;
                   1307:         }
                   1308: 
                   1309:         $Apache::lonratedt::resources[$newidx]=
                   1310:                   $comment.':'.$url.':'.$ext.':normal:res';
1.190     albertel 1311:         $Apache::lonratedt::order[$#Apache::lonratedt::order+1]= $newidx;
                   1312:         ($errtext,$fatal)=&storemap($coursenum,$coursedom,
                   1313: 				    $folder.'.'.$container);
1.188     raeburn  1314:         if ($fatal) {
                   1315:             $$upload_output .= '<p><font color="red">'.$errtext.'</font></p>';
                   1316:             return 'failed';
                   1317:         } else {
                   1318:             if ($parseaction eq 'parse') {
1.190     albertel 1319:                 my $total_embedded = keys(%{$allfiles});
1.188     raeburn  1320:                 if ($total_embedded > 0) {
                   1321:                     my $num = 0;
                   1322:                     $$upload_output .= 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />
                   1323:    <form name="upload_embedded" action="/adm/coursedocs"
                   1324:                   method="post" enctype="multipart/form-data">
                   1325:    <input type="hidden" name="folderpath" value="'.$env{'form.folderpath'}.'" />   <input type="hidden" name="cmd" value="upload_embedded" />
                   1326:    <input type="hidden" name="newidx" value="'.$newidx.'" />
                   1327:    <input type="hidden" name="primaryurl" value="'.&Apache::lonnet::escape($url).'" />
                   1328:    <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
                   1329:                     $$upload_output .= '<b>Upload embedded files</b>:<br />
                   1330:    <table>';
1.190     albertel 1331:                     foreach my $embed_file (keys(%{$allfiles})) {
1.188     raeburn  1332:                         $$upload_output .= '<tr><td>'.$embed_file.
1.190     albertel 1333:           '<input name="embedded_item_'.$num.'" type="file" />
                   1334:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&Apache::lonnet::escape($embed_file).'" />';
1.188     raeburn  1335:                         my $attrib;
                   1336:                         if (@{$$allfiles{$embed_file}} > 1) {
                   1337:                             $attrib = join(':',@{$$allfiles{$embed_file}});
                   1338:                         } else {
                   1339:                             $attrib = $$allfiles{$embed_file}[0];
                   1340:                         }
                   1341:                         $$upload_output .=
                   1342:            '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.$attrib.'" />';
                   1343:                         if (exists($$codebase{$embed_file})) {
                   1344:                             $$upload_output .= 
                   1345:           '<input name="codebase_'.$num.'" type="hidden" value="'.&Apache::lonnet::escape($$codebase{$embed_file}).'" />';
                   1346:                         }
                   1347:                         $$upload_output .= '</td></tr>';
                   1348:                         $num ++;
                   1349:                     }
                   1350:                     $phase_status = 'phasetwo';
                   1351:                     $$upload_output .= '</table><br />
                   1352:    <input type ="submit" value="Complete upload" />
                   1353:    </form>';
                   1354:                 } else {
                   1355:                     $$upload_output .= 'No embedded items identified<br />';
                   1356:                 }
                   1357:             }
                   1358:         }
                   1359:     }
                   1360:     return $phase_status;
                   1361: }
                   1362: 
                   1363: sub process_secondary_uploads {
                   1364:     my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
                   1365:     my $folder=$env{'form.folder'};
                   1366:     my $destination = 'docs/';
1.195     raeburn  1367:     if ($folder =~ /^supplemental/) {
                   1368:         $destination = 'supplemental/';
                   1369:     }
                   1370:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
1.188     raeburn  1371:         $destination .= 'default/';
1.195     raeburn  1372:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1.188     raeburn  1373:         $destination .=  $1.'/';
                   1374:     }
                   1375:     $destination .= $newidx;
                   1376:     my ($url,$filename);
                   1377:     $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
                   1378:     ($filename) = ($url =~ m-^/uploaded/$coursedom/$coursenum/$destination/(.+)$-);
                   1379:     return $filename;
                   1380: }
                   1381: 
1.8       www      1382: # --------------------------------------------------------------- An entry line
                   1383: 
                   1384: sub entryline {
1.112     raeburn  1385:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1.38      www      1386:     $title=~s/\&colon\;/\:/g;
                   1387:     $title=&HTML::Entities::encode(&HTML::Entities::decode(
1.109     albertel 1388:      &Apache::lonnet::unescape($title)),'"<>&\'');
1.38      www      1389:     my $renametitle=$title;
                   1390:     my $foldertitle=$title;
1.142     raeburn  1391:     my $pagetitle=$title;
1.122     www      1392:     my $orderidx=$Apache::lonratedt::order[$index];
1.109     albertel 1393:     if ($title=~ /^(\d+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(.*)$/	) { 
                   1394: 	$foldertitle=&Apache::lontexconvert::msgtexconverted($4);
                   1395: 	$renametitle=$4;
                   1396: 	$title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
                   1397: 	    &Apache::loncommon::plainname($2,$3).': <br />'.
                   1398: 	    $foldertitle;
                   1399:     }
1.38      www      1400:     $renametitle=~s/\&quot\;/\\\"/g;
1.8       www      1401:     my $line='<tr>';
                   1402: # Edit commands
1.142     raeburn  1403:     my $container;
1.120     www      1404:     my $folderpath;
1.174     albertel 1405:     if ($env{'form.folderpath'}) {
1.142     raeburn  1406:         $container = 'sequence';
1.174     albertel 1407: 	$folderpath=&Apache::lonnet::escape($env{'form.folderpath'});
                   1408: 	# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
1.120     www      1409:     }
1.156     albertel 1410:     my ($pagepath,$pagesymb);
1.174     albertel 1411:     if ($env{'form.pagepath'}) {
1.142     raeburn  1412:         $container = 'page';
1.174     albertel 1413:         $pagepath=&Apache::lonnet::escape($env{'form.pagepath'});
                   1414:         $pagesymb=&Apache::lonnet::escape($env{'form.pagesymb'});
1.142     raeburn  1415:     }
1.168     www      1416:     my $cpinfo='';
1.174     albertel 1417:     if ($env{'form.markedcopy_url'}) {
1.168     www      1418:        $cpinfo='&markedcopy_url='.
1.174     albertel 1419:                &Apache::lonnet::escape($env{'form.markedcopy_url'}).
1.168     www      1420:                '&markedcopy_title='.
1.174     albertel 1421:                &Apache::lonnet::escape($env{'form.markedcopy_title'});
1.168     www      1422:     }
1.109     albertel 1423:     if ($allowed) {
1.123     www      1424: 	my $incindex=$index+1;
                   1425: 	my $selectbox='';
1.168     www      1426: 	if (($folder!~/^supplemental/) &&
                   1427: 	    ($#Apache::lonratedt::order>0) && 
                   1428: 	    ((split(/\:/,
                   1429: 	     $Apache::lonratedt::resources[$Apache::lonratedt::order[0]]))[1] 
                   1430: 	     ne '') && 
                   1431: 	    ((split(/\:/,
                   1432: 	     $Apache::lonratedt::resources[$Apache::lonratedt::order[1]]))[1] 
                   1433: 	     ne '')) {
1.123     www      1434: 	    $selectbox=
1.124     www      1435: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.123     www      1436: 		'<select name="newpos" onChange="this.form.submit()">';
                   1437: 	    for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
                   1438: 		if ($i==$incindex) {
                   1439: 		    $selectbox.='<option value="" selected="1">('.$i.')</option>';
                   1440: 		} else {
                   1441: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
                   1442: 		}
                   1443: 	    }
                   1444: 	    $selectbox.='</select>';
                   1445: 	}
1.119     www      1446: 	my %lt=&Apache::lonlocal::texthash(
                   1447:                 'up' => 'Move Up',
1.109     albertel 1448: 		'dw' => 'Move Down',
                   1449: 		'rm' => 'Remove',
1.171     www      1450:                 'ct' => 'Cut',
1.168     www      1451: 		'rn' => 'Rename',
                   1452: 		'cp' => 'Copy');
1.174     albertel 1453:         if ($env{'form.pagepath'}) {
1.142     raeburn  1454:             $line.=(<<END);
                   1455: <form name="entry_$index" action="/adm/coursedocs" method="post">
1.174     albertel 1456: <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />
                   1457: <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />
                   1458: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
                   1459: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1.142     raeburn  1460: <input type="hidden" name="setparms" value="$orderidx" />
                   1461: <td><table border='0' cellspacing='2' cellpadding='0'>
                   1462: <tr><td bgcolor="#DDDDDD">
1.168     www      1463: <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
1.142     raeburn  1464: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
                   1465: <tr><td bgcolor="#DDDDDD">
1.168     www      1466: <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
1.142     raeburn  1467: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
                   1468: </table></td>
                   1469: <td>$selectbox
                   1470: </td><td bgcolor="#DDDDDD">
1.156     albertel 1471: <a href='javascript:removeres("$pagepath","$index","$renametitle","page","$pagesymb");'>
1.142     raeburn  1472: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.171     www      1473: <a href='javascript:cutres("$pagepath","$index","$renametitle","page","$pagesymb");'>
                   1474: <font size="-2" color="#550044">$lt{'ct'}</font></a>
1.156     albertel 1475: <a href='javascript:changename("$pagepath","$index","$renametitle","page","$pagesymb");'>
1.168     www      1476: <font size="-2" color="#009900">$lt{'rn'}</font></a>
                   1477: <a href='javascript:markcopy("$pagepath","$index","$renametitle","page","$pagesymb");'>
                   1478: <font size="-2" color="#000099">$lt{'cp'}</font></a></td>
1.142     raeburn  1479: END
                   1480:         } else {
                   1481:             $line.=(<<END); 
1.121     www      1482: <form name="entry_$index" action="/adm/coursedocs" method="post">
1.174     albertel 1483: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
                   1484: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
                   1485: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1.122     www      1486: <input type="hidden" name="setparms" value="$orderidx" />
1.54      www      1487: <td><table border='0' cellspacing='2' cellpadding='0'>
                   1488: <tr><td bgcolor="#DDDDDD">
1.168     www      1489: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath$cpinfo'>
1.90      www      1490: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1.54      www      1491: <tr><td bgcolor="#DDDDDD">
1.168     www      1492: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath$cpinfo'>
1.90      www      1493: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1.123     www      1494: </table></td>
                   1495: <td>$selectbox
                   1496: </td><td bgcolor="#DDDDDD">
1.142     raeburn  1497: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
1.90      www      1498: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.171     www      1499: <a href='javascript:cutres("$folderpath","$index","$renametitle","sequence");'>
                   1500: <font size="-2" color="#550044">$lt{'ct'}</font></a>
1.142     raeburn  1501: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
1.168     www      1502: <font size="-2" color="#009900">$lt{'rn'}</font></a>
                   1503: <a href='javascript:markcopy("$folderpath","$index","$renametitle","sequence");'>
                   1504: <font size="-2" color="#000099">$lt{'cp'}</font></a></td>
1.8       www      1505: END
1.142     raeburn  1506:         }
1.8       www      1507:     }
1.16      www      1508: # Figure out what kind of a resource this is
                   1509:     my ($extension)=($url=~/\.(\w+)$/);
                   1510:     my $uploaded=($url=~/^\/*uploaded\//);
1.97      albertel 1511:     my $icon=&Apache::loncommon::icon($url);
1.17      www      1512:     my $isfolder=0;
1.142     raeburn  1513:     my $ispage=0;
1.114     albertel 1514:     my $folderarg;
1.142     raeburn  1515:     my $pagearg;
                   1516:     my $pagefile;
1.16      www      1517:     if ($uploaded) {
1.135     albertel 1518: 	if ($extension eq 'sequence') {
                   1519: 	    $icon=$iconpath.'/folder_closed.gif';
                   1520: 	    $url=~/$coursenum\/([\/\w]+)\.sequence$/;
                   1521: 	    $url='/adm/coursedocs?';
                   1522: 	    $folderarg=$1;
                   1523: 	    $isfolder=1;
1.142     raeburn  1524:         } elsif ($extension eq 'page') {
                   1525:             $icon=$iconpath.'/page.gif';
                   1526:             $url=~/$coursenum\/([\/\w]+)\.page$/;
                   1527:             $pagearg=$1;
                   1528:             $url='/adm/coursedocs?';
                   1529:             $ispage=1;
1.135     albertel 1530: 	} else {
                   1531: 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
                   1532: 	}
1.16      www      1533:     }
1.18      www      1534:     $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
1.142     raeburn  1535:     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1.113     albertel 1536: 	my $symb=&Apache::lonnet::symbclean(
1.50      www      1537:           &Apache::lonnet::declutter('uploaded/'.
1.174     albertel 1538:            $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   1539:            $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
1.50      www      1540:            '.sequence').
                   1541:            '___'.$residx.'___'.
1.113     albertel 1542: 	   &Apache::lonnet::declutter($url));
                   1543: 	(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
                   1544: 	$url=&Apache::lonnet::clutter($url);
1.127     albertel 1545: 	if ($url=~/^\/*uploaded\//) {
                   1546: 	    $url=~/\.(\w+)$/;
                   1547: 	    my $embstyle=&Apache::loncommon::fileembstyle($1);
                   1548: 	    if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                   1549: 		$url='/adm/wrapper'.$url;
                   1550: 	    } elsif ($embstyle eq 'ssi') {
                   1551: 		#do nothing with these
                   1552: 	    } elsif ($url!~/\.(sequence|page)$/) {
                   1553: 		$url='/adm/coursedocs/showdoc'.$url;
                   1554: 	    }
1.145     albertel 1555: 	} elsif ($url=~m|^/ext/|) { 
                   1556: 	    $url='/adm/wrapper'.$url;
1.127     albertel 1557: 	}
1.152     albertel 1558: 	$url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
                   1559: 	if ($container eq 'page') {
1.174     albertel 1560: 	    my $symb=$env{'form.pagesymb'};
1.152     albertel 1561: 	    	    
                   1562: 	    $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1.142     raeburn  1563: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
1.152     albertel 1564: 	}
1.50      www      1565:     }
1.120     www      1566:     my $parameterset='&nbsp;';
1.114     albertel 1567:     if ($isfolder) {
                   1568: 	my $foldername=&Apache::lonnet::escape($foldertitle);
1.174     albertel 1569: 	my $folderpath=$env{'form.folderpath'};
1.114     albertel 1570: 	if ($folderpath) { $folderpath.='&' };
                   1571: 	$folderpath.=$folderarg.'&'.$foldername;
1.168     www      1572: 	$url.='folderpath='.&Apache::lonnet::escape($folderpath).$cpinfo;
1.147     matthew  1573: 	$parameterset='<label>'.&mt('Randomly Pick: ').
1.165     www      1574: 	    '<input type="text" size="4" onChange="this.form.submit()" name="randpick_'.$orderidx.'" value="'.
1.147     matthew  1575: 	    (&Apache::lonratedt::getparameter($orderidx,
                   1576:                                               'parameter_randompick'))[0].
1.165     www      1577:                                               '" />'.
                   1578: '<font size="-2"><a href="javascript:void(0)">'.&mt('Store').'</a></font></label>';
1.147     matthew  1579:        
1.114     albertel 1580:     }
1.142     raeburn  1581:     if ($ispage) {
                   1582:         my $pagename=&Apache::lonnet::escape($pagetitle);
                   1583:         my $pagepath;
1.174     albertel 1584:         my $folderpath=$env{'form.folderpath'};
1.142     raeburn  1585:         if ($folderpath) { $pagepath = $folderpath.'&' };
                   1586:         $pagepath.=$pagearg.'&'.$pagename;
1.174     albertel 1587: 	my $symb=$env{'form.pagesymb'};
1.152     albertel 1588: 	if (!$symb) {
                   1589: 	    my $path='uploaded/'.
1.174     albertel 1590: 		$env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   1591: 		$env{'course.'.$env{'request.course.id'}.'.num'}.'/';
1.152     albertel 1592: 	    $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
                   1593: 					       $residx,
                   1594: 					       $path.$pagearg.'.page');
                   1595: 	}
                   1596: 	$url.='pagepath='.&Apache::lonnet::escape($pagepath).
1.168     www      1597: 	    '&pagesymb='.&Apache::lonnet::escape($symb).$cpinfo;
1.142     raeburn  1598:     }
1.113     albertel 1599:     $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
                   1600: 	'" border="0"></a></td>'.
1.119     www      1601:         "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
1.120     www      1602:     if (($allowed) && ($folder!~/^supplemental/)) {
                   1603:  	my %lt=&Apache::lonlocal::texthash(
                   1604:  			      'hd' => 'Hidden',
1.165     www      1605:  			      'ec' => 'URL hidden');
1.122     www      1606: 	my $enctext=
                   1607: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
                   1608: 	my $hidtext=
                   1609: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1.120     www      1610: 	$line.=(<<ENDPARMS);
                   1611: <td bgcolor="#BBBBFF"><font size='-2'>
1.165     www      1612: <nobr><label><input type="checkbox" name="hidprs_$orderidx" onClick="this.form.submit()" $hidtext /> $lt{'hd'}</label></nobr></td>
1.149     albertel 1613: <td bgcolor="#BBBBFF"><font size='-2'>
1.165     www      1614: <nobr><label><input type="checkbox" name="encprs_$orderidx" onClick="this.form.submit()" $enctext /> $lt{'ec'}</label></nobr></td>
1.120     www      1615: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
                   1616: ENDPARMS
1.119     www      1617:     }
1.120     www      1618:     $line.="</form></tr>";
1.8       www      1619:     return $line;
                   1620: }
                   1621: 
1.27      www      1622: # ---------------------------------------------------------------- tie the hash
                   1623: 
                   1624: sub tiehash {
1.136     albertel 1625:     my ($mode)=@_;
1.27      www      1626:     $hashtied=0;
1.174     albertel 1627:     if ($env{'request.course.fn'}) {
1.136     albertel 1628: 	if ($mode eq 'write') {
1.174     albertel 1629: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1.136     albertel 1630: 		    &GDBM_WRCREAT(),0640)) {
                   1631:                 $hashtied=2;
                   1632: 	    }
                   1633: 	} else {
1.174     albertel 1634: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1.136     albertel 1635: 		    &GDBM_READER(),0640)) {
1.27      www      1636:                 $hashtied=1;
1.136     albertel 1637: 	    }
                   1638: 	}
1.27      www      1639:     }    
                   1640: }
                   1641: 
                   1642: sub untiehash {
                   1643:     if ($hashtied) { untie %hash; }
                   1644:     $hashtied=0;
                   1645: }
                   1646: 
1.29      www      1647: # --------------------------------------------------------------- check on this
                   1648: 
                   1649: sub checkonthis {
                   1650:     my ($r,$url,$level,$title)=@_;
1.140     www      1651:     $url=&Apache::lonnet::unescape($url);
1.29      www      1652:     $alreadyseen{$url}=1;
                   1653:     $r->rflush();
1.41      www      1654:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1.108     albertel 1655:        $r->print("\n<br />");
1.29      www      1656:        for (my $i=0;$i<=$level*5;$i++) {
                   1657:            $r->print('&nbsp;');
                   1658:        }
                   1659:        $r->print('<a href="'.$url.'" target="cat">'.
                   1660: 		 ($title?$title:$url).'</a> ');
                   1661:        if ($url=~/^\/res\//) {
                   1662: 	  my $result=&Apache::lonnet::repcopy(
                   1663:                               &Apache::lonnet::filelocation('',$url));
1.172     raeburn  1664:           if ($result eq 'ok') {
1.87      www      1665:              $r->print('<font color="green">'.&mt('ok').'</font>');
1.29      www      1666:              $r->rflush();
1.34      www      1667:              &Apache::lonnet::countacc($url);
                   1668:              $url=~/\.(\w+)$/;
                   1669:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                   1670: 		 $r->print('<br />');
                   1671:                  $r->rflush();
                   1672:                  for (my $i=0;$i<=$level*5;$i++) {
                   1673:                      $r->print('&nbsp;');
                   1674:                  }
1.84      www      1675:                  $r->print('- '.&mt('Rendering').': ');
1.170     www      1676: 		 my ($errorcount,$warningcount)=split(/:/,
                   1677: 	       &Apache::lonnet::ssi_body($url,
1.173     albertel 1678: 			       ('grade_target'=>'web',
                   1679: 				'return_only_error_and_warning_counts' => 1)));
1.170     www      1680:                  if (($errorcount) ||
                   1681:                      ($warningcount)) {
                   1682: 		     if ($errorcount) {
1.98      www      1683:                         $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
1.170     www      1684: 			  $errorcount.' '.
1.87      www      1685: 				  &mt('error(s)').'</b></font> ');
1.34      www      1686:                      }
1.170     www      1687: 		     if ($warningcount) {
1.34      www      1688:                         $r->print('<font color="blue">'.
1.170     www      1689: 			  $warningcount.' '.
1.84      www      1690: 				  &mt('warning(s)').'</font>');
1.34      www      1691:                      }
                   1692:                  } else {
1.87      www      1693:                      $r->print('<font color="green">'.&mt('ok').'</font>');
1.34      www      1694:                  }
                   1695:                  $r->rflush();
                   1696:              }
1.29      www      1697: 	     my $dependencies=
                   1698:                 &Apache::lonnet::metadata($url,'dependencies');
                   1699:              foreach (split(/\,/,$dependencies)) {
                   1700: 		 if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
                   1701:                     &checkonthis($r,$_,$level+1);
                   1702:                  }
                   1703:              }
1.172     raeburn  1704:           } elsif ($result eq 'unavailable') {
1.84      www      1705:              $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
1.172     raeburn  1706:           } elsif ($result eq 'not_found') {
1.100     www      1707: 	      unless ($url=~/\$/) {
                   1708: 		  $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
                   1709: 	      } else {
                   1710: 		  $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
                   1711: 	      }
1.29      www      1712:           } else {
1.84      www      1713:              $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
1.29      www      1714:           }
                   1715:       }
                   1716:    }
                   1717: }
                   1718: 
1.1       www      1719: 
1.75      www      1720: #
                   1721: # -------------------------------------------------------------- Verify Content
                   1722: # 
                   1723: sub verifycontent {
                   1724:    my $r=shift; 
1.26      www      1725:    my $loaderror=&Apache::lonnet::overloaderror($r);
                   1726:    if ($loaderror) { return $loaderror; }
1.167     albertel 1727:    my $html=&Apache::lonxml::xmlbegin();
                   1728:    $r->print($html.'<head><title>Verify Content</title></head>'.
1.26      www      1729:               &Apache::loncommon::bodytag('Verify Course Documents'));
1.27      www      1730:    $hashtied=0;
1.30      www      1731:    undef %alreadyseen;
                   1732:    %alreadyseen=();
1.27      www      1733:    &tiehash();
                   1734:    foreach (keys %hash) {
1.140     www      1735:        if ($hash{$_}=~/\.(page|sequence)$/) {
                   1736: 	   if (($_=~/^src_/) && ($alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
                   1737: 	       $r->print('<hr /><font color="red">'.
                   1738: 			 &mt('The following sequence or page is included more than once in your course: ').
                   1739: 			 &Apache::lonnet::unescape($hash{$_}).'</font><br />'.
                   1740: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
                   1741: 	   }
                   1742:        }
                   1743:        if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
1.29      www      1744:            &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27      www      1745:        }
                   1746:    }
                   1747:    &untiehash();
1.108     albertel 1748:    $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
                   1749: 	     &mt('Return to DOCS').'</a>');
1.75      www      1750: }
                   1751: 
1.192     www      1752: 
1.75      www      1753: # -------------------------------------------------------------- Check Versions
                   1754: 
1.192     www      1755: sub devalidateversioncache {
                   1756:     my $src=shift;
                   1757:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
                   1758: 					  &Apache::lonnet::clutter($src));
                   1759: }
                   1760: 
1.75      www      1761: sub checkversions {
                   1762:     my $r=shift;
1.167     albertel 1763:     my $html=&Apache::lonxml::xmlbegin();
                   1764:     $r->print($html.'<head><title>Check Versions</title></head>'.
1.26      www      1765:               &Apache::loncommon::bodytag('Check Course Document Versions'));
1.89      www      1766:     my $header='';
                   1767:     my $startsel='';
                   1768:     my $monthsel='';
                   1769:     my $weeksel='';
                   1770:     my $daysel='';
                   1771:     my $allsel='';
                   1772:     my %changes=();
                   1773:     my $starttime=0;
1.91      www      1774:     my $haschanged=0;
1.92      www      1775:     my %setversions=&Apache::lonnet::dump('resourceversions',
1.174     albertel 1776: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1777: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
1.92      www      1778: 
                   1779:     $hashtied=0;
                   1780:     &tiehash();
                   1781:     my %newsetversions=();
1.174     albertel 1782:     if ($env{'form.setmostrecent'}) {
1.91      www      1783: 	$haschanged=1;
1.92      www      1784: 	foreach (keys %hash) {
                   1785: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
1.93      www      1786: 		$newsetversions{$1}='mostrecent';
1.192     www      1787:                 &devalidateversioncache($1);
1.92      www      1788: 	    }
                   1789: 	}
1.174     albertel 1790:     } elsif ($env{'form.setcurrent'}) {
1.91      www      1791: 	$haschanged=1;
1.92      www      1792: 	foreach (keys %hash) {
                   1793: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
1.93      www      1794: 		my $getvers=&Apache::lonnet::getversion($1);
                   1795: 		if ($getvers>0) {
                   1796: 		    $newsetversions{$1}=$getvers;
1.192     www      1797: 		    &devalidateversioncache($1);
1.93      www      1798: 		}
1.92      www      1799: 	    }
                   1800: 	}
1.174     albertel 1801:     } elsif ($env{'form.setversions'}) {
1.91      www      1802: 	$haschanged=1;
1.174     albertel 1803: 	foreach (keys %env) {
1.92      www      1804: 	    if ($_=~/^form\.set_version_(.+)$/) {
                   1805: 		my $src=$1;
1.174     albertel 1806: 		if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
                   1807: 		    $newsetversions{$src}=$env{$_};
1.192     www      1808: 		    &devalidateversioncache($src);
1.92      www      1809: 		}
                   1810: 	    }
                   1811: 	}
1.91      www      1812:     }
                   1813:     if ($haschanged) {
1.92      www      1814:         if (&Apache::lonnet::put('resourceversions',\%newsetversions,
1.174     albertel 1815: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1816: 			  $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {		
1.92      www      1817: 	    $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
                   1818: 	} else {
                   1819: 	    $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
                   1820: 	}
1.136     albertel 1821: 	&mark_hash_old();
1.91      www      1822:     }
1.136     albertel 1823:     &changewarning($r,'');
1.174     albertel 1824:     if ($env{'form.timerange'} eq 'all') {
1.89      www      1825: # show all documents
                   1826: 	$header=&mt('All Documents in Course');
1.91      www      1827: 	$allsel=1;
1.90      www      1828: 	foreach (keys %hash) {
                   1829: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
                   1830: 		my $src=$1;
                   1831: 		$changes{$src}=1;
                   1832: 	    }
                   1833: 	}
1.89      www      1834:     } else {
                   1835: # show documents which changed
                   1836: 	%changes=&Apache::lonnet::dump
1.174     albertel 1837: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
                   1838:                      $env{'course.'.$env{'request.course.id'}.'.num'});
1.89      www      1839: 	my $firstkey=(keys %changes)[0];
                   1840: 	unless ($firstkey=~/^error\:/) {
1.174     albertel 1841: 	    unless ($env{'form.timerange'}) {
                   1842: 		$env{'form.timerange'}=604800;
1.89      www      1843: 	    }
1.174     albertel 1844: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
1.89      www      1845: 		.&mt('seconds');
1.174     albertel 1846: 	    if ($env{'form.timerange'}==-1) {
1.89      www      1847: 		$seltext='since start of course';
                   1848: 		$startsel='selected';
1.174     albertel 1849: 		$env{'form.timerange'}=time;
1.89      www      1850: 	    }
1.174     albertel 1851: 	    $starttime=time-$env{'form.timerange'};
                   1852: 	    if ($env{'form.timerange'}==2592000) {
1.89      www      1853: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1854: 		$monthsel='selected';
1.174     albertel 1855: 	    } elsif ($env{'form.timerange'}==604800) {
1.89      www      1856: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1857: 		$weeksel='selected';
1.174     albertel 1858: 	    } elsif ($env{'form.timerange'}==86400) {
1.89      www      1859: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1860: 		$daysel='selected';
                   1861: 	    }
                   1862: 	    $header=&mt('Content changed').' '.$seltext;
                   1863: 	} else {
                   1864: 	    $header=&mt('No content modifications yet.');
                   1865: 	}
                   1866:     }
1.92      www      1867:     %setversions=&Apache::lonnet::dump('resourceversions',
1.174     albertel 1868: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1869: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
1.89      www      1870:     my %lt=&Apache::lonlocal::texthash
1.88      www      1871: 	      ('st' => 'Version changes since start of Course',
                   1872: 	       'lm' => 'Version changes since last Month',
                   1873: 	       'lw' => 'Version changes since last Week',
                   1874: 	       'sy' => 'Version changes since Yesterday',
1.91      www      1875:                'al' => 'All Resources (possibly large output)',
1.88      www      1876: 	       'sd' => 'Display',
1.84      www      1877: 	       'fi' => 'File',
                   1878: 	       'md' => 'Modification Date',
1.87      www      1879:                'mr' => 'Most recently published Version',
                   1880: 	       've' => 'Version used in Course',
1.91      www      1881:                'vu' => 'Set Version to be used in Course',
                   1882: 'sv' => 'Set Versions to be used in Course according to Selections below',
                   1883: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                   1884: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.84      www      1885: 	       'di' => 'Differences');
1.89      www      1886:     $r->print(<<ENDHEADERS);
1.31      www      1887: <form action="/adm/coursedocs" method="post">
1.91      www      1888: <input type="hidden" name="versions" value="1" />
                   1889: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
                   1890: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1.31      www      1891: <select name="timerange">
1.88      www      1892: <option value='all' $allsel>$lt{'al'}</option>
1.84      www      1893: <option value="-1" $startsel>$lt{'st'}</option>
                   1894: <option value="2592000" $monthsel>$lt{'lm'}</option>
                   1895: <option value="604800" $weeksel>$lt{'lw'}</option>
                   1896: <option value="86400" $daysel>$lt{'sy'}</option>
1.31      www      1897: </select>
1.91      www      1898: <input type="submit" name="display" value="$lt{'sd'}" />
1.89      www      1899: <h3>$header</h3>
1.91      www      1900: <input type="submit" name="setversions" value="$lt{'sv'}" />
1.103     matthew  1901: <table border="0">
1.31      www      1902: ENDHEADERS
1.91      www      1903:     foreach (sort keys %changes) {
1.89      www      1904: 	if ($changes{$_}>$starttime) {
                   1905: 	    my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
                   1906: 	    my $currentversion=&Apache::lonnet::getversion($_);
1.93      www      1907: 	    if ($currentversion<0) {
                   1908: 		$currentversion=&mt('Could not be determined.');
                   1909: 	    }
1.89      www      1910: 	    my $linkurl=&Apache::lonnet::clutter($_);
                   1911: 	    $r->print(
1.103     matthew  1912: 		      '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1.91      www      1913: 		      &Apache::lonnet::gettitle($linkurl).
1.103     matthew  1914:                       '</b></font></td></tr>'.
                   1915:                       '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
                   1916:                       '<td colspan="4">'.
                   1917:                       '<a href="'.$linkurl.'" target="cat">'.$linkurl.
                   1918: 		      '</a></td></tr>'.
                   1919:                       '<tr><td></td>'.
                   1920:                       '<td title="'.$lt{'md'}.'">'.
1.102     matthew  1921: 		      &Apache::lonlocal::locallocaltime(
                   1922:                            &Apache::lonnet::metadata($root.'.'.$extension,
                   1923:                                                      'lastrevisiondate')
                   1924:                                                         ).
1.103     matthew  1925:                       '</td>'.
                   1926:                       '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
                   1927:                       '<font size="+1">'.$currentversion.'</font>'.
                   1928:                       '</nobr></td>'.
                   1929:                       '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
                   1930:                       '<font size="+1">');
1.87      www      1931: # Used in course
1.89      www      1932: 	    my $usedversion=$hash{'version_'.$linkurl};
1.93      www      1933: 	    if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.89      www      1934: 		$r->print($usedversion);
                   1935: 	    } else {
                   1936: 		$r->print($currentversion);
                   1937: 	    }
1.103     matthew  1938: 	    $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
                   1939:                       '<nobr>Use: ');
1.87      www      1940: # Set version
1.92      www      1941: 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1.89      www      1942: 						      'set_version_'.$linkurl,
1.136     albertel 1943: 						      ('select_form_order' =>
                   1944: 						       ['',1..$currentversion,'mostrecent'],
                   1945: 						       '' => '',
1.93      www      1946: 						       'mostrecent' => 'most recent',
1.89      www      1947: 						       map {$_,$_} (1..$currentversion))));
1.103     matthew  1948: 	    $r->print('</nobr></td></tr><tr><td></td>');
1.89      www      1949: 	    my $lastold=1;
                   1950: 	    for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                   1951: 		my $url=$root.'.'.$prevvers.'.'.$extension;
                   1952: 		if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
                   1953: 		    $starttime) {
                   1954: 		    $lastold=$prevvers;
                   1955: 		}
                   1956: 	    }
1.103     matthew  1957:             # 
                   1958:             # Code to figure out how many version entries should go in
                   1959:             # each of the four columns
                   1960:             my $entries_per_col = 0;
                   1961:             my $num_entries = ($currentversion-$lastold);
                   1962:             if ($num_entries % 4 == 0) {
                   1963:                 $entries_per_col = $num_entries/4;
                   1964:             } else {
                   1965:                 $entries_per_col = $num_entries/4 + 1;
                   1966:             }
                   1967:             my $entries_count = 0;
                   1968:             $r->print('<td valign="top"><font size="-2">'); 
                   1969:             my $cols_output = 1;
1.32      www      1970:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1.89      www      1971: 		my $url=$root.'.'.$prevvers.'.'.$extension;
1.103     matthew  1972: 		$r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
1.91      www      1973: 			  '">'.&mt('Version').' '.$prevvers.'</a> ('.
1.103     matthew  1974: 			  &Apache::lonlocal::locallocaltime(
                   1975:                                 &Apache::lonnet::metadata($url,
                   1976:                                                           'lastrevisiondate')
                   1977:                                                             ).
1.91      www      1978: 			  ')');
1.89      www      1979: 		if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1.33      www      1980:                     $r->print(' <a href="/adm/diff?filename='.
1.89      www      1981: 			      &Apache::lonnet::clutter($root.'.'.$extension).
                   1982: 			      '&versionone='.$prevvers.
                   1983: 			      '">'.&mt('Diffs').'</a>');
                   1984: 		}
1.103     matthew  1985: 		$r->print('</nobr><br />');
                   1986:                 if (++$entries_count % $entries_per_col == 0) {
                   1987:                     $r->print('</font></td>');
                   1988:                     if ($cols_output != 4) {
                   1989:                         $r->print('<td valign="top"><font size="-2">');
                   1990:                         $cols_output++;
                   1991:                     }
                   1992:                 }
1.89      www      1993: 	    }
1.103     matthew  1994:             while($cols_output++ < 4) {
                   1995:                 $r->print('</font></td><td><font>')
                   1996:             }
                   1997: 	    $r->print('</font></td></tr>'."\n");
1.89      www      1998: 	}
                   1999:     }
1.92      www      2000:     $r->print('</table></form>');
1.89      www      2001:     $r->print('<h1>'.&mt('Done').'.</h1>');
                   2002: 
                   2003:     &untiehash();
1.75      www      2004: }
                   2005: 
1.136     albertel 2006: sub mark_hash_old {
                   2007:     my $retie_hash=0;
                   2008:     if ($hashtied) {
                   2009: 	$retie_hash=1;
                   2010: 	&untiehash();
                   2011:     }
                   2012:     &tiehash('write');
                   2013:     $hash{'old'}=1;
                   2014:     &untiehash();
                   2015:     if ($retie_hash) { &tiehash(); }
                   2016: }
                   2017: 
                   2018: sub is_hash_old {
                   2019:     my $untie_hash=0;
                   2020:     if (!$hashtied) {
                   2021: 	$untie_hash=1;
                   2022: 	&tiehash();
                   2023:     }
                   2024:     my $return=$hash{'old'};
                   2025:     if ($untie_hash) { &untiehash(); }
                   2026:     return $return;
                   2027: }
                   2028: 
1.91      www      2029: sub changewarning {
1.177     albertel 2030:     my ($r,$postexec,$message,$url)=@_;
1.136     albertel 2031:     if (!&is_hash_old()) { return; }
1.150     albertel 2032:     my $pathvar='folderpath';
1.174     albertel 2033:     my $path=&Apache::lonnet::escape($env{'form.folderpath'});
1.177     albertel 2034:     if (!defined($url)) {
                   2035: 	if (defined($env{'form.pagepath'})) {
                   2036: 	    $pathvar='pagepath';
                   2037: 	    $path=&Apache::lonnet::escape($env{'form.pagepath'});
1.193     albertel 2038: 	    $path.='&amp;pagesymb='.&Apache::lonnet::escape($env{'form.pagesymb'});
1.177     albertel 2039: 	}
                   2040: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
                   2041:     }
                   2042:     if (!defined($message)) {
                   2043: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
1.150     albertel 2044:     }
1.185     www      2045:     $r->print("\n\n".
                   2046: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n". 
                   2047: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.177     albertel 2048: '<input type="hidden" name="orgurl" value="'.$url.
1.117     albertel 2049: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1.177     albertel 2050: &mt($message,' <input type="hidden" name="'.
                   2051:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
                   2052:     &mt('re-initializing course').'" onClick="reinit(this.form)" />').
1.185     www      2053: $help{'Caching'}.'</font></h3></form>'."\n\n");
1.91      www      2054: }
                   2055: 
1.75      www      2056: # ================================================================ Main Handler
                   2057: sub handler {
                   2058:     my $r = shift;
1.82      www      2059:     &Apache::loncommon::content_type($r,'text/html');
1.75      www      2060:     $r->send_http_header;
                   2061:     return OK if $r->header_only;
                   2062: 
                   2063: # --------------------------------------------- Initialize help topics for this
                   2064:   foreach ('Adding_Course_Doc','Main_Course_Documents',
                   2065:            'Adding_External_Resource','Navigate_Content',
                   2066:            'Adding_Folders','Docs_Overview', 'Load_Map',
1.142     raeburn  2067:            'Supplemental','Score_Upload_Form','Adding_Pages',
1.130     www      2068:            'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
                   2069: 	   'Check_Resource_Versions','Verify_Content') {
1.75      www      2070:       $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
                   2071:   }
                   2072:     # Composite help files
                   2073:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   2074: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   2075:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   2076: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1.86      albertel 2077:     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
                   2078: 		    'Option_Response_Simple');
1.75      www      2079:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   2080: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
                   2081:     $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
                   2082: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
                   2083:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.142     raeburn  2084: 
1.174     albertel 2085:   if ($env{'form.verify'}) {
1.75      www      2086:       &verifycontent($r);
1.174     albertel 2087:   } elsif ($env{'form.versions'}) {
1.75      www      2088:       &checkversions($r);
1.174     albertel 2089:   } elsif ($env{'form.dumpcourse'}) {
1.75      www      2090:       &dumpcourse($r);
1.174     albertel 2091:   } elsif ($env{'form.exportcourse'}) {
1.138     raeburn  2092:       &exportcourse($r);
1.26      www      2093:   } else {
1.7       www      2094: # is this a standard course?
                   2095: 
1.174     albertel 2096:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.155     raeburn  2097:     my $forcestandard = 0;
1.15      www      2098:     my $forcesupplement;
                   2099:     my $script='';
                   2100:     my $allowed;
                   2101:     my $events='';
1.19      www      2102:     my $showdoc=0;
1.142     raeburn  2103:     my $containertag;
                   2104:     my $uploadtag;
1.15      www      2105:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.168     www      2106:     ['folderpath','pagepath','pagesymb','markedcopy_url','markedcopy_title']);
1.174     albertel 2107:     if ($env{'form.folderpath'}) {
                   2108: 	my (@folderpath)=split('&',$env{'form.folderpath'});
                   2109: 	$env{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
                   2110: 	$env{'form.folder'}=pop(@folderpath);
                   2111:     }
                   2112:     if ($env{'form.pagepath'}) {
                   2113:         my (@pagepath)=split('&',$env{'form.pagepath'});
                   2114:         $env{'form.pagename'}=&Apache::lonnet::unescape(pop(@pagepath));
                   2115:         $env{'form.folder'}=pop(@pagepath);
1.156     albertel 2116:         $containertag = '<input type="hidden" name="pagepath" value="" />'.
                   2117: 	    '<input type="hidden" name="pagesymb" value="" />';
1.174     albertel 2118:         $uploadtag = '<input type="hidden" name="pagepath" value="'.$env{'form.pagepath'}.'" />'.
                   2119: 	    '<input type="hidden" name="pagesymb" value="'.$env{'form.pagesymb'}.'" />';
1.142     raeburn  2120:     }
1.21      www      2121:     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1.127     albertel 2122:        $showdoc='/'.$1;
1.21      www      2123:     }
                   2124:     unless ($showdoc) { # got called from remote
1.174     albertel 2125:        if (($env{'form.folder'}=~/^default_/) || 
                   2126:           ($env{'form.folder'} =~ m#^\d+/(pages|sequences)/#)) {
1.155     raeburn  2127:            $forcestandard = 1;
                   2128:        } 
1.174     albertel 2129:        $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
1.7       www      2130: 
1.4       www      2131: # does this user have privileges to post, etc?
1.174     albertel 2132:        $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.15      www      2133:        if ($allowed) { 
                   2134:          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   2135:          $script=&Apache::lonratedt::editscript('simple'); 
                   2136:        }
                   2137:     } else { # got called in sequence from course
                   2138:        $allowed=0;
1.49      www      2139:        $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
                   2140:        $events='onLoad="'.&Apache::lonmenu::loadevents.
                   2141:            '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1.3       www      2142:     }
1.4       www      2143: 
                   2144: # get course data
1.174     albertel 2145:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   2146:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.4       www      2147: 
1.14      www      2148: # get personal data
                   2149:  
1.174     albertel 2150:     my $uname=$env{'user.name'};
                   2151:     my $udom=$env{'user.domain'};
1.14      www      2152:     my $plainname=&Apache::lonnet::escape(
                   2153:                      &Apache::loncommon::plainname($uname,$udom));
                   2154: 
1.8       www      2155: # graphics settings
1.4       www      2156: 
1.176     albertel 2157:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
1.8       www      2158: 
1.22      www      2159:     my $now=time;
1.64      www      2160: 
1.4       www      2161: # print screen
1.167     albertel 2162:        my $html=&Apache::lonxml::xmlbegin();
1.1       www      2163:     $r->print(<<ENDDOCUMENT);
1.167     albertel 2164: $html
1.1       www      2165: <head>
                   2166: <title>The LearningOnline Network with CAPA</title>
1.16      www      2167: <script>
                   2168: $script
1.20      www      2169: </script>
1.19      www      2170: ENDDOCUMENT
                   2171:    if ($allowed) {
                   2172:     $r->print(<<ENDNEWSCRIPT);
1.20      www      2173: <script>
1.16      www      2174: function makenewfolder(targetform,folderseq) {
                   2175:     var foldername=prompt('Name of New Folder','New Folder');
                   2176:     if (foldername) {
                   2177: 	targetform.importdetail.value=foldername+"="+folderseq;
                   2178:         targetform.submit();
                   2179:     }
                   2180: }
                   2181: 
1.142     raeburn  2182: function makenewpage(targetform,folderseq) {
                   2183:     var pagename=prompt('Name of New Page','New Page');
                   2184:     if (pagename) {
                   2185:         targetform.importdetail.value=pagename+"="+folderseq;
                   2186:         targetform.submit();
                   2187:     }
                   2188: }
                   2189: 
1.18      www      2190: function makenewext(targetname) {
                   2191:     this.document.forms.extimport.useform.value=targetname;
                   2192:     window.open('/adm/rat/extpickframe.html');
                   2193: }
                   2194: 
1.62      www      2195: function makeexamupload() {
                   2196:    var title=prompt('Listed Title for the Uploaded Score');
                   2197:    if (title) { 
                   2198:     this.document.forms.newexamupload.importdetail.value=
                   2199: 	title+'=/res/lib/templates/examupload.problem';
                   2200:     this.document.forms.newexamupload.submit();
                   2201:    }
                   2202: }
                   2203: 
1.22      www      2204: function makesmppage() {
1.38      www      2205:    var title=prompt('Listed Title for the Page');
                   2206:    if (title) { 
1.22      www      2207:     this.document.forms.newsmppg.importdetail.value=
                   2208: 	title+'=/adm/$udom/$uname/$now/smppg';
                   2209:     this.document.forms.newsmppg.submit();
1.38      www      2210:    }
1.22      www      2211: }
                   2212: 
1.55      www      2213: function makesmpproblem() {
                   2214:    var title=prompt('Listed Title for the Problem');
                   2215:    if (title) { 
                   2216:     this.document.forms.newsmpproblem.importdetail.value=
1.63      www      2217: 	title+'=/res/lib/templates/simpleproblem.problem';
1.55      www      2218:     this.document.forms.newsmpproblem.submit();
                   2219:    }
                   2220: }
                   2221: 
1.22      www      2222: function makebulboard() {
1.38      www      2223:    var title=prompt('Listed Title for the Bulletin Board');
                   2224:    if (title) {
1.22      www      2225:     this.document.forms.newbul.importdetail.value=
                   2226: 	title+'=/adm/$udom/$uname/$now/bulletinboard';
                   2227:     this.document.forms.newbul.submit();
1.38      www      2228:    }
1.22      www      2229: }
                   2230: 
1.101     www      2231: function makeabout() {
                   2232:    var user=prompt("Enter user\@domain for User's 'About Me' Page");
                   2233:    if (user) {
                   2234:        var comp=new Array();
                   2235:        comp=user.split('\@');
                   2236:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   2237: 	   if ((comp[0]) && (comp[1])) {
                   2238: 	       this.document.forms.newaboutsomeone.importdetail.value=
                   2239: 		   'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
                   2240: 	       this.document.forms.newaboutsomeone.submit();
1.165     www      2241: 	   } else {
                   2242:                alert("Not a valid user\@domain");
                   2243:            }
                   2244:        } else {
                   2245:            alert("Please enter both user and domain in the format user\@domain"); 
1.101     www      2246:        }
                   2247:    }
                   2248: }
                   2249: 
1.110     raeburn  2250: function makeims() {
1.165     www      2251:     var caller = document.forms.ims.folder.value;
                   2252:     var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
                   2253:     newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
                   2254:     newWindow.location.href = newlocation;
1.110     raeburn  2255: }
                   2256: 
                   2257: 
1.18      www      2258: function finishpick() {
                   2259:     var title=this.document.forms.extimport.title.value;
                   2260:     var url=this.document.forms.extimport.url.value;
                   2261:     var form=this.document.forms.extimport.useform.value;
                   2262:     eval
                   2263:      ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
                   2264:     '";this.document.forms.'+form+'.submit();');
1.16      www      2265: }
1.36      www      2266: 
1.156     albertel 2267: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.36      www      2268:     var title=prompt('New Title',oldtitle);
                   2269:     if (title) {
                   2270: 	this.document.forms.renameform.title.value=title;
                   2271: 	this.document.forms.renameform.cmd.value='rename_'+index;
1.142     raeburn  2272:         if (container == 'sequence') {
                   2273: 	    this.document.forms.renameform.folderpath.value=folderpath;
                   2274:         }
                   2275:         if (container == 'page') {
                   2276:             this.document.forms.renameform.pagepath.value=folderpath;
1.156     albertel 2277:             this.document.forms.renameform.pagesymb.value=pagesymb;
1.142     raeburn  2278:         }
1.54      www      2279:         this.document.forms.renameform.submit();
                   2280:     }
                   2281: }
                   2282: 
1.156     albertel 2283: function removeres(folderpath,index,oldtitle,container,pagesymb) {
1.171     www      2284:     if (confirm('WARNING: Removing a resource makes associated grades and scores inaccessible!\\nRemove "'+oldtitle+'"?')) {
1.54      www      2285: 	this.document.forms.renameform.cmd.value='del_'+index;
1.142     raeburn  2286:         if (container == 'sequence') {
                   2287:             this.document.forms.renameform.folderpath.value=folderpath;
                   2288:         }
                   2289:         if (container == 'page') {
                   2290:             this.document.forms.renameform.pagepath.value=folderpath;
1.156     albertel 2291:             this.document.forms.renameform.pagesymb.value=pagesymb;
1.142     raeburn  2292:         }
1.36      www      2293:         this.document.forms.renameform.submit();
                   2294:     }
                   2295: }
1.121     www      2296: 
1.171     www      2297: function cutres(folderpath,index,oldtitle,container,pagesymb) {
1.186     www      2298:     if (confirm('WARNING: Cutting a resource makes associated grades and scores inaccessible!\\nGrades remain inaccessible if resource is pasted into another folder.\\nCut "'+oldtitle+'"?')) {
1.171     www      2299: 	this.document.forms.renameform.cmd.value='cut_'+index;
                   2300: 	this.document.forms.renameform.markcopy.value=index;
                   2301:         if (container == 'sequence') {
                   2302:             this.document.forms.renameform.folderpath.value=folderpath;
                   2303:         }
                   2304:         if (container == 'page') {
                   2305:             this.document.forms.renameform.pagepath.value=folderpath;
                   2306:             this.document.forms.renameform.pagesymb.value=pagesymb;
                   2307:         }
                   2308:         this.document.forms.renameform.submit();
                   2309:     }
                   2310: }
                   2311: 
1.168     www      2312: function markcopy(folderpath,index,oldtitle,container,pagesymb) {
                   2313:     this.document.forms.renameform.markcopy.value=index;
                   2314:     if (container == 'sequence') {
                   2315: 	this.document.forms.renameform.folderpath.value=folderpath;
                   2316:     }
                   2317:     if (container == 'page') {
                   2318: 	this.document.forms.renameform.pagepath.value=folderpath;
                   2319: 	this.document.forms.renameform.pagesymb.value=pagesymb;
                   2320:     }
                   2321:     this.document.forms.renameform.submit();
                   2322: }
                   2323: 
1.16      www      2324: </script>
1.42      www      2325: 
                   2326: ENDNEWSCRIPT
                   2327:   }
                   2328: # -------------------------------------------------------------------- Body tag
                   2329:   $r->print('</head>'.
1.72      www      2330:             &Apache::loncommon::bodytag('Course Documents','',$events,
1.99      www      2331: 					'','',$showdoc).
1.134     albertel 2332: 	    &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
1.188     raeburn  2333:   my %allfiles = ();
                   2334:   my %codebase = ();
                   2335:   my ($upload_result,$upload_output);
                   2336:   if ($allowed) {
                   2337:       if (($env{'form.uploaddoc.filename'}) &&                                               ($env{'form.cmd'}=~/^upload_(\w+)/)) {
                   2338: # Process file upload - phase one - upload and parse primary file.  
1.190     albertel 2339:           $upload_result = &process_file_upload(\$upload_output,$coursenum,
                   2340: 						$coursedom,\%allfiles,
1.194     raeburn  2341: 						\%codebase,$1);
1.188     raeburn  2342:           if ($upload_result eq 'phasetwo') {
                   2343:               $r->print($upload_output);
                   2344:           }
                   2345:       } elsif ($env{'form.phasetwo'}) {
                   2346:           my %newname = ();
                   2347:           my %origname = ();
                   2348:           my %attribs = ();
                   2349:           my $updateflag = 0;
                   2350:           my $residx = $env{'form.newidx'};
                   2351:           my $primary_url = &Apache::lonnet::unescape($env{'form.primaryurl'});
                   2352: # Process file upload - phase two - gather secondary files.
                   2353:           for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
                   2354:               if ($env{'form.embedded_item_'.$i.'.filename'}) {
                   2355:                   my $javacodebase;
                   2356:                   $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
                   2357:                   $origname{$i} = &Apache::lonnet::unescape($env{'form.embedded_orig_'.$i});
                   2358:                   if (exists($env{'form.embedded_codebase_'.$i})) {
                   2359:                       $javacodebase =  &Apache::lonnet::unescape($env{'form.embedded_codebase_'.$i});  
                   2360:                       $origname{$i} =~ s#^\Q$javacodebase\E/##; 
                   2361:                   }
                   2362:                   my @attributes = ();
                   2363:                   if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
                   2364:                       @attributes = split/:/,$env{'form.embedded_attrib_'.$i};
                   2365:                   } else {
                   2366:                       @attributes = ($env{'form.embedded_attrib_'.$i});
                   2367:                   }
                   2368:                   foreach (@attributes) {
                   2369:                       push(@{$attribs{$i}},&Apache::lonnet::unescape($_));
                   2370:                   }
                   2371:                   if ($javacodebase) {
                   2372:                       $codebase{$i} = $javacodebase;
                   2373:                       $codebase{$i} =~ s#/$##;
                   2374:                       $updateflag = 1;
                   2375:                   }
                   2376:               }
                   2377:               unless ($newname{$i} eq $origname{$i}) {
                   2378:                   $updateflag = 1;
                   2379:               }
                   2380:           }
                   2381: # Process file upload - phase three - modify primary file
                   2382:           if ($updateflag) {
                   2383:               my ($content,$rtncode);
                   2384:               my $updateflag = 0;
                   2385:               my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
                   2386:               if ($getstatus eq 'ok') {
                   2387:                   foreach my $item (keys %newname) {
                   2388:                       if ($newname{$item} ne $origname{$item}) {
                   2389:                           my $attrib_regexp = '';
                   2390:                           if (@{$attribs{$item}} > 1) {
                   2391:                               $attrib_regexp = join('|',@{$attribs{$item}});
                   2392:                           } else {
                   2393:                               $attrib_regexp = $attribs{$item}[0];
                   2394:                           }
                   2395:                           if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
                   2396:                           } 
                   2397:                           $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi; 
                   2398:                       }
                   2399:                       if (exists($codebase{$item})) {
                   2400:                           $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i;
                   2401:                       }
                   2402:                   }
                   2403: # Save edited file.
                   2404:                   my $saveresult;
                   2405:                   my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   2406:                   my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.191     raeburn  2407:                   my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
1.188     raeburn  2408:               } else {
                   2409:                   &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus); 
                   2410:               }
                   2411:           }
                   2412:       }
                   2413:   }
                   2414: 
                   2415:   unless ($showdoc ||  $upload_result eq 'phasetwo') {
1.81      www      2416: # -----------------------------------------------------------------------------
                   2417:        my %lt=&Apache::lonlocal::texthash(
                   2418:                 'uplm' => 'Upload a new main course document',
                   2419:                 'upls' => 'Upload a new supplemental course document',
1.168     www      2420:                 'impp' => 'Import a document',
                   2421:                 'pubd' => 'Published documents',
1.181     www      2422: 		'copm' => 'All documents out of a published map into this folder',
1.81      www      2423:                 'spec' => 'Special documents',
                   2424:                 'upld' => 'Upload Document',
                   2425:                 'srch' => 'Search',
                   2426:                 'impo' => 'Import',
                   2427:                 'selm' => 'Select Map',
                   2428:                 'load' => 'Load Map',
1.186     www      2429:                 'reco' => 'Recover Deleted Resources',
1.81      www      2430:                 'newf' => 'New Folder',
1.142     raeburn  2431:                 'newp' => 'New Composite Page',
1.81      www      2432:                 'extr' => 'External Resource',
                   2433:                 'syll' => 'Syllabus',
                   2434:                 'navc' => 'Navigate Contents',
                   2435:                 'sipa' => 'Simple Page',
                   2436:                 'sipr' => 'Simple Problem',
                   2437:                 'scuf' => 'Score Upload Form',
                   2438:                 'bull' => 'Bulletin Board',
1.96      sakharuk 2439:                 'mypi' => 'My Personal Info',
1.101     www      2440: 		'abou' => 'About User',
1.110     raeburn  2441:                 'imsf' => 'Import IMS package',
1.96      sakharuk 2442:                 'file' =>  'File',
                   2443:                 'title' => 'Title',
1.188     raeburn  2444:                 'comment' => 'Comment',
                   2445:                 'parse' => 'If HTML file, upload embedded images/multimedia files'
1.81      www      2446: 					  );
                   2447: # -----------------------------------------------------------------------------
1.42      www      2448:     if ($allowed) {
1.74      www      2449:        my $dumpbut=&dumpbutton();
1.138     raeburn  2450:        my $exportbut=&exportbutton();
1.88      www      2451:        my %lt=&Apache::lonlocal::texthash(
                   2452: 					 'vc' => 'Verify Content',
                   2453: 					 'cv' => 'Check/Set Resource Versions',
                   2454: 					  );
1.118     albertel 2455: 
1.174     albertel 2456:        my $folderpath=$env{'form.folderpath'};
1.118     albertel 2457:        if (!$folderpath) {
1.174     albertel 2458: 	   if ($env{'form.folder'} eq '' ||
                   2459: 	       $env{'form.folder'} eq 'supplemental') {
1.118     albertel 2460: 	       $folderpath='default&'.
                   2461: 		   &Apache::lonnet::escape(&mt('Main Course Documents'));
                   2462: 	   }
                   2463:        }
1.174     albertel 2464:        unless ($env{'form.pagepath'}) {
1.142     raeburn  2465:            $containertag = '<input type="hidden" name="folderpath" value="" />';
                   2466:            $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
                   2467:        }
                   2468: 
1.42      www      2469:        $r->print(<<ENDCOURSEVERIFY);
1.36      www      2470: <form name="renameform" method="post" action="/adm/coursedocs">
                   2471: <input type="hidden" name="title" />
                   2472: <input type="hidden" name="cmd" />
1.168     www      2473: <input type="hidden" name="markcopy" />
1.142     raeburn  2474: $containertag
1.36      www      2475: </form>
1.39      www      2476: <form name="simpleedit" method="post" action="/adm/coursedocs">
                   2477: <input type=hidden name="importdetail" value="">
1.142     raeburn  2478: $uploadtag
1.39      www      2479: </form>
1.26      www      2480: <form action="/adm/coursedocs" method="post" name="courseverify">
1.74      www      2481: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
                   2482: <tr><td bgcolor="#DDDDCC">
1.130     www      2483: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
1.74      www      2484: </td><td bgcolor="#DDDDCC">
1.130     www      2485:     <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
1.74      www      2486: $dumpbut
1.138     raeburn  2487: $exportbut
1.74      www      2488: </td></tr></table>
1.25      www      2489: </form>
                   2490: ENDCOURSEVERIFY
1.74      www      2491:        $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1.96      sakharuk 2492: 		     &mt('Editing the Table of Contents for your Course')));
1.25      www      2493:     }
1.17      www      2494: # --------------------------------------------------------- Standard documents
1.43      www      2495:     $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1.7       www      2496:     if (($standard) && ($allowed) && (!$forcesupplement)) {
1.116     albertel 2497: 	$r->print('<tr><td bgcolor="#BBBBBB">');
                   2498: #  '<h2>'.&mt('Main Course Documents').
                   2499: #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1.174     albertel 2500:        my $folder=$env{'form.folder'};
1.117     albertel 2501:        if ($folder eq '' || $folder eq 'supplemental') {
1.112     raeburn  2502:            $folder='default';
1.174     albertel 2503: 	   $env{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
1.112     raeburn  2504:        }
1.51      www      2505:        my $postexec='';
                   2506:        if ($folder eq 'default') {
                   2507: 	   $r->print('<script>this.window.name="loncapaclient";</script>');
                   2508:        } else {
1.117     albertel 2509:            #$postexec='self.close();';
1.51      www      2510:        }
1.40      www      2511:        $hadchanges=0;
1.188     raeburn  2512:        &editor($r,$coursenum,$coursedom,$folder,$allowed,$upload_output);
1.40      www      2513:        if ($hadchanges) {
1.136     albertel 2514: 	   &mark_hash_old()
1.40      www      2515:        }
1.136     albertel 2516:        &changewarning($r,$postexec);
1.16      www      2517:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                   2518:                      '.sequence';
1.142     raeburn  2519:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                   2520:                      '.page';
1.186     www      2521: 	my $container='sequence';
                   2522: 	if ($env{'form.pagepath'}) {
                   2523: 	    $container='page';
                   2524: 	}
                   2525: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
1.8       www      2526:        $r->print(<<ENDFORM);
1.43      www      2527: <table cellspacing=4 cellpadding=4><tr>
1.81      www      2528: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
                   2529: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
                   2530: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.11      www      2531: </tr>
1.16      www      2532: <tr><td bgcolor="#DDDDDD">
1.96      sakharuk 2533: $lt{'file'}:<br />
1.182     albertel 2534: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59      www      2535: <input type="file" name="uploaddoc" size="40">
1.8       www      2536: <br />
1.96      sakharuk 2537: $lt{'title'}:<br />
1.11      www      2538: <input type="text" size="50" name="comment">
1.142     raeburn  2539: $uploadtag
1.10      www      2540: <input type="hidden" name="cmd" value="upload_default">
1.188     raeburn  2541: <br />
                   2542: <nobr>
1.190     albertel 2543: <label>$lt{'parse'}?
1.188     raeburn  2544: <input type="checkbox" name="parserflag" />
1.190     albertel 2545: </label>
1.188     raeburn  2546: </nobr>
                   2547: <br />
                   2548: <br />
1.129     albertel 2549: <nobr>
1.81      www      2550: <input type="submit" value="$lt{'upld'}">
1.60      albertel 2551:  $help{'Uploading_From_Harddrive'}
1.58      albertel 2552: </nobr>
1.60      albertel 2553: </form>
1.11      www      2554: </td>
1.16      www      2555: <td bgcolor="#DDDDDD">
1.39      www      2556: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.168     www      2557: $lt{'pubd'}<br />
1.142     raeburn  2558: $uploadtag
1.115     albertel 2559: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
1.58      albertel 2560: <nobr>
1.115     albertel 2561: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
1.58      albertel 2562: $help{'Importing_LON-CAPA_Resource'}
                   2563: </nobr>
1.59      www      2564: <p>
                   2565: <hr />
1.181     www      2566: $lt{'copm'}<br />
                   2567: <input type="text" size="40" name="importmap"><br />
1.68      bowersj2 2568: <nobr><input type=button 
1.52      www      2569: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.81      www      2570: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
1.68      bowersj2 2571: $help{'Load_Map'}</nobr>
1.59      www      2572: </p>
1.52      www      2573: </form>
1.186     www      2574: <hr />
                   2575: <form action="/adm/groupsort" method="post" name="recover">
                   2576: <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1)" value="$lt{'reco'}" />
                   2577: </form>
1.142     raeburn  2578: ENDFORM
1.174     albertel 2579:        unless ($env{'form.pagepath'}) {
1.168     www      2580: 	   $r->print(<<ENDFORM);
                   2581: <hr />
                   2582: <form action="/adm/coursedocs" method="post" name="newext">
                   2583: $uploadtag
                   2584: <input type=hidden name="importdetail" value="">
                   2585: <nobr>
                   2586: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
                   2587: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
                   2588: </nobr>
                   2589: </form>
                   2590: <form action="/adm/imsimportdocs" method="post" name="ims">
                   2591: <input type="hidden" name="folder" value="$folder" />
                   2592: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
                   2593: </nobr>
                   2594: </form>
                   2595: ENDFORM
                   2596:        }
                   2597:        $r->print('</td><td bgcolor="#DDDDDD">');
1.174     albertel 2598:        unless ($env{'form.pagepath'}) {
1.142     raeburn  2599:            $r->print(<<ENDFORM);
1.11      www      2600: <form action="/adm/coursedocs" method="post" name="newfolder">
1.174     albertel 2601: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.13      www      2602: <input type=hidden name="importdetail" value="">
1.58      albertel 2603: <nobr>
1.16      www      2604: <input name="newfolder" type="button"
                   2605: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81      www      2606: value="$lt{'newf'}" />$help{'Adding_Folders'}
1.58      albertel 2607: </nobr>
1.11      www      2608: </form>
1.142     raeburn  2609: <form action="/adm/coursedocs" method="post" name="newpage">
1.174     albertel 2610: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.142     raeburn  2611: <input type=hidden name="importdetail" value="">
                   2612: <nobr>
                   2613: <input name="newpage" type="button"
                   2614: onClick="javascript:makenewpage(this.form,'$pageseq');"
                   2615: value="$lt{'newp'}" />$help{'Adding_Pages'}
                   2616: </nobr>
                   2617: </form>
1.11      www      2618: <form action="/adm/coursedocs" method="post" name="newsyl">
1.142     raeburn  2619: $uploadtag
1.14      www      2620: <input type=hidden name="importdetail" 
                   2621: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58      albertel 2622: <nobr>
1.81      www      2623: <input name="newsyl" type="submit" value="$lt{'syll'}" /> 
1.65      bowersj2 2624:  $help{'Syllabus'}
1.58      albertel 2625: </nobr>
                   2626: </form>
1.17      www      2627: <form action="/adm/coursedocs" method="post" name="newnav">
1.142     raeburn  2628: $uploadtag
1.15      www      2629: <input type=hidden name="importdetail" 
                   2630: value="Navigate Content=/adm/navmaps">
1.58      albertel 2631: <nobr>
1.81      www      2632: <input name="newnav" type="submit" value="$lt{'navc'}" />
1.47      www      2633: $help{'Navigate_Content'}
1.58      albertel 2634: </nobr>
1.22      www      2635: </form>
                   2636: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.142     raeburn  2637: $uploadtag
1.22      www      2638: <input type=hidden name="importdetail" value="">
1.58      albertel 2639: <nobr>
1.81      www      2640: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1.65      bowersj2 2641: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1.58      albertel 2642: </nobr>
1.55      www      2643: </form>
                   2644: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.142     raeburn  2645: $uploadtag
1.55      www      2646: <input type=hidden name="importdetail" value="">
1.58      albertel 2647: <nobr>
1.81      www      2648: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1.65      bowersj2 2649: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.62      www      2650: </nobr>
                   2651: </form>
                   2652: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.142     raeburn  2653: $uploadtag
1.62      www      2654: <input type=hidden name="importdetail" value="">
                   2655: <nobr>
1.81      www      2656: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1.62      www      2657: onClick="javascript:makeexamupload();" />
1.66      bowersj2 2658: $help{'Score_Upload_Form'}
1.58      albertel 2659: </nobr>
1.22      www      2660: </form>
                   2661: <form action="/adm/coursedocs" method="post" name="newbul">
1.142     raeburn  2662: $uploadtag
1.22      www      2663: <input type=hidden name="importdetail" value="">
1.58      albertel 2664: <nobr>
1.81      www      2665: <input name="newbulletin" type="button" value="$lt{'bull'}"
1.22      www      2666: onClick="javascript:makebulboard();" />
1.65      bowersj2 2667: $help{'Bulletin Board'}
1.58      albertel 2668: </nobr>
                   2669: </form>
1.12      www      2670: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.142     raeburn  2671: $uploadtag
1.14      www      2672: <input type=hidden name="importdetail" 
                   2673: value="$plainname=/adm/$udom/$uname/aboutme">
1.58      albertel 2674: <nobr>
1.81      www      2675: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65      bowersj2 2676: $help{'My Personal Info'}
1.101     www      2677: </nobr>
                   2678: </form>
                   2679: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.142     raeburn  2680: $uploadtag
1.101     www      2681: <input type=hidden name="importdetail" value="">
                   2682: <nobr>
                   2683: <input name="newaboutsomeone" type="button" value="$lt{'abou'}" 
                   2684: onClick="javascript:makeabout();" />
1.110     raeburn  2685: </nobr>
1.182     albertel 2686: </form>
1.142     raeburn  2687: ENDFORM
                   2688:        }
1.174     albertel 2689:        if ($env{'form.pagepath'}) {
1.142     raeburn  2690:            $r->print(<<ENDBLOCK);
                   2691: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
                   2692: $uploadtag
                   2693: <input type=hidden name="importdetail" value="">
                   2694: <nobr>
                   2695: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
                   2696: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
                   2697: </nobr>
                   2698: </form>
                   2699: <form action="/adm/coursedocs" method="post" name="newexamupload">
                   2700: $uploadtag
                   2701: <input type=hidden name="importdetail" value="">
                   2702: <nobr>
                   2703: <input name="newexamupload" type="button" value="$lt{'scuf'}"
                   2704: onClick="javascript:makeexamupload();" />
                   2705: $help{'Score_Upload_Form'}
                   2706: </nobr>
1.182     albertel 2707: </form>
1.142     raeburn  2708: ENDBLOCK
                   2709:        }
                   2710:        $r->print('</td></tr>'."\n".
                   2711: '</table>');
1.24      www      2712:        $r->print('</td></tr>');
1.7       www      2713:     }
                   2714: # ----------------------------------------------------- Supplemental documents
                   2715:     if (!$forcestandard) {
1.116     albertel 2716:        $r->print('<tr><td bgcolor="#BBBBBB">');
                   2717: # '<h2>'.&mt('Supplemental Course Documents').
                   2718: #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1.174     albertel 2719:        my $folder=$env{'form.folder'};
1.117     albertel 2720:        unless ($folder=~/^supplemental/) {
1.116     albertel 2721: 	   $folder='supplemental';
1.117     albertel 2722:        }
                   2723:        if ($folder =~ /^supplemental$/ &&
1.174     albertel 2724: 	   $env{'form.folderpath'} =~ /^default\&/) {
                   2725: 	   $env{'form.folderpath'}='supplemental&'.
1.117     albertel 2726: 	       &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
1.116     albertel 2727:        }
1.7       www      2728:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8       www      2729:        if ($allowed) {
1.17      www      2730:        my $folderseq=
                   2731:                   '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
                   2732:                      '.sequence';
                   2733: 
1.8       www      2734:           $r->print(<<ENDSUPFORM);
1.43      www      2735: <table cellspacing=4 cellpadding=4><tr>
1.81      www      2736: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
                   2737: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.17      www      2738: </tr>
                   2739: <tr><td bgcolor="#DDDDDD">
1.10      www      2740: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59      www      2741: <input type="file" name="uploaddoc" size="40">
1.196     raeburn  2742: <br />
                   2743: <br />
                   2744: <nobr>
                   2745: <label>$lt{'parse'}?
                   2746: <input type="checkbox" name="parserflag" />
                   2747: </label>
                   2748: </nobr>
                   2749: <br /><br />
                   2750: $lt{'comment'}:<br />
1.4       www      2751: <textarea cols=50 rows=4 name='comment'>
                   2752: </textarea>
1.115     albertel 2753: <br />
1.174     albertel 2754: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.10      www      2755: <input type="hidden" name="cmd" value="upload_supplemental">
1.58      albertel 2756: <nobr>
1.81      www      2757: <input type="submit" value="$lt{'upld'}">
1.58      albertel 2758:  $help{'Uploading_From_Harddrive'}
                   2759: </nobr>
                   2760: </form>
1.17      www      2761: </td>
                   2762: <td bgcolor="#DDDDDD">
1.18      www      2763: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.174     albertel 2764: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17      www      2765: <input type=hidden name="importdetail" value="">
1.58      albertel 2766: <nobr>
1.17      www      2767: <input name="newfolder" type="button"
                   2768: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81      www      2769: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1.58      albertel 2770: </nobr>
1.17      www      2771: </form>
1.18      www      2772: <form action="/adm/coursedocs" method="post" name="supnewext">
1.174     albertel 2773: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17      www      2774: <input type=hidden name="importdetail" value="">
1.58      albertel 2775: <nobr>
1.18      www      2776: <input name="newext" type="button" 
                   2777: onClick="javascript:makenewext('supnewext');"
1.81      www      2778: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.58      albertel 2779: </nobr>
1.17      www      2780: </form>
1.18      www      2781: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.174     albertel 2782: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17      www      2783: <input type=hidden name="importdetail" 
                   2784: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58      albertel 2785: <nobr>
1.81      www      2786: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65      bowersj2 2787: $help{'Syllabus'}
1.58      albertel 2788: </nobr>
                   2789: </form>
1.18      www      2790: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.174     albertel 2791: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17      www      2792: <input type=hidden name="importdetail" 
                   2793: value="$plainname=/adm/$udom/$uname/aboutme">
1.58      albertel 2794: <nobr>
1.81      www      2795: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65      bowersj2 2796: $help{'My Personal Info'}
1.58      albertel 2797: </nobr>
                   2798: </form>
1.17      www      2799: </td></tr>
1.24      www      2800: </table></td></tr>
1.8       www      2801: ENDSUPFORM
                   2802:        }
1.7       www      2803:     }
1.18      www      2804:     if ($allowed) {
1.182     albertel 2805: 	$r->print('<form method="POST" name="extimport" action="/adm/coursedocs"><input type="hidden" name="title" /><input type="hidden" name="url" /><input type="hidden" name="useform" /></form>');
1.18      www      2806:     }
1.24      www      2807:     $r->print('</table>');
1.19      www      2808:   } else {
1.188     raeburn  2809:       unless ($upload_result eq 'phasetwo') {
1.19      www      2810: # -------------------------------------------------------- This is showdoc mode
1.188     raeburn  2811:           $r->print("<h1>".&mt('Uploaded Document').' - '.
1.141     albertel 2812: 		&Apache::lonnet::gettitle($r->uri).'</h1><p>'.
1.81      www      2813: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
1.188     raeburn  2814:           &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
                   2815:       }
1.19      www      2816:   }
1.26      www      2817:  }
1.95      www      2818:  $r->print('</body></html>');
1.26      www      2819:  return OK;
1.1       www      2820: } 
                   2821: 
                   2822: 1;
                   2823: __END__

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