File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.127: download - view: text, annotated - select for diffs
Thu Oct 21 09:53:44 2004 UTC (19 years, 8 months ago) by foxr
Branches: MAIN
CVS tags: HEAD
Move javascript_escape into loncommon.pm per Guy's good suggestion.

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

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