mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
cambios de legacytables3
This commit is contained in:
227
ci4/app/Controllers/Configuracion/Tipologias.php
Normal file
227
ci4/app/Controllers/Configuracion/Tipologias.php
Normal file
@ -0,0 +1,227 @@
|
||||
<?php namespace App\Controllers\Configuracion;
|
||||
|
||||
|
||||
use App\Entities\Configuracion\TipologiasEntity;
|
||||
|
||||
class Tipologias extends \App\Controllers\GoBaseController {
|
||||
|
||||
use \CodeIgniter\API\ResponseTrait;
|
||||
|
||||
protected static $primaryModelName = 'App\Models\Configuracion\TipologiasLibroModel';
|
||||
|
||||
protected static $singularObjectNameCc = 'tipologiaLibros';
|
||||
protected static $singularObjectName = 'Tipologia Libros';
|
||||
protected static $pluralObjectName = 'Tipologias Libros';
|
||||
protected static $controllerSlug = 'tipologiaslibros';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/configuracion/tipologias/';
|
||||
|
||||
protected $indexRoute = 'tipologiaLibrosList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('TipologiasLibros.moduleTitle');
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
}
|
||||
|
||||
public function index() {
|
||||
|
||||
$this->viewData['usingClientSideDataTable'] = true;
|
||||
|
||||
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('TipologiasLibros.tipologiaLibros')]);
|
||||
parent::index();
|
||||
|
||||
}
|
||||
|
||||
public function add() {
|
||||
|
||||
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
$noException = false;
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
endif;
|
||||
|
||||
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
|
||||
$id = $this->model->db->insertID();
|
||||
|
||||
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros'))]).'.';
|
||||
$message .= anchor(route_to('editTipologiaLibros', $id), lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
|
||||
else:
|
||||
return $this->redirect2listView('successMessage', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->viewData['successMessage'] = $message;
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tipologiasEntity'] = isset($sanitizedData) ? new TipologiasEntity($sanitizedData) : new TipologiasEntity();
|
||||
|
||||
$this->viewData['formAction'] = route_to('createTipologiaLibros');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TipologiasLibros.tipologiaLibros').' '.lang('Basic.global.addNewSuffix');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__);
|
||||
} // end function add()
|
||||
|
||||
public function edit($requestedId = null) {
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
||||
$tipologiasEntity = $this->model->find($id);
|
||||
|
||||
if ($tipologiasEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros')), $id]);
|
||||
return $this->redirect2listView('errorMessage', $message);
|
||||
endif;
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
|
||||
$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('TipologiasLibros.tipologiaLibros'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$tipologiasEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $tipologiasEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros'))]).'.';
|
||||
$message .= anchor(route_to('editTipologiaLibros', $id), lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
|
||||
else:
|
||||
return $this->redirect2listView('successMessage', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->viewData['successMessage'] = $message;
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tipologiasEntity'] = $tipologiasEntity;
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateTipologiaLibros', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TipologiasLibros.tipologiaLibros').' '.lang('Basic.global.edit3');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
} // end function edit(...)
|
||||
|
||||
|
||||
|
||||
public function allItemsSelect() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$onlyActiveOnes = true;
|
||||
$reqVal = $this->request->getPost('val') ?? 'id';
|
||||
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function menuItems() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
|
||||
$reqId = goSanitize($this->request->getPost('id'))[0];
|
||||
$reqText = goSanitize($this->request->getPost('text'))[0];
|
||||
$onlyActiveOnes = false;
|
||||
$columns2select = [$reqId ?? 'id', $reqText ?? 'nombre'];
|
||||
$onlyActiveOnes = false;
|
||||
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->text = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -137,11 +137,6 @@ abstract class GoBaseController extends Controller {
|
||||
//--------------------------------------------------------------------
|
||||
// E.g.:
|
||||
$this->session = \Config\Services::session();
|
||||
|
||||
// Language Validate
|
||||
$language = \Config\Services::language();
|
||||
$language->setLocale($this->session->lang);
|
||||
$this->viewData['currentLocale'] = $this->request->getLocale();
|
||||
|
||||
|
||||
if ((!isset($this->viewData['pageTitle']) || empty($this->viewData['pageTitle']) ) && isset(static::$pluralObjectName) && !empty(static::$pluralObjectName)) {
|
||||
@ -174,7 +169,10 @@ abstract class GoBaseController extends Controller {
|
||||
|
||||
// Preload any models, libraries, etc, here.
|
||||
|
||||
|
||||
|
||||
// Language Validate
|
||||
$language = \Config\Services::language();
|
||||
$language->setLocale($this->session->lang);
|
||||
|
||||
// Set TimeZone
|
||||
if(empty($this->session->get('settings'))){
|
||||
@ -196,7 +194,8 @@ abstract class GoBaseController extends Controller {
|
||||
$this->session->set('notification', []);
|
||||
$this->session->set('pulse', 0);
|
||||
}
|
||||
|
||||
|
||||
$this->viewData['currentLocale'] = $this->request->getLocale();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ class Home extends BaseController
|
||||
else
|
||||
$salutation = lang("App.dashboard_good_night");
|
||||
|
||||
echo view(getenv('theme.path').'main/all_selects');
|
||||
echo view(getenv('theme.path').'main/all');
|
||||
|
||||
/*
|
||||
//echo view(getenv('theme.path').'main/header');
|
||||
|
||||
@ -131,23 +131,23 @@ class Integration extends BaseController
|
||||
|
||||
foreach (keywordEmail()??[] as $item){
|
||||
$field = str_replace(['[','user_',']'],'',$item);
|
||||
$template = str_replace('['.$item.']',$user->$field ?? "",$template);
|
||||
$template = str_replace('['.$item.']',$user[$field],$template);
|
||||
}
|
||||
|
||||
$token = random_string("alnum", 50);
|
||||
$url = base_url().'login/recovery/'.$token;
|
||||
$url = base_url().'/login/recovery/'.$token;
|
||||
|
||||
$this->pass_recovery_model->save([
|
||||
'user' => $user->token,
|
||||
'user' => $user['token'],
|
||||
'token' => $token
|
||||
]);
|
||||
|
||||
$title = $template['subject']??'';
|
||||
$msg = $template['body']??'';
|
||||
$msg = str_replace('[recovery_password]',$url,$msg);
|
||||
$email = $user->email;
|
||||
$email = $user['email'];
|
||||
|
||||
$this->setLog('recovery','recovery-password',$user->token);
|
||||
$this->setLog('recovery','recovery-password',$user['token']);
|
||||
$send = $this->sendMail($title,$msg,$email);
|
||||
if($send){
|
||||
$session->setFlashdata('toast', ['success',lang("App.login_alert_send"),lang("App.login_alert_send_pass")]);
|
||||
|
||||
@ -72,6 +72,7 @@ class login extends BaseController
|
||||
|
||||
public function authenticate()
|
||||
{
|
||||
|
||||
$session = session();
|
||||
$settings = $session->get('settings');
|
||||
|
||||
@ -185,6 +186,7 @@ class login extends BaseController
|
||||
if(!$login->status){
|
||||
$session->setFlashdata('toast', ['error',lang("App.login_alert"),lang("App.login_alert_disabled_access")]);
|
||||
return redirect()->to('/login');
|
||||
|
||||
}
|
||||
|
||||
// Get access rules
|
||||
@ -194,29 +196,44 @@ class login extends BaseController
|
||||
->where('token_user',$login->token)->findAll();
|
||||
|
||||
if (sizeof($groups)>1){
|
||||
|
||||
$rules = $this->group_model->select('rules')->where('token',$groups[0])->first()->rules;
|
||||
$rules = json_decode(html_entity_decode($rules), true);
|
||||
if($rules==null){
|
||||
// group doesn't exists now -> then delete from group-user
|
||||
$groups = $this->group_user_model
|
||||
->where('token_group',$groups[0])
|
||||
->delete();
|
||||
}
|
||||
for ($i=1; $i<sizeof($groups); $i++){
|
||||
$temp_rules = $this->group_model->select('rules')->where('token',$groups[$i])->first()->rules;
|
||||
foreach ($rules as $key => $value){
|
||||
if (array_key_exists($key, json_decode(html_entity_decode($temp_rules), true))){
|
||||
$value2 = json_decode(html_entity_decode($temp_rules), true)[$key];
|
||||
$rules[$key] = array_unique(array_merge($value, $value2));
|
||||
$temp_rules = $this->group_model->select('rules')->where('token',$groups[$i])->first();
|
||||
if($temp_rules==null){
|
||||
// group doesn't exists now -> then delete from group-user
|
||||
$groups = $this->group_user_model
|
||||
->where('token_group',$groups[$i])
|
||||
->delete();
|
||||
}
|
||||
else{
|
||||
$temp_rules=$temp_rules->rules;
|
||||
foreach ($rules as $key => $value){
|
||||
if (array_key_exists($key, json_decode(html_entity_decode($temp_rules), true))){
|
||||
$value2 = json_decode(html_entity_decode($temp_rules), true)[$key];
|
||||
$rules[$key] = array_unique(array_merge($value, $value2));
|
||||
}
|
||||
else{
|
||||
$rules[$key]= $value;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$rules[$key]= $value;
|
||||
}
|
||||
}
|
||||
foreach (json_decode(html_entity_decode($temp_rules), true) as $key2 => $value2){
|
||||
if (!array_key_exists($key2, $rules)){
|
||||
$rules[$key2] = $value2;
|
||||
foreach (json_decode(html_entity_decode($temp_rules), true) as $key2 => $value2){
|
||||
if (!array_key_exists($key2, $rules)){
|
||||
$rules[$key2] = $value2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$rules = $this->group_model->select('rules')->where('token',$groups[0])->first();
|
||||
$rules = json_decode($this->group_model->select('rules')->where('token',$groups[0])->first()->rules);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -509,7 +526,6 @@ class login extends BaseController
|
||||
$session = session();
|
||||
if(!empty($token) && $session->get('settings')['forgot_password']??false){
|
||||
$pass_recovery = $this->pass_recovery_model->where('token',$token)->where('changed',false)->first();
|
||||
|
||||
if($pass_recovery != null){
|
||||
$data['token'] = $token;
|
||||
$data['user'] = $pass_recovery['user'];
|
||||
@ -552,7 +568,7 @@ class login extends BaseController
|
||||
if($user != null){
|
||||
$phpass = new PasswordHash(8, true);
|
||||
$this->user_model->save([
|
||||
'id_user' => $user->id_user,
|
||||
'id_user' => $user['id_user'],
|
||||
'password' => $phpass->HashPassword($listPost['password'])
|
||||
]);
|
||||
$this->pass_recovery_model->save([
|
||||
|
||||
@ -30,14 +30,13 @@ class Tarifaacabado extends \App\Controllers\GoBaseController {
|
||||
$this->viewData['usingClientSideDataTable'] = true;
|
||||
|
||||
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Tarifaacabado.tarifaacabado')]);
|
||||
|
||||
parent::index();
|
||||
|
||||
}
|
||||
|
||||
public function add() {
|
||||
|
||||
|
||||
$session = session();
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
@ -46,8 +45,9 @@ class Tarifaacabado extends \App\Controllers\GoBaseController {
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
$sanitizedData['user_created_id'] = $session->id_user;
|
||||
$sanitizedData['user_update_id'] = $session->id_user;
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
@ -100,6 +100,8 @@ class Tarifaacabado extends \App\Controllers\GoBaseController {
|
||||
} // end function add()
|
||||
|
||||
public function edit($requestedId = null) {
|
||||
|
||||
$session = session();
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
@ -119,9 +121,9 @@ class Tarifaacabado extends \App\Controllers\GoBaseController {
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$sanitizedData['user_update_id'] = $session->id_user;
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
@ -223,5 +225,80 @@ class Tarifaacabado extends \App\Controllers\GoBaseController {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($requestedId, bool $deletePermanently = false) {
|
||||
|
||||
if (is_string($requestedId)) :
|
||||
if (is_numeric($requestedId)) :
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_NUMBER_INT);
|
||||
else:
|
||||
$onlyAlphaNumeric = true;
|
||||
$fromGetRequest = true;
|
||||
$idSanitization = goSanitize($requestedId, $onlyAlphaNumeric, $fromGetRequest); // filter_var(trim($requestedId), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$id = $idSanitization[0];
|
||||
endif;
|
||||
else:
|
||||
$id = intval($requestedId);
|
||||
endif;
|
||||
|
||||
if (empty($id) || $id === 0) :
|
||||
$error = 'Invalid identifier provided to delete the object.';
|
||||
endif;
|
||||
|
||||
$rawResult = null;
|
||||
|
||||
if (!isset($error)) :
|
||||
try {
|
||||
if ($deletePermanently) :
|
||||
if (is_numeric($id)) :
|
||||
$rawResult = $this->primaryModel->delete($id);
|
||||
else:
|
||||
$rawResult = $this->primaryModel->where($this->primaryModel->getPrimaryKeyName(), $id)->delete();
|
||||
endif;
|
||||
else:
|
||||
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
||||
$rawResult = $this->primaryModel->where('id',$id)
|
||||
->set(['deleted_at' => $datetime->format('Y-m-d H:i:s')])
|
||||
->update();
|
||||
endif;
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', "Exception: Error deleting object named '".(static::$singularObjectName ?? 'unknown')."' with $id :\r\n".$e->getMessage());
|
||||
}
|
||||
endif;
|
||||
|
||||
$ar = $this->primaryModel->db->affectedRows();
|
||||
|
||||
try {
|
||||
$dbError = $this->primaryModel->db->error();
|
||||
} catch (\Exception $e2) {
|
||||
if ($e2->getMessage() != "Trying to get property 'errno' of non-object") {
|
||||
log_message('error', $e2->getCode() . ' : ' . $e2->getMessage()) ;
|
||||
}
|
||||
}
|
||||
if (isset($dbError['code']) && isset($dbError['message'])) {
|
||||
log_message('error', $dbError['code'].' '.$dbError['message']);
|
||||
} else {
|
||||
$dbError = ['code' => '', 'message'=>''];
|
||||
}
|
||||
|
||||
$result = ['persisted'=>$ar>0, 'ar'=>$ar, 'persistedId'=>null, 'affectedRows'=>$ar, 'errorCode'=>$dbError['code'], 'error'=>$dbError['message']];
|
||||
|
||||
$nameOfDeletedObject = static::$singularObjectNameCc;
|
||||
|
||||
if ($ar < 1) :
|
||||
$errorMessage = lang('Basic.global.deleteError', [$nameOfDeletedObject]); // 'No ' . static::$singularObjectName . ' was deleted now, because it probably had already been deleted.';
|
||||
$fdKey = isset($this->viewData['usingSweetAlert'] ) && $this->viewData['usingSweetAlert'] ? 'sweet-error' : 'errorMessage';
|
||||
$errorMessage = str_replace("'", "\'", $errorMessage);
|
||||
return $this->redirect2listView($fdKey, str_replace("'", '', $errorMessage));
|
||||
else:
|
||||
$message = lang('Basic.global.deleteSuccess', [$nameOfDeletedObject]); // 'The ' . static::$singularObjectName . ' was successfully deleted.';
|
||||
$fdKey = isset($this->viewData['usingSweetAlert'] ) && $this->viewData['usingSweetAlert'] ? 'sweet-success' : 'successMessage';
|
||||
if ($result['affectedRows']>1) :
|
||||
log_message('warning', "More than one row has been deleted in attempt to delete row for object named '".(static::$singularObjectName ?? 'unknown')."' with id: $id");
|
||||
endif;
|
||||
$message = str_replace("'", "\'", $message);
|
||||
return $this->redirect2listView($fdKey, $message);
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,35 +1,227 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Tarifas;
|
||||
use App\Controllers\BaseController;
|
||||
<?php namespace App\Controllers\Tarifas;
|
||||
|
||||
|
||||
class Tarifamanipulado extends BaseController
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
use App\Entities\Tarifas\TarifamanipuladoEntity;
|
||||
|
||||
class Tarifamanipulado extends \App\Controllers\GoBaseController {
|
||||
|
||||
use \CodeIgniter\API\ResponseTrait;
|
||||
|
||||
protected static $primaryModelName = 'App\Models\Tarifas\TarifamanipuladoModel';
|
||||
|
||||
protected static $singularObjectNameCc = 'tarifamanipulado';
|
||||
protected static $singularObjectName = 'Tarifamanipulado';
|
||||
protected static $pluralObjectName = 'Tarifasmanipulado';
|
||||
protected static $controllerSlug = 'tarifamanipulado';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/tarifas/manipulado/';
|
||||
|
||||
protected $indexRoute = 'tarifamanipuladoList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('Tarifamanipulado.moduleTitle');
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
}
|
||||
|
||||
public function index() {
|
||||
|
||||
$this->viewData['usingClientSideDataTable'] = true;
|
||||
|
||||
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Tarifamanipulado.tarifamanipulado')]);
|
||||
parent::index();
|
||||
|
||||
}
|
||||
|
||||
public function add() {
|
||||
|
||||
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
$noException = false;
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
endif;
|
||||
|
||||
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
|
||||
$id = $this->model->db->insertID();
|
||||
|
||||
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado'))]).'.';
|
||||
$message .= anchor(route_to('editTarifamanipulado', $id), lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
|
||||
else:
|
||||
return $this->redirect2listView('successMessage', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->viewData['successMessage'] = $message;
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tarifamanipuladoEntity'] = isset($sanitizedData) ? new TarifamanipuladoEntity($sanitizedData) : new TarifamanipuladoEntity();
|
||||
|
||||
$this->viewData['formAction'] = route_to('createTarifamanipulado');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Tarifamanipulado.tarifamanipulado').' '.lang('Basic.global.addNewSuffix');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__);
|
||||
} // end function add()
|
||||
|
||||
public function edit($requestedId = null) {
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
||||
$tarifamanipuladoEntity = $this->model->find($id);
|
||||
|
||||
if ($tarifamanipuladoEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado')), $id]);
|
||||
return $this->redirect2listView('errorMessage', $message);
|
||||
endif;
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
|
||||
$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('Tarifamanipulado.tarifamanipulado'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$tarifamanipuladoEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $tarifamanipuladoEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado'))]).'.';
|
||||
$message .= anchor(route_to('editTarifamanipulado', $id), lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
|
||||
else:
|
||||
return $this->redirect2listView('successMessage', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->viewData['successMessage'] = $message;
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tarifamanipuladoEntity'] = $tarifamanipuladoEntity;
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateTarifamanipulado', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Tarifamanipulado.tarifamanipulado').' '.lang('Basic.global.edit3');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
} // end function edit(...)
|
||||
|
||||
|
||||
|
||||
public function allItemsSelect() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$onlyActiveOnes = true;
|
||||
$reqVal = $this->request->getPost('val') ?? 'id';
|
||||
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function menuItems() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
|
||||
$reqId = goSanitize($this->request->getPost('id'))[0];
|
||||
$reqText = goSanitize($this->request->getPost('text'))[0];
|
||||
$onlyActiveOnes = false;
|
||||
$columns2select = [$reqId ?? 'id', $reqText ?? 'nombre'];
|
||||
$onlyActiveOnes = false;
|
||||
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->text = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo 'Tarifa manipulado';
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,35 +1,227 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Tarifas;
|
||||
use App\Controllers\BaseController;
|
||||
<?php namespace App\Controllers\Tarifas;
|
||||
|
||||
|
||||
class Tarifapreimpresion extends BaseController
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
use App\Entities\Tarifas\TarifapreimpresionEntity;
|
||||
|
||||
class Tarifapreimpresion extends \App\Controllers\GoBaseController {
|
||||
|
||||
use \CodeIgniter\API\ResponseTrait;
|
||||
|
||||
protected static $primaryModelName = 'App\Models\Tarifas\TarifapreimpresionModel';
|
||||
|
||||
protected static $singularObjectNameCc = 'tarifapreimpresion';
|
||||
protected static $singularObjectName = 'Tarifapreimpresion';
|
||||
protected static $pluralObjectName = 'Tarifaspreimpresion';
|
||||
protected static $controllerSlug = 'tarifapreimpresion';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/tarifas/preimpresion/';
|
||||
|
||||
protected $indexRoute = 'tarifapreimpresionList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('Preimpresions.moduleTitle');
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
}
|
||||
|
||||
public function index() {
|
||||
|
||||
$this->viewData['usingClientSideDataTable'] = true;
|
||||
|
||||
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Preimpresions.tarifapreimpresion')]);
|
||||
parent::index();
|
||||
|
||||
}
|
||||
|
||||
public function add() {
|
||||
|
||||
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
|
||||
} catch (\Exception $e) {
|
||||
$noException = false;
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Preimpresions.tarifapreimpresion'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
endif;
|
||||
|
||||
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
|
||||
$id = $this->model->db->insertID();
|
||||
|
||||
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Preimpresions.tarifapreimpresion'))]).'.';
|
||||
$message .= anchor(route_to('editTarifapreimpresion', $id), lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
|
||||
else:
|
||||
return $this->redirect2listView('successMessage', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->viewData['successMessage'] = $message;
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tarifapreimpresionEntity'] = isset($sanitizedData) ? new TarifapreimpresionEntity($sanitizedData) : new TarifapreimpresionEntity();
|
||||
|
||||
$this->viewData['formAction'] = route_to('createTarifapreimpresion');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Preimpresions.tarifapreimpresion').' '.lang('Basic.global.addNewSuffix');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__);
|
||||
} // end function add()
|
||||
|
||||
public function edit($requestedId = null) {
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
||||
$tarifapreimpresionEntity = $this->model->find($id);
|
||||
|
||||
if ($tarifapreimpresionEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Preimpresions.tarifapreimpresion')), $id]);
|
||||
return $this->redirect2listView('errorMessage', $message);
|
||||
endif;
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
|
||||
$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('Preimpresions.tarifapreimpresion'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$tarifapreimpresionEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $tarifapreimpresionEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Preimpresions.tarifapreimpresion'))]).'.';
|
||||
$message .= anchor(route_to('editTarifapreimpresion', $id), lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
|
||||
else:
|
||||
return $this->redirect2listView('successMessage', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->viewData['successMessage'] = $message;
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['tarifapreimpresionEntity'] = $tarifapreimpresionEntity;
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateTarifapreimpresion', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Preimpresions.tarifapreimpresion').' '.lang('Basic.global.edit3');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
} // end function edit(...)
|
||||
|
||||
|
||||
|
||||
public function allItemsSelect() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$onlyActiveOnes = true;
|
||||
$reqVal = $this->request->getPost('val') ?? 'id';
|
||||
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function menuItems() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
|
||||
$reqId = goSanitize($this->request->getPost('id'))[0];
|
||||
$reqText = goSanitize($this->request->getPost('text'))[0];
|
||||
$onlyActiveOnes = false;
|
||||
$columns2select = [$reqId ?? 'id', $reqText ?? 'nombre'];
|
||||
$onlyActiveOnes = false;
|
||||
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->text = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo 'Tarifa papel impresion';
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
namespace App\Controllers;
|
||||
|
||||
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use App\Models\Usuarios\UserGroupModel;
|
||||
use App\Entities\Usuarios\UserGroupEntity;
|
||||
|
||||
class Test extends BaseController
|
||||
{
|
||||
@ -16,11 +17,122 @@ class Test extends BaseController
|
||||
|
||||
public function index()
|
||||
{
|
||||
helper('general');
|
||||
|
||||
echo lang('Tarifaacabado.tarifaacabado');
|
||||
|
||||
|
||||
|
||||
echo '<pre>';
|
||||
var_dump(getMenuControl());
|
||||
var_dump(json_decode(session()->get('rules')??'[]'));
|
||||
|
||||
echo '</pre>';
|
||||
|
||||
}
|
||||
|
||||
public function validateControllerAccess(){
|
||||
$request = \Config\Services::request();
|
||||
$uri = $uri = new \CodeIgniter\HTTP\URI('https://sk-jjo.imnavajas.es/envioslogistica/logistica');
|
||||
$language = \Config\Services::language();
|
||||
$language->setLocale(session()->lang);
|
||||
|
||||
$getWhiteList = $this->whiteListController();
|
||||
|
||||
foreach ($getWhiteList as $item){
|
||||
if(strtolower($item) == $uri->getSegment(1)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$getRules = json_decode(session()->get('rules')??'[]');
|
||||
|
||||
foreach ($this->whiteListMethod() as $item){
|
||||
if(strtolower($item) == $uri->getSegment(2)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($getRules as $key=>$value){
|
||||
if($key=='Digitalizacion') {
|
||||
echo 'Hola';
|
||||
}
|
||||
if(strtolower($key) == $uri->getSegment(1)){
|
||||
if($uri->getTotalSegments() <= 1){
|
||||
return true;
|
||||
}
|
||||
foreach ($value as $item){
|
||||
if(strtolower($item) == $uri->getSegment(2)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
foreach($this->controllerFolderWhiteList() as $folder){
|
||||
|
||||
if(strtolower($folder) == $uri->getSegment(1)){
|
||||
|
||||
if(strtolower($key) == $uri->getSegment(2)){
|
||||
if($uri->getTotalSegments() <= 2){
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($value as $item){
|
||||
if(strtolower($item) == $uri->getSegment(3)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function whiteListController(){
|
||||
return [
|
||||
'',
|
||||
'BaseController',
|
||||
'Home',
|
||||
'Login',
|
||||
'Oauth',
|
||||
'Language',
|
||||
'Api',
|
||||
'Cron',
|
||||
'lang',
|
||||
'Ajax',
|
||||
'Integration',
|
||||
'Migrate',
|
||||
'Test',
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function whiteListMethod(){
|
||||
return [
|
||||
'initController',
|
||||
'__construct',
|
||||
'validateControllerAccess',
|
||||
'whiteListController',
|
||||
'whiteListMethod'
|
||||
];
|
||||
}
|
||||
|
||||
public function controllerFolderWhiteList(){
|
||||
return [
|
||||
'Catalogo',
|
||||
'Clientes',
|
||||
'Configuracion',
|
||||
'Digitalizacion',
|
||||
'Facturacion',
|
||||
'Informes',
|
||||
'EnviosLogistica',
|
||||
'Pedidos',
|
||||
'Presupuestos',
|
||||
'Produccion',
|
||||
'Proveedores',
|
||||
'Tarifas',
|
||||
'Usuarios',
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,7 @@ class Group extends \App\Controllers\GoBaseController
|
||||
|
||||
static $viewPath = '';
|
||||
|
||||
protected $indexRoute = 'groupList';
|
||||
protected $indexRoute = 'userGroupList';
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('Group.moduleTitle');
|
||||
@ -39,6 +39,7 @@ class Group extends \App\Controllers\GoBaseController
|
||||
|
||||
public function add()
|
||||
{
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
@ -46,10 +47,46 @@ class Group extends \App\Controllers\GoBaseController
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
|
||||
|
||||
$title = $postData['title'];
|
||||
$dashboard = $postData['dashboard'];
|
||||
unset($postData['title']);
|
||||
unset($postData['dashboard']);
|
||||
unset($postData['id_group']);
|
||||
unset($postData['save']);
|
||||
|
||||
$controller = null;
|
||||
$rules_access = null;
|
||||
|
||||
foreach ($postData as $key=>$value){
|
||||
$exp = explode('_',$key);
|
||||
$controller[] = $exp[0];
|
||||
}
|
||||
|
||||
if($controller != null){
|
||||
foreach (array_unique($controller) as $item){
|
||||
$rules_access[$item] = [];
|
||||
|
||||
foreach ($postData as $key=>$value){
|
||||
$exp = explode('_',$key);
|
||||
if($exp[0] == $item){
|
||||
array_push($rules_access[$item],str_replace($exp[0].'_','',$key)) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$temp_data['rules'] = json_encode($rules_access??'{}');
|
||||
$temp_data['token'] = md5(uniqid(rand(), true));;
|
||||
$temp_data['title'] = $title;
|
||||
$temp_data['dashboard'] = $dashboard;
|
||||
|
||||
$sanitizedData = $this->sanitized($temp_data, $nullIfEmpty);
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
@ -91,8 +128,8 @@ class Group extends \App\Controllers\GoBaseController
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['group'] = isset($sanitizedData) ? new UserGroupModel($sanitizedData) : new UserGroupModel();
|
||||
|
||||
$this->viewData['formAction'] = route_to('createUserGroup');
|
||||
|
||||
$this->viewData['formAction'] = route_to('createGroup');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Group.moduleTitle').' '.lang('Basic.global.addNewSuffix');
|
||||
|
||||
@ -100,18 +137,20 @@ class Group extends \App\Controllers\GoBaseController
|
||||
return $this->displayForm(__METHOD__);
|
||||
}
|
||||
|
||||
//public function edit($id)
|
||||
public function edit($requestedId = null)
|
||||
{
|
||||
|
||||
public function edit($requestedId = null) {
|
||||
|
||||
helper('general');
|
||||
$session = session();
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
||||
$group = $this->model->find($id);
|
||||
$groupEntity = $this->model->find($id);
|
||||
|
||||
if ($group == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Paises.pais')), $id]);
|
||||
if ($groupEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Group.userGroup')), $id]);
|
||||
return $this->redirect2listView('errorMessage', $message);
|
||||
endif;
|
||||
|
||||
@ -122,7 +161,44 @@ class Group extends \App\Controllers\GoBaseController
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$id_group = $groupEntity->id_group;
|
||||
$token = $groupEntity->token;
|
||||
$title = $postData['title'];
|
||||
$dashboard = $postData['dashboard'];
|
||||
|
||||
unset($postData['id_group']);
|
||||
unset($postData['title']);
|
||||
unset($postData['dashboard']);
|
||||
|
||||
$controller = null;
|
||||
$rules_access = null;
|
||||
|
||||
foreach ($postData as $key=>$value){
|
||||
$exp = explode('_',$key);
|
||||
$controller[] = $exp[0];
|
||||
}
|
||||
|
||||
if($controller != null){
|
||||
foreach (array_unique($controller) as $item){
|
||||
$rules_access[$item] = [];
|
||||
|
||||
foreach ($postData as $key=>$value){
|
||||
$exp = explode('_',$key);
|
||||
if($exp[0] == $item){
|
||||
array_push($rules_access[$item],str_replace($exp[0].'_','',$key)) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$temp_data['id_group'] = $id_group;
|
||||
$temp_data['rules'] = json_encode($rules_access??'{}');
|
||||
$temp_data['token'] = $token;
|
||||
$temp_data['title'] = $title;
|
||||
$temp_data['dashboard'] = $dashboard;
|
||||
|
||||
$sanitizedData = $this->sanitized($temp_data, $nullIfEmpty);
|
||||
|
||||
|
||||
$noException = true;
|
||||
@ -138,21 +214,24 @@ class Group extends \App\Controllers\GoBaseController
|
||||
$this->dealWithException($e);
|
||||
}
|
||||
else:
|
||||
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Paises.pais'))]);
|
||||
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Group.userGroup'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$group->fill($sanitizedData);
|
||||
$groupEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $group->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Group.group'))]).'.';
|
||||
$id = $groupEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Group.userGroup'))]).'.';
|
||||
$message .= anchor(route_to('editGroup', $id), lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
if($session->get('group') == $this->request->getPost('token')){
|
||||
$session->set('rules', $temp_data['rules']);
|
||||
}
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
|
||||
@ -166,154 +245,63 @@ class Group extends \App\Controllers\GoBaseController
|
||||
endif; // $noException && $successfulResult
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['group'] = $group;
|
||||
$this->viewData['group'] = $groupEntity;
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateGroup', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Paises.pais').' '.lang('Basic.global.edit3');
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Group.userGroup').' '.lang('Basic.global.edit3');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
/*
|
||||
helper('form');
|
||||
} // end function edit(...)
|
||||
|
||||
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.group_edit_title"),
|
||||
'page' => lang("App.group_edit_subtitle"),
|
||||
'icon' => 'fas fa-edit'
|
||||
];
|
||||
public function allItemsSelect() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$onlyActiveOnes = true;
|
||||
$reqVal = $this->request->getPost('val') ?? 'id';
|
||||
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.group_title"), 'route' => "/group", 'active' => false],
|
||||
['title' => lang("App.group_edit_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_return'] = [
|
||||
'title' => lang("App.global_come_back"),
|
||||
'route' => 'usuarios/group',
|
||||
'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['obj'] = $this->group_model->where('token', $id)->first();
|
||||
if($data['obj']==null){
|
||||
return redirect()->to('/usuarios/group');
|
||||
}
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/group/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('/usuarios/group');
|
||||
}
|
||||
|
||||
$session = session();
|
||||
helper('form');
|
||||
|
||||
$rules = [
|
||||
'title' => 'required',
|
||||
'dashboard' => 'required'
|
||||
];
|
||||
$rules_error = [
|
||||
'title' => [
|
||||
'required' => lang("App.group_rules_title_r")
|
||||
],
|
||||
'dashboard' => [
|
||||
'required' => lang("App.group_rules_dashboard_r")
|
||||
],
|
||||
];
|
||||
|
||||
if ($this->validate($rules,$rules_error)){
|
||||
if($listPost = $this->request->getPost()){
|
||||
|
||||
$getChecked = $this->request->getPost();
|
||||
|
||||
unset($getChecked['id_group']);
|
||||
unset($getChecked['title']);
|
||||
unset($getChecked['dashboard']);
|
||||
|
||||
$controller = null;
|
||||
$rules_access = null;
|
||||
|
||||
foreach ($getChecked as $key=>$value){
|
||||
$exp = explode('_',$key);
|
||||
$controller[] = $exp[0];
|
||||
}
|
||||
|
||||
if($controller != null){
|
||||
foreach (array_unique($controller) as $item){
|
||||
$rules_access[$item] = [];
|
||||
|
||||
foreach ($getChecked as $key=>$value){
|
||||
$exp = explode('_',$key);
|
||||
if($exp[0] == $item){
|
||||
array_push($rules_access[$item],str_replace($exp[0].'_','',$key)) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$listPost['rules'] = json_encode($rules_access??'{}');
|
||||
|
||||
if(empty($listPost['id_group'])){
|
||||
$listPost['token'] = md5(uniqid(rand(), true));
|
||||
}
|
||||
|
||||
$this->group_model->save($listPost);
|
||||
|
||||
if(empty($listPost['id_group'])){
|
||||
$session->setFlashdata('sweet', ['success',lang("App.group_alert_add")]);
|
||||
return redirect()->to('/usuarios/group');
|
||||
}else{
|
||||
if($session->get('group') == $this->request->getPost('token')){
|
||||
$session->set('rules', $listPost['rules']);
|
||||
}
|
||||
$session->setFlashdata('sweet', ['success',lang("App.group_alert_edit")]);
|
||||
return redirect()->to('/usuarios/group');
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$session->setFlashdata('error','error');
|
||||
$this->add();
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function menuItems() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
|
||||
$reqId = goSanitize($this->request->getPost('id'))[0];
|
||||
$reqText = goSanitize($this->request->getPost('text'))[0];
|
||||
$onlyActiveOnes = false;
|
||||
$columns2select = [$reqId ?? 'id', $reqText ?? 'nombre'];
|
||||
$onlyActiveOnes = false;
|
||||
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
$nonItem->text = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
//Demo Mode
|
||||
if(env('demo.mode')??false){
|
||||
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
||||
return redirect()->to('/usuarios/group');
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
|
||||
$session = session();
|
||||
if($this->user_model->where('group', $id)->countAllResults() == 0){
|
||||
$this->group_model->where('token', $id)->delete();
|
||||
$session->setFlashdata('sweet', ['success',lang("App.group_alert_delete")]);
|
||||
}else{
|
||||
$session->setFlashdata('sweet', ['error',lang("App.group_alert_error")]);
|
||||
}
|
||||
return redirect()->to('/usuarios/group');
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@ -54,10 +54,8 @@ class Users extends \App\Controllers\GoBaseController {
|
||||
|
||||
}
|
||||
|
||||
public function add() {
|
||||
public function add() {
|
||||
|
||||
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
if ($requestMethod === 'post') :
|
||||
@ -70,6 +68,7 @@ class Users extends \App\Controllers\GoBaseController {
|
||||
$phpass = new PasswordHash(8, true);
|
||||
$postData['password'] = $phpass->HashPassword($this->request->getPost('password'));
|
||||
}
|
||||
|
||||
$currentGroups = $postData['group'];
|
||||
unset($postData['group']);
|
||||
|
||||
@ -163,6 +162,11 @@ class Users extends \App\Controllers\GoBaseController {
|
||||
$currentGroups = $postData['group'];
|
||||
unset($postData['group']);
|
||||
|
||||
if(!empty($postData['password'])){
|
||||
$phpass = new PasswordHash(8, true);
|
||||
$postData['password'] = $phpass->HashPassword($this->request->getPost('password'));
|
||||
}
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
if ($this->request->getPost('tfa') == null ) {
|
||||
$sanitizedData['tfa'] = false;
|
||||
|
||||
Reference in New Issue
Block a user