Initial import
This commit is contained in:
196
one-api/application/controllers/mockup/antrione/Counter.php
Normal file
196
one-api/application/controllers/mockup/antrione/Counter.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
class Counter 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 counter
|
||||
where
|
||||
counterIsActive = 'Y'";
|
||||
$sql_param = array($search);
|
||||
$total = $this->db_antrione->query($sql,$sql_param)->row()->total;
|
||||
|
||||
|
||||
$sql = "select *
|
||||
from counter
|
||||
where
|
||||
counterIsActive = '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("counter select");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows);
|
||||
$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'];
|
||||
$ip = $prm['ip'];
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM counter WHERE counterIsActive = 'Y' AND counterCode = '{$code}'";
|
||||
$exist_code = $this->db_antrione->query($query)->row()->exist;
|
||||
|
||||
if($exist_code == 0){
|
||||
$sql = "insert into counter(
|
||||
counterCode,
|
||||
counterIP
|
||||
)
|
||||
values( ?,?)";
|
||||
$query = $this->db_antrione->query($sql,
|
||||
array(
|
||||
$code,
|
||||
$ip
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("counter 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'];
|
||||
$ip = $prm['ip'];
|
||||
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM counter WHERE counterIsActive = 'Y' AND counterCode = '{$code}' AND counterID <> {$id}";
|
||||
//echo $query;
|
||||
$exist_code = $this->db_antrione->query($query)->row()->exist;
|
||||
|
||||
if($exist_code == 0){
|
||||
$sql = "update counter set
|
||||
counterCode = ?,
|
||||
counterIP = ?
|
||||
where counterID = ?
|
||||
";
|
||||
$query = $this->db_antrione->query($sql,
|
||||
array(
|
||||
$code,
|
||||
$ip,
|
||||
$id
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("counter 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 counter set
|
||||
counterIsActive = 'N'
|
||||
where counterID = ?
|
||||
";
|
||||
$query = $this->db_antrione->query($sql,
|
||||
array(
|
||||
$id
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("counter delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user