File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.128: download - view: text, annotated - select for diffs
Thu Oct 21 11:18:41 2004 UTC (19 years, 8 months ago) by foxr
Branches: MAIN
CVS tags: version_1_3_X, version_1_3_3, version_1_3_2, version_1_3_1, version_1_3_0, version_1_2_99_1, version_1_2_99_0, HEAD
Changed javascript_escape calls to escape_single.  I think this module
may be pretty well funky URL clean.

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

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