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

1.1       www         1: # The LearningOnline Network with CAPA
1.24      harris41    2: # Directory Indexer
                      3: #
1.93    ! albertel    4: # $Id: lonindexer.pm,v 1.92 2004/02/17 02:43:40 taceyjo1 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.87      www        57: my %hash; # global user-specific gdbm file
1.17      harris41   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;
1.87      www       119: 	if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_READER(),0640)) {
1.68      albertel  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.91      taceyjo1  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.90      taceyjo1  190: 	#&Apache::lonxml::debug("mode=$mode form=$form element=$element titleelement=$titleelement");
1.17      harris41  191: # ------ set catalogmodefunctions to have extra needed javascript functionality
1.15      harris41  192: 	my $catalogmodefunctions='';
                    193: 	if ($ENV{'form.catalogmode'} eq 'interactive' or
                    194: 	    $ENV{'form.catalogmode'} eq 'groupimport') {
1.35      matthew   195: 	    # The if statement below sets us up to use the old version
                    196: 	    # by default (ie. if $mode is undefined).  This is the easy
                    197: 	    # way out.  Hopefully in the future I'll find a way to get 
                    198: 	    # the calls dealt with in a more comprehensive manner.
1.41      www       199: 
                    200: #
                    201: # There is now also mode "simple", which is for the simple version of the rat
                    202: #
                    203: #
1.39      matthew   204: 	    if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
1.40      matthew   205:                 my $location = "/adm/groupsort?catalogmode=groupimport&";
1.41      www       206:                 $location .= "mode=".$mode."&";
1.40      matthew   207:                 $location .= "acts=";
1.35      matthew   208: 		$catalogmodefunctions=<<"END";
1.7       harris41  209: function select_data(title,url) {
                    210:     changeTitle(title);
                    211:     changeURL(url);
1.8       harris41  212:     self.close();
                    213: }
                    214: function select_group() {
1.40      matthew   215:     window.location="$location"+document.forms.fileattr.acts.value;
1.16      harris41  216: }
1.7       harris41  217: function changeTitle(val) {
1.35      matthew   218:     if (opener.inf) {
                    219:         if (opener.inf.document.forms.resinfo.elements.t) {
                    220:             opener.inf.document.forms.resinfo.elements.t.value=val;
                    221:         }
                    222:     }
                    223: }
                    224: function changeURL(val) {
                    225:     if (opener.inf) {
                    226:         if (opener.inf.document.forms.resinfo.elements.u) {
                    227: 	    opener.inf.document.forms.resinfo.elements.u.value=val;
                    228:         }
1.7       harris41  229:     }
                    230: }
1.35      matthew   231: END
1.39      matthew   232:             } elsif ($mode eq 'edit') { # we are in 'edit' mode
1.40      matthew   233:                 my $location = "/adm/groupsort?catalogmode=interactive&";
                    234:                 $location .= "form=$form&element=$element&mode=edit&acts=";
1.35      matthew   235: 		$catalogmodefunctions=<<END;
                    236: // mode = $mode
                    237: function select_data(title,url) {
                    238:     changeURL(url);
1.79      albertel  239:     changeTitle(title);
1.35      matthew   240:     self.close();
                    241: }
                    242: 
                    243: function select_group() {
1.40      matthew   244:     window.location="$location"+document.forms.fileattr.acts.value;
1.35      matthew   245: }
                    246: 
1.7       harris41  247: function changeURL(val) {
1.35      matthew   248:     if (window.opener.document) {
                    249: 	window.opener.document.forms["$form"].elements["$element"].value=val;
                    250:     } else {
                    251: 	    alert("The file you selected is: "+val);
1.7       harris41  252:     }
                    253: }
                    254: END
1.79      albertel  255:                 if (!$titleelement) {
                    256: 		    $catalogmodefunctions.='function changeTitle(val) {}';
                    257: 		} else {
                    258: 		    $catalogmodefunctions.=<<END;
                    259: function changeTitle(val) {
                    260:     if (window.opener.document) {
                    261: 	    window.opener.document.forms["$form"].elements["$titleelement"].value=val;
                    262:     } else {
                    263: 	    alert("The title of the file you selected is: "+val);
                    264:     }
                    265: }
                    266: END
                    267:                 }
1.39      matthew   268:             } elsif ($mode eq 'parmset') {
1.40      matthew   269:                 my $location = "/adm/groupsort?catalogmode=interactive&";
                    270:                 $location .= "form=$form&element=$element&mode=parmset&acts=";
1.39      matthew   271: 		$catalogmodefunctions=<<END;
                    272: // mode = $mode
                    273: function select_data(title,url) {
                    274:     changeURL(url);
                    275:     self.close();
                    276: }
                    277: 
                    278: function select_group() {
1.40      matthew   279:     window.location="$location"+document.forms.fileattr.acts.value;
1.39      matthew   280: }
                    281: 
                    282: function changeURL(val) {
                    283:     if (window.opener.document) {
                    284:         var elementname  = "$element"+"_value";
                    285:         var checkboxname = "$element"+"_setparmval";
                    286: 	window.opener.document.forms["$form"].elements[elementname].value=val;
                    287:         window.opener.document.forms["$form"].elements[checkboxname].checked=true;
                    288:     } else {
                    289: 	    alert("The file you selected is: "+val);
                    290:     }
                    291: }
                    292: 
                    293: END
                    294:             }
1.15      harris41  295:         }
1.38      matthew   296:         $catalogmodefunctions.=<<END;
                    297: var acts='';
                    298: function rep_dirpath(suffix,val) {
                    299:     eval("document.forms.dirpath"+suffix+".acts.value=val");
                    300: }
                    301: END
1.16      harris41  302: 	if ($ENV{'form.catalogmode'} eq 'groupimport') {
1.38      matthew   303:             $catalogmodefunctions.=<<END;
1.16      harris41  304: function queue(val) {
                    305:     if (eval("document.forms."+val+".filelink.checked")) {
                    306: 	var l=val.length;
                    307: 	var v=val.substring(4,l);
                    308: 	document.forms.fileattr.acts.value+='1a'+v+'b';
                    309:     }
                    310:     else {
                    311: 	var l=val.length;
                    312: 	var v=val.substring(4,l);
                    313: 	document.forms.fileattr.acts.value+='0a'+v+'b';
                    314:     }
                    315: }
                    316: END
                    317: 	}
