<?php
require_once 'conection.ini.php';

$filter_field = isset($_POST['filterField']) ? $_POST['filterField'] : NULL;
$filter_text = isset($_POST['filterText']) ? trim(strtolower($_POST['filterText'])) : NULL;

$where = '';
if ($filter_text && $filter_text != '') {
	if ($filter_field === 'active') {
		if ($filter_text == 'true' || $filter_text == 'yes') {
			$filter_text = 1;
		} else {
			$filter_text = 0;
		}
	}
	$where = "WHERE ".$filter_field . " LIKE '%" . $filter_text . "%'";
}
if ($where == '') {
	$result = mysql_query("SELECT * FROM total");
} else {
	$result = mysql_query("SELECT * FROM total ".$where);
}

$data = array();
while ($row = mysql_fetch_assoc($result)) {
	$data[] = array_map('utf8_encode',$row);
}

echo json_encode(array(
	 "success" => true,
	 "data" => $data)
);
?>