mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
459 lines
17 KiB
PHP
459 lines
17 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Configuracion;
|
|
|
|
|
|
use App\Controllers\GoBaseResourceController;
|
|
|
|
// DataTables PHP library
|
|
|
|
|
|
// Alias Editor classes so they are easy to use
|
|
use
|
|
DataTables\Editor,
|
|
DataTables\Database,
|
|
DataTables\Editor\Field,
|
|
DataTables\Editor\Format,
|
|
DataTables\Editor\Mjoin,
|
|
DataTables\Editor\Options,
|
|
DataTables\Editor\Upload,
|
|
DataTables\Editor\Validate,
|
|
DataTables\Editor\ValidateOptions;
|
|
|
|
|
|
use App\Models\Collection;
|
|
|
|
|
|
|
|
use App\Entities\Configuracion\PapelImpresion;
|
|
|
|
use App\Models\Configuracion\PapelImpresionModel;
|
|
|
|
use App\Models\Configuracion\PapelGenericoModel;
|
|
|
|
use App\Models\Configuracion\PapelImpresionTipologiaModel;
|
|
|
|
|
|
class Papelesimpresion extends \App\Controllers\GoBaseResourceController
|
|
{
|
|
|
|
protected $modelName = PapelImpresionModel::class;
|
|
protected $format = 'json';
|
|
|
|
protected static $singularObjectName = 'Papel Impresion';
|
|
protected static $singularObjectNameCc = 'papelImpresion';
|
|
protected static $pluralObjectName = 'Papeles Impresion';
|
|
protected static $pluralObjectNameCc = 'papelesImpresion';
|
|
|
|
protected static $controllerSlug = 'papelesimpresion';
|
|
|
|
protected static $viewPath = 'themes/backend/vuexy/form/configuracion/papel/';
|
|
|
|
protected $indexRoute = 'papelImpresionList';
|
|
|
|
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
|
{
|
|
$this->viewData['pageTitle'] = lang('PapelImpresion.moduleTitle');
|
|
$this->viewData['usingSweetAlert'] = true;
|
|
|
|
// Se indica que este controlador trabaja con soft_delete
|
|
$this->soft_delete = true;
|
|
// Se indica el flag para los ficheros borrados
|
|
$this->delete_flag = 1;
|
|
|
|
$this->tpModel = new PapelImpresionTipologiaModel();
|
|
|
|
parent::initController($request, $response, $logger);
|
|
}
|
|
|
|
|
|
public function index()
|
|
{
|
|
|
|
$viewData = [
|
|
'currentModule' => static::$controllerSlug,
|
|
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('PapelImpresion.papelImpresion')]),
|
|
'papelImpresion' => new PapelImpresion(),
|
|
'usingServerSideDataTable' => true,
|
|
|
|
];
|
|
|
|
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
|
|
|
return view(static::$viewPath . 'viewPapelImpresionList', $viewData);
|
|
}
|
|
|
|
|
|
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('PapelImpresion.papelImpresion'))]);
|
|
$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('PapelImpresion.papelImpresion'))]) . '.';
|
|
$message .= anchor("papelesimpresion/{$id}/edit", lang('Basic.global.continueEditing') . '?');
|
|
$message = ucfirst(str_replace("'", "\'", $message));
|
|
|
|
if ($thenRedirect) :
|
|
if (!empty($this->indexRoute)) :
|
|
return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
|
|
else :
|
|
return $this->redirect2listView('sweet-success', $message);
|
|
endif;
|
|
else :
|
|
$this->session->setFlashData('sweet-success', $message);
|
|
endif;
|
|
|
|
endif; // $noException && $successfulResult
|
|
|
|
endif; // ($requestMethod === 'post')
|
|
|
|
$this->viewData['papelImpresion'] = isset($sanitizedData) ? new PapelImpresion($sanitizedData) : new PapelImpresion();
|
|
$this->viewData['papelGenericoList'] = $this->getPapelGenericoListItems($papelImpresion->papel_generico_id ?? null);
|
|
|
|
$this->viewData['formAction'] = route_to('createPapelImpresion');
|
|
|
|
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('PapelImpresion.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
|
|
|
|
|
|
return $this->displayForm(__METHOD__);
|
|
} // end function add()
|
|
|
|
public function edit($requestedId = null)
|
|
{
|
|
// JJO
|
|
$session = session();
|
|
|
|
if ($requestedId == null) :
|
|
return $this->redirect2listView();
|
|
endif;
|
|
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
|
$papelImpresion = $this->model->find($id);
|
|
|
|
if ($papelImpresion == false) :
|
|
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('PapelImpresion.papelImpresion')), $id]);
|
|
return $this->redirect2listView('sweet-error', $message);
|
|
endif;
|
|
|
|
$requestMethod = $this->request->getMethod();
|
|
|
|
if ($requestMethod === 'post') :
|
|
|
|
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
|
|
|
$postData = $this->request->getPost();
|
|
|
|
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
|
|
|
// JJO
|
|
$sanitizedData['user_update_id'] = $session->id_user;
|
|
|
|
|
|
|
|
if ($this->request->getPost('defecto') == null) {
|
|
$sanitizedData['defecto'] = false;
|
|
}
|
|
if ($this->request->getPost('bn') == null) {
|
|
$sanitizedData['bn'] = false;
|
|
}
|
|
if ($this->request->getPost('color') == null) {
|
|
$sanitizedData['color'] = false;
|
|
}
|
|
if ($this->request->getPost('portada') == null) {
|
|
$sanitizedData['portada'] = false;
|
|
}
|
|
if ($this->request->getPost('cubierta') == null) {
|
|
$sanitizedData['cubierta'] = false;
|
|
}
|
|
if ($this->request->getPost('rotativa') == null) {
|
|
$sanitizedData['rotativa'] = false;
|
|
}
|
|
|
|
|
|
|
|
$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('PapelImpresion.papelImpresion'))]);
|
|
$this->session->setFlashdata('formErrors', $this->model->errors());
|
|
|
|
endif;
|
|
|
|
$papelImpresion->fill($sanitizedData);
|
|
|
|
$thenRedirect = true;
|
|
endif;
|
|
if ($noException && $successfulResult) :
|
|
$id = $papelImpresion->id ?? $id;
|
|
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('PapelImpresion.papelImpresion'))]) . '.';
|
|
$message .= anchor("papelesimpresion/{$id}/edit", lang('Basic.global.continueEditing') . '?');
|
|
$message = ucfirst(str_replace("'", "\'", $message));
|
|
|
|
if ($thenRedirect) :
|
|
if (!empty($this->indexRoute)) :
|
|
return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
|
|
else :
|
|
return $this->redirect2listView('sweet-success', $message);
|
|
endif;
|
|
else :
|
|
$this->session->setFlashData('sweet-success', $message);
|
|
endif;
|
|
|
|
endif; // $noException && $successfulResult
|
|
endif; // ($requestMethod === 'post')
|
|
|
|
$this->viewData['papelImpresion'] = $papelImpresion;
|
|
$this->viewData['papelGenericoList'] = $this->getPapelGenericoListItems($papelImpresion->papel_generico_id ?? null);
|
|
|
|
$this->viewData['formAction'] = route_to('updatePapelImpresion', $id);
|
|
|
|
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('PapelImpresion.moduleTitle') . ' ' . lang('Basic.global.edit3');
|
|
|
|
$this->viewData['usingServerSideDataTable'] = true; //JJO
|
|
|
|
return $this->displayForm(__METHOD__, $id);
|
|
} // end function edit(...)
|
|
|
|
|
|
|
|
public function datatable()
|
|
{
|
|
if ($this->request->isAJAX()) {
|
|
|
|
$reqData = $this->request->getPost();
|
|
if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
|
|
$errstr = 'No data available in response to this specific request.';
|
|
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
|
|
return $response;
|
|
}
|
|
|
|
if(isset($reqData['id_PI'])){
|
|
|
|
$id_PI = $reqData['id_PI'] ?? -1;
|
|
|
|
if($id_PI>=0){
|
|
|
|
$data = $this->tpModel->findTipologiasForPapelImpresion($id_PI);
|
|
$resourceData = $data->get()->getResultObject();
|
|
|
|
return $this->respond(Collection::datatable(
|
|
$resourceData,
|
|
$this->tpModel->findTipologiasForPapelImpresion($id_PI)->countAllResults(),
|
|
$this->tpModel->findTipologiasForPapelImpresion($id_PI)->countAllResults()
|
|
));
|
|
}
|
|
}
|
|
else{
|
|
|
|
$id_PG = $reqData['id_PG'] ?? -1;
|
|
$start = $reqData['start'] ?? 0;
|
|
$length = $reqData['length'] ?? 5;
|
|
$search = $reqData['search']['value'];
|
|
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
|
|
$order = PapelImpresionModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
|
|
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
|
|
|
if($id_PG<0){
|
|
|
|
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
|
|
|
return $this->respond(Collection::datatable(
|
|
$resourceData,
|
|
$this->model->getResource()->countAllResults(),
|
|
$this->model->getResource($search)->countAllResults()
|
|
));
|
|
}else{
|
|
$resourceData = $this->model->getResource($search, $id_PG)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
|
|
|
return $this->respond(Collection::datatable(
|
|
$resourceData,
|
|
$this->model->getResource("", $id_PG)->countAllResults(),
|
|
$this->model->getResource($search, $id_PG)->countAllResults()
|
|
));
|
|
}
|
|
}
|
|
} else {
|
|
return $this->failUnauthorized('Invalid request', 403);
|
|
}
|
|
}
|
|
|
|
|
|
public function datatable_editor(){
|
|
/*if ($this->request->isAJAX()) {
|
|
|
|
$reqData = $this->request->getPost();
|
|
$rows_id = array_keys($reqData['data']);
|
|
echo '<pre>' ;
|
|
var_dump($reqData['data'][$keys[0]]) ;
|
|
echo '</pre>';
|
|
}*/
|
|
|
|
if ($this->request->isAJAX()) {
|
|
|
|
$sql_details = array(
|
|
"type" => "Mysql", // Database type: "Mysql", "Postgres", "Sqlserver", "Sqlite" or "Oracle"
|
|
"user" => "sk_jjo", // Database user name
|
|
"pass" => "61tv&G1Zf^XY", // Database password
|
|
"host" => "localhost", // Database host
|
|
"port" => "", // Database connection port (can be left empty for default)
|
|
"db" => "sk_jjo", // Database name
|
|
"dsn" => "", // PHP DSN extra information. Set as `charset=utf8mb4` if you are using MySQL
|
|
"pdoAttr" => array() // PHP PDO attributes array. See the PHP documentation for all options
|
|
);
|
|
|
|
$db = new Database( array(
|
|
"type" => "Mysql",
|
|
"pdo" => $sql_details
|
|
) );
|
|
|
|
|
|
// Build our Editor instance and process the data coming from _POST
|
|
Editor::inst( $db, 'lg_papel_impresion_tipologias' )
|
|
->fields(
|
|
Field::inst( 'tipo' ),
|
|
//->validator( Validate::notEmpty( ValidateOptions::inst()) ),//->validator( Validate::values( array('negro', 'color', 'bicolor') ) ),
|
|
Field::inst( 'negro' ),
|
|
//->validator( Validate::notEmpty( ValidateOptions::inst()) ),
|
|
Field::inst( 'cyan' ),
|
|
//->validator( Validate::notEmpty( ValidateOptions::inst()) ),
|
|
Field::inst( 'magenta' ),
|
|
//->validator( Validate::notEmpty( ValidateOptions::inst()) ),
|
|
Field::inst( 'amarillo' ),
|
|
//->validator( Validate::notEmpty( ValidateOptions::inst()) ),
|
|
Field::inst( 'gota_negro' ),
|
|
//->validator( Validate::notEmpty( ValidateOptions::inst()) ),
|
|
Field::inst( 'got_color' ),
|
|
//->validator( Validate::notEmpty( ValidateOptions::inst()) ),
|
|
)
|
|
->process( $_POST )
|
|
->json();
|
|
}
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
function fetch_single_data()
|
|
{
|
|
if ($this->request->isAJAX()) {
|
|
$reqData = $this->request->getPost();
|
|
if(isset($reqData['id']))
|
|
{
|
|
$newTokenHash = csrf_hash();
|
|
$csrfTokenName = csrf_token();
|
|
|
|
$data = [
|
|
'data' => $this->tpModel->getResource($reqData['id'])->get()->getResultObject()[0],
|
|
$csrfTokenName => $newTokenHash
|
|
];
|
|
echo json_encode($data);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
protected function getPapelGenericoListItems($selId = null)
|
|
{
|
|
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('PapelGenerico.papelGenerico'))])];
|
|
if (!empty($selId)) :
|
|
$papelGenericoModel = model('App\Models\Configuracion\PapelGenericoModel');
|
|
|
|
$selOption = $papelGenericoModel->where('id', $selId)->findColumn('nombre');
|
|
if (!empty($selOption)) :
|
|
$data[$selId] = $selOption[0];
|
|
endif;
|
|
endif;
|
|
return $data;
|
|
}
|
|
}
|