db_onedev = $this->load->database("onedev", true); $this->load->helper(array('form', 'url')); } public function search() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $sql = "SELECT Nar_TestID as id, Nar_TestID, Nar_TestSystem, Nar_TestDisplay, Nar_TestCode, Nar_TestScope, Nar_TestDescription FROM nar_test WHERE Nar_TestIsActive = 'Y' GROUP BY Nar_TestID "; //echo $sql; $query = $this->db_onedev->query($sql); $rows = $query->result_array(); $result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query()); $this->sys_ok($result); exit; } public function search_listing() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $sql = "SELECT IFNULL(Nar_TestID,0) as id, Nar_TestID, Nar_TestSystem, Nar_TestDisplay, Nar_TestCode, Nar_TestScope, Nar_TestDescription FROM nar_test WHERE Nar_TestIsActive = 'Y' "; //echo $sql; $query = $this->db_onedev->query($sql); $rows = $query->result_array(); $result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query()); $this->sys_ok($result); exit; } function selectcategory(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query ="SELECT * FROM t_category WHERE T_CategoryIsActive = 'Y' ORDER BY T_CategoryName asc"; //echo $query; $rows['categorys'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function save(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $Nar_TestName = $prm['name']; $Nar_TestIsPCR = $prm['ispcr']; $Nar_TestIsSchedule = $prm['isschedule']; $Nar_TestIsKuota = $prm['iskuota']; $userid = $this->sys_user["M_UserID"]; if($prm['xid'] == 0){ $query = "SELECT COUNT(*) as exist FROM nar_test WHERE Nar_TestIsActive = 'Y' AND Nar_TestName = '{$Nar_TestName}' AND Nar_TestT_CategoryID = '{$Nar_TestT_CategoryID}'"; $exist_code = $this->db_onedev->query($query)->row()->exist; if($exist_code == 0){ $sql = "insert into nar_test( Nar_TestName, Nar_TestIsPCR, Nar_TestIsSchedule, Nar_TestIsKuota, Nar_TestUserID, Nar_TestLastUpdate, Nar_TestCreated) values(?,?,?,?,?,now(),now())"; $query = $this->db_onedev->query($sql, array( $Nar_TestName, $Nar_TestIsPCR, $Nar_TestIsSchedule, $Nar_TestIsKuota, $userid) ); if (!$query) { $this->sys_error_db("nar_test insert",$this->db_onedev); exit; } $last_id = $this->db_onedev->insert_id(); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); }else{ $errors = array(); if($exist_code != 0){ array_push($errors,array('field'=>'code','msg'=>'Nama sudah ada yang pakai dong')); } $result = array ("total" => -1,"errors" => $errors, "records" => 0); $this->sys_ok($result); } }else{ $query = "SELECT COUNT(*) as exist FROM nar_test WHERE Nar_TestIsActive = 'Y' AND Nar_TestName = '{$Nar_TestName}' AND Nar_TestT_CategoryID = '{$Nar_TestT_CategoryID}' AND Nar_TestID <> {$prm['xid']}"; //echo $query; $exist_code = $this->db_onedev->query($query)->row()->exist; // echo $exist_code; if($exist_code == 0){ $sql = "UPDATE nar_test SET Nar_TestName = '{$Nar_TestName}', Nar_TestIsPCR = '{$Nar_TestIsPCR}', Nar_TestIsSchedule = '{$Nar_TestIsSchedule}', Nar_TestIsKuota = '{$Nar_TestIsKuota}', Nar_TestUserID = '{$userid}' WHERE Nar_TestID = '{$prm['xid']}'"; //echo $sql; $query = $this->db_onedev->query($sql); $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); }else{ $errors = array(); if($exist_code != 0){ array_push($errors,array('field'=>'code','msg'=>'Nama sudah ada yang pakai dong')); } $result = array ("total" => -1,"errors" => $errors, "records" => 0); $this->sys_ok($result); } } } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function delete() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id = $prm['xid']; $userid = $this->sys_user["M_UserID"]; $sql = "update nar_test SET Nar_TestIsActive = 'N', Nar_TestUserID = $userid, Nar_TestLastUpdate = now() WHERE Nar_TestID = $id"; $query = $this->db_onedev->query($sql); if (!$query) { $this->sys_error_db("nar_test delete"); exit; } $sqltest = "update nar_test_test SET T_SubcategoryTestIsActive = 'N', T_SubcategoryTestUserID = $userid, T_SubcategoryTestLastUpdated = now() WHERE T_SubcategoryTestT_SubcategoryID = $id"; $querytest = $this->db_onedev->query($sqltest); // echo $query; if (!$querytest) { $this->sys_error_db("nar_test_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 savejpagroup(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $query = "insert into nar_test( Nar_TestName, Nar_TestUserID, Nar_TestCreated ) VALUES( '{$prm['value']}', {$userid}, NOW() )"; //echo $query; $action = $this->db_onedev->query($query); if($action){ $result = array( "total" => 1 , "records" => array(), ); $this->sys_ok($result); exit; } else{ $this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev); exit; } } function savelistingjpagroup(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $query = " UPDATE nar_test SET Nar_TestName = '{$prm['name']}', Nar_TestIsActive = '{$prm['status']}', Nar_TestUserID = {$userid} WHERE Nar_TestID = {$prm['id']} "; //echo $query; $action = $this->db_onedev->query($query); if($action){ $result = array( "total" => 1 , "records" => array(), ); $this->sys_ok($result); exit; } else{ $this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev); exit; } } function savealljpadetail(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $details = $prm['details']; $userid = $this->sys_user["M_UserID"]; foreach($details as $k => $v){ $query = "insert into nar_test( Nat_JPADetailNat_JPAID, Nat_JPADetailNar_TestID, Nat_JPADetailDiscount, Nat_JPADetailUserID, Nat_JPADetailCreated ) VALUES( '{$v['Nat_JpaID']}', '{$v['Nar_TestID']}', '{$v['Nat_JPADetailDiscount']}', {$userid}, NOW() ) ON DUPLICATE KEY UPDATE Nat_JPADetailDiscount = {$v['Nat_JPADetailDiscount']}, Nat_JPADetailUserID = {$userid}"; //echo $query; $action = $this->db_onedev->query($query); } if($action){ $result = array( "total" => 1 , "records" => array(), ); $this->sys_ok($result); exit; } else{ $this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev); exit; } } }