Diff for /loncom/interface/lonindexer.pm between versions 1.66 and 1.71

version 1.66, 2003/06/14 00:15:01 version 1.71, 2003/07/22 19:00:51
Line 62  use strict; Line 62  use strict;
 use Apache::lonnet();  use Apache::lonnet();
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
   use Apache::lonmeta;
 use Apache::File;  use Apache::File;
 use GDBM_File;  use GDBM_File;
   
Line 84  my @Omit = (); Line 85  my @Omit = ();
 # ----------------------------- Handling routine called via Apache and mod_perl  # ----------------------------- Handling routine called via Apache and mod_perl
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
       my $c = $r->connection();
     $r->content_type('text/html');      $r->content_type('text/html');
     &Apache::loncommon::no_cache($r);      &Apache::loncommon::no_cache($r);
     $r->send_http_header;      $r->send_http_header;
     return OK if $r->header_only;      return OK if $r->header_only;
     $fnum=0;      $fnum=0;
     $dnum=0;      $dnum=0;
     untie %hash;  
   
     # Deal with stupid global variables (is there a way around making      # Deal with stupid global variables (is there a way around making
     # these global to this package?  It is just so wrong....)      # these global to this package?  It is just so wrong....)
Line 125  sub handler { Line 126  sub handler {
     $extrafield='';      $extrafield='';
     my $diropendb =       my $diropendb = 
  "/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_indexer.db";   "/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_indexer.db";
       %hash = ();
     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {      {
    my %dbfile;
    if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
       while(my($key,$value)=each(%dbfile)) {
    $hash{$key}=$value;
       }
       untie(%dbfile);
    }
       }
       {
  if ($ENV{'form.launch'} eq '1') {   if ($ENV{'form.launch'} eq '1') {
     &start_fresh_session();      &start_fresh_session();
         }          }
Line 309  END Line 319  END
   
 <script type="text/javascript">  <script type="text/javascript">
 $catalogmodefunctions  $catalogmodefunctions
 function openWindow(url, wdwName, w, h, toolbar,scrollbar) {  function openWindow(url, wdwName, w, h, toolbar,scrollbar,locationbar) {
     var options = "width=" + w + ",height=" + h + ",";      var xpos = (screen.width-w)/2;
       xpos = (xpos < 0) ? '0' : xpos;
       var ypos = (screen.height-h)/2-30;
       ypos = (ypos < 0) ? '0' : ypos;
       var options = "width=" + w + ",height=" + h + ",screenx="+xpos+",screeny="+ypos+",";
     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";      options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";      options += "menubar=no,toolbar="+toolbar+",location="+locationbar+",directories=no";
     var newWin = window.open(url, wdwName, options);      var newWin = window.open(url, wdwName, options);
     newWin.focus();      newWin.focus();
 }  }
Line 368  $r->print(&Apache::loncommon::bodytag('B Line 382  $r->print(&Apache::loncommon::bodytag('B
   
 # ---------------------------------- get state of file attributes to be showing  # ---------------------------------- get state of file attributes to be showing
  if ($ENV{'form.attrs'} ne '') {   if ($ENV{'form.attrs'} ne '') {
     for (my $i=0; $i<=8; $i++) {      for (my $i=0; $i<=9; $i++) {
  delete $hash{'display_attrs_'.$i};   delete $hash{'display_attrs_'.$i};
  if ($ENV{'form.attr'.$i} == 1) {   if ($ENV{'form.attr'.$i} == 1) {
     $attrchk[$i] = 'checked';      $attrchk[$i] = 'checked';
Line 376  $r->print(&Apache::loncommon::bodytag('B Line 390  $r->print(&Apache::loncommon::bodytag('B
  }   }
     }      }
  } else {   } else {
     for (my $i=0; $i<=8; $i++) {      for (my $i=0; $i<=9; $i++) {
  $attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;   $attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;
     }      }
  }   }
 # ------------------------------- output state of file attributes to be showing  # ------------------------------- output state of file attributes to be showing
   #                                 All versions has to the last item
   #                                 since it does not take an extra col
  $r->print(<<END);   $r->print(<<END);
 <form method="post" name="fileattr" action="$uri"  <form method="post" name="fileattr" action="$uri"
  enctype="application/x-www-form-urlencoded">   enctype="application/x-www-form-urlencoded">
Line 390  $r->print(&Apache::loncommon::bodytag('B Line 406  $r->print(&Apache::loncommon::bodytag('B
 <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Size</td>  <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Size</td>
 <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last access</td>  <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last access</td>
 <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Last modified</td>  <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Last modified</td>
 <td><input type="checkbox" name="attr8" value="1" $attrchk[8] /> All versions</td></tr><tr>  <td><input type="checkbox" name="attr8" value="1" $attrchk[8] /> Statistics</td></tr><tr>
 <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Author</td>  <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Author</td>
 <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> Keywords</td>  <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> Keywords</td>
 <td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> Language</td>  <td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> Language</td>
 <td><input type="checkbox" name="attr7" value="1" $attrchk[7] /> Show Resource</td>  <td><input type="checkbox" name="attr7" value="1" $attrchk[7] /> Show Resource</td>
   <td><input type="checkbox" name="attr9" value="1" $attrchk[9] /> All versions</td>
 <td>&nbsp;</td>  <td>&nbsp;</td>
 </tr></table>  </tr></table>
 <input type="hidden" name="dirPointer" value="on" />  <input type="hidden" name="dirPointer" value="on" />
 <input type="hidden" name="acts" value="" />  <input type="hidden" name="acts" value="" />
 <input type="submit" name="attrs" value="Review" />&nbsp;  <input type="submit" name="attrs" value="Update Display" />
 <input type="submit" name="attrs" value="Refresh" />  
 $closebutton  $closebutton
 $groupimportbutton  $groupimportbutton
 </form>  </form>
Line 430  END Line 446  END
     if ($hash{'display_attrs_6'} == 1);      if ($hash{'display_attrs_6'} == 1);
  $r->print("<td><b>Resource</b></td>\n")   $r->print("<td><b>Resource</b></td>\n")
     if ($hash{'display_attrs_7'} == 1);      if ($hash{'display_attrs_7'} == 1);
    $r->print("<td><b>Usage Statistics <br />(Courses/Network Hits)</b></td>\n")
       if ($hash{'display_attrs_8'} == 1);
  $r->print('</tr>');   $r->print('</tr>');
   
 # ----------------- read in what directories have previously been set to "open"  # ----------------- read in what directories have previously been set to "open"
Line 493  END Line 511  END
   
 # --------------------------------------------------- end the output and return  # --------------------------------------------------- end the output and return
  $r->print('</body></html>'."\n");   $r->print('</body></html>'."\n");
  untie(%hash);  #    } else {
     } else {  # $r->print('<html><head></head><body>Unable to tie hash to db '.
  $r->print('<html><head></head><body>Unable to tie hash to db '.  #  'file</body></html>');
   'file</body></html>');  # return OK;
  return OK;      }
       if(! $c->aborted()) {
    my %dbfile;
           if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_NEWDB(),0640)) {
               while (my($key,$value) = each(%hash)) {
                   $dbfile{$key}=$value;
               }
               untie(%dbfile);
           }
     }      }
   
     return OK;      return OK;
 }  }
   
 # ----------------------------------------------- recursive scan of a directory  # ----------------------------------------------- recursive scan of a directory
 sub scanDir {  sub scanDir {
     my ($r,$startdir,$indent,$hashref)=@_;      my ($r,$startdir,$indent,$hashref)=@_;
       my $c = $r->connection();
     my ($compuri,$curdir);      my ($compuri,$curdir);
     my $dirptr=16384;      my $dirptr=16384;
     $indent++;      $indent++;
Line 512  sub scanDir { Line 540  sub scanDir {
     my %dupdirs = %dirs;      my %dupdirs = %dirs;
     my @list=&get_list($r,$startdir);      my @list=&get_list($r,$startdir);
     foreach my $line (@list) {      foreach my $line (@list) {
           return if ($c->aborted());
  my ($strip,$dom,undef,$testdir,undef)=split(/\&/,$line,5);    my ($strip,$dom,undef,$testdir,undef)=split(/\&/,$line,5); 
  next if $strip =~ /.*\.meta$/;   next if $strip =~ /.*\.meta$/;
  my (@fileparts) = split(/\./,$strip);   my (@fileparts) = split(/\./,$strip);
  if ($hash{'display_attrs_8'} != 1) {   if ($hash{'display_attrs_9'} != 1) {
     if (scalar(@fileparts) >= 3) {      if (scalar(@fileparts) >= 3) {
  my $fext = pop @fileparts;   my $fext = pop @fileparts;
  my $ov = pop @fileparts;   my $ov = pop @fileparts;
Line 554  sub get_list { Line 583  sub get_list {
     my @list;      my @list;
     (my $luri = $uri) =~ s/\//_/g;      (my $luri = $uri) =~ s/\//_/g;
   
     if ($ENV{'form.attrs'} eq 'Refresh') {      if ($ENV{'form.attrs'} eq 'Update Display') {
  foreach (keys %hash) {   foreach (keys %hash) {
     delete $hash{$_} if ($_ =~ /^dirlist_files_/);      delete $hash{$_} if ($_ =~ /^dirlist_files_/);
     }      }
Line 639  sub display_line { Line 668  sub display_line {
     my $tabtag='</td>';      my $tabtag='</td>';
     my $i=0;      my $i=0;
   
     while ($i<=7) {      while ($i<=8) {
  $tabtag=join('',$tabtag,"<td>&nbsp;</td>")   $tabtag=join('',$tabtag,"<td>&nbsp;</td>")
     if $hash{'display_attrs_'.$i} == 1;      if $hash{'display_attrs_'.$i} == 1;
  $i++;   $i++;
Line 649  sub display_line { Line 678  sub display_line {
   
 # display uplink arrow  # display uplink arrow
     if ($filecom[1] eq 'viewOneUp') {      if ($filecom[1] eq 'viewOneUp') {
  $r->print("<tr bgcolor=$fileclr>$extrafield");   $r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
  $r->print("<td valign=$valign>\n");   $r->print("<td>\n");
  $r->print ('<form method="post" name="dirpathUP" action="'.$startdir.   $r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
    '/" '.     '/" '.
    'onSubmit="return rep_dirpath(\'UP\','.     'onSubmit="return rep_dirpath(\'UP\','.
Line 674  sub display_line { Line 703  sub display_line {
     if ($filecom[1] eq 'domain') {      if ($filecom[1] eq 'domain') {
  $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")   $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
     if ($ENV{'form.dirPointer'} eq "on");      if ($ENV{'form.dirPointer'} eq "on");
  $r->print("<tr bgcolor=$fileclr>$extrafield");   $r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
  $r->print("<td valign=$valign>");   $r->print("<td>");
  &begin_form ($r,$filecom[0].'/');   &begin_form ($r,$filecom[0].'/');
  my $anchor = $filecom[0].'/';   my $anchor = $filecom[0].'/';
  $anchor =~ s/\///g;   $anchor =~ s/\///g;
Line 699  sub display_line { Line 728  sub display_line {
 # display user directory  # display user directory
     }      }
     if ($filecom[1] eq 'user') {      if ($filecom[1] eq 'user') {
  $r->print("<tr bgcolor=$fileclr>$extrafield");   $r->print("<tr valign=$valign bgcolor=$fileclr>$extrafield");
  $r->print("<td valign=$valign nowrap>\n");   $r->print("<td nowrap>\n");
  my $curdir = $startdir.$filecom[0].'/';   my $curdir = $startdir.$filecom[0].'/';
  my $anchor = $curdir;   my $anchor = $curdir;
  $anchor =~ s/\///g;   $anchor =~ s/\///g;
Line 743  sub display_line { Line 772  sub display_line {
  $iconname = $curfext.".gif" unless   $iconname = $curfext.".gif" unless
     (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn');      (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn');
  #   #
  $r->print("<tr bgcolor=$fileclr><td nowrap valign='$valign'>");   $r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap>");
  my $metafile = grep /^\Q$filecom[0]\E\.meta\&/, @list;   my $metafile = grep /^\Q$filecom[0]\E\.meta\&/, @list;
  my $title;   my $title;
         if ($ENV{'form.catalogmode'} eq 'interactive') {          if ($ENV{'form.catalogmode'} eq 'interactive') {
Line 757  sub display_line { Line 786  sub display_line {
                       $titleesc,"','",$filelink,"')\">");                        $titleesc,"','",$filelink,"')\">");
     $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".      $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
       "\n");        "\n");
     $r->print("</td><td valign='$valign' nowrap>");      $r->print("</td><td nowrap>");
  }   }
         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {          elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
     $title=$listname;      $title=$listname;
Line 776  sub display_line { Line 805  sub display_line {
     $r->print("<input type='hidden' name='title"."' ".      $r->print("<input type='hidden' name='title"."' ".
       "value='$titleesc'>\n");        "value='$titleesc'>\n");
     $r->print("</form>\n");      $r->print("</form>\n");
     $r->print("</td><td valign='$valign' nowrap>");      $r->print("</td><td nowrap>");
     $hash{"pre_${fnum}_link"}=$filelink;      $hash{"pre_${fnum}_link"}=$filelink;
     $hash{"pre_${fnum}_title"}=$titleesc;      $hash{"pre_${fnum}_title"}=$titleesc;
      $fnum++;       $fnum++;
Line 800  sub display_line { Line 829  sub display_line {
   
  $r->print("<img src=$iconpath$iconname border='0' />\n");   $r->print("<img src=$iconpath$iconname border='0' />\n");
  $r->print (" <a href=\"javascript:openWindow('".$filelink.   $r->print (" <a href=\"javascript:openWindow('".$filelink.
    "', 'metadatafile', '450', '500', 'no', 'yes')\";".     "', 'previewfile', '450', '500', 'no', 'yes','yes')\";".
    " TARGET=_self>$listname</a> ");     " TARGET=_self>$listname</a> ");
   
  $r->print (" (<a href=\"javascript:openWindow('".$filelink.   $r->print (" (<a href=\"javascript:openWindow('".$filelink.
    ".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; ".     ".meta', 'metadatafile', '500', '550', 'no', 'yes','no')\"; ".
    "TARGET=_self>metadata</a>) ") if ($metafile == 1);     "TARGET=_self>metadata</a>) ") if ($metafile == 1);
   
  $r->print("</td>\n");   $r->print("</td>\n");
  if ($hash{'display_attrs_0'} == 1) {   if ($hash{'display_attrs_0'} == 1) {
     my $title = &Apache::lonnet::metadata($filelink,'title')      my $title = &Apache::lonnet::gettitle($filelink,'title')
  if ($metafile == 1);   if ($metafile == 1);
     $r->print('<td valign=$valign> '.($title eq '' ? '&nbsp;' : $title).      $r->print('<td> '.($title eq '' ? '&nbsp;' : $title).
       ' </td>'."\n");        ' </td>'."\n");
  }   }
  $r->print('<td align=right valign=$valign> ',   $r->print('<td align=right> ',
   $filecom[8]," </td>\n")     $filecom[8]," </td>\n") 
     if $hash{'display_attrs_1'} == 1;      if $hash{'display_attrs_1'} == 1;
  $r->print('<td valign=$valign> '.   $r->print('<td> '.
   (localtime($filecom[9]))." </td>\n")     (localtime($filecom[9]))." </td>\n") 
     if $hash{'display_attrs_2'} == 1;      if $hash{'display_attrs_2'} == 1;
  $r->print('<td valign=$valign> '.   $r->print('<td> '.
   (localtime($filecom[10]))." </td>\n")     (localtime($filecom[10]))." </td>\n") 
     if $hash{'display_attrs_3'} == 1;      if $hash{'display_attrs_3'} == 1;
   
  if ($hash{'display_attrs_4'} == 1) {   if ($hash{'display_attrs_4'} == 1) {
     my $author = &Apache::lonnet::metadata($filelink,'author')      my $author = &Apache::lonnet::metadata($filelink,'author')
  if ($metafile == 1);   if ($metafile == 1);
     $r->print('<td valign=$valign> '.($author eq '' ? '&nbsp;' : $author).      $r->print('<td> '.($author eq '' ? '&nbsp;' : $author).
       " </td>\n");        " </td>\n");
  }   }
  if ($hash{'display_attrs_5'} == 1) {   if ($hash{'display_attrs_5'} == 1) {
     my $keywords = &Apache::lonnet::metadata($filelink,'keywords')      my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
  if ($metafile == 1);   if ($metafile == 1);
     # $keywords = '&nbsp;' if (!$keywords);      # $keywords = '&nbsp;' if (!$keywords);
     $r->print('<td valign=$valign> '.($keywords eq '' ? '&nbsp;' : $keywords).      $r->print('<td> '.($keywords eq '' ? '&nbsp;' : $keywords).
       " </td>\n");        " </td>\n");
  }   }
  if ($hash{'display_attrs_6'} == 1) {   if ($hash{'display_attrs_6'} == 1) {
     my $lang = &Apache::lonnet::metadata($filelink,'language')      my $lang = &Apache::lonnet::metadata($filelink,'language')
  if ($metafile == 1);   if ($metafile == 1);
     $lang = &Apache::loncommon::languagedescription($lang);      $lang = &Apache::loncommon::languagedescription($lang);
     $r->print('<td valign=$valign> '.($lang eq '' ? '&nbsp;' : $lang).      $r->print('<td> '.($lang eq '' ? '&nbsp;' : $lang).
       " </td>\n");        " </td>\n");
  }   }
         if ($hash{'display_attrs_7'} == 1) {          if ($hash{'display_attrs_7'} == 1) {
Line 857  sub display_line { Line 886  sub display_line {
  $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}.   $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}.
                  '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';                   '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
            }             }
    $r->print('<td valign=$valign> '.($output eq '' ? '&nbsp;':$output).     $r->print('<td> '.($output eq '' ? '&nbsp;':$output).
       " </td>\n");        " </td>\n");
         }          }
    if ($hash{'display_attrs_8'} == 1) {
       my (%stat) = &Apache::lonmeta::dynamicmeta($filelink) if ($metafile == 1);
       my $stat = (exists($stat{'course'}) ? $stat{'course'} : '').
    ((exists($stat{'course'}) || exists($stat{'count'})) ? '/' : '').
    (exists($stat{'count'}) ? $stat{'count'} : '');
       $r->print('<td align=center> '.($stat eq '' ? '&nbsp;' : $stat).
         ' </td>'."\n");
    }
   
  $r->print("</tr>\n");   $r->print("</tr>\n");
     }      }
   
Line 948  sub setvalues { Line 986  sub setvalues {
 sub cleanup {  sub cleanup {
     if (tied(%hash)){      if (tied(%hash)){
  &Apache::lonnet::logthis('Cleanup indexer: hash');   &Apache::lonnet::logthis('Cleanup indexer: hash');
         unless (untie(%hash)) {  
     &Apache::lonnet::logthis('Failed cleanup indexer: hash');  
         }  
     }      }
 }  }
   

Removed from v.1.66  
changed lines
  Added in v.1.71


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