<?php require_once '../includes/main.php'; logged_in('admin'); ?>
<?php require_once 'elements/head.php'; ?>

<?php $section = isset($_GET['section']) ? $_GET['section'] : 'completed'; ?>

<title><?php echo $set['website_name']; ?>: Orders: <?php echo ucwords($section); ?></title>

<meta name="robots" content="noindex">

</head>

<body>

<?php include_once 'elements/header.php'; ?>

<!-- CONTENT -->
<main class="Content">

<?php include_once DIR.'admin/elements/sidebar/orders.php'; ?>

<section class="Main L">

   <h1 class="GLOB-Title"><?php echo ucwords($section); ?> Orders: <span class="FR"><?php echo comma_number(fetch_record("SELECT COUNT(id) FROM orders WHERE status = '{$section}'")); ?></span></h1>

   <?php 
   
      switch($section){

         case 'completed':
         $sql = "SELECT * FROM orders WHERE status = 'completed' ORDER BY id DESC ";
         break;

         case 'pending':
         $sql = "SELECT * FROM orders WHERE status = 'pending' ORDER BY id DESC ";
         break;

         case 'canceled':
         $sql = "SELECT * FROM orders WHERE status = 'canceled' ORDER BY id DESC ";
         break;

         default:
         $sql = "SELECT * FROM orders WHERE status = 'Completed' ORDER BY id DESC ";
         break;

      }

      $sql .= "LIMIT {$per['orders']}";
   
   ?>

   <div id="append">
      <?php fetch_elements($sql, 'admin/elements/orders/main.php', 'a'); ?>
   </div>

   <?php if(fetch_rows($sql) == $per['listings']){ ?>
      <div class="MORE">
         <button onclick="loadMore(this, 'ex/more.orders.php', '.Orders');">Load More</button>
      </div>
   <?php } ?>

</section>

</main>
<!-- CONTENT -->

<?php include_once 'elements/footer.php'; ?>

</body>
</html>
