diff --git a/.idea/safekat.iml b/.idea/safekat.iml index c956989b..91d27d36 100755 --- a/.idea/safekat.iml +++ b/.idea/safekat.iml @@ -1,7 +1,11 @@ - + + + + + diff --git a/ci4/app/Config/Events.php b/ci4/app/Config/Events.php index 4a465ab0..048546da 100755 --- a/ci4/app/Config/Events.php +++ b/ci4/app/Config/Events.php @@ -54,7 +54,6 @@ Events::on('pre_system', static function () { } }); -/* Events::on('login', static function ($user) { helper('logger'); getSystemSettings(); @@ -65,4 +64,3 @@ Events::on('logout', static function ($user) { helper('logger'); setLog('information','user-logout', $user->id); }); -*/ \ No newline at end of file diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 7cc74df8..3f734a5d 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -15,6 +15,18 @@ $routes->get('/', 'Home::index'); $routes->get('lang/{locale}', 'Language::index'); $routes->get('viewmode/(:alpha)', 'Viewmode::index/$1'); + +$routes->group('activity', ['namespace' => 'App\Controllers\Sistema'], function ($routes) { + $routes->get('', 'Actividad::index', ['as' => 'activityList']); + $routes->post('datatable', 'Actividad::datatable', ['as' => 'dataTableOfActividad']); +}); + +$routes->group('settings', ['namespace' => 'App\Controllers\Sistema'], function ($routes) { + $routes->get('', 'Ajustes::settings', ['as' => 'settingsEdit']); + $routes->post('', 'Ajustes::settings', ['as' => 'settingsPost']); +}); + + /* * -------------------------------------------------------------------- * Route Definitions diff --git a/ci4/app/Controllers/BaseController.php b/ci4/app/Controllers/BaseController.php index a6a2478c..f27cea44 100755 --- a/ci4/app/Controllers/BaseController.php +++ b/ci4/app/Controllers/BaseController.php @@ -37,7 +37,7 @@ class BaseController extends Controller * * @var array */ - protected $helpers = ['general','jwt']; + protected $helpers = ['general', 'go_common']; /** * Constructor. @@ -57,24 +57,7 @@ class BaseController extends Controller $language->setLocale($session->lang); // Set TimeZone - if(empty($session->get('settings'))){ - $settingsModel = new SettingsModel(); - $settings = $settingsModel->select('default_timezone')->first()??[]; - date_default_timezone_set($settings['default_timezone']??'America/Sao_Paulo'); - }else{ - date_default_timezone_set($session->get('settings')['default_timezone']??'America/Sao_Paulo'); - } + date_default_timezone_set('Europe/Madrid'); - // Get notification - if(!empty($session->get('token'))) { - $notificationModel = new NotificationModel(); - $pulse = $notificationModel->where('user_recipient',$session->get('token'))->where('is_read',false)->countAllResults() ?? 0; - $notification = $notificationModel->select('token,title,is_read,created_at')->where('user_recipient',$session->get('token'))->orderBy('created_at','desc')->findAll(5) ?? []; - $session->set('notification', $notification); - $session->set('pulse', $pulse); - }else{ - $session->set('notification', []); - $session->set('pulse', 0); - } } } \ No newline at end of file diff --git a/ci4/app/Controllers/GoBaseResourceController.php b/ci4/app/Controllers/BaseResourceController.php old mode 100755 new mode 100644 similarity index 98% rename from ci4/app/Controllers/GoBaseResourceController.php rename to ci4/app/Controllers/BaseResourceController.php index 8b210d98..e7736796 --- a/ci4/app/Controllers/GoBaseResourceController.php +++ b/ci4/app/Controllers/BaseResourceController.php @@ -8,7 +8,7 @@ use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; -abstract class GoBaseResourceController extends \CodeIgniter\RESTful\ResourceController +abstract class BaseResourceController extends \CodeIgniter\RESTful\ResourceController { /** * @@ -48,7 +48,7 @@ abstract class GoBaseResourceController extends \CodeIgniter\RESTful\ResourceCon * * @var string */ - protected static $viewPath; + protected static string $viewPath; /** @@ -85,7 +85,7 @@ abstract class GoBaseResourceController extends \CodeIgniter\RESTful\ResourceCon * * @var array */ - protected $helpers = ['session', 'go_common', 'form', 'text', 'general','jwt']; //JJO + protected $helpers = ['session', 'go_common', 'form', 'text', 'general']; //JJO /** * Initializer method. diff --git a/ci4/app/Controllers/Clientes/Cliente.php b/ci4/app/Controllers/Clientes/Cliente.php index 0d027c33..699186a3 100755 --- a/ci4/app/Controllers/Clientes/Cliente.php +++ b/ci4/app/Controllers/Clientes/Cliente.php @@ -1,7 +1,7 @@ viewData['pageTitle'] = lang('Paises.moduleTitle'); + + // Breadcrumbs + $this->viewData['breadcrumb'] = [ + ['title' => "Home", 'route' => "javascript:void(0);", 'active' => false], + ['title' => lang("App.menu_activity"), 'route' => route_to('activityList'), 'active' => true] + ]; + + + parent::initController($request, $response, $logger); + } + + + public function index() + { + + $viewData = [ + + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Paises.pais')]), + 'activityEntity' => new ActivityEntity(), + 'usingServerSideDataTable' => true, + 'logs' => $this->model->getLogs()->get()->getResultArray()[0] // MEJORAR!!! + + ]; + + $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class + + return view(static::$viewPath . static::$indexRoute, $viewData); + } + + + public function datatable() + { + if ($this->request->isAJAX()) { + $reqData = $this->request->getPost(); + if (!isset($reqData['draw']) || !isset($reqData['columns'])) { + $errstr = 'No data available in response to this specific request.'; + $response = $this->respond(CollectionModel::datatable([], 0, 0, $errstr), 400, $errstr); + return $response; + } + $start = $reqData['start'] ?? 0; + $length = $reqData['length'] ?? 5; + $search = $reqData['search']['value']; + $requestedOrder = $reqData['order']['0']['column'] ?? 1; + $order = ActivityModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1]; + $dir = $reqData['order']['0']['dir'] ?? 'asc'; + + $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + + return $this->respond(CollectionModel::datatable( + $resourceData, + $this->model->getResource()->countAllResults(), + $this->model->getResource($search)->countAllResults() + )); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + +} diff --git a/ci4/app/Controllers/Sistema/Ajustes.php b/ci4/app/Controllers/Sistema/Ajustes.php new file mode 100644 index 00000000..301d796b --- /dev/null +++ b/ci4/app/Controllers/Sistema/Ajustes.php @@ -0,0 +1,100 @@ +viewData['pageTitle'] = lang('Provincias.moduleTitle'); + $this->viewData['usingSweetAlert'] = true; + parent::initController($request, $response, $logger); + } + + + public function settings() + { + + $id = 1; + $settingsEntity = $this->model->find($id); + + if (!$settingsEntity) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Provincias.provincia')), $id]); + return $this->redirect2listView('sweet-error', $message); + endif; + + + if ($this->request->is('post')) : + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, true); + + $noException = true; + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + + if ($this->canValidate()) : + try { + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Provincias.provincia'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $settingsEntity->fill($sanitizedData); + + $thenRedirect = false; + endif; + if ($noException && $successfulResult) : + $id = $settingsEntity->id ?? $id; + $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; + + if ($thenRedirect) : + if (!empty($this->indexRoute)) : + return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); + else: + return $this->redirect2listView('sweet-success', $message); + endif; + else: + $this->session->setFlashData('sweet-success', $message); + endif; + + endif; // $noException && $successfulResult + endif; // ($requestMethod === 'post') + + $this->viewData['settingsEntity'] = $settingsEntity; + $this->viewData['formAction'] = route_to('settingsEdit'); + + $this->viewData['tables'] = db_connect()->listTables(); + + + return $this->displayForm(__METHOD__, $id); + } // end function settings(...) + + + + + +} diff --git a/ci4/app/Controllers/Tarifas/Tarifaacabado.php b/ci4/app/Controllers/Tarifas/Tarifaacabado.php index 09f6e89e..95a7abd8 100755 --- a/ci4/app/Controllers/Tarifas/Tarifaacabado.php +++ b/ci4/app/Controllers/Tarifas/Tarifaacabado.php @@ -1,7 +1,7 @@ null, + "user_id" => null, + "level" => null, + "event" => null, + "ip" => null, + "os" => null, + "browser" => null, + "detail" => null, + "created_at" => null, + "updated_at" => null, + ]; + protected $casts = [ + + ]; +} diff --git a/ci4/app/Entities/Sistema/SettingsEntity.php b/ci4/app/Entities/Sistema/SettingsEntity.php new file mode 100644 index 00000000..0daaba12 --- /dev/null +++ b/ci4/app/Entities/Sistema/SettingsEntity.php @@ -0,0 +1,32 @@ + null, + "email_name" => null, + "email_address" => null, + "email_smtp" => null, + "email_port" => null, + "email_pass" => null, + "email_cert" => null, + "remove_log" => null, + "remove_log_time" => null, + "remove_log_latest" => null, + "storage_gateway" => null, + "backup_storage" => null, + "backup_table" => null, + "backup_email" => null, + "backup_notification_email" => null, + "backup_automatic" => null, + "backup_time" => null, + "backup_latest" => null, + ]; + protected $casts = [ + + ]; +} diff --git a/ci4/app/Helpers/go_common_helper.php b/ci4/app/Helpers/go_common_helper.php index 624017df..b5cf9e3b 100755 --- a/ci4/app/Helpers/go_common_helper.php +++ b/ci4/app/Helpers/go_common_helper.php @@ -165,4 +165,18 @@ if (!function_exists('newUUID')) { return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)); } +} + +if (!function_exists('getSystemSettings')) { + function getSystemSettings() + { + // Get Settings + $session = session(); + $settingsBase = new \App\Models\Sistema\SettingsModel(); + $settings = $settingsBase->first() ?? []; + $session->set('settings', $settings); + if (empty($session->get('lang'))) { + $session->set('lang', 'es'); + } + } } \ No newline at end of file diff --git a/ci4/app/Helpers/logger_helper.php b/ci4/app/Helpers/logger_helper.php new file mode 100644 index 00000000..58883455 --- /dev/null +++ b/ci4/app/Helpers/logger_helper.php @@ -0,0 +1,41 @@ +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'; + } +} diff --git a/ci4/app/Models/CollectionModel.php b/ci4/app/Models/CollectionModel.php new file mode 100644 index 00000000..3b1ceaa3 --- /dev/null +++ b/ci4/app/Models/CollectionModel.php @@ -0,0 +1,39 @@ +getPostGet('data') ?? []; + $draw = $reqData['draw'] ?? $req->getPostGet('draw') ?? 1; + + $response = [ + 'draw' => $draw, + 'recordsTotal' => $recordsTotal, + 'recordsFiltered' => $recordsFiltered, + 'data' => $data, + 'token' => csrf_hash(), // in case the CSRF token is regenerated + ]; + + if (!empty($error)) { + $response['error'] = $error; + } + + return $response; + } +} \ No newline at end of file diff --git a/ci4/app/Models/CountriesModel.php b/ci4/app/Models/CountriesModel.php deleted file mode 100755 index eb4fa043..00000000 --- a/ci4/app/Models/CountriesModel.php +++ /dev/null @@ -1,20 +0,0 @@ - "t1.id", + 2 => "t2.username", + 3 => "t1.level", + 4 => "t1.event", + 5 => "t1.ip", + 6 => "t1.os", + 7 => "t1.browser", + 8 => "t1.detail" + ]; + + protected $allowedFields = [ + 'user_id', + 'level', + 'event', + 'ip', + 'os', + 'browser', + 'detail' + ]; + + protected $useTimestamps = true; + protected $createdField = 'created_at'; + protected $updatedField = 'updated_at'; + + + /** + * Retrieves a resource from the database based on the given search string. + * + * @param string $search The search string to filter the resource by. Defaults to an empty string. + * @return mixed The resource query builder instance if search string is empty, otherwise the filtered resource query builder instance. + */ + public function getResource(string $search = "") + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t2.username AS user, t1.level AS level, t1.event AS event, t1.ip AS ip, t1.os AS os, + t1.browser AS browser, t1.created_at AS created_at" + ) + ->join("users t2", "t1.user_id = t2.id", "left") + ->orderBy('t1.created_at', 'DESC'); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.id", $search) + ->orLike("t2.username", $search) + ->orLike("t1.level", $search) + ->orLike("t1.event", $search) + ->orLike("t1.ip", $search) + ->orLike("t1.os", $search) + ->orLike("t1.browser", $search) + ->orLike("t1.created_at", $search) + ->groupEnd(); + } + + public function getLogs() + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + 'SUM( IF( os LIKE "%Windows%", 1, 0 ) ) AS windows, + SUM( IF( os = "Mac OS X", 1, 0 ) ) AS mac, + SUM( IF( os = "Linux", 1, 0 ) ) AS linux, + SUM( IF( os = "Android", 1, 0 ) ) AS android, + SUM( IF( os = "iOS", 1, 0 ) ) AS iphone, + SUM( IF( browser LIKE "%Chrome%", 1, 0 ) ) AS chrome, + SUM( IF( browser LIKE "%Firefox%", 1, 0 ) ) AS firefox, + SUM( IF( browser LIKE "%Safari%", 1, 0 ) ) AS safari, + SUM( IF( browser LIKE "%Internet Explorer%", 1, 0 ) ) AS ie, + SUM( IF( browser LIKE "%Edge%", 1, 0 ) ) AS edge, + SUM( IF( browser LIKE "%Opera%", 1, 0 ) ) AS opera' + ); + + return $builder; + } + +} \ No newline at end of file diff --git a/ci4/app/Models/Sistema/SettingsModel.php b/ci4/app/Models/Sistema/SettingsModel.php new file mode 100644 index 00000000..32525a23 --- /dev/null +++ b/ci4/app/Models/Sistema/SettingsModel.php @@ -0,0 +1,38 @@ +include("themes/_commonPartialsBs/select2bs5") ?> include("themes/_commonPartialsBs/datatables") ?> -extend('themes/backend/vuexy/main/activities_layout') ?> +extend('themes/vuexy/main/defaultlayout') ?> section('content'); ?> @@ -137,31 +137,25 @@

