<?php
/*
  $Id$

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

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SPECIALS);
  $current_page = FILENAME_SPECIALS;
  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SPECIALS));
  
  require(DIR_WS_INCLUDES . 'template_top.php');
?>
<?php echo tep_draw_content_top();?>

<?php echo tep_draw_heading_top();?>
<h2><?php echo HEADING_TITLE; ?></h2>
<?php echo tep_draw_heading_bottom();?>
<div id="tabs_page_specils" class="tabs">
<?php 
 	echo  ((SPECIALS_PAGE_LYOUT == 'Grid') ? '<ul class="row_table"><li class="layout table_view" id="grid"><a href="#tabs-1" title="'.PRODUCT_LAYOUT_VIEW_GRID.'"></a></li><li class="layout row_view" id="list"><a href="#tabs-2" title="'.PRODUCT_LAYOUT_VIEW_ROW.'"></a></li></ul>' : '<ul class="row_table"><li class="layout row_view" id="list"><a href="#tabs-2" title="'.PRODUCT_LAYOUT_VIEW_ROW.'"></a></li><li class="layout table_view" id="grid"><a href="#tabs-1" title="'.PRODUCT_LAYOUT_VIEW_GRID.'"></a></li></ul>');
?>
<?php
  $specials_query_raw = "select p.products_id, pd.products_name, m.manufacturers_id, p.products_price, p.products_tax_class_id, p.products_image, s.specials_date_added, s.specials_last_modified, s.specials_new_products_price, s.expires_date, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by s.specials_date_added DESC, pd.products_name";
  $specials_split = new splitPageResults($specials_query_raw, MAX_DISPLAY_SPECIALS_PRODUCTS);

  if (($specials_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 $specials_split->display_count(TEXT_DISPLAY_NUMBER_OF_SPECIALS); ?></div>
            <div class="result_right"><?php echo TEXT_RESULT_PAGE . ' ' . $specials_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
  }
?>
<div class="contentContainer page_new_product">
<?php
  if ($specials_split->number_of_rows > 0) {
?>
<?php
	  $row = 0;
	  $col = 0;
		$image_width = (SPECIALS_PAGE_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_WIDTH : SPECIALS_PAGE_IMAGE_WIDTH;
		$image_height = (SPECIALS_PAGE_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_HEIGHT : SPECIALS_PAGE_IMAGE_HEIGHT;
		$image_width_row = (SPECIALS_PAGE_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_WIDTH_ROW : SPECIALS_PAGE_IMAGE_WIDTH_ROW;
		$image_height_row = (SPECIALS_PAGE_GENERAL_CUSTOM_IMAGE_SIZE == 'General') ? GENERAL_IMAGE_HEIGHT_ROW : SPECIALS_PAGE_IMAGE_HEIGHT_ROW;
	  $col_items = (MAX_DISPLAY_SPECIALS_PAGE_PER_ROW);
		if (MAX_DISPLAY_SPECIALS_PAGE_PER_ROW  <= 1)	{
			$products_block_width = 100;
			$products_block_width .= '%';
			$view = 'r_view';
			$equal_height_products_block = 'equal-height_products_block';
			$equal_height_products_name = 'equal-height_products_name';
			$equal_height_products_desc = 'equal-height_products_desc'; 
		}else{
			$products_block_width = SPECIALS_PAGE_BLOCK_WIDTH.'px';
			$view = 't_view';
			$equal_height_products_block = 'equal-height_products_block';
			$equal_height_products_name = 'equal-height_products_name';
			$equal_height_products_desc = 'equal-height_products_desc'; 
		}
  	$new_prods_content .= '<div class="content '.$view.'">';
		$new_prods_content_row .= '<div class="content '.$view.'">';


	$specials_query = tep_db_query($specials_split->sql_query);
    while ($specials = tep_db_fetch_array($specials_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_products_desc row_products_block row_products_name" id="view_grid-'.$row.'">' : '<li class="prods_vseparator"><div class="'.$equal_height_products_block.'">'.tep_draw_separator('spacer.gif', '10', '1').'</div>');
		$new_prods_content_row .= (($col === 0) ? '<ul class="row_products_desc row_products_block row_products_name" id="view_row-'.$row.'">' : '<li class="prods_vseparator"><div class="'.$equal_height_products_block.'">'.tep_draw_separator('spacer.gif', '10', '1').'</div>');
  	$featured_query = tep_db_query("select status, products_id from " . TABLE_FEATURED . " where products_id = '" . (int)$specials['products_id'] . "'");
    $featured_product = tep_db_fetch_array($featured_query);
		$p_featured = ((SPECIALS_PAGE_SHOW_FEATURED_LABEL == '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)$specials['products_id'] . "' and language_id = '" . (int)$languages_id . "'");
		$product = tep_db_fetch_array($product_query);
		$p_desc = ((MAX_SPECIALS_PAGE_DESCR !=0) ? '<div class="desc '.$equal_height_products_desc.'">'.mb_substr(strip_tags($product['products_description']), 0, MAX_SPECIALS_PAGE_DESCR, 'UTF-8').'...</div>' : '');
		$p_desc_row = ((MAX_SPECIALS_PAGE_DESCR_ROW !=0) ? '<div class="desc '.$equal_height_products_desc.'">'.mb_substr(strip_tags($product['products_description']), 0, MAX_SPECIALS_PAGE_DESCR_ROW, 'UTF-8').'...</div>' : '');
		$p_id = $product['products_id'];
						$products_price = '<div class="product_price_wrapper price '.$extra.'"><b>'.PRICE. '</b><del>' . $currencies->display_price($specials['products_price'], tep_get_tax_rate($specials['products_tax_class_id'])) . '</del><span class="productSpecialPrice">' . $currencies->display_price($specials['specials_new_products_price'], tep_get_tax_rate($specials['products_tax_class_id'])) . '</span></div>';
						$extra = 'extra';
						$persent = ($currencies->display_sale_percent($specials['products_price'], tep_get_tax_rate($specials['products_tax_class_id']), $specials['specials_new_products_price']) * -1);
						$sale_percent = ((SPECIALS_PAGE_SHOW_SPECIALS_LABEL == 'Show') ? '<div class="sale_percent '.$color.'"><strong>'.$persent.'%</strong></div>' : '');
		$p_price = ((SPECIALS_PAGE_SHOW_PRICE == 'Show') ? $products_price : '');
		$p_pic = ((SPECIALS_PAGE_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=' . $specials['products_id']) . '" style="width:'.$image_width.'px;height:'.$image_height.'px;">' . tep_image(DIR_WS_IMAGES . $specials['products_image'], $specials['products_name'], $image_width, $image_height, ' style="width:'.$image_width.'px;height:'.$image_height.'px;"') . '</a></div>' : '');
		$p_pic_row = ((SPECIALS_PAGE_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=' . $specials['products_id']) . '" style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;">' . tep_image(DIR_WS_IMAGES . $specials['products_image'], $specials['products_name'], $image_width_row, $image_height_row, ' style="width:'.$image_width_row.'px;height:'.$image_height_row.'px;"') . '</a></div>' : '');
		$p_name = ((SPECIALS_PAGE_SHOW_NAME == 'Show') ? '<h3 class="name '.$equal_height_products_name.'"><span><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials['products_id']) . '">' .$specials['products_name'] . '</a></span></h3>' : '');
		$p_data_add = ((SPECIALS_PAGE_SHOW_DATA_ADD == 'Show' && $specials['specials_date_added'] != NULL) ? '<div class="fl_left"><span>' . TEXT_DATE_ADDED . '</span> ' . tep_date_short($specials['specials_date_added']) . '</div>' : '');
		$p_data_mod = ((SPECIALS_PAGE_SHOW_DATA_MOD == 'Show' && $specials['specials_last_modified'] != NULL) ? '<div class="fl_right"><span>' . TEXT_DATE_LAST_MOD . '</span> ' . tep_date_short($specials['specials_last_modified']) . '</div>' : '');
		$p_data_exp = ((SPECIALS_PAGE_SHOW_DATA_EXP == 'Show' && $specials['expires_date'] != NULL) ? '<div class="data extra"><span>' . TEXT_DATE_LAST_EXP . '</span><br />' . tep_date_short($specials['expires_date']) . '</div>' : '');
		$p_data_exp_row = ((SPECIALS_PAGE_SHOW_DATA_EXP == 'Show' && $specials['expires_date'] != NULL) ? '<div class="data extra"><span>' . TEXT_DATE_LAST_EXP . '</span> ' . tep_date_short($specials['expires_date']) . '</div>' : '');		
		$p_data = (($p_data_add != NULL || $p_data_mod != NULL) ? '<div class="data">'.$p_data_add .' '. $p_data_mod.'</div>' : '');
		$p_manufacturers = ((SPECIALS_PAGE_SHOW_BRANDS == 'Show') ? '<div class="manuf"><span>' . TEXT_MANUFACTURER . '</span> <a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $specials['manufacturers_id']) . '">' . $specials['manufacturers_name'] . '</a></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 = ((SPECIALS_PAGE_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:100%;">'. "\n".
				  '		<div class="product_block '.$equal_height_products_block.'">'. "\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>'. "\n";			  
    $col ++;
    if ($col > $col_items-1) {
       $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>';
	$new_prods_content_row .= '</div>';
?>
	  <div id="tabs-1">
        <div class="contentBlock grid_view"><?php echo $new_prods_content;?>
<?php echo ((SPECIALS_PAGE_SHOW_NAME == 'Show') ? ''."\n".
'<script type="text/javascript">'."\n".
'$(document).ready(function(){' ."\n".				
'				var row_list_products_name = $(\'.row_products_name\');'."\n".
'						row_list_products_name.each(function(){'."\n".
'						new equalHeights_products_name($(\'#\' + $(this).attr("id")));'."\n".
'				});	'."\n".		 			 			  			  			  			  			   
'})'."\n".
'</script>'."\n".'' : '');
	echo ((MAX_SPECIALS_PAGE_DESCR !=0) ? ''."\n".
'<script type="text/javascript">'."\n".
'$(document).ready(function(){' ."\n".				
'				var row_list_products_desc = $(\'.row_products_desc\');'."\n".
'						row_list_products_desc.each(function(){'."\n".
'						new equalHeights_products_desc($(\'#\' + $(this).attr("id")));'."\n".
'				});	'."\n".		 			 			  			  			  			  			   
'})'."\n".
'</script>'."\n".'' : '');?>
<script type="text/javascript">
$(document).ready(function(){ 				
	var row_list_products_block = $('.row_products_block');
			row_list_products_block.each(function(){
			new equalHeights_products_block($('#' + $(this).attr("id")));
	});	
})
</script>
        </div>
	  </div>
	  <div id="tabs-2">
        <div class="contentBlock row_view"><?php echo $new_prods_content_row; ?></div>
	  </div>
<?php	} else { ?>
    <div><?php echo TEXT_NO_NEW_PRODUCTS; ?></div>
<?php } ?>  
</div>
<?php
  if (($specials_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 $specials_split->display_count(TEXT_DISPLAY_NUMBER_OF_SPECIALS); ?></div>
          <div class="result_right"><?php echo TEXT_RESULT_PAGE . ' ' . $specials_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
  }
?>
</div>
<?php echo tep_draw_content_bottom();?>
<script type="text/javascript">
$(document).ready(function(){ 				
		$("#tabs_page_specils.tabs").tabs({
		fx: { opacity: 'toggle',
          duration: <?php echo SPECIALS_PAGE_DURATION_GRID_LIST_VIEW; ?>},			  
		cookie: {
		// store cookie for a day, without, it would be a session cookie
		expires: <?php echo SPECIALS_PAGE_COOKIE_GRID_LIST_VIEW; ?>, name: "startTab_specils" }
		});
})
</script>
<?php
  require(DIR_WS_INCLUDES . 'template_bottom.php');
  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>