<?php require_once 'includes/main.php'; ?>
<?php require_once 'elements/head.php'; ?>
<?php 

$id = (int)$_GET['section'];

$sql = "SELECT * FROM categories WHERE id = '{$id}' LIMIT 1";
if(fetch_rows($sql) < 1){

   $_SESSION['messages'][] = "Category does not exist";
   header("Location: ".URL);
   exit;

}else{

   $x = fetch_records($sql);

}

?>

<!-- META: TITLE -->
<title><?php echo $x['name']; ?> - <?php echo $set['website_name']; ?></title>

</head>

<body>

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

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

   <h2 class="GLOB-Title"><?php echo $x['name']; ?>: <span class="FR"><?php echo comma_number(fetch_record("SELECT COUNT(id) FROM listings WHERE status = 'active' AND category_id = '{$x['id']}'")); ?></span></h2>

   <?php $sql = "SELECT * FROM listings WHERE status = 'active' AND points > 0 AND category_id = '{$x['id']}' ORDER BY points DESC, id ASC LIMIT {$per['listings']}"; ?>

   <!-- APPEND -->
   <section id="append">
      <?php fetch_elements($sql, 'elements/listings/main.php', 'a'); ?>
   </section>
   <!-- APPEND -->

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

</section>
<!-- CONTENT -->

<?php include_once 'elements/sidebar/main.php'; ?>

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

</body>
</html>
