<?php
/**
 *\licence GPL 2005-2010  The osCSS developers - osCSS Open Source E-commerce
 *\portion code Copyright (c) 2002 osCommerce
 *\package osCSS-2 <www http://www.oscss.org>
 *\version 2.1.0
 *\date  28/11/10, 08:18
 *\author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
 *\encode UTF-8
 *\brief Display list order for user id 
 *
 *		Cette boite affiche les commande du client en cours
*/
$DB=Database::getInstance();
if (tep_session_is_registered('customer_id')) {
// retreive the last x products purchased
    $orders_query = $DB->query($sql="select distinct op.products_id from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_PRODUCTS . " p where o.customers_id = '" . (int)$customer_id . "' and o.orders_id = op.orders_id and op.products_id = p.products_id and p.products_status = '1' group by products_id order by o.date_purchased desc limit " . MAX_DISPLAY_PRODUCTS_IN_ORDER_HISTORY_BOX);
    if ($orders_query->__get('numRows')) {
      $product_ids = '';
	while ($orders = $orders_query->fetchAssoc()) {
	  $product_ids .= (int)$orders['products_id'] . ',';
	}
	$product_ids = substr($product_ids, 0, -1);

	$products_query = $DB->query($sql="select products_id, products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id in (" . $product_ids . ") and language_id = '" . (int)$languages_id . "' order by products_name");
	while ($products = $products_query->fetchAssoc()) {
	  isset($customer_orders_string)? $customer_orders_string .= '<li><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['products_id']) . '">' . $products['products_name'] . '</a><a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=cust_order&amp;pid=' . $products['products_id']) . '">' . tep_image(DIR_WS_ICONS . 'cart.gif', ICON_CART) . '</a></li>'."\n" : $customer_orders_string = '<li><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['products_id']) . '">' . $products['products_name'] . '</a><a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=cust_order&amp;pid=' . $products['products_id']) . '">' . tep_image(DIR_WS_ICONS . 'cart.gif', ICON_CART) . '</a></li>'."\n";
	}
      $s.='<ul>'."\n".
	  $customer_orders_string.
	  '</ul>'."\n";
    }
  $array= array('title'=>__('box heading customer orders'),'content'=>tep_output_string_protected($s,false,true));
}
else $array= array('title'=>'','content'=>'');
?>