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

1.1       www         1: # The LearningOnline Network with CAPA
1.24      harris41    2: # Directory Indexer
                      3: #
1.32    ! harris41    4: # $Id: lonindexer.pm,v 1.31 2002/01/06 01:29:52 harris41 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.23      harris41   46: #
                     47: ###
                     48: 
                     49: ###############################################################################
                     50: ##                                                                           ##
                     51: ## ORGANIZATION OF THIS PERL MODULE                                          ##
                     52: ##                                                                           ##
                     53: ## 1. Description of functions                                               ##
                     54: ## 2. Modules used by this module                                            ##
                     55: ## 3. Choices for different output views (detailed, summary, xml, etc)       ##
                     56: ## 4. BEGIN block (to be run once after compilation)                         ##
                     57: ## 5. Handling routine called via Apache and mod_perl                        ##
                     58: ## 6. Other subroutines                                                      ##
                     59: ##                                                                           ##
                     60: ###############################################################################
1.7       harris41   61: 
1.1       www        62: package Apache::lonindexer;
                     63: 
1.23      harris41   64: # ------------------------------------------------- modules used by this module
1.1       www        65: use strict;
                     66: use Apache::lonnet();
1.30      harris41   67: use Apache::loncommon();
1.1       www        68: use Apache::Constants qw(:common);
1.2       harris41   69: use Apache::File;
                     70: use GDBM_File;
                     71: 
1.23      harris41   72: # ---------------------------------------- variables used throughout the module
1.17      harris41   73: my %hash; # tied to a user-specific gdbm file
                     74: my %dirs; # keys are directories, values are the open/close status
                     75: my %language; # has the reference information present in language.tab
                     76: 
                     77: # ----- Values which are set by the handler subroutine and are accessible to
                     78: # -----     other methods.
                     79: my $extrafield; # default extra table cell
                     80: my $fnum; # file counter
                     81: my $dnum; # directory counter
1.1       www        82: 
1.23      harris41   83: # ----------------------------- Handling routine called via Apache and mod_perl
1.1       www        84: sub handler {
                     85:     my $r = shift;
                     86:     $r->content_type('text/html');
                     87:     $r->send_http_header;
                     88:     return OK if $r->header_only;
1.9       harris41   89:     $fnum=0;
1.16      harris41   90:     $dnum=0;
1.22      harris41   91:     untie %hash;
1.17      harris41   92: 
1.23      harris41   93: # ------------------------------------- read in machine configuration variables
1.10      harris41   94:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1       www        95:     my $domain  = $r->dir_config('lonDefDomain');
                     96:     my $role    = $r->dir_config('lonRole');
                     97:     my $loadlim = $r->dir_config('lonLoadLim');
                     98:     my $servadm = $r->dir_config('lonAdmEMail');
                     99:     my $sysadm  = $r->dir_config('lonSysEMail');
                    100:     my $lonhost = $r->dir_config('lonHostID');
                    101:     my $tabdir  = $r->dir_config('lonTabDir');
                    102: 
1.7       harris41  103:     my $fileclr='#ffffe6';
1.15      harris41  104:     my $line;
                    105:     my (@attrchk,@openpath);
                    106:     my $uri=$r->uri;
                    107: 
1.7       harris41  108: # -------------------------------------- see if called from an interactive mode
1.17      harris41  109:     &get_unprocessed_cgi();
1.7       harris41  110: 
1.17      harris41  111:     my $closebutton='';
1.7       harris41  112:     my $groupimportbutton='';
                    113:     my $colspan=''; 
1.14      harris41  114: 
                    115:     $extrafield='';
1.17      harris41  116:     my $diropendb = 
                    117: 	"/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
1.15      harris41  118: 
                    119:     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
                    120: 	if ($ENV{'form.launch'} eq '1') {
1.17      harris41  121: 	    &start_fresh_session();
1.15      harris41  122: 	}
1.17      harris41  123: 
                    124: # -------------------- refresh environment with user database values (in %hash)
1.15      harris41  125: 	if ($hash{'mode_catalog'} eq 'interactive') {
                    126: 	    $ENV{'form.catalogmode'}='interactive';
                    127: 	}
                    128: 	if ($hash{'mode_catalog'} eq 'groupimport') {
                    129: 	    $ENV{'form.catalogmode'}='groupimport';
                    130: 	}
                    131: 
1.17      harris41  132: # --------------------- define extra fields and buttons in case of special mode
1.15      harris41  133: 	if ($ENV{'form.catalogmode'} eq 'interactive') {
                    134: 	    $hash{'mode_catalog'}='interactive';
                    135: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
                    136: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17      harris41  137: 		' border="0" /></td>';
1.15      harris41  138: 	    $colspan=" colspan='2' ";
                    139:             $closebutton=<<END;
1.7       harris41  140: <input type="button" name="close" value='CLOSE' onClick="self.close()">
                    141: END
1.16      harris41  142:         }
1.15      harris41  143: 	elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
                    144: 	    $hash{'mode_catalog'}='groupimport';
                    145: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
                    146: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17      harris41  147: 		' border="0" /></td>';
1.15      harris41  148: 	    $colspan=" colspan='2' ";
                    149:             $closebutton=<<END;
1.7       harris41  150: <input type="button" name="close" value='CLOSE' onClick="self.close()">
                    151: END
1.15      harris41  152:             $groupimportbutton=<<END;
1.17      harris41  153: <input type="button" name="groupimport" value='GROUP IMPORT'
                    154: onClick="javascript:select_group()">
1.7       harris41  155: END
1.15      harris41  156:         }
1.7       harris41  157: 
1.17      harris41  158: # ------ set catalogmodefunctions to have extra needed javascript functionality
1.15      harris41  159: 	my $catalogmodefunctions='';
                    160: 	if ($ENV{'form.catalogmode'} eq 'interactive' or
                    161: 	    $ENV{'form.catalogmode'} eq 'groupimport') {
                    162: 	    $catalogmodefunctions=<<END;
1.7       harris41  163: function select_data(title,url) {
                    164:     changeTitle(title);
                    165:     changeURL(url);
1.8       harris41  166:     self.close();
                    167: }
                    168: function select_group() {
1.20      harris41  169:     window.location="/adm/groupsort?catalogmode=groupimport&acts="+document.forms.fileattr.acts.value;
1.16      harris41  170: }
1.7       harris41  171: function changeTitle(val) {
                    172:     if (opener.inf.document.forms.resinfo.elements.t) {
                    173:         opener.inf.document.forms.resinfo.elements.t.value=val;
                    174:     }
                    175: }
                    176: function changeURL(val) {
                    177:     if (opener.inf.document.forms.resinfo.elements.u) {
                    178: 	opener.inf.document.forms.resinfo.elements.u.value=val;
                    179:     }
                    180: }
                    181: END
1.15      harris41  182:         }
1.16      harris41  183: 	if ($ENV{'form.catalogmode'} eq 'groupimport') {
                    184: 	    $catalogmodefunctions.=<<END;
                    185: var acts='';
                    186: function queue(val) {
                    187:     if (eval("document.forms."+val+".filelink.checked")) {
                    188: 	var l=val.length;
                    189: 	var v=val.substring(4,l);
                    190: 	document.forms.fileattr.acts.value+='1a'+v+'b';
                    191:     }
                    192:     else {
                    193: 	var l=val.length;
                    194: 	var v=val.substring(4,l);
                    195: 	document.forms.fileattr.acts.value+='0a'+v+'b';
                    196:     }
                    197: }
                    198: function rep_dirpath(suffix,val) {
                    199:     eval("document.forms.dirpath"+suffix+".acts.value=val");
                    200: }
                    201: END
                    202: 	}
