--- loncom/homework/Attic/lonindexer.pm 2000/02/22 21:33:18 1.1 +++ loncom/homework/Attic/lonindexer.pm 2000/08/02 12:20:28 1.2 @@ -33,6 +33,269 @@ 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("
"); + $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?'; @@ -41,9 +304,10 @@ 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__ +