1.17      harris41  318: 
1.1       www       319: # ---------------------------------------------------------------- Print Header
1.15      harris41  320: 	$r->print(<<ENDHEADER);
1.1       www       321: <html>
                    322: <head>
1.2       harris41  323: <title>The LearningOnline Network With CAPA Directory Browser</title>
1.3       harris41  324: 
1.19      harris41  325: <script type="text/javascript">
1.7       harris41  326: $catalogmodefunctions
1.69      www       327: function openWindow(url, wdwName, w, h, toolbar,scrollbar,locationbar) {
1.71      ng        328:     var xpos = (screen.width-w)/2;
                    329:     xpos = (xpos < 0) ? '0' : xpos;
                    330:     var ypos = (screen.height-h)/2-30;
                    331:     ypos = (ypos < 0) ? '0' : ypos;
                    332:     var options = "width=" + w + ",height=" + h + ",screenx="+xpos+",screeny="+ypos+",";
1.2       harris41  333:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
1.69      www       334:     options += "menubar=no,toolbar="+toolbar+",location="+locationbar+",directories=no";
1.2       harris41  335:     var newWin = window.open(url, wdwName, options);
                    336:     newWin.focus();
                    337: }
1.16      harris41  338: function gothere(val) {
                    339:     window.location=val+'?acts='+document.forms.fileattr.acts.value;
                    340: }
1.14      harris41  341: </script>
1.3       harris41  342: 
1.1       www       343: </head>
                    344: ENDHEADER
1.74      www       345: my ($headerdom)=($uri=~/^\/res\/(\w+)\//);
                    346: $r->print(&Apache::loncommon::bodytag('Browse Resources',undef,undef,undef,
                    347: 				      $headerdom));
1.17      harris41  348: # - Evaluate actions from previous page (both cumulatively and chronologically)
1.16      harris41  349:         if ($ENV{'form.catalogmode'} eq 'groupimport') {
                    350: 	    my $acts=$ENV{'form.acts'};
                    351: 	    my @Acts=split(/b/,$acts);
                    352: 	    my %ahash;
                    353: 	    my %achash;
                    354: 	    my $ac=0;
1.17      harris41  355: 	    # some initial hashes for working with data
1.27      harris41  356: 	    foreach (@Acts) {
1.16      harris41  357: 		my ($state,$ref)=split(/a/);
                    358: 		$ahash{$ref}=$state;
                    359: 		$achash{$ref}=$ac;
                    360: 		$ac++;
1.27      harris41  361: 	    }
1.87      www       362: 	    # sorting through the actions and changing the global database hash
1.27      harris41  363: 	    foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
1.16      harris41  364: 		my $key=$_;
                    365: 		if ($ahash{$key} eq '1') {
                    366: 		    $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
                    367: 			$hash{'pre_'.$key.'_title'};
                    368: 		    $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
                    369: 			$hash{'storectr'}+0;
                    370: 		    $hash{'storectr'}++;
                    371: 		}
                    372: 		if ($ahash{$key} eq '0') {
                    373: 		    if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
                    374: 			delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
                    375: 		    }
                    376: 		}
1.27      harris41  377: 	    }
1.17      harris41  378: 	    # deleting the previously cached listing
1.27      harris41  379: 	    foreach (keys %hash) {
1.16      harris41  380: 		if ($_ =~ /^pre_/ && $_ =~/link$/) {
                    381: 		    my $key = $_;
                    382: 		    $key =~ s/^pre_//;
                    383: 		    $key =~ s/_[^_]*$//;
                    384: 		    delete $hash{'pre_'.$key.'_title'};
                    385: 		    delete $hash{'pre_'.$key.'_link'};
                    386: 		}
1.27      harris41  387: 	    }
1.16      harris41  388: 	}
                    389: 	
1.23      harris41  390: # ---------------------------------- get state of file attributes to be showing
1.87      www       391: 	if ($ENV{'form.attrs'}) {
1.70      ng        392: 	    for (my $i=0; $i<=9; $i++) {
1.6       harris41  393: 		delete $hash{'display_attrs_'.$i};
                    394: 		if ($ENV{'form.attr'.$i} == 1) {
1.45      ng        395: 		    $attrchk[$i] = 'checked';
1.6       harris41  396: 		    $hash{'display_attrs_'.$i} = 1;
                    397: 		}
                    398: 	    }
                    399: 	} else {
1.70      ng        400: 	    for (my $i=0; $i<=9; $i++) {
1.45      ng        401: 		$attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;
1.6       harris41  402: 	    }
                    403: 	}
1.87      www       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.87      www       427: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] onClick="this.form.submit();" /> $lt{'ti'}</td>
                    428: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] onClick="this.form.submit();" /> $lt{'si'}</td>
                    429: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] onClick="this.form.submit();" /> $lt{'la'}</td>
                    430: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] onClick="this.form.submit();" /> $lt{'lm'}</td>
                    431: <td><input type="checkbox" name="attr8" value="1" $attrchk[8] onClick="this.form.submit();" /> $lt{'st'}</td>
1.77      www       432: </tr><tr>
1.87      www       433: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] onClick="this.form.submit();" /> $lt{'au'}</td>
                    434: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] onClick="this.form.submit();" /> $lt{'kw'}</td>
                    435: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] onClick="this.form.submit();" /> $lt{'ln'}</td>
                    436: <td><input type="checkbox" name="attr7" value="1" $attrchk[7] onClick="this.form.submit();" /> $lt{'sr'}</td>
                    437: <td><input type="checkbox" name="attr9" value="1" $attrchk[9] onClick="this.form.submit();" /> $lt{'av'}</td>
1.63      ng        438: <td>&nbsp;</td>
1.1       www       439: </tr></table>
1.87      www       440: <input type="hidden" name="attrs" value="1" />
                    441: <input type="submit" name="updatedisplay" value="$lt{'ud'}" />
