Files
BE_IBL/application/controllers/mockup/masterdata/Physiclang.php
2026-04-15 15:24:12 +07:00

216 lines
6.2 KiB
PHP

<?php
class Physiclang extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "EMAIL CONFIG API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function getlang()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "select Nat_LangID as id, Nat_LangName as name
from nat_lang
where
Nat_LangID <> 1 AND Nat_LangIsActive = 'Y'";
$rows = $this->db_onedev->query($sql)->result_array();
//echo $this->db_onedev->last_query();
if (!$rows) {
$this->sys_error_db("emailconfig 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 search()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$lang_id = $prm['lang_id'];
$max_rst = 10;
$page = $prm['page'];
if ($page == null)
$page = 1;
$offset = ($page - 1) * $max_rst;
// QUERY TOTAL
$sql = "select distinct count(*) as total
from translate_word
where
Translate_WordNat_LangID = {$lang_id} AND
Translate_WordFrom LIKE CONCAT('%','{$prm['search']}','%') AND
Translate_WordIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
if ($query) {
$tot_count = ceil($query->result_array()[0]["total"]/$max_rst);
}
else {
$this->sys_error_db("price company count", $this->db_onedev);
exit;
}
$sql = "select *
from translate_word
where
Translate_WordNat_LangID = {$lang_id} AND
Translate_WordFrom LIKE CONCAT('%','{$prm['search']}','%') AND
Translate_WordIsActive = 'Y'
LIMIT {$offset}, {$max_rst}";
$rows = $this->db_onedev->query($sql)->result_array();
//echo $this->db_onedev->last_query();
if (!$rows) {
$this->sys_error_db("emailconfig select");
exit;
}
$result = array ("total" => $tot_count ,"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function getdata()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$lang_id = $prm['lang_id'];
$sql = "select count(*) as total
from translate_word
where
Translate_WordNat_LangID = {$lang_id} AND
Translate_WordFrom LIKE CONCAT('%','{$prm['search']}','%') AND
Translate_WordIsActive = 'Y'";
$rows = $this->db_onedev->query($sql)->row_array();
//echo $this->db_onedev->last_query();
if (!$rows) {
$this->sys_error_db("emailconfig select");
exit;
}
$sql = "select *
from translate_word
where
Translate_WordNat_LangID = {$lang_id} AND
Translate_WordFrom LIKE CONCAT('%','{$prm['search']}','%') AND
Translate_WordIsActive = 'Y'";
$rows = $this->db_onedev->query($sql)->result_array();
//echo $this->db_onedev->last_query();
if (!$rows) {
$this->sys_error_db("emailconfig 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;
}
//# ambil parameter input
$prm = $this->sys_input;
//print_r($prm);
$userid = $this->sys_user["M_UserID"];
$datas = $prm['datas'];
$lang_id = $prm['lang']['id'];
foreach($datas as $k => $v){
if($v['Translate_WordFrom'] !== '' && $v['Translate_WordTo'] !== ''){
// Escape string untuk mencegah SQL injection dan error karena tanda petik
$wordFrom = $this->db_onedev->escape_str($v['Translate_WordFrom']);
$wordTo = $this->db_onedev->escape_str($v['Translate_WordTo']);
if(intval($v['Translate_WordID']) == 0){
$sql = "INSERT INTO translate_word (
Translate_WordNat_LangID,
Translate_WordFrom,
Translate_WordTo,
Translate_WordUserID
)
VALUES (
{$lang_id},
'{$wordFrom}',
'{$wordTo}',
{$userid}
)";
}else{
$sql = "UPDATE translate_word SET Translate_WordFrom = '{$wordFrom}',Translate_WordTo = '{$wordTo}' WHERE Translate_WordID = {$v['Translate_WordID']}";
}
$query = $this->db_onedev->query($sql);
// echo $this->db_onedev->last_query();
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("email config update");
exit;
}
}
}
$result = array ("total" => 1, "records" => array());
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}