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

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

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

<section class="Main L">

   <?php if($section != 'pending'){ ?>
      <input type="text" name="search" class="SEARCH" id="search" placeholder="Search Listings ...">
   <?php }else{ ?>
      <h1 class="GLOB-Title">Pending: <span class="FR"><?php echo comma_number(fetch_record("SELECT COUNT(id) FROM listings WHERE status = 'pending'")); ?></span></h1>
   <?php } ?>

   <?php 
   
      switch($section){

         case 'pending':
         $sql = "SELECT * FROM listings WHERE status = 'pending' ORDER BY id ASC ";
         $include = 'listings/pending.php';
         break;

         case 'points':
         $sql = "SELECT * FROM listings WHERE status != 'pending' ORDER BY points DESC ";
         $include = 'listings/main.php';
         break;

         case 'fresh':
         $sql = "SELECT * FROM listings WHERE status != 'pending' ORDER BY id DESC ";
         $include = 'listings/main.php';
         break;

         case 'active':
         $sql = "SELECT * FROM listings WHERE status != 'pending' ORDER BY last_click DESC ";
         $include = 'listings/main.php';
         break;

         case 'inactive':
         $sql = "SELECT * FROM listings WHERE status != 'pending' AND points = 0 ORDER BY id DESC ";
         $include = 'listings/main.php';
         break;

         default:
         $sql = "SELECT * FROM listings WHERE status = 'pending' ORDER BY id ASC ";
         $include = 'listings/pending.php';
         break;

      }

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

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

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

</section>

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

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

</body>
</html>
