mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Revisados formularios de crear y editar, con su validacion
This commit is contained in:
@ -66,10 +66,12 @@ class CatalogoLibros extends BaseResourceController
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, true);
|
||||
|
||||
$sanitizedData['user_created_id'] = auth()->user()->id;
|
||||
unset($sanitizedData['isk']);
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()):
|
||||
|
||||
|
||||
if ($this->canValidate()):
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
|
||||
@ -84,6 +86,7 @@ class CatalogoLibros extends BaseResourceController
|
||||
|
||||
$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();
|
||||
@ -105,10 +108,9 @@ class CatalogoLibros extends BaseResourceController
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['catalogoLibrosEntity'] = isset($sanitizedData) ? new CatalogoLibroEntity($sanitizedData) : new CatalogoLibroEntity();
|
||||
$this->viewData['formAction'] = route_to('createPais');
|
||||
$this->viewData['formAction'] = route_to('CatalogoLibrosAdd');
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Catalogo.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__);
|
||||
} // end function add()
|
||||
|
||||
@ -126,21 +128,15 @@ class CatalogoLibros extends BaseResourceController
|
||||
return $this->redirect2listView('sweet-error', $message);
|
||||
endif;
|
||||
|
||||
|
||||
|
||||
if ($this->request->getPost()):
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
if ($this->request->getPost('show_erp') == null) {
|
||||
$sanitizedData['show_erp'] = false;
|
||||
}
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, true);
|
||||
unset($sanitizedData['isk']);
|
||||
$sanitizedData['user_update_id'] = auth()->user()->id;
|
||||
|
||||
$noException = true;
|
||||
|
||||
if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
@ -158,9 +154,9 @@ class CatalogoLibros extends BaseResourceController
|
||||
endif;
|
||||
|
||||
$catalogoLibrosEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = false;
|
||||
endif;
|
||||
|
||||
if ($noException && $successfulResult):
|
||||
$id = $catalogoLibrosEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
|
||||
@ -178,15 +174,9 @@ class CatalogoLibros extends BaseResourceController
|
||||
endif; // $noException && $successfulResult
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$catalogoLibrosEntity->clienteName = model('App\Models\Clientes\ClienteModel')->find($catalogoLibrosEntity->cliente_id)->nombre;
|
||||
$catalogoLibrosEntity->encuadernacionName = model('App\Models\Configuracion\TipoPresupuestoModel')->find($catalogoLibrosEntity->encuadernacion_id)->encuadernacion;
|
||||
$catalogoLibrosEntity->createdUser = model('App\Models\Usuarios\UserModel')->getFullName($catalogoLibrosEntity->user_created_id);
|
||||
$catalogoLibrosEntity->updatedUser = model('App\Models\Usuarios\UserModel')->getFullName($catalogoLibrosEntity->user_update_id);
|
||||
|
||||
|
||||
$this->viewData['catalogoLibrosEntity'] = $catalogoLibrosEntity;
|
||||
|
||||
$this->viewData['formAction'] = route_to('CatalogoLibrosEdit', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Catalogo.moduleTitle') . ' ' . lang('Basic.global.edit3');
|
||||
|
||||
|
||||
@ -235,77 +225,6 @@ class CatalogoLibros extends BaseResourceController
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public function menuItems2()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
$query = $this->model->builder()->select(
|
||||
[
|
||||
"id",
|
||||
"nombre as name"
|
||||
]
|
||||
)->orderBy("nombre", "asc");
|
||||
if ($this->request->getGet("q")) {
|
||||
$query->groupStart()
|
||||
->orLike("lg_paises.nombre", $this->request->getGet("q"))
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
return $this->response->setJSON($query->get()->getResultObject());
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* IMN */
|
||||
public function getClientList()
|
||||
@ -316,92 +235,5 @@ class CatalogoLibros extends BaseResourceController
|
||||
|
||||
}
|
||||
|
||||
public function get_files()
|
||||
{
|
||||
|
||||
// Check if the request is a POST request
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
|
||||
$presupuesto_id = $this->request->getPost()['presupuesto_id'] ?? 0;
|
||||
|
||||
$model = model('App\Models\Presupuestos\PresupuestoFicheroModel');
|
||||
$files = $model->getFiles($presupuesto_id);
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
||||
$size = filesize($file->file_path);
|
||||
$splitPath = explode("presupuestos/", $file->file_path);
|
||||
|
||||
// se crea un objeto con el nombre del fichero y el tamaño
|
||||
$obj = (object) array(
|
||||
'name' => $file->nombre,
|
||||
'size' => $size,
|
||||
'hash' => $splitPath[1] ?? $file->file_path
|
||||
);
|
||||
|
||||
|
||||
// se añade el objeto al array
|
||||
array_push($result, $obj);
|
||||
}
|
||||
|
||||
return json_encode($result);
|
||||
}
|
||||
}
|
||||
|
||||
public function upload_files()
|
||||
{
|
||||
|
||||
$model = model('App\Models\Presupuestos\PresupuestoFicheroModel');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
|
||||
$presupuesto_id = $_POST['presupuesto_id'];
|
||||
$old_files = json_decode($_POST['oldFiles']);
|
||||
$ftp = new SafekatFtpClient();
|
||||
|
||||
// Comprobar si se han subido archivos
|
||||
if (!empty($_FILES['file']) || !empty($old_files)) {
|
||||
|
||||
|
||||
// Borrar los archivos existentes del presupuesto
|
||||
$ftp->removeFiles($presupuesto_id);
|
||||
$model->deleteFiles($presupuesto_id, $old_files);
|
||||
|
||||
if (!empty($_FILES['file'])) {
|
||||
$files = $_FILES['file'];
|
||||
|
||||
// Iterar sobre los archivos
|
||||
for ($i = 0; $i < count($files['name']); $i++) {
|
||||
// Aquí puedes acceder a las propiedades del archivo
|
||||
$name = $files['name'][$i];
|
||||
$extension = explode('.', $files['name'][$i])[1];
|
||||
$tmp_name = $files['tmp_name'][$i];
|
||||
|
||||
$new_name = $model->saveFileInBBDD($presupuesto_id, $name, $extension, auth()->id());
|
||||
|
||||
// Se sube el fichero
|
||||
// Pero primero se comprueba que la carpeta presupuestos exista
|
||||
if (!is_dir(WRITEPATH . 'uploads/presupuestos')) {
|
||||
mkdir(WRITEPATH . 'uploads/presupuestos', 0777, true);
|
||||
}
|
||||
|
||||
if (!is_null($new_name)) {
|
||||
$path = WRITEPATH . 'uploads/presupuestos/' . $new_name;
|
||||
move_uploaded_file($tmp_name, $path);
|
||||
}
|
||||
}
|
||||
$ftp->uploadFilePresupuesto($presupuesto_id);
|
||||
}
|
||||
} else {
|
||||
// Borrar los archivos existentes del presupuesto
|
||||
$ftp->removeFiles($presupuesto_id);
|
||||
$model->deleteFiles($presupuesto_id);
|
||||
}
|
||||
}
|
||||
return json_encode(['message' => 'Archivos subidos correctamente']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ class Test extends BaseController
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
private function index()
|
||||
{
|
||||
|
||||
$modelCL = new CatalogoLibroModel();
|
||||
|
||||
Reference in New Issue
Block a user