File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.148: download - view: text, annotated - select for diffs
Fri Jun 23 07:32:02 2006 UTC (17 years, 11 months ago) by www
Branches: MAIN
CVS tags: version_2_1_99_0, HEAD
Show me if I am already using a resource in a course

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

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