<?php
/*
  osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare 

Released under the GNU General Public License 
*/

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
<!-- whats_new //-->
          <tr>
            <td>
<?php
if(!defined('BOX_HEADING_LAST_PRODUCT'))define('BOX_HEADING_LAST_PRODUCT', 'Last Products');
	$customer_exists = '';
	if(tep_session_is_registered('customer_id'))
	$customer_exists = "OR(p.restrict_to_customers like '%," . $customer_id . ",%' OR p.restrict_to_groups like '%," . $customers_groups_id . ",%')";
	$last_sql = "select p.products_id, p.products_image_1,p.products_title_1, p.products_tax_class_id, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS . " o where op.orders_id=o.orders_id and p.products_id=op.products_id and op.products_type='P' " . 
				" and (" . 
						"(p.restrict_to_customers = '' OR ISNULL(p.restrict_to_customers))" . 
						"and(p.restrict_to_groups = '' OR ISNULL(p.restrict_to_groups))" . $customer_exists . 
				") order by o.date_purchased limit 1";
	$last_query = tep_db_query($last_sql);
	$random_product=false;
	if  (tep_db_num_rows($last_query)>0){
		$random_product=tep_db_fetch_array($last_query);
	}
	if (!$random_product){
		$random_sql = "select products_id, products_image_1,products_title_1, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status='1' " . 
				" and (" . 
						"(p.restrict_to_customers = '' OR ISNULL(p.restrict_to_customers))" . 
						"and(p.restrict_to_groups = '' OR ISNULL(p.restrict_to_groups))" . $customer_exists . 
				") order by products_date_added desc limit " . MAX_RANDOM_SELECT_NEW;
		$random_product = tep_random_select($random_sql);
	}
  if ($random_product) {
  	if (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . "small/" . $random_product['products_image_1'])){
	  	$image=tep_image(DIR_WS_IMAGES . "small/" . $random_product['products_image_1'], $random_product['products_title_1'], 60, 60);
	} else  if (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . "big/" . $random_product['products_image_1'])){
		$image=tep_image(DIR_WS_IMAGES . "big/" . $random_product['products_image_1'], $random_product['products_title_1'], 60, 60);
	} else {
		$image=tep_image(DIR_WS_IMAGES . $random_product['products_image_1'], $random_product['products_title_1'], 60, 60);
	}

    $random_product['products_name'] = tep_get_products_name($random_product['products_id']);
    $random_product['specials_new_products_price'] = tep_get_products_special_price($random_product['products_id']);

    $info_box_contents = array();
    $info_box_contents[] = array('align' => 'left',
                                 'text'  => BOX_HEADING_LAST_PRODUCT 
                                );
   // new infoBoxHeading($info_box_contents, false, false, tep_href_link(FILENAME_PRODUCTS_NEW, '', 'NONSSL'),"backgroundr.png");
 new infoBoxHeading($info_box_contents, true, true);
    if ($random_product['specials_new_products_price']) {
      $whats_new_price =  '<s>' . $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id']),1,true) . '</s>&nbsp;';
      $whats_new_price .= '<font class="productSpecialPrice">' . $currencies->display_price($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</font>';
    } else {
      $whats_new_price =  $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id']),1,true);
    }
	$temp_content.='<table border="0" cellspacing="0" cellpadding="1" width="200"><tr><td class="main" width="50" rowspan="2" valign="top">';
	$temp_content.='<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . $image . '</a>';
	$temp_content.='<td class="main" valign="top"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id'], 'NONSSL') . '">' . stripslashes($random_product['products_name']) . '</a><br><span class="productPrice">' . $whats_new_price . '</span>';
	$temp_content.='</td></tr><tr><td align="right" valign="bottom"><a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=1') . '">' . tep_template_image_button('button_products.gif','Products') . '</a>';
	$temp_content.='</td></tr></table>';
	
    $info_box_contents = array();
    $info_box_contents[] = array('align' => 'center',
                                 'text'  => $temp_content;
                                );
    new infoBox($info_box_contents);
  }


$info_box_contents = array();
  $info_box_contents[] = array('align' => 'left',
                                'text'  => tep_draw_separator('pixel_trans.gif', '100%', '1')
                              );
  new infoboxFooter($info_box_contents, true, true);

?>
            </td>
          </tr>
<!-- whats_new_eof //-->
