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

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

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