--- loncom/interface/lonindexer.pm 2001/11/29 20:31:45 1.24 +++ loncom/interface/lonindexer.pm 2001/12/11 03:50:09 1.27 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Directory Indexer # -# $Id: lonindexer.pm,v 1.24 2001/11/29 20:31:45 harris41 Exp $ +# $Id: lonindexer.pm,v 1.27 2001/12/11 03:50:09 harris41 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -39,6 +39,7 @@ # 8/6,8/7,8/10 Scott Harrison # 8/14 H. K. Ng # 8/28,10/15,11/28,11/29 Scott Harrison +# 11/30 Matthew Hall # ### @@ -79,10 +80,10 @@ my $dnum; # directory counter sub BEGIN { my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}. '/language.tab'); - map { + while(<$fh>) { $_=~/(\w+)\s+([\w\s\-]+)/; $language{$1}=$2; - } <$fh>; + } } # ----------------------------- Handling routine called via Apache and mod_perl @@ -238,14 +239,14 @@ ENDHEADER my %achash; my $ac=0; # some initial hashes for working with data - map { + foreach (@Acts) { my ($state,$ref)=split(/a/); $ahash{$ref}=$state; $achash{$ref}=$ac; $ac++; - } (@Acts); + } # sorting through the actions and changing the tied database hash - map { + foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) { my $key=$_; if ($ahash{$key} eq '1') { $hash{'store_'.$hash{'pre_'.$key.'_link'}}= @@ -259,9 +260,9 @@ ENDHEADER delete $hash{'store_'.$hash{'pre_'.$key.'_link'}}; } } - } sort {$achash{$a}<=>$achash{$b}} (keys %ahash); + } # deleting the previously cached listing - map { + foreach (keys %hash) { if ($_ =~ /^pre_/ && $_ =~/link$/) { my $key = $_; $key =~ s/^pre_//; @@ -269,7 +270,7 @@ ENDHEADER delete $hash{'pre_'.$key.'_title'}; delete $hash{'pre_'.$key.'_link'}; } - } keys %hash; + } } # ---------------------------------------------------------------- output title @@ -334,13 +335,13 @@ END $r->print(""); # ----------------- read in what directories have previously been set to "open" - map { + foreach (keys %hash) { if ($_ =~ /^diropen_status_/) { my $key = $_; $key =~ s/^diropen_status_//; $dirs{$key} = $hash{$_}; } - } keys %hash; + } if ($ENV{'form.openuri'}) { # take care of review and refresh options my $uri=$ENV{'form.openuri'}; @@ -456,9 +457,9 @@ sub get_list { $luri =~ s/\//_/g; if ($ENV{'form.attrs'} eq "Refresh") { - map { + foreach (keys %hash) { delete $hash{$_} if ($_ =~ /^dirlist_files_/); - } keys %hash; + } } if ($hash{'dirlist_files'.$luri}) { @@ -478,16 +479,6 @@ sub match_ext { 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 my $line (@content) { - (my $ext,my $foo) = split /\s+/,$line; - push @fileext,$ext; - } - } foreach my $line (@packlist) { chomp $line; $line =~ s/^\/home\/httpd\/html//; @@ -498,9 +489,9 @@ sub match_ext { my $fext = pop(@filecom); my $fnptr = $unpackline[3]&$dirptr; if ($fnptr == 0 and $unpackline[3] ne "") { - foreach my $nextline (@fileext) { - push @trimlist,$line if $nextline eq $fext; - } + my $embstyle = &Apache::lonnet::fileembstyle($fext); + push @trimlist,$line if (defined($embstyle) && + $embstyle ne 'hdn' ); } else { push @trimlist,$line; } @@ -600,7 +591,14 @@ sub display_line { # display file if ($fnptr == 0 and $filecom[3] ne "") { my @file_ext = split (/\./,$listname); - my $curfext = $file_ext[scalar(@file_ext)-1]; + my $curfext = $file_ext[-1]; + # Set the icon for the file + my $iconname = "unknown.gif"; + my $embstyle = &Apache::lonnet::fileembstyle($curfext); + # The unless conditional that follows is a bit of overkill + $iconname = $curfext.".gif" unless + (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn'); + # my $filelink = $startdir.$filecom[0]; $r->print(""); my $metafile = grep /^$filecom[0]\.meta\&/, @list; @@ -654,7 +652,7 @@ sub display_line { ".gif border='0' />\n") if $rem > 0; } - $r->print("\n"); + $r->print("\n"); $r->print (" $listname "); @@ -755,27 +753,27 @@ sub begin_form { # ----------- grab unprocessed CGI variables that may have been appended to URL sub get_unprocessed_cgi { - map { + foreach (split(/&/,$ENV{'QUERY_STRING'})) { my ($name, $value) = split(/=/,$_); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') { $ENV{'form.'.$name}=$value; } - } (split(/&/,$ENV{'QUERY_STRING'})); + } } # --------- settings whenever the user causes the indexer window to be launched sub start_fresh_session { delete $hash{'mode_catalog'}; - map { + foreach (keys %hash) { if ($_ =~ /^pre_/) { delete $hash{$_}; } if ($_ =~ /^store/) { delete $hash{$_}; } - } keys %hash; + } } 1;