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

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

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