<?php
/*

	Released under the GNU General Public License 
*/	
// Check to ensure this file is included in osConcert!
defined('_FEXEC') or die();
       if($FSESSION->is_registered("account"))
	   {
			$messageStack->add('account', $FSESSION->get('account'));
	   $FSESSION->remove('account');}

		$isblocked=$FREQUEST->getvalue('isblocked');
		$suspended=$FREQUEST->getvalue('suspended');
		if($isblocked=='yes')
			$messageStack->add('account', ERROR_BLOCKED_CUSTOMER);
		if($suspended=='yes')
			$messageStack->add('account', ERROR_SUSPENDED_CUSTOMER);
				
     ?>
	<?php
	if ($messageStack->size('account') > 0) 
	{
	?>
	<div><?php echo $messageStack->output('account'); ?></div>
	<?php
	}
	?>
	<div class="container-fluid account">
	<div class="section-header">
	<h2><?php echo HEADING_TITLE; ?></h2>
	<div class="index_static">
	<?php
	$customers_id = $FSESSION->get("customer_id");
	$gv_query = tep_db_query("select amount from coupon_season_customer where customer_id = '" . $customers_id . "'");
		$gv_count =tep_db_num_rows($gv_query);
		if ($gv_count > 0 )
		{
        $gv_result = tep_db_fetch_array($gv_query);
        $gv_amount = $gv_result['amount'] ;
		}
	?>

	<?php if(MODULE_ORDER_TOTAL_GV_STATUS == 'true') 
	{  
	?>
		
	<div><b><?php echo MY_ACCOUNT_SEASON; ?></b></div>
	
				 <table cellpadding="2" width="100%">

					<tr>
						<td class="main"><?php 
								
								//echo $customers_id;
								//echo '<br>';
								echo sprintf(MY_ACCOUNT_SEASON_TEXT, $gv_amount);
						?>
						</td>
					</tr>
				</table><br><br>	

	
	   <?php 
	}			
?>
<div class="container">
  <!-- Current Purchases Title -->
  <div class="row mb-3">
    <div class="col-12">
      <strong><?php echo MY_ACCOUNT_CURRENT_PURCHASES; ?></strong>
    </div>
  </div>

  <!-- Current Purchases Section -->
  <div class="row align-items-center mb-4">
    <div class="col">
      <div class="table-responsive">
        <table class="table table-hover">
          <?php
          $amount = 0;
          $products_query = tep_db_query("SELECT DISTINCT o.date_purchased, op.products_type, op.products_name, o.orders_id, op.final_price, op.products_tax, op.categories_name, op.concert_venue, op.concert_date, op.concert_time, op.products_quantity 
              FROM " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op 
              WHERE o.customers_id = '" . (int)$FSESSION->customer_id . "' AND o.orders_id = op.orders_id 
              ORDER BY o.date_purchased DESC LIMIT 3");

          if (tep_db_num_rows($products_query) > 0) {
            while ($products = tep_db_fetch_array($products_query)) {
              $type = ($products['products_type'] == 'P') ? TEXT_PRODUCT : '';
          ?>
          <tr class="moduleRow" onMouseOver="rowOverEffect(this)" onMouseOut="rowOutEffect(this)" onClick="document.location.href='<?php echo tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $products['orders_id'] . '&return=ma', 'SSL'); ?>'">
            <td class="main"><?php echo $type; ?></td>
            <td class="main"></td>
            <td class="main"><?php echo $products["products_name"] . ' ' . $products["categories_name"]; ?></td>
            <td class="main text-end"><?php echo $currencies->format(tep_add_tax($products["final_price"], $products['products_tax']) * $products["products_quantity"]); ?></td>
            <td class="main 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=' . $products['orders_id'] . '&return=ma', 'SSL') . '\'"'); ?>
			</td>
          </tr>
          <?php 
            }
          } 
          ?>
          <tr>
            <td colspan="5" class="main">
              <?php echo (tep_db_num_rows($products_query) == 0) ? TEXT_NO_ITEMS : '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL') . '"><u>' . SHOW_ALL_ORDERS . '</u></a>'; ?>
            </td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</div>

