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

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

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