1.17      harris41  203: 
1.1       www       204: # ---------------------------------------------------------------- Print Header
1.15      harris41  205: 	$r->print(<<ENDHEADER);
1.1       www       206: <html>
                    207: <head>
1.2       harris41  208: <title>The LearningOnline Network With CAPA Directory Browser</title>
1.3       harris41  209: 
1.19      harris41  210: <script type="text/javascript">
1.7       harris41  211: $catalogmodefunctions
1.2       harris41  212: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                    213:     var options = "width=" + w + ",height=" + h + ",";
                    214:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                    215:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                    216:     var newWin = window.open(url, wdwName, options);
                    217:     newWin.focus();
                    218: }
1.16      harris41  219: function gothere(val) {
                    220:     window.location=val+'?acts='+document.forms.fileattr.acts.value;
                    221: }
1.14      harris41  222: </script>
1.3       harris41  223: 
1.1       www       224: </head>
                    225: <body bgcolor="#FFFFFF">
                    226: ENDHEADER
1.17      harris41  227: 
                    228: # - Evaluate actions from previous page (both cumulatively and chronologically)
1.16      harris41  229:         if ($ENV{'form.catalogmode'} eq 'groupimport') {
                    230: 	    my $acts=$ENV{'form.acts'};
                    231: 	    my @Acts=split(/b/,$acts);
                    232: 	    my %ahash;
                    233: 	    my %achash;
                    234: 	    my $ac=0;
1.17      harris41  235: 	    # some initial hashes for working with data
1.27      harris41  236: 	    foreach (@Acts) {
1.16      harris41  237: 		my ($state,$ref)=split(/a/);
                    238: 		$ahash{$ref}=$state;
                    239: 		$achash{$ref}=$ac;
                    240: 		$ac++;
1.27      harris41  241: 	    }
1.17      harris41  242: 	    # sorting through the actions and changing the tied database hash
1.27      harris41  243: 	    foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
1.16      harris41  244: 		my $key=$_;
                    245: 		if ($ahash{$key} eq '1') {
                    246: 		    $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
                    247: 			$hash{'pre_'.$key.'_title'};
                    248: 		    $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
                    249: 			$hash{'storectr'}+0;
                    250: 		    $hash{'storectr'}++;
                    251: 		}
                    252: 		if ($ahash{$key} eq '0') {
                    253: 		    if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
                    254: 			delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
                    255: 		    }
                    256: 		}
