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

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

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