<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  $listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');
?>


<?php
  if ( ($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {
?>
<?php echo tep_draw_result1_top(); ?> 
        	<div class="result_left"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></div>
          <div class="result_right"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></div>
<?php echo tep_draw_result1_bottom(); ?>        
<?php
  }
	/* *************************************** */	
		if ($listing_split->number_of_rows > 0) {
	  $row = 0;
	  $col = 0;
		$image_width = (SEARCH_RESULTS_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_WIDTH : SEARCH_RESULTS_IMAGE_WIDTH;
		$image_height = (SEARCH_RESULTS_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_HEIGHT : SEARCH_RESULTS_IMAGE_HEIGHT;
		$image_width_row = (SEARCH_RESULTS_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_WIDTH_ROW : SEARCH_RESULTS_IMAGE_WIDTH_ROW;
		$image_height_row = (SEARCH_RESULTS_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_HEIGHT_ROW : SEARCH_RESULTS_IMAGE_HEIGHT_ROW;
	 	$col_items = (MAX_DISPLAY_SEARCH_RESULTS_PER_ROW - 1);
		
		if (MAX_DISPLAY_SEARCH_RESULTS_PER_ROW  <= 1)	{
			$products_block_width = 100;
			$products_block_width .= '%';
			$view = 'r_view';
			$equal_height_products_block = 'equal-height_listing_block';
			$equal_height_products_name = 'equal-height_listing_name';
			$equal_height_products_name2 = 'equal-height_listing_name2';			
			$equal_height_products_desc = 'equal-height_listing_desc'; 
		}else{
			$products_block_width = PRODS_BLOCK_SEARCH_WIDTH.'px';
			$view = 't_view';
			$equal_height_products_block = 'equal-height_listing_block';
			$equal_height_products_name = 'equal-height_listing_name';
			$equal_height_products_name2 = 'equal-height_listing_name2';			
			$equal_height_products_desc = 'equal-height_listing_desc'; 
		}
  	
    $listing_query = tep_db_query($listing_split->sql_query);
		
  	$prod_contents_grid .= '<div class="content '.$view.'">';
  	$prod_contents_row .= '<div class="content '.$view.'">';		
    while ($listing = tep_db_fetch_array($listing_query)) {
			if (($col === 0) && ($row != 0)) {
				$prod_contents_grid .= '<ul class="row_separator"><li class="prods_hseparator">'.tep_draw_separator('spacer.gif', '1', '1').'</li></ul>'. "\n";
				$prod_contents_row .= '<ul class="row_separator"><li class="prods_hseparator">'.tep_draw_separator('spacer.gif', '1', '1').'</li></ul>'. "\n";
			} 			 
			if ($col === 0) {
					$prod_contents_grid .= '<ul class="row_listing_desc row_listing_name row_listing_block" id="view_grid-'.$row.'">'. "\n";
					$prod_contents_row .= '<ul id="view_row-'.$row.'">'. "\n";
			 }else {
				$prod_contents_grid .= '<li class="prods_vseparator '.$equal_height_products_block.'">'.tep_draw_separator('spacer.gif', '1', '1').''; 
				$prod_contents_row .= '<li class="prods_vseparator">'.tep_draw_separator('spacer.gif', '1', '1').''; 
			 }
// *************************************
// *************************************

      for ($col_sort=0, $n=sizeof($column_list); $col_sort<$n; $col_sort++) {
        switch ($column_list[$col_sort]) {
          case 'PRODUCT_LIST_MODEL':
            $p_model = '<tr>
							<td class="td_left"><b><strong>'.TABLE_HEADING_MODEL.'&nbsp;:</strong></b></td>
							<td class="td_right"><strong>' . $listing['products_model'] . '</strong></td>
						</tr>';
            break;
      //    case 'PRODUCT_LIST_NAME':
//            break;
          case 'PRODUCT_LIST_MANUFACTURER':
            $p_manufact = '<tr>
							<td class="td_left"><b><strong>'.TABLE_HEADING_MANUFACTURER.'&nbsp;:</strong></b></td>
							<td class="td_right"><strong><a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' .$listing['manufacturers_name'].  '</a></strong></td>
						  </tr>';
            break;
          case 'PRODUCT_LIST_PRICE':
						$persent = '';
						if (tep_not_null($listing['specials_new_products_price'])) {
										$products_price = $lc_text = '<div class="product_price_wrapper price '.$extra.'"><b>'.PRICE. '</b><del>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</del> <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></div>';
										$extra = 'extra';
										$persent = ($currencies->display_sale_percent($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id']), $listing['specials_new_products_price']) * -1);
										$sale_percent = '<div class="sale_percent '.$color.'"><strong>'.$persent.'%</strong></div>';
						} else {
										$products_price = $lc_text = '<div class="product_price_wrapper price '.$extra.'"><b>'.PRICE. '</b><span class="productSpecialPrice">' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></div>';
										$extra = '';
										$sale_percent	= '';
						}
						$p_price =  $products_price;
						$p_price = ((PRODUCT_LIST_PRICE >= '1') ? $products_price : '');
            break;
          case 'PRODUCT_LIST_QUANTITY':
            $p_qty = '	<tr>
							<td class="td_left"><b><strong>'.TABLE_HEADING_QUANTITY.'&nbsp;:</strong></b></td>
							<td class="td_right"><strong>' . $listing['products_quantity'] . '</strong></td>
						</tr>';
            break;
          case 'PRODUCT_LIST_WEIGHT':
            $p_weight = '<tr>
							<td class="td_left"><b><strong>'.TABLE_HEADING_WEIGHT.'&nbsp;:</strong></b></td>
							<td class="td_right"><strong>' . $listing['products_weight'] . '</strong></td>
						</tr>';
/*						
*/         
            break;
          	case 'PRODUCT_LIST_IMAGE':
          //	PRODUCT_LIST_IMAGE
						if (isset($HTTP_GET_VARS['manufacturers_id'])  && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
							$p_pic = '<div class="product_pic_wrapper" style="width:'.$image_width.'px;height:'.$image_height.'px;"><a class="product_img" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '" style="width:'.$image_width.'px;height:'.$image_height.'px;">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], $image_width, $image_height, ' style="width:'.$image_width.'px;height:'.$image_height.'px;"') . '</a></div>';
							$p_pic_row = '<div class="product_pic_wrapper" style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;"><a class="product_img" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '" style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], $image_width_row, $image_height_row, ' style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;"') . '</a></div>';
						} else {
							$p_pic = '<div class="product_pic_wrapper" style="width:'.$image_width.'px;height:'.$image_height.'px;"><a class="product_img" href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '" style="width:'.$image_width.'px;height:'.$image_height.'px;">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], $image_width, $image_height, ' style="width:'.$image_width.'px;height:'.$image_height.'px;"') . '</a></div>';
							$p_pic_row = '<div class="product_pic_wrapper" style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;"><a class="product_img" href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '" style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], $image_width_row, $image_height_row, ' style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;"') . '</a></div>';
						}
            break;
			
	    }
			$p_id = $listing['products_id'];
			$featured_query = tep_db_query("select status, products_id from " . TABLE_FEATURED . " where products_id = '" . (int)$listing['products_id'] . "'");
			$featured_product = tep_db_fetch_array($featured_query);
			$p_featured = (($featured_product['status']) ? '<div class="featured_label '.$color.'"><strong></strong></div>' : '');
		
			$product_query = tep_db_query("select products_description, products_id from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$listing['products_id'] . "' and language_id = '" . (int)$languages_id . "'");
      $product = tep_db_fetch_array($product_query);
		
			$p_desc = (MAX_DESCR_LISTING !=0) ? '<div class="product_desc_wrapper desc '.$equal_height_products_desc.'">'.mb_substr(strip_tags($product['products_description']), 0, MAX_DESCR_LISTING, 'UTF-8').'...</div>' : '';
			$p_desc_row = (MAX_DESCR_LISTING_ROW !=0) ? '<div class="product_desc_wrapper desc">'.mb_substr(strip_tags($product['products_description']), 0, MAX_DESCR_LISTING_ROW, 'UTF-8').'...</div>' : '';

			if (PRODUCT_LIST_MODEL != 0 || PRODUCT_LIST_MANUFACTURER != 0 || PRODUCT_LIST_QUANTITY != 0 || PRODUCT_LIST_WEIGHT != 0) {
			$p_listing = '<div class="listing"><table>'.$p_model.''.$p_manufact.'' . ''.$p_qty.'' . ''.$p_weight.'</table></div>';
			}
			
			
			
			if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
				
			$p_name = (PRODUCT_LIST_NAME != '0') ? '<h3 class="product_name_wrapper name '.$equal_height_products_name.'"><span><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a></span></h3>' : '';
			} else {
			$p_name = (PRODUCT_LIST_NAME != '0') ? '<h3 class="product_name_wrapper name '.$equal_height_products_name.'"><span><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a></span></h3>' : '';
			}
			if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
			$p_name2 = (PRODUCT_LIST_NAME != '0') ? '<h3 class="product_name_wrapper name"><span><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a></span></h3>' : '';
			} else {
			$p_name2 = (PRODUCT_LIST_NAME != '0') ? '<h3 class="product_name_wrapper name"><span><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a></span></h3>' : '';
			}
			$p_details_text = '' .tep_draw_button2_top() . '<a href="' . tep_href_link('product_info.php?products_id='.$p_id) . '" role="button"><span class="ui-button-text">'.  IMAGE_BUTTON_DETAILS .'</span></a>' . tep_draw_button2_bottom().'';
	
			$p_buy_now_text = '' .tep_draw_button1_top() . '<a href="'.tep_href_link("products_new.php","action=buy_now&products_id=".$p_id).'" role="button"><span class="ui-button-text">'.  IMAGE_BUTTON_IN_CART .'</span></a>' . tep_draw_button1_bottom().'';
			$button_block = (SEARCH_RESULTS_SHOW_BUTTONS == 'Show') ? '<div class="product_button_wrapper">'.$p_buy_now_text.' '.$p_details_text.'</div>' : '';
		}
		
		$p_data_add = ((SEARCH_RESULTS_SHOW_DATA_ADD == 'Show' && $listing['products_date_added'] != NULL) ? '<div class="fl_left"><span>' . TEXT_DATE_ADDED . '</span> ' . tep_date_short($listing['products_date_added']) . '</div>' : '');
		$p_data_mod = ((SEARCH_RESULTS_SHOW_DATA_MOD == 'Show' && $listing['products_last_modified'] != NULL) ? '<div class="fl_right"><span>' . TEXT_DATE_LAST_MOD . '</span> ' . tep_date_short($listing['products_last_modified']) . '</div>' : '');
		$p_data_exp = ((SPECIALS_PAGE_SHOW_DATA_EXP == 'Show' && $listing['expires_date'] != NULL) ? '<div class="data extra"><span>' . TEXT_DATE_LAST_EXP . '</span><br />' . tep_date_short($listing['expires_date']) . '</div>' : '');
		$p_data_exp_row = ((SPECIALS_PAGE_SHOW_DATA_EXP == 'Show' && $listing['expires_date'] != NULL) ? '<div class="data extra"><span>' . TEXT_DATE_LAST_EXP . '</span> ' . tep_date_short($listing['expires_date']) . '</div>' : '');		
		$p_data = (($p_data_add != NULL || $p_data_mod != NULL) ? '<div class="data">'.$p_data_add .' '. $p_data_mod.'</div>' : '');

			if ($p_name !='' || $p_desc !='' || $p_price !='' || $button_block !='' ||  $p_listing !='') {
				$wrapper_top = '<div class="product_info_wrapper">';
				$wrapper_bottom = '</div>';
			}else {
				$wrapper_top = '';
				$wrapper_bottom = '';
			}
   $prod_contents_grid .= ''. "\n".
					'<li class="responsive_block" style="width:'.$products_block_width.'">'. "\n".
				  '		<div class="product_block '.$equal_height_products_block.'">'. "\n".
					'			'.$p_pic.''. "\n". 
					'			'.$p_featured . "\n".
					'			'.$sale_percent . "\n".
          '			'. "\n".	
				  '			'.$wrapper_top.''."\n".
					'   			'.$p_data.''. "\n".	
					'    		<div class="row_01">'. "\n".								
					'					'.$p_name.''. "\n".	
					'					'.$p_manufacturers.''. "\n".	
					'					'.$p_desc.''. "\n".
					'         '.$p_listing.''. "\n".	
					'				</div>'. "\n".	
					'				<div class="row_02">'. "\n".	
					'					<div class="cl_both block">'.$p_data_exp.''. "\n".																	
					'					'.$p_price.'</div>'. "\n".
					'					'.$button_block.''. "\n".	
					'				</div>'. "\n".	
				  '		'.$wrapper_bottom.''."\n".			  
				  '		</div>'. "\n";
						
   $prod_contents_row .= ''. "\n".
					'<li class="responsive_block" style="width:100%">'. "\n".
				  '		<div class="product_block"><div>'. "\n".
					'			'.$p_pic_row.''. "\n". 
					'			'.$p_featured . "\n".
					'			'.$sale_percent . "\n".
          '			'. "\n".	
				  '			'.$wrapper_top.''."\n".
					'   			'.$p_data.''. "\n".	
					'				<div class="row_02">'. "\n".	
					'					'.$p_price.''. "\n".
					'					'.$p_data_exp_row.''. "\n".																	
					'					'.$button_block.''. "\n".	
					'				</div>'. "\n".	
					'    		<div class="row_01">'. "\n".								
					'					'.$p_name.''. "\n".	
					'					'.$p_manufacturers.''. "\n".	
					'					'.$p_desc_row.''. "\n".
					'         '.$p_listing.''. "\n".	
					'				</div>'. "\n".	
				  '		'.$wrapper_bottom.''."\n".			  
				  '		</div></div>'. "\n";			  
							  
    $col ++;
    if ($col > $col_items) {
      	$prod_contents_grid .= '</ul>'. "\n";
				$prod_contents_row .= '</ul>'. "\n";
	  	$row ++;
      	$col = 0;
    }else{
		$prod_contents_grid .= '</li>'. "\n";
		$prod_contents_row .= '</li>'. "\n";
		}
  }
	  $prod_contents_grid .= '</div>'. "\n";
	  $prod_contents_row .= '</div>'. "\n";
/* *************************************** */
?>
<div class="contentContainer module_listing">
	  <div id="tabs-1">
        <div class="contentBlock grid_view"><?php echo $prod_contents_grid;?></div>
<script type="text/javascript">
$(document).ready(function(){ 
	 var row_list_listing_block = $('.row_listing_block');
	 row_list_listing_block.each(function(){
		 new equalHeights_listing_block($('#' + $(this).attr("id")));
	});
	 var row_list_listing_name = $('.row_listing_name');
	 row_list_listing_name.each(function(){
		 new equalHeights_listing_name($('#' + $(this).attr("id")));
	});
	 var row_list_listing_desc = $('.row_listing_desc');
	 row_list_listing_desc.each(function(){
		 new equalHeights_listing_desc($('#' + $(this).attr("id")));
	});	
})				     			  		 			 			  			  			  			  			   
</script>        
        
	  </div>
	  <div id="tabs-2">
        <div class="contentBlock row_view"><?php echo $prod_contents_row; ?></div>
	  </div>
</div>
<?php	
  } else {
?>
    <p><?php echo TEXT_NO_PRODUCTS; ?></p>
 <script type="text/javascript">
$(document).ready(function(){ 
	 $(".row_table").css('display','none');
})				     			  		 			 			  			  			  			  			   
</script>        
   
<?php
  }
  if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>
<?php echo tep_draw_result2_top(); ?> 
        	<div class="result_left"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></div>
          <div class="result_right"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></div>
<?php echo tep_draw_result2_bottom(); ?> 
<?php
  }
?>
