File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.28: download - view: text, annotated - select for diffs
Thu Dec 13 13:38:14 2001 UTC (22 years, 6 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
replacing lonnet::fileembstyle with loncommon::fileembstyle -Scott Harrison

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

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