1.27      harris41  257: 	    }
1.17      harris41  258: 	    # deleting the previously cached listing
1.27      harris41  259: 	    foreach (keys %hash) {
1.16      harris41  260: 		if ($_ =~ /^pre_/ && $_ =~/link$/) {
                    261: 		    my $key = $_;
                    262: 		    $key =~ s/^pre_//;
                    263: 		    $key =~ s/_[^_]*$//;
                    264: 		    delete $hash{'pre_'.$key.'_title'};
                    265: 		    delete $hash{'pre_'.$key.'_link'};
                    266: 		}
1.27      harris41  267: 	    }
1.16      harris41  268: 	}
                    269: 	
1.23      harris41  270: # ---------------------------------------------------------------- output title
1.17      harris41  271: 	$r->print('<h2><font color="#888888">The LearningOnline With CAPA '.
                    272: 		  'Network Directory Browser</font></h2>'."\n");
1.23      harris41  273: # ---------------------------------- get state of file attributes to be showing
1.6       harris41  274: 	if ($ENV{'form.attrs'} ne "") {
1.18      ng        275: 	    for (my $i=0; $i<=6; $i++) {
1.6       harris41  276: 		delete $hash{'display_attrs_'.$i};
                    277: 		if ($ENV{'form.attr'.$i} == 1) {
                    278: 		    $attrchk[$i] = "checked";
                    279: 		    $hash{'display_attrs_'.$i} = 1;
                    280: 		}
                    281: 	    }
                    282: 	} else {
1.18      ng        283: 	    for (my $i=0; $i<=6; $i++) {
1.6       harris41  284: 		$attrchk[$i] = "checked" if $hash{'display_attrs_'.$i} == 1;
                    285: 	    }
                    286: 	}
1.23      harris41  287: # ------------------------------- output state of file attributes to be showing
1.15      harris41  288: 	$r->print(<<END);
1.17      harris41  289: <b><font color="#666666">Display file attributes</font></b><br />
                    290: <form method="post" name="fileattr" action="$uri"
                    291:  enctype="application/x-www-form-urlencoded">
1.1       www       292: <table border=0><tr>
1.16      harris41  293: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> Size</td>
1.18      ng        294: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Last access</td>
                    295: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last modified</td>
                    296: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> All versions</td>
1.1       www       297: </tr><tr>
1.16      harris41  298: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Author</td>
                    299: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Keywords</td>
                    300: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> Language</td>
1.18      ng        301: <td>&nbsp;</td>
1.1       www       302: </tr></table>
1.16      harris41  303: <input type="hidden" name="dirPointer" value="on" />
                    304: <input type="hidden" name="acts" value="" />
                    305: <input type="submit" name="attrs" value="Review" />&nbsp;
                    306: <input type="submit" name="attrs" value="Refresh" />
1.7       harris41  307: $closebutton
                    308: $groupimportbutton
1.1       www       309: </form>
                    310: END
                    311: 
1.23      harris41  312: # ----------------- output starting row to the indexed file/directory hierarchy
1.15      harris41  313:         my $titleclr="#ddffff";
                    314:         $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
                    315: 	$r->print("<table border=0><tr>\n");
                    316: 	$r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
1.17      harris41  317: 	$r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) ".
                    318: 		  "</b></td>\n") if ($hash{'display_attrs_0'} == 1);
                    319: 	$r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n") 
                    320: 	    if ($hash{'display_attrs_1'} == 1);
                    321: 	$r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n")
                    322: 	    if ($hash{'display_attrs_2'} == 1);
                    323: 	$r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n")
                    324: 	    if ($hash{'display_attrs_3'} == 1);
                    325: 	$r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n")
                    326: 	    if ($hash{'display_attrs_4'} == 1);
                    327: 	$r->print("<td bgcolor=$titleclr><b>Language</b></td>\n")
                    328: 	    if ($hash{'display_attrs_5'} == 1);
1.15      harris41  329: 	$r->print("</tr>");
1.5       harris41  330: 
1.23      harris41  331: # ----------------- read in what directories have previously been set to "open"
1.27      harris41  332: 	foreach (keys %hash) {
1.4       harris41  333: 	    if ($_ =~ /^diropen_status_/) {
                    334: 		my $key = $_;
                    335: 		$key =~ s/^diropen_status_//;
                    336: 		$dirs{$key} = $hash{$_};
                    337: 	    }
1.27      harris41  338: 	}
1.4       harris41  339: 
1.2       harris41  340: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
                    341: 	    my $uri=$ENV{'form.openuri'};
1.4       harris41  342: 	    if (exists($hash{'diropen_status_'.$uri})) {
                    343: 		my $cursta = $hash{'diropen_status_'.$uri};
1.2       harris41  344: 		$dirs{$uri} = 'open';
1.4       harris41  345: 		$hash{'diropen_status_'.$uri} = 'open';
                    346: 		if ($cursta eq 'open') {
                    347: 		    $dirs{$uri} = 'closed';
                    348: 		    $hash{'diropen_status_'.$uri} = 'closed';
                    349: 		}
1.2       harris41  350: 	    } else {
1.4       harris41  351: 		$hash{'diropen_status_'.$uri} = 'open';
1.2       harris41  352: 		$dirs{$uri} = 'open';
                    353: 	    }
                    354: 	}
