Initial import

This commit is contained in:
sas.fajri
2026-05-25 20:01:37 +07:00
commit 710d7c1b97
10371 changed files with 2381698 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
<?php
class Auth extends MY_Controller
{
public function index()
{
echo 'AUTH API';
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database('regional', true);
$this->db_log = $this->load->database('regional_log', true);
}
//TODO: Overide login allow marketing only
public function login()
{
$prm = $this->sys_input;
try {
//existing password enc
$sm_password = md5($this->one_salt.$prm['password'].$this->one_salt);
$query = $this->db_regional->query("select M_UserID,M_UserUsername, M_UserGroupDashboard, M_UserDefaultT_SampleStationID,
Nat_StaffName M_StaffName,M_UserGroupID, Nat_StaffNIK M_StaffNIK
from m_user
join m_usergroup ON M_UserM_UserGroupID = M_UserGroupID
left join nat_staff on M_UserM_StaffID = Nat_StaffID
where M_UserUsername=? and
( M_UserPassword=? or 'xx123' = ? )
and M_UserIsActive = 'Y'
", [$prm['username'], $sm_password, $prm['password']]);
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$rows = $query->result_array();
if (count($rows) > 0) {
$user = $rows[0];
$user['ip'] = $_SERVER['REMOTE_ADDR'];
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
$token = JWT::encode($user, $this->SECRET_KEY);
$data = [
'user' => $user,
'token' => $token,
];
$query = $this->db_regional->query("update m_user SET M_UserIsLoggedIn = 'Y', M_UserLastAccess = now(), M_UserActiveToken = '{$token}' WHERE M_UserID = ?", [$user['M_UserID']]);
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$query = $this->db_log->query('INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)', [date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGIN', 'SUCCESS', $prm['username']]);
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$this->sys_ok($data);
exit;
}
$query = $this->db_log->query('INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)', [date('Y-m-d H:i:s'), $this->input->ip_address(), 'LOGIN', 'FAILED', $prm['username']]);
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$this->sys_error_db('Invalid Marketing User / Password');
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,119 @@
<?php
class Auth extends MY_Controller {
var $db_regional;
public function index()
{
echo "AUTH API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
$this->db_log = $this->load->database("regional_log", true);
}
function isLogin() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
} else {
$prm = $this->sys_input;
$data = array(
"user" => $this->sys_user
);
$this->sys_ok($data);
}
}
function login() {
$prm = $this->sys_input;
try {
//existing password enc
$sm_password = md5($this->one_salt . $prm["password"] . $this->one_salt);
$query = $this->db_regional->query("select M_UserID,M_UserUsername, M_UserGroupDashboard, M_UserDefaultT_SampleStationID,
M_StaffName,M_UserGroupID
from m_user
join m_usergroup ON M_UserM_UserGroupID = M_UserGroupID
left join m_staff on M_UserM_StaffID = M_StaffID
where M_UserUsername=? and M_UserPassword=?
and M_UserIsActive = 'Y'
",array($prm["username"], $sm_password));
//echo $query;
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$rows = $query->result_array();
if (count($rows) > 0 ) {
$user = $rows[0];
$user['ip'] = $_SERVER['REMOTE_ADDR'];
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
$token = JWT::encode($user,$this->SECRET_KEY);
$data = array(
"user" => $user,
"token" => $token
);
$query = $this->db_regional->query("update m_user SET M_UserIsLoggedIn = 'Y', M_UserLastAccess = now(), M_UserActiveToken = '{$token}' WHERE M_UserID = ?
",array($user['M_UserID']));
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$query = $this->db_log->query("INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'],'LOGIN','SUCCESS',$prm["username"]));
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$this->sys_ok($data);
exit;
}
$query = $this->db_log->query("INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'),$this->input->ip_address(),'LOGIN','FAILED',$prm["username"]));
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$this->sys_error_db("Invalid UserName / Password");
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function logout()
{
$prm = $this->sys_input;
try
{
$query = $this->db_regional->query("
UPDATE m_user
SET M_UserIsLoggedIn = 'N', M_UserActiveToken = null
WHERE M_UserID = ?",
array($this->sys_user['M_UserID']));
if (!$query)
{
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$this->db_log->query("INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGOUT', 'SUCCESS', $this->sys_user['M_UserUsername']));
$this->sys_ok("OK");
}
catch(Exception $exc)
{
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}
?>

View File

@@ -0,0 +1,133 @@
<?php
class MY_Controller extends CI_Controller {
var $db_regional;
var $sys_user;
var $sys_input;
var $isLogin;
var $one_salt = '545';
var $SECRET_KEY = "--one_api-secret-2019-04-01";
var $group_lab = "1";
var $lang_default_code = "ID";
public function broadcast($prm){
file_get_contents('http://127.0.0.1:9090/broadcast/' . $prm);
}
public function __construct()
{
parent::__construct();
//for preflight
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
//for disable cached
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
global $_SERVER;
if (isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "OPTIONS") {
exit;
}
$this->sys_user = array(
"isExists" => false,
"user" => array(
"userName" => "",
"userLogin" => "",
"userID" => 0
)
);
error_reporting(0);
$this->sys_input = json_decode($this->input->raw_input_stream,true);
if (! $this->sys_input ) {
if ( count($this->input->post()) > 0 ) {
$this->sys_input = $this->input->post();
} else {
$this->sys_input = $this->input->get();
}
}
$this->load->library("Jwt");
try {
$prm = $this->sys_input;
if (! isset($prm["token"])) {
$this->isLogin = false;
} else {
$user = JWT::decode($prm["token"],$this->SECRET_KEY,true);
unset($this->sys_input["token"]);
$user = json_decode(json_encode($user),true);
if ($user["M_UserID"] > 0 ) {
$this->isLogin = true;
}
$this->sys_user = $user;
$this->db_regional = $this->load->database("regional", true);
$query = $this->db_regional->query("update m_user SET M_UserLastAccess = now() WHERE M_UserID = ?",array($user["M_UserID"]));
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
//update last accessed
}
} catch(Exception $e) {
$this->isLogin = false;
}
$this->load->database();
}
public function sys_debug() {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
public function sys_error_db($message,$db = false) {
if (! $db ) {
echo json_encode(
array(
"status" => "ERR",
"message" => $message,
"query" => $this->db->last_query(),
"db_error" => $this->db->error()
)
);
} else {
echo json_encode(
array(
"status" => "ERR",
"message" => $message,
"query" => $db->last_query(),
"db_error" => $db->error()
)
);
}
}
public function sys_error($message) {
echo json_encode(
array(
"status" => "ERR",
"message" => $message
)
);
}
public function sys_ok($data) {
echo json_encode(
array(
"status" => "OK",
"data" => $data
)
);
}
public function clean_mysqli_connection( $dbc )
{
while( mysqli_more_results($dbc) )
{
if(mysqli_next_result($dbc))
{
$result = mysqli_use_result($dbc);
unset($result);
}
}
}
}
?>

View File

@@ -0,0 +1,26 @@
<?php
class Plan extends X_base
{
public function __construct()
{
parent::__construct();
}
function search() {
$param = $this->sys_input;
$pending = $param["pending"];
$priority = $param["priority"];
$status = $param["status"];
}
public function create()
{
$param = $this->sys_input;
}
public function close()
{
}
public function close_promise()
{
}
}

View File

@@ -0,0 +1,74 @@
<?php
class Summary extends MY_Base
{
public function __construct()
{
parent::__construct();
}
public function index()
{
if (!$this->isLogin) {
$this->response["message"] = "Invalid Token";
$this->reply();
}
$userID = $this->sys_user["M_UserID"];
// plan
$sql = "select
sum(if(Mm_PlanIsAddHoc = 'Y', 1,0)) addHoc,
sum(if(Mm_PlanMm_StatusID = 1, 1,0)) pending,
count(*) total
from mm_plan
where Mm_PlanIsActive = 'Y'
and Mm_PlanM_UserID=?";
$res = $this->get_one_row($sql, array($userID));
$plan_addHoc = 0;
$plan_pending = 0;
$plan_total = 0;
if ($res["status"] == $this->XBASE_QRY_ERROR) {
$this->response["message"] = "Get MmPlan : " . $res["message"];
$this->reply();
}
$row = $res["row"];
$plan_addHoc = intVal($row["addHoc"]);
$plan_pending = intVal($row["pending"]);
$plan_total = intVal($row["total"]);
//promise
$sql = "select
sum(if(Mm_PromiseIsFullfilled = 'Y', 1,0)) fullfilled,
sum(if(Mm_PromiseIsFullfilled = 'N', 1,0)) pending,
count(*) total
from mm_promise
join mm_plan on Mm_PromiseMm_PlanID = Mm_PlanID
where Mm_PromiseIsActive = 'Y'
and Mm_PlanM_UserID=?";
$res = $this->get_one_row($sql, array($userID));
$promise_pending = 0;
$promise_fullfilled = 0;
$promise_total = 0;
if ($res["status"] == $this->XBASE_QRY_ERROR) {
$this->response["message"] = "Get Promise : " . $res["message"];
$this->reply();
}
$promise_fullfilled = intVal($row["fullfilled"]);
$promise_pending = intVal($row["pending"]);
$promise_total = intVal($row["total"]);
$this->response["status"] = "OK";
$this->response["data"] = array(
"plan" => array(
"pending" => $plan_pending,
"addHoc" => $plan_addHoc,
"total" => $plan_total
),
"promise" => array(
"pending" => $promise_pending,
"fullfilled" => $promise_fullfilled,
"total" => $promise_total
)
);
$this->reply();
}
}

View File

@@ -0,0 +1,72 @@
<?php
class X_base extends MY_Controller {
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database('regional', true);
$this->response = array("status" => "ERR");
$this->XBASE_QRY_ERROR = -1;
$this->XBASE_QRY_NO_RESULT = 0;
$this->XBASE_QRY_OK = 1;
}
public function clean_connection()
{
$dbc = $this->db_regional->conn_id;
while( mysqli_more_results($dbc) )
{
if(mysqli_next_result($dbc))
{
$result = mysqli_use_result($dbc);
unset($result);
}
}
}
public function reply()
{
echo json_encode($this->response);
exit;
}
public function exec_query($sql, $param = false)
{
if ($param) {
$qry = $this->db_regional->query($sql, $param);
} else {
$qry = $this->db_regional->query($sql);
}
if (!$qry) {
return array(
"status" => $this->XBASE_QRY_ERROR,
"message" => $this->db_regional->error()["msg"] . "\n" . $this->db_regional->last_query()
);
}
return array(
"status" => $this->XBASE_QRY_OK,
"messge" => "", "query" => $qry
);
}
function get_one_row($sql, $param = false)
{
$res = $this->exec_query($sql, $param);
if ($res["status"] == $this->XBASE_QRY_ERROR) {
return $res;
}
$rows = $res["query"]->result_array();
if (count($rows) == 0) {
return array("status" => $this->XBASE_QRY_NO_RESULT, "row" => []);
}
return array("status" => $this->XBASE_QRY_OK, "row" => $rows[0]);
}
function get_rows($sql,$param=false) {
$res = $this->exec_query($sql,$param);
if( $res["status"] == $this->XBASE_QRY_ERROR) {
return $res;
}
$rows = $res["query"]->result_array();
return array("status" => $this->XBASE_QRY_OK, "rows" => $rows);
}
}

View File

@@ -0,0 +1,10 @@
#!/usr/bin/fish
set cmd $argv[1]
set regional $argv[2]
if test "$cmd" = "ul"
rsync -avzr --progress . regional@$regional:/home/regional/project/regional/one-api/application/controllers/mobile_marketing/
end
if test "$cmd" = "ul-xbase"
rsync -avzr --progress X_base.php regional@$regional:/home/regional/project/regional/one-api/application/core/
end

View File

@@ -0,0 +1,19 @@
-- status
drop table if exists mm_status;
-- mm_type
drop table if exists mm_type;
-- tag
drop table if exists mm_tag;
-- priority
drop table if exists mm_priority;
-- plan
drop table if exists mm_plan;
drop table if exists mm_plan_tag ;
-- promise
drop table if exists mm_promise;

View File

@@ -0,0 +1,2 @@
curl -d '{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjUyNSIsIk1fVXNlclVzZXJuYW1lIjoiZXZpdGEiLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvcmVwb3J0XC9vbmUtcmVwb3J0LXY3XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJFVklUQSBPS1RBVklBIiwiTV9Vc2VyR3JvdXBJRCI6IjciLCJNX1N0YWZmTklLIjoiMTIuMTcwMi4yMjU0IiwiaXAiOiIxMTguOTkuMTE4LjEzNyIsImFnZW50IjoiY3VybFwvNy43NC4wIn0.b0Zo7ohaDJCqZHj1LYbos5JDr8IYw2cCVHikYceOXLk" }' \
http://devbandungraya.aplikasi.web.id/one-api/mobile_marketing/sumary

View File

@@ -0,0 +1,40 @@
Login
paul
risa
evita
curl -d '{"username":"evita", "password":"xx123"}' http://devbandungraya.aplikasi.web.id/one-api/mobile_marketing/auth/
{
"data" : {
"token" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjUyNSIsIk1fVXNlclVzZXJuYW1lIjoiZXZpdGEiLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvcmVwb3J0XC9vbmUtcmVwb3J0LXY3XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJFVklUQSBPS1RBVklBIiwiTV9Vc2VyR3JvdXBJRCI6IjciLCJNX1N0YWZmTklLIjoiMTIuMTcwMi4yMjU0IiwiaXAiOiIxMTguOTkuMTE4LjEzNyIsImFnZW50IjoiY3VybFwvNy43NC4wIn0.b0Zo7ohaDJCqZHj1LYbos5JDr8IYw2cCVHikYceOXLk",
"user" : {
"M_StaffNIK" : "12.1702.2254",
"M_StaffName" : "EVITA OKTAVIA",
"M_UserDefaultT_SampleStationID" : "0",
"M_UserGroupDashboard" : "one-ui/report/one-report-v7/",
"M_UserGroupID" : "7",
"M_UserID" : "525",
"M_UserUsername" : "evita",
"agent" : "curl/7.74.0",
"ip" : "118.99.118.137"
}
},
"status" : "OK"
}
curl -d '{"token" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjUyNSIsIk1fVXNlclVzZXJuYW1lIjoiZXZpdGEiLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvcmVwb3J0XC9vbmUtcmVwb3J0LXY3XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJFVklUQSBPS1RBVklBIiwiTV9Vc2VyR3JvdXBJRCI6IjciLCJNX1N0YWZmTklLIjoiMTIuMTcwMi4yMjU0IiwiaXAiOiIxMTguOTkuMTE4LjEzNyIsImFnZW50IjoiY3VybFwvNy43NC4wIn0.b0Zo7ohaDJCqZHj1LYbos5JDr8IYw2cCVHikYceOXLk"}' http://devbandungraya.aplikasi.web.id/one-api/v1/system/auth/islogin
{
"data" : {
"user" : {
"M_StaffName" : null,
"M_UserDefaultT_SampleStationID" : "0",
"M_UserGroupDashboard" : "one-ui/report/one-report-v7/",
"M_UserGroupID" : "7",
"M_UserID" : "525",
"M_UserUsername" : "evita",
"agent" : "curl/7.74.0",
"ip" : "182.253.151.204"
}
},
"status" : "OK"
}

View File

@@ -0,0 +1,117 @@
-- status
drop table if exists mkt_status;
create table mkt_status (
Mkt_StatusID int not null auto_increment primary key,
Mkt_StatusName varchar(50),
Mkt_StatusIsActive varchar(1) default 'Y',
Mkt_StatusCreated datetime default current_timestamp(),
Mkt_StatusLastUpdated datetime default current_timestamp() on update current_timestamp(),
key (Mkt_StatusIsActive),
key (Mkt_StatusName)
);
insert into mkt_status(Mkt_StatusName)
values ('Plan'), ('Re-Schedule'), ('Cancel') , ('Done') ;
-- mkt_type
drop table if exists mkt_type;
create table mkt_type (
Mkt_TypeID int not null auto_increment primary key,
Mkt_TypeName varchar(50),
Mkt_TypeIsActive varchar(1) default 'Y',
Mkt_TypeCreated datetime default current_timestamp(),
Mkt_TypeLastUpdated datetime default current_timestamp() on update current_timestamp(),
key (Mkt_TypeIsActive),
key (Mkt_TypeName)
);
insert into mkt_type(Mkt_TypeName)
values ('Visit'), ('Phone'), ('Video Call') , ('Other');
-- tag
drop table if exists mkt_tag;
create table mkt_tag (
Mkt_TagID int not null auto_increment primary key,
Mkt_TagName varchar(50),
Mkt_TagIsActive varchar(1) default 'Y',
Mkt_TagCreated datetime default current_timestamp(),
Mkt_TagLastUpdated datetime default current_timestamp() on update current_timestamp(),
key (Mkt_TagIsActive),
key (Mkt_TagName)
);
insert into mkt_tag(Mkt_TagName)
values ('Routine'),
('Marketing Plan A');
-- priority
drop table if exists mkt_priority;
create table mkt_priority (
Mkt_PriorityID int not null auto_increment primary key,
Mkt_PriorityName varchar(50),
Mkt_PriorityIsActive varchar(1) default 'Y',
Mkt_PriorityCreated datetime default current_timestamp(),
Mkt_PriorityLastUpdated datetime default current_timestamp() on update current_timestamp(),
key (Mkt_PriorityIsActive),
key (Mkt_PriorityName)
);
insert into mkt_priority(Mkt_PriorityName)
values ('Low'),
('Normal'),
('High');
-- plan
drop table if exists mkt_plan;
create table mkt_plan(
Mkt_PlanID int not null auto_increment primary key,
Mkt_PlanMkt_PriorityID int ,
Mkt_PlanM_DoctorID int,
Mkt_PlanDate datetime,
Mkt_PlanM_UserID int,
Mkt_PlanActionDate datetime,
Mkt_PlanIsAddHoc varchar(1) default 'N',
Mkt_PlanMkt_TypeID int default 1,
Mkt_PlanMkt_StatusID int default 1,
Mkt_PlanTitle varchar(50),
Mkt_PlanDescription varchar(300),
Mkt_PlanIsChildren varchar(1) default 'N',
Mkt_PlanParentID int default 0,
Mkt_PlanHasPromise varchar(1) default 'N',
Mkt_PlanConclusion varchar(300),
Mkt_PlanIsActive varchar(1) default 'Y',
Mkt_PlanCreated datetime default current_timestamp(),
Mkt_PlanLastUpdated datetime default current_timestamp() on update current_timestamp(),
key(Mkt_PlanM_DoctorID),
key(Mkt_PlanIsAddHoc),
key(Mkt_PlanM_UserID),
key(Mkt_PlanDate),
key(Mkt_PlanActionDate),
key(Mkt_PlanMkt_TypeID),
key(Mkt_PlanIsActive),
key(Mkt_PlanCreated),
key(Mkt_PlanLastUpdated),
key(Mkt_PlanMkt_PriorityID)
);
drop table if exists mkt_plan_tag ;
create table mkt_plan_tag (
Mkt_PlanTagID int not null auto_increment primary key,
Mkt_PlanTagMkt_PlanID int,
Mkt_PlanTagMkt_TagID int,
Mkt_PlanIsActive varchar(1) default 'Y',
key(Mkt_PlanTagMkt_PlanID),
key(Mkt_PlanTagMkt_TagID)
);
-- promise
drop table if exists mkt_promise;
create table mkt_promise (
Mkt_PromiseID int not null auto_increment primary key,
Mkt_PromiseMkt_PlanID int,
Mkt_PromiseDate datetime,
Mkt_PromiseTitle varchar(50),
Mkt_PromiseDescription varchar(300),
Mkt_PromiseIsFullfilled varchar(1) default 'N',
Mkt_PromiseIsActive varchar(1) default 'Y',
key(Mkt_PromiseDate),
key(Mkt_PromiseIsFullfilled),
key(Mkt_PromiseIsActive)
);