<?php 

$dir = '../../';

require_once $dir.'includes/main.php';

$section = filter_var($_POST['section'], FILTER_SANITIZE_STRING);
$offset = (int)$_POST['offset'];

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_active 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 $offset, {$per['listings']}";

fetch_elements($sql, 'admin/elements/'.$include, 'x');