mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
42 lines
1.0 KiB
PHP
42 lines
1.0 KiB
PHP
<?php
|
|
|
|
|
|
if (!function_exists('setLog')) {
|
|
function setLog($level, $event, $user_id = 0)
|
|
{
|
|
$activity_model = new \App\Models\Sistema\ActivityModel();
|
|
$request = \Config\Services::request();
|
|
$ip = $request->getIPAddress();
|
|
$agent = $request->getUserAgent();
|
|
|
|
$currentAgent = identifyAgent($agent);
|
|
|
|
$activity_model->save([
|
|
'user_id' => $user_id,
|
|
'level' => $level,
|
|
'event' => $event,
|
|
'ip' => $ip,
|
|
'os' => $agent->getPlatform(),
|
|
'browser' => $currentAgent,
|
|
'detail' => $agent
|
|
]);
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('identifyAgent')) {
|
|
function identifyAgent($agent)
|
|
{
|
|
if ($agent->isBrowser()) {
|
|
return $agent->getBrowser() . ' ' . $agent->getVersion();
|
|
}
|
|
if ($agent->isRobot()) {
|
|
return $agent->getRobot();
|
|
}
|
|
if ($agent->isMobile()) {
|
|
return $agent->getMobile();
|
|
}
|
|
return 'Unidentified User Agent';
|
|
}
|
|
}
|