- get('dashboard')=='admin') : ?> -
- " class="btn btn-primary float-md-right"> - - -
-
- - - +
- +
- - - - - - - + + + + + + + + + +
@@ -174,48 +168,112 @@ endSection() ?> section('additionalInlineJs') ?> - "use strict"; - $(document).ready(function () { - let dataFormat = [ - { - targets: 1, - render: function ( data, type, row ) { - switch (data) { - case 'error': - return ''; - case 'recovery': - return ''; - case 'throttling': - return ''; - case 'information': - return ''; - default: - return ''+data+''; - } - } - }, - { - targets: 2, - render: function ( data, type, row ) { - switch (data) { - case 'login-authenticate': - return ''; - case 'recovery-password': - return ''; - default: - return data; - } - } - }, - { - targets: 6, - //render: $.fn.dataTable.render.moment('YYYY-MM-DD HH:mm:ss','') + + + const lastColNr = $('#activityTable').find("tr:first th").length - 1; + const actionBtns = function(data) { + return ` +
+ +
+ `; + }; + theTable = $('#activityTable').DataTable({ + processing: true, + serverSide: true, + autoWidth: true, + responsive: true, + scrollX: true, + lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], + pageLength: 10, + lengthChange: true, + "dom": 'lfBrtip', + "buttons": [ + 'copy', 'csv', 'excel', 'print', { + extend: 'pdfHtml5', + orientation: 'landscape', + pageSize: 'A4' } - ]; - let order = [[6, "desc"]]; - let translate = '/themes/focus2/vendor/datatables/locales/.json'; - let button = ["","","",""]; - let columns = [{ data: 'name' },{ data: 'level' },{ data: 'event' },{ data: 'ip' },{ data: 'os' },{ data: 'browser' },{ data: 'created_at' }]; - loadDataTableAjax('table-grid', '', translate, true, true, order, columns,dataFormat, button); + ], + stateSave: true, + order: [[1, 'asc']], + language: { + url: "/themes/vuexy/vendors/libs/datatables-sk/plugins/i18n/es-ES.json" + }, + ajax : $.fn.dataTable.pipeline( { + url: '', + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr] + } + ], + columns : [ + { 'data': 'user' }, + { 'data': 'level' }, + { 'data': 'event' }, + { 'data': 'ip' }, + { 'data': 'os' }, + { 'data': 'browser' }, + { 'data': 'created_at' }, + { 'data': actionBtns } + ] }); + + theTable.on( 'draw.dt', function () { + const boolCols = [7]; + for (let coln of boolCols) { + theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) { + cell.innerHTML = cell.innerHTML == '1' ? '' : ''; + }); + } + }); + + + /*$(document).on('click', '.btn-delete', function(e) { + Swal.fire({ + title: '', + text: '', + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#3085d6', + confirmButtonText: '', + cancelButtonText: '', + cancelButtonColor: '#d33' + }) + .then((result) => { + const dataId = $(this).data('id'); + const row = $(this).closest('tr'); + if (result.value) { + $.ajax({ + url: `/${dataId}`, + method: 'DELETE', + }).done((data, textStatus, jqXHR) => { + Toast.fire({ + icon: 'success', + title: data.msg ?? jqXHR.statusText, + }); + + theTable.clearPipeline(); + theTable.row($(row)).invalidate().draw(); + }).fail((jqXHR, textStatus, errorThrown) => { + Toast.fire({ + icon: 'error', + title: jqXHR.responseJSON.messages.error, + }); + }) + } + }); + });*/ + + + + + + endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/backend/vuexy/form/activity/index_bk.php b/ci4/app/Views/themes/backend/vuexy/form/activity/index_bk.php deleted file mode 100755 index b3625cf5..00000000 --- a/ci4/app/Views/themes/backend/vuexy/form/activity/index_bk.php +++ /dev/null @@ -1,234 +0,0 @@ - -
-
-
-
-
-

- -
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
- get('dashboard')=='admin') : ?> - - -
-
- - - -
- - - - - - - - - - - - -
-
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file