Annotation of loncom/interface/lonindexer.pm, revision 1.78

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

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