File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.80: download - view: text, annotated - select for diffs
Sat Nov 8 10:33:27 2003 UTC (20 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: version_1_1_X, version_1_1_3, version_1_1_2, version_1_1_1, version_1_1_0, version_1_0_99_3, version_1_0_99_2, version_1_0_99_1, version_1_0_99, HEAD
- BUG#2362, sort files listing case insesitively

    1: # The LearningOnline Network with CAPA
    2: # Directory Indexer
    3: #
    4: # $Id: lonindexer.pm,v 1.80 2003/11/08 10:33:27 albertel 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: # YEAR=1999
   29: # 5/21/99, 5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
   30: # 11/23 Gerd Kortemeyer
   31: # YEAR=2000
   32: # 07/20-08/04 H.K. Ng
   33: # YEAR=2001
   34: # 05/9-05/19/2001 H. K. Ng
   35: # 05/21/2001 H. K. Ng
   36: # 05/23/2001 H. K. Ng
   37: # 6/26,7/8 H. K. Ng
   38: # 8/14 H. K. Ng
   39: # 11/30 Matthew Hall
   40: # YEAR=2002
   41: # 6/29/2002 H. K. Ng
   42: #
   43: ###
   44: 
   45: ###############################################################################
   46: ##                                                                           ##
   47: ## ORGANIZATION OF THIS PERL MODULE                                          ##
   48: ##                                                                           ##
   49: ## 1. Description of functions                                               ##
   50: ## 2. Modules used by this module                                            ##
   51: ## 3. Choices for different output views (detailed, summary, xml, etc)       ##
   52: ## 4. BEGIN block (to be run once after compilation)                         ##
   53: ## 5. Handling routine called via Apache and mod_perl                        ##
   54: ## 6. Other subroutines                                                      ##
   55: ##                                                                           ##
   56: ###############################################################################
   57: 
   58: package Apache::lonindexer;
   59: 
   60: # ------------------------------------------------- modules used by this module
   61: use strict;
   62: use Apache::lonnet();
   63: use Apache::loncommon();
   64: use Apache::Constants qw(:common);
   65: use Apache::lonmeta;
   66: use Apache::File;
   67: use Apache::lonlocal;
   68: use GDBM_File;
   69: 
   70: # ---------------------------------------- variables used throughout the module
   71: my %hash; # tied to a user-specific gdbm file
   72: my %dirs; # keys are directories, values are the open/close status
   73: my %language; # has the reference information present in language.tab
   74: 
   75: # ----- Values which are set by the handler subroutine and are accessible to
   76: # -----     other methods.
   77: my $extrafield; # default extra table cell
   78: my $fnum; # file counter
   79: my $dnum; # directory counter
   80: 
   81: # ----- Used to include or exclude files with certain extensions.
   82: my @Only = ();
   83: my @Omit = ();
   84: 
   85: 
   86: # ----------------------------- Handling routine called via Apache and mod_perl
   87: sub handler {
   88:     my $r = shift;
   89:     my $c = $r->connection();
   90:     &Apache::loncommon::content_type($r,'text/html');
   91:     &Apache::loncommon::no_cache($r);
   92:     $r->send_http_header;
   93:     return OK if $r->header_only;
   94:     $fnum=0;
   95:     $dnum=0;
   96: 
   97:     # Deal with stupid global variables (is there a way around making
   98:     # these global to this package?  It is just so wrong....)
   99:     undef (@Only);
  100:     undef (@Omit);
  101: 
  102: # ------------------------------------- read in machine configuration variables
  103:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
  104:     my $domain  = $r->dir_config('lonDefDomain');
  105:     my $role    = $r->dir_config('lonRole');
  106:     my $loadlim = $r->dir_config('lonLoadLim');
  107:     my $servadm = $r->dir_config('lonAdmEMail');
  108:     my $sysadm  = $r->dir_config('lonSysEMail');
  109:     my $lonhost = $r->dir_config('lonHostID');
  110:     my $tabdir  = $r->dir_config('lonTabDir');
  111: 
  112:     my $fileclr='#ffffe6';
  113:     my $line;
  114:     my (@attrchk,@openpath);
  115:     my $uri=$r->uri;
  116: 
  117: # -------------------------------------- see if called from an interactive mode
  118:     # Get the parameters from the query string
  119:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  120: 	     ['catalogmode','launch','acts','mode','form','element',
  121:               'only','omit','titleelement']);
  122:     #-------------------------------------------------------------------
  123:     my $closebutton='';
  124:     my $groupimportbutton='';
  125:     my $colspan=''; 
  126: 
  127:     $extrafield='';
  128:     my $diropendb = 
  129: 	"/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_indexer.db";
  130:     %hash = ();
  131:     {
  132: 	my %dbfile;
  133: 	if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
  134: 	    while(my($key,$value)=each(%dbfile)) {
  135: 		$hash{$key}=$value;
  136: 	    }
  137: 	    untie(%dbfile);
  138: 	}
  139:     }
  140:     {
  141: 	if ($ENV{'form.launch'} eq '1') {
  142: 	    &start_fresh_session();
  143:         }
  144: # -------------------- refresh environment with user database values (in %hash)
  145: 	&setvalues(\%hash,'form.catalogmode',\%ENV,'form.catalogmode'   );
  146: 
  147: # --------------------- define extra fields and buttons in case of special mode
  148: 	if ($ENV{'form.catalogmode'} eq 'interactive') {
  149: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
  150: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
  151: 		' border="0" /></td>';
  152: 	    $colspan=" colspan='2' ";
  153:             my $cl=&mt('Close');
  154:             $closebutton=<<END;
  155: <input type="button" name="close" value='$cl' onClick="self.close()">
  156: END
  157:         }
  158: 	elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
  159: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
  160: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
  161: 		' border="0" /></td>';
  162: 	    $colspan=" colspan='2' ";
  163: 	    my $cl=&mt('Close');
  164:             my $gi=&mt('Group Import');
  165:             $closebutton=<<END;
  166: <input type="button" name="close" value='$cl' onClick="self.close()">
  167: END
  168:             $groupimportbutton=<<END;
  169: <input type="button" name="groupimport" value='$gi'
  170: onClick="javascript:select_group()">
  171: END
  172:         }
  173: 	# Additions made by Matthew to make the browser a little easier to deal
  174: 	# with in the future.
  175: 	#
  176: 	# $mode (at this time) indicates if we are in edit mode.
  177: 	# $form is the name of the form that the URL is placed when the
  178: 	#       selection is made.
  179: 	# $element is the name of the element in $formname which receives
  180: 	#       the URL.
  181: 	# &Apache::lonxml::debug('Checking mode, form, element');
  182: 	&setvalues(\%hash,'form.mode'        ,\%ENV,'form.mode'   );
  183: 	&setvalues(\%hash,'form.form'        ,\%ENV,'form.form'   );
  184: 	&setvalues(\%hash,'form.element'     ,\%ENV,'form.element');
  185: 	&setvalues(\%hash,'form.titleelement',\%ENV,'form.titleelement');
  186: 	&setvalues(\%hash,'form.only'        ,\%ENV,'form.only'   );
  187: 	&setvalues(\%hash,'form.omit'        ,\%ENV,'form.omit'   );
  188: 
  189:         # Deal with 'omit' and 'only' 
  190:         if (exists $ENV{'form.omit'}) {
  191:             @Omit = split(',',$ENV{'form.omit'});
  192:         }
  193:         if (exists $ENV{'form.only'}) {
  194:             @Only = split(',',$ENV{'form.only'});
  195:         }
  196:         
  197: 	my $mode = $ENV{'form.mode'};
  198: 	my ($form,$element,$titleelement);
  199: 	if ($mode eq 'edit' || $mode eq 'parmset') {
  200: 	    $form         = $ENV{'form.form'};
  201: 	    $element      = $ENV{'form.element'};
  202: 	    $titleelement = $ENV{'form.titleelement'};
  203: 	}
  204: 	&Apache::lonxml::debug("mode=$mode form=$form element=$element
  205:                                 titleelement=$titleelement");
  206: # ------ set catalogmodefunctions to have extra needed javascript functionality
  207: 	my $catalogmodefunctions='';
  208: 	if ($ENV{'form.catalogmode'} eq 'interactive' or
  209: 	    $ENV{'form.catalogmode'} eq 'groupimport') {
  210: 	    # The if statement below sets us up to use the old version
  211: 	    # by default (ie. if $mode is undefined).  This is the easy
  212: 	    # way out.  Hopefully in the future I'll find a way to get 
  213: 	    # the calls dealt with in a more comprehensive manner.
  214: 
  215: #
  216: # There is now also mode "simple", which is for the simple version of the rat
  217: #
  218: #
  219: 	    if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
  220:                 my $location = "/adm/groupsort?catalogmode=groupimport&";
  221:                 $location .= "mode=".$mode."&";
  222:                 $location .= "acts=";
  223: 		$catalogmodefunctions=<<"END";
  224: function select_data(title,url) {
  225:     changeTitle(title);
  226:     changeURL(url);
  227:     self.close();
  228: }
  229: function select_group() {
  230:     window.location="$location"+document.forms.fileattr.acts.value;
  231: }
  232: function changeTitle(val) {
  233:     if (opener.inf) {
  234:         if (opener.inf.document.forms.resinfo.elements.t) {
  235:             opener.inf.document.forms.resinfo.elements.t.value=val;
  236:         }
  237:     }
  238: }
  239: function changeURL(val) {
  240:     if (opener.inf) {
  241:         if (opener.inf.document.forms.resinfo.elements.u) {
  242: 	    opener.inf.document.forms.resinfo.elements.u.value=val;
  243:         }
  244:     }
  245: }
  246: END
  247:             } elsif ($mode eq 'edit') { # we are in 'edit' mode
  248:                 my $location = "/adm/groupsort?catalogmode=interactive&";
  249:                 $location .= "form=$form&element=$element&mode=edit&acts=";
  250: 		$catalogmodefunctions=<<END;
  251: // mode = $mode
  252: function select_data(title,url) {
  253:     changeURL(url);
  254:     changeTitle(title);
  255:     self.close();
  256: }
  257: 
  258: function select_group() {
  259:     window.location="$location"+document.forms.fileattr.acts.value;
  260: }
  261: 
  262: function changeURL(val) {
  263:     if (window.opener.document) {
  264: 	window.opener.document.forms["$form"].elements["$element"].value=val;
  265:     } else {
  266: 	    alert("The file you selected is: "+val);
  267:     }
  268: }
  269: END
  270:                 if (!$titleelement) {
  271: 		    $catalogmodefunctions.='function changeTitle(val) {}';
  272: 		} else {
  273: 		    $catalogmodefunctions.=<<END;
  274: function changeTitle(val) {
  275:     if (window.opener.document) {
  276: 	    window.opener.document.forms["$form"].elements["$titleelement"].value=val;
  277:     } else {
  278: 	    alert("The title of the file you selected is: "+val);
  279:     }
  280: }
  281: END
  282:                 }
  283:             } elsif ($mode eq 'parmset') {
  284:                 my $location = "/adm/groupsort?catalogmode=interactive&";
  285:                 $location .= "form=$form&element=$element&mode=parmset&acts=";
  286: 		$catalogmodefunctions=<<END;
  287: // mode = $mode
  288: function select_data(title,url) {
  289:     changeURL(url);
  290:     self.close();
  291: }
  292: 
  293: function select_group() {
  294:     window.location="$location"+document.forms.fileattr.acts.value;
  295: }
  296: 
  297: function changeURL(val) {
  298:     if (window.opener.document) {
  299:         var elementname  = "$element"+"_value";
  300:         var checkboxname = "$element"+"_setparmval";
  301: 	window.opener.document.forms["$form"].elements[elementname].value=val;
  302:         window.opener.document.forms["$form"].elements[checkboxname].checked=true;
  303:     } else {
  304: 	    alert("The file you selected is: "+val);
  305:     }
  306: }
  307: 
  308: END
  309:             }
  310:         }
  311:         $catalogmodefunctions.=<<END;
  312: var acts='';
  313: function rep_dirpath(suffix,val) {
  314:     eval("document.forms.dirpath"+suffix+".acts.value=val");
  315: }
  316: END
  317: 	if ($ENV{'form.catalogmode'} eq 'groupimport') {
  318:             $catalogmodefunctions.=<<END;
  319: function queue(val) {
  320:     if (eval("document.forms."+val+".filelink.checked")) {
  321: 	var l=val.length;
  322: 	var v=val.substring(4,l);
  323: 	document.forms.fileattr.acts.value+='1a'+v+'b';
  324:     }
  325:     else {
  326: 	var l=val.length;
  327: 	var v=val.substring(4,l);
  328: 	document.forms.fileattr.acts.value+='0a'+v+'b';
  329:     }
  330: }
  331: END
  332: 	}
  333: 
  334: # ---------------------------------------------------------------- Print Header
  335: 	$r->print(<<ENDHEADER);
  336: <html>
  337: <head>
  338: <title>The LearningOnline Network With CAPA Directory Browser</title>
  339: 
  340: <script type="text/javascript">
  341: $catalogmodefunctions
  342: function openWindow(url, wdwName, w, h, toolbar,scrollbar,locationbar) {
  343:     var xpos = (screen.width-w)/2;
  344:     xpos = (xpos < 0) ? '0' : xpos;
  345:     var ypos = (screen.height-h)/2-30;
  346:     ypos = (ypos < 0) ? '0' : ypos;
  347:     var options = "width=" + w + ",height=" + h + ",screenx="+xpos+",screeny="+ypos+",";
  348:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
  349:     options += "menubar=no,toolbar="+toolbar+",location="+locationbar+",directories=no";
  350:     var newWin = window.open(url, wdwName, options);
  351:     newWin.focus();
  352: }
  353: function gothere(val) {
  354:     window.location=val+'?acts='+document.forms.fileattr.acts.value;
  355: }
  356: </script>
  357: 
  358: </head>
  359: ENDHEADER
  360: my ($headerdom)=($uri=~/^\/res\/(\w+)\//);
  361: $r->print(&Apache::loncommon::bodytag('Browse Resources',undef,undef,undef,
  362: 				      $headerdom));
  363: # - Evaluate actions from previous page (both cumulatively and chronologically)
  364:         if ($ENV{'form.catalogmode'} eq 'groupimport') {
  365: 	    my $acts=$ENV{'form.acts'};
  366: 	    my @Acts=split(/b/,$acts);
  367: 	    my %ahash;
  368: 	    my %achash;
  369: 	    my $ac=0;
  370: 	    # some initial hashes for working with data
  371: 	    foreach (@Acts) {
  372: 		my ($state,$ref)=split(/a/);
  373: 		$ahash{$ref}=$state;
  374: 		$achash{$ref}=$ac;
  375: 		$ac++;
  376: 	    }
  377: 	    # sorting through the actions and changing the tied database hash
  378: 	    foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
  379: 		my $key=$_;
  380: 		if ($ahash{$key} eq '1') {
  381: 		    $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
  382: 			$hash{'pre_'.$key.'_title'};
  383: 		    $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
  384: 			$hash{'storectr'}+0;
  385: 		    $hash{'storectr'}++;
  386: 		}
  387: 		if ($ahash{$key} eq '0') {
  388: 		    if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
  389: 			delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
  390: 		    }
  391: 		}
  392: 	    }
  393: 	    # deleting the previously cached listing
  394: 	    foreach (keys %hash) {
  395: 		if ($_ =~ /^pre_/ && $_ =~/link$/) {
  396: 		    my $key = $_;
  397: 		    $key =~ s/^pre_//;
  398: 		    $key =~ s/_[^_]*$//;
  399: 		    delete $hash{'pre_'.$key.'_title'};
  400: 		    delete $hash{'pre_'.$key.'_link'};
  401: 		}
  402: 	    }
  403: 	}
  404: 	
  405: # ---------------------------------- get state of file attributes to be showing
  406: 	if ($ENV{'form.attrs'} ne '') {
  407: 	    for (my $i=0; $i<=9; $i++) {
  408: 		delete $hash{'display_attrs_'.$i};
  409: 		if ($ENV{'form.attr'.$i} == 1) {
  410: 		    $attrchk[$i] = 'checked';
  411: 		    $hash{'display_attrs_'.$i} = 1;
  412: 		}
  413: 	    }
  414: 	} else {
  415: 	    for (my $i=0; $i<=9; $i++) {
  416: 		$attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;
  417: 	    }
  418: 	}
  419: # ------------------------------- output state of file attributes to be showing
  420: #                                 All versions has to the last item
  421: #                                 since it does not take an extra col
  422: 	my %lt=&Apache::lonlocal::texthash(
  423: 					   'ti' => 'Title',
  424: 					   'si' => 'Size',
  425: 					   'la' => 'Last access',
  426: 					   'lm' => 'Last modified',
  427: 					   'st' => 'Statistics',
  428: 					   'au' => 'Author',
  429: 					   'kw' => 'Keywords',
  430: 					   'ln' => 'Language',
  431: 					   'sr' => 'Show resource',
  432: 					   'av' => 'All versions',
  433: 					   'ud' => 'Update Display'
  434: 					   );
  435: 	$r->print(<<END);
  436: <form method="post" name="fileattr" action="$uri"
  437:  enctype="application/x-www-form-urlencoded">
  438: <b><font color="#666666">Display file attributes</font></b><br />
  439: <table border=0><tr>
  440: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> $lt{'ti'}</td>
  441: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> $lt{'si'}</td>
  442: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> $lt{'la'}</td>
  443: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> $lt{'lm'}</td>
  444: <td><input type="checkbox" name="attr8" value="1" $attrchk[8] /> $lt{'st'}</td>
  445: </tr><tr>
  446: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> $lt{'au'}</td>
  447: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> $lt{'kw'}</td>
  448: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> $lt{'ln'}</td>
  449: <td><input type="checkbox" name="attr7" value="1" $attrchk[7] /> $lt{'sr'}</td>
  450: <td><input type="checkbox" name="attr9" value="1" $attrchk[9] /> $lt{'av'}</td>
  451: <td>&nbsp;</td>
  452: </tr></table>
  453: <input type="hidden" name="dirPointer" value="on" />
  454: <input type="hidden" name="acts" value="" />
  455: <input type="submit" name="attrs" value="$lt{'ud'}" />
  456: $closebutton
  457: $groupimportbutton
  458: </form>
  459: END
  460: 
  461: # ----------------- output starting row to the indexed file/directory hierarchy
  462:         my $titleclr="#ddffff";
  463: #        $r->print(&initdebug());
  464: #        $r->print(&writedebug("Omit:@Omit")) if (@Omit);
  465: #        $r->print(&writedebug("Only:@Only")) if (@Only);
  466:         $r->print("<table width='100\%' border=0><tr><td bgcolor=#777777>\n");
  467: 	$r->print("<table width='100\%' border=0><tr bgcolor=$titleclr>\n");
  468: 	$r->print("<td $colspan><b>".&mt('Name')."</b></td>\n");
  469: 	$r->print("<td><b>".&mt('Title')."</b></td>\n") 
  470: 	    if ($hash{'display_attrs_0'} == 1);
  471: 	$r->print("<td align=right><b>".&mt("Size")." (".&mt("bytes").") ".
  472: 		  "</b></td>\n") if ($hash{'display_attrs_1'} == 1);
  473: 	$r->print("<td><b>".&mt("Last accessed")."</b></td>\n") 
  474: 	    if ($hash{'display_attrs_2'} == 1);
  475: 	$r->print("<td><b>".&mt("Last modified")."</b></td>\n")
  476: 	    if ($hash{'display_attrs_3'} == 1);
  477: 	$r->print("<td><b>".&mt("Author(s)")."</b></td>\n")
  478: 	    if ($hash{'display_attrs_4'} == 1);
  479: 	$r->print("<td><b>".&mt("Keywords")."</b></td>\n")
  480: 	    if ($hash{'display_attrs_5'} == 1);
  481: 	$r->print("<td><b>".&mt("Language")."</b></td>\n")
  482: 	    if ($hash{'display_attrs_6'} == 1);
  483: 	$r->print("<td><b>".&mt("Resource")."</b></td>\n")
  484: 	    if ($hash{'display_attrs_7'} == 1);
  485: 	$r->print("<td><b>".&mt("Usage Statistics")." <br />(".
  486: 		  &mt("Courses/Network Hits").")</b></td>\n")
  487: 	    if ($hash{'display_attrs_8'} == 1);
  488: 	$r->print('</tr>');
  489: 
  490: # ----------------- read in what directories have previously been set to "open"
  491: 	foreach (keys %hash) {
  492: 	    if ($_ =~ /^diropen_status_/) {
  493: 		my $key = $_;
  494: 		$key =~ s/^diropen_status_//;
  495: 		$dirs{$key} = $hash{$_};
  496: 	    }
  497: 	}
  498: 
  499: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
  500: 	    my $uri=$ENV{'form.openuri'};
  501: 	    if (exists($hash{'diropen_status_'.$uri})) {
  502: 		my $cursta = $hash{'diropen_status_'.$uri};
  503: 		$dirs{$uri} = 'open';
  504: 		$hash{'diropen_status_'.$uri} = 'open';
  505: 		if ($cursta eq 'open') {
  506: 		    $dirs{$uri} = 'closed';
  507: 		    $hash{'diropen_status_'.$uri} = 'closed';
  508: 		}
  509: 	    } else {
  510: 		$hash{'diropen_status_'.$uri} = 'open';
  511: 		$dirs{$uri} = 'open';
  512: 	    }
  513: 	}
  514: 	
  515: 	my $bredir = $ENV{'form.dirPointer'};
  516: 	my $toplevel;
  517: 	my $indent = 0;
  518: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
  519: 
  520: 	if ($bredir ne 'on') {
  521: 	    $hash{'top.level'} = $uri;
  522: 	    $toplevel = $uri;
  523: 
  524: 	} else {
  525: 	    $toplevel = $hash{'top.level'};
  526: 	}
  527: 
  528: # -------------------------------- if not at top level, provide an uplink arrow
  529: 	if ($toplevel ne '/res/'){
  530: 	    my (@uri_com) = split(/\//,$uri);
  531: 	    pop @uri_com;
  532: 	    my $upone = join('/',@uri_com);
  533: 	    my @list = qw (0);
  534: 	    &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
  535: 	    $indent = 1;
  536: 	}
  537: 
  538: # -------- recursively go through all the directories and output as appropriate
  539: 	&scanDir ($r,$toplevel,$indent,\%hash);
  540: 	
  541: # ---------------------------- embed hidden information useful for group import
  542: 	$r->print("<form name='fnum'>");
  543: 	$r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
  544: 
  545: # -------------------------------------------------------------- end the tables
  546: 	$r->print('</table>');
  547: 	$r->print('</td></tr></table>');
  548: 
  549: # --------------------------------------------------- end the output and return
  550: 	$r->print('</body></html>'."\n");
  551: #    } else {
  552: #	$r->print('<html><head></head><body>Unable to tie hash to db '.
  553: #		  'file</body></html>');
  554: #	return OK;
  555:     }
  556:     if(! $c->aborted()) {
  557: 	my %dbfile;
  558:         if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_NEWDB(),0640)) {
  559:             while (my($key,$value) = each(%hash)) {
  560:                 $dbfile{$key}=$value;
  561:             }
  562:             untie(%dbfile);
  563:         }
  564:     }
  565: 
  566:     return OK;
  567: }
  568: 
  569: # ----------------------------------------------- recursive scan of a directory
  570: sub scanDir {
  571:     my ($r,$startdir,$indent,$hashref)=@_;
  572:     my $c = $r->connection();
  573:     my ($compuri,$curdir);
  574:     my $dirptr=16384;
  575:     $indent++;
  576: 
  577:     my %dupdirs = %dirs;
  578:     my @list=&get_list($r,$startdir);
  579:     foreach my $line (@list) {
  580:         return if ($c->aborted());
  581: 	my ($strip,$dom,undef,$testdir,undef)=split(/\&/,$line,5); 
  582: 	next if $strip =~ /.*\.meta$/;
  583: 	my (@fileparts) = split(/\./,$strip);
  584: 	if ($hash{'display_attrs_9'} != 1) {
  585: 	    if (scalar(@fileparts) >= 3) {
  586: 		my $fext = pop @fileparts;
  587: 		my $ov = pop @fileparts;
  588: 		my $fname = join ('.',@fileparts,$fext);
  589: 		next if (grep /\Q$fname\E/,@list and $ov =~ /^\d+$/);
  590: 	    }
  591: 	}
  592: 
  593: 	if ($dom eq 'domain') {
  594: 	    # dom list has full path /res/<domain name>/ already
  595: 	    $curdir='';
  596: 	    $compuri = (split(/\&/,$line))[0];
  597: 	} else {
  598: 	    # user, dir & file have name only, i.e., w/o path
  599: 	    $compuri = join('',$startdir,$strip,'/');
  600: 	    $curdir = $startdir;
  601: 	}
  602: 	my $diropen = 'closed';
  603: 	if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
  604: 	    while (my ($key,$val)= each %dupdirs) {
  605: 		if ($key eq $compuri and $val eq "open") {
  606: 		    $diropen = "opened";
  607: 		    delete($dupdirs{$key});
  608: 		    delete($dirs{$key});
  609: 		}
  610: 	    }
  611: 	}
  612: 	&display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
  613: 	&scanDir ($r,$compuri,$indent) if $diropen eq 'opened';
  614:     }
  615:     $indent--;
  616: }
  617: 
  618: # --------------- get complete matched list based on the uri (returns an array)
  619: sub get_list {
  620:     my ($r,$uri)=@_;
  621:     my @list;
  622:     (my $luri = $uri) =~ s/\//_/g;
  623: 
  624:     if ($ENV{'form.attrs'} eq &mt('Update Display')) {
  625: 	foreach (keys %hash) {
  626: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
  627: 	    }
  628:     }
  629: 
  630:     if ($hash{'dirlist_files'.$luri}) {
  631: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
  632:     } else {
  633: 	@list = &Apache::lonnet::dirlist($uri);
  634: 	$hash{'dirlist_files_'.$luri} = join('\n',@list);
  635:     }
  636:     return @list=&match_ext($r,@list);
  637: }
  638: 
  639: sub initdebug {
  640:     return <<ENDJS;
  641: <script>
  642: var debugging = true;
  643: if (debugging) {
  644:     var debuggingWindow = window.open('','Debug','width=400,height=300',true);
  645: } 
  646: 
  647: function output(text) {
  648:     if (debugging) {
  649:         debuggingWindow.document.writeln(text);
  650:     }
  651: }
  652: output("<html><head><title>Debugging Window</title></head><body><pre>");   
  653: </script>
  654: ENDJS
  655: }
  656: 
  657: sub writedebug {
  658:     my $text = shift;
  659:     return "<script>output('$text');</script>";
  660: }
  661: 
  662: # -------------------- filters out files based on extensions (returns an array)
  663: sub match_ext {
  664:     my ($r,@packlist)=@_;
  665:     my @trimlist;
  666:     my $nextline;
  667:     my @fileext;
  668:     my $dirptr=16384;
  669: 
  670:     foreach my $line (@packlist) {
  671: 	chomp $line;
  672: 	$line =~ s/^\/home\/httpd\/html//;
  673: 	my @unpackline = split (/\&/,$line);
  674: 	next if ($unpackline[0] eq '.');
  675: 	next if ($unpackline[0] eq '..');
  676: 	my @filecom = split (/\./,$unpackline[0]);
  677: 	my $fext = pop(@filecom);
  678: 	my $fnptr = $unpackline[3]&$dirptr;
  679:  	if ($fnptr == 0 and $unpackline[3] ne "") {
  680: 	    my $embstyle = &Apache::loncommon::fileembstyle($fext);
  681:             push @trimlist,$line if (defined($embstyle) && 
  682: 				     ($embstyle ne 'hdn' or $fext eq 'meta'));
  683: 	} else {
  684: 	    push @trimlist,$line;
  685: 	}
  686:     }
  687:     @trimlist = sort {uc($a) cmp uc($b)} (@trimlist);
  688:     return @trimlist;
  689: }
  690: 
  691: # ------------------------------- displays one line in appropriate table format
  692: sub display_line {
  693:     my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
  694:     my (@pathfn, $fndir);
  695:     my $dirptr=16384;
  696:     my $fileclr="#ffffe6";
  697:     my $iconpath= $r->dir_config('lonIconsURL') . '/';
  698: 
  699:     my @filecom = split (/\&/,$line);
  700:     my @pathcom = split (/\//,$filecom[0]);
  701:     my $listname = $pathcom[scalar(@pathcom)-1];
  702:     my $fnptr = $filecom[3]&$dirptr;
  703:     my $msg = &mt('View').' '.$filecom[0].' '.&mt('resources');
  704:     $msg = &mt('Close').' '.$filecom[0].' '.&mt('directory') if $diropen eq 'opened';
  705: 
  706:     my $tabtag='</td>';
  707:     my $i=0;
  708: 
  709:     while ($i<=8) {
  710: 	$tabtag=join('',$tabtag,"<td>&nbsp;</td>")
  711: 	    if $hash{'display_attrs_'.$i} == 1;
  712: 	$i++;
  713:     }
  714: 	
  715:     my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom');
  716: 
  717: # display uplink arrow
  718:     if ($filecom[1] eq 'viewOneUp') {
  719: 	$r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
  720: 	$r->print("<td>\n");
  721: 	$r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
  722: 		   '/" '.
  723: 		   'onSubmit="return rep_dirpath(\'UP\','.
  724: 		   'document.forms.fileattr.acts.value)" '.
  725: 		   'enctype="application/x-www-form-urlencoded"'.
  726:                    '>'."\n");
  727: 	$r->print ('<input type=hidden name=openuri value="'.
  728: 		   $startdir.'">'."\n");
  729: 	$r->print ('<input type="hidden" name="acts" value="">'."\n");
  730: 	$r->print ('<input src="'.$iconpath.'arrow_up.gif"');
  731: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  732: 		   "\n");
  733: 	$r->print(&mt("Up")." $tabtag</tr></form>\n");
  734: 	return OK;
  735:     }
  736: # Do we have permission to look at this?
  737: 
  738:     return OK if (!&Apache::lonnet::allowed('bre',$startdir.$filecom[0]));
  739: 
  740: # display domain
  741:     if ($filecom[1] eq 'domain') {
  742: 	$r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
  743: 	    if ($ENV{'form.dirPointer'} eq "on");
  744: 	$r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
  745: 	$r->print("<td>");
  746: 	&begin_form ($r,$filecom[0]);
  747: 	my $anchor = $filecom[0];
  748: 	$anchor =~ s/\///g;
  749: 	$r->print ('<a name="'.$anchor.'">');
  750: 	$r->print ('<input type="hidden" name="acts" value="">');
  751: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.
  752: 		   $diropen.'.gif"'); 
  753: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  754: 		   "\n");
  755: 	$r->print ('<a href="javascript:gothere(\''.$filecom[0].
  756: 		   '\')"><img src="'.$iconpath.'server.gif"');
  757: 	$r->print (' border="0" /></a>'."\n");
  758: 	$r->print (&mt("Domain")." - $listname ");
  759: 	if ($Apache::lonnet::domaindescription{$listname}) {
  760: 	    $r->print("(".$Apache::lonnet::domaindescription{$listname}.
  761: 		      ")");
  762: 	}
  763: 	$r->print (" $tabtag</tr></form>\n");
  764: 	return OK;
  765: 
  766: # display user directory
  767:     }
  768:     if ($filecom[1] eq 'user') {
  769: 	$r->print("<tr valign=$valign bgcolor=$fileclr>$extrafield");
  770: 	$r->print("<td nowrap>\n");
  771: 	my $curdir = $startdir.$filecom[0].'/';
  772: 	my $anchor = $curdir;
  773: 	$anchor =~ s/\///g;
  774: 	&begin_form ($r,$curdir);
  775: 	$r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
  776: 		   'whitespace1.gif" border="0" />'."\n");
  777: 	$r->print ('<input type="hidden" name="acts" value="">');
  778: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
  779: 		   '.gif"'); 
  780: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  781: 		   "\n");
  782: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
  783: 		   $iconpath.'quill.gif border="0" name="'.$msg.
  784: 		   '" height="22" /></a>');
  785: 	my $domain=(split(m|/|,$startdir))[2];
  786: 	my $plainname=&Apache::loncommon::plainname($listname,$domain);
  787: 	$r->print ($listname);
  788: 	if (defined($plainname) && $plainname) { $r->print(" ($plainname) "); }
  789: 	$r->print ($tabtag.'</tr></form>'."\n");
  790: 	return OK;
  791:     }
  792: 
  793: # display file
  794:     if ($fnptr == 0 and $filecom[3] ne '') {
  795: 	my $filelink = $startdir.$filecom[0];
  796: 	next if &Apache::lonnet::metadata($filelink,'obsolete');
  797: 	my @file_ext = split (/\./,$listname);
  798: 	my $curfext = $file_ext[-1];
  799:         if (@Omit) {
  800:             foreach (@Omit) { return OK if ($curfext eq $_); }
  801:         }
  802:         if (@Only) {
  803:             my $skip = 1;
  804:             foreach (@Only) { $skip = 0 if ($curfext eq $_); }
  805:             return OK if ($skip > 0);
  806:         }
  807: 	# Set the icon for the file
  808: 	my $iconname = "unknown.gif";
  809: 	my $embstyle = &Apache::loncommon::fileembstyle($curfext);
  810: 	# The unless conditional that follows is a bit of overkill
  811: 	$iconname = $curfext.".gif" unless
  812: 	    (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn');
  813: 	#
  814: 	$r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap>");
  815: 	my $metafile = grep /^\Q$filecom[0]\E\.meta\&/, @list;
  816: 	my $title;
  817:         if ($ENV{'form.catalogmode'} eq 'interactive') {
  818: 	    $title=$listname;
  819: 	    $title = &Apache::lonnet::metadata($filelink,'title')
  820: 		if ($metafile == 1);
  821: 	    $title=$listname unless $title;
  822: 	    my $titleesc=HTML::Entities::encode($title);
  823: 	    $titleesc=~s/\'/\\'/; #' (clean up this spare quote)
  824:             $r->print("<a href=\"javascript:select_data(\'",
  825:                       $titleesc,"','",$filelink,"')\">");
  826: 	    $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
  827: 		      "\n");
  828: 	    $r->print("</td><td nowrap>");
  829: 	}
  830:         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
  831: 	    $title=$listname;
  832: 	    $title = &Apache::lonnet::metadata($filelink,'title')
  833: 		if ($metafile == 1);
  834: 	    $title=$listname unless $title;
  835: 	    my $titleesc=&HTML::Entities::encode($title);
  836: 	    $r->print("<form name='form$fnum'>\n");
  837: 	    $r->print("<input type='checkbox' name='filelink"."' ".
  838: 		      "value='$filelink' onClick='".
  839: 		      "javascript:queue(\"form$fnum\")' ");
  840: 	    if ($hash{'store_'.$filelink}) {
  841: 		$r->print("checked");
  842: 	    }
  843: 	    $r->print(">\n");
  844: 	    $r->print("<input type='hidden' name='title"."' ".
  845: 		      "value='$titleesc'>\n");
  846: 	    $r->print("</form>\n");
  847: 	    $r->print("</td><td nowrap>");
  848: 	    $hash{"pre_${fnum}_link"}=$filelink;
  849: 	    $hash{"pre_${fnum}_title"}=$titleesc;
  850:   	    $fnum++;
  851: 	}
  852: 
  853: 	if ($indent > 0 and $indent < 11) {
  854: 	    $r->print("<img src=",$iconpath,"whitespace",$indent,
  855: 		      ".gif border='0' />\n");
  856: 	} elsif ($indent >0) {
  857: 	    my $ten = int($indent/10.);
  858: 	    my $rem = $indent%10.0;
  859: 	    my $count = 0;
  860: 	    while ($count < $ten) {
  861: 		$r->print("<img src=",$iconpath,
  862: 			  "whitespace10.gif border='0' />\n");
  863: 	    $count++;
  864: 	    }
  865: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,
  866: 		      ".gif border='0' />\n") if $rem > 0;
  867: 	}
  868: 
  869: 	$r->print("<img src=$iconpath$iconname border='0' />\n");
  870: 	$r->print (" <a href=\"javascript:openWindow('".$filelink.
  871: 		   "', 'previewfile', '450', '500', 'no', 'yes','yes')\";".
  872: 		   " TARGET=_self>$listname</a> ");
  873: 
  874: 	$r->print (" (<a href=\"javascript:openWindow('".$filelink.
  875: 		   ".meta', 'metadatafile', '500', '550', 'no', 'yes','no')\"; ".
  876: 		   "TARGET=_self>metadata</a>) ") if ($metafile == 1);
  877: 
  878: 	$r->print("</td>\n");
  879: 	if ($hash{'display_attrs_0'} == 1) {
  880: 	    my $title = &Apache::lonnet::gettitle($filelink,'title')
  881: 		if ($metafile == 1);
  882: 	    $r->print('<td> '.($title eq '' ? '&nbsp;' : $title).
  883: 		      ' </td>'."\n");
  884: 	}
  885: 	$r->print('<td align=right> ',
  886: 		  $filecom[8]," </td>\n") 
  887: 	    if $hash{'display_attrs_1'} == 1;
  888: 	$r->print('<td> '.
  889: 		  (localtime($filecom[9]))." </td>\n") 
  890: 	    if $hash{'display_attrs_2'} == 1;
  891: 	$r->print('<td> '.
  892: 		  (localtime($filecom[10]))." </td>\n") 
  893: 	    if $hash{'display_attrs_3'} == 1;
  894: 
  895: 	if ($hash{'display_attrs_4'} == 1) {
  896: 	    my $author = &Apache::lonnet::metadata($filelink,'author')
  897: 		if ($metafile == 1);
  898: 	    $r->print('<td> '.($author eq '' ? '&nbsp;' : $author).
  899: 		      " </td>\n");
  900: 	}
  901: 	if ($hash{'display_attrs_5'} == 1) {
  902: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
  903: 		if ($metafile == 1);
  904: 	    # $keywords = '&nbsp;' if (!$keywords);
  905: 	    $r->print('<td> '.($keywords eq '' ? '&nbsp;' : $keywords).
  906: 		      " </td>\n");
  907: 	}
  908: 	if ($hash{'display_attrs_6'} == 1) {
  909: 	    my $lang = &Apache::lonnet::metadata($filelink,'language')
  910: 		if ($metafile == 1);
  911: 	    $lang = &Apache::loncommon::languagedescription($lang);
  912: 	    $r->print('<td> '.($lang eq '' ? '&nbsp;' : $lang).
  913: 		      " </td>\n");
  914: 	}
  915:         if ($hash{'display_attrs_7'} == 1) {
  916:             my $output='';
  917:             my $embstyle=&Apache::loncommon::fileembstyle($curfext);
  918: 	    if ($embstyle eq 'ssi') {
  919: 	       $output=&Apache::lonnet::ssi_body($filelink);
  920:                $output='<font size="-2">'.$output.'</font>';
  921: 	   } elsif ($embstyle eq 'img') {
  922:                $output='<img src="'.$filelink.'" />';
  923:            } elsif ($filelink=~/^\/res\/(\w+)\/(\w+)\//) {
  924:                $output='<img src="http://'.
  925: 		 $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}.
  926:                  '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
  927:            }
  928: 	   $r->print('<td> '.($output eq '' ? '&nbsp;':$output).
  929: 		      " </td>\n");
  930:         }
  931: 	if ($hash{'display_attrs_8'} == 1) {
  932: 	    my (%stat) = &Apache::lonmeta::dynamicmeta($filelink) if ($metafile == 1);
  933: 	    my $stat = (exists($stat{'course'}) ? $stat{'course'} : '').
  934: 		((exists($stat{'course'}) || exists($stat{'count'})) ? '/' : '').
  935: 		(exists($stat{'count'}) ? $stat{'count'} : '');
  936: 	    $r->print('<td align=center> '.($stat eq '' ? '&nbsp;' : $stat).
  937: 		      ' </td>'."\n");
  938: 	}
  939: 
  940: 	$r->print("</tr>\n");
  941:     }
  942: 
  943: # -- display directory
  944:     if ($fnptr == $dirptr) {
  945: 	my @file_ext = split (/\./,$listname);
  946: 	my $curfext = $file_ext[scalar(@file_ext)-1];
  947: 	my $curdir = $startdir.$filecom[0].'/';
  948: 	my $anchor = $curdir;
  949: 	$anchor =~ s/\///g;
  950: 	$r->print("<tr bgcolor=$fileclr>$extrafield<td valign=$valign>");
  951: 	&begin_form ($r,$curdir);
  952: 	my $indentm1 = $indent-1;
  953: 	if ($indentm1 < 11 and $indentm1 > 0) {
  954: 	    $r->print("<img src=",$iconpath,"whitespace",$indentm1,
  955: 		      ".gif border='0' />\n");
  956: 	} else {
  957: 	    my $ten = int($indentm1/10.);
  958: 	    my $rem = $indentm1%10.0;
  959: 	    my $count = 0;
  960: 	    while ($count < $ten) {
  961: 		$r->print ("<img src=",$iconpath
  962: 			   ,"whitespace10.gif border='0' />\n");
  963: 		$count++;
  964: 	    }
  965: 	    $r->print ("<img src=",$iconpath,"whitespace",$rem,
  966: 		       ".gif border='0' />\n") if $rem > 0;
  967: 	}
  968: 	$r->print ('<input type="hidden" name="acts" value="">');
  969: 	$r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
  970: 		   'folder_pointer_'.$diropen.'.gif"');
  971: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  972: 		   "\n");
  973: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
  974: 		   $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
  975: 		   "\n");
  976: 	$r->print ("$listname$tabtag</tr></form>\n");
  977:     }
  978: 
  979: }
  980: 
  981: # ------------------- prints the beginning of a form for directory or file link
  982: sub begin_form {
  983:     my ($r,$uri) = @_;
  984:     my $anchor = $uri;
  985:     $anchor =~ s/\///g;
  986:     $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
  987: 	       '#'.$anchor.
  988: 	       '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
  989: 	       ',document.forms.fileattr.acts.value)" '.
  990: 	       'enctype="application/x-www-form-urlencoded">'."\n");
  991:     $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
  992: 	       "\n");
  993:     $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
  994:     $dnum++;
  995: }
  996: 
  997: # --------- settings whenever the user causes the indexer window to be launched
  998: sub start_fresh_session {
  999:     delete $hash{'form.catalogmode'};
 1000:     delete $hash{'form.mode'};
 1001:     delete $hash{'form.form'};
 1002:     delete $hash{'form.element'};
 1003:     delete $hash{'form.omit'};
 1004:     delete $hash{'form.only'};
 1005:     foreach (keys %hash) {
 1006:         delete $hash{$_} if (/^(pre_|store)/);
 1007:     }
 1008: }
 1009: 
 1010: # ------------------------------------------------------------------- setvalues
 1011: sub setvalues {
 1012:     # setvalues is used in registerurl to synchronize the database
 1013:     # hash and environment hashes
 1014:     my ($H1,$h1key,$H2,$h2key) =@_;
 1015:     #
 1016:     if (exists $H2->{$h2key}) {
 1017: 	$H1->{$h1key} = $H2->{$h2key};
 1018:     } elsif (exists $H1->{$h1key}) {
 1019: 	$H2->{$h2key} = $H1->{$h1key};
 1020:     } 
 1021: }
 1022: 
 1023: 1;
 1024: 
 1025: sub cleanup {
 1026:     if (tied(%hash)){
 1027: 	&Apache::lonnet::logthis('Cleanup indexer: hash');
 1028:     }
 1029: }
 1030: 
 1031: =head1 NAME
 1032: 
 1033: Apache::lonindexer - mod_perl module for cross server filesystem browsing
 1034: 
 1035: =head1 SYNOPSIS
 1036: 
 1037: Invoked by /etc/httpd/conf/srm.conf:
 1038: 
 1039:  <LocationMatch "^/res.*/$">
 1040:  SetHandler perl-script
 1041:  PerlHandler Apache::lonindexer
 1042:  </LocationMatch>
 1043: 
 1044: =head1 INTRODUCTION
 1045: 
 1046: This module enables a scheme of browsing across a cross server.
 1047: 
 1048: This is part of the LearningOnline Network with CAPA project
 1049: described at http://www.lon-capa.org.
 1050: 
 1051: =head1 BEGIN SUBROUTINE
 1052: 
 1053: This routine is only run once after compilation.
 1054: 
 1055: =over 4
 1056: 
 1057: =item *
 1058: 
 1059: Initializes %language hash table.
 1060: 
 1061: =back
 1062: 
 1063: =head1 HANDLER SUBROUTINE
 1064: 
 1065: This routine is called by Apache and mod_perl.
 1066: 
 1067: =over 4
 1068: 
 1069: =item *
 1070: 
 1071: read in machine configuration variables
 1072: 
 1073: =item *
 1074: 
 1075: see if called from an interactive mode
 1076: 
 1077: =item *
 1078: 
 1079: refresh environment with user database values (in %hash)
 1080: 
 1081: =item *
 1082: 
 1083: define extra fields and buttons in case of special mode
 1084: 
 1085: =item *
 1086: 
 1087: set catalogmodefunctions to have extra needed javascript functionality
 1088: 
 1089: =item *
 1090: 
 1091: print header
 1092: 
 1093: =item *
 1094: 
 1095: evaluate actions from previous page (both cumulatively and chronologically)
 1096: 
 1097: =item *
 1098: 
 1099: output title
 1100: 
 1101: =item *
 1102: 
 1103: get state of file attributes to be showing
 1104: 
 1105: =item *
 1106: 
 1107: output state of file attributes to be showing
 1108: 
 1109: =item *
 1110: 
 1111: output starting row to the indexed file/directory hierarchy
 1112: 
 1113: =item *
 1114: 
 1115: read in what directories have previously been set to "open"
 1116: 
 1117: =item *
 1118: 
 1119: if not at top level, provide an uplink arrow
 1120: 
 1121: =item *
 1122: 
 1123: recursively go through all the directories and output as appropriate
 1124: 
 1125: =item *
 1126: 
 1127: information useful for group import
 1128: 
 1129: =item *
 1130: 
 1131: end the tables
 1132: 
 1133: =item *
 1134: 
 1135: end the output and return
 1136: 
 1137: =back
 1138: 
 1139: =head1 OTHER SUBROUTINES
 1140: 
 1141: =over 4
 1142: 
 1143: =item *
 1144: 
 1145: scanDir - recursive scan of a directory
 1146: 
 1147: =item *
 1148: 
 1149: get_list - get complete matched list based on the uri (returns an array)
 1150: 
 1151: =item *
 1152: 
 1153: match_ext - filters out files based on extensions (returns an array)
 1154: 
 1155: =item *
 1156: 
 1157: display_line - displays one line in appropriate table format
 1158: 
 1159: =item *
 1160: 
 1161: begin_form - prints the beginning of a form for directory or file link
 1162: 
 1163: =item *
 1164: 
 1165: start_fresh_session - settings whenever the user causes the indexer window
 1166: to be launched
 1167: 
 1168: =back
 1169: 
 1170: =cut

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