File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.24: download - view: text, annotated - select for diffs
Thu Nov 29 20:31:45 2001 UTC (22 years, 7 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
GPL

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

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