File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.29: download - view: text, annotated - select for diffs
Thu Dec 13 13:42:15 2001 UTC (22 years, 6 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
removing language.tab reading since use loncommon function -Scott Harrison

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

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