db_onedev = $this->load->database("onedev", true); } public function search() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $testname = $prm["testname"]; $packetname = $prm["packetname"]; $status = $prm["status"]; // echo $testname; $sql_where = "WHERE T_FavoriteType = '{$status}' AND T_FavoriteIsActive = 'Y' "; $sql_param = array(); if ($packetname != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " T_TestName like ? "; $sql_param[] = "%$packetname%"; } if ($testname != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " T_PacketName like ? "; $sql_param[] = "%$testname%"; } //if ($sql_where != "") $sql_where .= " and "; // Order masih dalam status registrasi //$sql_where .= " T_FavoriteIsActive = 'Y' "; $sql = " SELECT count(*) as total FROM t_favorite LEFT JOIN t_test ON T_FavoriteT_TestID = T_TestID LEFT JOIN t_packet ON T_FavoriteT_PacketID = T_PacketID $sql_where "; //echo $sql; $query = $this->db_onedev->query($sql, $sql_param); $tot_count = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("t_favorite count", $this->db_onedev); exit; } $sql = "SELECT t_favorite.*, CASE WHEN T_FavoriteType = 'PX' THEN 'Test' WHEN T_FavoriteType = 'PN' THEN 'Paket Panel' WHEN T_FavoriteType = 'PR' THEN 'Paket Profil' END as T_FavoriteTypeName, T_TestID, T_TestName, T_PacketID, T_PacketName, IF(T_FavoriteIsPacket = 'Y','YA','TIDAK') as ispacket FROM t_favorite LEFT JOIN t_test ON T_FavoriteT_TestID = T_TestID LEFT JOIN t_packet ON T_FavoriteT_PacketID = T_PacketID $sql_where ORDER BY T_FavoriteID ASC limit 0,$tot_count"; //echo $sql; $query = $this->db_onedev->query($sql, $sql_param); $rows = $query->result_array(); if($rows){ foreach($rows as $k => $v){ //$rows[$k]['verification_px'] = $this->add_verification_test($v['T_FavoriteID']); } } //$this->_add_address($rows); $result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query()); $this->sys_ok($result); exit; } function getsexreg(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query ="SELECT 'Test' as T_FavoriteTypeName, 'PX' as T_FavoriteType UNION SELECT 'Paket Panel' as T_FavoriteTypeName, 'PN' as T_FavoriteType UNION SELECT 'Paket Profil' as T_FavoriteTypeName, 'PR' as T_FavoriteType "; //echo $query; $rows['types'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function searchtest(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM t_test WHERE T_TestName like ? AND T_TestIsActive = 'Y' AND T_TestIsPrice = 'Y'"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("t_test count",$this->db_onedev); exit; } $sql = " SELECT * FROM t_test WHERE T_TestName like ? AND T_TestIsActive = 'Y' AND T_TestIsPrice = 'Y' ORDER BY T_TestName DESC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("t_test rows",$this->db_onedev); exit; } } function searchpacket(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $search = $prm["search"]; $tipe = $prm["tipe"]; $sql_where = "WHERE T_PacketIsActive = 'Y' "; $sql_param = array(); if ($search != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " T_PacketName like ? "; $sql_param[] = "%$search%"; } if ($tipe != "") { if ($sql_where != "") { $sql_where .=" and "; } $sql_where .= " T_PacketType like ? "; $sql_param[] = "%$tipe%"; } // QUERY TOTAL $sql = "SELECT count(*) as total FROM t_packet $sql_where"; $query = $this->db_onedev->query($sql,$sql_param); echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("t_packet count",$this->db_onedev); exit; } $sql = " SELECT * FROM t_packet $sql_where"; $query = $this->db_onedev->query($sql,$sql_param); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("t_packet rows",$this->db_onedev); exit; } } function getsubarea(){ $prm = $this->sys_input; $query =" SELECT * FROM m_subarea WHERE M_SubareaIsActive = 'Y' AND M_SubareaT_TestID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array($prm['id']))->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function save(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $ispacket = $prm['T_FavoriteIsPacket']; $userid = $this->sys_user["M_UserID"]; $query ="UPDATE t_favorite SET T_FavoriteType = '{$prm['T_FavoriteType']}', T_FavoriteT_TestID = '{$prm['T_FavoriteT_TestID']}', T_FavoriteT_PacketID = '{$prm['T_FavoriteT_PacketID']}', T_FavoriteIsPacket = '{$ispacket}', T_FavoriteUserID = '{$userid}', T_FavoriteLastUpdated = now() WHERE T_FavoriteID = '{$prm['T_FavoriteID']}' "; //echo $query; $rows = $this->db_onedev->query($query); if($rows){ } $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function newtestfavorite(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $ispacket = $prm['T_FavoriteIsPacket']; $userid = $this->sys_user["M_UserID"]; $query ="INSERT INTO t_favorite( T_FavoriteType, T_FavoriteT_TestID, T_FavoriteT_PacketID, T_FavoriteIsPacket, T_FavoriteUserID, T_FavoriteCreated, T_FavoriteLastUpdated ) VALUES( '{$prm['T_FavoriteType']}', '{$prm['T_FavoriteT_TestID']}', '{$prm['T_FavoriteT_PacketID']}', '{$ispacket}', '{$userid}', now(), now() ) "; //echo $query; $rows = $this->db_onedev->query($query); $last_id = $this->db_onedev->insert_id(); if($rows){ } $result = array( "total" => 1 , "records" => array('status'=>'OK'), "id" => $last_id ); $this->sys_ok($result); exit; } function deletetestfavorite(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query ="UPDATE t_favorite SET T_FavoriteIsActive = 'N' WHERE T_FavoriteID = '{$prm['T_FavoriteID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function getaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query =" SELECT t_favoriteaddress.*, M_KelurahanName, M_DistrictID, M_DistrictName, T_TestID, T_TestName, '' as action FROM t_favoriteaddress JOIN m_kelurahan ON T_FavoriteAddressM_KelurahanID = M_KelurahanID JOIN m_district ON M_KelurahanM_DistrictID = M_DistrictID JOIN t_test ON M_DistrictT_TestID = T_TestID WHERE T_FavoriteAddressIsActive = 'Y' AND T_FavoriteAddressT_FavoriteID = ? "; //echo $query; $rows = $this->db_onedev->query($query,array($prm['id']))->result_array(); if($rows){ foreach($rows as $k => $v){ $rows[$k]['action'] = 'delete'; $rows[$k]['action'] .= 'edit'; } } $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function savenewaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $count_addrs = $this->db_onedev->query("SELECT COUNT(*) as countx FROM t_favoriteaddress WHERE T_FavoriteAddressT_FavoriteID = '{$prm['T_FavoriteAddressT_FavoriteID']}' AND T_FavoriteAddressIsActive = 'Y'")->row()->countx; //echo $this->db_onedev->last_query(); if($count_addrs == 0){ $prm['T_FavoriteAddressNote'] = 'Utama'; } else{ $count_addrs_utama = $this->db_onedev->query("SELECT COUNT(*) as countx FROM t_favoriteaddress WHERE T_FavoriteAddressT_FavoriteID = '{$prm['T_FavoriteAddressT_FavoriteID']}' AND T_FavoriteAddressNote = 'Utama' AND T_FavoriteAddressIsActive = 'Y'")->row()->countx; if($count_addrs_utama > 0 && strtolower($prm['T_FavoriteAddressNote']) == 'utama'){ $rx = date('YmdHis'); $prm['T_FavoriteAddressNote'] = 'Utama_'.$rx; } } $query ="INSERT INTO t_favoriteaddress ( T_FavoriteAddressT_FavoriteID, T_FavoriteAddressNote, T_FavoriteAddressDescription, T_FavoriteAddressM_KelurahanID, T_FavoriteAddressCreated ) VALUES( '{$prm['T_FavoriteAddressT_FavoriteID']}', '{$prm['T_FavoriteAddressNote']}', '{$prm['T_FavoriteAddressDescription']}', '{$prm['T_FavoriteAddressM_KelurahanID']}', NOW() ) "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function saveeditaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query ="UPDATE t_favoriteaddress SET T_FavoriteAddressT_FavoriteID = '{$prm['T_FavoriteAddressT_FavoriteID']}', T_FavoriteAddressNote = '{$prm['T_FavoriteAddressNote']}', T_FavoriteAddressDescription = '{$prm['T_FavoriteAddressDescription']}', T_FavoriteAddressM_KelurahanID = '{$prm['T_FavoriteAddressM_KelurahanID']}' WHERE T_FavoriteAddressID = '{$prm['T_FavoriteAddressID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function deleteaddress(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $query ="UPDATE t_favoriteaddress SET T_FavoriteAddressIsActive = 'N' WHERE T_FavoriteAddressID = '{$prm['T_FavoriteAddressID']}' "; //echo $query; $rows = $this->db_onedev->query($query); $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } }