--- loncom/homework/Attic/lonindexer.pm 2000/02/22 21:33:18 1.1 +++ loncom/homework/Attic/lonindexer.pm 2000/08/04 19:24:12 1.4 @@ -3,6 +3,7 @@ # (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 +# 07/20-08/04 H.K. Ng # package Apache::lonindexer; @@ -33,6 +34,312 @@ sub handler { 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
+
+ + + + + + + + +
SizeLast accessLast modified
AuthorKeywordsLanguage
+ + + +
+END + my $titleclr="#ddffff"; + my $fileclr="#ffffdd"; + + $r->print("
\n"); + $r->print("\n"); + $r->print("\n"); + $r->print("\n") if ($ENV{'form.attr0'} == 1); + $r->print("\n") if ($ENV{'form.attr1'} == 1); + $r->print("\n") if ($ENV{'form.attr2'} == 1); + $r->print(""); + + if ($ENV{'form.openuri'} =~ /$uri\&/) { + my @pathcom = split(/\//,$uri); + pop @pathcom; + my $splituri = join ('/',@pathcom); + $uri = join ('',$splituri,"/"); + } + + + my $openuri = $ENV{'form.openuri'}; +# $r->print ("
openuri=$openuri
"); + $openuri =~ s/$uri(.*)\&//g; +# $r->print ("
parsed openuri=$openuri
"); + @openpath = split(/\&/,$openuri); +# $r->print ("
open path=@openpath
"); + push @openpath, $uri; +# $r->print ("
append current uri to open path=@openpath
"); + @openpath = sort @openpath; +# $r->print ("
sorted open path=@openpath
"); + + + my $indent = -1; + &display_line ($r,1,"/res/".$domain."&domain"); + &branch ($r,"/res/".$domain."/",$indent,@openpath); + + $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,$indent,@openuri)=@_; + my ($calluri,$line,@list); + my ($domusr,$foo,$strip,$testdir,$compuri,$chkdir,$diropen); + my $dirptr=16384; + $indent++; + + foreach $calluri (@openuri) { + @list=&get_list($r,$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,$indent); + + my @securi; + push @securi,$calluri; + &branch($r,$compuri,$indent,@securi) if ($calluri =~ $compuri and $calluri=~/^$uri/ and $chkdir == $dirptr and $testdir ne ""); + } + } + $indent--; +} + +# ------ get complete list based on the uri ------ +sub get_list { + my ($r,$uri)=@_; + my @list; + my $luri=$uri; + $luri=~s/\//_/g; + unlink "/home/httpd/perl/tmp/$ENV{'user.name'}_dirlist*.tmp" if ($ENV{'form.dirlistattr'} eq "Refresh"); + 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($r,@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 ($r,@packlist)=@_; + my $line; + my @trimlist; + my $nextline; + my @fileext; + my $dirptr=16384; + + my $tabdir = $r->dir_config('lonTabDir'); + my $fn = $tabdir."/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,$indent)=@_; + my (@pathfn, $fndir, $fnptr); + my $dirptr=16384; + my $fileclr="#ffffe6"; + 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 $tabtag=""; + my $nextline; + my $i=0; + + while ($i<=5) { + my $key="form.attr".$i; + $tabtag=join('',$tabtag," ") if $ENV{$key} == 1; + $i++; + } + + if ($filecom[1] eq "domain") { + $r->print(""); + $r->print(""); + &begin_form ($r,$filecom[0]); + $r->print ("print ("comp.blue.gif\""); + $r->print (" name=\"submit\" height=\"22\" type=\"image\" border=\"0\">\n"); + $r->print("Domain - $listname $tabtag\n"); + return OK; + } + + if ($filecom[1] eq "user") { + $r->print(""); + $r->print("\n"); + &begin_form ($r,$filecom[0]); + my $count = 0; + while ($count <= $indent) { + $r->print("\n"); + $count++; + } + $r->print ("print ("folder_pointer_closed.gif\"") if $diropen == 0; + $r->print ("folder_pointer_opened.gif\"") if $diropen == 1; + $r->print (" name=\"submit\" height=\"22\" type=\"image\" border=\"0\">\n"); + $r->print("\n"); + $r->print("$listname $tabtag\n"); + 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 <= $indent) { + $r->print("\n"); + $count++; + } + $r->print("\n"); + $r->print("\n"); + $r->print(" ",$listname," \n"); + $r->print(" ",$filecom[8]," \n") if $ENV{'form.attr0'} == 1; + $r->print(" ".(localtime($filecom[9]))." \n") if $ENV{'form.attr1'} == 1; + $r->print(" ".(localtime($filecom[10]))." \n") if $ENV{'form.attr2'} == 1; + $r->print("\n"); + } + +# display directory + if ($fnptr == $dirptr) { + my @file_ext = split (/\./,$listname); + my $curfext = $file_ext[scalar(@file_ext)-1]; + $r->print(""); + &begin_form ($r,$filecom[0]); + + my $count = 0; + while ($count <= $indent) { + $r->print("\n"); + $count++; + } + + $r->print ("print ("folder_pointer_closed.gif\"") if $diropen == 0; + $r->print ("folder_pointer_opened.gif\"") if $diropen == 1; + $r->print (" name=\"submit\" height=\"22\" type=\"image\" border=\"0\">\n"); + $r->print("\n") if $diropen == 0; + $r->print("\n") if $diropen == 1; + $r->print("$listname $tabtag\n"); + } +} + +sub begin_form { + my ($r,$uri) = @_; + my $currenturi = $r->uri; + my $openuri = $ENV{'form.openuri'}; + if ($ENV{'form.openuri'} =~ /$currenturi(.*)\&/) { + $openuri =~ s/$currenturi(.*)\&//g; + } else { + $currenturi = join ('',$currenturi,"&"); + $openuri = join ('&',$ENV{'form.openuri'},$currenturi); + $openuri =~ s/\&+/\&/g; + } + $r->print ("
\n"); + $r->print ("\n"); + + for (my $i=0; $i<=5; $i++) { + $r->print ("\n") if $ENV{'form.attr'.$i} == 1; + } +} + +sub display_env { + my $r=shift; my %otherenv; $otherenv{'hi'}='there'; $otherenv{'does_this'}='work?'; @@ -41,9 +348,9 @@ ENDHEADER foreach $envkey (sort keys %ENV) { $r->print("$envkey: $ENV{$envkey}
\n"); } - $r->print("\n"); - return OK; -} +# $r->print("
".&Apache::lonnet::ssi('/res/msu/korte/test.tex')); +# $r->print("
".join('
',&Apache::lonnet::dirlist('/res/msu/korte/'))); +} 1; __END__