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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Documents
1.1       www         3: #
1.142   ! raeburn     4: # $Id: londocs.pm,v 1.141 2004/09/09 18:56:01 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.4       www        33: use Apache::lonnet;
                     34: use Apache::loncommon;
1.7       www        35: use Apache::lonratedt;
                     36: use Apache::lonratsrv;
1.15      www        37: use Apache::lonxml;
1.74      www        38: use Apache::loncreatecourse;
1.138     raeburn    39: use Apache::lonnavmaps;
1.38      www        40: use HTML::Entities;
1.27      www        41: use GDBM_File;
1.81      www        42: use Apache::lonlocal;
1.7       www        43: 
1.8       www        44: my $iconpath;
1.7       www        45: 
1.27      www        46: my %hash;
                     47: 
                     48: my $hashtied;
1.29      www        49: my %alreadyseen=();
1.27      www        50: 
1.40      www        51: my $hadchanges;
                     52: 
1.47      www        53: # Available help topics
                     54: 
                     55: my %help=();
                     56: 
1.7       www        57: # Mapread read maps into lonratedt::global arrays 
1.10      www        58: # @order and @resources, determines status
1.7       www        59: # sets @order - pointer to resources in right order
                     60: # sets @resources - array with the resources with correct idx
                     61: #
                     62: 
                     63: sub mapread {
                     64:     my ($coursenum,$coursedom,$map)=@_;
                     65:     return
                     66:       &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                     67:                                 $map);
                     68: }
                     69: 
                     70: sub storemap {
                     71:     my ($coursenum,$coursedom,$map)=@_;
1.104     albertel   72:     my ($outtext,$errtext)=
1.7       www        73:       &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.15      www        74:                                 $map,1);
1.104     albertel   75:     if ($errtext) { return ($errtext,2); }
                     76:     
                     77:     $hadchanges=1;
                     78:     return ($errtext,0);
1.7       www        79: }
                     80: 
1.74      www        81: # ----------------------------------------- Return hash with valid author names
                     82: 
                     83: sub authorhosts {
                     84:     my %outhash=();
                     85:     my $home=0;
                     86:     my $other=0;
                     87:     foreach (keys %ENV) {
                     88: 	if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
                     89: 	    my $role=$1;
                     90: 	    my $realm=$2;
                     91: 	    my ($start,$end)=split(/\./,$ENV{$_});
                     92: 	    if (($start) && ($start>time)) { next; }
                     93: 	    if (($end) && (time>$end)) { next; }
                     94: 	    my $ca; my $cd;
                     95: 	    if ($1 eq 'au') {
                     96: 		$ca=$ENV{'user.name'};
                     97: 		$cd=$ENV{'user.domain'};
                     98: 	    } else {
                     99: 		($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
                    100: 	    }
1.107     albertel  101: 	    my $allowed=0;
                    102: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
                    103: 	    my @ids=&Apache::lonnet::current_machine_ids();
                    104: 	    foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
                    105: 	    if ($allowed) {
1.74      www       106: 		$home++;
                    107: 		$outhash{'home_'.$ca.'@'.$cd}=1;
                    108: 	    } else {
1.107     albertel  109: 		$outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
1.74      www       110: 		$other++;
                    111: 	    }
                    112: 	}
                    113:     }
                    114:     return ($home,$other,%outhash);
                    115: }
                    116: # ------------------------------------------------------ Generate "dump" button
                    117: 
                    118: sub dumpbutton {
                    119:     my ($home,$other,%outhash)=&authorhosts();
                    120:     if ($home+$other==0) { return ''; }
                    121:     my $output='</td><td bgcolor="#DDDDCC">';
                    122:     if ($home) {
                    123: 	return '</td><td bgcolor="#DDDDCC">'.
1.81      www       124: 	    '<input type="submit" name="dumpcourse" value="'.
1.130     www       125: 	    &mt('Dump Course DOCS to Construction Space').'" />'.
                    126: 	    &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
1.74      www       127:     } else {
                    128: 	return'</td><td bgcolor="#DDDDCC">'.
1.81      www       129:      &mt('Dump Course DOCS to Construction Space: available on other servers');
1.74      www       130:     }
                    131: }
                    132: 
                    133: # -------------------------------------------------------- Actually dump course
                    134: 
                    135: sub dumpcourse {
1.75      www       136:     my $r=shift;
                    137:     $r->print('<html><head><title>Dump DOCS</title></head>'.
1.76      www       138:         &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
                    139: 	      '<form name="dumpdoc" method="post">');
1.74      www       140:     my ($home,$other,%outhash)=&authorhosts();
1.75      www       141:     unless ($home) { return ''; }
1.76      www       142:     my $origcrsid=$ENV{'request.course.id'};
                    143:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    144:     if (($ENV{'form.authorspace'}) && ($ENV{'form.authorfolder'}=~/\w/)) {
                    145: # Do the dumping
1.75      www       146: 	unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
                    147: 	my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
1.87      www       148: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
1.76      www       149: 	my $title=$ENV{'form.authorfolder'};
1.79      www       150: 	$title=~s/[^\w\/]+/\_/g;
                    151: 	my %replacehash=();
                    152: 	foreach (keys %ENV) {
                    153: 	    if ($_=~/^form\.namefor\_(.+)/) {
                    154: 		$replacehash{$1}=$ENV{$_};
                    155: 	    }
                    156: 	}
                    157: 	my $crs='/uploaded/'.$ENV{'request.course.id'}.'/';
                    158: 	$crs=~s/\_/\//g;
                    159: 	foreach (keys %replacehash) {
                    160: 	    my $newfilename=$title.'/'.$replacehash{$_};
1.132     www       161: 	    $newfilename=~s/[^\w\/\.\/]+/\_/g;
1.79      www       162: 	    my @dirs=split(/\//,$newfilename);
                    163: 	    my $path='/home/'.$ca.'/public_html';
                    164: 	    my $makepath=$path;
                    165: 	    my $fail=0;
                    166: 	    for (my $i=0;$i<$#dirs;$i++) {
                    167: 		$makepath.='/'.$dirs[$i];
                    168: 		unless (-e $makepath) { 
                    169: 		    unless(mkdir($makepath,0777)) { $fail=1; } 
                    170: 		}
                    171: 	    }
                    172: 	    $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
                    173: 	    if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
                    174: 		if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
                    175: 		    print $fh &Apache::loncreatecourse::rewritefile(
                    176:          &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_),
                    177: 				     (%replacehash,$crs => '')
                    178: 								    );
                    179: 		} else {
                    180: 		    print $fh
                    181:          &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_);
                    182: 		       }
                    183: 		$fh->close();
                    184: 	    } else {
                    185: 		$fail=1;
                    186: 	    }
                    187: 	    if ($fail) {
                    188: 		$r->print('<font color="red">fail</font>');
                    189: 	    } else {
                    190: 		$r->print('<font color="green">ok</font>');
                    191: 	    }
                    192: 	}
