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 map_word where ( Map_WordName LIKE CONCAT('%','{$search}','%') )AND Map_WordIsActive = '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("map_word count", $this->db_onedev); exit; } $sql = "select Map_WordID as id, Map_WordName as name, Map_WordName as description, 'N' as show_detail, '' as mapwordlangs from map_word where ( Map_WordName LIKE CONCAT('%','{$search}','%') )AND Map_WordIsActive = 'Y' ORDER BY Map_WordName 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]['mapwordlangs'] = $this->add_mapwordlang($v['id']); } } } } else { $this->sys_error_db("map_word 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 addnewmapword() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $name_mapword = $prm['name']; $sqlmapword = "insert into map_word( Map_WordName, Map_WordCreated, Map_WordLastUpdated ) values( ?, now(), now())"; $querymapword = $this->db->query($sqlmapword, array( $name_mapword ) ); //echo $query; $last_id = $this->db->insert_id(); $sqlmapwordlang = "insert into map_word_lang( Map_WordLangMap_WordID, Map_WordLangNat_LangID, Map_WordLangName, Map_WordLangCreated, Map_WordLangLastUpdated ) values( ?, ?, ?, now(), now())"; $querymapwordlang = $this->db->query($sqlmapwordlang, array( $last_id, 1, $name_mapword ) ); if (!$querymapword) { $this->sys_error_db("map_word 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 editmapword() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $id_mapword = $prm['id']; $name_mapword = $prm['name']; $sqlmapword = "update map_word SET Map_WordName = ?, Map_WordLastUpdated = now() where Map_WordID = ? "; $querymapword = $this->db->query($sqlmapword, array($name_mapword, $id_mapword ) ); $sqlmapwordlang = "update map_word_lang SET Map_WordLangName = ?, Map_WordLangLastUpdated = now() where Map_WordLangMap_WordID = ? AND Map_WordLangNat_LangID = 1 "; $querymapwordlang = $this->db->query($sqlmapwordlang, array($name_mapword, $id_mapword ) ); //echo $query; if (!$querymapword) { $this->sys_error_db("map_word update"); exit; } $result = array ("total" => 1, "records" => array("xid" => $id_mapword)); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } public function deletemapword() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } //# ambil parameter input $prm = $this->sys_input; $sql = "update map_word SET Map_WordIsActive = 'N', Map_WordLastUpdated = now() WHERE Map_WordID = ? "; $query = $this->db->query($sql, array( $prm['id'] ) ); // echo $query; if (!$query) { $this->sys_error_db("map_word 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 lookupmapwordlang(){ try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = $prm['id']; $sql = "select Map_WordLangID as id, Map_WordLangMap_WordID as mapwordid, Map_WordName as mapwordname, Map_WordLangName as name, Nat_LangName as langname, 'xxx' as action, 'Y' as show_detail from nat_lang left join map_word_lang ON Nat_LangID = Map_WordLangNat_LangID AND Map_WordLangMap_WordID = {$id} left join map_word ON Map_WordLangMap_WordID = Map_WordID where Nat_LangIsActive = 'Y' ORDER BY Map_WordName 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 lookupmapwordlangx() { 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 map_word where ( Map_WordName LIKE CONCAT('%','{$search}','%') )AND Map_WordIsActive = '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("map_word count", $this->db_onedev); exit; } $sql = "select Map_WordID as id, Map_WordName as name, Map_WordName as description, IF(Map_WordID = '{$id}','Y','N') as show_detail, '' as mapwordlangs from map_word where ( Map_WordName LIKE CONCAT('%','{$search}','%') )AND Map_WordIsActive = 'Y' ORDER BY Map_WordName 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]['mapwordlangs'] = $this->add_mapwordlang($id); } } } else { $this->sys_error_db("map_word 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_mapwordlang($mapwordid){ $query ="select IFNULL(Map_WordLangID,0) as id, IFNULL(Map_WordLangMap_WordID,$mapwordid) as mapwordid, IFNULL(Map_WordLangName,'') as name, IFNULL(Map_WordLangNat_LangID, 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 map_word_lang ON Nat_LangID = Map_WordLangNat_LangID AND Map_WordLangMap_WordID = {$mapwordid} left join map_word ON Map_WordLangMap_WordID = Map_WordID where Nat_LangIsActive = 'Y'"; // echo $query; $rows = $this->db->query($query)->result_array(); if(!$rows) $rows = array(); return $rows; } public function lookupmapwordlanghidex() { 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 map_word where ( Map_WordName LIKE CONCAT('%','{$search}','%') )AND Map_WordIsActive = '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("map_word count", $this->db_onedev); exit; } $sql = "select Map_WordID as id, Map_WordName as name, Map_WordName as description, 'N' as show_detail, '' as mapwordlangs from map_word where ( Map_WordName LIKE CONCAT('%','{$search}','%') )AND Map_WordIsActive = 'Y' ORDER BY Map_WordName 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]['mapwordlangs'] = $this->add_mapwordlang($id); } } } else { $this->sys_error_db("map_word 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 savemapwordlang(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $mapword_id = $prm['mapwordid']; $userid = $this->sys_user["M_UserID"]; foreach($prm['mapwordlangs'] as $k=>$v){ if($v['id'] == 0 || $v['id'] == '0'){ $query = "INSERT INTO map_word_lang ( Map_WordLangMap_WordID, Map_WordLangNat_LangID, Map_WordLangName, Map_WordLangUserID, Map_WordLangCreated, Map_WordLangLastUpdated ) VALUE( ?,?,?,?,now(),now() )"; $insert_new_mapwordlang = $this->db->query($query,array( $mapword_id, $v['langid'], $v['name'], $userid )); } else { $query = "UPDATE map_word_lang SET Map_WordLangMap_WordID = ?, Map_WordLangNat_LangID = ?, Map_WordLangName = ?, Map_WordLangUserID = ? WHERE Map_WordLangID = ?"; $update_mapwordlang = $this->db->query($query,array($mapword_id,$v['langid'],$v['name'],$v['siname'],$v['konversi'],$userid,$v['id'])); } } $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } }