# The LearningOnline Network with CAPA # Directory Indexer # (Login Screen # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer) # 11/23 Gerd Kortemeyer # package Apache::lonindexer; use strict; use Apache::lonnet(); use Apache::Constants qw(:common); sub handler { my $r = shift; $r->content_type('text/html'); $r->send_http_header; return OK if $r->header_only; my $iconpath= $r->dir_config('lonIconsURL'); my $domain = $r->dir_config('lonDefDomain'); my $role = $r->dir_config('lonRole'); my $loadlim = $r->dir_config('lonLoadLim'); my $servadm = $r->dir_config('lonAdmEMail'); my $sysadm = $r->dir_config('lonSysEMail'); my $lonhost = $r->dir_config('lonHostID'); my $tabdir = $r->dir_config('lonTabDir'); # ---------------------------------------------------------------- Print Header $r->print(< The LearningOnline Network Directory Browser ENDHEADER my $line; my (@attrchk,@openpath); my $uri=$r->uri; my $iconpath="/res/adm/pages/indexericons/"; $r->print("

The LearningOnline Network Directory Browser

\n"); for (my $i=0; $i<=5; $i++) { $attrchk[$i] = "checked" if $ENV{'form.attr'.$i} == 1; } $r->print(<Display file attributes
Size Last access Last modified
Author Keywords Language
END my $titleclr="#ddffff"; my $fileclr="#ffffdd"; $r->print("
"); $r->print(""); $r->print("\n"); $r->print("") if ($ENV{'form.attr0'} == 1); $r->print("") if ($ENV{'form.attr1'} == 1); $r->print("") if ($ENV{'form.attr2'} == 1); $r->print(""); if ($ENV{'dirlist.lvl'} eq "") { my %dirlvl; $dirlvl{'dirlist.lvl'}='-2'; &Apache::lonnet::appenv(%dirlvl); } else { $ENV{'dirlist.lvl'}='-2'; } # $r->print ("original uri=$uri"); my $uri = &get_openpath($uri); # $r->print ("shortened uri=$shorturi"); my $domain="/res/"; &branch($r,$domain,$uri); $r->print("
NameSize (bytes)Last accessedLast modified
"); $r->print("
"); $r->print("\n"); # &display_env($r); return OK; } # my @packlist=&Apache::lonnet::dirlist($uri); # print "Dir list
".join('
',@packlist)."
"; sub branch { my ($r,$uri,$calluri)=@_; my ($line,@list); my ($domusr,$foo,$strip,$testdir,$compuri,$chkdir,$diropen); my $dirptr=16384; # my $calluri=$r->uri; $ENV{'dirlist.lvl'}++; @list=&get_list($uri); foreach $line (@list) { chomp $line; ($strip,$domusr,$foo,$testdir,$foo)=split(/\&/,$line,5); $compuri=join("",$strip,"/"); $chkdir=$testdir&$dirptr; if ($domusr eq "domain" or $domusr eq "user") { $chkdir = $dirptr; $testdir = $dirptr; } $diropen = 0; $diropen = 1 if ($compuri eq $calluri); &display_line($r,$diropen,$line); &branch($r,$compuri,$calluri) if ($calluri =~ $compuri and $calluri=~/^$uri/ and $chkdir == $dirptr and $testdir ne ""); } $ENV{'dirlist.lvl'}--; } # ------ get complete list based on the uri ------ sub get_list { my $uri=shift; my @list; my $luri=$uri; $luri=~s/\//_/g; my $dirlist = "/home/httpd/perl/tmp/$ENV{'user.name'}_dirlist$luri.tmp"; if (-e $dirlist) { my $FH = Apache::File->new($dirlist); @list=<$FH>; } else { @list=&Apache::lonnet::dirlist($uri); my $FH = Apache::File->new(">$dirlist"); print $FH join("\n",@list); } return @list=&match_ext(@list); } # ------ get previously opened path, if any ------ sub get_openpath { my $uri=shift; my @list; my $openlist = "/home/httpd/perl/tmp/$ENV{'user.name'}_dirlist_open_path.tmp"; if (-e $openlist) { my $FH = Apache::File->new($openlist); @list=<$FH>; close ($FH); my $line; my $FH = Apache::File->new(">$openlist"); print $FH "$uri\n" if $list[0] eq ""; foreach $line (@list) { chomp $line; if ($line eq $uri) { my @pathcom = split(/\//,$uri); pop @pathcom; my $splituri = join ('/',@pathcom); $uri = join ('',$splituri,"/"); } else { print $FH "$line\n"; } } } else { my $FH = Apache::File->new(">$openlist"); print $FH "$uri\n"; } return $uri; } sub match_ext { my @packlist=@_; my $line; my @trimlist; my $nextline; my @fileext; my $dirptr=16384; my $fn="/home/httpd/lonTabs/filetypes.tab"; if (-e $fn) { my $FH=Apache::File->new($fn); my @content=<$FH>; foreach $line (@content) { (my $ext,my $foo) = split /\s+/,$line; push @fileext,$ext; } } foreach $line (@packlist) { my ($foo,$strip) = split(/\/html/,$line); my @unpacklist = split (/\&/,$strip); my @pathfn = split (/\//,$unpacklist[0]); my $fndir = $pathfn[scalar(@pathfn)-1]; my @filecom = split (/\./,$fndir); my $curfext = $filecom[scalar(@filecom)-1]; my $fnptr = $unpacklist[3]&$dirptr; if ($fnptr == 0 and $unpacklist[3] ne "") { foreach $nextline (@fileext) { push @trimlist,$strip if $nextline eq $curfext; } } else { push @trimlist,$strip; } } return @trimlist; } sub display_line{ my ($r,$diropen,$line)=@_; my (@pathfn, $fndir, $fnptr, $disattr); my $dirptr=16384; my $fileclr="#ffffdd"; my $iconpath="/res/adm/pages/indexericons/"; my @filecom = split (/\&/,$line); my @pathcom = split (/\//,$filecom[0]); my $listname = $pathcom[scalar(@pathcom)-1]; my $fnptr = $filecom[3]&$dirptr; my $indent = $ENV{'dirlist.lvl'}; my $tabtag=""; my $nextline; my $i=0; while ($i<=5) { my $key="form.attr".$i; $i++; $tabtag=join('',$tabtag," ") if $ENV{$key} == 1; } if ($filecom[1] eq "domain") { $r->print(""); $r->print("\n"); $r->print("Domain - $listname $tabtag"); return OK; } if ($filecom[1] eq "user") { $r->print(""); $r->print("\n"); my $count = 0; while ($count <= $ENV{'dirlist.lvl'}) { $r->print("\n"); $count++; } $r->print("print("right.gif border=0>\n") if $diropen == 0; $r->print("down.gif border=0>\n") if $diropen == 1; $r->print("\n"); $r->print("$listname $tabtag"); return OK; } # display file if ($fnptr == 0 and $filecom[3] ne "") { my @file_ext = split (/\./,$listname); my $curfext = $file_ext[scalar(@file_ext)-1]; my $count = 0; $r->print(""); while ($count <= $ENV{'dirlist.lvl'}) { $r->print("\n"); $count++; } $r->print("\n"); $r->print("\n"); $r->print(" ",$listname," "); $r->print(" ",$filecom[8]," ") if $ENV{'form.attr0'} == 1; $r->print(" ".(localtime($filecom[9]))." ") if $ENV{'form.attr1'} == 1; $r->print(" ".(localtime($filecom[10]))." ") if $ENV{'form.attr2'} == 1; $r->print(""); } # display directory if ($fnptr == $dirptr) { my @file_ext = split (/\./,$listname); my $curfext = $file_ext[scalar(@file_ext)-1]; $r->print(""); my $count = 0; while ($count <= $ENV{'dirlist.lvl'}) { $r->print("\n"); $count++; } $r->print("print("right.gif border=0>\n") if $diropen == 0; $r->print("down.gif border=0>\n") if $diropen == 1; $r->print("\n") if $diropen == 0; $r->print("\n") if $diropen == 1; $r->print("$listname $tabtag"); } } sub display_env { my $r=shift; my %otherenv; $otherenv{'hi'}='there'; $otherenv{'does_this'}='work?'; &Apache::lonnet::appenv(%otherenv); my $envkey; foreach $envkey (sort keys %ENV) { $r->print("$envkey: $ENV{$envkey}
\n"); } # $r->print("
".&Apache::lonnet::ssi('/res/msu/korte/test.tex')); # $r->print("
".join('
',&Apache::lonnet::dirlist('/res/msu/korte/'))); } 1; __END__