mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Modificando usuarios y roles
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
<?php namespace App\Controllers\Clientes;
|
||||
|
||||
|
||||
use App\Controllers\BaseResourceController;
|
||||
|
||||
use App\Models\Collection;
|
||||
|
||||
@ -9,15 +8,9 @@ use App\Entities\Clientes\ClienteEntity;
|
||||
|
||||
use App\Models\Clientes\ClienteModel;
|
||||
|
||||
use App\Models\Configuracion\ProvinciaModel;
|
||||
|
||||
use App\Models\Configuracion\UserModel;
|
||||
|
||||
use App\Models\Configuracion\ComunidadAutonomaModel;
|
||||
|
||||
use App\Models\Configuracion\FormaPagoModel;
|
||||
|
||||
use App\Models\Configuracion\PaisModel;
|
||||
|
||||
class Cliente extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
@ -79,8 +72,6 @@ class Cliente extends \App\Controllers\BaseResourceController
|
||||
public function add()
|
||||
{
|
||||
|
||||
|
||||
|
||||
if ($this->request->getPost()) :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
<?php namespace App\Controllers\Configuracion;
|
||||
|
||||
use App\Entities\Usuarios\UserGroupEntity;
|
||||
|
||||
use App\Controllers\BaseResourceController;
|
||||
use App\Models\Usuarios\UserGroupModel;
|
||||
use App\Models\Usuarios\GroupUserModel;
|
||||
|
||||
@ -47,8 +45,6 @@ class Group extends \App\Controllers\GoBaseController
|
||||
public function add()
|
||||
{
|
||||
|
||||
|
||||
|
||||
if ($this->request->getPost()) :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
@ -5,9 +5,7 @@ use App\Entities\Usuarios\UserEntity;
|
||||
|
||||
use App\Models\Usuarios\UserGroupModel;
|
||||
use App\Models\Usuarios\GroupUserModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
|
||||
use App\Libraries\PasswordHash;
|
||||
use App\Models\UserModel;
|
||||
|
||||
class Users extends \App\Controllers\GoBaseController {
|
||||
|
||||
@ -18,7 +16,7 @@ class Users extends \App\Controllers\GoBaseController {
|
||||
|
||||
use \CodeIgniter\API\ResponseTrait;
|
||||
|
||||
protected static $primaryModelName = 'App\Models\Usuarios\UserModel';
|
||||
protected static $primaryModelName = 'App\Models\UserModel';
|
||||
|
||||
protected static $singularObjectNameCc = 'user';
|
||||
protected static $singularObjectName = 'User';
|
||||
|
||||
@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\ActivityModel;
|
||||
use App\Models\BackupModel;
|
||||
use App\Models\CronTabModel;
|
||||
use App\Models\NotificationModel;
|
||||
use App\Models\SettingsModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
|
||||
class Cron extends BaseController
|
||||
{
|
||||
private $integration;
|
||||
private $user_model;
|
||||
private $notification_model;
|
||||
private $crontab_model;
|
||||
private $settings_model;
|
||||
private $activity_model;
|
||||
private $backup_model;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->integration = new Integration();
|
||||
$this->user_model = new UserModel();
|
||||
$this->notification_model = new NotificationModel();
|
||||
$this->settings_model = new SettingsModel();
|
||||
$this->crontab_model = new CronTabModel();
|
||||
$this->activity_model = new ActivityModel();
|
||||
$this->backup_model = new BackupModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$settings = $this->settings_model->first()??[];
|
||||
|
||||
// Cron Notification E-mail
|
||||
try {
|
||||
$email_list = $this->notification_model
|
||||
->select('notification.id_notification, recipient.email, notification.title, notification.body')
|
||||
->join('user AS recipient','notification.user_recipient = recipient.token','left')
|
||||
->where('send_email_notification',true)
|
||||
->where('is_send_email',false)
|
||||
->orderBy('notification.id_notification','desc')
|
||||
->findAll(25);
|
||||
foreach ($email_list as $item){
|
||||
if($this->integration->send_email($item['email'],$item['title'],$item['body'])){
|
||||
$this->notification_model->save(['id_notification' => $item['id_notification'],'is_send_email' => true]);
|
||||
}
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
$this->crontab_model->save(['routine'=>'Notification Email','error'=>$e->getMessage()]);
|
||||
}
|
||||
|
||||
// Cron Backup
|
||||
if(date('Y-m-d') > date('Y-m-d',strtotime($settings['backup_latest']))){
|
||||
if(date('H:i:s') >= date('H:i:s',strtotime($settings['backup_time']))){
|
||||
try {
|
||||
$this->settings_model->save([
|
||||
'id_settings' => $settings['id_settings'],
|
||||
'backup_latest' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
$this->integration->create_backup();
|
||||
}catch (\Exception $e){
|
||||
$this->crontab_model->save(['routine'=>'Backup','error'=>$e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cron Log Delete
|
||||
if(date('Y-m-d') >= date('Y-m-d',strtotime(date($settings['remove_log_latest']) . ' +'.$settings['remove_log_time'].' day'))){
|
||||
try {
|
||||
$this->settings_model->save([
|
||||
'id_settings' => $settings['id_settings'],
|
||||
'remove_log_latest' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
$dateStart = date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s') . ' -5 year'));
|
||||
$dateEnd = date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s') . ' -30 day'));
|
||||
$this->crontab_model->where('created_at between "'.$dateStart.'" and "'.$dateEnd.'"')->delete();
|
||||
$this->activity_model->where('created_at between "'.$dateStart.'" and "'.$dateEnd.'"')->delete();
|
||||
$this->backup_model->where('created_at between "'.$dateStart.'" and "'.$dateEnd.'"')->delete();
|
||||
}catch (\Exception $e){
|
||||
$this->crontab_model->save(['routine'=>'Delete Log','error'=>$e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -19,134 +19,7 @@ class Home extends BaseController
|
||||
public function index()
|
||||
{
|
||||
|
||||
$session = session();
|
||||
|
||||
echo view(getenv('theme.path').'main/defaultlayout');
|
||||
|
||||
/*
|
||||
//echo view(getenv('theme.path').'main/header');
|
||||
//echo view(getenv('theme.path').'main/menu');
|
||||
//echo view(getenv('theme.path').'form/dashboard/index');
|
||||
//echo view(getenv('theme.path').'main/footer');
|
||||
|
||||
/*switch ($session->get('dashboard')):
|
||||
case 'admin':
|
||||
$data['title'] = [
|
||||
'module' => lang("App.dashboard_hello").' '.$name,
|
||||
'page' => lang("App.dashboard_indicators"),
|
||||
'icon' => ''
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
//Cards Top
|
||||
$initialDate = date('Y-m-d H:i:s', strtotime('-1 day', time()));
|
||||
$finalDate = date('Y-m-d H:i:s');
|
||||
$data['total_user'] = $this->user_model->countAllResults();
|
||||
$data['total_new'] = $this->user_model->where('created_at between \''.$initialDate.'\' and \''.$finalDate.'\'')->countAllResults();
|
||||
$data['total_enabled'] = $this->user_model->where('status',true)->countAllResults();
|
||||
$data['total_disabled'] = $this->user_model->where('status',false)->countAllResults();
|
||||
|
||||
//Char Bar
|
||||
$titles_char_bar["labels"] = explode(',',lang("App.dashboard_chart_months"));
|
||||
$value_char_bar["series"] = [];
|
||||
$return_char_bar_geral = $this->user_model->select("DATE_FORMAT(created_at,'%m') AS month,COUNT(DATE_FORMAT(created_at,'%m')) AS total")
|
||||
->where("DATE_FORMAT(NOW(),'%Y') = DATE_FORMAT(created_at,'%Y')")
|
||||
->groupBy("DATE_FORMAT(created_at,'%Y-%m')")
|
||||
->findAll();
|
||||
$return_char_bar_enabled = $this->user_model->select("DATE_FORMAT(created_at,'%m') AS month,COUNT(DATE_FORMAT(created_at,'%m')) AS total")
|
||||
->where("DATE_FORMAT(NOW(),'%Y') = DATE_FORMAT(created_at,'%Y') AND status = true")
|
||||
->groupBy("DATE_FORMAT(created_at,'%Y-%m')")
|
||||
->findAll();
|
||||
$return_char_bar_disabled = $this->user_model->select("DATE_FORMAT(updated_at,'%m') AS month,COUNT(DATE_FORMAT(updated_at,'%m')) AS total")
|
||||
->where("DATE_FORMAT(NOW(),'%Y') = DATE_FORMAT(updated_at,'%Y') AND status = false")
|
||||
->groupBy("DATE_FORMAT(updated_at,'%Y-%m')")
|
||||
->findAll();
|
||||
$year = [];
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
$notFound = true;
|
||||
foreach ($return_char_bar_geral as $item){
|
||||
if($i == intval($item->month)){
|
||||
array_push($year,intval($item->total));
|
||||
$notFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($notFound){
|
||||
array_push($year,0);
|
||||
}
|
||||
}
|
||||
array_push($value_char_bar["series"],$year);
|
||||
$year = [];
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
$notFound = true;
|
||||
foreach ($return_char_bar_enabled as $item){
|
||||
if($i == intval($item->month)){
|
||||
array_push($year,intval($item->total));
|
||||
$notFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($notFound){
|
||||
array_push($year,0);
|
||||
}
|
||||
}
|
||||
array_push($value_char_bar["series"],$year);
|
||||
$year = [];
|
||||
for ($i = 1; $i <= 12; $i++) {
|
||||
$notFound = true;
|
||||
foreach ($return_char_bar_disabled as $item){
|
||||
if($i == intval($item->month)){
|
||||
array_push($year,intval($item->total));
|
||||
$notFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($notFound){
|
||||
array_push($year,0);
|
||||
}
|
||||
}
|
||||
array_push($value_char_bar["series"],$year);
|
||||
$data['data_char_bar'] = json_encode(array_merge($titles_char_bar,$value_char_bar));
|
||||
|
||||
$data['data_user'] = $this->user_model->select('picture,first_name,last_name,email,created_at')
|
||||
->orderBy('id_user','DESC')
|
||||
->findAll(15);
|
||||
|
||||
$data['data_activity'] = $this->activity_model
|
||||
->select('auth_user.first_name,auth_user.email,auth_activity.detail,auth_activity.created_at')
|
||||
->join('auth_user','auth_user.token=auth_activity.user')
|
||||
->orderBy('auth_activity.id_activity','DESC')
|
||||
->findAll(30);
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
//echo view(getenv('theme.path').'form/dashboard/admin',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
$data['title'] = [
|
||||
'module' => lang("App.dashboard_hello").' '.$name,
|
||||
'page' => lang("App.dashboard_indicators"),
|
||||
'icon' => ''
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
//echo view(getenv('theme.path').'form/dashboard/user',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
break;
|
||||
default:
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
//echo view(getenv('theme.path').'form/dashboard/index');
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
endswitch;
|
||||
*/
|
||||
echo view(getenv('theme.path') . 'main/defaultlayout');
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
use Throwable;
|
||||
|
||||
class Migrate extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$migrate = \Config\Services::migrations();
|
||||
|
||||
$file = 'Database\\Migrations\\2023-04-25-161753_RemoveGroupFromUser.php';
|
||||
|
||||
try {
|
||||
$migrate->force($file);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,190 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\CountriesModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use App\Models\NotificationModel;
|
||||
|
||||
class Notification extends BaseController
|
||||
{
|
||||
private $user_model;
|
||||
private $countries_model;
|
||||
private $id_user;
|
||||
private $token_user;
|
||||
private $notification_model;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->countries_model = new CountriesModel();
|
||||
$this->id_user = session()->get('id_user');
|
||||
$this->token_user = session()->get('token');
|
||||
$this->notification_model = new NotificationModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = [
|
||||
'module' => lang("App.notification_title"),
|
||||
'page' => lang("App.notification_subtitle"),
|
||||
'icon' => 'fas fa-bell'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.notification_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_add'] = [
|
||||
'title' => lang("App.notification_btn_add"),
|
||||
'route' => '/notification/add',
|
||||
'class' => 'btn btn-lg btn-primary float-md-right',
|
||||
'icon' => 'fas fa-plus'
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/notification/index',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
helper('form');
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.notification_add_title"),
|
||||
'page' => lang("App.notification_add_subtitle"),
|
||||
'icon' => 'far fa-plus-square'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.notification_title"), 'route' => "/user", 'active' => false],
|
||||
['title' => lang("App.notification_add_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_return'] = [
|
||||
'title' => lang("App.global_come_back"),
|
||||
'route' => '/notification',
|
||||
'class' => 'btn btn-dark mr-1',
|
||||
'icon' => 'fas fa-angle-left'
|
||||
];
|
||||
|
||||
$data['btn_submit'] = [
|
||||
'title' => lang("App.global_save"),
|
||||
'route' => '',
|
||||
'class' => 'btn btn-primary mr-1',
|
||||
'icon' => 'fas fa-save'
|
||||
];
|
||||
|
||||
$data['user'] = $this->user_model->where('status',true)->findAll();
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/notification/form',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/notification');
|
||||
}
|
||||
|
||||
$session = session();
|
||||
helper('form');
|
||||
|
||||
$rules = [
|
||||
'title' => 'required',
|
||||
'body' => 'required'
|
||||
];
|
||||
|
||||
$rules_error = [
|
||||
'title' => [
|
||||
'required' => lang("App.notification_rules_title_r"),
|
||||
],
|
||||
'body' => [
|
||||
'required' => lang("App.notification_rules_body_r"),
|
||||
]
|
||||
];
|
||||
|
||||
if ($this->validate($rules,$rules_error)){
|
||||
if($listPost = $this->request->getPost()){
|
||||
|
||||
$listPost['send_email_notification'] = isset($listPost['send_email_notification']) && $listPost['send_email_notification'] == 'on';
|
||||
|
||||
if(!empty($listPost['user_recipient'])){
|
||||
$user = $this->user_model->where('token',$session->get('token'))->first();
|
||||
foreach (keywordEmail()??[] as $item){
|
||||
$field = str_replace(['[','user_',']'],'',$item);
|
||||
$listPost['title'] = str_replace('['.$item.']',$user[$field],$listPost['title']);
|
||||
$listPost['body'] = str_replace('['.$item.']',$user[$field],$listPost['body']);
|
||||
}
|
||||
$listPost['token'] = md5(uniqid(rand(), true));
|
||||
$listPost['user_sender'] = $session->get('token');
|
||||
$this->notification_model->save($listPost);
|
||||
}else{
|
||||
$users = $this->user_model->where('status',true)->findAll();
|
||||
$data = [];
|
||||
foreach ($users as $user){
|
||||
$title = $listPost['title'];
|
||||
$template = $listPost['body'];
|
||||
foreach (keywordEmail()??[] as $item){
|
||||
$field = str_replace(['[','user_',']'],'',$item);
|
||||
$title = str_replace('['.$item.']',$user[$field],$title);
|
||||
$template = str_replace('['.$item.']',$user[$field],$template);
|
||||
}
|
||||
array_push($data,[
|
||||
'id_notification' => null,
|
||||
'user_sender' => $session->get('token'),
|
||||
'user_recipient' => $user['token'],
|
||||
'title' => $title,
|
||||
'body' => $template,
|
||||
'is_read' => false,
|
||||
'is_send_email' => false,
|
||||
'send_email_notification' => $listPost['send_email_notification'],
|
||||
'token' => md5(uniqid(rand(), true)),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
if(count($data)>0){
|
||||
$this->notification_model->insertBatch($data);
|
||||
}
|
||||
}
|
||||
if(empty($this->request->getPost('id_notification'))){
|
||||
$session->setFlashdata('sweet', ['success',lang("App.notification_alert_add")]);
|
||||
return redirect()->to('/notification');
|
||||
}else{
|
||||
$session->setFlashdata('sweet', ['success',lang("App.notification_alert_edit")]);
|
||||
return redirect()->to('/notification');
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('error','error');
|
||||
$this->add();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($token)
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/notification');
|
||||
}
|
||||
|
||||
$session = session();
|
||||
if(!empty($session->get('token'))){
|
||||
$this->notification_model->where('token', $token)->delete();
|
||||
$session->setFlashdata('sweet', ['success',lang("App.notification_alert_delete")]);
|
||||
return redirect()->to('/notification');
|
||||
}else{
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Presupuestos;
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
|
||||
class PresupuestoInterfazCliente extends BaseController
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.settings_title"),
|
||||
'page' => lang("App.settings_subtitle"),
|
||||
'icon' => 'fas fa-sliders-h'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_presupuesto"), 'route' => site_url('presupuesto'), 'active' => true]
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'form/presupuestos/index', $data);
|
||||
}
|
||||
|
||||
public function tapa_blanda_encolada()
|
||||
{
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.settings_title"),
|
||||
'page' => lang("App.settings_subtitle"),
|
||||
'icon' => 'fas fa-sliders-h'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_presupuesto"), 'route' => site_url('presupuesto'), 'active' => false],
|
||||
['title' => lang("App.menu_presupuesto"), 'route' => site_url('presupuesto/tapa_blanda_encolada'), 'active' => true]
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'form/presupuestos/tapa-blanda-encolada', $data);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user