File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.117: download - view: text, annotated - select for diffs
Tue Jun 22 13:27:51 2004 UTC (20 years ago) by www
Branches: MAIN
CVS tags: HEAD
Also read dynamic metadata for resources inside sequences and pages.

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

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