<?php 
/*
	osConcert Seat Booking Software
	https://www.osconcert.com
	Copyright (c) 2024 osConcert

	Released under the GNU General Public License 
*/	
// Check to ensure this file is included in osConcert!
defined('_FEXEC') or die();
?>

<div class="section-header">
<h2><?php echo HEADING_TITLE; ?></h2>
</div>
<div class="index_static">
<?php
  $orders_total = tep_count_customer_orders();

  if ($orders_total > 0) {
// Changed for Paypal IPN Mod

//Here is the new line for paypal IPN
    $history_query_raw = "select o.orders_id, o.date_purchased, o.delivery_name, o.billing_name, ot.text as order_total, s.orders_status_name from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_TOTAL . " ot, " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . (int)$FSESSION->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)$FSESSION->languages_id . "' and o.orders_status != '99999' order by orders_id DESC";
//End Paypal IPN Mod
    $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'];
      }
?>
<div class="container mb-3">
  <!-- Order Number and Status -->
  <div class="row">
    <div class="col-6">
      <strong><?php echo TEXT_ORDER_NUMBER; ?></strong> <?php echo $history['orders_id']; ?>
    </div>
    <div class="col-6 text-end">
      <strong><?php echo TEXT_ORDER_STATUS; ?></strong> <?php echo $history['orders_status_name']; ?>
    </div>
  </div>

  <!-- Order Details -->
  <div class="row mt-2 p-3 border rounded" onMouseOver="rowOverEffect(this)" onMouseOut="rowOutEffect(this)" onClick="document.location.href='<?php echo tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $history['orders_id'] . '&return=ma', 'SSL'); ?>'">
    <div class="col-6">
      <strong><?php echo TEXT_ORDER_DATE; ?></strong> <?php echo format_date($history['date_purchased']); ?><br>
      <strong><?php echo $order_type; ?></strong> <?php echo tep_output_string_protected($order_name); ?>
    </div>
    <div class="col-4">
      <strong><?php echo TEXT_ORDER_PRODUCTS; ?></strong> <?php echo $products['count']; ?><br>
      <strong><?php echo TEXT_ORDER_COST; ?></strong> <?php echo strip_tags($history['order_total']); ?>
    </div>
    <div class="col-2 text-end">
	  <?php echo tep_template_image_button_basic('', SMALL_IMAGE_BUTTON_VIEW, 'onclick="window.location.href=\''. tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $history['orders_id'] . '&return=ma', 'SSL') . '\'"'); ?>
    </div>
  </div>
</div>

<?php
    }
  } else {
?>
          <?php echo TEXT_NO_PURCHASES; ?>
<?php
  }
?>

<?php
  if ($orders_total > 0) {
?>
      <div class="container mb-3">
  <div class="row">
    <!-- Display Count -->
    <div class="col-6 small text-start">
      <?php echo $history_split->display_count(TEXT_DISPLAY_NUMBER_OF_ORDERS); ?>
    </div>

    <!-- Page Navigation -->
    <div class="col-6 small text-end">
      <?php echo TEXT_RESULT_PAGE . '&nbsp;' . $history_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?>
    </div>
  </div>
</div>

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