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

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

<title><?php echo $set['website_name']; ?>: Users: <?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/users.php'; ?>

   <section class="Main L">

      <input type="text" name="search" class="SEARCH" id="search" placeholder="Search Users ...">

      <?php 
      
         switch($section){

            case 'active':
            $sql = "SELECT * FROM users ORDER BY last_seen DESC ";
            break;

            case 'purchased':
            $sql = "SELECT * FROM users WHERE orders > 0 ORDER BY orders DESC ";
            break;

            case 'points':
            $sql = "SELECT * FROM users ORDER BY points DESC ";
            break;

            case 'visits':
            $sql = "SELECT * FROM users ORDER BY visits DESC ";
            break;

            default:
            $sql = "SELECT * FROM users ORDER BY last_seen DESC ";
            break;

         }

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

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

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

   </section>

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

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

</body>

</html>