Diff for /loncom/interface/lonindexer.pm between versions 1.3 and 1.4

version 1.3, 2001/05/19 14:31:45 version 1.4, 2001/05/21 15:22:48
Line 6 Line 6
 # 07/20-08/04 H.K. Ng  # 07/20-08/04 H.K. Ng
 #  #
 # 05/9-05/19/2001 H. K. Ng  # 05/9-05/19/2001 H. K. Ng
   # 05/21/2001 H. K. Ng
 #  #
 package Apache::lonindexer;  package Apache::lonindexer;
   
Line 15  use Apache::Constants qw(:common); Line 16  use Apache::Constants qw(:common);
 use Apache::File;  use Apache::File;
 use GDBM_File;  use GDBM_File;
   
   my %hash;
 my %dirs;  my %dirs;
 my %language;  my %language;
   
Line 88  ENDHEADER Line 90  ENDHEADER
 </form>  </form>
 END  END
   
     my $diropen = "/home/httpd/perl/tmp/$domain$ENV{'user.name'}_diropen.db";      my $diropen = "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_diropen.db";
   
     if (tie(%dirs,'GDBM_File',$diropen,&GDBM_WRCREAT,0640)) {      if (tie(%hash,'GDBM_File',$diropen,&GDBM_WRCREAT,0640)) {
  my $titleclr="#ddffff";   my $titleclr="#ddffff";
  $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");   $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
  $r->print("<table border=0><tr>\n");   $r->print("<table border=0><tr>\n");
Line 103  END Line 105  END
  $r->print("<td bgcolor=$titleclr><b>Language</b></td>\n") if ($ENV{'form.attr5'} == 1);   $r->print("<td bgcolor=$titleclr><b>Language</b></td>\n") if ($ENV{'form.attr5'} == 1);
  $r->print("</tr>");   $r->print("</tr>");
   
    map {
       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   if ($ENV{'form.openuri'}) {  # take care of review and refresh options
     my $uri=$ENV{'form.openuri'};      my $uri=$ENV{'form.openuri'};
     if (exists($dirs{$uri})) {      if (exists($hash{'diropen_status_'.$uri})) {
  my $cursta = $dirs{$uri};   my $cursta = $hash{'diropen_status_'.$uri};
  $dirs{$uri} = 'open';   $dirs{$uri} = 'open';
  $dirs{$uri} = 'closed' if $cursta eq 'open';   $hash{'diropen_status_'.$uri} = 'open';
    if ($cursta eq 'open') {
       $dirs{$uri} = 'closed';
       $hash{'diropen_status_'.$uri} = 'closed';
    }
     } else {      } else {
    $hash{'diropen_status_'.$uri} = 'open';
  $dirs{$uri} = 'open';   $dirs{$uri} = 'open';
     }      }
  }   }
  sort keys %dirs;  
   
  my $toplevel = "/res/";   my $toplevel = "/res/";
  my $indent = -1;   my $indent = 0;
  &scanDir ($r,$toplevel,$indent);   &scanDir ($r,$toplevel,$indent);
   
  $r->print("</table>");   $r->print("</table>");
  $r->print("</td></tr></table>");   $r->print("</td></tr></table>");
  $r->print("</body></html>\n");   $r->print("</body></html>\n");
  untie(%dirs);   untie(%hash);
     } else {      } else {
  $r->print("Unable to tie hash to db file");   $r->print("Unable to tie hash to db file");
     }      }