1.76      www       193:     } else {
                    194: # Input form
                    195: 	unless ($home==1) {
                    196: 	    $r->print(
1.81      www       197: 		      '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
1.76      www       198: 	}
                    199: 	foreach (sort keys %outhash) {
                    200: 	    if ($_=~/^home_(.+)$/) {
                    201: 		if ($home==1) {
                    202: 		    $r->print(
                    203: 		  '<input type="hidden" name="authorspace" value="'.$1.'" />');
                    204: 		} else {
1.133     www       205: 		    $r->print('<option value="'.$1.'">'.$1.' - '.
                    206: 			      &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
1.76      www       207: 		}
                    208: 	    }
                    209: 	}
                    210: 	unless ($home==1) {
                    211: 	    $r->print('</select>');
                    212: 	}
                    213: 	my $title=$origcrsdata{'description'};
                    214: 	$title=~s/\s+/\_/gs;
                    215: 	$title=~s/\W//gs;
1.81      www       216: 	$r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
1.76      www       217: 	&tiehash();
1.81      www       218: 	$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       219: 	foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
1.78      www       220: 	    $r->print('<tr><td>'.$_.'</td>');
                    221: 	    my ($ext)=($_=~/\.(\w+)$/);
                    222: 	    my $title=$hash{'title_'.$hash{
                    223: 		'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
                    224: 	    $r->print('<td>'.($title?$title:'&nbsp;').'</td>');
                    225: 	    unless ($title) {
                    226: 		$title=$_;
                    227: 	    }
                    228: 	    $title=~s/\.(\w+)$//;
1.132     www       229: 	    $title=~s/[^\w\/]+/\_/gs;
1.78      www       230: 	    $title.='.'.$ext;
1.79      www       231: 	    $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
1.76      www       232: 	}
1.78      www       233: 	$r->print("</table>\n");
1.76      www       234: 	&untiehash();
                    235: 	$r->print(
1.81      www       236:   '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump Course DOCS').'" /></p></form>');
1.75      www       237:     }
1.74      www       238: }
1.76      www       239: 
1.138     raeburn   240: # ------------------------------------------------------ Generate "export" button
                    241: 
                    242: sub exportbutton {
                    243:     return '</td><td bgcolor="#DDDDCC">'.
                    244:             '<input type="submit" name="exportcourse" value="'.
                    245:             &mt('Export Course to IMS').'" />'.
                    246:             &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
                    247: }
                    248: 
                    249: sub exportcourse {
                    250:     my $r=shift;
                    251:     my %discussiontime = &Apache::lonnet::dump('discussiontimes',
                    252:                                                $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    253:     my $numdisc = keys %discussiontime;
                    254:     my $navmap = Apache::lonnavmaps::navmap->new();
                    255:     my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
                    256:     my $curRes;
                    257: 
                    258:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    259:                                             ['finishexport']);
                    260:     if ($ENV{'form.finishexport'}) {
                    261:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    262:                                             ['archive','discussion']);
                    263: 
                    264:         my @exportitems = ();
                    265:         if (defined($ENV{'form.archive'})) {
                    266:             if (ref($ENV{'form.archive'}) eq 'ARRAY') {
                    267:                 @exportitems = @{$ENV{'form.archive'}};
                    268:             } else {
                    269:                 $exportitems[0] = $ENV{'form.archive'};
                    270:             }
                    271:         }
                    272:         my @discussions = ();
                    273:         if (defined($ENV{'form.discussion'})) {
                    274:             if (ref($ENV{'form.discussion'}) eq 'ARRAY') {
                    275:                 @discussions = $ENV{'form.discussion'};
                    276:             } else {
                    277:                 $discussions[0] = $ENV{'form.discussion'};
                    278:             }
                    279:         }
                    280:         my $curRes;
                    281:         my $count;
                    282:         my %symbs;
                    283:         my $display;
                    284:         while ($curRes = $it->next()) {
                    285:             if (ref($curRes)) {
                    286:                 $count ++;
                    287:                 $symbs{$count} = $curRes->symb();
                    288:                 if (grep/^$count$/,@exportitems) {
                    289:                     $display.= 'Export content item '.$curRes->title()."<br />\n";
                    290:                 }
                    291:                 if (grep/^$count$/,@discussions) {
                    292:                     $display.= 'Export discussion posts '.$curRes->title()."<br />\n";
                    293:                 }  
                    294:             }
                    295:         }
                    296: 
                    297:         $r->print('<html><head><title>Export Course</title></head>'.
                    298:             &Apache::loncommon::bodytag('Export course to IMS or SCORM content package'
                    299: ));
                    300: 
                    301:         my $exportfile;
                    302:         $r->print($display);
                    303:         $r->print('</body></html>');
                    304:     } else {
                    305:         my $display;
                    306:         $display = '<form name="exportdoc" method="post">'."\n";
                    307:         $display .= 'Choose which items you wish to export from your course.<br /><br />';
                    308:         $display .= '<table border="0" cellspacing="0" cellpadding="3">'.
                    309:                     '<tr><td><fieldset><legend>&nbsp;<b>Content items</b></legend>'.
                    310:                     '<input type="button" value="check all" '.
                    311:                     'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
                    312:                     '&nbsp;&nbsp;<input type="button" value="uncheck all"'.
                    313:                     ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.
                    314:                     '<td>&nbsp;</td><td>&nbsp;</td>'.
                    315:                     '<td align="right"><fieldset><legend>&nbsp;<b>Discussion posts'.
                    316:                     '</b></legend><input type="button" value="check all"'.
                    317:                     ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
                    318:                     '&nbsp;&nbsp;<input type="button" value="uncheck all"'.
                    319:                     ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.
                    320:                     '</tr></table>';
                    321:         my $curRes;
                    322:         my $depth = 0;
                    323:         my $count = 0;
                    324:         my $boards = 0;
                    325:         my $startcount = 5;
                    326:         my %parent = ();
                    327:         my %children = ();
                    328:         my $lastcontainer = $startcount;
                    329:         my @bgcolors = ('#F6F6F6','#FFFFFF');
                    330:         $display .= '<table cellspacing="0"><tr>'.
                    331:             '<td><b>Export content item?<br /></b></td><td>&nbsp;</td><td align="right">'."\n";
                    332:         if ($numdisc > 0) {
                    333:             $display.='<b>Export&nbsp;discussion posts?</b>'."\n";
                    334:         }
                    335:         $display.='&nbsp;</td></tr>';
                    336:         while ($curRes = $it->next()) {
                    337:             if (ref($curRes)) {
                    338:                 $count ++;
                    339:             }
                    340:             if ($curRes == $it->BEGIN_MAP()) {
                    341:                 $depth++;
                    342:                 $parent{$depth} = $lastcontainer;
                    343:             }
                    344:             if ($curRes == $it->END_MAP()) {
                    345:                 $depth--;
                    346:                 $lastcontainer = $parent{$depth};
                    347:             }
                    348:             if (ref($curRes)) {
                    349:                 my $symb = $curRes->symb();
                    350:                 my $color = $count%2;
                    351:                 $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".
                    352:                     '<input type="checkbox" name="archive" value="'.$count.'" ';
                    353:                 if (($curRes->is_sequence()) || ($curRes->is_page())) {
                    354:                     my $checkitem = $count + $boards + $startcount;
                    355:                     $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';
                    356:                 }
                    357:                 $display .= ' />'."\n";
                    358:                 for (my $i=0; $i<$depth; $i++) {
                    359:                     $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";
                    360:                 }
                    361:                 if ($curRes->is_sequence()) {
                    362:                     $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif">&nbsp;'."\n";
                    363:                     $lastcontainer = $count + $startcount + $boards;
                    364:                 } elsif ($curRes->is_page()) {
                    365:                     $display .= '<img src="/adm/lonIcons/navmap.page.open.gif">&nbsp;'."\n";
                    366:                     $lastcontainer = $count + $startcount + $boards;
                    367:                 }
                    368:                 my $currelem = $count+$boards+$startcount;
                    369:                 $children{$parent{$depth}} .= $currelem.':';
                    370:                 $display .= '&nbsp;'.$curRes->title().'</td>';
                    371:                 if ($discussiontime{$symb} > 0) {
                    372:                     $boards ++;
                    373:                     $currelem = $count+$boards+$startcount;
                    374:                     $display .= '<td>&nbsp;</td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" />&nbsp;</td>'."\n";
                    375:                 } else {
                    376:                     $display .= '<td colspan="2">&nbsp;</td>'."\n";
                    377:                 }
                    378:             }
                    379:         }
                    380:         my $scripttag = qq|
                    381: <script>
                    382: 
                    383: function checkAll(field) {
                    384:     for (i = 0; i < field.length; i++)
                    385:         field[i].checked = true ;
                    386: }
                    387: 
                    388: function uncheckAll(field) {
                    389:     for (i = 0; i < field.length; i++)
                    390:         field[i].checked = false ;
                    391: }
                    392: 
                    393: function propagateCheck(item) {
                    394:     if (document.exportdoc.elements[item].checked == true) {
                    395:         containerCheck(item)
                    396:     }
                    397: } 
                    398: 
                    399: function containerCheck(item) {
                    400:     document.exportdoc.elements[item].checked = true
                    401:     var numitems = $count + $boards + $startcount
                    402:     var parents = new Array(numitems)
                    403:     for (var i=$startcount; i<numitems; i++) {
                    404:         parents[i] = new Array
                    405:     }
                    406:         |;
                    407: 
                    408:         foreach my $container (sort { $a <=> $b } keys %children) {
                    409:             my @contents = split/:/,$children{$container};
                    410:             for (my $i=0; $i<@contents; $i ++) {
                    411:                 $scripttag .= '    parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
                    412:             }
                    413:         }
                    414: 
                    415:         $scripttag .= qq|
                    416:     if (parents[item].length > 0) {
                    417:         for (var j=0; j<parents[item].length; j++) {
                    418:             containerCheck(parents[item][j])
                    419:         }
                    420:      }   
                    421: }
                    422: 
                    423: </script>
                    424:         |;
                    425:         $r->print('<html><head><title>Export Course</title>'.$scripttag.'</head>'.
                    426:             &Apache::loncommon::bodytag('Export course to IMS or SCORM content package'
                    427: ));
                    428: 
                    429:         $r->print($display.'</table>'.
                    430:                   '<p><input type="hidden" name="finishexport" value="1">'.
                    431:                   '<input type="submit" name="exportcourse" value="'.
                    432:                   &mt('Export Course DOCS').'" /></p></form></body></html>');
                    433:     }
                    434: }
                    435: 
1.74      www       436: 
1.73      bowersj2  437: # Imports the given (name, url) resources into the course
                    438: # coursenum, coursedom, and folder must precede the list
                    439: sub group_import {
                    440:     my $coursenum = shift;
                    441:     my $coursedom = shift;
                    442:     my $folder = shift;
1.142   ! raeburn   443:     my $container = shift;
        !           444:     my $caller = shift;
1.73      bowersj2  445:     while (@_) {
                    446: 	my $name = shift;
                    447: 	my $url = shift;
1.142   ! raeburn   448:         if (($url =~ m#^/uploaded/$coursedom/$coursenum/(default_\d+\.)(page|sequence)$#) && ($caller eq 'londocs')) {
        !           449:             my $errtext = '';
        !           450:             my $fatal = 0;
        !           451:             my $newmapstr = '<map>'."\n".
        !           452:                             '<resource id="1" src="" type="start"></resource>'."\n".
        !           453:                             '<link from="1" to="2" index="1"></link>'."\n".
        !           454:                             '<resource id="2" src="" type="finish"></resource>'."\n".
        !           455:                             '</map>';
        !           456:             $ENV{'form.output'}=$newmapstr;
        !           457:             my $home=&Apache::lonnet::homeserver($coursenum,$coursedom);
        !           458:             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$home,
        !           459:                                                 'output',$1.$2);
        !           460:             if ($result != m|^/uploaded/|) {
        !           461:                 $errtext.='Map not saved: A network error occured when trying to save the new map. ';
        !           462:                 $fatal = 2;
        !           463:             }
        !           464:             if ($fatal) {
        !           465:                 return ($errtext,$fatal);
        !           466:             }
        !           467:         }
1.73      bowersj2  468: 	if ($url) {
                    469: 	    my $idx = $#Apache::lonratedt::resources + 1;
                    470: 	    $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
                    471: 	    my $ext = 'false';
                    472: 	    if ($url=~/^http:\/\//) { $ext = 'true'; }
                    473: 	    $url =~ s/:/\&colon;/g;
                    474: 	    $name =~ s/:/\&colon;/g;
                    475: 	    $Apache::lonratedt::resources[$idx] = 
                    476: 		join ':', ($name, $url, $ext, 'normal', 'res');
                    477: 	}
                    478:     }
1.142   ! raeburn   479:     return &storemap($coursenum, $coursedom, $folder.'.'.$container);
1.73      bowersj2  480: }
                    481: 
1.114     albertel  482: sub breadcrumbs {
                    483:     my ($where)=@_;
                    484:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.142   ! raeburn   485:     my (@folders);
        !           486:     if ($ENV{'form.pagepath'}) {
        !           487:         @folders = split('&',$ENV{'form.pagepath'});
        !           488:     } else {
        !           489:         @folders=split('&',$ENV{'form.folderpath'});
        !           490:     }
1.116     albertel  491:     my $folderpath;
                    492:     while (@folders) {
                    493: 	my $folder=shift(@folders);
                    494: 	my $foldername=shift(@folders);
                    495: 	if ($folderpath) {$folderpath.='&';}
                    496: 	$folderpath.=$folder.'&'.$foldername;
                    497: 	my $url='/adm/coursedocs?folderpath='.
                    498: 	    &Apache::lonnet::escape($folderpath);
1.114     albertel  499: 	    &Apache::lonhtmlcommon::add_breadcrumb(
                    500: 		      {'href'=>$url,
                    501: 		       'title'=>&Apache::lonnet::unescape($foldername),
1.117     albertel  502: 		       'text'=>'<font size="+1">'.
                    503: 			   &Apache::lonnet::unescape($foldername).'</font>'
                    504: 		       });
1.114     albertel  505: 		       
                    506: 						 
                    507:     }
1.137     albertel  508:     return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,
                    509: 					       0,'nohelp');
1.114     albertel  510: }
                    511: 
