--- loncom/interface/lonindexer.pm 2000/08/28 21:07:32 1.1 +++ loncom/interface/lonindexer.pm 2001/05/18 21:10:48 1.2 @@ -5,11 +5,26 @@ # 11/23 Gerd Kortemeyer # 07/20-08/04 H.K. Ng # +# 05/9-05/19/2001 H. K. Ng +# package Apache::lonindexer; use strict; use Apache::lonnet(); use Apache::Constants qw(:common); +use Apache::File; +use GDBM_File; + +my %dirs; +my %language; + +sub BEGIN { + my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/language.tab'); + map { + $_=~/(\w+)\s+([\w\s\-]+)/; + $language{$1}=$2; + } <$fh>; +} sub handler { my $r = shift; @@ -30,7 +45,16 @@ sub handler { $r->print(< -The LearningOnline Network Directory Browser +The LearningOnline Network With CAPA Directory Browser + ENDHEADER @@ -40,113 +64,119 @@ ENDHEADER my $uri=$r->uri; my $iconpath="/res/adm/pages/indexericons/"; - $r->print("

The LearningOnline Network Directory Browser

\n"); + $r->print("

The LearningOnline With CAPA 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
+Display file attributes
- - - + + + - - - + + +
SizeLast accessLast modified Size Last access Last modified
AuthorKeywordsLanguage Author Keywords Language
- - + 
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 $diropen = "/home/httpd/perl/tmp/$domain$ENV{'user.name'}_diropen.db"; + if (tie(%dirs,'GDBM_File',$diropen,&GDBM_WRCREAT,0640)) { + my $titleclr="#ddffff"; +# my $fileclr="#ffffdd"; + $r->print("
NameSize (bytes) Last accessedLast modified
\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("\n") if ($ENV{'form.attr3'} == 1); + $r->print("\n") if ($ENV{'form.attr4'} == 1); + $r->print("\n") if ($ENV{'form.attr5'} == 1); + $r->print(""); + + if ($ENV{'form.openuri'}) { # take care of review and refresh options + my $uri=$ENV{'form.openuri'}; + if (exists($dirs{$uri})) { + my $cursta = $dirs{$uri}; + $dirs{$uri} = 'open'; + $dirs{$uri} = 'closed' if $cursta eq 'open'; + } else { + $dirs{$uri} = 'open'; + } + } - 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 modifiedAuthor(s)KeywordsLanguage
"); - $r->print("
"); - $r->print("\n"); -# &display_env($r); + sort keys %dirs; + my $toplevel = "/res/"; + my $indent = -1; + &scanDir ($r,$toplevel,$indent); + + $r->print("
"); + $r->print(""); + $r->print("\n"); + untie(%dirs); + } else { + $r->print("Unable to tie hash to db file"); + } 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; + +# --------------------recursive scan of a directory +sub scanDir { + my ($r,$startdir,$indent)=@_; + my $compuri; $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 ""); + my %dupdirs = %dirs; + sort keys %dupdirs; + my @list=&get_list($r,$startdir); + foreach my $line (@list) { + my ($strip,$domusr,$foo,$testdir,$foo)=split(/\&/,$line,5); + if ($domusr eq "domain") { + $compuri=join('',$strip,"/"); # domain list has /res/ + } else { + $compuri = join('',$startdir,$strip,"/"); # user, dir & file having name only, i.e., w/o path + } + my $diropen = 0; + &display_line($r,$diropen,$line,$indent,$strip."/") if $domusr eq "domain"; + while (my ($key,$val)= each %dupdirs) { + $diropen = 1 if ($key eq $compuri and $val eq "open"); } + &display_line($r,$diropen,$line,$indent,$startdir) if ($domusr ne "domain"); + &scanDir ($r,$compuri,$indent) if $diropen == 1; } $indent--; } -# ------ get complete list based on the uri ------ +# ----------------- get complete matched 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"; + my $luri = $uri; + my $domain = $r->dir_config('lonDefDomain'); + $luri =~ s/\//_/g; + + if ($ENV{'form.dirlistattr'} eq "Refresh") { + my $tmpdir="/home/httpd/perl/tmp"; + my $filename; + opendir(DIR,$tmpdir); + while ($filename=readdir(DIR)) { + if ($filename=~/^$domain$ENV{'user.name'}_dirlist.*\.tmp$/) { + unlink($tmpdir.'/'.$filename); + } + } + closedir(DIR); + } + + my $dirlist = "/home/httpd/perl/tmp/$domain$ENV{'user.name'}_dirlist$luri.tmp"; if (-e $dirlist) { my $FH = Apache::File->new($dirlist); @list=<$FH>; @@ -155,42 +185,13 @@ sub get_list { my $FH = Apache::File->new(">$dirlist"); print $FH join("\n",@list); } + @list = sort(@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; -} - +#-------------------------- filters out files based on extensions sub match_ext { my ($r,@packlist)=@_; - my $line; my @trimlist; my $nextline; my @fileext; @@ -201,33 +202,35 @@ sub match_ext { if (-e $fn) { my $FH=Apache::File->new($fn); my @content=<$FH>; - foreach $line (@content) { + foreach my $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; + foreach my $line (@packlist) { + chomp $line; + $line =~ s/^\/home\/httpd\/html//; + my @unpackline = split (/\&/,$line); + next if ($unpackline[0] eq "."); + next if ($unpackline[0] eq ".."); + my @filecom = split (/\./,$unpackline[0]); + my $fext = pop(@filecom); + next if $fext eq "meta"; + my $fnptr = $unpackline[3]&$dirptr; + if ($fnptr == 0 and $unpackline[3] ne "") { + foreach my $nextline (@fileext) { + push @trimlist,$line if $nextline eq $fext; } } else { - push @trimlist,$strip; + push @trimlist,$line; } } return @trimlist; } +#------------------- displays one line in appropriate table format sub display_line{ - my ($r,$diropen,$line,$indent)=@_; + my ($r,$diropen,$line,$indent,$startdir)=@_; my (@pathfn, $fndir, $fnptr); my $dirptr=16384; my $fileclr="#ffffe6"; @@ -239,7 +242,6 @@ sub display_line{ my $fnptr = $filecom[3]&$dirptr; my $tabtag=""; - my $nextline; my $i=0; while ($i<=5) { @@ -247,64 +249,82 @@ sub display_line{ $tabtag=join('',$tabtag," ") if $ENV{$key} == 1; $i++; } - if ($filecom[1] eq "domain") { $r->print(""); $r->print(""); - &begin_form ($r,$filecom[0]); + &begin_form ($r,$filecom[0].'/'); $r->print ("print ("comp.blue.gif\""); - $r->print (" name=\"submit\" height=\"22\" type=\"image\" border=\"0\">\n"); + $r->print (" name=\"View $filecom[0]/ resources\" 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++; - } + my $curdir = $startdir.$filecom[0].'/'; + &begin_form ($r,$curdir); + $r->print("\n"); $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 (" name=\"View $curdir resources\" 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 $filelink = $startdir.$filecom[0]; my $count = 0; $r->print(""); - while ($count <= $indent) { + while ($count < $indent) { $r->print("\n"); $count++; } $r->print("\n"); $r->print("\n"); - $r->print(" ",$listname," \n"); + $r->print(" ",$listname,""); + my $metafile = '/home/httpd/html'.$filelink.'.meta'; + + $r->print (" (metadata) ") if (-e $metafile); + +# $r->print(" (metadata)") if (-e $metafile); + $r=>print("\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; + + if ($ENV{'form.attr3'} == 1) { + my $author = &Apache::lonnet::metadata($filelink,'author'); + $author = ' ' if (!$author); + $r->print(" ".$author." \n"); + } + if ($ENV{'form.attr4'} == 1) { + my $keywords = &Apache::lonnet::metadata($filelink,'keywords'); + $keywords = ' ' if (!$keywords); + $r->print(" ".$keywords." \n"); + } + if ($ENV{'form.attr5'} == 1) { + my $lang = &Apache::lonnet::metadata($filelink,'language'); + $lang = $language{$lang}; + $lang = ' ' if (!$lang); + $r->print(" ".$lang." \n"); + } $r->print("\n"); } - -# display directory +# -- display directory if ($fnptr == $dirptr) { my @file_ext = split (/\./,$listname); my $curfext = $file_ext[scalar(@file_ext)-1]; + my $curdir = $startdir.$filecom[0].'/'; $r->print(""); - &begin_form ($r,$filecom[0]); + &begin_form ($r,$curdir); my $count = 0; - while ($count <= $indent) { + while ($count < $indent) { $r->print("\n"); $count++; } @@ -312,45 +332,25 @@ sub display_line{ $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 (" name=\"View $curdir resources\" height=\"22\" type=\"image\" border=\"0\">\n"); $r->print("\n") if $diropen == 0; $r->print("\n") if $diropen == 1; $r->print("$listname $tabtag\n"); } + } +#---------------------prints the beginning of a form for directory or file link 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"); + + $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?'; - &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__