The eAuction Support Forums
https://www.everyscript.de/cgi-bin/yabb/YaBB.pl
eAuction 1.6.1.x >> Discussion of Functions >> sub disp_list (Replacement)
https://www.everyscript.de/cgi-bin/yabb/YaBB.pl?num=1069603462

Message started by Forum Admin on 11/23/03 at 17:04:22

Title: sub disp_list (Replacement)
Post by Forum Admin on 11/23/03 at 17:04:22

The following code should be used as a replacement of the original subroutine.
The layout of the tables has been changed and they are able to display 'thumbnails' of an item-image instead of displaying only the camera-icon.


Code:

##############################################
# Sub: Display all needed Listings
# Written by: Dieter Werner
##############################################
sub disp_list {
   my $itm_cnt = 0;
   my $line_cnt = 0;
   my $page_cnt = 0;
   my $found = 0;
   my $dest = undef;
   my $ret_val = 1;
   my @allfiles = ();
   my (
       $query, $item, $cat, $title, $reserve, $inc, $desc, $end_date,
     $end_time, $start_time, $close_time, $the_time, $image,
     $img_info, $bid, $bids, $buy_it, $buy_it_info, $row,
     $rowcolor, $check_string, $tbl_title, $record,
       @bids, @firstbid, @lastbid, @closetime, @image, @output
   );
   local $_;
   
   $form{'page'} = 0 unless exists $form{'page'};
   $form{'trash'} = 0 unless exists $form{'trash'};
   ($check_string = $form{'searchstring'}) =~ s/\s//g;

   oops($txt{'The searchstring may not contain any non word characters'})
   if $check_string =~ /\W/ or !$check_string;
   
   $query = {
       'end'                  => q|$close_time - $the_time < ($config{'soon_time'} * 3600)|,
       'hot'                  => q|$#bids > $config{'hot_num'}|,
       'new'                  => q|$the_time - $start_time < ($config{'new_time'} * 3600)|,
       'min'                  => q|$firstbid[2] == 1|,
       'reserve'            => q|$reserve <= $lastbid[2]|,    
       'keyword'            => q|$title =~ /$form{'searchstring'}/i or $desc =~ /$form{'searchstring'}/i|,
       'username'            => q|$firstbid[0] eq $form{'searchstring'}|,
       'itemnumber'      => q|$item =~ /$form{'searchstring'}/o|,
       'price'            => q|$lastbid[2] <= $form{'searchstring'}|,
       'buyitnow'            => q|$firstbid[3] > 0|,
       'items'            => q|$cat eq $form{'searchstring'}|
   };    
   
   $form{'searchtype'} eq 'items'
       ?   do {
               $dest = "$config{'categories'}/$form{'searchstring'}";
               $tbl_title = $category{$form{'searchstring'];
           }
       :   do {
               ($form{'searchtype'} eq 'keyword'
                   or $form{'searchtype'} eq 'username'
                   or $form{'searchtype'} eq 'itemnumber'
                   or $form{'searchtype'} eq 'price'
               )
                   ? ($tbl_title = "$txt{'Search Result'}: $form{'searchstring'}")
                   : ($tbl_title = $form{'searchstring'});
           };
 
print <<EO_HTML;
<div align="center">
<h4>$tbl_title</h4>
<table width="660" border="0" cellspacing="1" cellpadding="3">
   <tr bgcolor="$config{'colortablehead'}">
       <td align="center" colspan="2"><b>$txt{'Item'}</b></td>
EO_HTML

print <<EO_HTML if $form{'searchtype'} ne 'items';  
       <td align="center" width="190"><b>$txt{'Category'}</b></td>
       <td align="center" width="60" nowrap><b>$txt{'Bids'}</b></td>
       <td align="center" width="100" nowrap><b>$txt{'High Bid'}</b></td>
       <td align="center" width="60" nowrap><b>$txt{'Closes'}</b></td>
   </tr>
EO_HTML

print <<EO_HTML if $form{'searchtype'} eq 'items';
       <td align="center" width="60" nowrap><b>$txt{'Bids'}</b></td>
       <td align="center" width="100" nowrap><b>$txt{'High Bid'}</b></td>
       <td align="center" width="60" nowrap><b>$txt{'Closes'}</b></td>
   </tr>
EO_HTML


       while ($ret_val) {
           (time - $^T > $config{'max_searchtime'}) && last; # We are the master of our CPU-Usage
           ($ret_val, $itm_cnt) = read_dir_range($dest, $ret_val, $itm_cnt, \@allfiles);
         
               while ($#allfiles >= 0) {
                   ($item, $cat) = @allfiles;
                   shift @allfiles for 0 .. 1;
                     
                   (
                       $title,
                       $reserve,
                       $inc,
                       $desc,
                       $image,
                       $start_time,
                       $close_time,
                       undef,
                       @bids
                   ) = @{read_item_file($cat, $item)};
                     
                   @firstbid = @{read_bid($bids[0])};
                   @lastbid = @{read_bid($bids[-1])};

                   $buy_it = $firstbid[3];
                   $start_time > time && next;  
                   $the_time = time;
                   eval $query->{$form{'searchtype'] || next;
                   $line_cnt++;
                   $line_cnt > $config{'page_break'} && do { $line_cnt = 1; $page_cnt++ };

                   # This is saving Memory and CPU-Load ...
                   ($page_cnt - $form{'page'} > 3) && do { undef $ret_val; last };
               # We have reached the PageBreak-Focus - no further informations are needed.
               
                   $page_cnt != $form{'page'} && next;
                 
               $record = join '[]', (
                       $close_time,
                 $image,
                 $cat,
                 $item,
                 $title,
                 $#bids,
                 $buy_it,
                 $lastbid[2]
               );
                 
               push @output, $record;
                   $found++;
               }
       }
   
     foreach $record (sort @output) {
         
         (
               $close_time,
           $image,
           $cat,
           $item,
           $title,
           $bids,
           $buy_it,
           $bid
         ) = split /\[\]/, $record;
         
           @closetime = form_date($close_time);
         
           $buy_it > 0
               ? ($buy_it_info = qq|<font color="green" size="1"><b><i>Buy It <font color="red" size="1">Now</i></b></font>|)
               : ($buy_it_info = "");          
         
           $image
               ?   do {
                 @image = split / /, $image;
                 $image !~ /http\:/
                     ?      ($img_info = qq|<img src="$config{'img_url'}/$image"@{[img_size($image[0], 50)]}>|)
                     :      ($img_info = qq|<img src="$image[0]" width=50 border=0>|);
                 
               }
               :   ($img_info = qq|<img src="$config{'icon_url'}/$config{'no_image'}" border="0">|);
         
           $bid = form_amt($bid);          
           ($row, $rowcolor) = get_row_color($row);
         
print <<EO_HTML if $form{'searchtype'} ne 'items';
   <tr $$rowcolor>
       <td align="center" width="30">$img_info </td>
       <td align="left" valign="middle" nowrap>
           <a class="item" href="$ENV{'SCRIPT_NAME'}?action=dispitem&category=$cat&item=$item&lang=$form{'lang'}">$title   $buy_it_info</a>
       </td>
       <td align="left" nowrap>
           <a class="item" href="$ENV{'SCRIPT_NAME'}?action=search&searchtype=items&searchstring=$cat&lang=$form{'lang'}">
           $category{$cat}</a>
       </td>
       <td align="center" nowrap>$bids</td>
       <td align="right" nowrap>$bid  </td>
       <td align="center" nowrap><font size="1">
           $closetime[0]<br>$closetime[1]</font>
       </td>
   </tr>
EO_HTML

print <<EO_HTML if $form{'searchtype'} eq 'items';
   <tr $$rowcolor>
       <td align="center" width="30">$img_info </td>
       <td align="left" valign="middle" nowrap>
           <a class="item" href="$ENV{'SCRIPT_NAME'}?action=dispitem&category=$cat&item=$item&lang=$form{'lang'}">$title   $buy_it_info</a>
       </td>
       <td align="center" nowrap>$bids</td>
       <td align="right" nowrap>$bid  </td>
       <td align="center" nowrap><font size="1">
           $closetime[0]<br>$closetime[1]</font>
       </td>
   </tr>
EO_HTML

       }
   
print <<EO_HTML if $found == 0;
   <tr bgcolor="$config{'the_row_color'}">
       <td align="center" colspan="6" valign="top" height="50">
           $txt{'There are no items matching your request'}</font><br>
           @{[disp_runtime()]}
       </td>
   </tr>
</table>
<br>
@{[disp_banner('tbl')]}
</div>
<br>
EO_HTML

print <<EO_HTML if $found > 0 and $page_cnt > 0;
</table>
</div>
<br>
EO_HTML

print <<EO_HTML if $found > 0 and $page_cnt == 0;
</table>
<br>
@{[disp_runtime()]}
@{[disp_banner('tbl')]}
</div>
<br>
EO_HTML

   $page_cnt > 0 && pagebreak($page_cnt);
}


Title: Re: sub disp_list (Replacement)
Post by thisolddoll on 11/23/03 at 23:50:37

Hi Dieter!

Tried swapping out the old sub disp_list with the new one on the forum.

Before:
http://www.todauction.com/cgi-bin/dieter/dieterbef.pl?action=search&searchtype=items&searchstring=50&lang=1

and after:
http://www.todauction.com/cgi-bin/dieter/dieteraft.pl?action=search&searchtype=items&searchstring=50&lang=1

However, as you can see from the first, I'd been noodling and came up with this from your "you can do it this way" code.

Also managed to make it work for the my items sub.  :-D

http://www.todauction.com/cgi-bin/dieter/dieter.pl?action=search&searchtype=items&searchstring=50&lang=1

Not using your image size subroutine because these photos in the listing need to be big and it wasn't letting me list with my photos.


# in sub disp_user_auction {
Again Replace this:
#    $image
#       ? ($img_info = qq|<img src="$config{'icon_url'}/$config{'if_image'}" border="0">|)
#       : ($img_info = qq|<img src="$config{'icon_url'}/$config{'no_image'}" border="0">|);
###########
################ with this
           my @image;  #not declared yet in disp_user_auction so do it here
           my $disp_img;  #use in place of img_info because it's used elsewhere and get confusing
           @image = split /\s/, $image;    #white space delimiter
           $image
      ?   do {                        
               $image !~ /http\:/  #this assumes the user didn't put in any direct links along with upload
                   ? ($disp_img = qq|<img src="$config{'img_url'}/$image[0]" width=50 border=0>|)
                    : ($disp_img = qq|<img src="$image[0]" width=50 border=0>|);
                }
         :   ($disp_img = qq|<img src="$config{'icon_url'}/$config{'no_image'}" border="0">|);

#################    
#Then instead of the line after this:
#print <<EO_HTML if $form{'searchtype'} =~ /^my_/;
#    <tr $$rowcolor>
#put this:
<td align="center" width="50">$disp_img</td>


#####################################
#
#  In sub disp_list
#
Replace this:
#    $image
#       ? ($img_info = qq|<img src="$config{'icon_url'}/$config{'if_image'}" border="0">|)
#       : ($img_info = qq|<img src="$config{'icon_url'}/$config{'no_image'}" border="0">|);
################ with this
           my $disp_img;
           @image = split /\s/, $image;  
           $image
                  ?   do {                        
                         $image !~ /http\:/
                         ? ($disp_img = qq|<img src="$config{'img_url'}/$image[0]" width=50 border=0>|)
                       : ($disp_img = qq|<img src="$image[0]" width=50 border=0>|);
   
              }
     :   ($disp_img = qq|<img src="$config{'icon_url'}/$config{'no_image'}" border="0">|);

#################  
and substitute $disp_img for img_info in the two html blocks:
print <<EO_HTML unless $form{'searchtype'} =~ /^my_/;
   <tr $$rowcolor>
       <td align="center" width="50">$disp_img</td>


print <<EO_HTML if $form{'searchtype'} =~ /^my_/;
   <tr $$rowcolor>
       <td align="center" width="50">$disp_img</td>


So, do that call that a "case statement" in perl?

Nice!

Thanks, Dieter!
Michele







Title: Re: sub disp_list (Replacement)
Post by www.blitzday.com on 08/26/04 at 13:08:47

Michelles Way does not work for me as the uses strings which i cannot  even find back in the whole script like:

print <<EO_HTML if $form{'searchtype'} =~ /^my_/;

especially the =~ /^my_/;

Does someone have a  good working script which indeed shows on  the first page where the top items are listed which shows a a little  thumbnail? ie 20 x 20

Please met me know if you do, as will i try to figue out how to do this, you might save me time though :-)


The eAuction Support Forums » Powered by YaBB 2.2!
YaBB © 2000-2007. All Rights Reserved.