FHM28052601 - add email config endpoint

This commit is contained in:
sas.fajri
2026-05-28 10:55:34 +07:00
parent 7834c044ad
commit 01c73cffb4

View File

@@ -0,0 +1,78 @@
<?php
class Config_email extends MY_Controller
{
var $db_onedev;
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function index()
{
echo "EMAIL CONFIG API";
}
public function getdata()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "select *
from m_emailconfig
where
M_EmailConfigIsActive = 'Y' LIMIT 1";
$rows = $this->db_onedev->query($sql)->row_array();
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 {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "update m_emailconfig SET
M_EmailConfigSender = '{$prm['M_EmailConfigSender']}',
M_EmailConfigUsername = '{$prm['M_EmailConfigUsername']}',
M_EmailConfigPassword = '{$prm['M_EmailConfigPassword']}',
M_EmailConfigServer = '{$prm['M_EmailConfigServer']}',
M_EmailConfigMaxRetry = '{$prm['M_EmailConfigMaxRetry']}',
M_EmailConfigResultFormatAPS = '{$prm['M_EmailConfigResultFormatAPS']}',
M_EmailConfigCc = '{$prm['M_EmailConfigCc']}',
M_EmailConfigLastUpdate = now()
where
M_EmailConfigID = {$prm['M_EmailConfigID']}";
$query = $this->db_onedev->query($sql);
if (!$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);
}
}
}