1.16      harris41  442: <input type="hidden" name="acts" value="" />
1.87      www       443: $closebutton $groupimportbutton
1.1       www       444: END
1.82      www       445: # ---------------------------------------------------------------- Bread crumbs
1.87      www       446:         $r->print(&Apache::lonhtmlcommon::crumbs($uri,'','',
                    447: 				(($ENV{'form.catalogmode'} eq 'groupimport')?
                    448: 				 'document.forms.fileattr':'')).
                    449: 		  &Apache::lonhtmlcommon::select_recent('residx','resrecent',
                    450: 'this.form.action=this.form.resrecent.options[this.form.resrecent.selectedIndex].value;this.form.submit();').
                    451: 		  '</form>');
1.85      www       452: # ------------------------------------------------------ Remember where we were
                    453: 	&Apache::loncommon::storeresurl($uri);
1.87      www       454: 	&Apache::lonhtmlcommon::store_recent('residx',$uri,$uri);
1.23      harris41  455: # ----------------- output starting row to the indexed file/directory hierarchy
1.15      harris41  456:         my $titleclr="#ddffff";
1.40      matthew   457: #        $r->print(&initdebug());
                    458: #        $r->print(&writedebug("Omit:@Omit")) if (@Omit);
                    459: #        $r->print(&writedebug("Only:@Only")) if (@Only);
1.46      ng        460:         $r->print("<table width='100\%' border=0><tr><td bgcolor=#777777>\n");
1.45      ng        461: 	$r->print("<table width='100\%' border=0><tr bgcolor=$titleclr>\n");
1.77      www       462: 	$r->print("<td $colspan><b>".&mt('Name')."</b></td>\n");
                    463: 	$r->print("<td><b>".&mt('Title')."</b></td>\n") 
1.45      ng        464: 	    if ($hash{'display_attrs_0'} == 1);
1.77      www       465: 	$r->print("<td align=right><b>".&mt("Size")." (".&mt("bytes").") ".
1.45      ng        466: 		  "</b></td>\n") if ($hash{'display_attrs_1'} == 1);
1.77      www       467: 	$r->print("<td><b>".&mt("Last accessed")."</b></td>\n") 
1.17      harris41  468: 	    if ($hash{'display_attrs_2'} == 1);
1.77      www       469: 	$r->print("<td><b>".&mt("Last modified")."</b></td>\n")
1.17      harris41  470: 	    if ($hash{'display_attrs_3'} == 1);
1.77      www       471: 	$r->print("<td><b>".&mt("Author(s)")."</b></td>\n")
1.17      harris41  472: 	    if ($hash{'display_attrs_4'} == 1);
1.77      www       473: 	$r->print("<td><b>".&mt("Keywords")."</b></td>\n")
1.17      harris41  474: 	    if ($hash{'display_attrs_5'} == 1);
1.77      www       475: 	$r->print("<td><b>".&mt("Language")."</b></td>\n")
1.45      ng        476: 	    if ($hash{'display_attrs_6'} == 1);
1.77      www       477: 	$r->print("<td><b>".&mt("Resource")."</b></td>\n")
1.63      ng        478: 	    if ($hash{'display_attrs_7'} == 1);
1.77      www       479: 	$r->print("<td><b>".&mt("Usage Statistics")." <br />(".
                    480: 		  &mt("Courses/Network Hits").")</b></td>\n")
1.70      ng        481: 	    if ($hash{'display_attrs_8'} == 1);
1.45      ng        482: 	$r->print('</tr>');
1.5       harris41  483: 
1.23      harris41  484: # ----------------- read in what directories have previously been set to "open"
1.27      harris41  485: 	foreach (keys %hash) {
1.4       harris41  486: 	    if ($_ =~ /^diropen_status_/) {
                    487: 		my $key = $_;
                    488: 		$key =~ s/^diropen_status_//;
                    489: 		$dirs{$key} = $hash{$_};
                    490: 	    }
1.27      harris41  491: 	}
1.4       harris41  492: 
1.2       harris41  493: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
                    494: 	    my $uri=$ENV{'form.openuri'};
1.4       harris41  495: 	    if (exists($hash{'diropen_status_'.$uri})) {
                    496: 		my $cursta = $hash{'diropen_status_'.$uri};
1.2       harris41  497: 		$dirs{$uri} = 'open';
1.4       harris41  498: 		$hash{'diropen_status_'.$uri} = 'open';
                    499: 		if ($cursta eq 'open') {
                    500: 		    $dirs{$uri} = 'closed';
                    501: 		    $hash{'diropen_status_'.$uri} = 'closed';
                    502: 		}
1.2       harris41  503: 	    } else {
1.4       harris41  504: 		$hash{'diropen_status_'.$uri} = 'open';
1.2       harris41  505: 		$dirs{$uri} = 'open';
                    506: 	    }
                    507: 	}
1.12      ng        508: 	
                    509: 	my $toplevel;
1.13      ng        510: 	my $indent = 0;
1.12      ng        511: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
1.17      harris41  512: 
1.88      www       513:  	if ($ENV{'form.dirPointer'} ne 'on') {
                    514:  	    $hash{'top.level'} = $uri;
                    515:  	    $toplevel = $uri;
                    516:  	} else {
                    517:  	    $toplevel = $hash{'top.level'};
                    518:  	}