1.12      ng        355: 	
                    356: 	my $bredir = $ENV{'form.dirPointer'};
                    357: 	my $toplevel;
1.13      ng        358: 	my $indent = 0;
1.12      ng        359: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
1.17      harris41  360: 
1.13      ng        361: 	if ($bredir ne "on") {
1.12      ng        362: 	    $hash{'top.level'} = $uri;
                    363: 	    $toplevel = $uri;
1.13      ng        364: 
                    365: 	} else {
                    366: 	    $toplevel = $hash{'top.level'};
                    367: 	}
1.17      harris41  368: 
1.23      harris41  369: # -------------------------------- if not at top level, provide an uplink arrow
1.13      ng        370: 	if ($toplevel ne "/res/"){
                    371: 	    my (@uri_com) = split(/\//,$uri);
                    372: 	    pop @uri_com;
                    373: 	    my $upone = join('/',@uri_com);
                    374: 	    my @list = qw (0);
                    375: 	    &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
                    376: 	    $indent = 1;
1.12      ng        377: 	}
1.17      harris41  378: 
1.23      harris41  379: # -------- recursively go through all the directories and output as appropriate
1.16      harris41  380: 	&scanDir ($r,$toplevel,$indent,\%hash);
1.12      ng        381: 	
1.23      harris41  382: # ---------------------------- embed hidden information useful for group import
1.8       harris41  383: 	$r->print("<form name='fnum'>");
                    384: 	$r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
1.17      harris41  385: 
1.23      harris41  386: # -------------------------------------------------------------- end the tables
1.2       harris41  387: 	$r->print("</table>");
                    388: 	$r->print("</td></tr></table>");
1.17      harris41  389: 
1.23      harris41  390: # --------------------------------------------------- end the output and return
1.2       harris41  391: 	$r->print("</body></html>\n");
1.4       harris41  392: 	untie(%hash);
1.2       harris41  393:     } else {
1.17      harris41  394: 	$r->print('<html><head></head><body>Unable to tie hash to db '.
                    395: 		  'file</body></html>');
                    396: 	return OK;
1.2       harris41  397:     }
1.1       www       398:     return OK;
                    399: }
1.2       harris41  400: 
1.17      harris41  401: # ----------------------------------------------- recursive scan of a directory
1.2       harris41  402: sub scanDir {
1.16      harris41  403:     my ($r,$startdir,$indent,$hashref)=@_;
1.3       harris41  404:     my ($compuri,$curdir);
                    405:     my $dirptr=16384;
1.1       www       406:     $indent++;
                    407: 
1.2       harris41  408:     my %dupdirs = %dirs;
                    409:     my @list=&get_list($r,$startdir);
                    410:     foreach my $line (@list) {
1.5       harris41  411: 	my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5); 
1.4       harris41  412: 	next if $strip =~ /.*\.meta$/;
1.18      ng        413: 	my (@fileparts) = split(/\./,$strip);
                    414: 	if ($hash{'display_attrs_6'} != 1) {
                    415: 	    if (scalar(@fileparts) >= 3) {
                    416: 		my $fext = pop @fileparts;
                    417: 		my $ov = pop @fileparts;
                    418: 		my $fname = join ('.',@fileparts,$fext);
                    419: 		next if (grep /$fname/,@list and $ov =~ /\d+/);
                    420: 	    }
                    421: 	}
                    422: 
1.5       harris41  423: 	if ($dom eq "domain") {
1.17      harris41  424: 	    $compuri = join('',$strip,"/");  # dom list has /res/<domain name>
1.3       harris41  425: 	    $curdir = $compuri;
1.2       harris41  426: 	} else {
1.17      harris41  427: 	    # user, dir & file have name only, i.e., w/o path
                    428: 	    $compuri = join('',$startdir,$strip,"/");
1.3       harris41  429: 	    $curdir = $startdir;
1.2       harris41  430: 	}
1.11      ng        431: 	my $diropen = "closed";
1.5       harris41  432: 	if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
1.3       harris41  433: 	    while (my ($key,$val)= each %dupdirs) {
1.5       harris41  434: 		if ($key eq $compuri and $val eq "open") {
1.11      ng        435: 		    $diropen = "opened";
1.5       harris41  436: 		    delete $dupdirs{key},$dirs{$key};
                    437: 		}
1.3       harris41  438: 	    }
1.1       www       439: 	}
1.16      harris41  440: 	&display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
1.11      ng        441: 	&scanDir ($r,$compuri,$indent) if $diropen eq "opened";
1.1       www       442:     }
                    443:     $indent--;
                    444: }
                    445: 
