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

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

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