<?php
/*
  osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

	Freeway eCommerce
	http://www.openfreeway.org
	Copyright (c) 2007 ZacWare

Featured Products for GA Updated for osConcert by cartZone UK 
Copyright (c) 2009-2014 osConcert
	
Released under the GNU General Public License 
*/

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
		<?php
			if (!isset($array)){	
				  $featured_query = "select p.products_id, pd.products_name, pd.products_description, p.products_image_1,p.products_title_1,p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id left join " . TABLE_FEATURED . " f on p.products_id = f.products_id and pd.language_id = '" . (int)$FSESSION->languages_id . "' where p.products_status = '1' and f.status = '1' order by rand($mtm) limit 4";
				  $featured_result_query = tep_db_query($featured_query);
				  while ($featured_result = tep_db_fetch_array($featured_result_query)) {
					$array[] = array('id' => $featured_result['products_id'],
												  'name' => $featured_result['products_name'],
												  'image' => $featured_result['products_image_1'],
												  'title'=>$featured_result['products_title_1'],
												  'price' => $featured_result['products_price'],
												  'specials_price' => $featured_result['specials_new_products_price'],
												  'tax_class_id' => $featured_result['products_tax_class_id'],
												  'products_description' => $featured_result['products_description'],
												  'manufacturer' => $featured_result['manufacturers_name']);
				  }
			}
		
		  if (sizeof($array) == '0') {
			  
		?>
				<span style="text-align:center"><?php echo TEXT_NO_FEATURED_PRODUCTS; ?></span>

		<?php
		  } else {
			for($z=0; $z<sizeof($array); $z++) {
			  if ($array[$z]['specials_price']) {
				$products_price = '<s>' .  $currencies->display_price($array[$z]['price'], tep_get_tax_rate($array[$z]['tax_class_id']),1,true) . '</s>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($array[$z]['specials_price'], tep_get_tax_rate($array[$z]['tax_class_id'])) . '</span>';
			  } else {
				$products_price = $currencies->display_price($array[$z]['price'], tep_get_tax_rate($array[$z]['tax_class_id']),1,true);
			  }
			  if(strlen(strip_tags($array[$z]['products_description']))>150)
			  		$description=substr(strip_tags($array[$z]['products_description']),0,150)."...";
				else 
					$description=strip_tags($array[$z]['products_description'],'<br>');
		?>
		

<?php
     // if (($i+1) != sizeof($featured_products_array)) {

$new_prods_content .= '
	  	
		<div class="mosaicflow__item">
		<div class="centerBoxContentsNew centeredContent">
		<div class="view view-fifth">
            <div class="imagename">
				<div class="product_image">
					<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $array[$z]['id'], 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . '/big/' . $array[$z]['image'], $array[$z]['name'], '','') . '</a>
			</div>
			
            <div class="mask">
				<div class="product_name">
					<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $array[$z]['id'], 'NONSSL') . '">' . $array[$z]['name'] . '</a>
				</div>
				
                <div class="product_desc">
					<p class="s_desc">
						<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $array[$z]['id'], 'NONSSL') . '">' . $description . '</a>
					</p>
				</div>
                 <div class="propricemain">
                	<div class="productbtn">
	  				 	<div class="productdetailimage">
							<span style="background-color:#555;">
							<a href="' . tep_href_link(FILENAME_FEATURED_PRODUCTS, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $array[$z]['id'], 'NONSSL') . '">' . tep_template_image_button_dark('button_buynow.gif', IMAGE_BUTTON_BUY_NOW) . '</a></span>
							<!--<br><span style="background-color:#555;">
							<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $array[$z]['id'], 'NONSSL') . '">' . tep_template_image_button_dark('button_details.gif', IMAGE_BUTTON_DETAILS) . '</a></span>-->
					 	</div>
				  	</div>
                 	
                    <div class="prodprice">
					' . $products_price . 
						//$currencies->display_price($featured_result['products_price'], tep_get_tax_rate($featured_result['products_tax_class_id'])) .  
				 	'</div>
			  	</div>  
			</div>
		</div>
		</div>
		</div>
			';

      $col ++;
    }

?>
      </td>
      	</tr>
  <?php //echo sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')); ?>

  <div class="mosaicflow">
    <?php echo $new_prods_content; ?>
  </div>

<?php
  }
?>