1.17      harris41  446: # --------------- get complete matched list based on the uri (returns an array)
1.1       www       447: sub get_list {
                    448:     my ($r,$uri)=@_;
                    449:     my @list;
1.2       harris41  450:     my $luri = $uri;
                    451:     $luri =~ s/\//_/g;
                    452: 
1.6       harris41  453:     if ($ENV{'form.attrs'} eq "Refresh") {
1.27      harris41  454: 	foreach (keys %hash) {
1.4       harris41  455: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
1.27      harris41  456: 	    }
1.2       harris41  457:     }
                    458: 
1.4       harris41  459:     if ($hash{'dirlist_files'.$luri}) {
                    460: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.1       www       461:     } else {
1.4       harris41  462: 	@list = &Apache::lonnet::dirlist($uri);
                    463: 	$hash{'dirlist_files_'.$luri} = join('\n',@list);
1.1       www       464:     }
                    465:     return @list=&match_ext($r,@list);
                    466: }
                    467: 
1.17      harris41  468: # -------------------- filters out files based on extensions (returns an array)
1.1       www       469: sub match_ext {
                    470:     my ($r,@packlist)=@_;
                    471:     my @trimlist;
                    472:     my $nextline;
                    473:     my @fileext;
                    474:     my $dirptr=16384;
                    475: 
1.2       harris41  476:     foreach my $line (@packlist) {
                    477: 	chomp $line;
                    478: 	$line =~ s/^\/home\/httpd\/html//;
                    479: 	my @unpackline = split (/\&/,$line);
                    480: 	next if ($unpackline[0] eq ".");
                    481: 	next if ($unpackline[0] eq "..");
                    482: 	my @filecom = split (/\./,$unpackline[0]);
                    483: 	my $fext = pop(@filecom);
                    484: 	my $fnptr = $unpackline[3]&$dirptr;
                    485:  	if ($fnptr == 0 and $unpackline[3] ne "") {
1.28      harris41  486: 	    my $embstyle = &Apache::loncommon::fileembstyle($fext);
1.25      matthew   487:             push @trimlist,$line if (defined($embstyle) && 
1.32    ! harris41  488: 				     ($embstyle ne 'hdn' or $fext eq 'meta'));
1.1       www       489: 	} else {
1.2       harris41  490: 	    push @trimlist,$line;
1.1       www       491: 	}
                    492:     }
1.4       harris41  493:     @trimlist = sort (@trimlist);
1.1       www       494:     return @trimlist;
                    495: }
                    496: 
1.17      harris41  497: # ------------------------------- displays one line in appropriate table format
1.23      harris41  498: sub display_line {
1.16      harris41  499:     my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
1.1       www       500:     my (@pathfn, $fndir, $fnptr);
                    501:     my $dirptr=16384;
                    502:     my $fileclr="#ffffe6";
1.10      harris41  503:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1       www       504: 
                    505:     my @filecom = split (/\&/,$line);
                    506:     my @pathcom = split (/\//,$filecom[0]);
                    507:     my $listname = $pathcom[scalar(@pathcom)-1];
                    508:     my $fnptr = $filecom[3]&$dirptr;
1.4       harris41  509:     my $msg = 'View '.$filecom[0].' resources';
1.11      ng        510:     $msg = 'Close '.$filecom[0].' directory' if $diropen eq "opened";
1.1       www       511: 
                    512:     my $tabtag="</td>";
                    513:     my $i=0;
                    514: 
                    515:     while ($i<=5) {
1.17      harris41  516: 	$tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,">&nbsp;</td>")
                    517: 	    if $hash{'display_attrs_'.$i} == 1;
1.1       www       518: 	$i++;
                    519:     }
1.17      harris41  520: 
                    521: # display uplink arrow
1.13      ng        522:     if ($filecom[1] eq "viewOneUp") {
                    523: 	$r->print("<tr>$extrafield");
                    524: 	$r->print("<td bgcolor=$fileclr valign=bottom>\n");
1.16      harris41  525: 	$r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
                    526: 		   '/" '.
1.17      harris41  527: 		   'onSubmit="return rep_dirpath(\'UP\','.
                    528: 		   'document.forms.fileattr.acts.value)" '.
1.16      harris41  529: 		   'enctype="application/x-www-form-urlencoded"'.
                    530:                    '>'."\n");
1.17      harris41  531: 	$r->print ('<input type=hidden name=openuri value="'.
                    532: 		   $startdir.'">'."\n");
1.16      harris41  533: 	$r->print ('<input type="hidden" name="acts" value="">'."\n");
1.13      ng        534: 	$r->print ('<input src="'.$iconpath.'arrow_up.gif"');
1.17      harris41  535: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    536: 		   "\n");
1.13      ng        537: 	$r->print("Up $tabtag</tr></form>\n");
                    538: 	return OK;
                    539:     }
1.17      harris41  540: 
                    541: # display domain
1.1       www       542:     if ($filecom[1] eq "domain") {
1.17      harris41  543: 	$r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
                    544: 	    if ($ENV{'form.dirPointer'} eq "on");
1.7       harris41  545: 	$r->print("<tr>$extrafield");
1.1       www       546: 	$r->print("<td bgcolor=$fileclr valign=bottom>");
1.2       harris41  547: 	&begin_form ($r,$filecom[0].'/');
1.3       harris41  548: 	my $anchor = $filecom[0].'/';
                    549: 	$anchor =~ s/\///g;
1.13      ng        550: 	$r->print ('<a name="'.$anchor.'">');
1.16      harris41  551: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41  552: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.
                    553: 		   $diropen.'.gif"'); 
                    554: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    555: 		   "\n");
                    556: 	$r->print ('<a href="javascript:gothere(\''.$filecom[0].
                    557: 		   '/\')"><img src="'.$iconpath.'server.gif"');
                    558: 	$r->print (' border="0" /></a>'."\n");
