522 lines
18 KiB
PHP
522 lines
18 KiB
PHP
<?php
|
|
|
|
class Testlang extends MY_Controller
|
|
{
|
|
public function index()
|
|
{
|
|
echo "TEST LANG API";
|
|
}
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function lookup()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
$sql = "select COUNT(*) as total
|
|
FROM t_test
|
|
LEFT JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
LEFT JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
|
LEFT JOIN nat_subgroup ON T_TestNat_SubGroupID = Nat_SubGroupID
|
|
LEFT JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
|
LEFT JOIN nat_subsubgroup ON nat_subsubgroupID = Nat_Testnat_subsubgroupID
|
|
LEFT JOIN nat_testtype ON Nat_TestNat_TestTypeID = Nat_TestTypeID
|
|
where
|
|
( Nat_TestName LIKE CONCAT('%','{$search}','%') OR
|
|
T_TestSasCode LIKE CONCAT('%','{$search}','%')
|
|
)AND
|
|
T_TestIsActive = 'Y'";
|
|
$sql_param = array($search);
|
|
$query = $this->db_onedev->query($sql);
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("nat_test count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
|
|
$sql = "select *, Nat_TestID as id,
|
|
Nat_TestName as name,
|
|
Nat_TestName as description,
|
|
'N' as show_detail,
|
|
'' as nattestlangs,
|
|
T_TestIsNonLab as T_TestIsNonLabID,IF(T_TestIsNonLab = '', 'LAB',T_TestIsNonLab) as T_TestIsNonLabs, T_TestSasCode as db_T_TestSasCode
|
|
FROM t_test
|
|
LEFT JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
LEFT JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
|
LEFT JOIN nat_subgroup ON T_TestNat_SubGroupID = Nat_SubGroupID
|
|
LEFT JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
|
LEFT JOIN nat_subsubgroup ON nat_subsubgroupID = Nat_Testnat_subsubgroupID
|
|
LEFT JOIN nat_testtype ON Nat_TestNat_TestTypeID = Nat_TestTypeID
|
|
where
|
|
( Nat_TestName LIKE CONCAT('%','{$search}','%') OR
|
|
T_TestSasCode LIKE CONCAT('%','{$search}','%')
|
|
)AND
|
|
T_TestIsActive = 'Y'
|
|
ORDER BY T_TestSasCode ASC
|
|
limit $number_limit offset $number_offset ";
|
|
$sql_param = array($search);
|
|
$query = $this->db->query($sql);
|
|
//echo $this->db->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
if($v['show_detail'] === 'Y'){
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['nattestlangs'] = $this->add_nattestlang($v['id']);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
$this->sys_error_db("nat_test select");
|
|
exit;
|
|
}
|
|
|
|
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
public function addnewnattest()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$name_nattest = $prm['name'];
|
|
$sqlnattest = "insert into nat_test(
|
|
Nat_TestName,
|
|
Nat_TestCreated,
|
|
Nat_TestLastUpdated
|
|
)
|
|
values( ?, now(), now())";
|
|
$querynattest = $this->db->query($sqlnattest,
|
|
array(
|
|
$name_nattest
|
|
)
|
|
);
|
|
//echo $query;
|
|
$last_id = $this->db->insert_id();
|
|
$sqlnattestlang = "insert into nat_testlang(
|
|
Nat_TestLangNat_TestID,
|
|
Nat_TestLangLangID,
|
|
Nat_TestLangName,
|
|
Nat_TestLangCreated,
|
|
Nat_TestLangLastUpdated
|
|
)
|
|
values( ?, ?, ?, now(), now())";
|
|
$querynattestlang = $this->db->query($sqlnattestlang,
|
|
array(
|
|
$last_id,
|
|
1,
|
|
$name_nattest
|
|
)
|
|
);
|
|
if (!$querynattest) {
|
|
$this->sys_error_db("nat_test insert");
|
|
exit;
|
|
}
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function editnattest()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$id_nattest = $prm['id'];
|
|
$name_nattest = $prm['name'];
|
|
$sqlnattest = "update nat_test SET
|
|
Nat_TestName = ?,
|
|
Nat_TestLastUpdated = now()
|
|
where
|
|
Nat_TestID = ?
|
|
";
|
|
$querynattest = $this->db->query($sqlnattest,
|
|
array($name_nattest,
|
|
$id_nattest
|
|
)
|
|
);
|
|
$sqlnattestlang = "update nat_testlang SET
|
|
Nat_TestLangName = ?,
|
|
Nat_TestLangLastUpdated = now()
|
|
where
|
|
Nat_TestLangNat_TestID = ? AND
|
|
Nat_TestLangLangID = 1
|
|
";
|
|
$querynattestlang = $this->db->query($sqlnattestlang,
|
|
array($name_nattest,
|
|
$id_nattest
|
|
)
|
|
);
|
|
//echo $query;
|
|
if (!$querynattest) {
|
|
$this->sys_error_db("nat_test update");
|
|
exit;
|
|
}
|
|
$result = array ("total" => 1, "records" => array("xid" => $id_nattest));
|
|
$this->sys_ok($result);
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function deletenattest()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
|
|
$sql = "update nat_test SET
|
|
Nat_TestIsActive = 'N',
|
|
Nat_TestLastUpdated = now()
|
|
WHERE
|
|
Nat_TestID = ?
|
|
|
|
";
|
|
|
|
$query = $this->db->query($sql,
|
|
array(
|
|
$prm['id']
|
|
)
|
|
);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("nat_test delete");
|
|
exit;
|
|
}
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function lookupnattestlang(){
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $prm['id'];
|
|
$sql = "select Nat_TestLangID as id,
|
|
Nat_TestLangNat_TestID as nattestid,
|
|
Nat_TestName as nattestname,
|
|
Nat_TestLangName as name,
|
|
Nat_LangName as langname,
|
|
'xxx' as action,
|
|
'Y' as show_detail
|
|
from nat_lang
|
|
left join nat_testlang ON Nat_LangID = Nat_TestLangLangID AND Nat_TestLangNat_TestID = {$id}
|
|
left join nat_test ON Nat_TestLangNat_TestID = Nat_TestID
|
|
where
|
|
Nat_LangIsActive = 'Y' ORDER BY T_TestSasCode ASC";
|
|
//echo $sql;
|
|
$rows = $this->db->query($sql)->result();
|
|
|
|
$result = array ("total" => count($rows), "records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function lookupnattestlangx()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
$all = $prm['all'];
|
|
$id = $prm['id'];
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
|
|
$sql = "select COUNT(*) as total
|
|
FROM t_test
|
|
LEFT JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
LEFT JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
|
LEFT JOIN nat_subgroup ON T_TestNat_SubGroupID = Nat_SubGroupID
|
|
LEFT JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
|
LEFT JOIN nat_subsubgroup ON nat_subsubgroupID = Nat_Testnat_subsubgroupID
|
|
LEFT JOIN nat_testtype ON Nat_TestNat_TestTypeID = Nat_TestTypeID
|
|
where
|
|
( Nat_TestName LIKE CONCAT('%','{$search}','%') OR
|
|
T_TestSasCode LIKE CONCAT('%','{$search}','%')
|
|
)AND
|
|
T_TestIsActive = 'Y'";
|
|
$sql_param = array($search);
|
|
$query = $this->db_onedev->query($sql);
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("nat_test count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
$sql = "select *, Nat_TestID as id,
|
|
Nat_TestName as name,
|
|
Nat_TestName as description,
|
|
IF(Nat_TestID = '{$id}','Y','N') as show_detail,
|
|
'' as nattestlangs,
|
|
T_TestIsNonLab as T_TestIsNonLabID,IF(T_TestIsNonLab = '', 'LAB',T_TestIsNonLab) as T_TestIsNonLabs, T_TestSasCode as db_T_TestSasCode
|
|
FROM t_test
|
|
LEFT JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
LEFT JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
|
LEFT JOIN nat_subgroup ON T_TestNat_SubGroupID = Nat_SubGroupID
|
|
LEFT JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
|
LEFT JOIN nat_subsubgroup ON nat_subsubgroupID = Nat_Testnat_subsubgroupID
|
|
LEFT JOIN nat_testtype ON Nat_TestNat_TestTypeID = Nat_TestTypeID
|
|
where
|
|
( Nat_TestName LIKE CONCAT('%','{$search}','%') OR
|
|
T_TestSasCode LIKE CONCAT('%','{$search}','%')
|
|
)AND
|
|
T_TestIsActive = 'Y'
|
|
ORDER BY T_TestSasCode ASC
|
|
limit $number_limit offset $number_offset";
|
|
$sql_param = array($search);
|
|
$query = $this->db->query($sql);
|
|
//echo $this->db->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['nattestlangs'] = $this->add_nattestlang($id);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
$this->sys_error_db("nat_test select");
|
|
exit;
|
|
}
|
|
|
|
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function add_nattestlang($nattestid){
|
|
$sqltestname = $this->db_onedev->query("SELECT Nat_TestName FROM nat_test
|
|
WHERE Nat_TestID = $nattestid ")->row();
|
|
$testname = $sqltestname->Nat_TestName;
|
|
|
|
$query ="select IFNULL(Nat_TestLangID,0) as id,
|
|
IFNULL(Nat_TestLangNat_TestID,$nattestid) as nattestid,
|
|
IFNULL(Nat_TestLangName,IF(Nat_LangID = 1,'{$testname}','')) as name,
|
|
IFNULL(Nat_TestLangLangID, Nat_LangID) as langid,
|
|
IFNULL(Nat_LangName,'') as langname,
|
|
'xxx' as action,
|
|
'Y' as show_detail,
|
|
Nat_LangID as idx,
|
|
Nat_LangID
|
|
from nat_lang
|
|
left join nat_testlang ON Nat_LangID = Nat_TestLangLangID AND Nat_TestLangNat_TestID = {$nattestid}
|
|
left join nat_test ON Nat_TestLangNat_TestID = Nat_TestID
|
|
where
|
|
Nat_LangIsActive = 'Y'";
|
|
// echo $query;
|
|
$rows = $this->db->query($query)->result_array();
|
|
if(!$rows)
|
|
$rows = array();
|
|
return $rows;
|
|
}
|
|
public function lookupnattestlanghidex()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$prm = $this->sys_input;
|
|
$search = $prm['search'];
|
|
$all = $prm['all'];
|
|
$id = $prm['id'];
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
|
|
$sql = "select COUNT(*) as total
|
|
FROM t_test
|
|
LEFT JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
LEFT JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
|
LEFT JOIN nat_subgroup ON T_TestNat_SubGroupID = Nat_SubGroupID
|
|
LEFT JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
|
LEFT JOIN nat_subsubgroup ON nat_subsubgroupID = Nat_Testnat_subsubgroupID
|
|
LEFT JOIN nat_testtype ON Nat_TestNat_TestTypeID = Nat_TestTypeID
|
|
where
|
|
( Nat_TestName LIKE CONCAT('%','{$search}','%') OR
|
|
T_TestSasCode LIKE CONCAT('%','{$search}','%')
|
|
)AND
|
|
T_TestIsActive = 'Y'";
|
|
$sql_param = array($search);
|
|
$query = $this->db_onedev->query($sql);
|
|
$tot_count = 0;
|
|
$tot_page = 0;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
$tot_page = ceil($tot_count/$number_limit);
|
|
} else {
|
|
$this->sys_error_db("nat_test count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
$sql = "select *, Nat_TestID as id,
|
|
Nat_TestName as name,
|
|
Nat_TestName as description,
|
|
'N' as show_detail,
|
|
'' as nattestlangs,
|
|
T_TestIsNonLab as T_TestIsNonLabID,IF(T_TestIsNonLab = '', 'LAB',T_TestIsNonLab) as T_TestIsNonLabs, T_TestSasCode as db_T_TestSasCode
|
|
FROM t_test
|
|
LEFT JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
|
|
LEFT JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID
|
|
LEFT JOIN nat_subgroup ON T_TestNat_SubGroupID = Nat_SubGroupID
|
|
LEFT JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
|
LEFT JOIN nat_subsubgroup ON nat_subsubgroupID = Nat_Testnat_subsubgroupID
|
|
LEFT JOIN nat_testtype ON Nat_TestNat_TestTypeID = Nat_TestTypeID
|
|
where
|
|
( Nat_TestName LIKE CONCAT('%','{$search}','%') OR
|
|
T_TestSasCode LIKE CONCAT('%','{$search}','%')
|
|
)AND
|
|
T_TestIsActive = 'Y'
|
|
ORDER BY T_TestSasCode ASC
|
|
limit $number_limit offset $number_offset";
|
|
$sql_param = array($search);
|
|
$query = $this->db->query($sql);
|
|
//echo $this->db->last_query();
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['nattestlangs'] = $this->add_nattestlang($id);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
$this->sys_error_db("nat_test select");
|
|
exit;
|
|
}
|
|
|
|
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
function savenattestlang(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$nattest_id = $prm['nattestid'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
foreach($prm['nattestlangs'] as $k=>$v){
|
|
if($v['id'] == 0 || $v['id'] == '0'){
|
|
$query = "INSERT INTO nat_testlang (
|
|
Nat_TestLangNat_TestID,
|
|
Nat_TestLangLangID,
|
|
Nat_TestLangName,
|
|
Nat_TestLangCreated,
|
|
Nat_TestLangLastUpdated
|
|
)
|
|
VALUE(
|
|
?,?,?,now(),now()
|
|
)";
|
|
$insert_new_nattestlang = $this->db->query($query,array(
|
|
$nattest_id,
|
|
$v['langid'],
|
|
$v['name']
|
|
));
|
|
} else {
|
|
$query = "UPDATE nat_testlang SET
|
|
Nat_TestLangNat_TestID = ?,
|
|
Nat_TestLangLangID = ?,
|
|
Nat_TestLangName = ?
|
|
WHERE
|
|
Nat_TestLangID = ?";
|
|
$update_nattestlang = $this->db->query($query,array($nattest_id,$v['langid'],$v['name'],$v['siname'],$v['konversi'],$v['id']));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
}
|