File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.30: download - view: text, annotated - select for diffs
Thu Dec 13 13:59:22 2001 UTC (22 years, 6 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
use Apache::loncommon added -Scott Harrison

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

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