1.1       www       559: 	$r->print("Domain - $listname $tabtag</tr></form>\n");
                    560: 	return OK;
1.17      harris41  561: 
                    562: # display user directory
1.1       www       563:     }
                    564:     if ($filecom[1] eq "user") {
1.7       harris41  565: 	$r->print("<tr>$extrafield");
1.13      ng        566: 	$r->print("<td bgcolor=$fileclr valign=bottom nowrap>\n");
1.2       harris41  567: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  568: 	my $anchor = $curdir;
                    569: 	$anchor =~ s/\///g;
1.13      ng        570: 	&begin_form ($r,$curdir);
1.17      harris41  571: 	$r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
                    572: 		   'whitespace1.gif" border="0" />'."\n");
1.16      harris41  573: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41  574: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
                    575: 		   '.gif"'); 
                    576: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    577: 		   "\n");
                    578: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
                    579: 		   $iconpath.'quill.gif border="0" name="'.$msg.
                    580: 		   '" height="22" /></a>');
1.13      ng        581: 	$r->print ($listname.$tabtag.'</tr></form>'."\n");
1.1       www       582: 	return OK;
                    583:     }
1.17      harris41  584: 
1.1       www       585: # display file
                    586:     if ($fnptr == 0 and $filecom[3] ne "") {
                    587: 	my @file_ext = split (/\./,$listname);
1.25      matthew   588: 	my $curfext = $file_ext[-1];
                    589: 	# Set the icon for the file
1.26      matthew   590: 	my $iconname = "unknown.gif";
1.28      harris41  591: 	my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.25      matthew   592: 	# The unless conditional that follows is a bit of overkill
                    593: 	$iconname = $curfext.".gif" unless
1.26      matthew   594: 	    (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn');
1.25      matthew   595: 	#
1.2       harris41  596: 	my $filelink = $startdir.$filecom[0];
1.8       harris41  597: 	$r->print("<tr><td nowrap valign='bottom' bgcolor=$fileclr>");
1.7       harris41  598: 	my $metafile = grep /^$filecom[0]\.meta\&/, @list;
                    599: 	my $title;
                    600:         if ($ENV{'form.catalogmode'} eq 'interactive') {
                    601: 	    $title=$listname;
1.8       harris41  602: 	    $title = &Apache::lonnet::metadata($filelink,'title')
                    603: 		if ($metafile == 1);
1.7       harris41  604: 	    $title=$listname unless $title;
                    605: 	    $r->print("<a href='javascript:select_data(\"",
                    606: 	              $title,'","',$filelink,"\")'>");
1.17      harris41  607: 	    $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
                    608: 		      "\n");
1.8       harris41  609: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
                    610: 	}
                    611:         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
                    612: 	    $title=$listname;
                    613: 	    $title = &Apache::lonnet::metadata($filelink,'title')
                    614: 		if ($metafile == 1);
                    615: 	    $title=$listname unless $title;
                    616: 	    $r->print("<form name='form$fnum'>\n");
                    617: 	    $r->print("<input type='checkbox' name='filelink"."' ".
1.16      harris41  618: 		      "value='$filelink' onClick='".
                    619: 		      "javascript:queue(\"form$fnum\")' ");
                    620: 	    if ($hash{'store_'.$filelink}) {
                    621: 		$r->print("checked");
                    622: 	    }
                    623: 	    $r->print(">\n");
1.8       harris41  624: 	    $r->print("<input type='hidden' name='title"."' ".
                    625: 		      "value='$title'>\n");
                    626: 	    $r->print("</form>\n");
                    627: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
1.16      harris41  628: 	    $hash{"pre_${fnum}_link"}=$filelink;
                    629: 	    $hash{"pre_${fnum}_title"}=$title;
1.8       harris41  630:   	    $fnum++;
1.7       harris41  631: 	}
1.4       harris41  632: 
1.12      ng        633: 	if ($indent > 0 and $indent < 11) {
1.17      harris41  634: 	    $r->print("<img src=",$iconpath,"whitespace",$indent,
                    635: 		      ".gif border='0' />\n");
1.11      ng        636: 	} elsif ($indent >0) {
1.4       harris41  637: 	    my $ten = int($indent/10.);
                    638: 	    my $rem = $indent%10.0;
                    639: 	    my $count = 0;
                    640: 	    while ($count < $ten) {
1.17      harris41  641: 		$r->print("<img src=",$iconpath,
                    642: 			  "whitespace10.gif border='0' />\n");
1.1       www       643: 	    $count++;
1.4       harris41  644: 	    }
1.17      harris41  645: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,
                    646: 		      ".gif border='0' />\n") if $rem > 0;
