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

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

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