77 lines
2.2 KiB
PHP
77 lines
2.2 KiB
PHP
<?php
|
|
class Tat extends MY_Controller
|
|
{
|
|
var $db;
|
|
public function index()
|
|
{
|
|
echo "Tat API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
// $this->db = $this->load->database("default", true);
|
|
$this->db->query("use one_dash");
|
|
}
|
|
|
|
function corss()
|
|
{
|
|
global $_SERVER;
|
|
if (isset($_SERVER["HTTP_ORIGIN"])) {
|
|
header("Access-Control-Allow-Origin: " . $_SERVER["HTTP_ORIGIN"]);
|
|
} else {
|
|
header("Access-Control-Allow-Origin: */*");
|
|
}
|
|
header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS");
|
|
header(
|
|
"Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization"
|
|
);
|
|
if (
|
|
isset($_SERVER["REQUEST_METHOD"]) &&
|
|
$_SERVER["REQUEST_METHOD"] == "OPTIONS"
|
|
) {
|
|
http_response_code(200);
|
|
echo json_encode("OK");
|
|
exit();
|
|
}
|
|
}
|
|
|
|
public function list_category_tat()
|
|
{
|
|
$this->corss();
|
|
try {
|
|
$sql_cat = "SELECT *
|
|
FROM tat_report_category
|
|
ORDER BY TatReportCategoryOrder DESC";
|
|
|
|
$qry_cat = $this->db->query($sql_cat, []);
|
|
if (!$qry_cat) {
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$last_qry_cat = $this->db->last_query();
|
|
$rst_cat = $qry_cat->result_array();
|
|
|
|
$result = array(
|
|
"list_category_tat" => [],
|
|
"last_qry_cat" => $last_qry_cat
|
|
);
|
|
|
|
if (count($rst_cat) > 0) {
|
|
$result = array(
|
|
"list_category_tat" => $rst_cat,
|
|
"last_qry_cat" => $last_qry_cat
|
|
);
|
|
}
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|