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

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

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