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:
@ -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');
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user