File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.113: download - view: text, annotated - select for diffs
Thu Jun 17 18:22:13 2004 UTC (20 years ago) by www
Branches: MAIN
CVS tags: HEAD
"People who got this also get that" now works. Still needs stats.

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

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