File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.82: download - view: text, annotated - select for diffs
Mon Dec 22 18:58:26 2003 UTC (20 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bread crumbs on top of lonindexer.

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

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