<?php
/**
 * product_listing module
 *
 * @package modules
 * @copyright Copyright 2003-2011 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: product_listing.php 18695 2011-05-04 05:24:19Z drbyte $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
$show_submit = zen_run_normal();
$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_PRODUCTS_LISTING, 'p.products_id', 'page');
$zco_notifier->notify('NOTIFY_MODULE_PRODUCT_LISTING_RESULTCOUNT', $listing_split->number_of_rows);
$how_many = 0;

$zc_col_count_description = 0;
$lc_align = '';

if ($listing_split->number_of_rows > 0) {
  $row = 0;
  $col = 0;
  $listing = $db->Execute($listing_split->sql_query);
  $extra_row = 0;
  while (!$listing->EOF) {

    $products_price = zen_get_products_display_price($listing->fields['products_id']);
    if (!isset($productsInCategory[$listing->fields['products_id']])) $productsInCategory[$listing->fields['products_id']] = zen_get_generated_category_path_rev($listing->fields['master_categories_id']);

    $additional_images = genesis_get_additional_images( $listing->fields['products_id'] );

    $product_image = '<div class="product-images ' . ( $additional_images && zen_not_null($genesis_options['products_additional_image']) ? 'has_additional' : '') . '"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . $productsInCategory[$listing->fields['products_id']] . '&products_id=' . $listing->fields['products_id']) . '">';
    if( $listing->fields['products_image'] != '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS != 0 ){
      $product_image .= sprintf( '<div class="product-main-images">%s</div>', zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="img-responsive"') );
    }
    
    if( $additional_images && zen_not_null($genesis_options['products_additional_image']) ){
      $product_image .= sprintf( '<div class="product-additional-images">%s</div>', zen_image($additional_images[0], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="img-responsive"') );
    }
    $product_image .= '</a>';
    $product_image .= '</div>';

    if( zen_not_null($genesis_options['products_category']) ){
      $product_cat = sprintf( '<div class="product-category">%s</div>', zen_get_categories_name( $listing->fields['master_categories_id'] ) );
    }else{
      $product_cat = '';
    }

    $product_name = sprintf( '<h2 class="product-name"><a href="%s">%s</a></h2>', zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . $productsInCategory[$listing->fields['products_id']] . '&products_id=' . $listing->fields['products_id']), $listing->fields['products_name'] );

    $product_price = sprintf( '<div class="product-price">%s</div>', zen_get_products_display_price($listing->fields['products_id']) );

    if( zen_not_null($genesis_options['products_action']) ){
      $button = genesis_get_product_action( $listing->fields, $how_many );
      $how_many += $button['how_many'];

      $product_action = '<div class="product-action">' . $button['button'] . '</div>';
    }

    $list_box_contents[$row][$col] = array( 
      'params'  => 'class="product column"',
      'text'    => $product_image  . $product_cat . $product_name . $product_price . $product_action
    );
        
    $col ++;

    $listing->MoveNext();
  }
  $error_categories = false;
} else {
  $list_box_contents = array();

  $list_box_contents[0] = array('params' => 'class="productListing-odd"');
  $list_box_contents[0][] = array('params' => 'class="productListing-data"',
                                              'text' => TEXT_NO_PRODUCTS);

  $error_categories = true;
}

if (($how_many > 0 and $show_submit == true and $listing_split->number_of_rows > 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == 1 or  PRODUCT_LISTING_MULTIPLE_ADD_TO_CART == 3) ) {
  $show_top_submit_button = true;
} else {
  $show_top_submit_button = false;
}
if (($how_many > 0 and $show_submit == true and $listing_split->number_of_rows > 0) and (PRODUCT_LISTING_MULTIPLE_ADD_TO_CART >= 2) ) {
  $show_bottom_submit_button = true;
} else {
  $show_bottom_submit_button = false;
}

unset($columns);
unset($classes);

$columns = 3;
$classes = 'products grid';

