Update besar apk finance
This commit is contained in:
@@ -8,19 +8,17 @@ function log_activity($module, $action, $desc, $status = 'success')
|
||||
|
||||
$ip = $CI->input->ip_address();
|
||||
|
||||
if (!$ip || $ip == '0.0.0.0') {
|
||||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ??
|
||||
$_SERVER['REMOTE_ADDR'] ??
|
||||
'UNKNOWN';
|
||||
}
|
||||
if (!$ip || $ip == '0.0.0.0') {
|
||||
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'UNKNOWN';
|
||||
}
|
||||
|
||||
$CI->db->insert('activity_logs', [
|
||||
'user_id' => $CI->session->userdata('user_id') ?? 0,
|
||||
'module' => strtolower($module),
|
||||
'action' => strtolower($action),
|
||||
'description' => $desc,
|
||||
'description' => substr(strip_tags((string) $desc), 0, 1000),
|
||||
'status' => strtolower($status),
|
||||
'ip_address' => $ip,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,35 @@ defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
* @param string $action => action yang dicek (misal: 'can_view', 'can_export')
|
||||
* @return bool
|
||||
*/
|
||||
function check_permission($key, $action = 'can_view') {
|
||||
$CI =& get_instance();
|
||||
$permissions = $CI->session->userdata('permissions');
|
||||
function is_master_admin_user() {
|
||||
static $resolved = array();
|
||||
$CI =& get_instance();
|
||||
$roleId = (int) $CI->session->userdata('role_id');
|
||||
$roleName = strtolower(trim((string) $CI->session->userdata('role')));
|
||||
|
||||
if ((int) $CI->session->userdata('is_super_admin') === 1) {
|
||||
return true;
|
||||
}
|
||||
// Kompatibilitas untuk session lama sebelum flag super-admin disimpan.
|
||||
if (in_array($roleName, array('admin', 'master admin', 'master admin/admin'), true)) {
|
||||
return true;
|
||||
}
|
||||
if ($roleId < 1 || !isset($CI->db) || !$CI->db->table_exists('roles')) {
|
||||
return false;
|
||||
}
|
||||
if (!array_key_exists($roleId, $resolved)) {
|
||||
$role = $CI->db->select('is_super_admin,is_active')->get_where('roles', array('id' => $roleId))->row();
|
||||
$resolved[$roleId] = $role && (int)$role->is_active === 1 && (int)$role->is_super_admin === 1;
|
||||
}
|
||||
return $resolved[$roleId];
|
||||
}
|
||||
|
||||
function check_permission($key, $action = 'can_view') {
|
||||
$CI =& get_instance();
|
||||
if (is_master_admin_user()) {
|
||||
return true;
|
||||
}
|
||||
$permissions = $CI->session->userdata('permissions');
|
||||
|
||||
if (!$permissions || !is_array($permissions)) {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
function json_response($success, $message, array $data = array(), $httpStatus = 200)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$payload = array_merge(array(
|
||||
'status' => (bool) $success,
|
||||
'message' => (string) $message
|
||||
), $data);
|
||||
|
||||
return $CI->output
|
||||
->set_status_header((int) $httpStatus)
|
||||
->set_content_type('application/json', 'utf-8')
|
||||
->set_output(json_encode($payload));
|
||||
}
|
||||
|
||||
function business_exception_response(Throwable $exception)
|
||||
{
|
||||
$status = $exception instanceof BusinessException ? $exception->getCode() : 500;
|
||||
if ($status < 400 || $status > 599) {
|
||||
$status = 500;
|
||||
}
|
||||
|
||||
if (!($exception instanceof BusinessException)) {
|
||||
log_message('error', get_class($exception) . ': ' . $exception->getMessage());
|
||||
}
|
||||
|
||||
$message = $exception instanceof BusinessException
|
||||
? $exception->getMessage()
|
||||
: 'Terjadi kesalahan saat memproses transaksi.';
|
||||
|
||||
return json_response(false, $message, array(), $status);
|
||||
}
|
||||
Reference in New Issue
Block a user