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

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

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