File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.106: download - view: text, annotated - select for diffs
Tue May 11 13:22:41 2004 UTC (20 years, 1 month ago) by matthew
Branches: MAIN
CVS tags: HEAD
I like code that compiles.

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

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