1.17      harris41  519: 
1.23      harris41  520: # -------------------------------- if not at top level, provide an uplink arrow
1.45      ng        521: 	if ($toplevel ne '/res/'){
1.13      ng        522: 	    my (@uri_com) = split(/\//,$uri);
                    523: 	    pop @uri_com;
                    524: 	    my $upone = join('/',@uri_com);
                    525: 	    my @list = qw (0);
                    526: 	    &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
                    527: 	    $indent = 1;
1.12      ng        528: 	}
1.17      harris41  529: 
1.23      harris41  530: # -------- recursively go through all the directories and output as appropriate
1.16      harris41  531: 	&scanDir ($r,$toplevel,$indent,\%hash);
1.12      ng        532: 	
1.23      harris41  533: # ---------------------------- embed hidden information useful for group import
1.8       harris41  534: 	$r->print("<form name='fnum'>");
                    535: 	$r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
1.17      harris41  536: 
1.23      harris41  537: # -------------------------------------------------------------- end the tables
1.45      ng        538: 	$r->print('</table>');
                    539: 	$r->print('</td></tr></table>');
1.17      harris41  540: 
1.23      harris41  541: # --------------------------------------------------- end the output and return
1.45      ng        542: 	$r->print('</body></html>'."\n");
1.2       harris41  543:     }
1.67      matthew   544:     if(! $c->aborted()) {
1.87      www       545: # write back into the temporary file
1.68      albertel  546: 	my %dbfile;
1.67      matthew   547:         if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_NEWDB(),0640)) {
                    548:             while (my($key,$value) = each(%hash)) {
                    549:                 $dbfile{$key}=$value;
                    550:             }
                    551:             untie(%dbfile);
                    552:         }
                    553:     }
                    554: 
1.1       www       555:     return OK;
                    556: }
1.2       harris41  557: 
1.17      harris41  558: # ----------------------------------------------- recursive scan of a directory
1.2       harris41  559: sub scanDir {
1.16      harris41  560:     my ($r,$startdir,$indent,$hashref)=@_;
1.67      matthew   561:     my $c = $r->connection();
1.3       harris41  562:     my ($compuri,$curdir);
                    563:     my $dirptr=16384;
1.90      taceyjo1  564:     my $obs;
1.1       www       565:     $indent++;
1.2       harris41  566:     my %dupdirs = %dirs;
                    567:     my @list=&get_list($r,$startdir);
                    568:     foreach my $line (@list) {
1.67      matthew   569:         return if ($c->aborted());
1.90      taceyjo1  570: 	#This is a kludge, sorry aboot this
1.92      taceyjo1  571: 	my ($strip,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
1.90      taceyjo1  572: 	next if($strip =~ /.*\.meta$/ | $obs eq '1');
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.87      www       613:     if ($ENV{'form.updatedisplay'}) {
1.27      harris41  614: 	foreach (keys %hash) {
1.4       harris41  615: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
1.87      www       616: 	}
1.2       harris41  617:     }
                    618: 
1.87      www       619:     if ($hash{'dirlist_files_'.$luri}) {
1.4       harris41  620: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.1       www       621:     } else {
1.4       harris41  622: 	@list = &Apache::lonnet::dirlist($uri);
1.87      www       623: 	$hash{'dirlist_files_'.$luri} = join("\n",@list);
1.1       www       624:     }
1.91      taceyjo1  625:     return @list=&match_ext($r,@list);
1.1       www       626: }
                    627: 
1.40      matthew   628: sub initdebug {
                    629:     return <<ENDJS;
                    630: <script>
                    631: var debugging = true;
                    632: if (debugging) {
                    633:     var debuggingWindow = window.open('','Debug','width=400,height=300',true);
                    634: } 
                    635: 
                    636: function output(text) {
                    637:     if (debugging) {
                    638:         debuggingWindow.document.writeln(text);
                    639:     }
                    640: }
                    641: output("<html><head><title>Debugging Window</title></head><body><pre>");   
                    642: </script>
                    643: ENDJS
                    644: }
                    645: 
                    646: sub writedebug {
                    647:     my $text = shift;
                    648:     return "<script>output('$text');</script>";
                    649: }
                    650: 
1.17      harris41  651: # -------------------- filters out files based on extensions (returns an array)
1.1       www       652: sub match_ext {
                    653:     my ($r,@packlist)=@_;
                    654:     my @trimlist;
                    655:     my $nextline;
                    656:     my @fileext;
                    657:     my $dirptr=16384;
                    658: 
1.2       harris41  659:     foreach my $line (@packlist) {
                    660: 	chomp $line;
                    661: 	$line =~ s/^\/home\/httpd\/html//;
                    662: 	my @unpackline = split (/\&/,$line);
1.45      ng        663: 	next if ($unpackline[0] eq '.');
                    664: 	next if ($unpackline[0] eq '..');
1.2       harris41  665: 	my @filecom = split (/\./,$unpackline[0]);
                    666: 	my $fext = pop(@filecom);
                    667: 	my $fnptr = $unpackline[3]&$dirptr;
                    668:  	if ($fnptr == 0 and $unpackline[3] ne "") {
1.28      harris41  669: 	    my $embstyle = &Apache::loncommon::fileembstyle($fext);
1.25      matthew   670:             push @trimlist,$line if (defined($embstyle) && 
1.32      harris41  671: 				     ($embstyle ne 'hdn' or $fext eq 'meta'));
1.1       www       672: 	} else {
1.2       harris41  673: 	    push @trimlist,$line;
1.1       www       674: 	}
                    675:     }
1.80      albertel  676:     @trimlist = sort {uc($a) cmp uc($b)} (@trimlist);
1.1       www       677:     return @trimlist;
                    678: }
                    679: 
1.17      harris41  680: # ------------------------------- displays one line in appropriate table format
1.23      harris41  681: sub display_line {
1.16      harris41  682:     my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
1.53      albertel  683:     my (@pathfn, $fndir);
1.1       www       684:     my $dirptr=16384;
                    685:     my $fileclr="#ffffe6";
1.45      ng        686:     my $iconpath= $r->dir_config('lonIconsURL') . '/';
1.1       www       687: 
                    688:     my @filecom = split (/\&/,$line);
                    689:     my @pathcom = split (/\//,$filecom[0]);
                    690:     my $listname = $pathcom[scalar(@pathcom)-1];
                    691:     my $fnptr = $filecom[3]&$dirptr;
1.77      www       692:     my $msg = &mt('View').' '.$filecom[0].' '.&mt('resources');
                    693:     $msg = &mt('Close').' '.$filecom[0].' '.&mt('directory') if $diropen eq 'opened';
1.1       www       694: 
1.45      ng        695:     my $tabtag='</td>';
1.1       www       696:     my $i=0;
1.70      ng        697:     while ($i<=8) {
1.45      ng        698: 	$tabtag=join('',$tabtag,"<td>&nbsp;</td>")
1.17      harris41  699: 	    if $hash{'display_attrs_'.$i} == 1;
1.1       www       700: 	$i++;
                    701:     }
1.63      ng        702: 	
                    703:     my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom');
1.17      harris41  704: 
                    705: # display uplink arrow
1.45      ng        706:     if ($filecom[1] eq 'viewOneUp') {
1.70      ng        707: 	$r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
                    708: 	$r->print("<td>\n");
1.16      harris41  709: 	$r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
                    710: 		   '/" '.
1.17      harris41  711: 		   'onSubmit="return rep_dirpath(\'UP\','.
                    712: 		   'document.forms.fileattr.acts.value)" '.
1.16      harris41  713: 		   'enctype="application/x-www-form-urlencoded"'.
                    714:                    '>'."\n");
1.17      harris41  715: 	$r->print ('<input type=hidden name=openuri value="'.
                    716: 		   $startdir.'">'."\n");
1.16      harris41  717: 	$r->print ('<input type="hidden" name="acts" value="">'."\n");
1.13      ng        718: 	$r->print ('<input src="'.$iconpath.'arrow_up.gif"');
1.17      harris41  719: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    720: 		   "\n");
1.77      www       721: 	$r->print(&mt("Up")." $tabtag</tr></form>\n");
1.13      ng        722: 	return OK;
                    723:     }
1.92      taceyjo1  724: # Do we have permission to look at this? 
1.93    ! albertel  725:     if($filecom[15] ne '1') { return OK if (!&Apache::lonnet::allowed('bre',$startdir.$filecom[0])); }
1.17      harris41  726: 
                    727: # display domain
1.45      ng        728:     if ($filecom[1] eq 'domain') {
1.88      www       729:  	$r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
                    730:  	    if ($ENV{'form.dirPointer'} eq "on");
1.70      ng        731: 	$r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
                    732: 	$r->print("<td>");
1.73      albertel  733: 	&begin_form ($r,$filecom[0]);
                    734: 	my $anchor = $filecom[0];
1.3       harris41  735: 	$anchor =~ s/\///g;
1.13      ng        736: 	$r->print ('<a name="'.$anchor.'">');
1.16      harris41  737: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41  738: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.
                    739: 		   $diropen.'.gif"'); 
                    740: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    741: 		   "\n");
                    742: 	$r->print ('<a href="javascript:gothere(\''.$filecom[0].
1.73      albertel  743: 		   '\')"><img src="'.$iconpath.'server.gif"');
1.17      harris41  744: 	$r->print (' border="0" /></a>'."\n");
1.77      www       745: 	$r->print (&mt("Domain")." - $listname ");
1.60      albertel  746: 	if ($Apache::lonnet::domaindescription{$listname}) {
                    747: 	    $r->print("(".$Apache::lonnet::domaindescription{$listname}.
                    748: 		      ")");
                    749: 	}
                    750: 	$r->print (" $tabtag</tr></form>\n");
1.1       www       751: 	return OK;
1.17      harris41  752: 
                    753: # display user directory
1.1       www       754:     }
1.45      ng        755:     if ($filecom[1] eq 'user') {
1.70      ng        756: 	$r->print("<tr valign=$valign bgcolor=$fileclr>$extrafield");
                    757: 	$r->print("<td nowrap>\n");
1.2       harris41  758: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  759: 	my $anchor = $curdir;
                    760: 	$anchor =~ s/\///g;
1.13      ng        761: 	&begin_form ($r,$curdir);
1.17      harris41  762: 	$r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
                    763: 		   'whitespace1.gif" border="0" />'."\n");
