<?php
/*
  $Id$

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

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/	
		$max_dnpm = (($current_page == FILENAME_DEFAULT) ? NEW_PRODUCTS_MODUL_MAX_DISPLAY_FIRST_PAGE : NEW_PRODUCTS_MODUL_MAX_DISPLAY);
		if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
			$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, p.products_date_added, p.products_last_modified, s.specials_new_products_price, p.products_price  from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added desc limit " . $max_dnpm);
		} else {
			$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, p.products_date_added, p.products_last_modified, s.specials_new_products_price, p.products_price  from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, 
			" . TABLE_PRODUCTS_DESCRIPTION . " pd, 
			" . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, 
			" . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added desc limit " . $max_dnpm);
		}
	$text_no_product = false;		
	$cooke_name	= (($current_page == FILENAME_DEFAULT) ? 'startTab_module_new_product2' : 'startTab_module_new_product');
  $col = 0;
  $row = 0;
	$col_items = (($current_page == FILENAME_DEFAULT) ? MAX_DISPLAY_NEW_PRODUCTS_MODUL_PER_ROW_FIRST_PAGE - 1 : MAX_DISPLAY_NEW_PRODUCTS_MODUL_PER_ROW - 1);
	$name = ($current_page == FILENAME_DEFAULT) ? NEW_PRODUCTS_MODUL_SHOW_NAME_FIRST_PAGE : NEW_PRODUCTS_MODUL_SHOW_NAME;
	if ($current_page == FILENAME_DEFAULT)	{
	$image_width = (NEW_PRODUCTS_MODUL_GENERAL_CUSTOM_IMAGE_SIZE_FIRST_PAGE == 'General') ? GENERAL_IMAGE_WIDTH : NEW_PRODUCTS_MODUL_IMAGE_WIDTH_FIRST_PAGE;
	$image_height = (NEW_PRODUCTS_MODUL_GENERAL_CUSTOM_IMAGE_SIZE_FIRST_PAGE == 'General') ? GENERAL_IMAGE_HEIGHT : NEW_PRODUCTS_MODUL_IMAGE_HEIGHT_FIRST_PAGE;
	$image_width_row = (NEW_PRODUCTS_MODUL_GENERAL_CUSTOM_IMAGE_SIZE_FIRST_PAGE == 'General') ? GENERAL_IMAGE_WIDTH_ROW : NEW_PRODUCTS_MODUL_IMAGE_WIDTH_ROW_FIRST_PAGE;
	$image_height_row = (NEW_PRODUCTS_MODUL_GENERAL_CUSTOM_IMAGE_SIZE_FIRST_PAGE == 'General') ? GENERAL_IMAGE_HEIGHT_ROW : NEW_PRODUCTS_MODUL_IMAGE_HEIGHT_ROW_FIRST_PAGE;
	$label_specials = NEW_PRODUCTS_MODUL_SHOW_SPECIALS_LABEL_FIRST_PAGE;
	$label_featured = NEW_PRODUCTS_MODUL_SHOW_FEATURED_LABEL_FIRST_PAGE;
	$row_new_products_desc = (NEW_PRODUCTS_MODUL_MAX_DESCR_FIRST_PAGE != 0) ? 'row_new_products_desc' : '';
	$row_new_products_name = (NEW_PRODUCTS_MODUL_SHOW_NAME_FIRST_PAGE == 'Show') ? 'row_new_products_name' : '';	
		if (MAX_DISPLAY_NEW_PRODUCTS_MODUL_PER_ROW_FIRST_PAGE  >= 1 && NEW_PRODUCTS_MODUL_LYOUT_FIRST_PAGE =='Grid')	{
			$products_block_width = NEW_PRODUCTS_MODUL_BLOCK_WIDTH_FIRST_PAGE.'px';
			$r_view = 't_view';
			$equal_height_products_block = 'equal-height_new_products_block';
			$equal_height_products_name = 'equal-height_new_products_name';
			$equal_height_products_desc = 'equal-height_new_products_desc'; 
		}else{
			$products_block_width = 100;
			$products_block_width .= '%';
			$r_view = 'r_view';
			$equal_height_products_block = 'equal-height_new_products_block';
			$equal_height_products_name = 'equal-height_new_products_name';
			$equal_height_products_desc = 'equal-height_new_products_desc'; 
		}
	}else{
	$image_width = (NEW_PRODUCTS_MODUL_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_WIDTH : NEW_PRODUCTS_MODUL_IMAGE_WIDTH;
	$image_height = (NEW_PRODUCTS_MODUL_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_HEIGHT : NEW_PRODUCTS_MODUL_IMAGE_HEIGHT;
	$image_width_row = (NEW_PRODUCTS_MODUL_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_WIDTH_ROW : NEW_PRODUCTS_MODUL_IMAGE_WIDTH_ROW;
	$image_height_row = (NEW_PRODUCTS_MODUL_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_HEIGHT_ROW : NEW_PRODUCTS_MODUL_IMAGE_HEIGHT_ROW;
	$label_specials = NEW_PRODUCTS_MODUL_SHOW_SPECIALS_LABEL;
	$label_featured = NEW_PRODUCTS_MODUL_SHOW_FEATURED_LABEL;
	$row_new_products_desc = (NEW_PRODUCTS_MODUL_MAX_DESCR != 0) ? 'row_new_products_desc' : '';
	$row_new_products_name = (NEW_PRODUCTS_MODUL_SHOW_NAME == 'Show') ? 'row_new_products_name' : '';		
		if (MAX_DISPLAY_NEW_PRODUCTS_MODUL_PER_ROW  >= 1 && NEW_PRODUCTS_MODUL_LYOUT =='Grid')	{
			$products_block_width = NEW_PRODUCTS_MODUL_BLOCK_WIDTH.'px';
			$r_view = 't_view';
			$equal_height_products_block = 'equal-height_new_products_block';
			$equal_height_products_name = 'equal-height_new_products_name';
			$equal_height_products_desc = 'equal-height_new_products_desc'; 
		}else{
			$products_block_width = 100;
			$products_block_width .= '%';
			$r_view = 'r_view';
			$equal_height_products_block = 'equal-height_new_products_block';
			$equal_height_products_name = 'equal-height_new_products_name';
			$equal_height_products_desc = 'equal-height_new_products_desc'; 
		}
	}
  $new_prods_content .= '<div class="content '.$view.'">';
	$new_prods_content_row .= '<div class="content '.$view.'">';
  while ($new_products = tep_db_fetch_array($new_products_query)) {
		$new_prods_content .= (($col === 0) && ($row != 0)) ? '<ul class="row_separator"><li class="prods_hseparator">'.tep_draw_separator('spacer.gif', '1', '1').'</li></ul>' : '';
		$new_prods_content_row .= (($col === 0) && ($row != 0)) ? '<ul class="row_separator"><li class="prods_hseparator">'.tep_draw_separator('spacer.gif', '1', '1').'</li></ul>' : '';
		$new_prods_content .= ($col === 0) ? '<ul class="'.$row_new_products_name.' '.$row_new_products_desc.' row_new_products_block" id="view_grid-'.$row.'">' : '<li class="prods_vseparator '.$equal_height_products_block.'">'.tep_draw_separator('spacer.gif', '1', '1').'';
		$new_prods_content_row .= ($col === 0) ? '<ul class="'.$row_new_products_name.' '.$row_new_products_desc_row.' row_new_products_block" id="view_row-'.$row.'">' : '<li class="prods_vseparator">'.tep_draw_separator('spacer.gif', '1', '1').'';
// *************************************		
		$p_id = $new_products['products_id'];	
  	$featured_query = tep_db_query("select status, products_id from " . TABLE_FEATURED . " where products_id = '" . (int)$new_products['products_id'] . "'");
    $featured_product = tep_db_fetch_array($featured_query);
		$p_featured = (($label_featured == 'Show' && $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)$p_id . "' and language_id = '" . (int)$languages_id . "'");
		$product = tep_db_fetch_array($product_query);
		$p_pic = (($current_page == FILENAME_DEFAULT) ? ((NEW_PRODUCTS_MODUL_SHOW_THUMBS_FIRST_PAGE == 'Show') ? '<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, 'products_id=' . $p_id) . '" style="width:'.$image_width.'px;height:'.$image_height.'px;">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], $image_width, $image_height, ' style="width:'.$image_width.'px;height:'.$image_height.'px;"') . '</a></div>' : '') : ((NEW_PRODUCTS_MODUL_SHOW_THUMBS == 'Show') ? '<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, 'products_id=' . $p_id) . '" style="width:'.$image_width.'px;height:'.$image_height.'px;">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], $image_width, $image_height, ' style="width:'.$image_width.'px;height:'.$image_height.'px;"') . '</a></div>' : ''));
		$p_pic_row = (($current_page == FILENAME_DEFAULT) ? ((NEW_PRODUCTS_MODUL_SHOW_THUMBS_FIRST_PAGE == 'Show') ? '<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, 'products_id=' . $p_id) . '" style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], $image_width_row, $image_height_row, ' style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;"') . '</a></div>' : '') : ((NEW_PRODUCTS_MODUL_SHOW_THUMBS == 'Show') ? '<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, 'products_id=' . $p_id) . '" style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], $image_width_row, $image_height_row, ' style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;"') . '</a></div>' : ''));
		if ($new_price = tep_get_products_special_price($new_products['products_id'])) {
						$products_price = '<div class="product_price_wrapper price '.$extra.'"><b>'.PRICE. '</b><del>' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])) . '</del> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($new_products['products_tax_class_id'])) . '</span></div>';
						$extra = 'extra';
						$persent = ($currencies->display_sale_percent($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id']), $new_price) * -1);
						$sale_percent = (($label_specials == 'Show') ? '<div class="sale_percent '.$color.'"><strong>'.$persent.'%</strong></div>' : '');
		} else {
						$products_price = '<div class="product_price_wrapper price '.$extra.'"><b>'.PRICE. '</b><span class="productSpecialPrice">' .$currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])).'</span></div>';
						$extra = '';
						$sale_percent	= '';
    } $text_no_product = true;  
		$p_price = (($current_page == FILENAME_DEFAULT) ? ((NEW_PRODUCTS_MODUL_SHOW_PRICE_FIRST_PAGE == 'Show') ? $products_price : '') : ((NEW_PRODUCTS_MODUL_SHOW_PRICE == 'Show') ? $products_price : '') );
		$p_name = (($current_page == FILENAME_DEFAULT) ? ((NEW_PRODUCTS_MODUL_SHOW_NAME_FIRST_PAGE == 'Show') ? '<h3 class="product_name_wrapper name '.$equal_height_products_name.'"><span><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $p_id) . '">' . $new_products['products_name'] . '</a></span></h3>' : '') : ((NEW_PRODUCTS_MODUL_SHOW_NAME == 'Show') ? '<h3 class="product_name_wrapper name '.$equal_height_products_name.'"><span><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $p_id) . '">' . $new_products['products_name'] . '</a></span></h3>' : ''));
		$p_desc = (($current_page == FILENAME_DEFAULT) ? ((NEW_PRODUCTS_MODUL_MAX_DESCR_FIRST_PAGE !=0) ? '<div class="product_desc_wrapper desc '.$equal_height_products_desc.'">'.mb_substr(strip_tags($product['products_description']), 0, NEW_PRODUCTS_MODUL_MAX_DESCR_FIRST_PAGE, 'UTF-8').'...</div>' : '') : ((NEW_PRODUCTS_MODUL_MAX_DESCR !=0) ? '<div class="product_desc_wrapper desc '.$equal_height_products_desc.'">'.mb_substr(strip_tags($product['products_description']), 0, NEW_PRODUCTS_MODUL_MAX_DESCR, 'UTF-8').'...</div>' : ''));
		$p_desc_row = (($current_page == FILENAME_DEFAULT) ? ((NEW_PRODUCTS_MODUL_MAX_DESCR_ROW_FIRST_PAGE !=0) ? '<div class="product_desc_wrapper desc '.$equal_height_products_desc.'">'.mb_substr(strip_tags($product['products_description']), 0, NEW_PRODUCTS_MODUL_MAX_DESCR_ROW_FIRST_PAGE, 'UTF-8').'...</div>' : '') : ((NEW_PRODUCTS_MODUL_MAX_DESCR_ROW !=0) ? '<div class="product_desc_wrapper desc '.$equal_height_products_desc.'">'.mb_substr(strip_tags($product['products_description']), 0, NEW_PRODUCTS_MODUL_MAX_DESCR_ROW, 'UTF-8').'...</div>' : ''));
		$p_data_add = (($current_page == FILENAME_DEFAULT) ? ((NEW_PRODUCTS_MODUL_SHOW_DATA_ADD_FIRST_PAGE == 'Show' && $new_products['products_date_added'] != NULL) ? '<div class="fl_left"><span>' . TEXT_DATE_ADDED . '</span> ' . tep_date_short($new_products['products_date_added']) . '</div>' : '') : ((NEW_PRODUCTS_MODUL_SHOW_DATA_ADD == 'Show' && $new_products['products_date_added'] != NULL) ? '<div class="fl_left"><span>' . TEXT_DATE_ADDED . '</span> ' . tep_date_short($new_products['products_date_added']) . '</div>' : ''));
		$p_data_mod = (($current_page == FILENAME_DEFAULT) ? ((NEW_PRODUCTS_MODUL_SHOW_DATA_MOD_FIRST_PAGE == 'Show' && $new_products['products_last_modified'] != NULL) ? '<div class="fl_right"><span>' . TEXT_DATE_LAST_MOD . '</span> ' . tep_date_short($new_products['products_last_modified']) . '</div>' : '') : ((NEW_PRODUCTS_MODUL_SHOW_DATA_MOD == 'Show' && $new_products['products_last_modified'] != NULL) ? '<div class="fl_right"><span>' . TEXT_DATE_LAST_MOD . '</span> ' . tep_date_short($new_products['products_last_modified']) . '</div>' : ''));
	  $p_data = (($current_page == FILENAME_DEFAULT) ? (($p_data_add != NULL || $p_data_mod != NULL) ? '<div class="data">'.$p_data_add .' '. $p_data_mod.'</div>' : '') : (($p_data_add != NULL || $p_data_mod != NULL) ? '<div class="data">'.$p_data_add .' '. $p_data_mod.'</div>' : ''));
		$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 = (($current_page == FILENAME_DEFAULT) ? ((NEW_PRODUCTS_MODUL_SHOW_BUTTONS_FIRST_PAGE == 'Show') ? '<div class="product_button_wrapper">'.$p_buy_now_text.''.$p_details_text.'</div>' : '') : ((NEW_PRODUCTS_MODUL_SHOW_BUTTONS == 'Show') ? '<div class="product_button_wrapper">'.$p_buy_now_text.''.$p_details_text.'</div>' : ''));
		
// *************************************
		if ($p_name !='' || $p_desc !='' || $p_price !='' || $p_buttons_text !='') {
			$wrapper_top = '<div class="product_info_wrapper">';
			$wrapper_bottom = '</div>';
		}else {
			$wrapper_top = '';
			$wrapper_bottom = '';
		}

		$new_prods_content .= ''. "\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".	
					'				</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";	
   $new_prods_content_row .= ''. "\n".
					'<li class="responsive_block" style="width:'.$products_block_width.'">'. "\n".
				  '		<div class="product_block '.$equal_height_products_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".	
					'				</div>'. "\n".	
				  '		'.$wrapper_bottom.''."\n".			  
				  '		</div></div>'. "\n";			  
							  
		$col ++;
    if ($col > $col_items) {
      $new_prods_content .= '</ul>';
		  $new_prods_content_row .= '</ul>';
	  	$row ++;
      $col = 0;
    }else{
			$new_prods_content .= '</li>';	
			$new_prods_content_row .= '</li>';	
		}
  }
  $new_prods_content .= '</div>'. "\n";	
	$new_prods_content_row .= '</div>'. "\n";	

?>
<div class="contentContainer module_new_product">
<?php
echo (($current_page == FILENAME_DEFAULT) ? ((NEW_PRODUCTS_MODUL_LYOUT_FIRST_PAGE =='Grid') ? '
	  <div id="tabs-new_grid">
        <div class="contentBlock grid_view">'.$new_prods_content.'</div>
	  </div>
<script type="text/javascript">
$(document).ready(function(){ 				
	var row_list_new_products_name = $(\'.row_new_products_name\');
		 row_list_new_products_name.each(function(){
			new equalHeights_new_products_name($(\'#\' + $(this).attr("id")));
	});			 			 			  			  			  			  			   
	 var row_list_new_products_block = $(\'.row_new_products_block\');
		 row_list_new_products_block.each(function(){
			new equalHeights_new_products_block($(\'#\' + $(this).attr("id")));
	});	
	var row_list_new_products_desc = $(\'.row_new_products_desc\');
		 row_list_new_products_desc.each(function(){
			new equalHeights_new_products_desc($(\'#\' + $(this).attr("id")));
	});	
});	
</script>
		' : '
	  <div id="tabs-new_row">
        <div class="contentBlock row_view">'.$new_prods_content_row.'</div>
	  </div>')
		 : ((NEW_PRODUCTS_MODUL_LYOUT =='Grid') ? '
	  <div id="tabs-new_grid">
        <div class="contentBlock grid_view">'.$new_prods_content.'</div>
	  </div>
<script type="text/javascript">
$(document).ready(function(){ 				
	var row_list_new_products_name = $(\'.row_new_products_name\');
		 row_list_new_products_name.each(function(){
			new equalHeights_new_products_name($(\'#\' + $(this).attr("id")));
	});			 			 			  			  			  			  			   
	 var row_list_new_products_block = $(\'.row_new_products_block\');
		 row_list_new_products_block.each(function(){
			new equalHeights_new_products_block($(\'#\' + $(this).attr("id")));
	});	
	var row_list_new_products_desc = $(\'.row_new_products_desc\');
		 row_list_new_products_desc.each(function(){
			new equalHeights_new_products_desc($(\'#\' + $(this).attr("id")));
	});	
});	
</script>
		
' : '

	  <div id="tabs-new_row">
        <div class="contentBlock row_view">'.$new_prods_content_row.'</div>
	  </div>
'
));
?>
</div>
