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

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

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