Line 140  sub scanDir { Line 154  sub scanDir {
     my @list=&get_list($r,$startdir);      my @list=&get_list($r,$startdir);
     foreach my $line (@list) {      foreach my $line (@list) {
  my ($strip,$domusr,$foo,$testdir,$foo)=split(/\&/,$line,5);    my ($strip,$domusr,$foo,$testdir,$foo)=split(/\&/,$line,5); 
    next if $strip =~ /.*\.meta$/;
  if ($domusr eq "domain") {   if ($domusr eq "domain") {
     $compuri = join('',$strip,"/");  # domain list has /res/<domain name>      $compuri = join('',$strip,"/");  # domain list has /res/<domain name>
     $curdir = $compuri;      $curdir = $compuri;
Line 153  sub scanDir { Line 168  sub scanDir {
  $diropen = 1 if ($key eq $compuri and $val eq "open");   $diropen = 1 if ($key eq $compuri and $val eq "open");
     }      }
  }   }
  &display_line($r,$diropen,$line,$indent,$curdir);   &display_line($r,$diropen,$line,$indent,$curdir,@list);
  &scanDir ($r,$compuri,$indent) if $diropen == 1;   &scanDir ($r,$compuri,$indent) if $diropen == 1;
     }      }
     $indent--;      $indent--;
Line 164  sub get_list { Line 179  sub get_list {
     my ($r,$uri)=@_;      my ($r,$uri)=@_;
     my @list;      my @list;
     my $luri = $uri;      my $luri = $uri;
     my $domain  = $r->dir_config('lonDefDomain');  
     $luri =~ s/\//_/g;      $luri =~ s/\//_/g;
   
     if ($ENV{'form.dirlistattr'} eq "Refresh") {      if ($ENV{'form.dirlistattr'} eq "Refresh") {
  my $tmpdir="/home/httpd/perl/tmp";   map {
  my $filename;      delete $hash{$_} if ($_ =~ /^dirlist_files_/);
  opendir(DIR,$tmpdir);      } keys %hash;
  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 ($hash{'dirlist_files'.$luri}) {
     if (-e $dirlist) {   @list = split(/\n/,$hash{'dirlist_files_'.$luri});
  my $FH = Apache::File->new($dirlist);  
  @list=<$FH>;  
     } else {      } else {
  @list=&Apache::lonnet::dirlist($uri);   @list = &Apache::lonnet::dirlist($uri);
  my $FH = Apache::File->new(">$dirlist");   $hash{'dirlist_files_'.$luri} = join('\n',@list);
  print $FH join("\n",@list);  
     }      }
     @list = sort(@list);  
     return @list=&match_ext($r,@list);      return @list=&match_ext($r,@list);
 }  }
   
Line 218  sub match_ext { Line 222  sub match_ext {
  next if ($unpackline[0] eq "..");   next if ($unpackline[0] eq "..");
  my @filecom = split (/\./,$unpackline[0]);   my @filecom = split (/\./,$unpackline[0]);
  my $fext = pop(@filecom);   my $fext = pop(@filecom);
  next if $fext eq "meta";  
  my $fnptr = $unpackline[3]&$dirptr;   my $fnptr = $unpackline[3]&$dirptr;
   if ($fnptr == 0 and $unpackline[3] ne "") {    if ($fnptr == 0 and $unpackline[3] ne "") {
     foreach my $nextline (@fileext) {      foreach my $nextline (@fileext) {
Line 228  sub match_ext { Line 231  sub match_ext {
     push @trimlist,$line;      push @trimlist,$line;
  }   }
     }      }
       @trimlist = sort (@trimlist);
     return @trimlist;      return @trimlist;
 }  }
   
 #------------------- displays one line in appropriate table format  #------------------- displays one line in appropriate table format
 sub display_line{  sub display_line{
     my ($r,$diropen,$line,$indent,$startdir)=@_;      my ($r,$diropen,$line,$indent,$startdir,@list)=@_;
     my (@pathfn, $fndir, $fnptr);      my (@pathfn, $fndir, $fnptr);
     my $dirptr=16384;      my $dirptr=16384;
     my $fileclr="#ffffe6";      my $fileclr="#ffffe6";
Line 243  sub display_line{ Line 247  sub display_line{
     my @pathcom = split (/\//,$filecom[0]);      my @pathcom = split (/\//,$filecom[0]);
     my $listname = $pathcom[scalar(@pathcom)-1];      my $listname = $pathcom[scalar(@pathcom)-1];
     my $fnptr = $filecom[3]&$dirptr;      my $fnptr = $filecom[3]&$dirptr;
       my $msg = 'View '.$filecom[0].' resources';
       $msg = 'Close '.$filecom[0].' directory' if $diropen == 1;
   
     my $tabtag="</td>";      my $tabtag="</td>";
     my $i=0;      my $i=0;
Line 259  sub display_line{ Line 265  sub display_line{
  my $anchor = $filecom[0].'/';   my $anchor = $filecom[0].'/';
  $anchor =~ s/\///g;   $anchor =~ s/\///g;
  $r->print ("<a name=\"".$anchor."\">\n<input src=\"".$iconpath."comp.blue.gif\"");   $r->print ("<a name=\"".$anchor."\">\n<input src=\"".$iconpath."comp.blue.gif\"");
  $r->print (" name=\"View $filecom[0]/ resources\" height=\"22\" type=\"image\" border=\"0\">\n");   $r->print (" name=\"$msg\" height=\"22\" type=\"image\" border=\"0\">\n");
  $r->print("Domain - $listname $tabtag</tr></form>\n");   $r->print("Domain - $listname $tabtag</tr></form>\n");
  return OK;   return OK;
     }      }
Line 270  sub display_line{ Line 276  sub display_line{
  &begin_form ($r,$curdir);   &begin_form ($r,$curdir);
  my $anchor = $curdir;   my $anchor = $curdir;
  $anchor =~ s/\///g;   $anchor =~ s/\///g;
  $r->print ("<a name=\"$anchor\">\n<img src=",$iconpath,"white_space_20_22.gif border=0>\n");  # $r->print ("<a name=\"$anchor\">\n<img src=",$iconpath,"white_space_20_22.gif border=0>\n");
    $r->print ("<a name=\"$anchor\">\n<img src=",$iconpath,"whitespace1.gif border=0>\n");
  $r->print ("<input src=\"$iconpath");   $r->print ("<input src=\"$iconpath");
  $r->print ("folder_pointer_closed.gif\"") if $diropen == 0;   $r->print ("folder_pointer_closed.gif\"") if $diropen == 0;
  $r->print ("folder_pointer_opened.gif\"") if $diropen == 1;   $r->print ("folder_pointer_opened.gif\"") if $diropen == 1;
  $r->print (" name=\"View $curdir resources\" height=\"22\" type=\"image\" border=\"0\">\n");   $r->print (" name=\"$msg\" height=\"22\" type=\"image\" border=\"0\">\n");
  $r->print ("<img src=",$iconpath,"quill.gif border=0>\n");   $r->print ("<img src=",$iconpath,"quill.gif border=0>\n");
  $r->print ("$listname $tabtag</tr></form>\n");   $r->print ("$listname $tabtag</tr></form>\n");
  return OK;   return OK;
Line 284  sub display_line{ Line 291  sub display_line{
  my @file_ext = split (/\./,$listname);   my @file_ext = split (/\./,$listname);
  my $curfext = $file_ext[scalar(@file_ext)-1];   my $curfext = $file_ext[scalar(@file_ext)-1];
  my $filelink = $startdir.$filecom[0];   my $filelink = $startdir.$filecom[0];
  my $count = 0;  
  $r->print("<tr><td bgcolor=$fileclr>");   $r->print("<tr><td bgcolor=$fileclr>");
  while ($count < $indent) {  
     $r->print("<img src=",$iconpath,"white_space_20_22.gif border=0>\n");   if ($indent < 11) {
       $r->print("<img src=",$iconpath,"whitespace",$indent,".gif border=0>\n");
    } else {
       my $ten = int($indent/10.);
       my $rem = $indent%10.0;
       my $count = 0;
       while ($count < $ten) {
    $r->print("<img src=",$iconpath,"whitespace10.gif border=0>\n");
     $count++;      $count++;
       }
       $r->print("<img src=",$iconpath,"whitespace",$rem,".gif border=0>\n") if $rem > 0;
  }   }
  $r->print("<img src=",$iconpath,"white_space_20_22.gif border=0>\n");  
  $r->print("<img src=$iconpath$curfext.gif border=0>\n");   $r->print("<img src=$iconpath$curfext.gif border=0>\n");
  $r->print(" <a href=$filelink>",$listname,"</a>");   $r->print(" <a href=$filelink>",$listname,"</a>\n");
  my $metafile = '/home/httpd/html'.$filelink.'.meta';   my $metafile = grep /^$filecom[0]\.meta\&/, @list;
   
  $r->print (" (<a href=\"javascript:openWindow('".$filelink.".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; TARGET=_self>metadata</a>) ") if (-e $metafile);   $r->print (" (<a href=\"javascript:openWindow('".$filelink.".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; TARGET=_self>metadata</a>) ") if ($metafile == 1);
   
 # $r->print(" (<a href=$filelink.meta target=cat>metadata</a>)") if (-e $metafile);  
  $r=>print("</td>\n");   $r=>print("</td>\n");
  $r->print("<td bgcolor=$fileclr align=right valign=bottom> ",$filecom[8]," </td>\n") if $ENV{'form.attr0'} == 1;   $r->print("<td bgcolor=$fileclr align=right valign=bottom> ",$filecom[8]," </td>\n") if $ENV{'form.attr0'} == 1;
  $r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[9]))." </td>\n") if $ENV{'form.attr1'} == 1;   $r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[9]))." </td>\n") if $ENV{'form.attr1'} == 1;
  $r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[10]))." </td>\n") if $ENV{'form.attr2'} == 1;   $r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[10]))." </td>\n") if $ENV{'form.attr2'} == 1;
   
  if ($ENV{'form.attr3'} == 1) {   if ($ENV{'form.attr3'} == 1) {
     my $author = &Apache::lonnet::metadata($filelink,'author');      my $author = &Apache::lonnet::metadata($filelink,'author') if ($metafile == 1);
     $author = '&nbsp;' if (!$author);      $author = '&nbsp;' if (!$author);
     $r->print("<td bgcolor=$fileclr valign=bottom> ".$author." </td>\n");      $r->print("<td bgcolor=$fileclr valign=bottom> ".$author." </td>\n");
  }   }
  if ($ENV{'form.attr4'} == 1) {   if ($ENV{'form.attr4'} == 1) {
     my $keywords = &Apache::lonnet::metadata($filelink,'keywords');      my $keywords = &Apache::lonnet::metadata($filelink,'keywords') if ($metafile == 1);
     $keywords = '&nbsp;' if (!$keywords);      $keywords = '&nbsp;' if (!$keywords);
     $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords." </td>\n");      $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords." </td>\n");
  }   }
  if ($ENV{'form.attr5'} == 1) {   if ($ENV{'form.attr5'} == 1) {
     my $lang = &Apache::lonnet::metadata($filelink,'language');      my $lang = &Apache::lonnet::metadata($filelink,'language') if ($metafile == 1);
     $lang = $language{$lang};      $lang = $language{$lang};
     $lang = '&nbsp;' if (!$lang);      $lang = '&nbsp;' if (!$lang);
     $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang." </td>\n");      $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang." </td>\n");
Line 330  sub display_line{ Line 344  sub display_line{
  $anchor =~ s/\///g;   $anchor =~ s/\///g;
  $r->print("<tr><td bgcolor=$fileclr valign=bottom>");   $r->print("<tr><td bgcolor=$fileclr valign=bottom>");
  &begin_form ($r,$curdir);   &begin_form ($r,$curdir);
    my $indentm1 = $indent-1;
  my $count = 0;   if ($indentm1 < 11) {
  while ($count < $indent) {      $r->print("<img src=",$iconpath,"whitespace",$indentm1,".gif border=0>\n");
     $r->print("<img src=",$iconpath,"white_space_20_22.gif border=0>\n");   } else {
       my $ten = int($indentm1/10.);
       my $rem = $indentm1%10.0;
       my $count = 0;
       while ($count < $ten) {
    $r->print("<img src=",$iconpath,"whitespace10.gif border=0>\n");
     $count++;      $count++;
       }
       $r->print("<img src=",$iconpath,"whitespace",$rem,".gif border=0>\n") if $rem > 0;
  }   }
   
  $r->print ("<a name=\"$anchor\">\n<input src=\"$iconpath");   $r->print ("<a name=\"$anchor\">\n<input src=\"$iconpath");
  $r->print ("folder_pointer_closed.gif\"") if $diropen == 0;   $r->print ("folder_pointer_closed.gif\"") if $diropen == 0;
  $r->print ("folder_pointer_opened.gif\"") if $diropen == 1;   $r->print ("folder_pointer_opened.gif\"") if $diropen == 1;
  $r->print (" name=\"View $curdir resources\" height=\"22\" type=\"image\" border=\"0\">\n");   $r->print (" name=\"$msg\" height=\"22\" type=\"image\" border=\"0\">\n");
  $r->print("<img src=",$iconpath,"folder_closed.gif border=0>\n") if $diropen == 0;   $r->print("<img src=",$iconpath,"folder_closed.gif border=0>\n") if $diropen == 0;
  $r->print("<img src=",$iconpath,"folder_opened.gif border=0>\n") if $diropen == 1;   $r->print("<img src=",$iconpath,"folder_opened.gif border=0>\n") if $diropen == 1;
  $r->print("$listname $tabtag</tr></form>\n");   $r->print("$listname $tabtag</tr></form>\n");

Removed from v.1.3  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>