File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.137: download - view: text, annotated - select for diffs
Mon Nov 14 23:17:12 2005 UTC (18 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_2, version_2_1_1, version_2_1_0, version_2_0_99_1, HEAD
- figured out how to stop forms from casuing extra newlines in Standards Compliance mode in mozilla/firefox

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

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