152 lines
4.2 KiB
PHP
152 lines
4.2 KiB
PHP
<?php
|
|
|
|
class Kris extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
// https://devone.aplikasi.web.id/one-api/training/kris
|
|
function index()
|
|
{
|
|
echo json_encode(["status" => "OK", "message" => ""]);
|
|
}
|
|
|
|
// https://devone.aplikasi.web.id/one-api/training/kris/upload_request/100
|
|
function upload_request($mouID)
|
|
{
|
|
echo json_encode(["status" => "OK", "message" => "mcuID : $mouID"]);
|
|
}
|
|
function check_agreement($mouID)
|
|
{
|
|
echo json_encode(["status" => "OK", "message" => "mcuID : $mouID"]);
|
|
}
|
|
|
|
// https://devone.aplikasi.web.id/one-api/training/kris/test_input
|
|
function test_input()
|
|
{
|
|
$param = $this->sys_input;
|
|
echo json_encode(["status" => "OK", "message" => $param]);
|
|
}
|
|
|
|
function test_db_01()
|
|
{
|
|
$sql = "select * from m_religion where M_ReligionIsActive ='Y'";
|
|
//1. bikin query
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo json_encode(
|
|
[
|
|
"status" => "ERR",
|
|
"message" => $this->db->error(),
|
|
"sql" => $this->db->last_query()
|
|
]
|
|
);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
echo json_encode(["status" => "OK", "data" => $rows]);
|
|
}
|
|
|
|
function test_db_02()
|
|
{
|
|
$param = $this->sys_input;
|
|
$search = "%" . $param["search"] . "%";
|
|
$is_active = $param["active"];
|
|
|
|
$sql = "select * from m_religion where M_ReligionIsActive = ?
|
|
and M_ReligionName like ? ";
|
|
//1. bikin query
|
|
$qry = $this->db->query($sql, [$is_active, $search]);
|
|
if (!$qry) {
|
|
echo json_encode(
|
|
[
|
|
"status" => "ERR",
|
|
"message" => $this->db->error(),
|
|
"sql" => $this->db->last_query()
|
|
]
|
|
);
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
echo json_encode(["status" => "OK", "data" => $rows]);
|
|
}
|
|
|
|
//transaction
|
|
function test_db_03()
|
|
{
|
|
// ambil user dari token
|
|
$user = $this->sys_user;
|
|
$userID = $user["M_UserID"];
|
|
$param = $this->sys_input;
|
|
// start transaction
|
|
$this->db->trans_start();
|
|
|
|
$sql = "insert into m_religion(M_ReligionName,M_ReligionM_UserID)
|
|
values (?,?)";
|
|
$qry = $this->db->query($sql, [$param["name"], $userID]);
|
|
if (!$qry) {
|
|
echo json_encode(
|
|
[
|
|
"status" => "ERR",
|
|
"message" => $this->db->error(),
|
|
"sql" => $this->db->last_query()
|
|
]
|
|
);
|
|
// rollback jika ada error
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
// insert tbl c
|
|
// commit
|
|
$last_query = $this->db->last_query();
|
|
$xid = $this->db->insert_id();
|
|
$this->db->trans_commit();
|
|
echo json_encode([
|
|
"status" => "OK", "message" => "Last ID : $xid ",
|
|
"sql" => $last_query
|
|
]);
|
|
}
|
|
function test_del()
|
|
{
|
|
// ambil user dari token
|
|
$user = $this->sys_user;
|
|
$userID = $user["M_UserID"];
|
|
$param = $this->sys_input;
|
|
// start transaction
|
|
$this->db->trans_start();
|
|
|
|
$sql = "update m_religion set M_ReligionIsActive = 'N',
|
|
M_ReligionM_UserID = ?
|
|
where M_ReligionID = ?";
|
|
|
|
$qry = $this->db->query($sql, [$userID, $param["id"]]);
|
|
if (!$qry) {
|
|
echo json_encode(
|
|
[
|
|
"status" => "ERR",
|
|
"message" => $this->db->error(),
|
|
"sql" => $this->db->last_query()
|
|
]
|
|
);
|
|
// rollback jika ada error
|
|
$this->db->trans_rollback();
|
|
exit;
|
|
}
|
|
// insert tbl c
|
|
// commit
|
|
$last_query = $this->db->last_query();
|
|
$this->db->trans_commit();
|
|
echo json_encode([
|
|
"status" => "OK", "message" => "Last ID : {$param["id"]} ",
|
|
"sql" => $last_query
|
|
]);
|
|
}
|
|
}
|
|
/*
|
|
{
|
|
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjM0MCIsIk1fVXNlclVzZXJuYW1lIjoiYWRtaW5zYXMgIiwiTV9Vc2VyR3JvdXBEYXNoYm9hcmQiOiJvbmUtdWlcL3Rlc3RcL3Z1ZXhcL29uZS1mby1yZWdpc3RyYXRpb24tdjI1IiwiTV9Vc2VyRGVmYXVsdFRfU2FtcGxlU3RhdGlvbklEIjoiMCIsIk1fU3RhZmZOYW1lIjoiQURNSU4iLCJpc19jb3VyaWVyIjoiTiIsInRpbWVfYXV0b2xvZ291dCI6IjEyMCIsImlwIjoiMTgyLjIuNDMuMTUzIiwiYWdlbnQiOiJNb3ppbGxhXC81LjAgKFgxMTsgTGludXggeDg2XzY0KSBBcHBsZVdlYktpdFwvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lXC8xMjIuMC4wLjAgU2FmYXJpXC81MzcuMzYiLCJ2ZXJzaW9uIjoidjIiLCJsYXN0LWxvZ2luIjoiMjAyNC0wMy0xNyAxODozNjozNCIsIk1fU2F0ZWxsaXRlSUQiOjB9.F0lsol25rSGJI6p40lNuuS1T2lsugSElutzbRuQR3Io"
|
|
}
|
|
*/
|