1.16      harris41  764: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41  765: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
                    766: 		   '.gif"'); 
                    767: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    768: 		   "\n");
                    769: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
                    770: 		   $iconpath.'quill.gif border="0" name="'.$msg.
                    771: 		   '" height="22" /></a>');
1.60      albertel  772: 	my $domain=(split(m|/|,$startdir))[2];
                    773: 	my $plainname=&Apache::loncommon::plainname($listname,$domain);
                    774: 	$r->print ($listname);
                    775: 	if (defined($plainname) && $plainname) { $r->print(" ($plainname) "); }
                    776: 	$r->print ($tabtag.'</tr></form>'."\n");
1.1       www       777: 	return OK;
                    778:     }
1.17      harris41  779: 
1.1       www       780: # display file
1.45      ng        781:     if ($fnptr == 0 and $filecom[3] ne '') {
1.47      ng        782: 	my $filelink = $startdir.$filecom[0];
1.1       www       783: 	my @file_ext = split (/\./,$listname);
1.25      matthew   784: 	my $curfext = $file_ext[-1];
1.40      matthew   785:         if (@Omit) {
                    786:             foreach (@Omit) { return OK if ($curfext eq $_); }
                    787:         }
                    788:         if (@Only) {
                    789:             my $skip = 1;
                    790:             foreach (@Only) { $skip = 0 if ($curfext eq $_); }
                    791:             return OK if ($skip > 0);
                    792:         }
1.25      matthew   793: 	# Set the icon for the file
1.84      albertel  794: 	my $iconname = &Apache::loncommon::icon($listname);
1.70      ng        795: 	$r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap>");
1.62      albertel  796: 	my $metafile = grep /^\Q$filecom[0]\E\.meta\&/, @list;
1.7       harris41  797: 	my $title;
                    798:         if ($ENV{'form.catalogmode'} eq 'interactive') {
                    799: 	    $title=$listname;
1.8       harris41  800: 	    $title = &Apache::lonnet::metadata($filelink,'title')
                    801: 		if ($metafile == 1);
1.7       harris41  802: 	    $title=$listname unless $title;
1.42      albertel  803: 	    my $titleesc=HTML::Entities::encode($title);
                    804: 	    $titleesc=~s/\'/\\'/; #' (clean up this spare quote)
1.35      matthew   805:             $r->print("<a href=\"javascript:select_data(\'",
1.34      harris41  806:                       $titleesc,"','",$filelink,"')\">");
1.17      harris41  807: 	    $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
                    808: 		      "\n");
1.70      ng        809: 	    $r->print("</td><td nowrap>");
1.8       harris41  810: 	}
                    811:         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
                    812: 	    $title=$listname;
