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

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

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