1.1       www       647: 	}
1.4       harris41  648: 
1.25      matthew   649: 	$r->print("<img src=$iconpath$iconname border='0' />\n");
1.17      harris41  650: 	$r->print (" <a href=\"javascript:openWindow('".$filelink.
                    651: 		   "', 'metadatafile', '450', '500', 'no', 'yes')\";".
                    652: 		   " TARGET=_self>$listname</a> ");
                    653: 
                    654: 	$r->print (" (<a href=\"javascript:openWindow('".$filelink.
                    655: 		   ".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; ".
                    656: 		   "TARGET=_self>metadata</a>) ") if ($metafile == 1);
1.2       harris41  657: 
1.7       harris41  658: 	$r->print("</td>\n");
1.17      harris41  659: 	$r->print("<td bgcolor=$fileclr align=right valign=bottom> ",
                    660: 		  $filecom[8]," </td>\n") 
1.11      ng        661: 	    if $hash{'display_attrs_0'} == 1;
1.17      harris41  662: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".
                    663: 		  (localtime($filecom[9]))." </td>\n") 
1.11      ng        664: 	    if $hash{'display_attrs_1'} == 1;
1.17      harris41  665: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".
                    666: 		  (localtime($filecom[10]))." </td>\n") 
1.11      ng        667: 	    if $hash{'display_attrs_2'} == 1;
1.2       harris41  668: 
1.6       harris41  669: 	if ($hash{'display_attrs_3'} == 1) {
1.17      harris41  670: 	    my $author = &Apache::lonnet::metadata($filelink,'author')
                    671: 		if ($metafile == 1);
1.2       harris41  672: 	    $author = '&nbsp;' if (!$author);
1.17      harris41  673: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$author.
                    674: 		      " </td>\n");
1.2       harris41  675: 	}
1.6       harris41  676: 	if ($hash{'display_attrs_4'} == 1) {
1.17      harris41  677: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
                    678: 		if ($metafile == 1);
1.2       harris41  679: 	    $keywords = '&nbsp;' if (!$keywords);
1.17      harris41  680: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords.
                    681: 		      " </td>\n");
1.2       harris41  682: 	}
1.6       harris41  683: 	if ($hash{'display_attrs_5'} == 1) {
1.17      harris41  684: 	    my $lang = &Apache::lonnet::metadata($filelink,'language')
                    685: 		if ($metafile == 1);
1.28      harris41  686: 	    $lang = &Apache::loncommon::languagedescription($lang);
1.2       harris41  687: 	    $lang = '&nbsp;' if (!$lang);
1.17      harris41  688: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang.
                    689: 		      " </td>\n");
1.2       harris41  690: 	}
1.1       www       691: 	$r->print("</tr>\n");
                    692:     }
1.17      harris41  693: 
1.2       harris41  694: # -- display directory
1.1       www       695:     if ($fnptr == $dirptr) {
                    696: 	my @file_ext = split (/\./,$listname);
                    697: 	my $curfext = $file_ext[scalar(@file_ext)-1];
1.2       harris41  698: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  699: 	my $anchor = $curdir;
                    700: 	$anchor =~ s/\///g;
1.7       harris41  701: 	$r->print("<tr>$extrafield<td bgcolor=$fileclr valign=bottom>");
1.2       harris41  702: 	&begin_form ($r,$curdir);
1.4       harris41  703: 	my $indentm1 = $indent-1;
1.11      ng        704: 	if ($indentm1 < 11 and $indentm1 > 0) {
1.17      harris41  705: 	    $r->print("<img src=",$iconpath,"whitespace",$indentm1,
                    706: 		      ".gif border='0' />\n");
1.4       harris41  707: 	} else {
                    708: 	    my $ten = int($indentm1/10.);
                    709: 	    my $rem = $indentm1%10.0;
                    710: 	    my $count = 0;
                    711: 	    while ($count < $ten) {
1.17      harris41  712: 		$r->print ("<img src=",$iconpath
                    713: 			   ,"whitespace10.gif border='0' />\n");
1.12      ng        714: 		$count++;
1.4       harris41  715: 	    }
1.17      harris41  716: 	    $r->print ("<img src=",$iconpath,"whitespace",$rem,
                    717: 		       ".gif border='0' />\n") if $rem > 0;
1.1       www       718: 	}
1.16      harris41  719: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41  720: 	$r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
                    721: 		   'folder_pointer_'.$diropen.'.gif"');
                    722: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    723: 		   "\n");
                    724: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
                    725: 		   $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
                    726: 		   "\n");
1.13      ng        727: 	$r->print ("$listname$tabtag</tr></form>\n");
1.1       www       728:     }
1.2       harris41  729: 
1.1       www       730: }
                    731: 
1.14      harris41  732: # ------------------- prints the beginning of a form for directory or file link
1.1       www       733: sub begin_form {
                    734:     my ($r,$uri) = @_;
1.3       harris41  735:     my $anchor = $uri;
                    736:     $anchor =~ s/\///g;
1.17      harris41  737:     $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
                    738: 	       '#'.$anchor.
                    739: 	       '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
                    740: 	       ',document.forms.fileattr.acts.value)" '.
1.16      harris41  741: 	       'enctype="application/x-www-form-urlencoded">'."\n");
1.17      harris41  742:     $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
                    743: 	       "\n");
                    744:     $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16      harris41  745:     $dnum++;