1.90      taceyjo1  813: 	    #$title = &Apache::lonnet::metadata($filelink,'title')
                    814: 		#if ($metafile == 1);
1.8       harris41  815: 	    $title=$listname unless $title;
1.42      albertel  816: 	    my $titleesc=&HTML::Entities::encode($title);
1.8       harris41  817: 	    $r->print("<form name='form$fnum'>\n");
                    818: 	    $r->print("<input type='checkbox' name='filelink"."' ".
1.16      harris41  819: 		      "value='$filelink' onClick='".
                    820: 		      "javascript:queue(\"form$fnum\")' ");
                    821: 	    if ($hash{'store_'.$filelink}) {
                    822: 		$r->print("checked");
                    823: 	    }
                    824: 	    $r->print(">\n");
1.8       harris41  825: 	    $r->print("<input type='hidden' name='title"."' ".
1.42      albertel  826: 		      "value='$titleesc'>\n");
1.8       harris41  827: 	    $r->print("</form>\n");
1.70      ng        828: 	    $r->print("</td><td nowrap>");
1.16      harris41  829: 	    $hash{"pre_${fnum}_link"}=$filelink;
1.42      albertel  830: 	    $hash{"pre_${fnum}_title"}=$titleesc;
1.8       harris41  831:   	    $fnum++;
1.7       harris41  832: 	}
1.4       harris41  833: 
1.12      ng        834: 	if ($indent > 0 and $indent < 11) {
1.17      harris41  835: 	    $r->print("<img src=",$iconpath,"whitespace",$indent,
                    836: 		      ".gif border='0' />\n");
1.11      ng        837: 	} elsif ($indent >0) {
1.4       harris41  838: 	    my $ten = int($indent/10.);
                    839: 	    my $rem = $indent%10.0;
                    840: 	    my $count = 0;
                    841: 	    while ($count < $ten) {
1.17      harris41  842: 		$r->print("<img src=",$iconpath,
                    843: 			  "whitespace10.gif border='0' />\n");
1.1       www       844: 	    $count++;
1.4       harris41  845: 	    }
1.17      harris41  846: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,
                    847: 		      ".gif border='0' />\n") if $rem > 0;
1.1       www       848: 	}
1.4       harris41  849: 
1.84      albertel  850: 	$r->print("<img src='$iconname' border='0' />\n");
1.17      harris41  851: 	$r->print (" <a href=\"javascript:openWindow('".$filelink.
1.69      www       852: 		   "', 'previewfile', '450', '500', 'no', 'yes','yes')\";".
1.17      harris41  853: 		   " TARGET=_self>$listname</a> ");
                    854: 
                    855: 	$r->print (" (<a href=\"javascript:openWindow('".$filelink.
1.71      ng        856: 		   ".meta', 'metadatafile', '500', '550', 'no', 'yes','no')\"; ".
1.17      harris41  857: 		   "TARGET=_self>metadata</a>) ") if ($metafile == 1);
1.2       harris41  858: 
1.7       harris41  859: 	$r->print("</td>\n");
1.45      ng        860: 	if ($hash{'display_attrs_0'} == 1) {
1.70      ng        861: 	    my $title = &Apache::lonnet::gettitle($filelink,'title')
1.45      ng        862: 		if ($metafile == 1);
1.70      ng        863: 	    $r->print('<td> '.($title eq '' ? '&nbsp;' : $title).
1.45      ng        864: 		      ' </td>'."\n");
                    865: 	}
1.70      ng        866: 	$r->print('<td align=right> ',
1.17      harris41  867: 		  $filecom[8]," </td>\n") 
1.45      ng        868: 	    if $hash{'display_attrs_1'} == 1;
1.70      ng        869: 	$r->print('<td> '.
1.17      harris41  870: 		  (localtime($filecom[9]))." </td>\n") 
1.45      ng        871: 	    if $hash{'display_attrs_2'} == 1;
1.70      ng        872: 	$r->print('<td> '.
1.17      harris41  873: 		  (localtime($filecom[10]))." </td>\n") 
1.45      ng        874: 	    if $hash{'display_attrs_3'} == 1;
1.2       harris41  875: 
1.45      ng        876: 	if ($hash{'display_attrs_4'} == 1) {
1.17      harris41  877: 	    my $author = &Apache::lonnet::metadata($filelink,'author')
                    878: 		if ($metafile == 1);
1.70      ng        879: 	    $r->print('<td> '.($author eq '' ? '&nbsp;' : $author).
1.17      harris41  880: 		      " </td>\n");
1.2       harris41  881: 	}
1.45      ng        882: 	if ($hash{'display_attrs_5'} == 1) {
1.17      harris41  883: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
                    884: 		if ($metafile == 1);
1.45      ng        885: 	    # $keywords = '&nbsp;' if (!$keywords);
1.70      ng        886: 	    $r->print('<td> '.($keywords eq '' ? '&nbsp;' : $keywords).
1.17      harris41  887: 		      " </td>\n");
1.2       harris41  888: 	}
1.45      ng        889: 	if ($hash{'display_attrs_6'} == 1) {
1.17      harris41  890: 	    my $lang = &Apache::lonnet::metadata($filelink,'language')
                    891: 		if ($metafile == 1);
1.28      harris41  892: 	    $lang = &Apache::loncommon::languagedescription($lang);
1.70      ng        893: 	    $r->print('<td> '.($lang eq '' ? '&nbsp;' : $lang).
1.17      harris41  894: 		      " </td>\n");
1.2       harris41  895: 	}
1.63      ng        896:         if ($hash{'display_attrs_7'} == 1) {
1.56      www       897:             my $output='';
1.57      www       898:             my $embstyle=&Apache::loncommon::fileembstyle($curfext);
                    899: 	    if ($embstyle eq 'ssi') {
1.89      www       900: 		my $cache=$Apache::lonnet::perlvar{'lonDocRoot'}.$filelink.
                    901: 		    '.tmp';
                    902: 		if ((!$ENV{'form.updatedisplay'}) &&
                    903: 		    (-e $cache)) {
                    904: 		    open(FH,$cache);
                    905: 		    $output=join("\n",<FH>);
                    906: 		    close(FH);
                    907: 		} else {
                    908: 		    $output=&Apache::lonnet::ssi_body($filelink);
                    909: 		    open(FH,">$cache");
                    910: 		    print FH $output;
                    911: 		    close(FH);
                    912: 		}
                    913: 		$output='<font size="-2">'.$output.'</font>';
1.57      www       914: 	   } elsif ($embstyle eq 'img') {
                    915:                $output='<img src="'.$filelink.'" />';
1.58      www       916:            } elsif ($filelink=~/^\/res\/(\w+)\/(\w+)\//) {
                    917:                $output='<img src="http://'.
                    918: 		 $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}.
                    919:                  '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
1.57      www       920:            }
1.70      ng        921: 	   $r->print('<td> '.($output eq '' ? '&nbsp;':$output).
1.56      www       922: 		      " </td>\n");
                    923:         }
