File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.109: download - view: text, annotated - select for diffs
Sat Jun 12 01:08:11 2004 UTC (20 years ago) by taceyjo1
Branches: MAIN
CVS tags: HEAD
More of bug #78 you can now view the code and comming soon copy it to a directory in your construction space (which is proving to be slightly
more hard than expected)

Anyway

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

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