<!-- end current -->
	 
	<!-- order-->
	<?php
	if (tep_count_customer_orders() > 0) 
	{
	?>
	
	<div class="container">
  <!-- Orders Title -->
  <div class="row mb-3">
    <div class="col-12">
      <strong><?php echo MY_ORDERS_TITLE; ?></strong>
    </div>
  </div>

  <!-- Orders Section -->
  <div class="row align-items-center mb-2">
    <div class="col">
      <div class="table-responsive">
        <table class="table table-hover">
          <?php
          $orders_query = tep_db_query("SELECT o.orders_id, o.date_purchased, o.delivery_name, o.delivery_country, o.billing_name, o.billing_country, 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 . "' ORDER BY orders_id DESC LIMIT 3");

          while ($orders = tep_db_fetch_array($orders_query)) {
            if (tep_not_null($orders['delivery_name'])) {
              $order_name = $orders['delivery_name'];
              $order_country = $orders['delivery_country'];
            } else {
              $order_name = $orders['billing_name'];
              $order_country = $orders['billing_country'];
            }
          ?>
          <tr class="moduleRow" onMouseOver="rowOverEffect(this)" onMouseOut="rowOutEffect(this)" onClick="document.location.href='<?php echo tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $orders['orders_id'].'&return=hinfo', 'SSL'); ?>'">
            <td class="main"><?php echo format_date($orders['date_purchased']); ?></td>
            <td class="main"><?php echo '#' . $orders['orders_id']; ?></td>
            <td class="main"><?php echo tep_output_string_protected($order_name) . ', ' . $order_country; ?></td>
            <td class="main"><?php echo $orders['orders_status_name']; ?></td>
            <td class="main text-end"><?php echo $orders['order_total']; ?></td>
            <td class="main 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=' . $products['orders_id'] . '&return=ma', 'SSL') . '\'"'); ?>
			</td>
          </tr>
          <?php } ?>
          
          <!-- View All Orders Link -->
          <tr>
            <td colspan="6">
              <a href="<?php echo tep_href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL'); ?>">
                <u><?php echo OVERVIEW_SHOW_ALL_ORDERS; ?></u>
              </a>
            </td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</div>

	<?php
	}
	?>
<!-- end order -->
<div class="container">
  <!-- My Account Title -->
  <div class="row mb-3">
    <div class="col-12">
      <strong><?php echo MY_ACCOUNT_TITLE; ?></strong>
    </div>
  </div>

  <!-- Account Details Section -->
  <div class="row">
    <div class="col-1"></div> <!-- Spacer (optional) -->
    <div class="col-1">
      <?php echo tep_image(DIR_WS_IMAGES . 'account_personal.gif'); ?>
    </div>
    <div class="col-1"></div> <!-- Spacer (optional) -->
    <div class="col-9">
      <ul class="list-unstyled">
        <li class="mb-2">
          <?php echo tep_image(DIR_WS_IMAGES . 'arrow_green.gif'); ?>
          <a href="<?php echo tep_href_link(FILENAME_ACCOUNT_EDIT, '', 'SSL'); ?>">
            <?php echo MY_ACCOUNT_INFORMATION; ?>
          </a>
        </li>
        <!--<li class="mb-2">
          <?php //echo tep_image(DIR_WS_IMAGES . 'arrow_green.gif'); ?>
          <a href="<?php //echo tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL'); ?>">
            <?php //echo MY_ACCOUNT_ADDRESS_BOOK; ?>
          </a>
        </li>-->
        <li class="mb-2">
          <?php echo tep_image(DIR_WS_IMAGES . 'arrow_green.gif'); ?>
          <a href="<?php echo tep_href_link(FILENAME_ACCOUNT_PASSWORD, '', 'SSL'); ?>">
            <?php echo MY_ACCOUNT_PASSWORD; ?>
          </a>
        </li>

        <?php if (HIDE_DATA_PROTECT == 'false') { ?>
        <li class="mb-2">
          <?php echo tep_image(DIR_WS_IMAGES . 'arrow_green.gif'); ?>
          <a href="<?php echo tep_href_link('account_data.php', '', 'SSL'); ?>">
            <?php echo MY_ACCOUNT_DATA; ?>
          </a>
        </li>
        <li class="mb-2">
          <?php echo tep_image(DIR_WS_IMAGES . 'arrow_green.gif'); ?>
          <a href="<?php echo tep_href_link('account_close.php', '', 'SSL'); ?>">
            <span class="btn btn-primary btn-lg">
              <?php echo MY_ACCOUNT_CLOSE; ?>
            </span>
          </a>
        </li>
        <?php } ?>
      </ul>
    </div>
  </div>
</div>

<div class="container">
  <div class="row">
    <div class="col">
      <?php if (ACCOUNT_NEWSLETTER == 'true') { ?>
      <ul class="list-unstyled">
        <li>
          <?php echo tep_image(DIR_WS_IMAGES . 'arrow_green.gif'); ?>
          <a href="<?php echo tep_href_link(FILENAME_ACCOUNT_NEWSLETTERS, '', 'SSL'); ?>">
            <?php echo EMAIL_NOTIFICATIONS_NEWSLETTERS; ?>
          </a>
        </li>
      </ul>
      <?php } ?>
    </div>
  </div>
</div>

	
		</div>
		</div>
		<br>