Last active
June 11, 2019 11:40
-
-
Save dyazincahya/ebf0db11a657edd4b26a7939545a41e2 to your computer and use it in GitHub Desktop.
Library record activity for codeigniter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"module":"account", | |
"url":"http:\/\/kang.iseng\/github\/dokumentasi\/account\/action\/security", | |
"condition":"change password", | |
"raw_access":{ | |
"ip_address":"127.0.0.1", | |
"platform":"Windows 10", | |
"agent":"Chrome 57.0.2987.98", | |
"time":"2017-03-19 08:30:10 AM" | |
}, | |
"raw_user":{ | |
"first_name":"K4ng", | |
"last_name":"C4hya", | |
"username":"k4ng", | |
"email":"[email protected]" | |
}, | |
"raw_post":{ | |
"old_password":"123", | |
"new_password":"1", | |
"confirm_password":"1", | |
"submit":"change password" | |
}, | |
"raw_get":[ | |
], | |
"uid":"1" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
/* | |
| | |
| Library for record all activity | |
| K4ng | |
| | |
*/ | |
class Record_activity | |
{ | |
public function run() | |
{ | |
$CI =& get_instance(); | |
$post = $CI->input->post(); | |
$get = $CI->input->get(); | |
$data = array( | |
'module' => check_variable($CI->uri->segment(1), MAIN_CONTROLLER), | |
'url' => get_full_url(), | |
'condition' => $this->_condition($post, $get), | |
'raw_access' => array( | |
'ip_address' => get_ip_address(), | |
'platform' => get_platform(), | |
'agent' => get_agent(), | |
'time' => date('Y-m-d H:i:s A') | |
), | |
'raw_user' => array( | |
'first_name' => data_session('first_name'), | |
'last_name' => data_session('last_name'), | |
'username' => data_session('username'), | |
'email' => data_session('email') | |
), | |
'raw_post' => $post, | |
'raw_get' => $get, | |
'uid' => check_variable(data_session('id'), 0) | |
); | |
$CI->db->insert('sys_log', array( | |
'sl_su_id' => check_variable(data_session('id'), 0), | |
'sl_type' => $this->_activity_type($post, $get), | |
'sl_message' => json_encode($data), | |
'sl_created' => date_timestamp_get(date_create()) | |
)); | |
} | |
function _condition($post, $get) | |
{ | |
if (isset($post['submit'])) { | |
$ret = $post['submit']; | |
} else { | |
if (isset($get['condition'])) { | |
$ret = $get['condition']; | |
} else { | |
$ret = null; | |
} | |
} | |
return $ret; | |
} | |
function _activity_type($post, $get) | |
{ | |
if (isset($post)) { | |
if (count($post) != 0) { | |
$ret = 'LOG'; | |
} else { | |
if (isset($get)) { | |
if (count($get) != 0) { | |
$ret = 'LOG'; | |
} elseif (count($get) == 0) { | |
$ret = 'VISIT'; | |
} else { | |
$ret = 'ERR_TRACK'; | |
} | |
} | |
} | |
} | |
return $ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment