<?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  16/12/10, 21:52
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
*/
?>
<div id="accountHistory">

  <h2 class="content title <?php echo $language ;?>"><?php echo HEADING_TITLE_6; ?></h2>

  <div class="prod_box_big">
    <div class="top_prod_box_big"></div>
      <div class="center_prod_box_big">
<?php
  $orders_total = tep_count_customer_orders();

  if ($orders_total > 0) {
    $history_query_raw = "select o.orders_id,o.orders_prefix, o.date_purchased, o.delivery_name, o.billing_name, ot.text as order_total,o.orders_status, s.orders_status_name from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_TOTAL . " ot, " . TABLE_V_ORDERS_STATUS . " s where o.customers_id = '" . (int)$customer_id . "' and o.orders_id = ot.orders_id and ot.class = 'ot_total' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' order by orders_id DESC";
    $history_split = new splitPageResults($history_query_raw, MAX_DISPLAY_ORDER_HISTORY);
    $history_query = tep_db_query($history_split->sql_query);

    while ($history = tep_db_fetch_array($history_query)) {
      $products_query = tep_db_query("select count(*) as count from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$history['orders_id'] . "'");
      $products = tep_db_fetch_array($products_query);

      if (tep_not_null($history['delivery_name'])) {
        $order_type = TEXT_ORDER_SHIPPED_TO;
        $order_name = $history['delivery_name'];
      } else {
        $order_type = TEXT_ORDER_BILLED_TO;
        $order_name = $history['billing_name'];
      }
?>
      <dl class="orderHistory">
        <dt><?php echo TEXT_ORDER_NUMBER .  $history['orders_prefix'].$history['orders_id']; ?> <span class="linkPdf"><a href="<?php echo tep_href_link(FILENAME_ACCOUNT, 'action=pdf&amp;'.(isset($_GET['page']) ? 'page=' . $_GET['page'] . '&amp;' : '') . 'order_id=' . $history['orders_id'], 'SSL') ?>">PDF</a></span></dt>
        <dd><?php echo TEXT_ORDER_STATUS . $history['orders_status_name']; ?></dd>
        <dd><?php echo TEXT_ORDER_DATE . tep_date_long($history['date_purchased']) ;?></dd>
        <dd><?php echo $order_type . tep_output_string_protected($order_name); ?></dd>
        <dd><?php echo TEXT_ORDER_PRODUCTS . $products['count'] ;?></dd>
        <dd><?php echo TEXT_ORDER_COST . strip_tags($history['order_total']); ?></dd>
        <dd><?php echo '<a class="navBtMini" href="' . tep_href_link(FILENAME_ACCOUNT, 'action=history_info&amp;'.(isset($_GET['page']) ? 'page=' . $_GET['page'] . '&amp;' : '') . 'order_id=' . $history['orders_id'], 'SSL') . '">' . SMALL_IMAGE_BUTTON_VIEW . '</a>'; ?></dd>
       </dl>

<?php }
  } else { ?>
      <p class="infoText"><?php echo TEXT_NO_PURCHASES; ?></p>
<?php } ?>

<?php if ($orders_total > 0) { ?>

<div id="splitPageBottom">
   <p class="sP1"><?php echo $history_split->display_count(TEXT_DISPLAY_NUMBER_OF_ORDERS); ?></p>
   <p class="sP2"><?php echo TEXT_RESULT_PAGE . ' ' . $history_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></p>
</div>

<?php } ?>

    <div class="navBt">
   <?php echo '<a class="navBt" href="' . tep_href_link(FILENAME_ACCOUNT, '', 'SSL') . '">' . IMAGE_BUTTON_BACK . '</a>'; ?>
  </div>
</div>

    <div class="bottom_prod_box_big"></div>
  </div>

</div>