File:  [LON-CAPA] / loncom / interface / londocs.pm
Revision 1.142: download - view: text, annotated - select for diffs
Tue Sep 14 01:21:49 2004 UTC (19 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Add/edit/delete composite pages (.page files) via DOCS. Create .sequence and .page files
immediately when folders or pages are added via DOCS (before items have been added to them) - this
allows lonpageflip to work correctly. New help file for Composite Pages. Pages created via
DOCS stored in /uploaded area may contain uploaded files, resources form RES and simple
problems and score upload templates. Other Special documents are not supported.

    1: # The LearningOnline Network
    2: # Documents
    3: #
    4: # $Id: londocs.pm,v 1.142 2004/09/14 01:21:49 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   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.
   14: #
   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: 
   29: package Apache::londocs;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common :http);
   33: use Apache::lonnet;
   34: use Apache::loncommon;
   35: use Apache::lonratedt;
   36: use Apache::lonratsrv;
   37: use Apache::lonxml;
   38: use Apache::loncreatecourse;
   39: use Apache::lonnavmaps;
   40: use HTML::Entities;
   41: use GDBM_File;
   42: use Apache::lonlocal;
   43: 
   44: my $iconpath;
   45: 
   46: my %hash;
   47: 
   48: my $hashtied;
   49: my %alreadyseen=();
   50: 
   51: my $hadchanges;
   52: 
   53: # Available help topics
   54: 
   55: my %help=();
   56: 
   57: # Mapread read maps into lonratedt::global arrays 
   58: # @order and @resources, determines status
   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)=@_;
   72:     my ($outtext,$errtext)=
   73:       &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
   74:                                 $map,1);
   75:     if ($errtext) { return ($errtext,2); }
   76:     
   77:     $hadchanges=1;
   78:     return ($errtext,0);
   79: }
   80: 
   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: 	    }
  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) {
  106: 		$home++;
  107: 		$outhash{'home_'.$ca.'@'.$cd}=1;
  108: 	    } else {
  109: 		$outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
  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">'.
  124: 	    '<input type="submit" name="dumpcourse" value="'.
  125: 	    &mt('Dump Course DOCS to Construction Space').'" />'.
  126: 	    &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
  127:     } else {
  128: 	return'</td><td bgcolor="#DDDDCC">'.
  129:      &mt('Dump Course DOCS to Construction Space: available on other servers');
  130:     }
  131: }
  132: 
  133: # -------------------------------------------------------- Actually dump course
  134: 
  135: sub dumpcourse {
  136:     my $r=shift;
  137:     $r->print('<html><head><title>Dump DOCS</title></head>'.
  138:         &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
  139: 	      '<form name="dumpdoc" method="post">');
  140:     my ($home,$other,%outhash)=&authorhosts();
  141:     unless ($home) { return ''; }
  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
  146: 	unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
  147: 	my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
  148: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
  149: 	my $title=$ENV{'form.authorfolder'};
  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{$_};
  161: 	    $newfilename=~s/[^\w\/\.\/]+/\_/g;
  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: 	}
  193:     } else {
  194: # Input form
  195: 	unless ($home==1) {
  196: 	    $r->print(
  197: 		      '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
  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 {
  205: 		    $r->print('<option value="'.$1.'">'.$1.' - '.
  206: 			      &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
  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;
  216: 	$r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
  217: 	&tiehash();
  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>');
  219: 	foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
  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+)$//;
  229: 	    $title=~s/[^\w\/]+/\_/gs;
  230: 	    $title.='.'.$ext;
  231: 	    $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
  232: 	}
  233: 	$r->print("</table>\n");
  234: 	&untiehash();
  235: 	$r->print(
  236:   '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump Course DOCS').'" /></p></form>');
  237:     }
  238: }
  239: 
  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: 
  436: 
  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;
  443:     my $container = shift;
  444:     my $caller = shift;
  445:     while (@_) {
  446: 	my $name = shift;
  447: 	my $url = shift;
  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:         }
  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:     }
  479:     return &storemap($coursenum, $coursedom, $folder.'.'.$container);
  480: }
  481: 
  482: sub breadcrumbs {
  483:     my ($where)=@_;
  484:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  485:     my (@folders);
  486:     if ($ENV{'form.pagepath'}) {
  487:         @folders = split('&',$ENV{'form.pagepath'});
  488:     } else {
  489:         @folders=split('&',$ENV{'form.folderpath'});
  490:     }
  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);
  499: 	    &Apache::lonhtmlcommon::add_breadcrumb(
  500: 		      {'href'=>$url,
  501: 		       'title'=>&Apache::lonnet::unescape($foldername),
  502: 		       'text'=>'<font size="+1">'.
  503: 			   &Apache::lonnet::unescape($foldername).'</font>'
  504: 		       });
  505: 		       
  506: 						 
  507:     }
  508:     return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,
  509: 					       0,'nohelp');
  510: }
  511: 
  512: sub editor {
  513:     my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
  514: 
  515:     $r->print(&breadcrumbs($folder));
  516:     my $errtext='';
  517:     my $fatal=0;
  518:     my $container='sequence';
  519:     if ($ENV{'form.pagepath'}) {
  520:         $container='page';
  521:     }
  522:     ($errtext,$fatal)=
  523:               &mapread($coursenum,$coursedom,$folder.'.'.$container);
  524:     if ($#Apache::lonratedt::order<1) {
  525:        	$Apache::lonratedt::order[0]=1;
  526:         $Apache::lonratedt::resources[1]='';
  527:     }
  528:     if ($fatal) {
  529: 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
  530:     } else {
  531: # ------------------------------------------------------------ Process commands
  532: 
  533: # ---------------- if they are for this folder and user allowed to make changes
  534: 	if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
  535: # set parameters and change order
  536: 	    if (defined($ENV{'form.setparms'})) {
  537: 		my $idx=$ENV{'form.setparms'};
  538: # set parameters
  539: 		if ($ENV{'form.randpick_'.$idx}) {
  540: 		    &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
  541: 		} else {
  542: 		    &Apache::lonratedt::delparameter($idx,'parameter_randompick');
  543: 		}
  544: 		if ($ENV{'form.hidprs_'.$idx}) {
  545: 		    &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
  546: 		} else {
  547: 		    &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
  548: 		}
  549: 		if ($ENV{'form.encprs_'.$idx}) {
  550: 		    &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
  551: 		} else {
  552: 		    &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
  553: 		}
  554: 
  555: 		if ($ENV{'form.newpos'}) {
  556: # change order
  557: 
  558: 		    my $newpos=$ENV{'form.newpos'}-1;
  559: 		    my $currentpos=$ENV{'form.currentpos'}-1;
  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;
  588: 		}
  589: # store the changed version
  590: 
  591: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
  592: 		if ($fatal) {
  593: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
  594: 		    return;
  595: 		}
  596: 		
  597: 	    }
  598: 
  599: # upload a file, if present
  600:            if (($ENV{'form.uploaddoc.filename'}) &&
  601:                ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
  602: 	    if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
  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"
  605: 	      my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
  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;
  613:               if ($folder=~/^supplemental/) {
  614: 		  $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
  615: 		      $ENV{'user.domain'}.'___&&&___'.$comment;
  616:               }
  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;       
  622: 
  623: 	      ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
  624: 	      if ($fatal) {
  625: 		  $r->print('<p><font color="red">'.$errtext.'</font></p>');
  626: 		  return;
  627: 	      }
  628: 	     }
  629:             }
  630: 	    if ($ENV{'form.cmd'}) {
  631:                 my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
  632:                 if ($cmd eq 'del') {
  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: 		    }
  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') {
  643: 		  if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
  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;
  648: 		   }
  649:                 } elsif ($cmd eq 'down') {
  650: 		   if (defined($Apache::lonratedt::order[$idx+1])) {
  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;
  655: 		   }
  656:                 } elsif ($cmd eq 'rename') {
  657:                     my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]];
  658:                     my ($rtitle,@rrest)=split(/\:/,
  659:                        $Apache::lonratedt::resources[
  660: 				       $Apache::lonratedt::order[$idx]]);
  661:                     my $comment=
  662:                      &HTML::Entities::decode($ENV{'form.title'});
  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:                     
  670:                 }
  671: # Store the changed version
  672: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
  673: 					    $folder.'.'.$container);
  674: 		if ($fatal) {
  675: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
  676: 		    return;
  677: 		}
  678:             }
  679: # Group import/search
  680: 	    if ($ENV{'form.importdetail'}) {
  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: 		}
  690: # Store the changed version
  691: 		($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
  692: 					       $container,'londocs',@imports);
  693: 		if ($fatal) {
  694: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
  695: 		    return;
  696: 		}
  697:             }
  698: # Loading a complete map
  699: 	   if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
  700: 	       foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
  701:                    my $idx=$#Apache::lonratedt::resources;
  702:                    $idx++;
  703:                    $Apache::lonratedt::resources[$idx]=$_;
  704:                    $Apache::lonratedt::order
  705: 		       [$#Apache::lonratedt::order+1]=$idx;
  706: 	       }
  707: 
  708: # Store the changed version
  709: 	       ($errtext,$fatal)=&storemap($coursenum,$coursedom,
  710: 					   $folder.'.'.$container);
  711: 	       if ($fatal) {
  712: 		   $r->print('<p><font color="red">'.$errtext.'</font></p>');
  713: 		   return;
  714: 	       }
  715:            }
  716:        }
  717: # ---------------------------------------------------------------- End commands
  718: # ---------------------------------------------------------------- Print screen
  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]; }
  724:            unless ($name) { next; }
  725:            $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
  726:            $idx++;
  727:         }
  728: 	unless ($idx) {
  729: 	    $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
  730: 	}
  731:         $r->print('</table>');
  732:     }
  733: }
  734: 
  735: # --------------------------------------------------------------- An entry line
  736: 
  737: sub entryline {
  738:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
  739:     $title=~s/\&colon\;/\:/g;
  740:     $title=&HTML::Entities::encode(&HTML::Entities::decode(
  741:      &Apache::lonnet::unescape($title)),'"<>&\'');
  742:     my $renametitle=$title;
  743:     my $foldertitle=$title;
  744:     my $pagetitle=$title;
  745:     my $orderidx=$Apache::lonratedt::order[$index];
  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:     }
  753:     $renametitle=~s/\&quot\;/\\\"/g;
  754:     my $line='<tr>';
  755: # Edit commands
  756:     my $container;
  757:     my $folderpath;
  758:     if ($ENV{'form.folderpath'}) {
  759:         $container = 'sequence';
  760: 	$folderpath=&Apache::lonnet::escape($ENV{'form.folderpath'});
  761: 	# $htmlfoldername=&HTML::Entities::encode($ENV{'form.foldername'},'<>&"');
  762:     }
  763:     my $pagepath;
  764:     if ($ENV{'form.pagepath'}) {
  765:         $container = 'page';
  766:         $pagepath=&Apache::lonnet::escape($ENV{'form.pagepath'});
  767:     }
  768:     if ($allowed) {
  769: 	my $incindex=$index+1;
  770: 	my $selectbox='';
  771: 	if ($folder!~/^supplemental/) {
  772: 	    $selectbox=
  773: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
  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: 	}
  784: 	my %lt=&Apache::lonlocal::texthash(
  785:                 'up' => 'Move Up',
  786: 		'dw' => 'Move Down',
  787: 		'rm' => 'Remove',
  788: 		'rn' => 'Rename');
  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); 
  811: <form name="entry_$index" action="/adm/coursedocs" method="post">
  812: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
  813: <input type="hidden" name="setparms" value="$orderidx" />
  814: <td><table border='0' cellspacing='2' cellpadding='0'>
  815: <tr><td bgcolor="#DDDDDD">
  816: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath'>
  817: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
  818: <tr><td bgcolor="#DDDDDD">
  819: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath'>
  820: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
  821: </table></td>
  822: <td>$selectbox
  823: </td><td bgcolor="#DDDDDD">
  824: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
  825: <font size="-2" color="#990000">$lt{'rm'}</font></a>
  826: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
  827: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
  828: END
  829:         }
  830:     }
  831: # Figure out what kind of a resource this is
  832:     my ($extension)=($url=~/\.(\w+)$/);
  833:     my $uploaded=($url=~/^\/*uploaded\//);
  834:     my $icon=&Apache::loncommon::icon($url);
  835:     my $isfolder=0;
  836:     my $ispage=0;
  837:     my $folderarg;
  838:     my $pagearg;
  839:     my $pagefile;
  840:     if ($uploaded) {
  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;
  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;
  853: 	} else {
  854: 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
  855: 	}
  856:     }
  857:     $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
  858:     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
  859: 	my $symb=&Apache::lonnet::symbclean(
  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.'___'.
  865: 	   &Apache::lonnet::declutter($url));
  866: 	(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
  867: 	$url=&Apache::lonnet::clutter($url);
  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: 	}
  879:         unless ($container eq 'page') {
  880: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
  881:         }
  882:     }
  883:     my $parameterset='&nbsp;';
  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);
  890: 	$parameterset=&mt('Randomly Pick: ').
  891: 	    '<input type="text" size="4" name="randpick_'.$orderidx.'" value="'.
  892: 	    (&Apache::lonratedt::getparameter($orderidx,'parameter_randompick'))[0].'" />';
  893:     }
  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:     }
  902:     $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
  903: 	'" border="0"></a></td>'.
  904:         "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
  905:     if (($allowed) && ($folder!~/^supplemental/)) {
  906:  	my %lt=&Apache::lonlocal::texthash(
  907:  			      'hd' => 'Hidden',
  908:  			      'ec' => 'URL hidden',
  909:  			      'sp' => 'Store Parameters');
  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"':'');
  914: 	$line.=(<<ENDPARMS);
  915: <td bgcolor="#BBBBFF"><font size='-2'>
  916: <input type="checkbox" name="hidprs_$orderidx" $hidtext/> $lt{'hd'}</td>
  917: <!--<td bgcolor="#BBBBFF"><font size='-2'>
  918: <input type="checkbox" name="encprs_$orderidx" $enctext/> $lt{'ec'}</td>-->
  919: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
  920: <td bgcolor="#BBBBFF"><font size='-2'>
  921: <input type="submit" value="$lt{'sp'}" />
  922: </font></td>
  923: ENDPARMS
  924:     }
  925:     $line.="</form></tr>";
  926:     return $line;
  927: }
  928: 
  929: # ---------------------------------------------------------------- tie the hash
  930: 
  931: sub tiehash {
  932:     my ($mode)=@_;
  933:     $hashtied=0;
  934:     if ($ENV{'request.course.fn'}) {
  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)) {
  943:                 $hashtied=1;
  944: 	    }
  945: 	}
  946:     }    
  947: }
  948: 
  949: sub untiehash {
  950:     if ($hashtied) { untie %hash; }
  951:     $hashtied=0;
  952: }
  953: 
  954: # --------------------------------------------------------------- check on this
  955: 
  956: sub checkonthis {
  957:     my ($r,$url,$level,$title)=@_;
  958:     $url=&Apache::lonnet::unescape($url);
  959:     $alreadyseen{$url}=1;
  960:     $r->rflush();
  961:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
  962:        $r->print("\n<br />");
  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) {
  972:              $r->print('<font color="green">'.&mt('ok').'</font>');
  973:              $r->rflush();
  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:                  }
  982:                  $r->print('- '.&mt('Rendering').': ');
  983:                  my $oldpath=$ENV{'request.filename'};
  984:                  $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
  985:                  &Apache::lonxml::xmlparse($r,'web',
  986:                    &Apache::lonnet::getfile(
  987:                     &Apache::lonnet::filelocation('',$url)));
  988: 		 undef($Apache::lonhomework::parsing_a_problem);
  989: 		 $ENV{'request.filename'}=$oldpath;
  990:                  if (($Apache::lonxml::errorcount) ||
  991:                      ($Apache::lonxml::warningcount)) {
  992: 		     if ($Apache::lonxml::errorcount) {
  993:                         $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
  994: 			  $Apache::lonxml::errorcount.' '.
  995: 				  &mt('error(s)').'</b></font> ');
  996:                      }
  997: 		     if ($Apache::lonxml::warningcount) {
  998:                         $r->print('<font color="blue">'.
  999: 			  $Apache::lonxml::warningcount.' '.
 1000: 				  &mt('warning(s)').'</font>');
 1001:                      }
 1002:                  } else {
 1003:                      $r->print('<font color="green">'.&mt('ok').'</font>');
 1004:                  }
 1005:                  $r->rflush();
 1006:              }
 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) {
 1015:              $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
 1016:           } elsif ($result==HTTP_NOT_FOUND) {
 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: 	      }
 1022:           } else {
 1023:              $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
 1024:           }
 1025:       }
 1026:    }
 1027: }
 1028: 
 1029: 
 1030: #
 1031: # -------------------------------------------------------------- Verify Content
 1032: # 
 1033: sub verifycontent {
 1034:    my $r=shift; 
 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'));
 1040:    $hashtied=0;
 1041:    undef %alreadyseen;
 1042:    %alreadyseen=();
 1043:    &tiehash();
 1044:    foreach (keys %hash) {
 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{$_})})) {
 1054:            &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
 1055:        }
 1056:    }
 1057:    &untiehash();
 1058:    $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
 1059: 	     &mt('Return to DOCS').'</a>');
 1060: }
 1061: 
 1062: # -------------------------------------------------------------- Check Versions
 1063: 
 1064: sub checkversions {
 1065:     my $r=shift;
 1066:     $r->print('<html><head><title>Check Versions</title></head>'.
 1067:               &Apache::loncommon::bodytag('Check Course Document Versions'));
 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;
 1076:     my $haschanged=0;
 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=();
 1084:     if ($ENV{'form.setmostrecent'}) {
 1085: 	$haschanged=1;
 1086: 	foreach (keys %hash) {
 1087: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
 1088: 		$newsetversions{$1}='mostrecent';
 1089: 	    }
 1090: 	}
 1091:     } elsif ($ENV{'form.setcurrent'}) {
 1092: 	$haschanged=1;
 1093: 	foreach (keys %hash) {
 1094: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
 1095: 		my $getvers=&Apache::lonnet::getversion($1);
 1096: 		if ($getvers>0) {
 1097: 		    $newsetversions{$1}=$getvers;
 1098: 		}
 1099: 	    }
 1100: 	}
 1101:     } elsif ($ENV{'form.setversions'}) {
 1102: 	$haschanged=1;
 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: 	}
 1111:     }
 1112:     if ($haschanged) {
 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: 	}
 1120: 	&mark_hash_old();
 1121:     }
 1122:     &changewarning($r,'');
 1123:     if ($ENV{'form.timerange'} eq 'all') {
 1124: # show all documents
 1125: 	$header=&mt('All Documents in Course');
 1126: 	$allsel=1;
 1127: 	foreach (keys %hash) {
 1128: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
 1129: 		my $src=$1;
 1130: 		$changes{$src}=1;
 1131: 	    }
 1132: 	}
 1133:     } else {
 1134: # show documents which changed
 1135: 	%changes=&Apache::lonnet::dump
 1136: 	 ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1137:                      $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 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:     }
 1166:     %setversions=&Apache::lonnet::dump('resourceversions',
 1167: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 1168: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
 1169:     my %lt=&Apache::lonlocal::texthash
 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',
 1174:                'al' => 'All Resources (possibly large output)',
 1175: 	       'sd' => 'Display',
 1176: 	       'fi' => 'File',
 1177: 	       'md' => 'Modification Date',
 1178:                'mr' => 'Most recently published Version',
 1179: 	       've' => 'Version used in Course',
 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)',
 1184: 	       'di' => 'Differences');
 1185:     $r->print(<<ENDHEADERS);
 1186: <form action="/adm/coursedocs" method="post">
 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 />
 1190: <select name="timerange">
 1191: <option value='all' $allsel>$lt{'al'}</option>
 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>
 1196: </select>
 1197: <input type="submit" name="display" value="$lt{'sd'}" />
 1198: <h3>$header</h3>
 1199: <input type="submit" name="setversions" value="$lt{'sv'}" />
 1200: <table border="0">
 1201: ENDHEADERS
 1202:     foreach (sort keys %changes) {
 1203: 	if ($changes{$_}>$starttime) {
 1204: 	    my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
 1205: 	    my $currentversion=&Apache::lonnet::getversion($_);
 1206: 	    if ($currentversion<0) {
 1207: 		$currentversion=&mt('Could not be determined.');
 1208: 	    }
 1209: 	    my $linkurl=&Apache::lonnet::clutter($_);
 1210: 	    $r->print(
 1211: 		      '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
 1212: 		      &Apache::lonnet::gettitle($linkurl).
 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'}.'">'.
 1220: 		      &Apache::lonlocal::locallocaltime(
 1221:                            &Apache::lonnet::metadata($root.'.'.$extension,
 1222:                                                      'lastrevisiondate')
 1223:                                                         ).
 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">');
 1230: # Used in course
 1231: 	    my $usedversion=$hash{'version_'.$linkurl};
 1232: 	    if (($usedversion) && ($usedversion ne 'mostrecent')) {
 1233: 		$r->print($usedversion);
 1234: 	    } else {
 1235: 		$r->print($currentversion);
 1236: 	    }
 1237: 	    $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
 1238:                       '<nobr>Use: ');
 1239: # Set version
 1240: 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
 1241: 						      'set_version_'.$linkurl,
 1242: 						      ('select_form_order' =>
 1243: 						       ['',1..$currentversion,'mostrecent'],
 1244: 						       '' => '',
 1245: 						       'mostrecent' => 'most recent',
 1246: 						       map {$_,$_} (1..$currentversion))));
 1247: 	    $r->print('</nobr></td></tr><tr><td></td>');
 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: 	    }
 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;
 1269:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
 1270: 		my $url=$root.'.'.$prevvers.'.'.$extension;
 1271: 		$r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
 1272: 			  '">'.&mt('Version').' '.$prevvers.'</a> ('.
 1273: 			  &Apache::lonlocal::locallocaltime(
 1274:                                 &Apache::lonnet::metadata($url,
 1275:                                                           'lastrevisiondate')
 1276:                                                             ).
 1277: 			  ')');
 1278: 		if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
 1279:                     $r->print(' <a href="/adm/diff?filename='.
 1280: 			      &Apache::lonnet::clutter($root.'.'.$extension).
 1281: 			      '&versionone='.$prevvers.
 1282: 			      '">'.&mt('Diffs').'</a>');
 1283: 		}
 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:                 }
 1292: 	    }
 1293:             while($cols_output++ < 4) {
 1294:                 $r->print('</font></td><td><font>')
 1295:             }
 1296: 	    $r->print('</font></td></tr>'."\n");
 1297: 	}
 1298:     }
 1299:     $r->print('</table></form>');
 1300:     $r->print('<h1>'.&mt('Done').'.</h1>');
 1301: 
 1302:     &untiehash();
 1303: }
 1304: 
 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: 
 1328: sub changewarning {
 1329:     my ($r,$postexec)=@_;
 1330:     if (!&is_hash_old()) { return; }
 1331:     $r->print(
 1332: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'. 
 1333: '<form method="post" action="/adm/roles" target="loncapaclient">'.
 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">'.
 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: 
 1344: # ================================================================ Main Handler
 1345: sub handler {
 1346:     my $r = shift;
 1347:     &Apache::loncommon::content_type($r,'text/html');
 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',
 1355:            'Supplemental','Score_Upload_Form','Adding_Pages',
 1356:            'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
 1357: 	   'Check_Resource_Versions','Verify_Content') {
 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');
 1365:     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
 1366: 		    'Option_Response_Simple');
 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');
 1372: 
 1373:   if ($ENV{'form.verify'}) {
 1374:       &verifycontent($r);
 1375:   } elsif ($ENV{'form.versions'}) {
 1376:       &checkversions($r);
 1377:   } elsif ($ENV{'form.dumpcourse'}) {
 1378:       &dumpcourse($r);
 1379:   } elsif ($ENV{'form.exportcourse'}) {
 1380:       &exportcourse($r);
 1381:   } else {
 1382: # is this a standard course?
 1383: 
 1384:     my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
 1385:     my $forcestandard;
 1386:     my $forcesupplement;
 1387:     my $script='';
 1388:     my $allowed;
 1389:     my $events='';
 1390:     my $showdoc=0;
 1391:     my $containertag;
 1392:     my $uploadtag;
 1393:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 1394: 					    ['folderpath','pagepath']);
 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);
 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:     }
 1407:     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
 1408:        $showdoc='/'.$1;
 1409:     }
 1410:     unless ($showdoc) { # got called from remote
 1411:        $forcestandard=($ENV{'form.folder'}=~/^default_/);
 1412:        $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
 1413: 
 1414: # does this user have privileges to post, etc?
 1415:        $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
 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;
 1422:        $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
 1423:        $events='onLoad="'.&Apache::lonmenu::loadevents.
 1424:            '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
 1425:     }
 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: 
 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: 
 1438: # graphics settings
 1439: 
 1440:     $iconpath = $r->dir_config('lonIconsURL') . "/";
 1441: 
 1442:     my $now=time;
 1443: 
 1444: # print screen
 1445:     $r->print(<<ENDDOCUMENT);
 1446: <html>
 1447: <head>
 1448: <title>The LearningOnline Network with CAPA</title>
 1449: <script>
 1450: $script
 1451: </script>
 1452: ENDDOCUMENT
 1453:    if ($allowed) {
 1454:     $r->print(<<ENDNEWSCRIPT);
 1455: <script>
 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: 
 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: 
 1472: function makenewext(targetname) {
 1473:     this.document.forms.extimport.useform.value=targetname;
 1474:     window.open('/adm/rat/extpickframe.html');
 1475: }
 1476: 
 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: 
 1486: function makesmppage() {
 1487:    var title=prompt('Listed Title for the Page');
 1488:    if (title) { 
 1489:     this.document.forms.newsmppg.importdetail.value=
 1490: 	title+'=/adm/$udom/$uname/$now/smppg';
 1491:     this.document.forms.newsmppg.submit();
 1492:    }
 1493: }
 1494: 
 1495: function makesmpproblem() {
 1496:    var title=prompt('Listed Title for the Problem');
 1497:    if (title) { 
 1498:     this.document.forms.newsmpproblem.importdetail.value=
 1499: 	title+'=/res/lib/templates/simpleproblem.problem';
 1500:     this.document.forms.newsmpproblem.submit();
 1501:    }
 1502: }
 1503: 
 1504: function makebulboard() {
 1505:    var title=prompt('Listed Title for the Bulletin Board');
 1506:    if (title) {
 1507:     this.document.forms.newbul.importdetail.value=
 1508: 	title+'=/adm/$udom/$uname/$now/bulletinboard';
 1509:     this.document.forms.newbul.submit();
 1510:    }
 1511: }
 1512: 
 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: 
 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: 
 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();');
 1543: }
 1544: 
 1545: function changename(folderpath,index,oldtitle,container) {
 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;
 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:         }
 1556:         this.document.forms.renameform.submit();
 1557:     }
 1558: }
 1559: 
 1560: function removeres(folderpath,index,oldtitle,container) {
 1561:     if (confirm('Remove "'+oldtitle+'"?')) {
 1562: 	this.document.forms.renameform.cmd.value='del_'+index;
 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:         }
 1569:         this.document.forms.renameform.submit();
 1570:     }
 1571: }
 1572: 
 1573: </script>
 1574: 
 1575: ENDNEWSCRIPT
 1576:   }
 1577: # -------------------------------------------------------------------- Body tag
 1578:   $r->print('</head>'.
 1579:             &Apache::loncommon::bodytag('Course Documents','',$events,
 1580: 					'','',$showdoc).
 1581: 	    &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
 1582:   unless ($showdoc) {
 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',
 1595:                 'newp' => 'New Composite Page',
 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',
 1603:                 'mypi' => 'My Personal Info',
 1604: 		'abou' => 'About User',
 1605:                 'imsf' => 'Import IMS package',
 1606:                 'file' =>  'File',
 1607:                 'title' => 'Title',
 1608:                 'comment' => 'Comment' 
 1609: 					  );
 1610: # -----------------------------------------------------------------------------
 1611:     if ($allowed) {
 1612:        my $dumpbut=&dumpbutton();
 1613:        my $exportbut=&exportbutton();
 1614:        my %lt=&Apache::lonlocal::texthash(
 1615: 					 'vc' => 'Verify Content',
 1616: 					 'cv' => 'Check/Set Resource Versions',
 1617: 					  );
 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:        }
 1627:        unless ($ENV{'form.pagepath'}) {
 1628:            $containertag = '<input type="hidden" name="folderpath" value="" />';
 1629:            $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
 1630:        }
 1631: 
 1632:        $r->print(<<ENDCOURSEVERIFY);
 1633: <form name="renameform" method="post" action="/adm/coursedocs">
 1634: <input type="hidden" name="title" />
 1635: <input type="hidden" name="cmd" />
 1636: $containertag
 1637: </form>
 1638: <form name="simpleedit" method="post" action="/adm/coursedocs">
 1639: <input type=hidden name="importdetail" value="">
 1640: $uploadtag
 1641: </form>
 1642: <form action="/adm/coursedocs" method="post" name="courseverify">
 1643: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
 1644: <tr><td bgcolor="#DDDDCC">
 1645: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
 1646: </td><td bgcolor="#DDDDCC">
 1647:     <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
 1648: $dumpbut
 1649: $exportbut
 1650: </td></tr></table>
 1651: </form>
 1652: ENDCOURSEVERIFY
 1653:        $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
 1654: 		     &mt('Editing the Table of Contents for your Course')));
 1655:     }
 1656: # --------------------------------------------------------- Standard documents
 1657:     $r->print('<table border=2 cellspacing=4 cellpadding=4>');
 1658:     if (($standard) && ($allowed) && (!$forcesupplement)) {
 1659: 	$r->print('<tr><td bgcolor="#BBBBBB">');
 1660: #  '<h2>'.&mt('Main Course Documents').
 1661: #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
 1662:        my $folder=$ENV{'form.folder'};
 1663:        if ($folder eq '' || $folder eq 'supplemental') {
 1664:            $folder='default';
 1665: 	   $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
 1666:        }
 1667:        my $postexec='';
 1668:        if ($folder eq 'default') {
 1669: 	   $r->print('<script>this.window.name="loncapaclient";</script>');
 1670:        } else {
 1671:            #$postexec='self.close();';
 1672:        }
 1673:        $hadchanges=0;
 1674:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
 1675:        if ($hadchanges) {
 1676: 	   &mark_hash_old()
 1677:        }
 1678:        &changewarning($r,$postexec);
 1679:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 1680:                      '.sequence';
 1681:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
 1682:                      '.page';
 1683: 
 1684:        $r->print(<<ENDFORM);
 1685: <table cellspacing=4 cellpadding=4><tr>
 1686: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
 1687: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
 1688: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
 1689: </tr>
 1690: <tr><td bgcolor="#DDDDDD">
 1691: $lt{'file'}:<br />
 1692: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
 1693: <input type="file" name="uploaddoc" size="40">
 1694: <br />
 1695: $lt{'title'}:<br />
 1696: <input type="text" size="50" name="comment">
 1697: $uploadtag
 1698: <input type="hidden" name="cmd" value="upload_default">
 1699: <nobr>
 1700: <input type="submit" value="$lt{'upld'}">
 1701:  $help{'Uploading_From_Harddrive'}
 1702: </nobr>
 1703: </form>
 1704: </td>
 1705: <td bgcolor="#DDDDDD">
 1706: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
 1707: $uploadtag
 1708: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
 1709: <nobr>
 1710: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
 1711: $help{'Importing_LON-CAPA_Resource'}
 1712: </nobr>
 1713: <p>
 1714: <hr />
 1715: <input type="text" size="20" name="importmap"><br />
 1716: <nobr><input type=button 
 1717: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
 1718: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
 1719: $help{'Load_Map'}</nobr>
 1720: </p>
 1721: </form>
 1722: </td>
 1723: <td bgcolor="#DDDDDD">
 1724: ENDFORM
 1725:        unless ($ENV{'form.pagepath'}) {
 1726:            $r->print(<<ENDFORM);
 1727: <form action="/adm/coursedocs" method="post" name="newfolder">
 1728: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 1729: <input type=hidden name="importdetail" value="">
 1730: <nobr>
 1731: <input name="newfolder" type="button"
 1732: onClick="javascript:makenewfolder(this.form,'$folderseq');"
 1733: value="$lt{'newf'}" />$help{'Adding_Folders'}
 1734: </nobr>
 1735: </form>
 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>
 1745: <form action="/adm/coursedocs" method="post" name="newext">
 1746: $uploadtag
 1747: <input type=hidden name="importdetail" value="">
 1748: <nobr>
 1749: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
 1750: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
 1751: </nobr>
 1752: </form>
 1753: <form action="/adm/coursedocs" method="post" name="newsyl">
 1754: $uploadtag
 1755: <input type=hidden name="importdetail" 
 1756: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
 1757: <nobr>
 1758: <input name="newsyl" type="submit" value="$lt{'syll'}" /> 
 1759:  $help{'Syllabus'}
 1760: </nobr>
 1761: </form>
 1762: <form action="/adm/coursedocs" method="post" name="newnav">
 1763: $uploadtag
 1764: <input type=hidden name="importdetail" 
 1765: value="Navigate Content=/adm/navmaps">
 1766: <nobr>
 1767: <input name="newnav" type="submit" value="$lt{'navc'}" />
 1768: $help{'Navigate_Content'}
 1769: </nobr>
 1770: </form>
 1771: <form action="/adm/coursedocs" method="post" name="newsmppg">
 1772: $uploadtag
 1773: <input type=hidden name="importdetail" value="">
 1774: <nobr>
 1775: <input name="newsmppg" type="button" value="$lt{'sipa'}"
 1776: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
 1777: </nobr>
 1778: </form>
 1779: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
 1780: $uploadtag
 1781: <input type=hidden name="importdetail" value="">
 1782: <nobr>
 1783: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
 1784: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
 1785: </nobr>
 1786: </form>
 1787: <form action="/adm/coursedocs" method="post" name="newexamupload">
 1788: $uploadtag
 1789: <input type=hidden name="importdetail" value="">
 1790: <nobr>
 1791: <input name="newexamupload" type="button" value="$lt{'scuf'}"
 1792: onClick="javascript:makeexamupload();" />
 1793: $help{'Score_Upload_Form'}
 1794: </nobr>
 1795: </form>
 1796: <form action="/adm/coursedocs" method="post" name="newbul">
 1797: $uploadtag
 1798: <input type=hidden name="importdetail" value="">
 1799: <nobr>
 1800: <input name="newbulletin" type="button" value="$lt{'bull'}"
 1801: onClick="javascript:makebulboard();" />
 1802: $help{'Bulletin Board'}
 1803: </nobr>
 1804: </form>
 1805: <form action="/adm/coursedocs" method="post" name="newaboutme">
 1806: $uploadtag
 1807: <input type=hidden name="importdetail" 
 1808: value="$plainname=/adm/$udom/$uname/aboutme">
 1809: <nobr>
 1810: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
 1811: $help{'My Personal Info'}
 1812: </nobr>
 1813: </form>
 1814: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
 1815: $uploadtag
 1816: <input type=hidden name="importdetail" value="">
 1817: <nobr>
 1818: <input name="newaboutsomeone" type="button" value="$lt{'abou'}" 
 1819: onClick="javascript:makeabout();" />
 1820: </nobr>
 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);
 1845: </form>
 1846: <form action="/adm/imsimportdocs" method="post" name="ims">
 1847: <input type="hidden" name="folder" value="$folder" />
 1848: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
 1849: </nobr>
 1850: </form>
 1851: ENDFORM
 1852:        }
 1853:        $r->print('</td></tr>'."\n".
 1854: '</table>');
 1855:        $r->print('</td></tr>');
 1856:     }
 1857: # ----------------------------------------------------- Supplemental documents
 1858:     if (!$forcestandard) {
 1859:        $r->print('<tr><td bgcolor="#BBBBBB">');
 1860: # '<h2>'.&mt('Supplemental Course Documents').
 1861: #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
 1862:        my $folder=$ENV{'form.folder'};
 1863:        unless ($folder=~/^supplemental/) {
 1864: 	   $folder='supplemental';
 1865:        }
 1866:        if ($folder =~ /^supplemental$/ &&
 1867: 	   $ENV{'form.folderpath'} =~ /^default\&/) {
 1868: 	   $ENV{'form.folderpath'}='supplemental&'.
 1869: 	       &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
 1870:        }
 1871:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
 1872:        if ($allowed) {
 1873:        my $folderseq=
 1874:                   '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
 1875:                      '.sequence';
 1876: 
 1877:           $r->print(<<ENDSUPFORM);
 1878: <table cellspacing=4 cellpadding=4><tr>
 1879: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
 1880: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
 1881: </tr>
 1882: <tr><td bgcolor="#DDDDDD">
 1883: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
 1884: <input type="file" name="uploaddoc" size="40">
 1885: <br />$lt{'comment'}:<br />
 1886: <textarea cols=50 rows=4 name='comment'>
 1887: </textarea>
 1888: <br />
 1889: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 1890: <input type="hidden" name="cmd" value="upload_supplemental">
 1891: <nobr>
 1892: <input type="submit" value="$lt{'upld'}">
 1893:  $help{'Uploading_From_Harddrive'}
 1894: </nobr>
 1895: </form>
 1896: </td>
 1897: <td bgcolor="#DDDDDD">
 1898: <form action="/adm/coursedocs" method="post" name="supnewfolder">
 1899: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 1900: <input type=hidden name="importdetail" value="">
 1901: <nobr>
 1902: <input name="newfolder" type="button"
 1903: onClick="javascript:makenewfolder(this.form,'$folderseq');"
 1904: value="$lt{'newf'}" /> $help{'Adding_Folders'}
 1905: </nobr>
 1906: </form>
 1907: <form action="/adm/coursedocs" method="post" name="supnewext">
 1908: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 1909: <input type=hidden name="importdetail" value="">
 1910: <nobr>
 1911: <input name="newext" type="button" 
 1912: onClick="javascript:makenewext('supnewext');"
 1913: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
 1914: </nobr>
 1915: </form>
 1916: <form action="/adm/coursedocs" method="post" name="supnewsyl">
 1917: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 1918: <input type=hidden name="importdetail" 
 1919: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
 1920: <nobr>
 1921: <input name="newsyl" type="submit" value="$lt{'syll'}" />
 1922: $help{'Syllabus'}
 1923: </nobr>
 1924: </form>
 1925: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
 1926: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
 1927: <input type=hidden name="importdetail" 
 1928: value="$plainname=/adm/$udom/$uname/aboutme">
 1929: <nobr>
 1930: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
 1931: $help{'My Personal Info'}
 1932: </nobr>
 1933: </form>
 1934: </td></tr>
 1935: </table></td></tr>
 1936: ENDSUPFORM
 1937:        }
 1938:     }
 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:     }
 1942:     $r->print('</table>');
 1943:   } else {
 1944: # -------------------------------------------------------- This is showdoc mode
 1945:       $r->print("<h1>".&mt('Uploaded Document').' - '.
 1946: 		&Apache::lonnet::gettitle($r->uri).'</h1><p>'.
 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>');
 1949:   }
 1950:  }
 1951:  $r->print('</body></html>');
 1952:  return OK;
 1953: } 
 1954: 
 1955: 1;
 1956: __END__

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