1.7       www       512: sub editor {
                    513:     my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
1.114     albertel  514: 
                    515:     $r->print(&breadcrumbs($folder));
1.10      www       516:     my $errtext='';
                    517:     my $fatal=0;
1.142   ! raeburn   518:     my $container='sequence';
        !           519:     if ($ENV{'form.pagepath'}) {
        !           520:         $container='page';
        !           521:     }
1.10      www       522:     ($errtext,$fatal)=
1.142   ! raeburn   523:               &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.17      www       524:     if ($#Apache::lonratedt::order<1) {
                    525:        	$Apache::lonratedt::order[0]=1;
                    526:         $Apache::lonratedt::resources[1]='';
                    527:     }
1.7       www       528:     if ($fatal) {
                    529: 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    530:     } else {
                    531: # ------------------------------------------------------------ Process commands
1.121     www       532: 
1.16      www       533: # ---------------- if they are for this folder and user allowed to make changes
                    534: 	if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
1.123     www       535: # set parameters and change order
1.121     www       536: 	    if (defined($ENV{'form.setparms'})) {
                    537: 		my $idx=$ENV{'form.setparms'};
1.123     www       538: # set parameters
1.121     www       539: 		if ($ENV{'form.randpick_'.$idx}) {
1.122     www       540: 		    &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
1.121     www       541: 		} else {
1.122     www       542: 		    &Apache::lonratedt::delparameter($idx,'parameter_randompick');
1.121     www       543: 		}
                    544: 		if ($ENV{'form.hidprs_'.$idx}) {
1.122     www       545: 		    &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
1.121     www       546: 		} else {
1.122     www       547: 		    &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
1.121     www       548: 		}
                    549: 		if ($ENV{'form.encprs_'.$idx}) {
1.122     www       550: 		    &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
1.121     www       551: 		} else {
1.122     www       552: 		    &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
1.121     www       553: 		}
                    554: 
1.123     www       555: 		if ($ENV{'form.newpos'}) {
                    556: # change order
                    557: 
                    558: 		    my $newpos=$ENV{'form.newpos'}-1;
1.124     www       559: 		    my $currentpos=$ENV{'form.currentpos'}-1;
1.125     www       560: 		    my $i;
                    561: 		    my @neworder=();
                    562: 		    if ($newpos>$currentpos) {
                    563: # moving stuff up
                    564: 			for ($i=0;$i<$currentpos;$i++) {
                    565: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                    566: 			}
                    567: 			for ($i=$currentpos;$i<$newpos;$i++) {
                    568: 			    $neworder[$i]=$Apache::lonratedt::order[$i+1];
                    569: 			}
                    570:                         $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
                    571: 			for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
                    572: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                    573: 			}
                    574: 		    } else {
                    575: # moving stuff down
                    576: 			for ($i=0;$i<$newpos;$i++) {
                    577: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                    578: 			}
                    579: 			$neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
                    580: 			for ($i=$newpos+1;$i<$currentpos+1;$i++) {
                    581: 			    $neworder[$i]=$Apache::lonratedt::order[$i-1];
                    582: 			}
                    583: 			for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
                    584: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                    585: 			}
                    586: 		    }
                    587: 		    @Apache::lonratedt::order=@neworder;
1.124     www       588: 		}
                    589: # store the changed version
1.123     www       590: 
1.142   ! raeburn   591: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1.124     www       592: 		if ($fatal) {
                    593: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    594: 		    return;
1.123     www       595: 		}
1.124     www       596: 		
                    597: 	    }
1.123     www       598: 
1.10      www       599: # upload a file, if present
                    600:            if (($ENV{'form.uploaddoc.filename'}) &&
                    601:                ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
1.112     raeburn   602: 	    if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
1.10      www       603: # this is for a course, not a user, so set coursedoc flag
                    604: # probably the only place in the system where this should be "1"
1.126     albertel  605: 	      my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
1.10      www       606:               my $ext='false';
                    607:               if ($url=~/^http\:\/\//) { $ext='true'; }
                    608:               $url=~s/\:/\&colon;/g;
                    609: 	      my $comment=$ENV{'form.comment'};
                    610:               $comment=~s/\</\&lt\;/g;
                    611:               $comment=~s/\>/\&gt\;/g;
                    612:               $comment=~s/\:/\&colon;/g;
1.17      www       613:               if ($folder=~/^supplemental/) {
                    614: 		  $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
                    615: 		      $ENV{'user.domain'}.'___&&&___'.$comment;
                    616:               }
1.10      www       617:               my $newidx=$#Apache::lonratedt::resources+1;
                    618:               $Apache::lonratedt::resources[$newidx]=
                    619:                   $comment.':'.$url.':'.$ext.':normal:res';
                    620:               $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
                    621:                                                               $newidx;       
1.104     albertel  622: 
1.142   ! raeburn   623: 	      ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1.104     albertel  624: 	      if ($fatal) {
                    625: 		  $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    626: 		  return;
                    627: 	      }
1.10      www       628: 	     }
                    629:             }
1.8       www       630: 	    if ($ENV{'form.cmd'}) {
1.10      www       631:                 my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
                    632:                 if ($cmd eq 'del') {
1.128     albertel  633: 		    my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
                    634: 		    if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) {
                    635: 			&Apache::lonnet::removeuploadedurl($url);
                    636: 		    }
1.10      www       637: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
                    638:                         $Apache::lonratedt::order[$i]=
                    639:                           $Apache::lonratedt::order[$i+1];
                    640:                     }
                    641:                     $#Apache::lonratedt::order--;
                    642:                 } elsif ($cmd eq 'up') {
1.38      www       643: 		  if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
1.10      www       644:                     my $i=$Apache::lonratedt::order[$idx-1];
                    645:                     $Apache::lonratedt::order[$idx-1]=
                    646: 			$Apache::lonratedt::order[$idx];
                    647:                     $Apache::lonratedt::order[$idx]=$i;
1.38      www       648: 		   }
1.10      www       649:                 } elsif ($cmd eq 'down') {
1.38      www       650: 		   if (defined($Apache::lonratedt::order[$idx+1])) {
1.10      www       651:                     my $i=$Apache::lonratedt::order[$idx+1];
                    652:                     $Apache::lonratedt::order[$idx+1]=
                    653: 			$Apache::lonratedt::order[$idx];
                    654:                     $Apache::lonratedt::order[$idx]=$i;
1.38      www       655: 		   }
1.36      www       656:                 } elsif ($cmd eq 'rename') {
1.142   ! raeburn   657:                     my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]];
1.36      www       658:                     my ($rtitle,@rrest)=split(/\:/,
                    659:                        $Apache::lonratedt::resources[
                    660: 				       $Apache::lonratedt::order[$idx]]);
1.38      www       661:                     my $comment=
                    662:                      &HTML::Entities::decode($ENV{'form.title'});
1.36      www       663:                     $comment=~s/\</\&lt\;/g;
                    664:                     $comment=~s/\>/\&gt\;/g;
                    665:                     $comment=~s/\:/\&colon;/g;
                    666:                     $Apache::lonratedt::resources[
                    667: 				       $Apache::lonratedt::order[$idx]]=
                    668:                              $comment.':'.join(':',@rrest);
                    669:                     
1.10      www       670:                 }
                    671: # Store the changed version
1.104     albertel  672: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142   ! raeburn   673: 					    $folder.'.'.$container);
1.104     albertel  674: 		if ($fatal) {
                    675: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    676: 		    return;
                    677: 		}
1.8       www       678:             }
1.11      www       679: # Group import/search
                    680: 	    if ($ENV{'form.importdetail'}) {
1.73      bowersj2  681: 		my @imports;
                    682: 		foreach (split(/\&/,$ENV{'form.importdetail'})) {
                    683: 		    if (defined($_)) {
                    684: 			my ($name,$url)=split(/\=/,$_);
                    685: 			$name=&Apache::lonnet::unescape($name);
                    686: 			$url=&Apache::lonnet::unescape($url);
                    687: 			push @imports, $name, $url;
                    688: 		    }
                    689: 		}
1.11      www       690: # Store the changed version
1.104     albertel  691: 		($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
1.142   ! raeburn   692: 					       $container,'londocs',@imports);
1.104     albertel  693: 		if ($fatal) {
                    694: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    695: 		    return;
                    696: 		}
1.11      www       697:             }
1.53      www       698: # Loading a complete map
                    699: 	   if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
1.104     albertel  700: 	       foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
1.53      www       701:                    my $idx=$#Apache::lonratedt::resources;
                    702:                    $idx++;
                    703:                    $Apache::lonratedt::resources[$idx]=$_;
                    704:                    $Apache::lonratedt::order
1.104     albertel  705: 		       [$#Apache::lonratedt::order+1]=$idx;
                    706: 	       }
1.53      www       707: 
                    708: # Store the changed version
1.104     albertel  709: 	       ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142   ! raeburn   710: 					   $folder.'.'.$container);
1.104     albertel  711: 	       if ($fatal) {
                    712: 		   $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    713: 		   return;
                    714: 	       }
1.53      www       715:            }
1.16      www       716:        }
                    717: # ---------------------------------------------------------------- End commands
