Diff for /loncom/interface/lonindexer.pm between versions 1.16 and 1.17

version 1.16, 2001/08/08 03:00:11 version 1.17, 2001/08/13 14:50:35
Line 1 Line 1
 # The LearningOnline Network with CAPA  # The LearningOnline Network with CAPA
 #  #
 # Directory Indexer  # Directory Indexer
 # (Login Screen  
 #  #
 # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)  # YEAR=1999
   # 5/21/99, 5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
 # 11/23 Gerd Kortemeyer  # 11/23 Gerd Kortemeyer
   # YEAR=2000
 # 07/20-08/04 H.K. Ng  # 07/20-08/04 H.K. Ng
 #  # YEAR=2001
 # 05/9-05/19/2001 H. K. Ng  # 05/9-05/19/2001 H. K. Ng
 # 05/21/2001 H. K. Ng  # 05/21/2001 H. K. Ng
 # 05/23/2001 H. K. Ng  # 05/23/2001 H. K. Ng
 # 05/31/2001 Scott Harrison  # 5/31,6/1,6/2,6/15 Scott Harrison
 # 06/01/2001 Scott Harrison  # 6/26,7/8 H. K. Ng
 # 06/02/2001 Scott Harrison  # 8/6,8/7,8/10 Scott Harrison
 # 06/15/2001 Scott Harrison  
 # 06/26/2001 H. K. Ng  
 # 07/08/2001 H. K. Ng  
 # 8/6,8/7 Scott Harrison  
   
 package Apache::lonindexer;  package Apache::lonindexer;
   
Line 26  use Apache::Constants qw(:common); Line 23  use Apache::Constants qw(:common);
 use Apache::File;  use Apache::File;
 use GDBM_File;  use GDBM_File;
   
 my %hash;  my %hash; # tied to a user-specific gdbm file
 my %dirs;  my %dirs; # keys are directories, values are the open/close status
 my %language;  my %language; # has the reference information present in language.tab
 my $hidden;  
 my $extrafield;  # ----- Values which are set by the handler subroutine and are accessible to
 my $fnum;  # -----     other methods.
 my $dnum;  my $extrafield; # default extra table cell
   my $fnum; # file counter
   my $dnum; # directory counter
   
   # ---------------------------------------------------------------------- BEGIN
 sub BEGIN {  sub BEGIN {
     my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.      my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
      '/language.tab');       '/language.tab');
Line 42  sub BEGIN { Line 43  sub BEGIN {
     } <$fh>;      } <$fh>;
 }  }
   
   # ---------------------------------------------------------------- Main Handler
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
     $r->content_type('text/html');      $r->content_type('text/html');