1.17      harris41  746: }
                    747: 
                    748: # ----------- grab unprocessed CGI variables that may have been appended to URL
                    749: sub get_unprocessed_cgi {
1.27      harris41  750:     foreach (split(/&/,$ENV{'QUERY_STRING'})) {
1.17      harris41  751:        my ($name, $value) = split(/=/,$_);
                    752:        $value =~ tr/+/ /;
                    753:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                    754:        if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') {
                    755:            $ENV{'form.'.$name}=$value;
                    756:        }
1.27      harris41  757:     }
1.17      harris41  758: }
                    759: 
                    760: # --------- settings whenever the user causes the indexer window to be launched
                    761: sub start_fresh_session {
                    762:     delete $hash{'mode_catalog'};
1.27      harris41  763:     foreach (keys %hash) {
1.17      harris41  764: 	if ($_ =~ /^pre_/) {
                    765: 	    delete $hash{$_};
                    766: 	}
                    767: 	if ($_ =~ /^store/) {
                    768: 	    delete $hash{$_};
                    769: 	}
1.27      harris41  770:     }
1.1       www       771: }
                    772: 
                    773: 1;
1.23      harris41  774: 
                    775: =head1 NAME
                    776: 
                    777: Apache::lonindexer - mod_perl module for cross server filesystem browsing
                    778: 
                    779: =head1 SYNOPSIS
                    780: 
                    781: Invoked by /etc/httpd/conf/srm.conf:
                    782: 
                    783:  <LocationMatch "^/res.*/$">
                    784:  SetHandler perl-script
                    785:  PerlHandler Apache::lonindexer
                    786:  </LocationMatch>
                    787: 
                    788: =head1 INTRODUCTION
                    789: 
                    790: This module enables a scheme of browsing across a cross server.
                    791: 
                    792: This is part of the LearningOnline Network with CAPA project
                    793: described at http://www.lon-capa.org.
                    794: 
                    795: =head1 BEGIN SUBROUTINE
                    796: 
                    797: This routine is only run once after compilation.
                    798: 
                    799: =over 4
                    800: 
                    801: =item *
                    802: 
                    803: Initializes %language hash table.
                    804: 
                    805: =back
                    806: 
                    807: =head1 HANDLER SUBROUTINE
                    808: 
                    809: This routine is called by Apache and mod_perl.
                    810: 
                    811: =over 4
                    812: 
                    813: =item *
                    814: 
                    815: read in machine configuration variables
                    816: 
                    817: =item *
                    818: 
                    819: see if called from an interactive mode
                    820: 
                    821: =item *
                    822: 
                    823: refresh environment with user database values (in %hash)
                    824: 
                    825: =item *
                    826: 
                    827: define extra fields and buttons in case of special mode
                    828: 
                    829: =item *
                    830: 
                    831: set catalogmodefunctions to have extra needed javascript functionality
                    832: 
                    833: =item *
                    834: 
                    835: print header
                    836: 
                    837: =item *
                    838: 
                    839: evaluate actions from previous page (both cumulatively and chronologically)
                    840: 
                    841: =item *
                    842: 
                    843: output title
                    844: 
                    845: =item *
                    846: 
                    847: get state of file attributes to be showing
                    848: 
                    849: =item *
                    850: 
                    851: output state of file attributes to be showing
                    852: 
                    853: =item *
                    854: 
                    855: output starting row to the indexed file/directory hierarchy
                    856: 
                    857: =item *
                    858: 
                    859: read in what directories have previously been set to "open"
                    860: 
                    861: =item *
                    862: 
                    863: if not at top level, provide an uplink arrow
                    864: 
                    865: =item *
                    866: 
                    867: recursively go through all the directories and output as appropriate
                    868: 
                    869: =item *
                    870: 
                    871: information useful for group import
                    872: 
                    873: =item *
                    874: 
                    875: end the tables
                    876: 
                    877: =item *
                    878: 
                    879: end the output and return
                    880: 
                    881: =back
                    882: 
                    883: =head1 OTHER SUBROUTINES
                    884: 
                    885: =over 4
                    886: 
                    887: =item *
                    888: 
                    889: scanDir - recursive scan of a directory
                    890: 
                    891: =item *
                    892: 
                    893: get_list - get complete matched list based on the uri (returns an array)
                    894: 
                    895: =item *
                    896: 
                    897: match_ext - filters out files based on extensions (returns an array)
                    898: 
                    899: =item *
                    900: 
                    901: display_line - displays one line in appropriate table format
                    902: 
                    903: =item *
                    904: 
                    905: begin_form - prints the beginning of a form for directory or file link
                    906: 
                    907: =item *
                    908: 
                    909: get_unprocessed_cgi - grab unprocessed CGI variables that may have been
                    910: appended to URL
                    911: 
                    912: =item *
                    913: 
                    914: start_fresh_session - settings whenever the user causes the indexer window
                    915: to be launched
                    916: 
                    917: =back
                    918: 
                    919: =cut

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