File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.27: download - view: text, annotated - select for diffs
Tue Dec 11 03:50:09 2001 UTC (22 years, 6 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
removing void context map blocks and replacing with foreach blocks
-Scott Harrison

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

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