<?php
session_start();
require_once '../../config.php';
load('middleware', 'user');
if ($_SESSION['user']['level'] !== "Admin") {
    header('location:' . base_url('/id'));
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
	$table = 'users';
	$primaryKey = 'id';

	
	$columns = array(
		array( 'db' => 'username', 'dt' => 0),
		array( 'db' => 'email', 'dt' => 1),	
		array( 'db' => 'phone', 'dt' => 2),
		array( 'db' => 'id', 'dt' => 3),
	);
	require_once '../../system/helpers/ssp.class.php';
	$sql_details = array(
		'user' => $_CONFIG['db']['username'],
		'pass' => $_CONFIG['db']['password'],
		'db'   => $_CONFIG['db']['name'],
		'host' => $_CONFIG['db']['host']
	);
	$joinQuery = null;
	$extraWhere = '';
	$groupBy = '';
	$having = '';
	print(json_encode(
		SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery, $extraWhere, $groupBy, $having )
	));
} else {
	exit("No direct script access allowed!");
}