File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.33: download - view: text, annotated - select for diffs
Thu Jan 17 14:02:47 2002 UTC (22 years, 5 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
escaping single quotes for proper javascript

    1: # The LearningOnline Network with CAPA
    2: # Directory Indexer
    3: #
    4: # $Id: lonindexer.pm,v 1.33 2002/01/17 14:02:47 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: # YEAR=2002
   45: # 1/17 Scott Harrison
   46: #
   47: ###
   48: 
   49: ###############################################################################
   50: ##                                                                           ##
   51: ## ORGANIZATION OF THIS PERL MODULE                                          ##
   52: ##                                                                           ##
   53: ## 1. Description of functions                                               ##
   54: ## 2. Modules used by this module                                            ##
   55: ## 3. Choices for different output views (detailed, summary, xml, etc)       ##
   56: ## 4. BEGIN block (to be run once after compilation)                         ##
   57: ## 5. Handling routine called via Apache and mod_perl                        ##
   58: ## 6. Other subroutines                                                      ##
   59: ##                                                                           ##
   60: ###############################################################################
   61: 
   62: package Apache::lonindexer;
   63: 
   64: # ------------------------------------------------- modules used by this module
   65: use strict;
   66: use Apache::lonnet();
   67: use Apache::loncommon();
   68: use Apache::Constants qw(:common);
   69: use Apache::File;
   70: use GDBM_File;
   71: 
   72: # ---------------------------------------- variables used throughout the module
   73: my %hash; # tied to a user-specific gdbm file
   74: my %dirs; # keys are directories, values are the open/close status
   75: my %language; # has the reference information present in language.tab
   76: 
   77: # ----- Values which are set by the handler subroutine and are accessible to
   78: # -----     other methods.
   79: my $extrafield; # default extra table cell
   80: my $fnum; # file counter
   81: my $dnum; # directory counter
   82: 
   83: # ----------------------------- Handling routine called via Apache and mod_perl
   84: sub handler {
   85:     my $r = shift;
   86:     $r->content_type('text/html');
   87:     $r->send_http_header;
   88:     return OK if $r->header_only;
   89:     $fnum=0;
   90:     $dnum=0;
   91:     untie %hash;
   92: 
   93: # ------------------------------------- read in machine configuration variables
   94:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
   95:     my $domain  = $r->dir_config('lonDefDomain');
   96:     my $role    = $r->dir_config('lonRole');
   97:     my $loadlim = $r->dir_config('lonLoadLim');
   98:     my $servadm = $r->dir_config('lonAdmEMail');
   99:     my $sysadm  = $r->dir_config('lonSysEMail');
  100:     my $lonhost = $r->dir_config('lonHostID');
  101:     my $tabdir  = $r->dir_config('lonTabDir');
  102: 
  103:     my $fileclr='#ffffe6';
  104:     my $line;
  105:     my (@attrchk,@openpath);
  106:     my $uri=$r->uri;
  107: 
  108: # -------------------------------------- see if called from an interactive mode
  109:     &get_unprocessed_cgi();
  110: 
  111:     my $closebutton='';
  112:     my $groupimportbutton='';
  113:     my $colspan=''; 
  114: 
  115:     $extrafield='';
  116:     my $diropendb = 
  117: 	"/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
  118: 
  119:     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
  120: 	if ($ENV{'form.launch'} eq '1') {
  121: 	    &start_fresh_session();
  122: 	}
  123: 
  124: # -------------------- refresh environment with user database values (in %hash)
  125: 	if ($hash{'mode_catalog'} eq 'interactive') {
  126: 	    $ENV{'form.catalogmode'}='interactive';
  127: 	}
  128: 	if ($hash{'mode_catalog'} eq 'groupimport') {
  129: 	    $ENV{'form.catalogmode'}='groupimport';
  130: 	}
  131: 
  132: # --------------------- define extra fields and buttons in case of special mode
  133: 	if ($ENV{'form.catalogmode'} eq 'interactive') {
  134: 	    $hash{'mode_catalog'}='interactive';
  135: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
  136: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
  137: 		' border="0" /></td>';
  138: 	    $colspan=" colspan='2' ";
  139:             $closebutton=<<END;
  140: <input type="button" name="close" value='CLOSE' onClick="self.close()">
  141: END
  142:         }
  143: 	elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
  144: 	    $hash{'mode_catalog'}='groupimport';
  145: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
  146: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
  147: 		' border="0" /></td>';
  148: 	    $colspan=" colspan='2' ";
  149:             $closebutton=<<END;
  150: <input type="button" name="close" value='CLOSE' onClick="self.close()">
  151: END
  152:             $groupimportbutton=<<END;
  153: <input type="button" name="groupimport" value='GROUP IMPORT'
  154: onClick="javascript:select_group()">
  155: END
  156:         }
  157: 
  158: # ------ set catalogmodefunctions to have extra needed javascript functionality
  159: 	my $catalogmodefunctions='';
  160: 	if ($ENV{'form.catalogmode'} eq 'interactive' or
  161: 	    $ENV{'form.catalogmode'} eq 'groupimport') {
  162: 	    $catalogmodefunctions=<<END;
  163: function select_data(title,url) {
  164:     changeTitle(title);
  165:     changeURL(url);
  166:     self.close();
  167: }
  168: function select_group() {
  169:     window.location="/adm/groupsort?catalogmode=groupimport&acts="+document.forms.fileattr.acts.value;
  170: }
  171: function changeTitle(val) {
  172:     if (opener.inf.document.forms.resinfo.elements.t) {
  173:         opener.inf.document.forms.resinfo.elements.t.value=val;
  174:     }
  175: }
  176: function changeURL(val) {
  177:     if (opener.inf.document.forms.resinfo.elements.u) {
  178: 	opener.inf.document.forms.resinfo.elements.u.value=val;
  179:     }
  180: }
  181: END
  182:         }
  183: 	if ($ENV{'form.catalogmode'} eq 'groupimport') {
  184: 	    $catalogmodefunctions.=<<END;
  185: var acts='';
  186: function queue(val) {
  187:     if (eval("document.forms."+val+".filelink.checked")) {
  188: 	var l=val.length;
  189: 	var v=val.substring(4,l);
  190: 	document.forms.fileattr.acts.value+='1a'+v+'b';
  191:     }
  192:     else {
  193: 	var l=val.length;
  194: 	var v=val.substring(4,l);
  195: 	document.forms.fileattr.acts.value+='0a'+v+'b';
  196:     }
  197: }
  198: function rep_dirpath(suffix,val) {
  199:     eval("document.forms.dirpath"+suffix+".acts.value=val");
  200: }
  201: END
  202: 	}
  203: 
  204: # ---------------------------------------------------------------- Print Header
  205: 	$r->print(<<ENDHEADER);
  206: <html>
  207: <head>
  208: <title>The LearningOnline Network With CAPA Directory Browser</title>
  209: 
  210: <script type="text/javascript">
  211: $catalogmodefunctions
  212: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
  213:     var options = "width=" + w + ",height=" + h + ",";
  214:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
  215:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
  216:     var newWin = window.open(url, wdwName, options);
  217:     newWin.focus();
  218: }
  219: function gothere(val) {
  220:     window.location=val+'?acts='+document.forms.fileattr.acts.value;
  221: }
  222: </script>
  223: 
  224: </head>
  225: <body bgcolor="#FFFFFF">
  226: ENDHEADER
  227: 
  228: # - Evaluate actions from previous page (both cumulatively and chronologically)
  229:         if ($ENV{'form.catalogmode'} eq 'groupimport') {
  230: 	    my $acts=$ENV{'form.acts'};
  231: 	    my @Acts=split(/b/,$acts);
  232: 	    my %ahash;
  233: 	    my %achash;
  234: 	    my $ac=0;
  235: 	    # some initial hashes for working with data
  236: 	    foreach (@Acts) {
  237: 		my ($state,$ref)=split(/a/);
  238: 		$ahash{$ref}=$state;
  239: 		$achash{$ref}=$ac;
  240: 		$ac++;
  241: 	    }
  242: 	    # sorting through the actions and changing the tied database hash
  243: 	    foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
  244: 		my $key=$_;
  245: 		if ($ahash{$key} eq '1') {
  246: 		    $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
  247: 			$hash{'pre_'.$key.'_title'};
  248: 		    $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
  249: 			$hash{'storectr'}+0;
  250: 		    $hash{'storectr'}++;
  251: 		}
  252: 		if ($ahash{$key} eq '0') {
  253: 		    if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
  254: 			delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
  255: 		    }
  256: 		}
  257: 	    }
  258: 	    # deleting the previously cached listing
  259: 	    foreach (keys %hash) {
  260: 		if ($_ =~ /^pre_/ && $_ =~/link$/) {
  261: 		    my $key = $_;
  262: 		    $key =~ s/^pre_//;
  263: 		    $key =~ s/_[^_]*$//;
  264: 		    delete $hash{'pre_'.$key.'_title'};
  265: 		    delete $hash{'pre_'.$key.'_link'};
  266: 		}
  267: 	    }
  268: 	}
  269: 	
  270: # ---------------------------------------------------------------- output title
  271: 	$r->print('<h2><font color="#888888">The LearningOnline With CAPA '.
  272: 		  'Network Directory Browser</font></h2>'."\n");
  273: # ---------------------------------- get state of file attributes to be showing
  274: 	if ($ENV{'form.attrs'} ne "") {
  275: 	    for (my $i=0; $i<=6; $i++) {
  276: 		delete $hash{'display_attrs_'.$i};
  277: 		if ($ENV{'form.attr'.$i} == 1) {
  278: 		    $attrchk[$i] = "checked";
  279: 		    $hash{'display_attrs_'.$i} = 1;
  280: 		}
  281: 	    }
  282: 	} else {
  283: 	    for (my $i=0; $i<=6; $i++) {
  284: 		$attrchk[$i] = "checked" if $hash{'display_attrs_'.$i} == 1;
  285: 	    }
  286: 	}
  287: # ------------------------------- output state of file attributes to be showing
  288: 	$r->print(<<END);
  289: <b><font color="#666666">Display file attributes</font></b><br />
  290: <form method="post" name="fileattr" action="$uri"
  291:  enctype="application/x-www-form-urlencoded">
  292: <table border=0><tr>
  293: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> Size</td>
  294: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Last access</td>
  295: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last modified</td>
  296: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> All versions</td>
  297: </tr><tr>
  298: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Author</td>
  299: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Keywords</td>
  300: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> Language</td>
  301: <td>&nbsp;</td>
  302: </tr></table>
  303: <input type="hidden" name="dirPointer" value="on" />
  304: <input type="hidden" name="acts" value="" />
  305: <input type="submit" name="attrs" value="Review" />&nbsp;
  306: <input type="submit" name="attrs" value="Refresh" />
  307: $closebutton
  308: $groupimportbutton
  309: </form>
  310: END
  311: 
  312: # ----------------- output starting row to the indexed file/directory hierarchy
  313:         my $titleclr="#ddffff";
  314:         $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
  315: 	$r->print("<table border=0><tr>\n");
  316: 	$r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
  317: 	$r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) ".
  318: 		  "</b></td>\n") if ($hash{'display_attrs_0'} == 1);
  319: 	$r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n") 
  320: 	    if ($hash{'display_attrs_1'} == 1);
  321: 	$r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n")
  322: 	    if ($hash{'display_attrs_2'} == 1);
  323: 	$r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n")
  324: 	    if ($hash{'display_attrs_3'} == 1);
  325: 	$r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n")
  326: 	    if ($hash{'display_attrs_4'} == 1);
  327: 	$r->print("<td bgcolor=$titleclr><b>Language</b></td>\n")
  328: 	    if ($hash{'display_attrs_5'} == 1);
  329: 	$r->print("</tr>");
  330: 
  331: # ----------------- read in what directories have previously been set to "open"
  332: 	foreach (keys %hash) {
  333: 	    if ($_ =~ /^diropen_status_/) {
  334: 		my $key = $_;
  335: 		$key =~ s/^diropen_status_//;
  336: 		$dirs{$key} = $hash{$_};
  337: 	    }
  338: 	}
  339: 
  340: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
  341: 	    my $uri=$ENV{'form.openuri'};
  342: 	    if (exists($hash{'diropen_status_'.$uri})) {
  343: 		my $cursta = $hash{'diropen_status_'.$uri};
  344: 		$dirs{$uri} = 'open';
  345: 		$hash{'diropen_status_'.$uri} = 'open';
  346: 		if ($cursta eq 'open') {
  347: 		    $dirs{$uri} = 'closed';
  348: 		    $hash{'diropen_status_'.$uri} = 'closed';
  349: 		}
  350: 	    } else {
  351: 		$hash{'diropen_status_'.$uri} = 'open';
  352: 		$dirs{$uri} = 'open';
  353: 	    }
  354: 	}
  355: 	
  356: 	my $bredir = $ENV{'form.dirPointer'};
  357: 	my $toplevel;
  358: 	my $indent = 0;
  359: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
  360: 
  361: 	if ($bredir ne "on") {
  362: 	    $hash{'top.level'} = $uri;
  363: 	    $toplevel = $uri;
  364: 
  365: 	} else {
  366: 	    $toplevel = $hash{'top.level'};
  367: 	}
  368: 
  369: # -------------------------------- if not at top level, provide an uplink arrow
  370: 	if ($toplevel ne "/res/"){
  371: 	    my (@uri_com) = split(/\//,$uri);
  372: 	    pop @uri_com;
  373: 	    my $upone = join('/',@uri_com);
  374: 	    my @list = qw (0);
  375: 	    &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
  376: 	    $indent = 1;
  377: 	}
  378: 
  379: # -------- recursively go through all the directories and output as appropriate
  380: 	&scanDir ($r,$toplevel,$indent,\%hash);
  381: 	
  382: # ---------------------------- embed hidden information useful for group import
  383: 	$r->print("<form name='fnum'>");
  384: 	$r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
  385: 
  386: # -------------------------------------------------------------- end the tables
  387: 	$r->print("</table>");
  388: 	$r->print("</td></tr></table>");
  389: 
  390: # --------------------------------------------------- end the output and return
  391: 	$r->print("</body></html>\n");
  392: 	untie(%hash);
  393:     } else {
  394: 	$r->print('<html><head></head><body>Unable to tie hash to db '.
  395: 		  'file</body></html>');
  396: 	return OK;
  397:     }
  398:     return OK;
  399: }
  400: 
  401: # ----------------------------------------------- recursive scan of a directory
  402: sub scanDir {
  403:     my ($r,$startdir,$indent,$hashref)=@_;
  404:     my ($compuri,$curdir);
  405:     my $dirptr=16384;
  406:     $indent++;
  407: 
  408:     my %dupdirs = %dirs;
  409:     my @list=&get_list($r,$startdir);
  410:     foreach my $line (@list) {
  411: 	my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5); 
  412: 	next if $strip =~ /.*\.meta$/;
  413: 	my (@fileparts) = split(/\./,$strip);
  414: 	if ($hash{'display_attrs_6'} != 1) {
  415: 	    if (scalar(@fileparts) >= 3) {
  416: 		my $fext = pop @fileparts;
  417: 		my $ov = pop @fileparts;
  418: 		my $fname = join ('.',@fileparts,$fext);
  419: 		next if (grep /$fname/,@list and $ov =~ /\d+/);
  420: 	    }
  421: 	}
  422: 
  423: 	if ($dom eq "domain") {
  424: 	    $compuri = join('',$strip,"/");  # dom list has /res/<domain name>
  425: 	    $curdir = $compuri;
  426: 	} else {
  427: 	    # user, dir & file have name only, i.e., w/o path
  428: 	    $compuri = join('',$startdir,$strip,"/");
  429: 	    $curdir = $startdir;
  430: 	}
  431: 	my $diropen = "closed";
  432: 	if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
  433: 	    while (my ($key,$val)= each %dupdirs) {
  434: 		if ($key eq $compuri and $val eq "open") {
  435: 		    $diropen = "opened";
  436: 		    delete $dupdirs{key},$dirs{$key};
  437: 		}
  438: 	    }
  439: 	}
  440: 	&display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
  441: 	&scanDir ($r,$compuri,$indent) if $diropen eq "opened";
  442:     }
  443:     $indent--;
  444: }
  445: 
  446: # --------------- get complete matched list based on the uri (returns an array)
  447: sub get_list {
  448:     my ($r,$uri)=@_;
  449:     my @list;
  450:     my $luri = $uri;
  451:     $luri =~ s/\//_/g;
  452: 
  453:     if ($ENV{'form.attrs'} eq "Refresh") {
  454: 	foreach (keys %hash) {
  455: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
  456: 	    }
  457:     }
  458: 
  459:     if ($hash{'dirlist_files'.$luri}) {
  460: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
  461:     } else {
  462: 	@list = &Apache::lonnet::dirlist($uri);
  463: 	$hash{'dirlist_files_'.$luri} = join('\n',@list);
  464:     }
  465:     return @list=&match_ext($r,@list);
  466: }
  467: 
  468: # -------------------- filters out files based on extensions (returns an array)
  469: sub match_ext {
  470:     my ($r,@packlist)=@_;
  471:     my @trimlist;
  472:     my $nextline;
  473:     my @fileext;
  474:     my $dirptr=16384;
  475: 
  476:     foreach my $line (@packlist) {
  477: 	chomp $line;
  478: 	$line =~ s/^\/home\/httpd\/html//;
  479: 	my @unpackline = split (/\&/,$line);
  480: 	next if ($unpackline[0] eq ".");
  481: 	next if ($unpackline[0] eq "..");
  482: 	my @filecom = split (/\./,$unpackline[0]);
  483: 	my $fext = pop(@filecom);
  484: 	my $fnptr = $unpackline[3]&$dirptr;
  485:  	if ($fnptr == 0 and $unpackline[3] ne "") {
  486: 	    my $embstyle = &Apache::loncommon::fileembstyle($fext);
  487:             push @trimlist,$line if (defined($embstyle) && 
  488: 				     ($embstyle ne 'hdn' or $fext eq 'meta'));
  489: 	} else {
  490: 	    push @trimlist,$line;
  491: 	}
  492:     }
  493:     @trimlist = sort (@trimlist);
  494:     return @trimlist;
  495: }
  496: 
  497: # ------------------------------- displays one line in appropriate table format
  498: sub display_line {
  499:     my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
  500:     my (@pathfn, $fndir, $fnptr);
  501:     my $dirptr=16384;
  502:     my $fileclr="#ffffe6";
  503:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
  504: 
  505:     my @filecom = split (/\&/,$line);
  506:     my @pathcom = split (/\//,$filecom[0]);
  507:     my $listname = $pathcom[scalar(@pathcom)-1];
  508:     my $fnptr = $filecom[3]&$dirptr;
  509:     my $msg = 'View '.$filecom[0].' resources';
  510:     $msg = 'Close '.$filecom[0].' directory' if $diropen eq "opened";
  511: 
  512:     my $tabtag="</td>";
  513:     my $i=0;
  514: 
  515:     while ($i<=5) {
  516: 	$tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,">&nbsp;</td>")
  517: 	    if $hash{'display_attrs_'.$i} == 1;
  518: 	$i++;
  519:     }
  520: 
  521: # display uplink arrow
  522:     if ($filecom[1] eq "viewOneUp") {
  523: 	$r->print("<tr>$extrafield");
  524: 	$r->print("<td bgcolor=$fileclr valign=bottom>\n");
  525: 	$r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
  526: 		   '/" '.
  527: 		   'onSubmit="return rep_dirpath(\'UP\','.
  528: 		   'document.forms.fileattr.acts.value)" '.
  529: 		   'enctype="application/x-www-form-urlencoded"'.
  530:                    '>'."\n");
  531: 	$r->print ('<input type=hidden name=openuri value="'.
  532: 		   $startdir.'">'."\n");
  533: 	$r->print ('<input type="hidden" name="acts" value="">'."\n");
  534: 	$r->print ('<input src="'.$iconpath.'arrow_up.gif"');
  535: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  536: 		   "\n");
  537: 	$r->print("Up $tabtag</tr></form>\n");
  538: 	return OK;
  539:     }
  540: 
  541: # display domain
  542:     if ($filecom[1] eq "domain") {
  543: 	$r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
  544: 	    if ($ENV{'form.dirPointer'} eq "on");
  545: 	$r->print("<tr>$extrafield");
  546: 	$r->print("<td bgcolor=$fileclr valign=bottom>");
  547: 	&begin_form ($r,$filecom[0].'/');
  548: 	my $anchor = $filecom[0].'/';
  549: 	$anchor =~ s/\///g;
  550: 	$r->print ('<a name="'.$anchor.'">');
  551: 	$r->print ('<input type="hidden" name="acts" value="">');
  552: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.
  553: 		   $diropen.'.gif"'); 
  554: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  555: 		   "\n");
  556: 	$r->print ('<a href="javascript:gothere(\''.$filecom[0].
  557: 		   '/\')"><img src="'.$iconpath.'server.gif"');
  558: 	$r->print (' border="0" /></a>'."\n");
  559: 	$r->print("Domain - $listname $tabtag</tr></form>\n");
  560: 	return OK;
  561: 
  562: # display user directory
  563:     }
  564:     if ($filecom[1] eq "user") {
  565: 	$r->print("<tr>$extrafield");
  566: 	$r->print("<td bgcolor=$fileclr valign=bottom nowrap>\n");
  567: 	my $curdir = $startdir.$filecom[0].'/';
  568: 	my $anchor = $curdir;
  569: 	$anchor =~ s/\///g;
  570: 	&begin_form ($r,$curdir);
  571: 	$r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
  572: 		   'whitespace1.gif" border="0" />'."\n");
  573: 	$r->print ('<input type="hidden" name="acts" value="">');
  574: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
  575: 		   '.gif"'); 
  576: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  577: 		   "\n");
  578: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
  579: 		   $iconpath.'quill.gif border="0" name="'.$msg.
  580: 		   '" height="22" /></a>');
  581: 	$r->print ($listname.$tabtag.'</tr></form>'."\n");
  582: 	return OK;
  583:     }
  584: 
  585: # display file
  586:     if ($fnptr == 0 and $filecom[3] ne "") {
  587: 	my @file_ext = split (/\./,$listname);
  588: 	my $curfext = $file_ext[-1];
  589: 	# Set the icon for the file
  590: 	my $iconname = "unknown.gif";
  591: 	my $embstyle = &Apache::loncommon::fileembstyle($curfext);
  592: 	# The unless conditional that follows is a bit of overkill
  593: 	$iconname = $curfext.".gif" unless
  594: 	    (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn');
  595: 	#
  596: 	my $filelink = $startdir.$filecom[0];
  597: 	$r->print("<tr><td nowrap valign='bottom' bgcolor=$fileclr>");
  598: 	my $metafile = grep /^$filecom[0]\.meta\&/, @list;
  599: 	my $title;
  600:         if ($ENV{'form.catalogmode'} eq 'interactive') {
  601: 	    $title=$listname;
  602: 	    $title = &Apache::lonnet::metadata($filelink,'title')
  603: 		if ($metafile == 1);
  604: 	    $title=$listname unless $title;
  605: 	    my $titleesc=$title;
  606: 	    $titleesc=~s/\'/\\'/;
  607: 	    $r->print("<a href='javascript:select_data(\"",
  608: 	              $titleesc,'","',$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>