1.70      ng        924: 	if ($hash{'display_attrs_8'} == 1) {
                    925: 	    my (%stat) = &Apache::lonmeta::dynamicmeta($filelink) if ($metafile == 1);
1.71      ng        926: 	    my $stat = (exists($stat{'course'}) ? $stat{'course'} : '').
                    927: 		((exists($stat{'course'}) || exists($stat{'count'})) ? '/' : '').
                    928: 		(exists($stat{'count'}) ? $stat{'count'} : '');
1.70      ng        929: 	    $r->print('<td align=center> '.($stat eq '' ? '&nbsp;' : $stat).
                    930: 		      ' </td>'."\n");
                    931: 	}
                    932: 
1.1       www       933: 	$r->print("</tr>\n");
                    934:     }
1.17      harris41  935: 
1.2       harris41  936: # -- display directory
1.1       www       937:     if ($fnptr == $dirptr) {
1.2       harris41  938: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  939: 	my $anchor = $curdir;
                    940: 	$anchor =~ s/\///g;
1.63      ng        941: 	$r->print("<tr bgcolor=$fileclr>$extrafield<td valign=$valign>");
1.2       harris41  942: 	&begin_form ($r,$curdir);
1.4       harris41  943: 	my $indentm1 = $indent-1;
1.11      ng        944: 	if ($indentm1 < 11 and $indentm1 > 0) {
1.17      harris41  945: 	    $r->print("<img src=",$iconpath,"whitespace",$indentm1,
                    946: 		      ".gif border='0' />\n");
1.4       harris41  947: 	} else {
                    948: 	    my $ten = int($indentm1/10.);
                    949: 	    my $rem = $indentm1%10.0;
                    950: 	    my $count = 0;
                    951: 	    while ($count < $ten) {
1.17      harris41  952: 		$r->print ("<img src=",$iconpath
                    953: 			   ,"whitespace10.gif border='0' />\n");
1.12      ng        954: 		$count++;
1.4       harris41  955: 	    }
1.17      harris41  956: 	    $r->print ("<img src=",$iconpath,"whitespace",$rem,
                    957: 		       ".gif border='0' />\n") if $rem > 0;
1.1       www       958: 	}
1.16      harris41  959: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41  960: 	$r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
                    961: 		   'folder_pointer_'.$diropen.'.gif"');
                    962: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    963: 		   "\n");
                    964: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
                    965: 		   $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
                    966: 		   "\n");
1.86      www       967: 	$r->print ("$listname</td>\n");
                    968: # Attributes
                    969: 	my $filelink = $startdir.$filecom[0].'/default';
                    970: 
                    971: 	if ($hash{'display_attrs_0'} == 1) {
                    972: 	    my $title = &Apache::lonnet::gettitle($filelink,'title');
                    973: 	    $r->print('<td> '.($title eq '' ? '&nbsp;' : $title).
                    974: 		      ' </td>'."\n");
                    975: 	}
                    976: 	$r->print('<td align=right> ',
                    977: 		  $filecom[8]," </td>\n") 
                    978: 	    if $hash{'display_attrs_1'} == 1;
                    979: 	$r->print('<td> '.
                    980: 		  (localtime($filecom[9]))." </td>\n") 
                    981: 	    if $hash{'display_attrs_2'} == 1;
                    982: 	$r->print('<td> '.
                    983: 		  (localtime($filecom[10]))." </td>\n") 
                    984: 	    if $hash{'display_attrs_3'} == 1;
                    985: 
                    986: 	if ($hash{'display_attrs_4'} == 1) {
                    987: 	    my $author = &Apache::lonnet::metadata($filelink,'author');
                    988: 	    $r->print('<td> '.($author eq '' ? '&nbsp;' : $author).
                    989: 		      " </td>\n");
                    990: 	}
                    991: 	if ($hash{'display_attrs_5'} == 1) {
                    992: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
                    993: 	    # $keywords = '&nbsp;' if (!$keywords);
                    994: 	    $r->print('<td> '.($keywords eq '' ? '&nbsp;' : $keywords).
                    995: 		      " </td>\n");
                    996: 	}
                    997: 	if ($hash{'display_attrs_6'} == 1) {
                    998: 	    my $lang = &Apache::lonnet::metadata($filelink,'language');
                    999: 	    $lang = &Apache::loncommon::languagedescription($lang);
                   1000: 	    $r->print('<td> '.($lang eq '' ? '&nbsp;' : $lang).
                   1001: 		      " </td>\n");
                   1002: 	}
                   1003:         if ($hash{'display_attrs_7'} == 1) {
                   1004: 	   $r->print('<td>&nbsp;</td>');
                   1005:         }
                   1006: 	if ($hash{'display_attrs_8'} == 1) {
                   1007: 	   $r->print('<td>&nbsp;</td>');
                   1008: 	}
                   1009: 	$r->print('</form></tr>');
1.1       www      1010:     }
1.2       harris41 1011: 
1.1       www      1012: }
                   1013: 