1.7       www       718: # ---------------------------------------------------------------- Print screen
1.10      www       719:         my $idx=0;
                    720:         $r->print('<table>');
                    721:         foreach (@Apache::lonratedt::order) {
                    722:            my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
                    723:            unless ($name) {  $name=(split(/\//,$url))[-1]; }
1.106     www       724:            unless ($name) { next; }
1.112     raeburn   725:            $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
1.10      www       726:            $idx++;
                    727:         }
1.131     www       728: 	unless ($idx) {
                    729: 	    $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
                    730: 	}
1.10      www       731:         $r->print('</table>');
1.7       www       732:     }
                    733: }
1.1       www       734: 
1.8       www       735: # --------------------------------------------------------------- An entry line
                    736: 
                    737: sub entryline {
1.112     raeburn   738:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1.38      www       739:     $title=~s/\&colon\;/\:/g;
                    740:     $title=&HTML::Entities::encode(&HTML::Entities::decode(
1.109     albertel  741:      &Apache::lonnet::unescape($title)),'"<>&\'');
1.38      www       742:     my $renametitle=$title;
                    743:     my $foldertitle=$title;
1.142   ! raeburn   744:     my $pagetitle=$title;
1.122     www       745:     my $orderidx=$Apache::lonratedt::order[$index];
1.109     albertel  746:     if ($title=~ /^(\d+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(.*)$/	) { 
                    747: 	$foldertitle=&Apache::lontexconvert::msgtexconverted($4);
                    748: 	$renametitle=$4;
                    749: 	$title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
                    750: 	    &Apache::loncommon::plainname($2,$3).': <br />'.
                    751: 	    $foldertitle;
                    752:     }
1.38      www       753:     $renametitle=~s/\&quot\;/\\\"/g;
1.8       www       754:     my $line='<tr>';
                    755: # Edit commands
1.142   ! raeburn   756:     my $container;
1.120     www       757:     my $folderpath;
                    758:     if ($ENV{'form.folderpath'}) {
1.142   ! raeburn   759:         $container = 'sequence';
1.120     www       760: 	$folderpath=&Apache::lonnet::escape($ENV{'form.folderpath'});
                    761: 	# $htmlfoldername=&HTML::Entities::encode($ENV{'form.foldername'},'<>&"');
                    762:     }
1.142   ! raeburn   763:     my $pagepath;
        !           764:     if ($ENV{'form.pagepath'}) {
        !           765:         $container = 'page';
        !           766:         $pagepath=&Apache::lonnet::escape($ENV{'form.pagepath'});
        !           767:     }
1.109     albertel  768:     if ($allowed) {
1.123     www       769: 	my $incindex=$index+1;
                    770: 	my $selectbox='';
                    771: 	if ($folder!~/^supplemental/) {
                    772: 	    $selectbox=
1.124     www       773: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.123     www       774: 		'<select name="newpos" onChange="this.form.submit()">';
                    775: 	    for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
                    776: 		if ($i==$incindex) {
                    777: 		    $selectbox.='<option value="" selected="1">('.$i.')</option>';
                    778: 		} else {
                    779: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
                    780: 		}
                    781: 	    }
                    782: 	    $selectbox.='</select>';
                    783: 	}
1.119     www       784: 	my %lt=&Apache::lonlocal::texthash(
                    785:                 'up' => 'Move Up',
1.109     albertel  786: 		'dw' => 'Move Down',
                    787: 		'rm' => 'Remove',
                    788: 		'rn' => 'Rename');
1.142   ! raeburn   789:         if ($ENV{'form.pagepath'}) {
        !           790:             $line.=(<<END);
        !           791: <form name="entry_$index" action="/adm/coursedocs" method="post">
        !           792: <input type="hidden" name="pagepath" value="$ENV{'form.pagepath'}" />
        !           793: <input type="hidden" name="setparms" value="$orderidx" />
        !           794: <td><table border='0' cellspacing='2' cellpadding='0'>
        !           795: <tr><td bgcolor="#DDDDDD">
        !           796: <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath'>
        !           797: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
        !           798: <tr><td bgcolor="#DDDDDD">
        !           799: <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath'>
        !           800: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
        !           801: </table></td>
        !           802: <td>$selectbox
        !           803: </td><td bgcolor="#DDDDDD">
        !           804: <a href='javascript:removeres("$pagepath","$index","$renametitle","page");'>
        !           805: <font size="-2" color="#990000">$lt{'rm'}</font></a>
        !           806: <a href='javascript:changename("$pagepath","$index","$renametitle","page");'>
        !           807: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
        !           808: END
        !           809:         } else {
        !           810:             $line.=(<<END); 
1.121     www       811: <form name="entry_$index" action="/adm/coursedocs" method="post">
                    812: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.122     www       813: <input type="hidden" name="setparms" value="$orderidx" />
1.54      www       814: <td><table border='0' cellspacing='2' cellpadding='0'>
                    815: <tr><td bgcolor="#DDDDDD">
1.115     albertel  816: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath'>
1.90      www       817: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1.54      www       818: <tr><td bgcolor="#DDDDDD">
1.115     albertel  819: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath'>
1.90      www       820: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1.123     www       821: </table></td>
                    822: <td>$selectbox
                    823: </td><td bgcolor="#DDDDDD">
1.142   ! raeburn   824: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
1.90      www       825: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.142   ! raeburn   826: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
1.90      www       827: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
1.8       www       828: END
1.142   ! raeburn   829:         }
1.8       www       830:     }
1.16      www       831: # Figure out what kind of a resource this is
                    832:     my ($extension)=($url=~/\.(\w+)$/);
                    833:     my $uploaded=($url=~/^\/*uploaded\//);
1.97      albertel  834:     my $icon=&Apache::loncommon::icon($url);
1.17      www       835:     my $isfolder=0;
1.142   ! raeburn   836:     my $ispage=0;
1.114     albertel  837:     my $folderarg;
1.142   ! raeburn   838:     my $pagearg;
        !           839:     my $pagefile;
1.16      www       840:     if ($uploaded) {
1.135     albertel  841: 	if ($extension eq 'sequence') {
                    842: 	    $icon=$iconpath.'/folder_closed.gif';
                    843: 	    $url=~/$coursenum\/([\/\w]+)\.sequence$/;
                    844: 	    $url='/adm/coursedocs?';
                    845: 	    $folderarg=$1;
                    846: 	    $isfolder=1;
1.142   ! raeburn   847:         } elsif ($extension eq 'page') {
        !           848:             $icon=$iconpath.'/page.gif';
        !           849:             $url=~/$coursenum\/([\/\w]+)\.page$/;
        !           850:             $pagearg=$1;
        !           851:             $url='/adm/coursedocs?';
        !           852:             $ispage=1;
1.135     albertel  853: 	} else {
                    854: 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
                    855: 	}
1.16      www       856:     }
1.18      www       857:     $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
1.142   ! raeburn   858:     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1.113     albertel  859: 	my $symb=&Apache::lonnet::symbclean(
1.50      www       860:           &Apache::lonnet::declutter('uploaded/'.
                    861:            $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
                    862:            $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
                    863:            '.sequence').
                    864:            '___'.$residx.'___'.
1.113     albertel  865: 	   &Apache::lonnet::declutter($url));
                    866: 	(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
                    867: 	$url=&Apache::lonnet::clutter($url);
1.127     albertel  868: 	if ($url=~/^\/*uploaded\//) {
                    869: 	    $url=~/\.(\w+)$/;
                    870: 	    my $embstyle=&Apache::loncommon::fileembstyle($1);
                    871: 	    if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                    872: 		$url='/adm/wrapper'.$url;
                    873: 	    } elsif ($embstyle eq 'ssi') {
                    874: 		#do nothing with these
                    875: 	    } elsif ($url!~/\.(sequence|page)$/) {
                    876: 		$url='/adm/coursedocs/showdoc'.$url;
                    877: 	    }
                    878: 	}
1.142   ! raeburn   879:         unless ($container eq 'page') {
        !           880: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
        !           881:         }
1.50      www       882:     }
1.120     www       883:     my $parameterset='&nbsp;';
1.114     albertel  884:     if ($isfolder) {
                    885: 	my $foldername=&Apache::lonnet::escape($foldertitle);
                    886: 	my $folderpath=$ENV{'form.folderpath'};
                    887: 	if ($folderpath) { $folderpath.='&' };
                    888: 	$folderpath.=$folderarg.'&'.$foldername;
                    889: 	$url.='folderpath='.&Apache::lonnet::escape($folderpath);
1.120     www       890: 	$parameterset=&mt('Randomly Pick: ').
1.122     www       891: 	    '<input type="text" size="4" name="randpick_'.$orderidx.'" value="'.
                    892: 	    (&Apache::lonratedt::getparameter($orderidx,'parameter_randompick'))[0].'" />';
1.114     albertel  893:     }
1.142   ! raeburn   894:     if ($ispage) {
        !           895:         my $pagename=&Apache::lonnet::escape($pagetitle);
        !           896:         my $pagepath;
        !           897:         my $folderpath=$ENV{'form.folderpath'};
        !           898:         if ($folderpath) { $pagepath = $folderpath.'&' };
        !           899:         $pagepath.=$pagearg.'&'.$pagename;
        !           900:         $url.='pagepath='.&Apache::lonnet::escape($pagepath);
        !           901:     }
1.113     albertel  902:     $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
                    903: 	'" border="0"></a></td>'.
1.119     www       904:         "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
1.120     www       905:     if (($allowed) && ($folder!~/^supplemental/)) {
                    906:  	my %lt=&Apache::lonlocal::texthash(
                    907:  			      'hd' => 'Hidden',
                    908:  			      'ec' => 'URL hidden',
                    909:  			      'sp' => 'Store Parameters');
1.122     www       910: 	my $enctext=
                    911: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
                    912: 	my $hidtext=
                    913: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1.120     www       914: 	$line.=(<<ENDPARMS);
                    915: <td bgcolor="#BBBBFF"><font size='-2'>
1.122     www       916: <input type="checkbox" name="hidprs_$orderidx" $hidtext/> $lt{'hd'}</td>
1.139     albertel  917: <!--<td bgcolor="#BBBBFF"><font size='-2'>
                    918: <input type="checkbox" name="encprs_$orderidx" $enctext/> $lt{'ec'}</td>-->
1.120     www       919: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
                    920: <td bgcolor="#BBBBFF"><font size='-2'>
1.121     www       921: <input type="submit" value="$lt{'sp'}" />
1.120     www       922: </font></td>
                    923: ENDPARMS
1.119     www       924:     }
1.120     www       925:     $line.="</form></tr>";
1.8       www       926:     return $line;
                    927: }
                    928: 
1.27      www       929: # ---------------------------------------------------------------- tie the hash
                    930: 
                    931: sub tiehash {
1.136     albertel  932:     my ($mode)=@_;
1.27      www       933:     $hashtied=0;
                    934:     if ($ENV{'request.course.fn'}) {
1.136     albertel  935: 	if ($mode eq 'write') {
                    936: 	    if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
                    937: 		    &GDBM_WRCREAT(),0640)) {
                    938:                 $hashtied=2;
                    939: 	    }
                    940: 	} else {
                    941: 	    if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
                    942: 		    &GDBM_READER(),0640)) {
1.27      www       943:                 $hashtied=1;
1.136     albertel  944: 	    }
                    945: 	}
1.27      www       946:     }    
                    947: }
                    948: 
                    949: sub untiehash {
                    950:     if ($hashtied) { untie %hash; }
                    951:     $hashtied=0;
                    952: }
                    953: 
1.29      www       954: # --------------------------------------------------------------- check on this
                    955: 
                    956: sub checkonthis {
                    957:     my ($r,$url,$level,$title)=@_;
1.140     www       958:     $url=&Apache::lonnet::unescape($url);
1.29      www       959:     $alreadyseen{$url}=1;
                    960:     $r->rflush();
1.41      www       961:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1.108     albertel  962:        $r->print("\n<br />");
1.29      www       963:        for (my $i=0;$i<=$level*5;$i++) {
                    964:            $r->print('&nbsp;');
                    965:        }
                    966:        $r->print('<a href="'.$url.'" target="cat">'.
                    967: 		 ($title?$title:$url).'</a> ');
                    968:        if ($url=~/^\/res\//) {
                    969: 	  my $result=&Apache::lonnet::repcopy(
                    970:                               &Apache::lonnet::filelocation('',$url));
                    971:           if ($result==OK) {
1.87      www       972:              $r->print('<font color="green">'.&mt('ok').'</font>');
1.29      www       973:              $r->rflush();
1.34      www       974:              &Apache::lonnet::countacc($url);
                    975:              $url=~/\.(\w+)$/;
                    976:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                    977: 		 $r->print('<br />');
                    978:                  $r->rflush();
                    979:                  for (my $i=0;$i<=$level*5;$i++) {
                    980:                      $r->print('&nbsp;');
                    981:                  }
1.84      www       982:                  $r->print('- '.&mt('Rendering').': ');
1.69      albertel  983:                  my $oldpath=$ENV{'request.filename'};
                    984:                  $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
1.34      www       985:                  &Apache::lonxml::xmlparse($r,'web',
                    986:                    &Apache::lonnet::getfile(
1.35      albertel  987:                     &Apache::lonnet::filelocation('',$url)));
1.94      www       988: 		 undef($Apache::lonhomework::parsing_a_problem);
1.69      albertel  989: 		 $ENV{'request.filename'}=$oldpath;
1.34      www       990:                  if (($Apache::lonxml::errorcount) ||
                    991:                      ($Apache::lonxml::warningcount)) {
                    992: 		     if ($Apache::lonxml::errorcount) {
1.98      www       993:                         $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
1.87      www       994: 			  $Apache::lonxml::errorcount.' '.
                    995: 				  &mt('error(s)').'</b></font> ');
1.34      www       996:                      }
                    997: 		     if ($Apache::lonxml::warningcount) {
                    998:                         $r->print('<font color="blue">'.
1.84      www       999: 			  $Apache::lonxml::warningcount.' '.
                   1000: 				  &mt('warning(s)').'</font>');
1.34      www      1001:                      }
                   1002:                  } else {
1.87      www      1003:                      $r->print('<font color="green">'.&mt('ok').'</font>');
1.34      www      1004:                  }
                   1005:                  $r->rflush();
                   1006:              }
1.29      www      1007: 	     my $dependencies=
                   1008:                 &Apache::lonnet::metadata($url,'dependencies');
                   1009:              foreach (split(/\,/,$dependencies)) {
                   1010: 		 if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
                   1011:                     &checkonthis($r,$_,$level+1);
                   1012:                  }
                   1013:              }
                   1014:           } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
1.84      www      1015:              $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
1.29      www      1016:           } elsif ($result==HTTP_NOT_FOUND) {
1.100     www      1017: 	      unless ($url=~/\$/) {
                   1018: 		  $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
                   1019: 	      } else {
                   1020: 		  $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
                   1021: 	      }
1.29      www      1022:           } else {
1.84      www      1023:              $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
1.29      www      1024:           }
                   1025:       }
                   1026:    }
                   1027: }
                   1028: 
1.1       www      1029: 
1.75      www      1030: #
                   1031: # -------------------------------------------------------------- Verify Content
                   1032: # 
                   1033: sub verifycontent {
                   1034:    my $r=shift; 
1.26      www      1035:    my $loaderror=&Apache::lonnet::overloaderror($r);
                   1036:    if ($loaderror) { return $loaderror; }
                   1037: 
                   1038:    $r->print('<html><head><title>Verify Content</title></head>'.
                   1039:               &Apache::loncommon::bodytag('Verify Course Documents'));
1.27      www      1040:    $hashtied=0;
1.30      www      1041:    undef %alreadyseen;
                   1042:    %alreadyseen=();
1.27      www      1043:    &tiehash();
                   1044:    foreach (keys %hash) {
1.140     www      1045:        if ($hash{$_}=~/\.(page|sequence)$/) {
                   1046: 	   if (($_=~/^src_/) && ($alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
                   1047: 	       $r->print('<hr /><font color="red">'.
                   1048: 			 &mt('The following sequence or page is included more than once in your course: ').
                   1049: 			 &Apache::lonnet::unescape($hash{$_}).'</font><br />'.
                   1050: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
                   1051: 	   }
                   1052:        }
                   1053:        if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
1.29      www      1054:            &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27      www      1055:        }
                   1056:    }
                   1057:    &untiehash();
1.108     albertel 1058:    $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
                   1059: 	     &mt('Return to DOCS').'</a>');
1.75      www      1060: }
                   1061: 
                   1062: # -------------------------------------------------------------- Check Versions
                   1063: 
                   1064: sub checkversions {
                   1065:     my $r=shift;
1.89      www      1066:     $r->print('<html><head><title>Check Versions</title></head>'.
1.26      www      1067:               &Apache::loncommon::bodytag('Check Course Document Versions'));
1.89      www      1068:     my $header='';
                   1069:     my $startsel='';
                   1070:     my $monthsel='';
                   1071:     my $weeksel='';
                   1072:     my $daysel='';
                   1073:     my $allsel='';
                   1074:     my %changes=();
                   1075:     my $starttime=0;
1.91      www      1076:     my $haschanged=0;
1.92      www      1077:     my %setversions=&Apache::lonnet::dump('resourceversions',
                   1078: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1079: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   1080: 
                   1081:     $hashtied=0;
                   1082:     &tiehash();
                   1083:     my %newsetversions=();
1.91      www      1084:     if ($ENV{'form.setmostrecent'}) {
                   1085: 	$haschanged=1;
1.92      www      1086: 	foreach (keys %hash) {
                   1087: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
1.93      www      1088: 		$newsetversions{$1}='mostrecent';
1.92      www      1089: 	    }
                   1090: 	}
1.91      www      1091:     } elsif ($ENV{'form.setcurrent'}) {
                   1092: 	$haschanged=1;
1.92      www      1093: 	foreach (keys %hash) {
                   1094: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
1.93      www      1095: 		my $getvers=&Apache::lonnet::getversion($1);
                   1096: 		if ($getvers>0) {
                   1097: 		    $newsetversions{$1}=$getvers;
                   1098: 		}
1.92      www      1099: 	    }
                   1100: 	}
1.91      www      1101:     } elsif ($ENV{'form.setversions'}) {
                   1102: 	$haschanged=1;
1.92      www      1103: 	foreach (keys %ENV) {
                   1104: 	    if ($_=~/^form\.set_version_(.+)$/) {
                   1105: 		my $src=$1;
                   1106: 		if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
                   1107: 		    $newsetversions{$src}=$ENV{$_};
                   1108: 		}
                   1109: 	    }
                   1110: 	}
1.91      www      1111:     }
                   1112:     if ($haschanged) {
1.92      www      1113:         if (&Apache::lonnet::put('resourceversions',\%newsetversions,
                   1114: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1115: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {		
                   1116: 	    $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
                   1117: 	} else {
                   1118: 	    $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
                   1119: 	}
1.136     albertel 1120: 	&mark_hash_old();
1.91      www      1121:     }
1.136     albertel 1122:     &changewarning($r,'');
1.89      www      1123:     if ($ENV{'form.timerange'} eq 'all') {
                   1124: # show all documents
                   1125: 	$header=&mt('All Documents in Course');
1.91      www      1126: 	$allsel=1;
1.90      www      1127: 	foreach (keys %hash) {
                   1128: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
                   1129: 		my $src=$1;
                   1130: 		$changes{$src}=1;
                   1131: 	    }
                   1132: 	}
1.89      www      1133:     } else {
                   1134: # show documents which changed
                   1135: 	%changes=&Apache::lonnet::dump
                   1136: 	 ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.30      www      1137:                      $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.89      www      1138: 	my $firstkey=(keys %changes)[0];
                   1139: 	unless ($firstkey=~/^error\:/) {
                   1140: 	    unless ($ENV{'form.timerange'}) {
                   1141: 		$ENV{'form.timerange'}=604800;
                   1142: 	    }
                   1143: 	    my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
                   1144: 		.&mt('seconds');
                   1145: 	    if ($ENV{'form.timerange'}==-1) {
                   1146: 		$seltext='since start of course';
                   1147: 		$startsel='selected';
                   1148: 		$ENV{'form.timerange'}=time;
                   1149: 	    }
                   1150: 	    $starttime=time-$ENV{'form.timerange'};
                   1151: 	    if ($ENV{'form.timerange'}==2592000) {
                   1152: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1153: 		$monthsel='selected';
                   1154: 	    } elsif ($ENV{'form.timerange'}==604800) {
                   1155: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1156: 		$weeksel='selected';
                   1157: 	    } elsif ($ENV{'form.timerange'}==86400) {
                   1158: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1159: 		$daysel='selected';
                   1160: 	    }
                   1161: 	    $header=&mt('Content changed').' '.$seltext;
                   1162: 	} else {
                   1163: 	    $header=&mt('No content modifications yet.');
                   1164: 	}
                   1165:     }
1.92      www      1166:     %setversions=&Apache::lonnet::dump('resourceversions',
                   1167: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   1168: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.89      www      1169:     my %lt=&Apache::lonlocal::texthash
1.88      www      1170: 	      ('st' => 'Version changes since start of Course',
                   1171: 	       'lm' => 'Version changes since last Month',
                   1172: 	       'lw' => 'Version changes since last Week',
                   1173: 	       'sy' => 'Version changes since Yesterday',
1.91      www      1174:                'al' => 'All Resources (possibly large output)',
1.88      www      1175: 	       'sd' => 'Display',
1.84      www      1176: 	       'fi' => 'File',
                   1177: 	       'md' => 'Modification Date',
1.87      www      1178:                'mr' => 'Most recently published Version',
                   1179: 	       've' => 'Version used in Course',
1.91      www      1180:                'vu' => 'Set Version to be used in Course',
                   1181: 'sv' => 'Set Versions to be used in Course according to Selections below',
                   1182: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                   1183: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.84      www      1184: 	       'di' => 'Differences');
1.89      www      1185:     $r->print(<<ENDHEADERS);
1.31      www      1186: <form action="/adm/coursedocs" method="post">
1.91      www      1187: <input type="hidden" name="versions" value="1" />
                   1188: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
                   1189: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1.31      www      1190: <select name="timerange">
1.88      www      1191: <option value='all' $allsel>$lt{'al'}</option>
1.84      www      1192: <option value="-1" $startsel>$lt{'st'}</option>
                   1193: <option value="2592000" $monthsel>$lt{'lm'}</option>
                   1194: <option value="604800" $weeksel>$lt{'lw'}</option>
                   1195: <option value="86400" $daysel>$lt{'sy'}</option>
1.31      www      1196: </select>
1.91      www      1197: <input type="submit" name="display" value="$lt{'sd'}" />
1.89      www      1198: <h3>$header</h3>
1.91      www      1199: <input type="submit" name="setversions" value="$lt{'sv'}" />
1.103     matthew  1200: <table border="0">
1.31      www      1201: ENDHEADERS
1.91      www      1202:     foreach (sort keys %changes) {
1.89      www      1203: 	if ($changes{$_}>$starttime) {
                   1204: 	    my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
                   1205: 	    my $currentversion=&Apache::lonnet::getversion($_);
1.93      www      1206: 	    if ($currentversion<0) {
                   1207: 		$currentversion=&mt('Could not be determined.');
                   1208: 	    }
1.89      www      1209: 	    my $linkurl=&Apache::lonnet::clutter($_);
                   1210: 	    $r->print(
1.103     matthew  1211: 		      '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1.91      www      1212: 		      &Apache::lonnet::gettitle($linkurl).
1.103     matthew  1213:                       '</b></font></td></tr>'.
                   1214:                       '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
                   1215:                       '<td colspan="4">'.
                   1216:                       '<a href="'.$linkurl.'" target="cat">'.$linkurl.
                   1217: 		      '</a></td></tr>'.
                   1218:                       '<tr><td></td>'.
                   1219:                       '<td title="'.$lt{'md'}.'">'.
1.102     matthew  1220: 		      &Apache::lonlocal::locallocaltime(
                   1221:                            &Apache::lonnet::metadata($root.'.'.$extension,
                   1222:                                                      'lastrevisiondate')
                   1223:                                                         ).
1.103     matthew  1224:                       '</td>'.
                   1225:                       '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
                   1226:                       '<font size="+1">'.$currentversion.'</font>'.
                   1227:                       '</nobr></td>'.
                   1228:                       '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
                   1229:                       '<font size="+1">');
1.87      www      1230: # Used in course
1.89      www      1231: 	    my $usedversion=$hash{'version_'.$linkurl};
1.93      www      1232: 	    if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.89      www      1233: 		$r->print($usedversion);
                   1234: 	    } else {
                   1235: 		$r->print($currentversion);
                   1236: 	    }
1.103     matthew  1237: 	    $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
                   1238:                       '<nobr>Use: ');
1.87      www      1239: # Set version
1.92      www      1240: 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1.89      www      1241: 						      'set_version_'.$linkurl,
1.136     albertel 1242: 						      ('select_form_order' =>
                   1243: 						       ['',1..$currentversion,'mostrecent'],
                   1244: 						       '' => '',
1.93      www      1245: 						       'mostrecent' => 'most recent',
1.89      www      1246: 						       map {$_,$_} (1..$currentversion))));
1.103     matthew  1247: 	    $r->print('</nobr></td></tr><tr><td></td>');
1.89      www      1248: 	    my $lastold=1;
                   1249: 	    for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                   1250: 		my $url=$root.'.'.$prevvers.'.'.$extension;
                   1251: 		if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
                   1252: 		    $starttime) {
                   1253: 		    $lastold=$prevvers;
                   1254: 		}
                   1255: 	    }
1.103     matthew  1256:             # 
                   1257:             # Code to figure out how many version entries should go in
                   1258:             # each of the four columns
                   1259:             my $entries_per_col = 0;
                   1260:             my $num_entries = ($currentversion-$lastold);
                   1261:             if ($num_entries % 4 == 0) {
                   1262:                 $entries_per_col = $num_entries/4;
                   1263:             } else {
                   1264:                 $entries_per_col = $num_entries/4 + 1;
                   1265:             }
                   1266:             my $entries_count = 0;
                   1267:             $r->print('<td valign="top"><font size="-2">'); 
                   1268:             my $cols_output = 1;
1.32      www      1269:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1.89      www      1270: 		my $url=$root.'.'.$prevvers.'.'.$extension;
1.103     matthew  1271: 		$r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
1.91      www      1272: 			  '">'.&mt('Version').' '.$prevvers.'</a> ('.
1.103     matthew  1273: 			  &Apache::lonlocal::locallocaltime(
                   1274:                                 &Apache::lonnet::metadata($url,
                   1275:                                                           'lastrevisiondate')
                   1276:                                                             ).
1.91      www      1277: 			  ')');
1.89      www      1278: 		if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1.33      www      1279:                     $r->print(' <a href="/adm/diff?filename='.
1.89      www      1280: 			      &Apache::lonnet::clutter($root.'.'.$extension).
                   1281: 			      '&versionone='.$prevvers.
                   1282: 			      '">'.&mt('Diffs').'</a>');
                   1283: 		}
1.103     matthew  1284: 		$r->print('</nobr><br />');
                   1285:                 if (++$entries_count % $entries_per_col == 0) {
                   1286:                     $r->print('</font></td>');
                   1287:                     if ($cols_output != 4) {
                   1288:                         $r->print('<td valign="top"><font size="-2">');
                   1289:                         $cols_output++;
                   1290:                     }
                   1291:                 }
1.89      www      1292: 	    }
1.103     matthew  1293:             while($cols_output++ < 4) {
                   1294:                 $r->print('</font></td><td><font>')
                   1295:             }
                   1296: 	    $r->print('</font></td></tr>'."\n");
1.89      www      1297: 	}
                   1298:     }
1.92      www      1299:     $r->print('</table></form>');
1.89      www      1300:     $r->print('<h1>'.&mt('Done').'.</h1>');
                   1301: 
                   1302:     &untiehash();
1.75      www      1303: }
                   1304: 
1.136     albertel 1305: sub mark_hash_old {
                   1306:     my $retie_hash=0;
                   1307:     if ($hashtied) {
                   1308: 	$retie_hash=1;
                   1309: 	&untiehash();
                   1310:     }
                   1311:     &tiehash('write');
                   1312:     $hash{'old'}=1;
                   1313:     &untiehash();
                   1314:     if ($retie_hash) { &tiehash(); }
                   1315: }
                   1316: 
                   1317: sub is_hash_old {
                   1318:     my $untie_hash=0;
                   1319:     if (!$hashtied) {
                   1320: 	$untie_hash=1;
                   1321: 	&tiehash();
                   1322:     }
                   1323:     my $return=$hash{'old'};
                   1324:     if ($untie_hash) { &untiehash(); }
                   1325:     return $return;
                   1326: }
                   1327: 
1.91      www      1328: sub changewarning {
                   1329:     my ($r,$postexec)=@_;
1.136     albertel 1330:     if (!&is_hash_old()) { return; }
1.91      www      1331:     $r->print(
                   1332: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'. 
                   1333: '<form method="post" action="/adm/roles" target="loncapaclient">'.
1.117     albertel 1334: '<input type="hidden" name="orgurl" value="/adm/coursedocs?folderpath='.
                   1335: &Apache::lonnet::escape($ENV{'form.folderpath'}).
                   1336: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1.91      www      1337: &mt('Changes will become active for your current session after').
                   1338: ' <input type="hidden" name="'.
                   1339: $ENV{'request.role'}.'" value="1" /><input type="button" value="'.
                   1340: &mt('re-initializing course').'" onClick="reinit(this.form)"/>'.&mt(', or the next time you log in.').
                   1341: $help{'Caching'}.'</font></h3></form>');
                   1342: }
                   1343: 
1.75      www      1344: # ================================================================ Main Handler
                   1345: sub handler {
                   1346:     my $r = shift;
1.82      www      1347:     &Apache::loncommon::content_type($r,'text/html');
1.75      www      1348:     $r->send_http_header;
                   1349:     return OK if $r->header_only;
                   1350: 
                   1351: # --------------------------------------------- Initialize help topics for this
                   1352:   foreach ('Adding_Course_Doc','Main_Course_Documents',
                   1353:            'Adding_External_Resource','Navigate_Content',
                   1354:            'Adding_Folders','Docs_Overview', 'Load_Map',
1.142   ! raeburn  1355:            'Supplemental','Score_Upload_Form','Adding_Pages',
1.130     www      1356:            'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
                   1357: 	   'Check_Resource_Versions','Verify_Content') {
1.75      www      1358:       $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
                   1359:   }
                   1360:     # Composite help files
                   1361:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   1362: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   1363:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   1364: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1.86      albertel 1365:     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
                   1366: 		    'Option_Response_Simple');
1.75      www      1367:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   1368: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
                   1369:     $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
                   1370: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
                   1371:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.142   ! raeburn  1372: 
1.75      www      1373:   if ($ENV{'form.verify'}) {
                   1374:       &verifycontent($r);
                   1375:   } elsif ($ENV{'form.versions'}) {
                   1376:       &checkversions($r);
                   1377:   } elsif ($ENV{'form.dumpcourse'}) {
                   1378:       &dumpcourse($r);
1.138     raeburn  1379:   } elsif ($ENV{'form.exportcourse'}) {
                   1380:       &exportcourse($r);
1.26      www      1381:   } else {
1.7       www      1382: # is this a standard course?
                   1383: 
                   1384:     my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1.15      www      1385:     my $forcestandard;
                   1386:     my $forcesupplement;
                   1387:     my $script='';
                   1388:     my $allowed;
                   1389:     my $events='';
1.19      www      1390:     my $showdoc=0;
1.142   ! raeburn  1391:     my $containertag;
        !          1392:     my $uploadtag;
1.15      www      1393:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.142   ! raeburn  1394: 					    ['folderpath','pagepath']);
1.114     albertel 1395:     if ($ENV{'form.folderpath'}) {
                   1396: 	my (@folderpath)=split('&',$ENV{'form.folderpath'});
                   1397: 	$ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
                   1398: 	$ENV{'form.folder'}=pop(@folderpath);
1.142   ! raeburn  1399:     }
        !          1400:     if ($ENV{'form.pagepath'}) {
        !          1401:         my (@pagepath)=split('&',$ENV{'form.pagepath'});
        !          1402:         $ENV{'form.pagename'}=&Apache::lonnet::unescape(pop(@pagepath));
        !          1403:         $ENV{'form.folder'}=pop(@pagepath);
        !          1404:         $containertag = '<input type="hidden" name="pagepath" value="" />';
        !          1405:         $uploadtag = '<input type="hidden" name="pagepath" value="'.$ENV{'form.pagepath'}.'" />';
        !          1406:     }
1.21      www      1407:     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1.127     albertel 1408:        $showdoc='/'.$1;
1.21      www      1409:     }
                   1410:     unless ($showdoc) { # got called from remote
1.15      www      1411:        $forcestandard=($ENV{'form.folder'}=~/^default_/);
                   1412:        $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1.7       www      1413: 
1.4       www      1414: # does this user have privileges to post, etc?
1.77      www      1415:        $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1.15      www      1416:        if ($allowed) { 
                   1417:          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   1418:          $script=&Apache::lonratedt::editscript('simple'); 
                   1419:        }
                   1420:     } else { # got called in sequence from course
                   1421:        $allowed=0;
1.49      www      1422:        $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
                   1423:        $events='onLoad="'.&Apache::lonmenu::loadevents.
                   1424:            '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1.3       www      1425:     }
1.4       www      1426: 
                   1427: # get course data
                   1428:     my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                   1429:     my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                   1430: 
1.14      www      1431: # get personal data
                   1432:  
                   1433:     my $uname=$ENV{'user.name'};
                   1434:     my $udom=$ENV{'user.domain'};
                   1435:     my $plainname=&Apache::lonnet::escape(
                   1436:                      &Apache::loncommon::plainname($uname,$udom));
                   1437: 
1.8       www      1438: # graphics settings
1.4       www      1439: 
1.8       www      1440:     $iconpath = $r->dir_config('lonIconsURL') . "/";
                   1441: 
1.22      www      1442:     my $now=time;
1.64      www      1443: 
1.4       www      1444: # print screen
1.1       www      1445:     $r->print(<<ENDDOCUMENT);
                   1446: <html>
                   1447: <head>
                   1448: <title>The LearningOnline Network with CAPA</title>
1.16      www      1449: <script>
                   1450: $script
1.20      www      1451: </script>
1.19      www      1452: ENDDOCUMENT
                   1453:    if ($allowed) {
                   1454:     $r->print(<<ENDNEWSCRIPT);
1.20      www      1455: <script>
1.16      www      1456: function makenewfolder(targetform,folderseq) {
                   1457:     var foldername=prompt('Name of New Folder','New Folder');
                   1458:     if (foldername) {
                   1459: 	targetform.importdetail.value=foldername+"="+folderseq;
                   1460:         targetform.submit();
                   1461:     }
                   1462: }
                   1463: 
1.142   ! raeburn  1464: function makenewpage(targetform,folderseq) {
        !          1465:     var pagename=prompt('Name of New Page','New Page');
        !          1466:     if (pagename) {
        !          1467:         targetform.importdetail.value=pagename+"="+folderseq;
        !          1468:         targetform.submit();
        !          1469:     }
        !          1470: }
        !          1471: 
1.18      www      1472: function makenewext(targetname) {
                   1473:     this.document.forms.extimport.useform.value=targetname;
                   1474:     window.open('/adm/rat/extpickframe.html');
                   1475: }
                   1476: 
1.62      www      1477: function makeexamupload() {
                   1478:    var title=prompt('Listed Title for the Uploaded Score');
                   1479:    if (title) { 
                   1480:     this.document.forms.newexamupload.importdetail.value=
                   1481: 	title+'=/res/lib/templates/examupload.problem';
                   1482:     this.document.forms.newexamupload.submit();
                   1483:    }
                   1484: }
                   1485: 
1.22      www      1486: function makesmppage() {
1.38      www      1487:    var title=prompt('Listed Title for the Page');
                   1488:    if (title) { 
1.22      www      1489:     this.document.forms.newsmppg.importdetail.value=
                   1490: 	title+'=/adm/$udom/$uname/$now/smppg';
                   1491:     this.document.forms.newsmppg.submit();
1.38      www      1492:    }
1.22      www      1493: }
                   1494: 
1.55      www      1495: function makesmpproblem() {
                   1496:    var title=prompt('Listed Title for the Problem');
                   1497:    if (title) { 
                   1498:     this.document.forms.newsmpproblem.importdetail.value=
1.63      www      1499: 	title+'=/res/lib/templates/simpleproblem.problem';
1.55      www      1500:     this.document.forms.newsmpproblem.submit();
                   1501:    }
                   1502: }
                   1503: 
1.22      www      1504: function makebulboard() {
1.38      www      1505:    var title=prompt('Listed Title for the Bulletin Board');
                   1506:    if (title) {
1.22      www      1507:     this.document.forms.newbul.importdetail.value=
                   1508: 	title+'=/adm/$udom/$uname/$now/bulletinboard';
                   1509:     this.document.forms.newbul.submit();
1.38      www      1510:    }
1.22      www      1511: }
                   1512: 
1.101     www      1513: function makeabout() {
                   1514:    var user=prompt("Enter user\@domain for User's 'About Me' Page");
                   1515:    if (user) {
                   1516:        var comp=new Array();
                   1517:        comp=user.split('\@');
                   1518:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   1519: 	   if ((comp[0]) && (comp[1])) {
                   1520: 	       this.document.forms.newaboutsomeone.importdetail.value=
                   1521: 		   'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
                   1522: 	       this.document.forms.newaboutsomeone.submit();
                   1523: 	   }
                   1524:        }
                   1525:    }
                   1526: }
                   1527: 
1.110     raeburn  1528: function makeims() {
                   1529:     var caller = document.forms.ims.folder.value
                   1530:     var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
                   1531:     newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
                   1532:     newWindow.location.href = newlocation
                   1533: }
                   1534: 
                   1535: 
1.18      www      1536: function finishpick() {
                   1537:     var title=this.document.forms.extimport.title.value;
                   1538:     var url=this.document.forms.extimport.url.value;
                   1539:     var form=this.document.forms.extimport.useform.value;
                   1540:     eval
                   1541:      ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
                   1542:     '";this.document.forms.'+form+'.submit();');
1.16      www      1543: }
1.36      www      1544: 
1.142   ! raeburn  1545: function changename(folderpath,index,oldtitle,container) {
1.36      www      1546:     var title=prompt('New Title',oldtitle);
                   1547:     if (title) {
                   1548: 	this.document.forms.renameform.title.value=title;
                   1549: 	this.document.forms.renameform.cmd.value='rename_'+index;
1.142   ! raeburn  1550:         if (container == 'sequence') {
        !          1551: 	    this.document.forms.renameform.folderpath.value=folderpath;
        !          1552:         }
        !          1553:         if (container == 'page') {
        !          1554:             this.document.forms.renameform.pagepath.value=folderpath;
        !          1555:         }
1.54      www      1556:         this.document.forms.renameform.submit();
                   1557:     }
                   1558: }
                   1559: 
1.142   ! raeburn  1560: function removeres(folderpath,index,oldtitle,container) {
1.106     www      1561:     if (confirm('Remove "'+oldtitle+'"?')) {
1.54      www      1562: 	this.document.forms.renameform.cmd.value='del_'+index;
1.142   ! raeburn  1563:         if (container == 'sequence') {
        !          1564:             this.document.forms.renameform.folderpath.value=folderpath;
        !          1565:         }
        !          1566:         if (container == 'page') {
        !          1567:             this.document.forms.renameform.pagepath.value=folderpath;
        !          1568:         }
1.36      www      1569:         this.document.forms.renameform.submit();
                   1570:     }
                   1571: }
1.121     www      1572: 
1.16      www      1573: </script>
1.42      www      1574: 
                   1575: ENDNEWSCRIPT
                   1576:   }
                   1577: # -------------------------------------------------------------------- Body tag
                   1578:   $r->print('</head>'.
1.72      www      1579:             &Apache::loncommon::bodytag('Course Documents','',$events,
1.99      www      1580: 					'','',$showdoc).
1.134     albertel 1581: 	    &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
1.42      www      1582:   unless ($showdoc) {
1.81      www      1583: # -----------------------------------------------------------------------------
                   1584:        my %lt=&Apache::lonlocal::texthash(
                   1585:                 'uplm' => 'Upload a new main course document',
                   1586:                 'upls' => 'Upload a new supplemental course document',
                   1587:                 'impp' => 'Import a published document',
                   1588:                 'spec' => 'Special documents',
                   1589:                 'upld' => 'Upload Document',
                   1590:                 'srch' => 'Search',
                   1591:                 'impo' => 'Import',
                   1592:                 'selm' => 'Select Map',
                   1593:                 'load' => 'Load Map',
                   1594:                 'newf' => 'New Folder',
1.142   ! raeburn  1595:                 'newp' => 'New Composite Page',
1.81      www      1596:                 'extr' => 'External Resource',
                   1597:                 'syll' => 'Syllabus',
                   1598:                 'navc' => 'Navigate Contents',
                   1599:                 'sipa' => 'Simple Page',
                   1600:                 'sipr' => 'Simple Problem',
                   1601:                 'scuf' => 'Score Upload Form',
                   1602:                 'bull' => 'Bulletin Board',
1.96      sakharuk 1603:                 'mypi' => 'My Personal Info',
1.101     www      1604: 		'abou' => 'About User',
1.110     raeburn  1605:                 'imsf' => 'Import IMS package',
1.96      sakharuk 1606:                 'file' =>  'File',
                   1607:                 'title' => 'Title',
                   1608:                 'comment' => 'Comment' 
1.81      www      1609: 					  );
                   1610: # -----------------------------------------------------------------------------
1.42      www      1611:     if ($allowed) {
1.74      www      1612:        my $dumpbut=&dumpbutton();
1.138     raeburn  1613:        my $exportbut=&exportbutton();
1.88      www      1614:        my %lt=&Apache::lonlocal::texthash(
                   1615: 					 'vc' => 'Verify Content',
                   1616: 					 'cv' => 'Check/Set Resource Versions',
                   1617: 					  );
1.118     albertel 1618: 
                   1619:        my $folderpath=$ENV{'form.folderpath'};
                   1620:        if (!$folderpath) {
                   1621: 	   if ($ENV{'form.folder'} eq '' ||
                   1622: 	       $ENV{'form.folder'} eq 'supplemental') {
                   1623: 	       $folderpath='default&'.
                   1624: 		   &Apache::lonnet::escape(&mt('Main Course Documents'));
                   1625: 	   }
                   1626:        }
1.142   ! raeburn  1627:        unless ($ENV{'form.pagepath'}) {
        !          1628:            $containertag = '<input type="hidden" name="folderpath" value="" />';
        !          1629:            $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
        !          1630:        }
        !          1631: 
1.42      www      1632:        $r->print(<<ENDCOURSEVERIFY);
1.36      www      1633: <form name="renameform" method="post" action="/adm/coursedocs">
                   1634: <input type="hidden" name="title" />
                   1635: <input type="hidden" name="cmd" />
1.142   ! raeburn  1636: $containertag
1.36      www      1637: </form>
1.39      www      1638: <form name="simpleedit" method="post" action="/adm/coursedocs">
                   1639: <input type=hidden name="importdetail" value="">
1.142   ! raeburn  1640: $uploadtag
1.39      www      1641: </form>
1.26      www      1642: <form action="/adm/coursedocs" method="post" name="courseverify">
1.74      www      1643: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
                   1644: <tr><td bgcolor="#DDDDCC">
1.130     www      1645: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
1.74      www      1646: </td><td bgcolor="#DDDDCC">
1.130     www      1647:     <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
1.74      www      1648: $dumpbut
1.138     raeburn  1649: $exportbut
1.74      www      1650: </td></tr></table>
1.25      www      1651: </form>
                   1652: ENDCOURSEVERIFY
1.74      www      1653:        $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1.96      sakharuk 1654: 		     &mt('Editing the Table of Contents for your Course')));
1.25      www      1655:     }
1.17      www      1656: # --------------------------------------------------------- Standard documents
1.43      www      1657:     $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1.7       www      1658:     if (($standard) && ($allowed) && (!$forcesupplement)) {
1.116     albertel 1659: 	$r->print('<tr><td bgcolor="#BBBBBB">');
                   1660: #  '<h2>'.&mt('Main Course Documents').
                   1661: #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1.7       www      1662:        my $folder=$ENV{'form.folder'};
1.117     albertel 1663:        if ($folder eq '' || $folder eq 'supplemental') {
1.112     raeburn  1664:            $folder='default';
1.116     albertel 1665: 	   $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
1.112     raeburn  1666:        }
1.51      www      1667:        my $postexec='';
                   1668:        if ($folder eq 'default') {
                   1669: 	   $r->print('<script>this.window.name="loncapaclient";</script>');
                   1670:        } else {
1.117     albertel 1671:            #$postexec='self.close();';
1.51      www      1672:        }
1.40      www      1673:        $hadchanges=0;
1.7       www      1674:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.40      www      1675:        if ($hadchanges) {
1.136     albertel 1676: 	   &mark_hash_old()
1.40      www      1677:        }
1.136     albertel 1678:        &changewarning($r,$postexec);
1.16      www      1679:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                   1680:                      '.sequence';
1.142   ! raeburn  1681:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
        !          1682:                      '.page';
        !          1683: 
1.8       www      1684:        $r->print(<<ENDFORM);
1.43      www      1685: <table cellspacing=4 cellpadding=4><tr>
1.81      www      1686: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
                   1687: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
                   1688: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.11      www      1689: </tr>
1.16      www      1690: <tr><td bgcolor="#DDDDDD">
1.96      sakharuk 1691: $lt{'file'}:<br />
1.10      www      1692: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59      www      1693: <input type="file" name="uploaddoc" size="40">
1.8       www      1694: <br />
1.96      sakharuk 1695: $lt{'title'}:<br />
1.11      www      1696: <input type="text" size="50" name="comment">
1.142   ! raeburn  1697: $uploadtag
1.10      www      1698: <input type="hidden" name="cmd" value="upload_default">
1.129     albertel 1699: <nobr>
1.81      www      1700: <input type="submit" value="$lt{'upld'}">
1.60      albertel 1701:  $help{'Uploading_From_Harddrive'}
1.58      albertel 1702: </nobr>
1.60      albertel 1703: </form>
1.11      www      1704: </td>
1.16      www      1705: <td bgcolor="#DDDDDD">
1.39      www      1706: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.142   ! raeburn  1707: $uploadtag
1.115     albertel 1708: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
1.58      albertel 1709: <nobr>
1.115     albertel 1710: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
1.58      albertel 1711: $help{'Importing_LON-CAPA_Resource'}
                   1712: </nobr>
1.59      www      1713: <p>
                   1714: <hr />
1.68      bowersj2 1715: <input type="text" size="20" name="importmap"><br />
                   1716: <nobr><input type=button 
1.52      www      1717: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.81      www      1718: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
1.68      bowersj2 1719: $help{'Load_Map'}</nobr>
1.59      www      1720: </p>
1.52      www      1721: </form>
1.142   ! raeburn  1722: </td>
        !          1723: <td bgcolor="#DDDDDD">
        !          1724: ENDFORM
        !          1725:        unless ($ENV{'form.pagepath'}) {
        !          1726:            $r->print(<<ENDFORM);
1.11      www      1727: <form action="/adm/coursedocs" method="post" name="newfolder">
1.115     albertel 1728: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.13      www      1729: <input type=hidden name="importdetail" value="">
1.58      albertel 1730: <nobr>
1.16      www      1731: <input name="newfolder" type="button"
                   1732: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81      www      1733: value="$lt{'newf'}" />$help{'Adding_Folders'}
1.58      albertel 1734: </nobr>
1.11      www      1735: </form>
1.142   ! raeburn  1736: <form action="/adm/coursedocs" method="post" name="newpage">
        !          1737: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
        !          1738: <input type=hidden name="importdetail" value="">
        !          1739: <nobr>
        !          1740: <input name="newpage" type="button"
        !          1741: onClick="javascript:makenewpage(this.form,'$pageseq');"
        !          1742: value="$lt{'newp'}" />$help{'Adding_Pages'}
        !          1743: </nobr>
        !          1744: </form>
1.11      www      1745: <form action="/adm/coursedocs" method="post" name="newext">
1.142   ! raeburn  1746: $uploadtag
1.13      www      1747: <input type=hidden name="importdetail" value="">
1.58      albertel 1748: <nobr>
1.18      www      1749: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
1.81      www      1750: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.58      albertel 1751: </nobr>
1.11      www      1752: </form>
                   1753: <form action="/adm/coursedocs" method="post" name="newsyl">
1.142   ! raeburn  1754: $uploadtag
1.14      www      1755: <input type=hidden name="importdetail" 
                   1756: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58      albertel 1757: <nobr>
1.81      www      1758: <input name="newsyl" type="submit" value="$lt{'syll'}" /> 
1.65      bowersj2 1759:  $help{'Syllabus'}
1.58      albertel 1760: </nobr>
                   1761: </form>
1.17      www      1762: <form action="/adm/coursedocs" method="post" name="newnav">
1.142   ! raeburn  1763: $uploadtag
1.15      www      1764: <input type=hidden name="importdetail" 
                   1765: value="Navigate Content=/adm/navmaps">
1.58      albertel 1766: <nobr>
1.81      www      1767: <input name="newnav" type="submit" value="$lt{'navc'}" />
1.47      www      1768: $help{'Navigate_Content'}
1.58      albertel 1769: </nobr>
1.22      www      1770: </form>
                   1771: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.142   ! raeburn  1772: $uploadtag
1.22      www      1773: <input type=hidden name="importdetail" value="">
1.58      albertel 1774: <nobr>
1.81      www      1775: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1.65      bowersj2 1776: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1.58      albertel 1777: </nobr>
1.55      www      1778: </form>
                   1779: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.142   ! raeburn  1780: $uploadtag
1.55      www      1781: <input type=hidden name="importdetail" value="">
1.58      albertel 1782: <nobr>
1.81      www      1783: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1.65      bowersj2 1784: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.62      www      1785: </nobr>
                   1786: </form>
                   1787: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.142   ! raeburn  1788: $uploadtag
1.62      www      1789: <input type=hidden name="importdetail" value="">
                   1790: <nobr>
1.81      www      1791: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1.62      www      1792: onClick="javascript:makeexamupload();" />
1.66      bowersj2 1793: $help{'Score_Upload_Form'}
1.58      albertel 1794: </nobr>
1.22      www      1795: </form>
                   1796: <form action="/adm/coursedocs" method="post" name="newbul">
1.142   ! raeburn  1797: $uploadtag
1.22      www      1798: <input type=hidden name="importdetail" value="">
1.58      albertel 1799: <nobr>
1.81      www      1800: <input name="newbulletin" type="button" value="$lt{'bull'}"
1.22      www      1801: onClick="javascript:makebulboard();" />
1.65      bowersj2 1802: $help{'Bulletin Board'}
1.58      albertel 1803: </nobr>
                   1804: </form>
1.12      www      1805: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.142   ! raeburn  1806: $uploadtag
1.14      www      1807: <input type=hidden name="importdetail" 
                   1808: value="$plainname=/adm/$udom/$uname/aboutme">
1.58      albertel 1809: <nobr>
1.81      www      1810: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65      bowersj2 1811: $help{'My Personal Info'}
1.101     www      1812: </nobr>
                   1813: </form>
                   1814: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.142   ! raeburn  1815: $uploadtag
1.101     www      1816: <input type=hidden name="importdetail" value="">
                   1817: <nobr>
                   1818: <input name="newaboutsomeone" type="button" value="$lt{'abou'}" 
                   1819: onClick="javascript:makeabout();" />
1.110     raeburn  1820: </nobr>
1.142   ! raeburn  1821: ENDFORM
        !          1822:        }
        !          1823:        if ($ENV{'form.pagepath'}) {
        !          1824:            $r->print(<<ENDBLOCK);
        !          1825: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
        !          1826: $uploadtag
        !          1827: <input type=hidden name="importdetail" value="">
        !          1828: <nobr>
        !          1829: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
        !          1830: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
        !          1831: </nobr>
        !          1832: </form>
        !          1833: <form action="/adm/coursedocs" method="post" name="newexamupload">
        !          1834: $uploadtag
        !          1835: <input type=hidden name="importdetail" value="">
        !          1836: <nobr>
        !          1837: <input name="newexamupload" type="button" value="$lt{'scuf'}"
        !          1838: onClick="javascript:makeexamupload();" />
        !          1839: $help{'Score_Upload_Form'}
        !          1840: </nobr>
        !          1841: </form>
        !          1842: ENDBLOCK
        !          1843:        } else {
        !          1844:            $r->print(<<ENDFORM);
1.110     raeburn  1845: </form>
                   1846: <form action="/adm/imsimportdocs" method="post" name="ims">
1.118     albertel 1847: <input type="hidden" name="folder" value="$folder" />
1.110     raeburn  1848: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
1.58      albertel 1849: </nobr>
                   1850: </form>
1.8       www      1851: ENDFORM
1.142   ! raeburn  1852:        }
        !          1853:        $r->print('</td></tr>'."\n".
        !          1854: '</table>');
1.24      www      1855:        $r->print('</td></tr>');
1.7       www      1856:     }
                   1857: # ----------------------------------------------------- Supplemental documents
                   1858:     if (!$forcestandard) {
1.116     albertel 1859:        $r->print('<tr><td bgcolor="#BBBBBB">');
                   1860: # '<h2>'.&mt('Supplemental Course Documents').
                   1861: #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1.7       www      1862:        my $folder=$ENV{'form.folder'};
1.117     albertel 1863:        unless ($folder=~/^supplemental/) {
1.116     albertel 1864: 	   $folder='supplemental';
1.117     albertel 1865:        }
                   1866:        if ($folder =~ /^supplemental$/ &&
                   1867: 	   $ENV{'form.folderpath'} =~ /^default\&/) {
                   1868: 	   $ENV{'form.folderpath'}='supplemental&'.
                   1869: 	       &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
1.116     albertel 1870:        }
1.7       www      1871:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8       www      1872:        if ($allowed) {
1.17      www      1873:        my $folderseq=
                   1874:                   '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
                   1875:                      '.sequence';
                   1876: 
1.8       www      1877:           $r->print(<<ENDSUPFORM);
1.43      www      1878: <table cellspacing=4 cellpadding=4><tr>
1.81      www      1879: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
                   1880: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.17      www      1881: </tr>
                   1882: <tr><td bgcolor="#DDDDDD">
1.10      www      1883: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59      www      1884: <input type="file" name="uploaddoc" size="40">
1.96      sakharuk 1885: <br />$lt{'comment'}:<br />
1.4       www      1886: <textarea cols=50 rows=4 name='comment'>
                   1887: </textarea>
1.115     albertel 1888: <br />
                   1889: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.10      www      1890: <input type="hidden" name="cmd" value="upload_supplemental">
1.58      albertel 1891: <nobr>
1.81      www      1892: <input type="submit" value="$lt{'upld'}">
1.58      albertel 1893:  $help{'Uploading_From_Harddrive'}
                   1894: </nobr>
                   1895: </form>
1.17      www      1896: </td>
                   1897: <td bgcolor="#DDDDDD">
1.18      www      1898: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.115     albertel 1899: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17      www      1900: <input type=hidden name="importdetail" value="">
1.58      albertel 1901: <nobr>
1.17      www      1902: <input name="newfolder" type="button"
                   1903: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81      www      1904: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1.58      albertel 1905: </nobr>
1.17      www      1906: </form>
1.18      www      1907: <form action="/adm/coursedocs" method="post" name="supnewext">
1.115     albertel 1908: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17      www      1909: <input type=hidden name="importdetail" value="">
1.58      albertel 1910: <nobr>
1.18      www      1911: <input name="newext" type="button" 
                   1912: onClick="javascript:makenewext('supnewext');"
1.81      www      1913: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.58      albertel 1914: </nobr>
1.17      www      1915: </form>
1.18      www      1916: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.115     albertel 1917: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17      www      1918: <input type=hidden name="importdetail" 
                   1919: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58      albertel 1920: <nobr>
1.81      www      1921: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65      bowersj2 1922: $help{'Syllabus'}
1.58      albertel 1923: </nobr>
                   1924: </form>
1.18      www      1925: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.115     albertel 1926: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17      www      1927: <input type=hidden name="importdetail" 
                   1928: value="$plainname=/adm/$udom/$uname/aboutme">
1.58      albertel 1929: <nobr>
1.81      www      1930: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65      bowersj2 1931: $help{'My Personal Info'}
1.58      albertel 1932: </nobr>
                   1933: </form>
1.17      www      1934: </td></tr>
1.24      www      1935: </table></td></tr>
1.8       www      1936: ENDSUPFORM
                   1937:        }
1.7       www      1938:     }
1.18      www      1939:     if ($allowed) {
                   1940: 	$r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
                   1941:     }
1.24      www      1942:     $r->print('</table>');
1.19      www      1943:   } else {
                   1944: # -------------------------------------------------------- This is showdoc mode
1.141     albertel 1945:       $r->print("<h1>".&mt('Uploaded Document').' - '.
                   1946: 		&Apache::lonnet::gettitle($r->uri).'</h1><p>'.
1.81      www      1947: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
                   1948:          &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
1.19      www      1949:   }
1.26      www      1950:  }
1.95      www      1951:  $r->print('</body></html>');
1.26      www      1952:  return OK;
1.1       www      1953: } 
                   1954: 
                   1955: 1;
                   1956: __END__

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