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

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

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