1.14      harris41 1014: # ------------------- prints the beginning of a form for directory or file link
1.1       www      1015: sub begin_form {
                   1016:     my ($r,$uri) = @_;
1.3       harris41 1017:     my $anchor = $uri;
                   1018:     $anchor =~ s/\///g;
1.17      harris41 1019:     $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
                   1020: 	       '#'.$anchor.
                   1021: 	       '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
                   1022: 	       ',document.forms.fileattr.acts.value)" '.
1.16      harris41 1023: 	       'enctype="application/x-www-form-urlencoded">'."\n");
1.17      harris41 1024:     $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
                   1025: 	       "\n");
1.88      www      1026:     $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16      harris41 1027:     $dnum++;
1.17      harris41 1028: }
                   1029: 
                   1030: # --------- settings whenever the user causes the indexer window to be launched
                   1031: sub start_fresh_session {
1.48      matthew  1032:     delete $hash{'form.catalogmode'};
                   1033:     delete $hash{'form.mode'};
                   1034:     delete $hash{'form.form'};
                   1035:     delete $hash{'form.element'};
                   1036:     delete $hash{'form.omit'};
                   1037:     delete $hash{'form.only'};
1.27      harris41 1038:     foreach (keys %hash) {
1.48      matthew  1039:         delete $hash{$_} if (/^(pre_|store)/);
1.27      harris41 1040:     }
1.1       www      1041: }
                   1042: 
1.35      matthew  1043: # ------------------------------------------------------------------- setvalues
                   1044: sub setvalues {
                   1045:     # setvalues is used in registerurl to synchronize the database
                   1046:     # hash and environment hashes
                   1047:     my ($H1,$h1key,$H2,$h2key) =@_;
                   1048:     #
                   1049:     if (exists $H2->{$h2key}) {
                   1050: 	$H1->{$h1key} = $H2->{$h2key};
                   1051:     } elsif (exists $H1->{$h1key}) {
                   1052: 	$H2->{$h2key} = $H1->{$h1key};
                   1053:     } 
                   1054: }
                   1055: 
1.1       www      1056: 1;
1.54      www      1057: 
                   1058: sub cleanup {
1.55      www      1059:     if (tied(%hash)){
                   1060: 	&Apache::lonnet::logthis('Cleanup indexer: hash');
                   1061:     }
1.54      www      1062: }
1.23      harris41 1063: 
                   1064: =head1 NAME
                   1065: 
                   1066: Apache::lonindexer - mod_perl module for cross server filesystem browsing
                   1067: 
                   1068: =head1 SYNOPSIS
                   1069: 
                   1070: Invoked by /etc/httpd/conf/srm.conf:
                   1071: 
                   1072:  <LocationMatch "^/res.*/$">
                   1073:  SetHandler perl-script
                   1074:  PerlHandler Apache::lonindexer
                   1075:  </LocationMatch>
                   1076: 
                   1077: =head1 INTRODUCTION
                   1078: 
                   1079: This module enables a scheme of browsing across a cross server.
                   1080: 
                   1081: This is part of the LearningOnline Network with CAPA project
                   1082: described at http://www.lon-capa.org.
                   1083: 
                   1084: =head1 BEGIN SUBROUTINE
                   1085: 
                   1086: This routine is only run once after compilation.
                   1087: 
                   1088: =over 4
                   1089: 
                   1090: =item *
                   1091: 
                   1092: Initializes %language hash table.
                   1093: 
                   1094: =back
                   1095: 
                   1096: =head1 HANDLER SUBROUTINE
                   1097: 
                   1098: This routine is called by Apache and mod_perl.
                   1099: 
                   1100: =over 4
                   1101: 
                   1102: =item *
                   1103: 
                   1104: read in machine configuration variables
                   1105: 
                   1106: =item *
                   1107: 
                   1108: see if called from an interactive mode
                   1109: 
                   1110: =item *
                   1111: 
                   1112: refresh environment with user database values (in %hash)
                   1113: 
                   1114: =item *
                   1115: 
                   1116: define extra fields and buttons in case of special mode
                   1117: 
                   1118: =item *
                   1119: 
                   1120: set catalogmodefunctions to have extra needed javascript functionality
                   1121: 
                   1122: =item *
                   1123: 
                   1124: print header
                   1125: 
                   1126: =item *
                   1127: 
                   1128: evaluate actions from previous page (both cumulatively and chronologically)
                   1129: 
                   1130: =item *
                   1131: 
                   1132: output title
                   1133: 
                   1134: =item *
                   1135: 
                   1136: get state of file attributes to be showing
                   1137: 
                   1138: =item *
                   1139: 
                   1140: output state of file attributes to be showing
                   1141: 
                   1142: =item *
                   1143: 
                   1144: output starting row to the indexed file/directory hierarchy
                   1145: 
                   1146: =item *
                   1147: 
                   1148: read in what directories have previously been set to "open"
                   1149: 
                   1150: =item *
                   1151: 
                   1152: if not at top level, provide an uplink arrow
                   1153: 
                   1154: =item *
                   1155: 
                   1156: recursively go through all the directories and output as appropriate
                   1157: 
                   1158: =item *
                   1159: 
                   1160: information useful for group import
                   1161: 
                   1162: =item *
                   1163: 
                   1164: end the tables
                   1165: 
                   1166: =item *
                   1167: 
                   1168: end the output and return
                   1169: 
                   1170: =back
                   1171: 
                   1172: =head1 OTHER SUBROUTINES
                   1173: 
                   1174: =over 4
                   1175: 
                   1176: =item *
                   1177: 
                   1178: scanDir - recursive scan of a directory
                   1179: 
                   1180: =item *
                   1181: 
                   1182: get_list - get complete matched list based on the uri (returns an array)
                   1183: 
                   1184: =item *
                   1185: 
                   1186: match_ext - filters out files based on extensions (returns an array)
                   1187: 
                   1188: =item *
                   1189: 
                   1190: display_line - displays one line in appropriate table format
                   1191: 
                   1192: =item *
                   1193: 
                   1194: begin_form - prints the beginning of a form for directory or file link
                   1195: 
                   1196: =item *
                   1197: 
                   1198: start_fresh_session - settings whenever the user causes the indexer window
                   1199: to be launched
                   1200: 
                   1201: =back
                   1202: 
                   1203: =cut

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