File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.23: download - view: text, annotated - select for diffs
Wed Nov 28 16:47:25 2001 UTC (22 years, 6 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
updating documentation; entering POD-style tags -Scott

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

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