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

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

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