db_onedev = $this->load->database("onedev", true); } public function lookuptest() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = $prm['search']; $all = $prm['all']; $limit = ''; if($all == 'N'){ $limit = ' LIMIT 10'; } $sql = "select COUNT(*) as total from t_test where T_TestIsActive = 'Y'"; $sql_param = array($search); $total = $this->db_onedev->query($sql,$sql_param)->row()->total; $sql = "select T_TestID as id, T_TestName as dashboard, CONCAT(T_TestName,' ' ,'[ ',T_TestCode,' ]') as name, T_TestCode as code, T_TestName as description , 'xxx' as usergrouptype from t_test where T_TestName LIKE CONCAT('%','{$search}','%') AND T_TestIsActive = 'Y' union select T_PacketID as id, T_PacketName as dashboard, CONCAT(T_PacketName,' ' ,'[ ',T_PacketSasCode,' ]') as name, T_PacketSasCode as code, T_PacketName as description , 'xxx' as usergrouptype from t_packet where T_PacketName LIKE CONCAT('%','{$search}','%') AND T_PacketIsActive = 'Y' $limit"; $sql_param = array($search); $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("t_test 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 lookupfavorite() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = "SELECT T_TestID as id, T_TestName as name from t_favorite join t_test on T_FavoriteT_TestID = T_TestID WHERE T_FavoriteIsActive= 'y' union SELECT T_PacketID as id, T_PacketName as name from t_favorite join t_packet on T_FavoriteT_PacketID= T_PacketID where T_FavoriteIsActive= 'y' "; $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("m_usergroup select"); exit; } $result = array ("total"=>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; } $prm = $this->sys_input; $datas = $prm['datas']; foreach ($datas as $k => $v){ foreach ($v['childs'] as $kx => $vx){ if($vx['active'] == 'Y'){ if(is_null($vx['S_PrivilegeID']) && $vx['status'] == 'Y'){ $sql = "INSERT INTO s_privilege ( S_PrivilegeM_UserGroupID, S_PrivilegeS_MenuID, S_PrivilegeCreated ) VALUES( {$vx['usergroupid']}, {$vx['S_MenuID']}, NOW() )"; $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); } if(!is_null($vx['S_PrivilegeID'])){ $sql = "UPDATE s_privilege SET S_PrivilegeIsActive = '{$vx['status']}' WHERE S_PrivilegeID = '{$vx['S_PrivilegeID']}' "; $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); } } if($vx['childs']){ foreach ($vx['childs'] as $kxz => $vxz){ if($vxz['active'] == 'Y'){ if(is_null($vxz['S_PrivilegeID']) && $vxz['status'] == 'Y'){ $sql = "INSERT INTO s_privilege ( S_PrivilegeM_UserGroupID, S_PrivilegeS_MenuID, S_PrivilegeCreated ) VALUES( {$vxz['usergroupid']}, {$vxz['S_MenuID']}, NOW() )"; $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); } if(!is_null($vxz['S_PrivilegeID'])){ $sql = "UPDATE s_privilege SET S_PrivilegeIsActive = '{$vxz['status']}' WHERE S_PrivilegeID = '{$vxz['S_PrivilegeID']}' "; $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); } } } } } } $result = array ("total"=>1,"records" => array()); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function deletefavoritetest() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $sql = "update t_favorite SET T_FavoriteIsActive = 'N', T_FavoriteLastUpdated = now() WHERE T_FavoriteID = ? "; $query = $this->db_onedev->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("t_favorite delete"); exit; } $result = array ("total" => 1, "records" => array("xid" => 0)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } }