Files
REG_IBL/one-api/application/controllers/mockup/antrione/Service.php
2026-05-25 20:01:37 +07:00

202 lines
4.8 KiB
PHP

<?php
class Service extends MY_Controller
{
var $db_antrione;
public function index()
{
echo "SERVICE API";
}
public function __construct()
{
parent::__construct();
$this->db_antrione = $this->load->database("antrione", true);
}
public function loadx()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
$prm = $this->sys_input;
$sql = "select COUNT(*) as total
from service
where
serviceIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_antrione->query($sql,$sql_param)->row()->total;
$sql = "select *
from service
where
serviceIsActive = 'Y'";
$sql_param = array($search);
$query = $this->db_antrione->query($sql,$sql_param);
//echo $this->db_antrione->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("m_schedule select");
exit;
}
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows,
"ownIP" => $_SERVER["REMOTE_ADDR"] );
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function save()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$code = $prm['code'];
$name = $prm['name'];
$priority = $prm['priority'];
$query = "SELECT COUNT(*) as exist FROM service WHERE serviceIsActive = 'Y' AND serviceCode = '{$code}'";
$exist_code = $this->db_antrione->query($query)->row()->exist;
if($exist_code == 0){
$sql = "insert into service(
serviceCode,
serviceName,
servicePriority
)
values( ?,?,?)";
$query = $this->db_antrione->query($sql,
array(
$code,
$name,
$priority
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("service insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function update()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$code = $prm['code'];
$name = $prm['name'];
$priority = $prm['priority'];
$query = "SELECT COUNT(*) as exist FROM service WHERE serviceIsActive = 'Y' AND serviceCode = '{$code}' AND serviceID <> {$id}";
//echo $query;
$exist_code = $this->db_antrione->query($query)->row()->exist;
if($exist_code == 0){
$sql = "update service set
serviceCode = ?,
serviceName = ?,
servicePriority = ?
where serviceID = ?
";
$query = $this->db_antrione->query($sql,
array(
$code,
$name,
$priority,
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("service update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletex()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "update service set
serviceIsActive = 'N'
where serviceID = ?
";
$query = $this->db_antrione->query($sql,
array(
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("service delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}