Line 49  sub handler { Line 51  sub handler {
     return OK if $r->header_only;      return OK if $r->header_only;
     $fnum=0;      $fnum=0;
     $dnum=0;      $dnum=0;
   
   # --------------------------------------------- machine configuration variables
     my $iconpath= $r->dir_config('lonIconsURL') . "/";      my $iconpath= $r->dir_config('lonIconsURL') . "/";
     my $domain  = $r->dir_config('lonDefDomain');      my $domain  = $r->dir_config('lonDefDomain');
     my $role    = $r->dir_config('lonRole');      my $role    = $r->dir_config('lonRole');
Line 64  sub handler { Line 68  sub handler {
     my $uri=$r->uri;      my $uri=$r->uri;
   
 # -------------------------------------- see if called from an interactive mode  # -------------------------------------- see if called from an interactive mode
 #    foreach my $key (sort(keys(%ENV))) {      &get_unprocessed_cgi();
 # $r->print("$key is $ENV{$key}<br />");  
 #    }  
 #    $r->print("END ENV");  
     map {  
        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') {  
            $ENV{'form.'.$name}=$value;  
        }  
        if ($name eq 'launch') {  
            $ENV{'form.'.$name}=$value;  
        }  
        if ($name eq 'acts') {  
            $ENV{'form.'.$name}=$value;  
        }  
     } (split(/&/,$ENV{'QUERY_STRING'}));  
   
     $hidden=''; my $closebutton='';      my $closebutton='';
     my $groupimportbutton='';      my $groupimportbutton='';
     my $colspan='';       my $colspan=''; 
   
     $extrafield='';      $extrafield='';
     my $diropendb = "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";      my $diropendb = 
    "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
   
     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {      if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
  if ($ENV{'form.launch'} eq '1') {   if ($ENV{'form.launch'} eq '1') {
     delete $hash{'mode_catalog'};      &start_fresh_session();
     map {  
  if ($_ =~ /^pre_/) {  
     delete $hash{$_};  
  }  
  if ($_ =~ /^store/) {  
     delete $hash{$_};  
  }  
     } keys %hash;      
  }   }
   
   # -------------------- refresh environment with user database values (in %hash)
  if ($hash{'mode_catalog'} eq 'interactive') {   if ($hash{'mode_catalog'} eq 'interactive') {
     $ENV{'form.catalogmode'}='interactive';      $ENV{'form.catalogmode'}='interactive';
  }   }
Line 109  sub handler { Line 91  sub handler {
     $ENV{'form.catalogmode'}='groupimport';      $ENV{'form.catalogmode'}='groupimport';
  }   }
   
   # --------------------- define extra fields and buttons in case of special mode
  if ($ENV{'form.catalogmode'} eq 'interactive') {   if ($ENV{'form.catalogmode'} eq 'interactive') {
     $hash{'mode_catalog'}='interactive';      $hash{'mode_catalog'}='interactive';
     $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.      $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
  '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.   '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
  ' border="0"></td>';   ' border="0" /></td>';
     $colspan=" colspan='2' ";      $colspan=" colspan='2' ";
     $hidden=<<END;  
 <input type='hidden' name='catalogmode' value='interactive'>  
 END  
             $closebutton=<<END;              $closebutton=<<END;
 <input type="button" name="close" value='CLOSE' onClick="self.close()">  <input type="button" name="close" value='CLOSE' onClick="self.close()">
 END  END
Line 126  END Line 106  END
     $hash{'mode_catalog'}='groupimport';      $hash{'mode_catalog'}='groupimport';
     $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.      $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
  '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.   '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
  ' border="0"></td>';   ' border="0" /></td>';
     $colspan=" colspan='2' ";      $colspan=" colspan='2' ";
     $hidden=<<END;  
 <input type='hidden' name='catalogmode' value='groupimport'>  
 END  
             $closebutton=<<END;              $closebutton=<<END;
 <input type="button" name="close" value='CLOSE' onClick="self.close()">  <input type="button" name="close" value='CLOSE' onClick="self.close()">
 END  END
             $groupimportbutton=<<END;              $groupimportbutton=<<END;
 <input type="button" name="groupimport" value='GROUP IMPORT' onClick="javascript:select_group()">  <input type="button" name="groupimport" value='GROUP IMPORT'
   onClick="javascript:select_group()">
 END  END
         }          }
   
   # ------ set catalogmodefunctions to have extra needed javascript functionality
  my $catalogmodefunctions='';   my $catalogmodefunctions='';
  if ($ENV{'form.catalogmode'} eq 'interactive' or   if ($ENV{'form.catalogmode'} eq 'interactive' or
     $ENV{'form.catalogmode'} eq 'groupimport') {      $ENV{'form.catalogmode'} eq 'groupimport') {
Line 148  function select_data(title,url) { Line 127  function select_data(title,url) {
     changeURL(url);      changeURL(url);
     self.close();      self.close();
 }  }
 function save_group() {  
     for (var num=0; num<document.forms.fnum.fnum.value; num++) {  
  if (eval("document.forms.form"+num+".filelink.checked")) {  
     alert(eval("document.forms.form"+num+".title.value")+  
        eval("document.forms.form"+num+".filelink.value"));  
  }  
     }  
 }  
 function select_group() {  function select_group() {
 //    window.location="http://"+window.location.hostname+"/adm/groupsort?acts="+document.forms.fileattr.acts.value;  
     window.location="/adm/groupsort?acts="+document.forms.fileattr.acts.value;      window.location="/adm/groupsort?acts="+document.forms.fileattr.acts.value;
 }  }
 function select_group2() {  
     var linkflag=false;  
     for (var num=0; num<document.forms.fnum.fnum.value; num++) {  
  if (eval("document.forms.form"+num+".filelink.checked")) {  
 //    alert(eval("document.forms.form"+num+".title.value")+  
 //       eval("document.forms.form"+num+".filelink.value"));  
     insertRowInLastRow();  
     placeResourceInLastRow(  
    eval("document.forms.form"+num+".title.value"),  
    eval("document.forms.form"+num+".filelink.value"),  
    linkflag  
    );  
     linkflag=true;  
  }  
     }  
     opener.editmode=0;  
     opener.notclear=0;  
     opener.linkmode=0;  
     opener.infoclear();  
     opener.draw();  
     self.close();  
 }  
 function insertRowInLastRow() {  
     opener.insertrow(opener.maxrow);  
     opener.addobj(opener.maxrow,'e&2');  
 }  
 function placeResourceInLastRow (title,url,linkflag) {  
     opener.newresource(opener.maxrow,2,opener.escape(title),opener.escape(url),'false','normal');  
     opener.save();  
     opener.mostrecent=opener.obj.length-1;  
     if (linkflag) {  
  opener.joinres(opener.linkmode,opener.mostrecent,0);  
     }  
     opener.linkmode=opener.mostrecent;  
 }  
 function changeTitle(val) {  function changeTitle(val) {
     if (opener.inf.document.forms.resinfo.elements.t) {      if (opener.inf.document.forms.resinfo.elements.t) {
         opener.inf.document.forms.resinfo.elements.t.value=val;          opener.inf.document.forms.resinfo.elements.t.value=val;
Line 215  function queue(val) { Line 150  function queue(val) {
  var l=val.length;   var l=val.length;
  var v=val.substring(4,l);   var v=val.substring(4,l);
  document.forms.fileattr.acts.value+='1a'+v+'b';   document.forms.fileattr.acts.value+='1a'+v+'b';
 // alert(document.forms.fileattr.acts.value);  
     }      }
     else {      else {
  var l=val.length;   var l=val.length;
  var v=val.substring(4,l);   var v=val.substring(4,l);
  document.forms.fileattr.acts.value+='0a'+v+'b';   document.forms.fileattr.acts.value+='0a'+v+'b';
 // alert(document.forms.fileattr.acts.value);  
     }  
     if (typeof(document.forms.dirpathUP)!="undefined") {  
 // document.forms.dirpathUP.acts.value=document.forms.fileattr.acts.value;  
 // alert(document.forms.dirpathUP.acts.value);  
     }      }
 }  }
 function rep_dirpath(suffix,val) {  function rep_dirpath(suffix,val) {
     eval("document.forms.dirpath"+suffix+".acts.value=val");      eval("document.forms.dirpath"+suffix+".acts.value=val");
 //    eval("alert(document.forms.dirpath"+suffix+".acts.value)");  
 //    return false;  
 }  }
 END  END
  }   }
   
 # ---------------------------------------------------------------- Print Header  # ---------------------------------------------------------------- Print Header
  $r->print(<<ENDHEADER);   $r->print(<<ENDHEADER);
 <html>  <html>
Line 258  function gothere(val) { Line 186  function gothere(val) {
 </head>  </head>
 <body bgcolor="#FFFFFF">  <body bgcolor="#FFFFFF">
 ENDHEADER  ENDHEADER
   
   # - Evaluate actions from previous page (both cumulatively and chronologically)
         if ($ENV{'form.catalogmode'} eq 'groupimport') {          if ($ENV{'form.catalogmode'} eq 'groupimport') {
 #    $r->print($ENV{'form.acts'}."<br />");  
     my $acts=$ENV{'form.acts'};      my $acts=$ENV{'form.acts'};
     my @Acts=split(/b/,$acts);      my @Acts=split(/b/,$acts);
     my %ahash;      my %ahash;
     my %achash;      my %achash;
     my $ac=0;      my $ac=0;
       # some initial hashes for working with data
     map {      map {
  my ($state,$ref)=split(/a/);   my ($state,$ref)=split(/a/);
  $ahash{$ref}=$state;   $ahash{$ref}=$state;
  $achash{$ref}=$ac;   $achash{$ref}=$ac;
  $ac++;   $ac++;
     } (@Acts);      } (@Acts);
       # sorting through the actions and changing the tied database hash
     map {      map {
  my $key=$_;   my $key=$_;
  if ($ahash{$key} eq '1') {   if ($ahash{$key} eq '1') {
 #    $r->print("<b>NEW: ");  
 #    $r->print($hash{'pre_'.$key.'_title'});  
 #    $r->print(" : ");  
 #    $r->print($hash{'pre_'.$key.'_link'});  
 #    $r->print("</b><br />");  
     $hash{'store_'.$hash{'pre_'.$key.'_link'}}=      $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
  $hash{'pre_'.$key.'_title'};   $hash{'pre_'.$key.'_title'};
     $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=      $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
Line 291  ENDHEADER Line 217  ENDHEADER
     }      }
  }   }
     } sort {$achash{$a}<=>$achash{$b}} (keys %ahash);      } sort {$achash{$a}<=>$achash{$b}} (keys %ahash);
     map {      # deleting the previously cached listing
  if ($_ =~ /^store_/) {  
     my $key=$_;  
     $key=~s/^store_//;  
 #    $r->print("<b>STORE: ");  
 #    $r->print($hash{'storectr_'.$key});  
 #    $r->print(':');  
 #    $r->print($hash{'store_'.$key});  
 #    $r->print(':');  
 #    $r->print($key);  
 #    $r->print("</b><br />");  
  }  
     } keys %hash;  
     map {      map {
  if ($_ =~ /^pre_/ && $_ =~/link$/) {   if ($_ =~ /^pre_/ && $_ =~/link$/) {
     my $key = $_;      my $key = $_;
     $key =~ s/^pre_//;      $key =~ s/^pre_//;
     $key =~ s/_[^_]*$//;      $key =~ s/_[^_]*$//;
 #    $r->print($key);  
 #    $r->print(':');  
 #    $r->print($hash{'pre_'.$key.'_title'});  
 #    $r->print(':');  
 #    $r->print($hash{'pre_'.$key.'_link'});  
 #    $r->print('<br />');  
     delete $hash{'pre_'.$key.'_title'};      delete $hash{'pre_'.$key.'_title'};
     delete $hash{'pre_'.$key.'_link'};      delete $hash{'pre_'.$key.'_link'};
  }   }
     } keys %hash;      } keys %hash;
  }   }
   
  $r->print('<h2><font color="#888888">The LearningOnline With CAPA Network Directory Browser</font></h2>'."\n");  # output title
     } else {   $r->print('<h2><font color="#888888">The LearningOnline With CAPA '.
  $r->print('<html><head></head><body>Unable to tie hash to db file</body></html>');    'Network Directory Browser</font></h2>'."\n");
  return OK;  # get state of file attributes to be showing
     }  
     untie %hash;  
     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {  
   
  if ($ENV{'form.attrs'} ne "") {   if ($ENV{'form.attrs'} ne "") {
     for (my $i=0; $i<=5; $i++) {      for (my $i=0; $i<=5; $i++) {
  delete $hash{'display_attrs_'.$i};   delete $hash{'display_attrs_'.$i};
Line 342  ENDHEADER Line 246  ENDHEADER
  $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
  $r->print(<<END);   $r->print(<<END);
 <b><font color="#666666">Display file attributes</font></b><br>  <b><font color="#666666">Display file attributes</font></b><br />
 <form method="post" name="fileattr" action="$uri" enctype="application/x-www-form-urlencoded">  <form method="post" name="fileattr" action="$uri"
    enctype="application/x-www-form-urlencoded">
 <table border=0><tr>  <table border=0><tr>
 <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> Size</td>  <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> Size</td>
 <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Last access</td>  <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Last
 <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last modified</td>   access</td>
   <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last
    modified</td>
 </tr><tr>  </tr><tr>
 <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Author</td>  <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Author</td>
 <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Keywords</td>  <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Keywords</td>
Line 358  ENDHEADER Line 266  ENDHEADER
 <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="Review" />&nbsp;
 <input type="submit" name="attrs" value="Refresh" />  <input type="submit" name="attrs" value="Refresh" />
 $hidden  
 $closebutton  $closebutton
 $groupimportbutton  $groupimportbutton
 </form>  </form>
 END  END
   
       # output starting row to the indexed file/directory hierarchy
         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");
  $r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");   $r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
  $r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) </b></td>\n") if ($hash{'display_attrs_0'} == 1);   $r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) ".
  $r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n") if ($hash{'display_attrs_1'} == 1);    "</b></td>\n") if ($hash{'display_attrs_0'} == 1);
  $r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n") if ($hash{'display_attrs_2'} == 1);   $r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n") 
  $r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n") if ($hash{'display_attrs_3'} == 1);      if ($hash{'display_attrs_1'} == 1);
  $r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n") if ($hash{'display_attrs_4'} == 1);   $r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n")
  $r->print("<td bgcolor=$titleclr><b>Language</b></td>\n") if ($hash{'display_attrs_5'} == 1);      if ($hash{'display_attrs_2'} == 1);
    $r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n")
       if ($hash{'display_attrs_3'} == 1);
    $r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n")
       if ($hash{'display_attrs_4'} == 1);
    $r->print("<td bgcolor=$titleclr><b>Language</b></td>\n")
       if ($hash{'display_attrs_5'} == 1);
  $r->print("</tr>");   $r->print("</tr>");
   
    # read in what directories have previously been set to "open"
  map {   map {
     if ($_ =~ /^diropen_status_/) {      if ($_ =~ /^diropen_status_/) {
  my $key = $_;   my $key = $_;
Line 404  END Line 319  END
  my $toplevel;   my $toplevel;
  my $indent = 0;   my $indent = 0;
  $uri = $uri.'/' if $uri !~ /.*\/$/;   $uri = $uri.'/' if $uri !~ /.*\/$/;
   
  if ($bredir ne "on") {   if ($bredir ne "on") {
     $hash{'top.level'} = $uri;      $hash{'top.level'} = $uri;
     $toplevel = $uri;      $toplevel = $uri;
Line 411  END Line 327  END
  } else {   } else {
     $toplevel = $hash{'top.level'};      $toplevel = $hash{'top.level'};
  }   }
   
    # if not at top level, provide an uplink arrow
  if ($toplevel ne "/res/"){   if ($toplevel ne "/res/"){
     my (@uri_com) = split(/\//,$uri);      my (@uri_com) = split(/\//,$uri);
     pop @uri_com;      pop @uri_com;
Line 419  END Line 337  END
     &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);      &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
     $indent = 1;      $indent = 1;
  }   }
   
    # recursively go through all the directories and output as appropriate
  &scanDir ($r,$toplevel,$indent,\%hash);   &scanDir ($r,$toplevel,$indent,\%hash);
   
    # information useful for group import
  $r->print("<form name='fnum'>");   $r->print("<form name='fnum'>");
  $r->print("<input type='hidden' name='fnum' value='$fnum'></form>");   $r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
   
    # end the tables
  $r->print("</table>");   $r->print("</table>");
  $r->print("</td></tr></table>");   $r->print("</td></tr></table>");
   
    # end the output and return
  $r->print("</body></html>\n");   $r->print("</body></html>\n");
  untie(%hash);   untie(%hash);
     } else {      } else {
  $r->print("Unable to tie hash to db file");   $r->print('<html><head></head><body>Unable to tie hash to db '.
     'file</body></html>');
    return OK;
     }      }
     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 ($compuri,$curdir);      my ($compuri,$curdir);
Line 447  sub scanDir { Line 374  sub scanDir {
  my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5);    my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5); 
  next if $strip =~ /.*\.meta$/;   next if $strip =~ /.*\.meta$/;
  if ($dom eq "domain") {   if ($dom eq "domain") {
     $compuri = join('',$strip,"/");  # domain list has /res/<domain name>      $compuri = join('',$strip,"/");  # dom list has /res/<domain name>
     $curdir = $compuri;      $curdir = $compuri;
  } else {   } else {
     $compuri = join('',$startdir,$strip,"/"); # user, dir & file have name only, i.e., w/o path      # user, dir & file have name only, i.e., w/o path
       $compuri = join('',$startdir,$strip,"/");
     $curdir = $startdir;      $curdir = $startdir;
  }   }
  my $diropen = "closed";   my $diropen = "closed";
Line 468  sub scanDir { Line 396  sub scanDir {
     $indent--;      $indent--;
 }  }
   
 # ----------------- get complete matched list based on the uri ------  # --------------- get complete matched list based on the uri (returns an array)
 sub get_list {  sub get_list {
     my ($r,$uri)=@_;      my ($r,$uri)=@_;
     my @list;      my @list;
Line 490  sub get_list { Line 418  sub get_list {
     return @list=&match_ext($r,@list);      return @list=&match_ext($r,@list);
 }  }
   
 #-------------------------- filters out files based on extensions  # -------------------- filters out files based on extensions (returns an array)
 sub match_ext {  sub match_ext {
     my ($r,@packlist)=@_;      my ($r,@packlist)=@_;
     my @trimlist;      my @trimlist;
Line 529  sub match_ext { Line 457  sub match_ext {
     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,$hashref,@list)=@_;      my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
     my (@pathfn, $fndir, $fnptr);      my (@pathfn, $fndir, $fnptr);
Line 548  sub display_line{ Line 476  sub display_line{
     my $i=0;      my $i=0;
   
     while ($i<=5) {      while ($i<=5) {
  $tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,">&nbsp;</td>") if $hash{'display_attrs_'.$i} == 1;   $tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,">&nbsp;</td>")
       if $hash{'display_attrs_'.$i} == 1;
  $i++;   $i++;
     }      }
   
   # display uplink arrow
     if ($filecom[1] eq "viewOneUp") {      if ($filecom[1] eq "viewOneUp") {
  $r->print("<tr>$extrafield");   $r->print("<tr>$extrafield");
  $r->print("<td bgcolor=$fileclr valign=bottom>\n");   $r->print("<td bgcolor=$fileclr valign=bottom>\n");
  $r->print ('<form method="post" name="dirpathUP" action="'.$startdir.   $r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
    '/" '.     '/" '.
    'onSubmit="return rep_dirpath(\'UP\',document.forms.fileattr.acts.value)" '.     'onSubmit="return rep_dirpath(\'UP\','.
      'document.forms.fileattr.acts.value)" '.
    'enctype="application/x-www-form-urlencoded"'.     'enctype="application/x-www-form-urlencoded"'.
                    '>'."\n");                     '>'."\n");
  $r->print ($hidden.'<input type=hidden name=openuri value="'.$startdir.'">'."\n");   $r->print ('<input type=hidden name=openuri value="'.
      $startdir.'">'."\n");
  $r->print ('<input type="hidden" name="acts" value="">'."\n");   $r->print ('<input type="hidden" name="acts" value="">'."\n");
  $r->print ('<input src="'.$iconpath.'arrow_up.gif"');   $r->print ('<input src="'.$iconpath.'arrow_up.gif"');
  $r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");   $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
      "\n");
  $r->print("Up $tabtag</tr></form>\n");   $r->print("Up $tabtag</tr></form>\n");
  return OK;   return OK;
     }      }
   
   # display domain
     if ($filecom[1] eq "domain") {      if ($filecom[1] eq "domain") {
  $r->print ('<input type=hidden name=dirPointer value="on">'."\n") if ($ENV{'form.dirPointer'} eq "on");   $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
       if ($ENV{'form.dirPointer'} eq "on");
  $r->print("<tr>$extrafield");   $r->print("<tr>$extrafield");
  $r->print("<td bgcolor=$fileclr valign=bottom>");   $r->print("<td bgcolor=$fileclr valign=bottom>");
  &begin_form ($r,$filecom[0].'/');   &begin_form ($r,$filecom[0].'/');
Line 575  sub display_line{ Line 512  sub display_line{
  $anchor =~ s/\///g;   $anchor =~ s/\///g;
  $r->print ('<a name="'.$anchor.'">');   $r->print ('<a name="'.$anchor.'">');
  $r->print ('<input type="hidden" name="acts" value="">');   $r->print ('<input type="hidden" name="acts" value="">');
  $r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.'.gif"');    $r->print ('<input src="'.$iconpath.'folder_pointer_'.
  $r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");     $diropen.'.gif"'); 
  $r->print ('<a href="javascript:gothere(\''.$filecom[0].'/\')"><img src="'.$iconpath.'server.gif"');   $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  $r->print (' border="0"></a>'."\n");     "\n");
    $r->print ('<a href="javascript:gothere(\''.$filecom[0].
      '/\')"><img src="'.$iconpath.'server.gif"');
    $r->print (' border="0" /></a>'."\n");
  $r->print("Domain - $listname $tabtag</tr></form>\n");   $r->print("Domain - $listname $tabtag</tr></form>\n");
  return OK;   return OK;
   
   # display user directory
     }      }
     if ($filecom[1] eq "user") {      if ($filecom[1] eq "user") {
  $r->print("<tr>$extrafield");   $r->print("<tr>$extrafield");
Line 589  sub display_line{ Line 531  sub display_line{
  my $anchor = $curdir;   my $anchor = $curdir;
  $anchor =~ s/\///g;   $anchor =~ s/\///g;
  &begin_form ($r,$curdir);   &begin_form ($r,$curdir);
  $r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.'whitespace1.gif" border=0>'."\n");   $r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
      'whitespace1.gif" border="0" />'."\n");
  $r->print ('<input type="hidden" name="acts" value="">');   $r->print ('<input type="hidden" name="acts" value="">');
  $r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.'.gif"');    $r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
  $r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");     '.gif"'); 
  $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.$iconpath.'quill.gif border=0 name="'.$msg.'" height="22"></a>');   $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
      "\n");
    $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
      $iconpath.'quill.gif border="0" name="'.$msg.
      '" height="22" /></a>');
  $r->print ($listname.$tabtag.'</tr></form>'."\n");   $r->print ($listname.$tabtag.'</tr></form>'."\n");
  return OK;   return OK;
     }      }
   
 # display file  # display file
     if ($fnptr == 0 and $filecom[3] ne "") {      if ($fnptr == 0 and $filecom[3] ne "") {
  my @file_ext = split (/\./,$listname);   my @file_ext = split (/\./,$listname);
Line 612  sub display_line{ Line 560  sub display_line{
     $title=$listname unless $title;      $title=$listname unless $title;
     $r->print("<a href='javascript:select_data(\"",      $r->print("<a href='javascript:select_data(\"",
               $title,'","',$filelink,"\")'>");                $title,'","',$filelink,"\")'>");
     $r->print("<img src='",$iconpath,"select.gif' border=0></a>\n");      $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
         "\n");
     $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");      $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
  }   }
         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {          elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
Line 638  sub display_line{ Line 587  sub display_line{
  }   }
   
  if ($indent > 0 and $indent < 11) {   if ($indent > 0 and $indent < 11) {
     $r->print("<img src=",$iconpath,"whitespace",$indent,".gif border=0>\n");      $r->print("<img src=",$iconpath,"whitespace",$indent,
         ".gif border='0' />\n");
  } elsif ($indent >0) {   } elsif ($indent >0) {
     my $ten = int($indent/10.);      my $ten = int($indent/10.);
     my $rem = $indent%10.0;      my $rem = $indent%10.0;
     my $count = 0;      my $count = 0;
     while ($count < $ten) {      while ($count < $ten) {
  $r->print("<img src=",$iconpath,"whitespace10.gif border=0>\n");   $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,"whitespace",$rem,
         ".gif border='0' />\n") if $rem > 0;
  }   }
   
  $r->print("<img src=$iconpath$curfext.gif border=0>\n");   $r->print("<img src=$iconpath$curfext.gif border='0' />\n");
  $r->print (" <a href=\"javascript:openWindow('".$filelink."', 'metadatafile', '450', '500', 'no', 'yes')\"; TARGET=_self>$listname</a> ");   $r->print (" <a href=\"javascript:openWindow('".$filelink.
      "', 'metadatafile', '450', '500', 'no', 'yes')\";".
  $r->print (" (<a href=\"javascript:openWindow('".$filelink.".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; TARGET=_self>metadata</a>) ") if ($metafile == 1);     " TARGET=_self>$listname</a> ");
   
    $r->print (" (<a href=\"javascript:openWindow('".$filelink.
      ".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; ".
      "TARGET=_self>metadata</a>) ") if ($metafile == 1);
   
  $r->print("</td>\n");   $r->print("</td>\n");
  $r->print("<td bgcolor=$fileclr align=right valign=bottom> ",$filecom[8]," </td>\n")    $r->print("<td bgcolor=$fileclr align=right valign=bottom> ",
     $filecom[8]," </td>\n") 
     if $hash{'display_attrs_0'} == 1;      if $hash{'display_attrs_0'} == 1;
  $r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[9]))." </td>\n")    $r->print("<td bgcolor=$fileclr valign=bottom> ".
     (localtime($filecom[9]))." </td>\n") 
     if $hash{'display_attrs_1'} == 1;      if $hash{'display_attrs_1'} == 1;
  $r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[10]))." </td>\n")    $r->print("<td bgcolor=$fileclr valign=bottom> ".
     (localtime($filecom[10]))." </td>\n") 
     if $hash{'display_attrs_2'} == 1;      if $hash{'display_attrs_2'} == 1;
   
  if ($hash{'display_attrs_3'} == 1) {   if ($hash{'display_attrs_3'} == 1) {
     my $author = &Apache::lonnet::metadata($filelink,'author') if ($metafile == 1);      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 ($hash{'display_attrs_4'} == 1) {   if ($hash{'display_attrs_4'} == 1) {
     my $keywords = &Apache::lonnet::metadata($filelink,'keywords') if ($metafile == 1);      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 ($hash{'display_attrs_5'} == 1) {   if ($hash{'display_attrs_5'} == 1) {
     my $lang = &Apache::lonnet::metadata($filelink,'language') if ($metafile == 1);      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");
  }   }
  $r->print("</tr>\n");   $r->print("</tr>\n");
     }      }
   
 # -- display directory  # -- display directory
     if ($fnptr == $dirptr) {      if ($fnptr == $dirptr) {
  my @file_ext = split (/\./,$listname);   my @file_ext = split (/\./,$listname);
Line 692  sub display_line{ Line 658  sub display_line{
  &begin_form ($r,$curdir);   &begin_form ($r,$curdir);
  my $indentm1 = $indent-1;   my $indentm1 = $indent-1;
  if ($indentm1 < 11 and $indentm1 > 0) {   if ($indentm1 < 11 and $indentm1 > 0) {
     $r->print("<img src=",$iconpath,"whitespace",$indentm1,".gif border=0>\n");      $r->print("<img src=",$iconpath,"whitespace",$indentm1,
         ".gif border='0' />\n");
  } else {   } else {
     my $ten = int($indentm1/10.);      my $ten = int($indentm1/10.);
     my $rem = $indentm1%10.0;      my $rem = $indentm1%10.0;
     my $count = 0;      my $count = 0;
     while ($count < $ten) {      while ($count < $ten) {
  $r->print ("<img src=",$iconpath,"whitespace10.gif border=0>\n");   $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,"whitespace",$rem,
          ".gif border='0' />\n") if $rem > 0;
  }   }
  $r->print ('<input type="hidden" name="acts" value="">');   $r->print ('<input type="hidden" name="acts" value="">');
  $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.'folder_pointer_'.$diropen.'.gif"');   $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
  $r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");     'folder_pointer_'.$diropen.'.gif"');
  $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.$iconpath.'folder_'.$diropen.'.gif" border=0></a>'."\n");   $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
      "\n");
    $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
      $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
      "\n");
  $r->print ("$listname$tabtag</tr></form>\n");   $r->print ("$listname$tabtag</tr></form>\n");
     }      }
   
Line 717  sub begin_form { Line 690  sub begin_form {
     my ($r,$uri) = @_;      my ($r,$uri) = @_;
     my $anchor = $uri;      my $anchor = $uri;
     $anchor =~ s/\///g;      $anchor =~ s/\///g;
     $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.'#'.$anchor.      $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
        '" onSubmit="return rep_dirpath(\''.$dnum.'\',document.forms.fileattr.acts.value)" '.         '#'.$anchor.
          '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
          ',document.forms.fileattr.acts.value)" '.
        'enctype="application/x-www-form-urlencoded">'."\n");         'enctype="application/x-www-form-urlencoded">'."\n");
     $r->print ($hidden.'<input type=hidden name=openuri value="'.$uri.'">'."\n");      $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
     $r->print ('<input type=hidden name=dirPointer value="on">'."\n");         "\n");
       $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
     $dnum++;      $dnum++;
 }  }
   
   # ----------- grab unprocessed CGI variables that may have been appended to URL
   sub get_unprocessed_cgi {
       map {
          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 {
    if ($_ =~ /^pre_/) {
       delete $hash{$_};
    }
    if ($_ =~ /^store/) {
       delete $hash{$_};
    }
       } keys %hash;    
   }
   
 1;  1;
 __END__  __END__

Removed from v.1.16  
changed lines
  Added in v.1.17


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