diff --git a/app/modules/web/Controllers/AccessManagerController.php b/app/modules/web/Controllers/AccessManagerController.php index 8f189e59..68d07ca2 100644 --- a/app/modules/web/Controllers/AccessManagerController.php +++ b/app/modules/web/Controllers/AccessManagerController.php @@ -59,7 +59,6 @@ class AccessManagerController extends ControllerBase /** * @throws \SP\Core\Exceptions\InvalidArgumentException - * @throws \SP\Core\Exceptions\InvalidClassException */ public function indexAction() { @@ -70,7 +69,6 @@ class AccessManagerController extends ControllerBase * Returns a tabbed grid with items * * @throws \SP\Core\Exceptions\InvalidArgumentException - * @throws \SP\Core\Exceptions\InvalidClassException */ protected function getGridTabs() { @@ -150,8 +148,6 @@ class AccessManagerController extends ControllerBase /** * Returns public links data tab - * - * @throws \SP\Core\Exceptions\InvalidClassException */ protected function getPublicLinksList() { diff --git a/app/modules/web/Controllers/CategoryController.php b/app/modules/web/Controllers/CategoryController.php new file mode 100644 index 00000000..ccb514de --- /dev/null +++ b/app/modules/web/Controllers/CategoryController.php @@ -0,0 +1,282 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + + +use SP\Controller\ControllerBase; +use SP\Core\Acl\Acl; +use SP\Core\Acl\ActionsInterface; +use SP\Core\Exceptions\SPException; +use SP\Core\Exceptions\ValidationException; +use SP\Core\SessionUtil; +use SP\DataModel\CategoryData; +use SP\Forms\CategoryForm; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Helpers\ItemsGridHelper; +use SP\Modules\Web\Controllers\Traits\ItemTrait; +use SP\Modules\Web\Controllers\Traits\JsonTrait; +use SP\Mvc\Controller\CrudControllerInterface; +use SP\Services\Category\CategoryService; + +/** + * Class CategoryController + * + * @package SP\Modules\Web\Controllers + */ +class CategoryController extends ControllerBase implements CrudControllerInterface +{ + use JsonTrait; + use ItemTrait; + + /** + * @var CategoryService + */ + protected $categoryService; + + /** + * Search action + */ + public function searchAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_SEARCH)) { + return; + } + + $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $grid = $itemsGridHelper->getCategoriesGrid($this->categoryService->search($this->getSearchData($this->configData)))->updatePager(); + + $this->view->addTemplate('datagrid-table', 'grid'); + $this->view->assign('index', Request::analyze('activetab', 0)); + $this->view->assign('data', $grid); + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Create action + * + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function createAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_CREATE)) { + return; + } + + $this->view->assign(__FUNCTION__, 1); + $this->view->assign('header', __('Nueva Categoría')); + $this->view->assign('isView', false); + $this->view->assign('route', 'category/saveCreate'); + + try { + $this->setViewData(); + + $this->eventDispatcher->notifyEvent('show.category.create', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(1, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Sets view data for displaying user's data + * + * @param $categoryId + * @throws \Psr\Container\ContainerExceptionInterface + */ + protected function setViewData($categoryId = null) + { + $this->view->addTemplate('category', 'itemshow'); + + $category = $categoryId ? $this->categoryService->getById($categoryId) : new CategoryData(); + + $this->view->assign('category', $category); + + $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); + + if ($this->view->isView === true) { + $this->view->assign('disabled', 'disabled'); + $this->view->assign('readonly', 'readonly'); + } else { + $this->view->assign('disabled'); + $this->view->assign('readonly'); + } + + $this->view->assign('customFields', $this->getCustomFieldsForItem(ActionsInterface::CATEGORY, $categoryId)); + } + + /** + * Edit action + * + * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function editAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_EDIT)) { + return; + } + + $this->view->assign('header', __('Editar Categoría')); + $this->view->assign('isView', false); + $this->view->assign('route', 'category/saveEdit/' . $id); + + try { + $this->setViewData($id); + + $this->eventDispatcher->notifyEvent('show.category.edit', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Delete action + * + * @param $id + */ + public function deleteAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_DELETE)) { + return; + } + + try { + $this->categoryService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::CATEGORY, $id); + + $this->eventDispatcher->notifyEvent('delete.category', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Categoría eliminada')); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * Saves create action + */ + public function saveCreateAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_CREATE)) { + return; + } + + try { + $form = new CategoryForm(); + $form->validate(ActionsInterface::CATEGORY_CREATE); + + $id = $this->categoryService->create($form->getItemData()); + + $this->addCustomFieldsForItem(ActionsInterface::CATEGORY, $id); + + $this->eventDispatcher->notifyEvent('create.category', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Categoría creada')); + } catch (ValidationException $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * Saves edit action + * + * @param $id + */ + public function saveEditAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_EDIT)) { + return; + } + + try { + $form = new CategoryForm($id); + $form->validate(ActionsInterface::CATEGORY_EDIT); + + $this->categoryService->update($form->getItemData()); + + $this->updateCustomFieldsForItem(ActionsInterface::CATEGORY, $id); + + $this->eventDispatcher->notifyEvent('edit.category', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Categoría actualizada')); + } catch (ValidationException $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * View action + * + * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function viewAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CATEGORY_VIEW)) { + return; + } + + $this->view->assign('header', __('Ver Categoría')); + $this->view->assign('isView', true); + + try { + $this->setViewData($id); + + $this->eventDispatcher->notifyEvent('show.category', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Initialize class + */ + protected function initialize() + { + $this->checkLoggedIn(); + + $this->categoryService = new CategoryService(); + } + +} \ No newline at end of file diff --git a/app/modules/web/Controllers/ClientController.php b/app/modules/web/Controllers/ClientController.php new file mode 100644 index 00000000..c18c31cf --- /dev/null +++ b/app/modules/web/Controllers/ClientController.php @@ -0,0 +1,278 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + + +use SP\Controller\ControllerBase; +use SP\Core\Acl\Acl; +use SP\Core\Acl\ActionsInterface; +use SP\Core\Exceptions\SPException; +use SP\Core\Exceptions\ValidationException; +use SP\Core\SessionUtil; +use SP\DataModel\ClientData; +use SP\Forms\ClientForm; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Helpers\ItemsGridHelper; +use SP\Modules\Web\Controllers\Traits\ItemTrait; +use SP\Modules\Web\Controllers\Traits\JsonTrait; +use SP\Mvc\Controller\CrudControllerInterface; +use SP\Services\Client\ClientService; + +/** + * Class ClientController + * + * @package SP\Modules\Web\Controllers + */ +class ClientController extends ControllerBase implements CrudControllerInterface +{ + use JsonTrait; + use ItemTrait; + + /** + * @var ClientService + */ + protected $clientService; + + /** + * Search action + */ + public function searchAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_SEARCH)) { + return; + } + + $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $grid = $itemsGridHelper->getClientsGrid($this->clientService->search($this->getSearchData($this->configData)))->updatePager(); + + $this->view->addTemplate('datagrid-table', 'grid'); + $this->view->assign('index', Request::analyze('activetab', 0)); + $this->view->assign('data', $grid); + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Create action + * + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function createAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_CREATE)) { + return; + } + + $this->view->assign(__FUNCTION__, 1); + $this->view->assign('header', __('Nuevo Cliente')); + $this->view->assign('isView', false); + $this->view->assign('route', 'client/saveCreate'); + + try { + $this->setViewData(); + + $this->eventDispatcher->notifyEvent('show.client.create', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(1, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Sets view data for displaying user's data + * + * @param $clientId + * @throws \Psr\Container\ContainerExceptionInterface + */ + protected function setViewData($clientId = null) + { + $this->view->addTemplate('client', 'itemshow'); + + $client = $clientId ? $this->clientService->getById($clientId) : new ClientData(); + + $this->view->assign('client', $client); + + $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); + + if ($this->view->isView === true) { + $this->view->assign('disabled', 'disabled'); + $this->view->assign('readonly', 'readonly'); + } else { + $this->view->assign('disabled'); + $this->view->assign('readonly'); + } + + $this->view->assign('customFields', $this->getCustomFieldsForItem(ActionsInterface::CLIENT, $clientId)); + } + + /** + * Edit action + * + * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function editAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_EDIT)) { + return; + } + + $this->view->assign('header', __('Editar Cliente')); + $this->view->assign('isView', false); + $this->view->assign('route', 'client/saveEdit/' . $id); + + try { + $this->setViewData($id); + + $this->eventDispatcher->notifyEvent('show.client.edit', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Delete action + * + * @param $id + */ + public function deleteAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_DELETE)) { + return; + } + + try { + $this->clientService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::CLIENT, $id); + + $this->eventDispatcher->notifyEvent('delete.client', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Cliente eliminado')); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * Saves create action + */ + public function saveCreateAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_CREATE)) { + return; + } + + try { + $form = new ClientForm(); + $form->validate(ActionsInterface::CLIENT_CREATE); + + $this->clientService->create($form->getItemData()); + + $this->eventDispatcher->notifyEvent('create.client', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Cliente creado')); + } catch (ValidationException $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * Saves edit action + * + * @param $id + */ + public function saveEditAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_EDIT)) { + return; + } + + try { + $form = new ClientForm($id); + $form->validate(ActionsInterface::CLIENT_EDIT); + + $this->clientService->update($form->getItemData()); + + $this->eventDispatcher->notifyEvent('edit.client', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Cliente actualizado')); + } catch (ValidationException $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * View action + * + * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function viewAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CLIENT_VIEW)) { + return; + } + + $this->view->assign('header', __('Ver Cliente')); + $this->view->assign('isView', true); + + try { + $this->setViewData($id); + + $this->eventDispatcher->notifyEvent('show.client', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Initialize class + */ + protected function initialize() + { + $this->checkLoggedIn(); + + $this->clientService = new ClientService(); + } + +} \ No newline at end of file diff --git a/app/modules/web/Controllers/CustomFieldController.php b/app/modules/web/Controllers/CustomFieldController.php new file mode 100644 index 00000000..7b2b5f0f --- /dev/null +++ b/app/modules/web/Controllers/CustomFieldController.php @@ -0,0 +1,281 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + + +use SP\Controller\ControllerBase; +use SP\Core\Acl\Acl; +use SP\Core\Acl\ActionsInterface; +use SP\Core\Exceptions\SPException; +use SP\Core\Exceptions\ValidationException; +use SP\Core\SessionUtil; +use SP\DataModel\CustomFieldDefData; +use SP\Forms\CustomFieldDefForm; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Helpers\ItemsGridHelper; +use SP\Modules\Web\Controllers\Traits\ItemTrait; +use SP\Modules\Web\Controllers\Traits\JsonTrait; +use SP\Mvc\Controller\CrudControllerInterface; +use SP\Services\CustomField\CustomFieldDefService; +use SP\Services\CustomField\CustomFieldTypeService; + +/** + * Class CustomFieldController + * + * @package SP\Modules\Web\Controllers + */ +class CustomFieldController extends ControllerBase implements CrudControllerInterface +{ + use JsonTrait; + use ItemTrait; + + /** + * @var CustomFieldDefService + */ + protected $customFieldService; + + /** + * Search action + */ + public function searchAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_SEARCH)) { + return; + } + + $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $grid = $itemsGridHelper->getCustomFieldsGrid($this->customFieldService->search($this->getSearchData($this->configData)))->updatePager(); + + $this->view->addTemplate('datagrid-table', 'grid'); + $this->view->assign('index', Request::analyze('activetab', 0)); + $this->view->assign('data', $grid); + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Create action + * + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function createAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_CREATE)) { + return; + } + + $this->view->assign(__FUNCTION__, 1); + $this->view->assign('header', __('Nuevo Campo')); + $this->view->assign('isView', false); + $this->view->assign('route', 'customField/saveCreate'); + + try { + $this->setViewData(); + + $this->eventDispatcher->notifyEvent('show.customField.create', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(1, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Sets view data for displaying user's data + * + * @param $clientId + * @throws \Psr\Container\ContainerExceptionInterface + */ + protected function setViewData($clientId = null) + { + $this->view->addTemplate('customfield', 'itemshow'); + + $customField = $clientId ? $this->customFieldService->getById($clientId) : new CustomFieldDefData(); + + $customFieldTypeService = new CustomFieldTypeService(); + + $this->view->assign('field', $customField); + $this->view->assign('types', $customFieldTypeService->getAll()); + $this->view->assign('modules', CustomFieldDefService::getFieldModules()); + + $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); + + if ($this->view->isView === true) { + $this->view->assign('disabled', 'disabled'); + $this->view->assign('readonly', 'readonly'); + } else { + $this->view->assign('disabled'); + $this->view->assign('readonly'); + } + } + + /** + * Edit action + * + * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function editAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_EDIT)) { + return; + } + + $this->view->assign('header', __('Editar Campo')); + $this->view->assign('isView', false); + $this->view->assign('route', 'customField/saveEdit/' . $id); + + try { + $this->setViewData($id); + + $this->eventDispatcher->notifyEvent('show.customField.edit', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Delete action + * + * @param $id + */ + public function deleteAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_DELETE)) { + return; + } + + try { + $this->customFieldService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::CUSTOMFIELD, $id); + + $this->eventDispatcher->notifyEvent('delete.customField', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campo eliminado')); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * Saves create action + */ + public function saveCreateAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_CREATE)) { + return; + } + + try { + $form = new CustomFieldDefForm(); + $form->validate(ActionsInterface::CUSTOMFIELD_CREATE); + + $this->customFieldService->create($form->getItemData()); + + $this->eventDispatcher->notifyEvent('create.customField', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campo creado')); + } catch (ValidationException $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * Saves edit action + * + * @param $id + */ + public function saveEditAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_EDIT)) { + return; + } + + try { + $form = new CustomFieldDefForm($id); + $form->validate(ActionsInterface::CUSTOMFIELD_EDIT); + + $this->customFieldService->update($form->getItemData()); + + $this->eventDispatcher->notifyEvent('edit.customField', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Campo actualizado')); + } catch (ValidationException $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * View action + * + * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function viewAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::CUSTOMFIELD_VIEW)) { + return; + } + + $this->view->assign('header', __('Ver Campo')); + $this->view->assign('isView', true); + + try { + $this->setViewData($id); + + $this->eventDispatcher->notifyEvent('show.customField', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Initialize class + */ + protected function initialize() + { + $this->checkLoggedIn(); + + $this->customFieldService = new CustomFieldDefService(); + } + +} \ No newline at end of file diff --git a/app/modules/web/Controllers/Helpers/AccountHelper.php b/app/modules/web/Controllers/Helpers/AccountHelper.php index 205df418..c99c4ac4 100644 --- a/app/modules/web/Controllers/Helpers/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/AccountHelper.php @@ -41,8 +41,10 @@ use SP\Mgmt\Groups\GroupAccountsUtil; use SP\Mgmt\Tags\Tag; use SP\Mgmt\Users\UserPass; use SP\Mgmt\Users\UserUtil; +use SP\Modules\Web\Controllers\Traits\ItemTrait; use SP\Services\Account\AccountHistoryService; use SP\Services\Account\AccountService; +use SP\Services\CustomField\CustomFieldService; use SP\Services\PublicLink\PublicLinkService; use SP\Util\ErrorUtil; use SP\Util\Json; @@ -54,6 +56,8 @@ use SP\Util\Json; */ class AccountHelper extends HelperBase { + use ItemTrait; + /** @var Acl */ protected $acl; /** @@ -148,8 +152,6 @@ class AccountHelper extends HelperBase { $userProfileData = $this->session->getUserProfile(); - $this->getCustomFieldsForItem(); - if ($this->isGotData()) { $accountHistoryService = new AccountHistoryService(); @@ -181,6 +183,7 @@ class AccountHelper extends HelperBase } + $this->view->assign('customFields', $this->getCustomFieldsForItem(ActionsInterface::ACCOUNT, $this->accountId)); $this->view->assign('actionId', Acl::getActionRoute($this->actionId)); $this->view->assign('categories', Category::getItem()->getItemsForSelect()); $this->view->assign('customers', Customer::getItem()->getItemsForSelectByUser()); @@ -208,14 +211,6 @@ class AccountHelper extends HelperBase $this->view->assign('actions', $this->getActions()); } - /** - * Obtener la lista de campos personalizados y sus valores - */ - private function getCustomFieldsForItem() - { - $this->view->assign('customFields', CustomField::getItem(new CustomFieldData(ActionsInterface::ACCOUNT))->getById($this->accountId)); - } - /** * Set icons for view */ diff --git a/app/modules/web/Controllers/Helpers/ItemsGridHelper.php b/app/modules/web/Controllers/Helpers/ItemsGridHelper.php index 8bb7eb8b..8199694b 100644 --- a/app/modules/web/Controllers/Helpers/ItemsGridHelper.php +++ b/app/modules/web/Controllers/Helpers/ItemsGridHelper.php @@ -37,6 +37,7 @@ use SP\Html\DataGrid\DataGridData; use SP\Html\DataGrid\DataGridHeader; use SP\Html\DataGrid\DataGridPager; use SP\Html\DataGrid\DataGridTab; +use SP\Services\CustomField\CustomFieldDefService; /** * Class Grids con las plantillas de tablas de datos @@ -174,12 +175,16 @@ class ItemsGridHelper extends HelperBase $GridHeaders = new DataGridHeader(); $GridHeaders->addHeader(__('Nombre')); $GridHeaders->addHeader(__('Descripción')); + $GridHeaders->addHeader(__('Global')); // Grid Data $GridData = new DataGridData(); $GridData->setDataRowSourceId('customer_id'); $GridData->addDataRowSource('customer_name'); $GridData->addDataRowSource('customer_description'); + $GridData->addDataRowSource('customer_isGlobal', false, function ($value) { + return $value ? __u('SI') : __u('NO'); + }); $GridData->setData($data); // Grid @@ -224,7 +229,7 @@ class ItemsGridHelper extends HelperBase $GridActionEdit->setTitle(__('Editar Cliente')); $GridActionEdit->setIcon($this->icons->getIconEdit()); $GridActionEdit->setOnClickFunction('appMgmt/show'); - $GridActionEdit->addData('action-route', Acl::getActionRoute(ActionsInterface::CLIENT_VIEW)); + $GridActionEdit->addData('action-route', Acl::getActionRoute(ActionsInterface::CLIENT_EDIT)); $Grid->setDataActions($GridActionEdit); @@ -251,15 +256,17 @@ class ItemsGridHelper extends HelperBase { // Grid Header $GridHeaders = new DataGridHeader(); - $GridHeaders->addHeader(__('Módulo')); $GridHeaders->addHeader(__('Nombre')); + $GridHeaders->addHeader(__('Módulo')); $GridHeaders->addHeader(__('Tipo')); // Grid Data $GridData = new DataGridData(); $GridData->setDataRowSourceId('id'); - $GridData->addDataRowSource('moduleName'); $GridData->addDataRowSource('name'); + $GridData->addDataRowSource('moduleId', false, function ($value) { + return CustomFieldDefService::getFieldModuleById($value); + }); $GridData->addDataRowSource('typeName'); $GridData->setData($data); @@ -340,12 +347,12 @@ class ItemsGridHelper extends HelperBase // Grid Data $GridData = new DataGridData(); - $GridData->setDataRowSourceId('accfile_id'); + $GridData->setDataRowSourceId('id'); $GridData->addDataRowSource('account_name'); $GridData->addDataRowSource('customer_name'); - $GridData->addDataRowSource('accfile_name'); - $GridData->addDataRowSource('accfile_type'); - $GridData->addDataRowSource('accfile_size'); + $GridData->addDataRowSource('name'); + $GridData->addDataRowSource('type'); + $GridData->addDataRowSource('size'); $GridData->setData($data); // Grid @@ -1076,7 +1083,8 @@ class ItemsGridHelper extends HelperBase $GridActionEdit->setName(__('Editar Etiqueta')); $GridActionEdit->setTitle(__('Editar Etiqueta')); $GridActionEdit->setIcon($this->icons->getIconEdit()); - $GridActionEdit->addData('action-route', Acl::getActionRoute(ActionsInterface::TAG_VIEW)); + $GridActionEdit->setOnClickFunction('appMgmt/show'); + $GridActionEdit->addData('action-route', Acl::getActionRoute(ActionsInterface::TAG_EDIT)); $Grid->setDataActions($GridActionEdit); @@ -1108,11 +1116,11 @@ class ItemsGridHelper extends HelperBase // Grid Data $GridData = new DataGridData(); - $GridData->setDataRowSourceId('plugin_id'); - $GridData->addDataRowSource('plugin_name'); - $GridData->addDataRowSourceWithIcon('plugin_enabled', $this->icons->getIconEnabled()); - $GridData->addDataRowSourceWithIcon('plugin_enabled', $this->icons->getIconDisabled(), 0); - $GridData->addDataRowSourceWithIcon('plugin_available', $this->icons->getIconDelete()->setTitle(__('No disponible')), 0); + $GridData->setDataRowSourceId('id'); + $GridData->addDataRowSource('name'); + $GridData->addDataRowSourceWithIcon('enabled', $this->icons->getIconEnabled()); + $GridData->addDataRowSourceWithIcon('enabled', $this->icons->getIconDisabled(), 0); + $GridData->addDataRowSourceWithIcon('available', $this->icons->getIconDelete()->setTitle(__('No disponible')), 0); $GridData->setData($data); // Grid @@ -1145,7 +1153,7 @@ class ItemsGridHelper extends HelperBase $GridActionView->setTitle(__('Ver Plugin')); $GridActionView->setIcon($this->icons->getIconView()); $GridActionView->setOnClickFunction('appMgmt/show'); - $GridActionView->setFilterRowSource('plugin_available', 0); + $GridActionView->setFilterRowSource('available', 0); $GridActionView->addData('action-route', Acl::getActionRoute(ActionsInterface::PLUGIN_VIEW)); $Grid->setDataActions($GridActionView); @@ -1156,8 +1164,8 @@ class ItemsGridHelper extends HelperBase $GridActionEnable->setTitle(__('Habilitar')); $GridActionEnable->setIcon($this->icons->getIconEnabled()); $GridActionEnable->setOnClickFunction('plugin/toggle'); - $GridActionEnable->setFilterRowSource('plugin_enabled'); - $GridActionEnable->setFilterRowSource('plugin_available', 0); + $GridActionEnable->setFilterRowSource('enabled'); + $GridActionEnable->setFilterRowSource('available', 0); $GridActionEnable->addData('action-route', Acl::getActionRoute(ActionsInterface::PLUGIN_ENABLE)); $Grid->setDataActions($GridActionEnable); @@ -1168,8 +1176,8 @@ class ItemsGridHelper extends HelperBase $GridActionDisable->setTitle(__('Deshabilitar')); $GridActionDisable->setIcon($this->icons->getIconDisabled()); $GridActionDisable->setOnClickFunction('plugin/toggle'); - $GridActionDisable->setFilterRowSource('plugin_enabled', 0); - $GridActionDisable->setFilterRowSource('plugin_available', 0); + $GridActionDisable->setFilterRowSource('enabled', 0); + $GridActionDisable->setFilterRowSource('available', 0); $GridActionDisable->addData('action-route', Acl::getActionRoute(ActionsInterface::PLUGIN_DISABLE)); $Grid->setDataActions($GridActionDisable); @@ -1180,7 +1188,7 @@ class ItemsGridHelper extends HelperBase $GridActionReset->setTitle(__('Restablecer Datos')); $GridActionReset->setIcon($this->icons->getIconRefresh()); $GridActionReset->setOnClickFunction('plugin/reset'); - $GridActionReset->setFilterRowSource('plugin_available', 0); + $GridActionReset->setFilterRowSource('available', 0); $GridActionReset->addData('action-route', Acl::getActionRoute(ActionsInterface::PLUGIN_RESET)); $Grid->setDataActions($GridActionReset); diff --git a/app/modules/web/Controllers/ItemManagerController.php b/app/modules/web/Controllers/ItemManagerController.php new file mode 100644 index 00000000..56c0e7a3 --- /dev/null +++ b/app/modules/web/Controllers/ItemManagerController.php @@ -0,0 +1,211 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + +use SP\Controller\ControllerBase; +use SP\Core\Acl\Acl; +use SP\Core\Acl\ActionsInterface; +use SP\DataModel\ItemSearchData; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Helpers\ItemsGridHelper; +use SP\Modules\Web\Controllers\Helpers\TabsGridHelper; +use SP\Services\Account\AccountFileService; +use SP\Services\Account\AccountHistoryService; +use SP\Services\Account\AccountService; +use SP\Services\Category\CategoryService; +use SP\Services\Client\ClientService; +use SP\Services\CustomField\CustomFieldDefService; +use SP\Services\Plugin\PluginService; +use SP\Services\Tag\TagService; + +/** + * Class ItemManagerController + * + * @package SP\Modules\Web\Controllers + */ +class ItemManagerController extends ControllerBase +{ + /** + * @var ItemSearchData + */ + protected $itemSearchData; + /** + * @var ItemsGridHelper + */ + protected $itemsGridHelper; + /** + * @var TabsGridHelper + */ + protected $tabsGridHelper; + + /** + * @throws \SP\Core\Exceptions\InvalidArgumentException + */ + public function indexAction() + { + $this->getGridTabs(); + } + + /** + * Returns a tabbed grid with items + * + * @throws \SP\Core\Exceptions\InvalidArgumentException + */ + protected function getGridTabs() + { + $this->itemSearchData = new ItemSearchData(); + $this->itemSearchData->setLimitCount($this->configData->getAccountCount()); + + $this->itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + + $this->tabsGridHelper = new TabsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + + if ($this->checkAccess(ActionsInterface::CATEGORY)) { + $this->tabsGridHelper->addTab($this->getCategoriesList()); + } + + if ($this->checkAccess(ActionsInterface::TAG)) { + $this->tabsGridHelper->addTab($this->getTagsList()); + } + + if ($this->checkAccess(ActionsInterface::CLIENT)) { + $this->tabsGridHelper->addTab($this->getClientsList()); + } + + if ($this->checkAccess(ActionsInterface::CUSTOMFIELD)) { + $this->tabsGridHelper->addTab($this->getCustomFieldsList()); + } + + if ($this->checkAccess(ActionsInterface::FILE)) { + $this->tabsGridHelper->addTab($this->getAccountFilesList()); + } + + if ($this->checkAccess(ActionsInterface::ACCOUNTMGR)) { + $this->tabsGridHelper->addTab($this->getAccountsList()); + } + + if ($this->checkAccess(ActionsInterface::ACCOUNTMGR_HISTORY)) { + $this->tabsGridHelper->addTab($this->getAccountsHistoryList()); + } + + if ($this->checkAccess(ActionsInterface::PLUGIN)) { + $this->tabsGridHelper->addTab($this->getPluginsList()); + } + + $this->eventDispatcher->notifyEvent('show.itemlist.items', $this); + + $this->tabsGridHelper->renderTabs(Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE), Request::analyze('tabIndex', 0)); + + $this->view(); + } + + /** + * Returns categories' data tab + */ + protected function getCategoriesList() + { + $service = new CategoryService(); + + return $this->itemsGridHelper->getCategoriesGrid($service->search($this->itemSearchData))->updatePager(); + } + + /** + * Returns tags' data tab + */ + protected function getTagsList() + { + $service = new TagService(); + + return $this->itemsGridHelper->getTagsGrid($service->search($this->itemSearchData))->updatePager(); + } + + /** + * Returns clients' data tab + */ + protected function getClientsList() + { + $service = new ClientService(); + + return $this->itemsGridHelper->getClientsGrid($service->search($this->itemSearchData))->updatePager(); + } + + /** + * Returns custom fields' data tab + */ + protected function getCustomFieldsList() + { + $service = new CustomFieldDefService(); + + return $this->itemsGridHelper->getCustomFieldsGrid($service->search($this->itemSearchData))->updatePager(); + } + + /** + * Returns account files' data tab + */ + protected function getAccountFilesList() + { + $service = new AccountFileService(); + + return $this->itemsGridHelper->getFilesGrid($service->search($this->itemSearchData))->updatePager(); + } + + /** + * Returns accounts' data tab + */ + protected function getAccountsList() + { + $service = new AccountService(); + + return $this->itemsGridHelper->getAccountsGrid($service->search($this->itemSearchData))->updatePager(); + } + + /** + * Returns accounts' history data tab + */ + protected function getAccountsHistoryList() + { + $service = new AccountHistoryService(); + + return $this->itemsGridHelper->getAccountsHistoryGrid($service->search($this->itemSearchData))->updatePager(); + } + + /** + * Returns plugins' data tab + */ + protected function getPluginsList() + { + $service = new PluginService(); + + return $this->itemsGridHelper->getPluginsGrid($service->search($this->itemSearchData))->updatePager(); + } + + /** + * @return TabsGridHelper + */ + public function getTabsGridHelper() + { + return $this->tabsGridHelper; + } +} \ No newline at end of file diff --git a/app/modules/web/Controllers/TagController.php b/app/modules/web/Controllers/TagController.php new file mode 100644 index 00000000..c9b84ce5 --- /dev/null +++ b/app/modules/web/Controllers/TagController.php @@ -0,0 +1,276 @@ +. + */ + +namespace SP\Modules\Web\Controllers; + + +use SP\Controller\ControllerBase; +use SP\Core\Acl\Acl; +use SP\Core\Acl\ActionsInterface; +use SP\Core\Exceptions\SPException; +use SP\Core\Exceptions\ValidationException; +use SP\Core\SessionUtil; +use SP\DataModel\TagData; +use SP\Forms\TagForm; +use SP\Http\JsonResponse; +use SP\Http\Request; +use SP\Modules\Web\Controllers\Helpers\ItemsGridHelper; +use SP\Modules\Web\Controllers\Traits\ItemTrait; +use SP\Modules\Web\Controllers\Traits\JsonTrait; +use SP\Mvc\Controller\CrudControllerInterface; +use SP\Services\Tag\TagService; + +/** + * Class TagController + * + * @package SP\Modules\Web\Controllers + */ +class TagController extends ControllerBase implements CrudControllerInterface +{ + use JsonTrait; + use ItemTrait; + + /** + * @var TagService + */ + protected $tagService; + + /** + * Search action + */ + public function searchAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::TAG_SEARCH)) { + return; + } + + $itemsGridHelper = new ItemsGridHelper($this->view, $this->config, $this->session, $this->eventDispatcher); + $grid = $itemsGridHelper->getTagsGrid($this->tagService->search($this->getSearchData($this->configData)))->updatePager(); + + $this->view->addTemplate('datagrid-table', 'grid'); + $this->view->assign('index', Request::analyze('activetab', 0)); + $this->view->assign('data', $grid); + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Create action + * + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function createAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::TAG_CREATE)) { + return; + } + + $this->view->assign(__FUNCTION__, 1); + $this->view->assign('header', __('Nueva Etiqueta')); + $this->view->assign('isView', false); + $this->view->assign('route', 'tag/saveCreate'); + + try { + $this->setViewData(); + + $this->eventDispatcher->notifyEvent('show.tag.create', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(1, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Sets view data for displaying user's data + * + * @param $tagId + * @throws \Psr\Container\ContainerExceptionInterface + */ + protected function setViewData($tagId = null) + { + $this->view->addTemplate('tag', 'itemshow'); + + $tag = $tagId ? $this->tagService->getById($tagId) : new TagData(); + + $this->view->assign('tag', $tag); + + $this->view->assign('sk', SessionUtil::getSessionKey(true)); + $this->view->assign('nextAction', Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE)); + + if ($this->view->isView === true) { + $this->view->assign('disabled', 'disabled'); + $this->view->assign('readonly', 'readonly'); + } else { + $this->view->assign('disabled'); + $this->view->assign('readonly'); + } + } + + /** + * Edit action + * + * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function editAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::TAG_EDIT)) { + return; + } + + $this->view->assign('header', __('Editar Etiqueta')); + $this->view->assign('isView', false); + $this->view->assign('route', 'tag/saveEdit/' . $id); + + try { + $this->setViewData($id); + + $this->eventDispatcher->notifyEvent('show.tag.edit', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Delete action + * + * @param $id + */ + public function deleteAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::TAG_DELETE)) { + return; + } + + try { + $this->tagService->delete($id); + + $this->deleteCustomFieldsForItem(ActionsInterface::TAG, $id); + + $this->eventDispatcher->notifyEvent('delete.tag', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiqueta eliminada')); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * Saves create action + */ + public function saveCreateAction() + { + if (!$this->acl->checkUserAccess(ActionsInterface::TAG_CREATE)) { + return; + } + + try { + $form = new TagForm(); + $form->validate(ActionsInterface::TAG_CREATE); + + $this->tagService->create($form->getItemData()); + + $this->eventDispatcher->notifyEvent('create.tag', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiqueta creada')); + } catch (ValidationException $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * Saves edit action + * + * @param $id + */ + public function saveEditAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::TAG_EDIT)) { + return; + } + + try { + $form = new TagForm($id); + $form->validate(ActionsInterface::TAG_EDIT); + + $this->tagService->update($form->getItemData()); + + $this->eventDispatcher->notifyEvent('edit.tag', $this); + + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Etiqueta actualizada')); + } catch (ValidationException $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } catch (SPException $e) { + debugLog($e->getMessage(), true); + + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + } + + /** + * View action + * + * @param $id + * @throws \Psr\Container\ContainerExceptionInterface + */ + public function viewAction($id) + { + if (!$this->acl->checkUserAccess(ActionsInterface::TAG_VIEW)) { + return; + } + + $this->view->assign('header', __('Ver Etiqueta')); + $this->view->assign('isView', true); + + try { + $this->setViewData($id); + + $this->eventDispatcher->notifyEvent('show.tag', $this); + } catch (\Exception $e) { + $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage()); + } + + $this->returnJsonResponseData(['html' => $this->render()]); + } + + /** + * Initialize class + */ + protected function initialize() + { + $this->checkLoggedIn(); + + $this->tagService = new TagService(); + } + +} \ No newline at end of file diff --git a/app/modules/web/Controllers/Traits/ItemTrait.php b/app/modules/web/Controllers/Traits/ItemTrait.php index c45850b0..cd84539e 100644 --- a/app/modules/web/Controllers/Traits/ItemTrait.php +++ b/app/modules/web/Controllers/Traits/ItemTrait.php @@ -24,8 +24,10 @@ namespace SP\Modules\Web\Controllers\Traits; +use Defuse\Crypto\Exception\CryptoException; use SP\Config\ConfigData; use SP\Core\Exceptions\SPException; +use SP\DataModel\CustomFieldData; use SP\DataModel\ItemSearchData; use SP\Http\Request; use SP\Services\CustomField\CustomFieldService; @@ -43,12 +45,35 @@ trait ItemTrait * @param $moduleId * @param $itemId * @return array - * @throws \Defuse\Crypto\Exception\CryptoException */ protected function getCustomFieldsForItem($moduleId, $itemId) { $customFieldService = new CustomFieldService(); - return $customFieldService->getForModuleById($moduleId, $itemId); + $customFields = []; + + $customFieldBase = new \stdClass(); + + foreach ($customFieldService->getForModuleById($moduleId, $itemId) as $item) { + try { + $customField = clone $customFieldBase; + $customField->required = (bool)$item->required; + $customField->showInList = (bool)$item->showInList; + $customField->help = $item->help; + $customField->definitionId = (int)$item->definitionId; + $customField->definitionName = $item->definitionName; + $customField->typeId = (int)$item->typeId; + $customField->typeName = $item->typeName; + $customField->moduleId = (int)$item->moduleId; + $customField->formId = CustomFieldService::getFormIdForName($item->definitionName); + $customField->value = $item->data !== null ? CustomFieldService::unencryptData($item->data) : ''; + + $customFields[] = $customField; + } catch (CryptoException $e) { + debugLog($e->getMessage()); + } + } + + return $customFields; } /** @@ -60,8 +85,25 @@ trait ItemTrait */ protected function addCustomFieldsForItem($moduleId, $itemId) { - $customFieldService = new CustomFieldService(); - $customFieldService->addCustomFieldData(Request::analyze('customfield'), $itemId, $moduleId); + $customFields = Request::analyze('customfield'); + + if (is_array($customFields)) { + $customFieldData = new CustomFieldData(); + $customFieldData->setId($itemId); + $customFieldData->setModuleId($moduleId); + + $customFieldService = new CustomFieldService(); + try { + foreach ($customFields as $id => $value) { + $customFieldData->setDefinitionId($id); + $customFieldData->setData($value); + + $customFieldService->create($customFieldData); + } + } catch (CryptoException $e) { + throw new SPException(SPException::SP_ERROR, __u('Error interno')); + } + } } /** @@ -86,8 +128,25 @@ trait ItemTrait */ protected function updateCustomFieldsForItem($moduleId, $itemId) { - $customFieldService = new CustomFieldService(); - $customFieldService->updateCustomFieldData(Request::analyze('customfield'), $itemId, $moduleId); + $customFields = Request::analyze('customfield'); + + if (is_array($customFields)) { + $customFieldService = new CustomFieldService(); + $customFieldData = new CustomFieldData(); + $customFieldData->setId($itemId); + $customFieldData->setModuleId($moduleId); + + try { + foreach ($customFields as $id => $value) { + $customFieldData->setDefinitionId($id); + $customFieldData->setData($value); + + $customFieldService->update($customFieldData); + } + } catch (CryptoException $e) { + throw new SPException(SPException::SP_ERROR, __u('Error interno')); + } + } } /** diff --git a/app/modules/web/themes/material-blue/views/common/aux-customfields.inc b/app/modules/web/themes/material-blue/views/common/aux-customfields.inc index 1bb11cce..e42b91e0 100644 --- a/app/modules/web/themes/material-blue/views/common/aux-customfields.inc +++ b/app/modules/web/themes/material-blue/views/common/aux-customfields.inc @@ -3,57 +3,56 @@ use SP\Mgmt\CustomFields\CustomFieldTypes; /** @var $icons \Theme\Icons */ -/** @var \SP\DataModel\CustomFieldData $field */ foreach ($customFields as $index => $field):?> - getDefinition()->getName(); ?> - getDefinition()->getHelp()): ?> -
typeName; ?> + help): ?> +
getIconHelp()->getIcon(); ?>
-

getDefinition()->getHelp(); ?>

+ for="help-formId; ?>"> +

formId; ?>

- getDefinition()->getType() === CustomFieldTypes::TYPE_COLOR && $isView): ?> + typeId === CustomFieldTypes::TYPE_COLOR && $isView): ?> - getDefinition()->getType() === CustomFieldTypes::TYPE_PASSWORD): ?> + typeId === CustomFieldTypes::TYPE_PASSWORD): ?>
- getDefinition()->isRequired() ? 'required' : ''; ?> > + value="value !== '') ? '***' : htmlspecialchars($field->value, ENT_QUOTES); ?>" required ? 'required' : ''; ?> > + for="formId; ?>">typeName; ?>
- getDefinition()->getType() === CustomFieldTypes::TYPE_TEXTAREA): ?> + typeId === CustomFieldTypes::TYPE_TEXTAREA): ?>
+ name="customfield[definitionId; ?>]" + id="formId; ?>" >value); ?> + for="formId; ?>">definitionName; ?>
- getDefinition()->isRequired() ? 'required' : ''; ?> > + value="value); ?>" required ? 'required' : ''; ?> > + for="formId; ?>">definitionName; ?>
diff --git a/app/modules/web/themes/material-blue/views/grid/datagrid-rows.inc b/app/modules/web/themes/material-blue/views/grid/datagrid-rows.inc index c19c1000..10cc76a8 100644 --- a/app/modules/web/themes/material-blue/views/grid/datagrid-rows.inc +++ b/app/modules/web/themes/material-blue/views/grid/datagrid-rows.inc @@ -20,6 +20,7 @@ use SP\Html\Html; data-activetab=""> getData()->getDataRowSources() as $rowSrc): ?> {$rowSrc['name']}() : $dataItem->{$rowSrc['name']}; ?> + diff --git a/app/modules/web/themes/material-blue/views/itemshow/categories.inc b/app/modules/web/themes/material-blue/views/itemshow/category.inc similarity index 91% rename from app/modules/web/themes/material-blue/views/itemshow/categories.inc rename to app/modules/web/themes/material-blue/views/itemshow/category.inc index ca05af1a..6f41878a 100644 --- a/app/modules/web/themes/material-blue/views/itemshow/categories.inc +++ b/app/modules/web/themes/material-blue/views/itemshow/category.inc @@ -7,8 +7,9 @@
@@ -42,8 +43,6 @@ - -
diff --git a/app/modules/web/themes/material-blue/views/itemshow/customers.inc b/app/modules/web/themes/material-blue/views/itemshow/client.inc similarity index 88% rename from app/modules/web/themes/material-blue/views/itemshow/customers.inc rename to app/modules/web/themes/material-blue/views/itemshow/client.inc index 49e2c63c..c192f0d1 100644 --- a/app/modules/web/themes/material-blue/views/itemshow/customers.inc +++ b/app/modules/web/themes/material-blue/views/itemshow/client.inc @@ -1,7 +1,7 @@ @@ -10,8 +10,9 @@
@@ -21,7 +22,7 @@
+ maxlength="50" value="getCustomerName(); ?>">
@@ -34,7 +35,7 @@
+ maxlength="50" value="getCustomerDescription(); ?>">
@@ -58,7 +59,7 @@ @@ -70,8 +71,6 @@ - -
diff --git a/app/modules/web/themes/material-blue/views/itemshow/customfields.inc b/app/modules/web/themes/material-blue/views/itemshow/customfield.inc similarity index 86% rename from app/modules/web/themes/material-blue/views/itemshow/customfields.inc rename to app/modules/web/themes/material-blue/views/itemshow/customfield.inc index ec4c2926..f40622ff 100644 --- a/app/modules/web/themes/material-blue/views/itemshow/customfields.inc +++ b/app/modules/web/themes/material-blue/views/itemshow/customfield.inc @@ -10,8 +10,9 @@
@@ -33,9 +34,10 @@
@@ -48,7 +50,7 @@ @@ -70,7 +72,7 @@ @@ -78,8 +80,6 @@ - -
diff --git a/app/modules/web/themes/material-blue/views/itemshow/plugins.inc b/app/modules/web/themes/material-blue/views/itemshow/plugin.inc similarity index 100% rename from app/modules/web/themes/material-blue/views/itemshow/plugins.inc rename to app/modules/web/themes/material-blue/views/itemshow/plugin.inc diff --git a/app/modules/web/themes/material-blue/views/itemshow/tags.inc b/app/modules/web/themes/material-blue/views/itemshow/tag.inc similarity index 88% rename from app/modules/web/themes/material-blue/views/itemshow/tags.inc rename to app/modules/web/themes/material-blue/views/itemshow/tag.inc index 700ed2f4..e6e000f9 100644 --- a/app/modules/web/themes/material-blue/views/itemshow/tags.inc +++ b/app/modules/web/themes/material-blue/views/itemshow/tag.inc @@ -7,8 +7,9 @@
@@ -27,8 +28,6 @@ - -
diff --git a/lib/SP/Api/SyspassApi.php b/lib/SP/Api/SyspassApi.php index 0be233c1..f298505d 100644 --- a/lib/SP/Api/SyspassApi.php +++ b/lib/SP/Api/SyspassApi.php @@ -36,7 +36,7 @@ use SP\Core\Crypt\Crypt; use SP\Core\Exceptions\SPException; use SP\DataModel\AccountExtData; use SP\DataModel\CategoryData; -use SP\DataModel\CustomerData; +use SP\DataModel\ClientData; use SP\DataModel\ItemSearchData; use SP\Mgmt\Categories\Category; use SP\Mgmt\Categories\CategorySearch; @@ -358,7 +358,7 @@ class SyspassApi extends ApiBase { $this->checkActionAccess(ActionsInterface::CLIENT); - $CustomerData = new CustomerData(); + $CustomerData = new ClientData(); $CustomerData->setCustomerName($this->getParam('name', true)); $CustomerData->setCustomerDescription($this->getParam('description')); diff --git a/lib/SP/Controller/ItemActionController.php b/lib/SP/Controller/ItemActionController.php index 79ed20b5..7f1f0b62 100644 --- a/lib/SP/Controller/ItemActionController.php +++ b/lib/SP/Controller/ItemActionController.php @@ -41,7 +41,7 @@ use SP\DataModel\PublicLinkData; use SP\Forms\AccountForm; use SP\Forms\ApiTokenForm; use SP\Forms\CategoryForm; -use SP\Forms\CustomerForm; +use SP\Forms\ClientForm; use SP\Forms\CustomFieldDefForm; use SP\Forms\NoticeForm; use SP\Forms\TagForm; @@ -484,7 +484,7 @@ class ItemActionController implements ItemControllerInterface */ protected function customerAction() { - $Form = new CustomerForm($this->itemId); + $Form = new ClientForm($this->itemId); $Form->validate($this->actionId); $this->setCustomFieldData(ActionsInterface::CLIENT); diff --git a/lib/SP/Controller/ItemShowController.php b/lib/SP/Controller/ItemShowController.php index 06b6bdd4..5e3b5233 100644 --- a/lib/SP/Controller/ItemShowController.php +++ b/lib/SP/Controller/ItemShowController.php @@ -40,7 +40,7 @@ use SP\Mvc\View\Template; use SP\DataModel\AccountExtData; use SP\DataModel\ApiTokenData; use SP\DataModel\CategoryData; -use SP\DataModel\CustomerData; +use SP\DataModel\ClientData; use SP\DataModel\CustomFieldData; use SP\DataModel\CustomFieldDefData; use SP\DataModel\GroupData; @@ -359,7 +359,7 @@ class ItemShowController extends ControllerBase implements ActionsInterface, Ite $this->module = self::CLIENT; $this->view->addTemplate('customers'); - $this->view->assign('customer', $this->itemId ? Customer::getItem()->getById($this->itemId) : new CustomerData()); + $this->view->assign('customer', $this->itemId ? Customer::getItem()->getById($this->itemId) : new ClientData()); $this->getCustomFieldsForItem(); $this->JsonResponse->setStatus(0); @@ -399,7 +399,7 @@ class ItemShowController extends ControllerBase implements ActionsInterface, Ite $this->view->assign('users', User::getItem()->getItemsForSelect()); $this->view->assign('actions', ApiTokensUtil::getTokenActions()); - $this->view->assign('ApiTokenData', $ApiTokenData); + $this->view->assign('apiTokenData', $ApiTokenData); $this->view->assign('isDisabled', ($this->view->actionId === self::APITOKEN_VIEW) ? 'disabled' : ''); $this->view->assign('isReadonly', $this->view->isDisabled ? 'readonly' : ''); diff --git a/lib/SP/DataModel/CategoryData.php b/lib/SP/DataModel/CategoryData.php index c30473a8..d6eb569a 100644 --- a/lib/SP/DataModel/CategoryData.php +++ b/lib/SP/DataModel/CategoryData.php @@ -51,7 +51,7 @@ class CategoryData extends DataModelBase implements DataModelInterface public $category_hash = ''; /** - * CategoryData constructor. + * categoryData constructor. * * @param int $category_id * @param string $category_name diff --git a/lib/SP/DataModel/CustomerData.php b/lib/SP/DataModel/ClientData.php similarity index 97% rename from lib/SP/DataModel/CustomerData.php rename to lib/SP/DataModel/ClientData.php index 6312bdb1..3e04f42c 100644 --- a/lib/SP/DataModel/CustomerData.php +++ b/lib/SP/DataModel/ClientData.php @@ -27,11 +27,11 @@ namespace SP\DataModel; defined('APP_ROOT') || die(); /** - * Class CustomerData + * Class ClientData * * @package SP\DataModel */ -class CustomerData extends DataModelBase implements DataModelInterface +class ClientData extends DataModelBase implements DataModelInterface { /** * @var int diff --git a/lib/SP/DataModel/CustomFieldData.php b/lib/SP/DataModel/CustomFieldData.php index 42e26952..10d4daa0 100644 --- a/lib/SP/DataModel/CustomFieldData.php +++ b/lib/SP/DataModel/CustomFieldData.php @@ -26,138 +26,84 @@ namespace SP\DataModel; defined('APP_ROOT') || die(); -use SP\Html\Html; - /** * Class CustomFieldData * * @package SP\DataModel */ -class CustomFieldData extends CustomFieldBaseData +class CustomFieldData { /** * @var int */ - public $customfielddata_itemId = 0; + public $id; /** * @var int */ - public $customfielddata_moduleId = 0; + public $moduleId; /** * @var int */ - public $customfielddata_defId = 0; + public $itemId; + /** + * @var int + */ + public $definitionId; + /** + * @var string Encrypted data + */ + public $data; /** * @var string */ - public $typeName = ''; - /** - * @var string - */ - public $value = ''; - /** - * @var int - */ - public $definitionId = 0; - /** - * @var CustomFieldDefData - */ - protected $definition; + public $key; /** * @return int */ - public function getCustomfielddataItemId() + public function getId() { - return $this->customfielddata_itemId; + return $this->id; } /** - * @param int $customfielddata_itemId + * @param int $id */ - public function setCustomfielddataItemId($customfielddata_itemId) + public function setId($id) { - $this->customfielddata_itemId = $customfielddata_itemId; + $this->id = $id; } /** * @return int */ - public function getCustomfielddataModuleId() + public function getModuleId() { - return $this->customfielddata_moduleId; + return (int)$this->moduleId; } /** - * @param int $customfielddata_moduleId + * @param int $moduleId */ - public function setCustomfielddataModuleId($customfielddata_moduleId) + public function setModuleId($moduleId) { - $this->customfielddata_moduleId = $customfielddata_moduleId; + $this->moduleId = (int)$moduleId; } /** * @return int */ - public function getCustomfielddataDefId() + public function getItemId() { - return $this->customfielddata_defId; + return (int)$this->itemId; } /** - * @param int $customfielddata_defId + * @param int $itemId */ - public function setCustomfielddataDefId($customfielddata_defId) + public function setItemId($itemId) { - $this->customfielddata_defId = $customfielddata_defId; - } - - /** - * @return string - */ - public function getTypeName() - { - return $this->typeName; - } - - /** - * @param string $typeName - */ - public function setTypeName($typeName) - { - $this->typeName = $typeName; - } - - /** - * @return string - */ - public function getValue() - { - return $this->value; - } - - /** - * @param string $value - */ - public function setValue($value) - { - $this->value = $value; - } - - /** - * @return string - */ - public function getCleanValue() - { - return Html::sanitize($this->value); - } - - /** - * @return string - */ - public function getSafeHtmlValue() - { - return htmlspecialchars($this->value, ENT_QUOTES); + $this->itemId = (int)$itemId; } /** @@ -165,7 +111,7 @@ class CustomFieldData extends CustomFieldBaseData */ public function getDefinitionId() { - return $this->definitionId; + return (int)$this->definitionId; } /** @@ -173,23 +119,38 @@ class CustomFieldData extends CustomFieldBaseData */ public function setDefinitionId($definitionId) { - $this->definitionId = $definitionId; + $this->definitionId = (int)$definitionId; } /** - * @return CustomFieldDefData + * @return string */ - public function getDefinition() + public function getData() { - return $this->definition; + return $this->data; } /** - * @param CustomFieldDefData $definition + * @param string $data */ - public function setDefinition(CustomFieldDefData $definition) + public function setData($data) { - $this->definition = $definition; + $this->data = $data; } + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * @param string $key + */ + public function setKey($key) + { + $this->key = $key; + } } \ No newline at end of file diff --git a/lib/SP/DataModel/CustomFieldDefData.php b/lib/SP/DataModel/CustomFieldDefData.php index 5251d4be..d2f1fbb8 100644 --- a/lib/SP/DataModel/CustomFieldDefData.php +++ b/lib/SP/DataModel/CustomFieldDefData.php @@ -24,126 +24,124 @@ namespace SP\DataModel; -use SP\Mgmt\CustomFields\CustomFieldTypes; - /** * Class CustomFieldDefData * * @package SP\DataModel */ -class CustomFieldDefData extends CustomFieldBaseData implements DataModelInterface +class CustomFieldDefData { /** * @var int */ - public $customfielddef_module = 0; + public $id; /** * @var string */ - public $typeName = ''; + public $name; + /** + * @var int + */ + public $moduleId; /** * @var string */ - public $moduleName = ''; + public $field; /** - * @var bool + * @var int */ - public $required = false; + public $required; /** * @var string */ - public $help = ''; + public $help; /** - * @var bool + * @var int */ - public $showInItemsList = false; + public $showInList; + /** + * @var int + */ + public $typeId; /** * @return int */ - public function getCustomfielddefModule() + public function getId() { - return $this->customfielddef_module; + return (int)$this->id; } /** - * @param int $customfielddef_module + * @param int $id */ - public function setCustomfielddefModule($customfielddef_module) + public function setId($id) { - $this->customfielddef_module = $customfielddef_module; + $this->id = (int)$id; } /** * @return string */ - public function getTypeName() + public function getName() { - return $this->typeName; + return $this->name; } /** - * @param string $typeName + * @param string $name */ - public function setTypeName($typeName) + public function setName($name) { - $this->typeName = $typeName; + $this->name = $name; + } + + /** + * @return int + */ + public function getModuleId() + { + return (int)$this->moduleId; + } + + /** + * @param int $moduleId + */ + public function setModuleId($moduleId) + { + $this->moduleId = (int)$moduleId; } /** * @return string */ - public function getModuleName() + public function getField() { - return $this->moduleName; + return $this->field; } /** - * @param string $moduleName + * @param string $field */ - public function setModuleName($moduleName) + public function setField($field) { - $this->moduleName = $moduleName; + $this->field = $field; } /** - * @return string + * @return int */ - public function getFormId() + public function getRequired() { - return 'cf_' . strtolower(preg_replace('/\W*/', '', $this->name)); + return (int)$this->required; } /** - * @return boolean - */ - public function isShowInItemsList() - { - return $this->showInItemsList; - } - - /** - * @param boolean $showInItemsList - */ - public function setShowInItemsList($showInItemsList) - { - $this->showInItemsList = $showInItemsList; - } - - /** - * @return boolean - */ - public function isRequired() - { - return $this->required; - } - - /** - * @param boolean $required + * @param int $required */ public function setRequired($required) { - $this->required = $required; + $this->required = (int)$required; } /** @@ -163,27 +161,34 @@ class CustomFieldDefData extends CustomFieldBaseData implements DataModelInterfa } /** - * unserialize() checks for the presence of a function with the magic name __wakeup. - * If present, this function can reconstruct any resources that the object may have. - * The intended use of __wakeup is to reestablish any database connections that may have been lost during - * serialization and perform other reinitialization tasks. - * - * @return void - * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep + * @return int */ - public function __wakeup() + public function getShowInList() { - parent::__wakeup(); + return (int)$this->showInList; + } - $this->moduleName = CustomFieldTypes::getFieldsModules($this->getModule()); - $this->typeName = CustomFieldTypes::getFieldsTypes($this->getType(), true); + /** + * @param int $showInList + */ + public function setShowInList($showInList) + { + $this->showInList = (int)$showInList; } /** * @return int */ - public function getId() + public function getTypeId() { - return $this->customfielddef_id; + return (int)$this->typeId; + } + + /** + * @param int $typeId + */ + public function setTypeId($typeId) + { + $this->typeId = (int)$typeId; } } \ No newline at end of file diff --git a/lib/SP/DataModel/CustomFieldDefDataOld.php b/lib/SP/DataModel/CustomFieldDefDataOld.php new file mode 100644 index 00000000..ba21e4fa --- /dev/null +++ b/lib/SP/DataModel/CustomFieldDefDataOld.php @@ -0,0 +1,189 @@ +. + */ + +namespace SP\DataModel; + +use SP\Mgmt\CustomFields\CustomFieldTypes; + +/** + * Class CustomFieldDefDataOld + * + * @package SP\DataModel + */ +class CustomFieldDefDataOld extends CustomFieldBaseData implements DataModelInterface +{ + /** + * @var int + */ + public $customfielddef_module = 0; + /** + * @var string + */ + public $typeName = ''; + /** + * @var string + */ + public $moduleName = ''; + /** + * @var bool + */ + public $required = false; + /** + * @var string + */ + public $help = ''; + /** + * @var bool + */ + public $showInItemsList = false; + + /** + * @return int + */ + public function getCustomfielddefModule() + { + return $this->customfielddef_module; + } + + /** + * @param int $customfielddef_module + */ + public function setCustomfielddefModule($customfielddef_module) + { + $this->customfielddef_module = $customfielddef_module; + } + + /** + * @return string + */ + public function getTypeName() + { + return $this->typeName; + } + + /** + * @param string $typeName + */ + public function setTypeName($typeName) + { + $this->typeName = $typeName; + } + + /** + * @return string + */ + public function getModuleName() + { + return $this->moduleName; + } + + /** + * @param string $moduleName + */ + public function setModuleName($moduleName) + { + $this->moduleName = $moduleName; + } + + /** + * @return string + */ + public function getFormId() + { + return 'cf_' . strtolower(preg_replace('/\W*/', '', $this->name)); + } + + /** + * @return boolean + */ + public function isShowInItemsList() + { + return $this->showInItemsList; + } + + /** + * @param boolean $showInItemsList + */ + public function setShowInItemsList($showInItemsList) + { + $this->showInItemsList = $showInItemsList; + } + + /** + * @return boolean + */ + public function isRequired() + { + return $this->required; + } + + /** + * @param boolean $required + */ + public function setRequired($required) + { + $this->required = $required; + } + + /** + * @return string + */ + public function getHelp() + { + return $this->help; + } + + /** + * @param string $help + */ + public function setHelp($help) + { + $this->help = $help; + } + + /** + * unserialize() checks for the presence of a function with the magic name __wakeup. + * If present, this function can reconstruct any resources that the object may have. + * The intended use of __wakeup is to reestablish any database connections that may have been lost during + * serialization and perform other reinitialization tasks. + * + * @return void + * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep + */ + public function __wakeup() + { + parent::__wakeup(); + + $this->moduleName = CustomFieldTypes::getFieldsModules($this->getModule()); + $this->typeName = CustomFieldTypes::getFieldsTypes($this->getType(), true); + } + + /** + * @return int + */ + public function getId() + { + return $this->customfielddef_id; + } +} \ No newline at end of file diff --git a/lib/SP/DataModel/CustomFieldTypeData.php b/lib/SP/DataModel/CustomFieldTypeData.php new file mode 100644 index 00000000..02726b38 --- /dev/null +++ b/lib/SP/DataModel/CustomFieldTypeData.php @@ -0,0 +1,97 @@ +. + */ + +namespace SP\DataModel; + + +/** + * Class CustomFieldTypeData + * + * @package SP\DataModel + */ +class CustomFieldTypeData extends DataModelBase implements DataModelInterface +{ + /** + * @var int + */ + public $id; + /** + * @var string + */ + public $name; + /** + * @var string + */ + public $text; + + /** + * @return int + */ + public function getId() + { + return (int)$this->id; + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = (int)$id; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + */ + public function setText($text) + { + $this->text = $text; + } + + +} \ No newline at end of file diff --git a/lib/SP/DataModel/FileData.php b/lib/SP/DataModel/FileData.php index d8b840fb..fac54bae 100644 --- a/lib/SP/DataModel/FileData.php +++ b/lib/SP/DataModel/FileData.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link http://syspass.org + * @author nuxsmin + * @link http://syspass.org * @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -36,178 +36,66 @@ class FileData extends DataModelBase implements DataModelInterface /** * @var int */ - public $accfile_id = 0; + public $id; /** * @var int */ - public $accfile_accountId = 0; + public $accountId; /** * @var string */ - public $accfile_name = ''; + public $name; /** * @var int */ - public $accfile_type = 0; + public $type; /** * @var string */ - public $accfile_content = ''; + public $content; /** * @var string */ - public $accfile_extension = ''; + public $extension; /** * @var string */ - public $accfile_thumb = ''; + public $thumb; /** * @var int */ - public $accfile_size = 0; - - /** - * @return int - */ - public function getAccfileAccountId() - { - return $this->accfile_accountId; - } - - /** - * @param int $accfile_accountId - */ - public function setAccfileAccountId($accfile_accountId) - { - $this->accfile_accountId = $accfile_accountId; - } - - /** - * @return string - */ - public function getAccfileName() - { - return $this->accfile_name; - } - - /** - * @param string $accfile_name - */ - public function setAccfileName($accfile_name) - { - $this->accfile_name = $accfile_name; - } - - /** - * @return int - */ - public function getAccfileType() - { - return $this->accfile_type; - } - - /** - * @param int $accfile_type - */ - public function setAccfileType($accfile_type) - { - $this->accfile_type = $accfile_type; - } - - /** - * @return string - */ - public function getAccfileContent() - { - return $this->accfile_content; - } - - /** - * @param string $accfile_content - */ - public function setAccfileContent($accfile_content) - { - $this->accfile_content = $accfile_content; - } - - /** - * @return string - */ - public function getAccfileExtension() - { - return $this->accfile_extension; - } - - /** - * @param string $accfile_extension - */ - public function setAccfileExtension($accfile_extension) - { - $this->accfile_extension = $accfile_extension; - } - - /** - * @return string - */ - public function getAccfileThumb() - { - return $this->accfile_thumb; - } - - /** - * @param string $accfile_thumb - */ - public function setAccfileThumb($accfile_thumb) - { - $this->accfile_thumb = $accfile_thumb; - } - - /** - * @return int - */ - public function getAccfileSize() - { - return $this->accfile_size; - } - - /** - * @param int $accfile_size - */ - public function setAccfileSize($accfile_size) - { - $this->accfile_size = $accfile_size; - } - - /** - * @return float - */ - public function getRoundSize() - { - return round(($this->accfile_size / 1000), 2); - } - - /** - * @return int - */ - public function getAccfileId() - { - return $this->accfile_id; - } - - /** - * @param int $accfile_id - */ - public function setAccfileId($accfile_id) - { - $this->accfile_id = $accfile_id; - } + public $size; /** * @return int */ public function getId() { - return $this->accfile_id; + return $this->id; + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return int + */ + public function getAccountId() + { + return $this->accountId; + } + + /** + * @param int $accountId + */ + public function setAccountId($accountId) + { + $this->accountId = $accountId; } /** @@ -215,6 +103,102 @@ class FileData extends DataModelBase implements DataModelInterface */ public function getName() { - return $this->accfile_name; + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return int + */ + public function getType() + { + return $this->type; + } + + /** + * @param int $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * @param string $content + */ + public function setContent($content) + { + $this->content = $content; + } + + /** + * @return string + */ + public function getExtension() + { + return $this->extension; + } + + /** + * @param string $extension + */ + public function setExtension($extension) + { + $this->extension = $extension; + } + + /** + * @return string + */ + public function getThumb() + { + return $this->thumb; + } + + /** + * @param string $thumb + */ + public function setThumb($thumb) + { + $this->thumb = $thumb; + } + + /** + * @return int + */ + public function getSize() + { + return $this->size; + } + + /** + * @param int $size + */ + public function setSize($size) + { + $this->size = $size; + } + + /** + * @return float + */ + public function getRoundSize() + { + return round($this->size / 1000, 2); } } \ No newline at end of file diff --git a/lib/SP/Forms/ApiTokenForm.php b/lib/SP/Forms/ApiTokenForm.php index 926abe55..3839e9b0 100644 --- a/lib/SP/Forms/ApiTokenForm.php +++ b/lib/SP/Forms/ApiTokenForm.php @@ -39,7 +39,7 @@ class ApiTokenForm extends FormBase implements FormInterface /** * @var ApiTokenData */ - protected $ApiTokenData; + protected $apiTokenData; /** * Validar el formulario @@ -68,11 +68,11 @@ class ApiTokenForm extends FormBase implements FormInterface */ protected function analyzeRequestData() { - $this->ApiTokenData = new ApiTokenData(); - $this->ApiTokenData->setAuthtokenId($this->itemId); - $this->ApiTokenData->setAuthtokenUserId(Request::analyze('users', 0)); - $this->ApiTokenData->setAuthtokenActionId(Request::analyze('actions', 0)); - $this->ApiTokenData->setAuthtokenHash(Request::analyzeEncrypted('pass')); + $this->apiTokenData = new ApiTokenData(); + $this->apiTokenData->setAuthtokenId($this->itemId); + $this->apiTokenData->setAuthtokenUserId(Request::analyze('users', 0)); + $this->apiTokenData->setAuthtokenActionId(Request::analyze('actions', 0)); + $this->apiTokenData->setAuthtokenHash(Request::analyzeEncrypted('pass')); } /** @@ -80,19 +80,19 @@ class ApiTokenForm extends FormBase implements FormInterface */ protected function checkCommon() { - if ($this->ApiTokenData->getAuthtokenUserId() === 0) { + if ($this->apiTokenData->getAuthtokenUserId() === 0) { throw new ValidationException(__u('Usuario no indicado')); } - if ($this->ApiTokenData->getAuthtokenActionId() === 0) { + if ($this->apiTokenData->getAuthtokenActionId() === 0) { throw new ValidationException(__u('Acción no indicada')); } - $action = $this->ApiTokenData->getAuthtokenActionId(); + $action = $this->apiTokenData->getAuthtokenActionId(); if (($action === ActionsInterface::ACCOUNT_VIEW_PASS || $action === ActionsInterface::ACCOUNT_CREATE) - && $this->ApiTokenData->getAuthtokenHash() === '' + && $this->apiTokenData->getAuthtokenHash() === '' ) { throw new ValidationException(__u('La clave no puede estar en blanco')); } @@ -103,6 +103,6 @@ class ApiTokenForm extends FormBase implements FormInterface */ public function getItemData() { - return $this->ApiTokenData; + return $this->apiTokenData; } } \ No newline at end of file diff --git a/lib/SP/Forms/CategoryForm.php b/lib/SP/Forms/CategoryForm.php index bc0e6bba..6a782b9a 100644 --- a/lib/SP/Forms/CategoryForm.php +++ b/lib/SP/Forms/CategoryForm.php @@ -39,7 +39,7 @@ class CategoryForm extends FormBase implements FormInterface /** * @var CategoryData */ - protected $CategoryData; + protected $categoryData; /** * Validar el formulario @@ -68,10 +68,10 @@ class CategoryForm extends FormBase implements FormInterface */ protected function analyzeRequestData() { - $this->CategoryData = new CategoryData(); - $this->CategoryData->setCategoryId($this->itemId); - $this->CategoryData->setCategoryName(Request::analyze('name')); - $this->CategoryData->setCategoryDescription(Request::analyze('description')); + $this->categoryData = new CategoryData(); + $this->categoryData->setCategoryId($this->itemId); + $this->categoryData->setCategoryName(Request::analyze('name')); + $this->categoryData->setCategoryDescription(Request::analyze('description')); } /** @@ -79,7 +79,7 @@ class CategoryForm extends FormBase implements FormInterface */ protected function checkCommon() { - if (!$this->CategoryData->getCategoryName()) { + if (!$this->categoryData->getCategoryName()) { throw new ValidationException(__u('Es necesario un nombre de categoría')); } } @@ -89,6 +89,6 @@ class CategoryForm extends FormBase implements FormInterface */ public function getItemData() { - return $this->CategoryData; + return $this->categoryData; } } \ No newline at end of file diff --git a/lib/SP/Forms/CustomerForm.php b/lib/SP/Forms/ClientForm.php similarity index 69% rename from lib/SP/Forms/CustomerForm.php rename to lib/SP/Forms/ClientForm.php index e944a111..3831d770 100644 --- a/lib/SP/Forms/CustomerForm.php +++ b/lib/SP/Forms/ClientForm.php @@ -24,22 +24,22 @@ namespace SP\Forms; -use SP\Core\ActionsInterface; +use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\ValidationException; -use SP\DataModel\CustomerData; +use SP\DataModel\ClientData; use SP\Http\Request; /** - * Class CustomerForm + * Class ClientForm * * @package SP\Forms */ -class CustomerForm extends FormBase implements FormInterface +class ClientForm extends FormBase implements FormInterface { /** - * @var CustomerData + * @var ClientData */ - protected $CustomerData; + protected $clientData; /** * Validar el formulario @@ -68,11 +68,11 @@ class CustomerForm extends FormBase implements FormInterface */ protected function analyzeRequestData() { - $this->CustomerData = new CustomerData(); - $this->CustomerData->setCustomerId($this->itemId); - $this->CustomerData->setCustomerName(Request::analyze('name')); - $this->CustomerData->setCustomerDescription(Request::analyze('description')); - $this->CustomerData->setCustomerIsGlobal(Request::analyze('isglobal', 0, false, 1)); + $this->clientData = new ClientData(); + $this->clientData->setCustomerId($this->itemId); + $this->clientData->setCustomerName(Request::analyze('name')); + $this->clientData->setCustomerDescription(Request::analyze('description')); + $this->clientData->setCustomerIsGlobal(Request::analyze('isglobal', 0, false, 1)); } /** @@ -80,16 +80,16 @@ class CustomerForm extends FormBase implements FormInterface */ protected function checkCommon() { - if (!$this->CustomerData->getCustomerName()) { - throw new ValidationException(__('Es necesario un nombre de cliente', false)); + if (!$this->clientData->getCustomerName()) { + throw new ValidationException(__u('Es necesario un nombre de cliente')); } } /** - * @return CustomerData + * @return ClientData */ public function getItemData() { - return $this->CustomerData; + return $this->clientData; } } \ No newline at end of file diff --git a/lib/SP/Forms/CustomFieldDefForm.php b/lib/SP/Forms/CustomFieldDefForm.php index 75f2f90f..ae634c64 100644 --- a/lib/SP/Forms/CustomFieldDefForm.php +++ b/lib/SP/Forms/CustomFieldDefForm.php @@ -39,7 +39,7 @@ class CustomFieldDefForm extends FormBase implements FormInterface /** * @var CustomFieldDefData */ - protected $CustomFieldDefData; + protected $customFieldDefData; /** * Validar el formulario @@ -68,14 +68,13 @@ class CustomFieldDefForm extends FormBase implements FormInterface */ protected function analyzeRequestData() { - $this->CustomFieldDefData = new CustomFieldDefData(); - $this->CustomFieldDefData->setCustomfielddefId($this->itemId); - $this->CustomFieldDefData->setId($this->itemId); - $this->CustomFieldDefData->setName(Request::analyze('name')); - $this->CustomFieldDefData->setType(Request::analyze('type', 0)); - $this->CustomFieldDefData->setModule(Request::analyze('module', 0)); - $this->CustomFieldDefData->setHelp(Request::analyze('help')); - $this->CustomFieldDefData->setRequired(Request::analyze('required', false, false, true)); + $this->customFieldDefData = new CustomFieldDefData(); + $this->customFieldDefData->setId($this->itemId); + $this->customFieldDefData->setName(Request::analyze('name')); + $this->customFieldDefData->setTypeId(Request::analyze('type', 0)); + $this->customFieldDefData->setModuleId(Request::analyze('module', 0)); + $this->customFieldDefData->setHelp(Request::analyze('help')); + $this->customFieldDefData->setRequired(Request::analyze('required', false, false, true)); } /** @@ -83,12 +82,16 @@ class CustomFieldDefForm extends FormBase implements FormInterface */ protected function checkCommon() { - if (!$this->CustomFieldDefData->getName()) { - throw new ValidationException(__('Nombre del campo no indicado', false)); - } elseif ($this->CustomFieldDefData->getType() === 0) { - throw new ValidationException(__('Tipo del campo no indicado', false)); - } elseif ($this->CustomFieldDefData->getModule() === 0) { - throw new ValidationException(__('Módulo del campo no indicado', false)); + if (!$this->customFieldDefData->getName()) { + throw new ValidationException(__u('Nombre del campo no indicado')); + } + + if ($this->customFieldDefData->getTypeId() === 0) { + throw new ValidationException(__u('Tipo del campo no indicado')); + } + + if ($this->customFieldDefData->getModuleId() === 0) { + throw new ValidationException(__u('Módulo del campo no indicado')); } } @@ -97,6 +100,6 @@ class CustomFieldDefForm extends FormBase implements FormInterface */ public function getItemData() { - return $this->CustomFieldDefData; + return $this->customFieldDefData; } } \ No newline at end of file diff --git a/lib/SP/Forms/NoticeForm.php b/lib/SP/Forms/NoticeForm.php index e1f6e331..180059ea 100644 --- a/lib/SP/Forms/NoticeForm.php +++ b/lib/SP/Forms/NoticeForm.php @@ -40,7 +40,7 @@ class NoticeForm extends FormBase implements FormInterface /** * @var NoticeData */ - protected $NoticeData; + protected $noticeData; /** * Validar el formulario @@ -72,32 +72,40 @@ class NoticeForm extends FormBase implements FormInterface $Description = new NoticeMessage(); $Description->addDescription(Request::analyze('notice_description')); - $this->NoticeData = new NoticeData(); - $this->NoticeData->setNoticeId($this->itemId); - $this->NoticeData->setNoticeType(Request::analyze('notice_type')); - $this->NoticeData->setNoticeComponent(Request::analyze('notice_component')); - $this->NoticeData->setNoticeDescription($Description); - $this->NoticeData->setNoticeUserId(Request::analyze('notice_user', 0)); + $this->noticeData = new NoticeData(); + $this->noticeData->setNoticeId($this->itemId); + $this->noticeData->setNoticeType(Request::analyze('notice_type')); + $this->noticeData->setNoticeComponent(Request::analyze('notice_component')); + $this->noticeData->setNoticeDescription($Description); + $this->noticeData->setNoticeUserId(Request::analyze('notice_user', 0)); - if ($this->NoticeData->getNoticeUserId() === 0) { - $this->NoticeData->setNoticeOnlyAdmin(Request::analyze('notice_onlyadmin', 0, false, 1)); - $this->NoticeData->setNoticeSticky(Request::analyze('notice_sticky', 0, false, 1)); + if ($this->noticeData->getNoticeUserId() === 0) { + $this->noticeData->setNoticeOnlyAdmin(Request::analyze('notice_onlyadmin', 0, false, 1)); + $this->noticeData->setNoticeSticky(Request::analyze('notice_sticky', 0, false, 1)); } } + /** + * @throws ValidationException + */ private function checkCommon() { - if (!$this->NoticeData->getNoticeComponent()) { - throw new ValidationException(__('Es necesario un componente', false)); - } elseif (!$this->NoticeData->getNoticeType()) { - throw new ValidationException(__('Es necesario un tipo', false)); - } elseif (!$this->NoticeData->getNoticeDescription()) { - throw new ValidationException(__('Es necesaria una descripción', false)); - } elseif (!$this->NoticeData->getNoticeUserId() - && !$this->NoticeData->isNoticeOnlyAdmin() - && !$this->NoticeData->isNoticeSticky() - ) { - throw new ValidationException(__('Es necesario un destinatario', false)); + if (!$this->noticeData->getNoticeComponent()) { + throw new ValidationException(__u('Es necesario un componente')); + } + + if (!$this->noticeData->getNoticeType()) { + throw new ValidationException(__u('Es necesario un tipo')); + } + + if (!$this->noticeData->getNoticeDescription()) { + throw new ValidationException(__u('Es necesaria una descripción')); + } + + if (!$this->noticeData->getNoticeUserId() + && !$this->noticeData->isNoticeOnlyAdmin() + && !$this->noticeData->isNoticeSticky()) { + throw new ValidationException(__u('Es necesario un destinatario')); } } @@ -106,6 +114,6 @@ class NoticeForm extends FormBase implements FormInterface */ public function getItemData() { - return $this->NoticeData; + return $this->noticeData; } } \ No newline at end of file diff --git a/lib/SP/Forms/PublicLinkForm.php b/lib/SP/Forms/PublicLinkForm.php index 6004d5a6..f79b7d94 100644 --- a/lib/SP/Forms/PublicLinkForm.php +++ b/lib/SP/Forms/PublicLinkForm.php @@ -41,7 +41,7 @@ class PublicLinkForm extends FormBase implements FormInterface /** * @var PublicLinkData */ - protected $PublicLinkData; + protected $publicLinkData; /** * Validar el formulario @@ -72,12 +72,12 @@ class PublicLinkForm extends FormBase implements FormInterface */ protected function analyzeRequestData() { - $this->PublicLinkData = new PublicLinkData(); - $this->PublicLinkData->setPublicLinkId($this->itemId); - $this->PublicLinkData->setPublicLinkTypeId(PublicLink::TYPE_ACCOUNT); - $this->PublicLinkData->setPublicLinkItemId(Request::analyze('accountId', 0)); - $this->PublicLinkData->setPublicLinkNotify(Request::analyze('notify', false, false, true)); - $this->PublicLinkData->setPublicLinkHash(Util::generateRandomBytes()); + $this->publicLinkData = new PublicLinkData(); + $this->publicLinkData->setPublicLinkId($this->itemId); + $this->publicLinkData->setPublicLinkTypeId(PublicLink::TYPE_ACCOUNT); + $this->publicLinkData->setPublicLinkItemId(Request::analyze('accountId', 0)); + $this->publicLinkData->setPublicLinkNotify(Request::analyze('notify', false, false, true)); + $this->publicLinkData->setPublicLinkHash(Util::generateRandomBytes()); } /** @@ -85,7 +85,7 @@ class PublicLinkForm extends FormBase implements FormInterface */ protected function checkCommon() { - if (!$this->PublicLinkData->getPublicLinkItemId()) { + if (!$this->publicLinkData->getPublicLinkItemId()) { throw new ValidationException(__u('Es necesario una cuenta')); } } @@ -95,6 +95,6 @@ class PublicLinkForm extends FormBase implements FormInterface */ public function getItemData() { - return $this->PublicLinkData; + return $this->publicLinkData; } } \ No newline at end of file diff --git a/lib/SP/Forms/TagForm.php b/lib/SP/Forms/TagForm.php index 32b4c2ce..daf3ed40 100644 --- a/lib/SP/Forms/TagForm.php +++ b/lib/SP/Forms/TagForm.php @@ -24,7 +24,7 @@ namespace SP\Forms; -use SP\Core\ActionsInterface; +use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\ValidationException; use SP\DataModel\TagData; use SP\Http\Request; @@ -39,7 +39,7 @@ class TagForm extends FormBase implements FormInterface /** * @var TagData */ - protected $TagData; + protected $tagData; /** * Validar el formulario @@ -68,9 +68,9 @@ class TagForm extends FormBase implements FormInterface */ protected function analyzeRequestData() { - $this->TagData = new TagData(); - $this->TagData->setTagId($this->itemId); - $this->TagData->setTagName(Request::analyze('name')); + $this->tagData = new TagData(); + $this->tagData->setTagId($this->itemId); + $this->tagData->setTagName(Request::analyze('name')); } /** @@ -78,8 +78,8 @@ class TagForm extends FormBase implements FormInterface */ protected function checkCommon() { - if (!$this->TagData->getTagName()) { - throw new ValidationException(__('Es necesario un nombre de etiqueta', false)); + if (!$this->tagData->getTagName()) { + throw new ValidationException(__u('Es necesario un nombre de etiqueta')); } } @@ -88,6 +88,6 @@ class TagForm extends FormBase implements FormInterface */ public function getItemData() { - return $this->TagData; + return $this->tagData; } } \ No newline at end of file diff --git a/lib/SP/Forms/UserForm.php b/lib/SP/Forms/UserForm.php index 106f91c3..5257017d 100644 --- a/lib/SP/Forms/UserForm.php +++ b/lib/SP/Forms/UserForm.php @@ -42,7 +42,7 @@ class UserForm extends FormBase implements FormInterface /** * @var UserData */ - protected $UserData; + protected $userData; /** * @var int */ @@ -86,20 +86,20 @@ class UserForm extends FormBase implements FormInterface */ protected function analyzeRequestData() { - $this->UserData = new UserData(); - $this->UserData->setUserId($this->itemId); - $this->UserData->setUserName(Request::analyze('name')); - $this->UserData->setUserLogin(Request::analyze('login')); - $this->UserData->setUserSsoLogin(Request::analyze('login_sso')); - $this->UserData->setUserEmail(Request::analyze('email')); - $this->UserData->setUserNotes(Request::analyze('notes')); - $this->UserData->setUserGroupId(Request::analyze('groupid', 0)); - $this->UserData->setUserProfileId(Request::analyze('profileid', 0)); - $this->UserData->setUserIsAdminApp(Request::analyze('adminapp', 0, false, 1)); - $this->UserData->setUserIsAdminAcc(Request::analyze('adminacc', 0, false, 1)); - $this->UserData->setUserIsDisabled(Request::analyze('disabled', 0, false, 1)); - $this->UserData->setUserIsChangePass(Request::analyze('changepass', 0, false, 1)); - $this->UserData->setUserPass(Request::analyzeEncrypted('pass')); + $this->userData = new UserData(); + $this->userData->setUserId($this->itemId); + $this->userData->setUserName(Request::analyze('name')); + $this->userData->setUserLogin(Request::analyze('login')); + $this->userData->setUserSsoLogin(Request::analyze('login_sso')); + $this->userData->setUserEmail(Request::analyze('email')); + $this->userData->setUserNotes(Request::analyze('notes')); + $this->userData->setUserGroupId(Request::analyze('groupid', 0)); + $this->userData->setUserProfileId(Request::analyze('profileid', 0)); + $this->userData->setUserIsAdminApp(Request::analyze('adminapp', 0, false, 1)); + $this->userData->setUserIsAdminAcc(Request::analyze('adminacc', 0, false, 1)); + $this->userData->setUserIsDisabled(Request::analyze('disabled', 0, false, 1)); + $this->userData->setUserIsChangePass(Request::analyze('changepass', 0, false, 1)); + $this->userData->setUserPass(Request::analyzeEncrypted('pass')); } /** @@ -107,27 +107,29 @@ class UserForm extends FormBase implements FormInterface */ protected function checkCommon() { - if (!$this->isLdap && !$this->UserData->getUserName()) { + if (!$this->isLdap && !$this->userData->getUserName()) { throw new ValidationException(__u('Es necesario un nombre de usuario')); } - if (!$this->isLdap && !$this->UserData->getUserLogin()) { + if (!$this->isLdap && !$this->userData->getUserLogin()) { throw new ValidationException(__u('Es necesario un login')); } - if (!$this->UserData->getUserProfileId()) { + if (!$this->userData->getUserProfileId()) { throw new ValidationException(__u('Es necesario un perfil')); } - if (!$this->UserData->getUserGroupId()) { + if (!$this->userData->getUserGroupId()) { throw new ValidationException(__u('Es necesario un grupo')); } - if (!$this->isLdap && !$this->UserData->getUserEmail()) { + if (!$this->isLdap && !$this->userData->getUserEmail()) { throw new ValidationException(__u('Es necesario un email')); } - if ($this->ConfigData->isDemoEnabled() && !SessionFactory::getUserData()->isUserIsAdminApp() && $this->UserData->getUserLogin() === 'demo') { + if ($this->ConfigData->isDemoEnabled() + && $this->userData->getUserLogin() === 'demo' + && !SessionFactory::getUserData()->isUserIsAdminApp()) { throw new ValidationException(__u('Ey, esto es una DEMO!!')); } } @@ -143,11 +145,11 @@ class UserForm extends FormBase implements FormInterface throw new ValidationException(__u('Ey, esto es una DEMO!!')); } - if (!$userPassR || !$this->UserData->getUserPass()) { + if (!$userPassR || !$this->userData->getUserPass()) { throw new ValidationException(__u('La clave no puede estar en blanco')); } - if ($this->UserData->getUserPass() !== $userPassR) { + if ($this->userData->getUserPass() !== $userPassR) { throw new ValidationException(__u('Las claves no coinciden')); } } @@ -173,7 +175,7 @@ class UserForm extends FormBase implements FormInterface */ public function getItemData() { - return $this->UserData; + return $this->userData; } /** diff --git a/lib/SP/Forms/UserGroupForm.php b/lib/SP/Forms/UserGroupForm.php index a9f76de6..22c2594e 100644 --- a/lib/SP/Forms/UserGroupForm.php +++ b/lib/SP/Forms/UserGroupForm.php @@ -39,7 +39,7 @@ class UserGroupForm extends FormBase implements FormInterface /** * @var GroupData */ - protected $GroupData; + protected $groupData; /** * Validar el formulario @@ -68,11 +68,11 @@ class UserGroupForm extends FormBase implements FormInterface */ protected function analyzeRequestData() { - $this->GroupData = new GroupData(); - $this->GroupData->setUsergroupId($this->itemId); - $this->GroupData->setUsergroupName(Request::analyze('name')); - $this->GroupData->setUsergroupDescription(Request::analyze('description')); - $this->GroupData->setUsers(Request::analyze('users', 0)); + $this->groupData = new GroupData(); + $this->groupData->setUsergroupId($this->itemId); + $this->groupData->setUsergroupName(Request::analyze('name')); + $this->groupData->setUsergroupDescription(Request::analyze('description')); + $this->groupData->setUsers(Request::analyze('users', 0)); } /** @@ -80,7 +80,7 @@ class UserGroupForm extends FormBase implements FormInterface */ protected function checkCommon() { - if (!$this->GroupData->getUsergroupName()) { + if (!$this->groupData->getUsergroupName()) { throw new ValidationException(__u('Es necesario un nombre de grupo')); } } @@ -90,6 +90,6 @@ class UserGroupForm extends FormBase implements FormInterface */ public function getItemData() { - return $this->GroupData; + return $this->groupData; } } \ No newline at end of file diff --git a/lib/SP/Forms/UserProfileForm.php b/lib/SP/Forms/UserProfileForm.php index c0f35d3f..b5705a80 100644 --- a/lib/SP/Forms/UserProfileForm.php +++ b/lib/SP/Forms/UserProfileForm.php @@ -39,7 +39,7 @@ class UserProfileForm extends FormBase implements FormInterface /** * @var ProfileData */ - protected $ProfileData; + protected $profileData; /** * Validar el formulario @@ -68,38 +68,38 @@ class UserProfileForm extends FormBase implements FormInterface */ protected function analyzeRequestData() { - $this->ProfileData = new ProfileData(); - $this->ProfileData->setUserprofileName(Request::analyze('profile_name')); - $this->ProfileData->setUserprofileId($this->itemId); - $this->ProfileData->setAccAdd(Request::analyze('profile_accadd', 0, false, 1)); - $this->ProfileData->setAccView(Request::analyze('profile_accview', 0, false, 1)); - $this->ProfileData->setAccViewPass(Request::analyze('profile_accviewpass', 0, false, 1)); - $this->ProfileData->setAccViewHistory(Request::analyze('profile_accviewhistory', 0, false, 1)); - $this->ProfileData->setAccEdit(Request::analyze('profile_accedit', 0, false, 1)); - $this->ProfileData->setAccEditPass(Request::analyze('profile_acceditpass', 0, false, 1)); - $this->ProfileData->setAccDelete(Request::analyze('profile_accdel', 0, false, 1)); - $this->ProfileData->setAccFiles(Request::analyze('profile_accfiles', 0, false, 1)); - $this->ProfileData->setAccPublicLinks(Request::analyze('profile_accpublinks', 0, false, 1)); - $this->ProfileData->setAccPrivate(Request::analyze('profile_accprivate', 0, false, 1)); - $this->ProfileData->setAccPrivateGroup(Request::analyze('profile_accprivategroup', 0, false, 1)); - $this->ProfileData->setAccPermission(Request::analyze('profile_accpermissions', 0, false, 1)); - $this->ProfileData->setAccGlobalSearch(Request::analyze('profile_accglobalsearch', 0, false, 1)); - $this->ProfileData->setConfigGeneral(Request::analyze('profile_config', 0, false, 1)); - $this->ProfileData->setConfigEncryption(Request::analyze('profile_configmpw', 0, false, 1)); - $this->ProfileData->setConfigBackup(Request::analyze('profile_configback', 0, false, 1)); - $this->ProfileData->setConfigImport(Request::analyze('profile_configimport', 0, false, 1)); - $this->ProfileData->setMgmCategories(Request::analyze('profile_categories', 0, false, 1)); - $this->ProfileData->setMgmCustomers(Request::analyze('profile_customers', 0, false, 1)); - $this->ProfileData->setMgmCustomFields(Request::analyze('profile_customfields', 0, false, 1)); - $this->ProfileData->setMgmUsers(Request::analyze('profile_users', 0, false, 1)); - $this->ProfileData->setMgmGroups(Request::analyze('profile_groups', 0, false, 1)); - $this->ProfileData->setMgmProfiles(Request::analyze('profile_profiles', 0, false, 1)); - $this->ProfileData->setMgmApiTokens(Request::analyze('profile_apitokens', 0, false, 1)); - $this->ProfileData->setMgmPublicLinks(Request::analyze('profile_publinks', 0, false, 1)); - $this->ProfileData->setMgmAccounts(Request::analyze('profile_accounts', 0, false, 1)); - $this->ProfileData->setMgmFiles(Request::analyze('profile_files', 0, false, 1)); - $this->ProfileData->setMgmTags(Request::analyze('profile_tags', 0, false, 1)); - $this->ProfileData->setEvl(Request::analyze('profile_eventlog', 0, false, 1)); + $this->profileData = new ProfileData(); + $this->profileData->setUserprofileName(Request::analyze('profile_name')); + $this->profileData->setUserprofileId($this->itemId); + $this->profileData->setAccAdd(Request::analyze('profile_accadd', 0, false, 1)); + $this->profileData->setAccView(Request::analyze('profile_accview', 0, false, 1)); + $this->profileData->setAccViewPass(Request::analyze('profile_accviewpass', 0, false, 1)); + $this->profileData->setAccViewHistory(Request::analyze('profile_accviewhistory', 0, false, 1)); + $this->profileData->setAccEdit(Request::analyze('profile_accedit', 0, false, 1)); + $this->profileData->setAccEditPass(Request::analyze('profile_acceditpass', 0, false, 1)); + $this->profileData->setAccDelete(Request::analyze('profile_accdel', 0, false, 1)); + $this->profileData->setAccFiles(Request::analyze('profile_accfiles', 0, false, 1)); + $this->profileData->setAccPublicLinks(Request::analyze('profile_accpublinks', 0, false, 1)); + $this->profileData->setAccPrivate(Request::analyze('profile_accprivate', 0, false, 1)); + $this->profileData->setAccPrivateGroup(Request::analyze('profile_accprivategroup', 0, false, 1)); + $this->profileData->setAccPermission(Request::analyze('profile_accpermissions', 0, false, 1)); + $this->profileData->setAccGlobalSearch(Request::analyze('profile_accglobalsearch', 0, false, 1)); + $this->profileData->setConfigGeneral(Request::analyze('profile_config', 0, false, 1)); + $this->profileData->setConfigEncryption(Request::analyze('profile_configmpw', 0, false, 1)); + $this->profileData->setConfigBackup(Request::analyze('profile_configback', 0, false, 1)); + $this->profileData->setConfigImport(Request::analyze('profile_configimport', 0, false, 1)); + $this->profileData->setMgmCategories(Request::analyze('profile_categories', 0, false, 1)); + $this->profileData->setMgmCustomers(Request::analyze('profile_customers', 0, false, 1)); + $this->profileData->setMgmCustomFields(Request::analyze('profile_customfields', 0, false, 1)); + $this->profileData->setMgmUsers(Request::analyze('profile_users', 0, false, 1)); + $this->profileData->setMgmGroups(Request::analyze('profile_groups', 0, false, 1)); + $this->profileData->setMgmProfiles(Request::analyze('profile_profiles', 0, false, 1)); + $this->profileData->setMgmApiTokens(Request::analyze('profile_apitokens', 0, false, 1)); + $this->profileData->setMgmPublicLinks(Request::analyze('profile_publinks', 0, false, 1)); + $this->profileData->setMgmAccounts(Request::analyze('profile_accounts', 0, false, 1)); + $this->profileData->setMgmFiles(Request::analyze('profile_files', 0, false, 1)); + $this->profileData->setMgmTags(Request::analyze('profile_tags', 0, false, 1)); + $this->profileData->setEvl(Request::analyze('profile_eventlog', 0, false, 1)); } /** @@ -107,7 +107,7 @@ class UserProfileForm extends FormBase implements FormInterface */ protected function checkCommon() { - if (!$this->ProfileData->getUserprofileName()) { + if (!$this->profileData->getUserprofileName()) { throw new ValidationException(__u('Es necesario un nombre de perfil')); } } @@ -117,6 +117,6 @@ class UserProfileForm extends FormBase implements FormInterface */ public function getItemData() { - return $this->ProfileData; + return $this->profileData; } } \ No newline at end of file diff --git a/lib/SP/Html/DataGrid/DataGridDataBase.php b/lib/SP/Html/DataGrid/DataGridDataBase.php index 0f85eff7..7e5f884c 100644 --- a/lib/SP/Html/DataGrid/DataGridDataBase.php +++ b/lib/SP/Html/DataGrid/DataGridDataBase.php @@ -73,12 +73,13 @@ abstract class DataGridDataBase implements DataGridDataInterface } /** - * @param $source string - * @param bool $isMethod + * @param string $source + * @param bool $isMethod + * @param null $filter */ - public function addDataRowSource($source, $isMethod = false) + public function addDataRowSource($source, $isMethod = false, $filter = null) { - $this->_sources[] = ['name' => $source, 'isMethod' => $isMethod]; + $this->_sources[] = ['name' => $source, 'isMethod' => $isMethod, 'filter' => $filter]; } /** diff --git a/lib/SP/Html/DataGrid/DataGridDataInterface.php b/lib/SP/Html/DataGrid/DataGridDataInterface.php index 13c20672..927b3659 100644 --- a/lib/SP/Html/DataGrid/DataGridDataInterface.php +++ b/lib/SP/Html/DataGrid/DataGridDataInterface.php @@ -38,10 +38,11 @@ interface DataGridDataInterface /** * Establecer los orígenes de datos de la consulta * - * @param $source string - * @param bool $isMethod + * @param string $source + * @param bool $isMethod + * @param null $filter */ - public function addDataRowSource($source, $isMethod = false); + public function addDataRowSource($source, $isMethod = false, $filter = null); /** * Devolver los orígenes de datos de la consulta diff --git a/lib/SP/Import/CsvImportBase.php b/lib/SP/Import/CsvImportBase.php index c95c33d3..a764cb12 100644 --- a/lib/SP/Import/CsvImportBase.php +++ b/lib/SP/Import/CsvImportBase.php @@ -27,7 +27,7 @@ namespace SP\Import; use SP\Core\Exceptions\SPException; use SP\DataModel\AccountExtData; use SP\DataModel\CategoryData; -use SP\DataModel\CustomerData; +use SP\DataModel\ClientData; defined('APP_ROOT') || die(); @@ -90,7 +90,7 @@ abstract class CsvImportBase extends ImportBase list($accountName, $customerName, $categoryName, $url, $login, $password, $notes) = $fields; // Obtener los ids de cliente y categoría - $CustomerData = new CustomerData(null, $customerName); + $CustomerData = new ClientData(null, $customerName); $this->addCustomer($CustomerData); $CategoryData = new CategoryData(null, $categoryName); $this->addCategory($CategoryData); diff --git a/lib/SP/Import/ImportBase.php b/lib/SP/Import/ImportBase.php index 7480f952..a0b5eca0 100644 --- a/lib/SP/Import/ImportBase.php +++ b/lib/SP/Import/ImportBase.php @@ -32,7 +32,7 @@ use SP\Core\Messages\LogMessage; use SP\Core\OldCrypt; use SP\DataModel\AccountExtData; use SP\DataModel\CategoryData; -use SP\DataModel\CustomerData; +use SP\DataModel\ClientData; use SP\DataModel\TagData; use SP\Log\Log; use SP\Mgmt\Categories\Category; @@ -196,10 +196,10 @@ abstract class ImportBase implements ImportInterface /** * Añadir un cliente y devolver el Id * - * @param CustomerData $CustomerData + * @param ClientData $CustomerData * @return Customer|null */ - protected function addCustomer(CustomerData $CustomerData) + protected function addCustomer(ClientData $CustomerData) { try { $Customer = Customer::getItem($CustomerData)->add(); diff --git a/lib/SP/Import/KeepassImport.php b/lib/SP/Import/KeepassImport.php index d3f00f9c..26f0cd42 100644 --- a/lib/SP/Import/KeepassImport.php +++ b/lib/SP/Import/KeepassImport.php @@ -28,7 +28,7 @@ use DOMElement; use DOMXPath; use SP\DataModel\AccountExtData; use SP\DataModel\CategoryData; -use SP\DataModel\CustomerData; +use SP\DataModel\ClientData; defined('APP_ROOT') || die(); @@ -52,7 +52,7 @@ class KeepassImport extends ImportBase */ public function doImport() { - $customerData = new CustomerData(null, 'KeePass'); + $customerData = new ClientData(null, 'KeePass'); $this->addCustomer($customerData); $this->customerId = $customerData->getCustomerId(); diff --git a/lib/SP/Import/KeepassXImport.php b/lib/SP/Import/KeepassXImport.php index 05fc0beb..94e26253 100644 --- a/lib/SP/Import/KeepassXImport.php +++ b/lib/SP/Import/KeepassXImport.php @@ -27,7 +27,7 @@ namespace SP\Import; use SimpleXMLElement; use SP\DataModel\AccountExtData; use SP\DataModel\CategoryData; -use SP\DataModel\CustomerData; +use SP\DataModel\ClientData; defined('APP_ROOT') || die(); @@ -52,7 +52,7 @@ class KeepassXImport extends ImportBase */ public function doImport() { - $customerData = new CustomerData(null, 'KeePassX'); + $customerData = new ClientData(null, 'KeePassX'); $this->addCustomer($customerData); $this->customerId = $customerData->getCustomerId(); diff --git a/lib/SP/Import/SyspassImport.php b/lib/SP/Import/SyspassImport.php index 6240e9a4..03bfdd6d 100644 --- a/lib/SP/Import/SyspassImport.php +++ b/lib/SP/Import/SyspassImport.php @@ -32,7 +32,7 @@ use SP\Core\Exceptions\SPException; use SP\Core\OldCrypt; use SP\DataModel\AccountExtData; use SP\DataModel\CategoryData; -use SP\DataModel\CustomerData; +use SP\DataModel\ClientData; use SP\DataModel\TagData; defined('APP_ROOT') || die(); @@ -206,7 +206,7 @@ class SyspassImport extends ImportBase return; } - $CustomerData = new CustomerData(); + $CustomerData = new ClientData(); foreach ($Customer->childNodes as $customerNode) { if (isset($customerNode->tagName)) { diff --git a/lib/SP/Mgmt/Customers/Customer.php b/lib/SP/Mgmt/Customers/Customer.php index 281d4eb5..298c055a 100644 --- a/lib/SP/Mgmt/Customers/Customer.php +++ b/lib/SP/Mgmt/Customers/Customer.php @@ -29,7 +29,7 @@ defined('APP_ROOT') || die(); use SP\Account\AccountUtil; use SP\Core\Exceptions\SPException; -use SP\DataModel\CustomerData; +use SP\DataModel\ClientData; use SP\Mgmt\ItemInterface; use SP\Mgmt\ItemSelectInterface; use SP\Mgmt\ItemTrait; @@ -39,7 +39,7 @@ use SP\Storage\QueryData; /** * Esta clase es la encargada de realizar las operaciones sobre los clientes de sysPass * - * @property CustomerData $itemData + * @property ClientData $itemData */ class Customer extends CustomerBase implements ItemInterface, ItemSelectInterface { @@ -156,7 +156,7 @@ class Customer extends CustomerBase implements ItemInterface, ItemSelectInterfac /** * @param $id int - * @return CustomerData + * @return ClientData */ public function getById($id) { @@ -224,7 +224,7 @@ class Customer extends CustomerBase implements ItemInterface, ItemSelectInterfac } /** - * @return CustomerData[] + * @return ClientData[] */ public function getAll() { @@ -269,7 +269,7 @@ class Customer extends CustomerBase implements ItemInterface, ItemSelectInterfac * Devolver los elementos con los ids especificados * * @param array $ids - * @return CustomerData[] + * @return ClientData[] */ public function getByIdBatch(array $ids) { diff --git a/lib/SP/Mgmt/Customers/CustomerBase.php b/lib/SP/Mgmt/Customers/CustomerBase.php index 2cf09fe9..45493b00 100644 --- a/lib/SP/Mgmt/Customers/CustomerBase.php +++ b/lib/SP/Mgmt/Customers/CustomerBase.php @@ -27,7 +27,7 @@ namespace SP\Mgmt\Customers; defined('APP_ROOT') || die(); use SP\Core\Exceptions\InvalidClassException; -use SP\DataModel\CustomerData; +use SP\DataModel\ClientData; use SP\Mgmt\ItemBaseInterface; use SP\Mgmt\ItemBaseTrait; @@ -48,6 +48,6 @@ abstract class CustomerBase implements ItemBaseInterface */ protected function init() { - $this->setDataModel(CustomerData::class); + $this->setDataModel(ClientData::class); } } \ No newline at end of file diff --git a/lib/SP/Mgmt/Files/File.php b/lib/SP/Mgmt/Files/File.php index c8a0959e..cc8131e1 100644 --- a/lib/SP/Mgmt/Files/File.php +++ b/lib/SP/Mgmt/Files/File.php @@ -60,13 +60,13 @@ class File extends FileBase implements ItemInterface, ItemSelectInterface { $query = /** @lang SQL */ 'INSERT INTO accFiles - SET accfile_accountId = ?, - accfile_name = ?, - accfile_type = ?, - accfile_size = ?, - accfile_content = ?, - accfile_extension = ?, - accfile_thumb = ?'; + SET accountId = ?, + name = ?, + type = ?, + size = ?, + content = ?, + extension = ?, + thumb = ?'; $Data = new QueryData(); $Data->setQuery($query); @@ -117,7 +117,7 @@ class File extends FileBase implements ItemInterface, ItemSelectInterface { // Eliminamos el archivo de la BBDD $query = /** @lang SQL */ - 'DELETE FROM accFiles WHERE accfile_id = ? LIMIT 1'; + 'DELETE FROM accFiles WHERE id = ? LIMIT 1'; $Data = new QueryData(); $Data->setQuery($query); @@ -140,17 +140,17 @@ class File extends FileBase implements ItemInterface, ItemSelectInterface public function getInfoById($id) { $query = /** @lang SQL */ - 'SELECT accfile_name, - accfile_size, - accfile_type, - accfile_accountId, - accfile_extension, + 'SELECT name, + size, + type, + accountId, + extension, account_name, customer_name FROM accFiles - LEFT JOIN accounts ON account_id = accfile_accountId + LEFT JOIN accounts ON account_id = accountId LEFT JOIN customers ON customer_id = account_customerId - WHERE accfile_id = ? LIMIT 1'; + WHERE id = ? LIMIT 1'; $Data = new QueryData(); $Data->setMapClassName(FileExtData::class); @@ -175,19 +175,19 @@ class File extends FileBase implements ItemInterface, ItemSelectInterface public function getById($id) { $query = /** @lang SQL */ - 'SELECT accfile_name, - accfile_size, - accfile_type, - accfile_accountId, - accfile_content, - accfile_thumb, - accfile_extension, + 'SELECT name, + size, + type, + accountId, + content, + thumb, + extension, account_name, customer_name FROM accFiles - LEFT JOIN accounts ON account_id = accfile_accountId + LEFT JOIN accounts ON account_id = accountId LEFT JOIN customers ON customer_id = account_customerId - WHERE accfile_id = ? LIMIT 1'; + WHERE id = ? LIMIT 1'; $Data = new QueryData(); $Data->setMapClassName(FileExtData::class); @@ -243,19 +243,19 @@ class File extends FileBase implements ItemInterface, ItemSelectInterface } $query = /** @lang SQL */ - 'SELECT accfile_name, - accfile_size, - accfile_type, - accfile_accountId, - accfile_content, - accfile_thumb, - accfile_extension, + 'SELECT name, + size, + type, + accountId, + content, + thumb, + extension, account_name, customer_name FROM accFiles - LEFT JOIN accounts ON account_id = accfile_accountId + LEFT JOIN accounts ON account_id = accountId LEFT JOIN customers ON customer_id = account_customerId - WHERE accfile_id IN (' . $this->getParamsFromArray($ids) . ')'; + WHERE id IN (' . $this->getParamsFromArray($ids) . ')'; $Data = new QueryData(); $Data->setMapClassName(FileExtData::class); diff --git a/lib/SP/Mgmt/Files/FileUtil.php b/lib/SP/Mgmt/Files/FileUtil.php index 7d5a3083..d81eae2a 100644 --- a/lib/SP/Mgmt/Files/FileUtil.php +++ b/lib/SP/Mgmt/Files/FileUtil.php @@ -49,13 +49,13 @@ class FileUtil */ public static function getAccountFiles($accountId) { - $query = 'SELECT accfile_id, - accfile_name, - accfile_size, - accfile_thumb, - accfile_type + $query = 'SELECT id, + name, + size, + thumb, + type FROM accFiles - WHERE accfile_accountId = ?'; + WHERE accountId = ?'; $Data = new QueryData(); $Data->setMapClassName(FileData::class); @@ -75,7 +75,7 @@ class FileUtil */ public static function countAccountFiles($accountId) { - $query = 'SELECT accfile_id FROM accFiles WHERE accfile_accountId = ?'; + $query = 'SELECT id FROM accFiles WHERE accountId = ?'; $Data = new QueryData(); $Data->setQuery($query); @@ -94,7 +94,7 @@ class FileUtil */ public static function deleteAccountFiles($accountId) { - $query = 'DELETE FROM accFiles WHERE accfile_accountId = ?'; + $query = 'DELETE FROM accFiles WHERE accountId = ?'; $Data = new QueryData(); $Data->setQuery($query); @@ -110,6 +110,6 @@ class FileUtil */ public static function isImage(FileData $FileData) { - return in_array(mb_strtoupper($FileData->getAccfileExtension()), FileUtil::$imageExtensions); + return in_array(mb_strtoupper($FileData->getExtension()), FileUtil::$imageExtensions); } } \ No newline at end of file diff --git a/lib/SP/Mgmt/Plugins/Plugin.php b/lib/SP/Mgmt/Plugins/Plugin.php index 5fac619f..92d0d9c5 100644 --- a/lib/SP/Mgmt/Plugins/Plugin.php +++ b/lib/SP/Mgmt/Plugins/Plugin.php @@ -50,7 +50,7 @@ class Plugin extends PluginBase implements ItemInterface public function add() { $query = /** @lang SQL */ - 'INSERT INTO plugins SET plugin_name = ?, plugin_data = ?, plugin_enabled = ?, plugin_available = ?'; + 'INSERT INTO plugins SET name = ?, data = ?, enabled = ?, available = ?'; $Data = new QueryData(); $Data->setQuery($query); @@ -77,7 +77,7 @@ class Plugin extends PluginBase implements ItemInterface public function delete($name) { $query = /** @lang SQL */ - 'DELETE FROM plugins WHERE plugin_name = ? LIMIT 1'; + 'DELETE FROM plugins WHERE name = ? LIMIT 1'; $Data = new QueryData(); $Data->setQuery($query); @@ -103,11 +103,11 @@ class Plugin extends PluginBase implements ItemInterface { $query = /** @lang SQL */ 'UPDATE plugins - SET plugin_name = ?, - plugin_data = ?, - plugin_enabled = ?, - plugin_available = ? - WHERE plugin_name = ? LIMIT 1'; + SET name = ?, + data = ?, + enabled = ?, + available = ? + WHERE name = ? LIMIT 1'; $Data = new QueryData(); $Data->setQuery($query); @@ -132,13 +132,13 @@ class Plugin extends PluginBase implements ItemInterface public function getById($id) { $query = /** @lang SQL */ - 'SELECT plugin_id, - plugin_name, - plugin_data, - plugin_enabled, - plugin_available + 'SELECT id, + name, + data, + enabled, + available FROM plugins - WHERE plugin_id = ? LIMIT 1'; + WHERE id = ? LIMIT 1'; $Data = new QueryData(); $Data->setMapClassName($this->getDataModel()); @@ -156,12 +156,12 @@ class Plugin extends PluginBase implements ItemInterface public function getAll() { $query = /** @lang SQL */ - 'SELECT plugin_id, - plugin_name, - plugin_enabled, - plugin_available + 'SELECT id, + name, + enabled, + available FROM plugins - ORDER BY plugin_name'; + ORDER BY name'; $Data = new QueryData(); $Data->setMapClassName($this->getDataModel()); @@ -204,13 +204,13 @@ class Plugin extends PluginBase implements ItemInterface public function getByName($name) { $query = /** @lang SQL */ - 'SELECT plugin_id, - plugin_name, - plugin_data, - plugin_enabled, - plugin_available + 'SELECT id, + name, + data, + enabled, + available FROM plugins - WHERE plugin_name = ? LIMIT 1'; + WHERE name = ? LIMIT 1'; $Data = new QueryData(); $Data->setMapClassName($this->getDataModel()); @@ -230,8 +230,8 @@ class Plugin extends PluginBase implements ItemInterface { $query = /** @lang SQL */ 'UPDATE plugins - SET plugin_enabled = ? - WHERE plugin_id = ? LIMIT 1'; + SET enabled = ? + WHERE id = ? LIMIT 1'; $Data = new QueryData(); $Data->setQuery($query); @@ -254,8 +254,8 @@ class Plugin extends PluginBase implements ItemInterface { $query = /** @lang SQL */ 'UPDATE plugins - SET plugin_enabled = ? - WHERE plugin_name = ? LIMIT 1'; + SET enabled = ? + WHERE name = ? LIMIT 1'; $Data = new QueryData(); $Data->setQuery($query); @@ -278,8 +278,8 @@ class Plugin extends PluginBase implements ItemInterface { $query = /** @lang SQL */ 'UPDATE plugins - SET plugin_available = ?, plugin_enabled = ? - WHERE plugin_id = ? LIMIT 1'; + SET available = ?, enabled = ? + WHERE id = ? LIMIT 1'; $Data = new QueryData(); $Data->setQuery($query); @@ -303,8 +303,8 @@ class Plugin extends PluginBase implements ItemInterface { $query = /** @lang SQL */ 'UPDATE plugins - SET plugin_available = ?, plugin_enabled = ? - WHERE plugin_name = ? LIMIT 1'; + SET available = ?, enabled = ? + WHERE name = ? LIMIT 1'; $Data = new QueryData(); $Data->setQuery($query); @@ -329,8 +329,8 @@ class Plugin extends PluginBase implements ItemInterface { $query = /** @lang SQL */ 'UPDATE plugins - SET plugin_data = NULL - WHERE plugin_id = ? LIMIT 1'; + SET data = NULL + WHERE id = ? LIMIT 1'; $Data = new QueryData(); $Data->setQuery($query); @@ -355,12 +355,12 @@ class Plugin extends PluginBase implements ItemInterface } $query = /** @lang SQL */ - 'SELECT plugin_id, - plugin_name, - plugin_enabled, - plugin_available + 'SELECT id, + name, + enabled, + available FROM plugins - WHERE plugin_id IN (' . $this->getParamsFromArray($ids) . ')'; + WHERE id IN (' . $this->getParamsFromArray($ids) . ')'; $Data = new QueryData(); $Data->setMapClassName($this->getDataModel()); @@ -378,7 +378,7 @@ class Plugin extends PluginBase implements ItemInterface public function getEnabled() { $query = /** @lang SQL */ - 'SELECT plugin_name FROM plugins WHERE plugin_enabled = 1'; + 'SELECT name FROM plugins WHERE enabled = 1'; $Data = new QueryData(); $Data->setQuery($query); diff --git a/lib/SP/Services/Account/AccountFileService.php b/lib/SP/Services/Account/AccountFileService.php new file mode 100644 index 00000000..2e5b36bb --- /dev/null +++ b/lib/SP/Services/Account/AccountFileService.php @@ -0,0 +1,341 @@ +. + */ + +namespace SP\Services\Account; + +use SP\Core\Exceptions\SPException; +use SP\DataModel\FileData; +use SP\DataModel\FileExtData; +use SP\DataModel\ItemSearchData; +use SP\Mgmt\Files\FileUtil; +use SP\Services\Service; +use SP\Services\ServiceItemInterface; +use SP\Services\ServiceItemTrait; +use SP\Storage\DbWrapper; +use SP\Storage\QueryData; +use SP\Util\ImageUtil; + +/** + * Class AccountFileService + * + * @package SP\Services\Account + */ +class AccountFileService extends Service implements ServiceItemInterface +{ + use ServiceItemTrait; + + /** + * Creates an item + * + * @param FileData $itemData + * @return mixed + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function create($itemData) + { + $query = /** @lang SQL */ + 'INSERT INTO accFiles + SET accountId = ?, + name = ?, + type = ?, + size = ?, + content = ?, + extension = ?, + thumb = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getAccountId()); + $Data->addParam($itemData->getName()); + $Data->addParam($itemData->getType()); + $Data->addParam($itemData->getSize()); + $Data->addParam($itemData->getContent()); + $Data->addParam($itemData->getExtension()); + $Data->setOnErrorMessage(__u('No se pudo guardar el archivo')); + + if (FileUtil::isImage($itemData)) { + $thumbnail = ImageUtil::createThumbnail($itemData->getContent()); + + $Data->addParam($thumbnail ?: 'no_thumb'); + } else { + $Data->addParam('no_thumb'); + } + +// $Log = new Log(); +// $LogMessage = $Log->getLogMessage(); +// $LogMessage->setAction(__('Subir Archivo', false)); +// $LogMessage->addDetails(__('Cuenta', false), AccountUtil::getAccountNameById($this->itemData->getAccfileAccountId())); +// $LogMessage->addDetails(__('Archivo', false), $this->itemData->getAccfileName()); +// $LogMessage->addDetails(__('Tipo', false), $this->itemData->getAccfileType()); +// $LogMessage->addDetails(__('Tamaño', false), $this->itemData->getRoundSize() . 'KB'); +// +// DbWrapper::getQuery($Data); +// +// $LogMessage->addDescription(__('Archivo subido', false)); +// $Log->writeLog(); +// +// Email::sendEmail($LogMessage); + + DbWrapper::getQuery($Data, $this->db); + + return $this->db->getLastId(); + } + + /** + * Updates an item + * + * @param mixed $itemData + * @return mixed + */ + public function update($itemData) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * @param $id + * @return FileExtData + */ + public function getInfoById($id) + { + $query = /** @lang SQL */ + 'SELECT name, + size, + type, + accountId, + extension, + account_name, + customer_name + FROM accFiles + INNER JOIN accounts ON account_id = accountId + INNER JOIN customers ON customer_id = account_customerId + WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setMapClassName(FileExtData::class); + $Data->setQuery($query); + $Data->addParam($id); + + return DbWrapper::getResults($Data, $this->db); + } + + /** + * Returns the item for given id + * + * @param int $id + * @return mixed + */ + public function getById($id) + { + $query = /** @lang SQL */ + 'SELECT name, + size, + type, + accountId, + content, + thumb, + extension, + account_name, + customer_name + FROM accFiles + INNER JOIN accounts ON account_id = accountId + INNER JOIN customers ON customer_id = account_customerId + WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setMapClassName(FileExtData::class); + $Data->setQuery($query); + $Data->addParam($id); + + return DbWrapper::getResults($Data, $this->db); + } + + /** + * Returns all the items + * + * @return FileExtData[] + */ + public function getAll() + { + $query = /** @lang SQL */ + 'SELECT name, + size, + type, + accountId, + content, + thumb, + extension, + account_name, + customer_name + FROM accFiles + INNER JOIN accounts ON account_id = accountId + INNER JOIN customers ON customer_id = account_customerId'; + + $Data = new QueryData(); + $Data->setMapClassName(FileExtData::class); + $Data->setQuery($query); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Returns all the items for given ids + * + * @param array $ids + * @return array + */ + public function getByIdBatch(array $ids) + { + $query = /** @lang SQL */ + 'SELECT name, + size, + type, + accountId, + content, + thumb, + extension, + account_name, + customer_name + FROM accFiles + LEFT JOIN accounts ON account_id = accountId + LEFT JOIN customers ON customer_id = account_customerId + WHERE id IN (' . $this->getParamsFromArray($ids) . ')'; + + $Data = new QueryData(); + $Data->setMapClassName(FileExtData::class); + $Data->setQuery($query); + $Data->setParams($ids); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Deletes all the items for given ids + * + * @param array $ids + * @return void + * @throws SPException + */ + public function deleteByIdBatch(array $ids) + { + foreach ($ids as $id) { + $this->delete($id); + } + } + + /** + * Deletes an item + * + * @param $id + * @return AccountFileService + * @throws SPException + */ + public function delete($id) + { + // Eliminamos el archivo de la BBDD + $query = /** @lang SQL */ + 'DELETE FROM accFiles WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + $Data->setOnErrorMessage(__u('Error al eliminar el archivo')); + + DbWrapper::getQuery($Data, $this->db); + + if ($Data->getQueryNumRows() === 0) { + throw new SPException(SPException::SP_INFO, __u('Archivo no encontrado')); + } + + return $this; + } + + /** + * Checks whether the item is in use or not + * + * @param $id int + */ + public function checkInUse($id) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Checks whether the item is duplicated on updating + * + * @param mixed $itemData + */ + public function checkDuplicatedOnUpdate($itemData) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Checks whether the item is duplicated on adding + * + * @param mixed $itemData + */ + public function checkDuplicatedOnAdd($itemData) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Searches for items by a given filter + * + * @param ItemSearchData $SearchData + * @return mixed + */ + public function search(ItemSearchData $SearchData) + { + $Data = new QueryData(); + $Data->setMapClassName(FileExtData::class); + $Data->setSelect('id, name, CONCAT(ROUND(size/1000, 2), "KB") AS size, thumb, type, account_name, customer_name'); + $Data->setFrom('accFiles INNER JOIN accounts ON accountId = account_id INNER JOIN customers ON customer_id = account_customerId'); + $Data->setOrder('name'); + + if ($SearchData->getSeachString() !== '') { + $Data->setWhere('name LIKE ? OR type LIKE ? OR account_name LIKE ? OR customer_name LIKE ?'); + + $search = '%' . $SearchData->getSeachString() . '%'; + $Data->addParam($search); + $Data->addParam($search); + $Data->addParam($search); + $Data->addParam($search); + } + + $Data->setLimit('?,?'); + $Data->addParam($SearchData->getLimitStart()); + $Data->addParam($SearchData->getLimitCount()); + + DbWrapper::setFullRowCount(); + + $queryRes = DbWrapper::getResultsArray($Data, $this->db); + + $queryRes['count'] = $Data->getQueryNumRows(); + + return $queryRes; + } +} \ No newline at end of file diff --git a/lib/SP/Services/Account/AccountHistoryService.php b/lib/SP/Services/Account/AccountHistoryService.php index db61af2a..a3b89c2e 100644 --- a/lib/SP/Services/Account/AccountHistoryService.php +++ b/lib/SP/Services/Account/AccountHistoryService.php @@ -236,7 +236,7 @@ class AccountHistoryService extends Service implements ServiceItemInterface */ public function update($itemData) { - throw new \RuntimeException('Unimplemented'); + throw new \RuntimeException('Not implemented'); } /** @@ -344,7 +344,7 @@ class AccountHistoryService extends Service implements ServiceItemInterface */ public function getByIdBatch(array $ids) { - throw new \RuntimeException('Unimplemented'); + throw new \RuntimeException('Not implemented'); } /** @@ -355,7 +355,7 @@ class AccountHistoryService extends Service implements ServiceItemInterface */ public function deleteByIdBatch(array $ids) { - throw new \RuntimeException('Unimplemented'); + throw new \RuntimeException('Not implemented'); } /** @@ -366,7 +366,7 @@ class AccountHistoryService extends Service implements ServiceItemInterface */ public function checkInUse($id) { - throw new \RuntimeException('Unimplemented'); + throw new \RuntimeException('Not implemented'); } /** @@ -377,7 +377,7 @@ class AccountHistoryService extends Service implements ServiceItemInterface */ public function checkDuplicatedOnUpdate($itemData) { - throw new \RuntimeException('Unimplemented'); + throw new \RuntimeException('Not implemented'); } /** @@ -388,7 +388,7 @@ class AccountHistoryService extends Service implements ServiceItemInterface */ public function checkDuplicatedOnAdd($itemData) { - throw new \RuntimeException('Unimplemented'); + throw new \RuntimeException('Not implemented'); } /** @@ -399,6 +399,29 @@ class AccountHistoryService extends Service implements ServiceItemInterface */ public function search(ItemSearchData $SearchData) { - throw new \RuntimeException('Unimplemented'); + $Data = new QueryData(); + $Data->setSelect('acchistory_id, acchistory_name, customer_name, IFNULL(acchistory_dateEdit,acchistory_dateAdd) as acchistory_date, BIN(acchistory_isModify) as acchistory_isModify, BIN(acchistory_isDeleted) as acchistory_isDeleted'); + $Data->setFrom('accHistory LEFT JOIN customers ON acchistory_customerId = customer_id'); + $Data->setOrder('acchistory_name, customer_name, acchistory_id DESC'); + + if ($SearchData->getSeachString() !== '') { + $Data->setWhere('acchistory_name LIKE ? OR customer_name LIKE ?'); + + $search = '%' . $SearchData->getSeachString() . '%'; + $Data->addParam($search); + $Data->addParam($search); + } + + $Data->setLimit('?,?'); + $Data->addParam($SearchData->getLimitStart()); + $Data->addParam($SearchData->getLimitCount()); + + DbWrapper::setFullRowCount(); + + $queryRes = DbWrapper::getResultsArray($Data, $this->db); + + $queryRes['count'] = $Data->getQueryNumRows(); + + return $queryRes; } } \ No newline at end of file diff --git a/lib/SP/Services/Account/AccountService.php b/lib/SP/Services/Account/AccountService.php index 4a44b5e1..b39b6fe9 100644 --- a/lib/SP/Services/Account/AccountService.php +++ b/lib/SP/Services/Account/AccountService.php @@ -270,18 +270,6 @@ class AccountService extends Service implements ServiceItemInterface } } - /** - * Actualiza los datos de una cuenta en la BBDD. - * - * @param AccountExtData $accountData - * @return AccountExtData - * @throws \SP\Core\Exceptions\SPException - */ - public function edit(AccountExtData $accountData) - { - - } - /** * Actualiza la clave de una cuenta en la BBDD. * @@ -532,66 +520,60 @@ class AccountService extends Service implements ServiceItemInterface /** * Returns all the items * - * @return array */ public function getAll() { - // TODO: Implement getAll() method. + throw new \RuntimeException('Not implemented'); } /** * Returns all the items for given ids * * @param array $ids - * @return array */ public function getByIdBatch(array $ids) { - // TODO: Implement getByIdBatch() method. + throw new \RuntimeException('Not implemented'); } /** * Deletes all the items for given ids * * @param array $ids - * @return $this */ public function deleteByIdBatch(array $ids) { - // TODO: Implement deleteByIdBatch() method. + throw new \RuntimeException('Not implemented'); } /** * Checks whether the item is in use or not * * @param $id int - * @return bool */ public function checkInUse($id) { - // TODO: Implement checkInUse() method. + throw new \RuntimeException('Not implemented'); } /** * Checks whether the item is duplicated on updating * * @param mixed $itemData - * @return bool */ public function checkDuplicatedOnUpdate($itemData) { - // TODO: Implement checkDuplicatedOnUpdate() method. + throw new \RuntimeException('Not implemented'); } /** * Checks whether the item is duplicated on adding * * @param mixed $itemData - * @return bool */ public function checkDuplicatedOnAdd($itemData) { - // TODO: Implement checkDuplicatedOnAdd() method. + throw new \RuntimeException('Not implemented'); } /** @@ -602,7 +584,30 @@ class AccountService extends Service implements ServiceItemInterface */ public function search(ItemSearchData $SearchData) { - // TODO: Implement search() method. + $Data = new QueryData(); + $Data->setSelect('account_id, account_name, customer_name'); + $Data->setFrom('accounts LEFT JOIN customers ON account_customerId = customer_id'); + $Data->setOrder('account_name'); + + if ($SearchData->getSeachString() !== '') { + $Data->setWhere('account_name LIKE ? OR customer_name LIKE ?'); + + $search = '%' . $SearchData->getSeachString() . '%'; + $Data->addParam($search); + $Data->addParam($search); + } + + $Data->setLimit('?,?'); + $Data->addParam($SearchData->getLimitStart()); + $Data->addParam($SearchData->getLimitCount()); + + DbWrapper::setFullRowCount(); + + $queryRes = DbWrapper::getResultsArray($Data, $this->db); + + $queryRes['count'] = $Data->getQueryNumRows(); + + return $queryRes; } /** diff --git a/lib/SP/Services/Category/CategoryService.php b/lib/SP/Services/Category/CategoryService.php new file mode 100644 index 00000000..fe1306aa --- /dev/null +++ b/lib/SP/Services/Category/CategoryService.php @@ -0,0 +1,310 @@ +. + */ + +namespace SP\Services\Category; + + +use SP\Core\Exceptions\SPException; +use SP\DataModel\CategoryData; +use SP\DataModel\ItemSearchData; +use SP\Services\Service; +use SP\Services\ServiceItemInterface; +use SP\Services\ServiceItemTrait; +use SP\Storage\DbWrapper; +use SP\Storage\QueryData; + +/** + * Class CategoryService + * + * @package SP\Services\Category + */ +class CategoryService extends Service implements ServiceItemInterface +{ + use ServiceItemTrait; + + /** + * Creates an item + * + * @param CategoryData $itemData + * @return mixed + * @throws SPException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function create($itemData) + { + if ($this->checkDuplicatedOnAdd($itemData)) { + throw new SPException(SPException::SP_WARNING, __u('Categoría duplicada')); + } + + $query = /** @lang SQL */ + 'INSERT INTO categories SET category_name = ?, category_description = ?, category_hash = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getCategoryName()); + $Data->addParam($itemData->getCategoryDescription()); + $Data->addParam($this->makeItemHash($itemData->getCategoryName())); + $Data->setOnErrorMessage(__u('Error al crear la categoría')); + + DbWrapper::getQuery($Data, $this->db); + + return $this->db->getLastId(); + } + + /** + * Checks whether the item is duplicated on adding + * + * @param CategoryData $itemData + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function checkDuplicatedOnAdd($itemData) + { + $query = /** @lang SQL */ + 'SELECT category_id FROM categories WHERE category_hash = ? OR category_name = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($this->makeItemHash($itemData->getCategoryName())); + $Data->addParam($itemData->getCategoryName()); + $Data->addParam($itemData->getCategoryId()); + + DbWrapper::getQuery($Data, $this->db); + + return $Data->getQueryNumRows() > 0; + } + + /** + * Updates an item + * + * @param CategoryData $itemData + * @return mixed + * @throws SPException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function update($itemData) + { + if ($this->checkDuplicatedOnUpdate($itemData)) { + throw new SPException(SPException::SP_WARNING, __u('Nombre de categoría duplicado')); + } + + $query = /** @lang SQL */ + 'UPDATE categories + SET category_name = ?, + category_description = ?, + category_hash = ? + WHERE category_id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getCategoryName()); + $Data->addParam($itemData->getCategoryDescription()); + $Data->addParam($this->makeItemHash($itemData->getCategoryName())); + $Data->addParam($itemData->getCategoryId()); + $Data->setOnErrorMessage(__u('Error al actualizar la categoría')); + + DbWrapper::getQuery($Data, $this->db); + + return $this; + } + + /** + * Checks whether the item is duplicated on updating + * + * @param CategoryData $itemData + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function checkDuplicatedOnUpdate($itemData) + { + $query = /** @lang SQL */ + 'SELECT category_id FROM categories WHERE (category_hash = ? OR category_name = ?) AND category_id <> ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($this->makeItemHash($itemData->getCategoryName())); + $Data->addParam($itemData->getCategoryName()); + $Data->addParam($itemData->getCategoryId()); + + DbWrapper::getQuery($Data, $this->db); + + return $Data->getQueryNumRows() > 0; + } + + /** + * Returns the item for given id + * + * @param int $id + * @return mixed + */ + public function getById($id) + { + $query = /** @lang SQL */ + 'SELECT category_id, category_name, category_description FROM categories WHERE category_id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + $Data->setMapClassName(CategoryData::class); + + return DbWrapper::getResults($Data, $this->db); + } + + /** + * Returns all the items + * + * @return array + */ + public function getAll() + { + $query = /** @lang SQL */ + 'SELECT category_id, category_name, category_description, category_hash FROM categories ORDER BY category_name'; + + $Data = new QueryData(); + $Data->setMapClassName(CategoryData::class); + $Data->setQuery($query); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Returns all the items for given ids + * + * @param array $ids + * @return array + */ + public function getByIdBatch(array $ids) + { + $query = /** @lang SQL */ + 'SELECT category_id, category_name, category_description FROM categories WHERE category_id IN (' . $this->getParamsFromArray($ids) . ')'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->setParams($ids); + $Data->setMapClassName(CategoryData::class); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Deletes all the items for given ids + * + * @param array $ids + * @return void + * @throws SPException + */ + public function deleteByIdBatch(array $ids) + { + foreach ($ids as $id) { + $this->delete($id); + } + } + + /** + * Deletes an item + * + * @param $id + * @return CategoryService + * @throws SPException + */ + public function delete($id) + { + $query = /** @lang SQL */ + 'DELETE FROM categories WHERE category_id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + $Data->setOnErrorMessage(__u('Error al eliminar la categoría')); + + DbWrapper::getQuery($Data, $this->db); + + if ($Data->getQueryNumRows() === 0) { + throw new SPException(SPException::SP_INFO, __u('Categoría no encontrada')); + } + + return $this; + } + + /** + * Checks whether the item is in use or not + * + * @param $id int + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function checkInUse($id) + { + $query = /** @lang SQL */ + 'SELECT account_id FROM accounts WHERE account_categoryId = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + + DbWrapper::getQuery($Data, $this->db); + + return $Data->getQueryNumRows() > 0; + } + + /** + * Searches for items by a given filter + * + * @param ItemSearchData $SearchData + * @return mixed + */ + public function search(ItemSearchData $SearchData) + { + $Data = new QueryData(); + $Data->setSelect('category_id, category_name, category_description'); + $Data->setFrom('categories'); + $Data->setOrder('category_name'); + + if ($SearchData->getSeachString() !== '') { + $Data->setWhere('category_name LIKE ? OR category_description LIKE ?'); + + $search = '%' . $SearchData->getSeachString() . '%'; + $Data->addParam($search); + $Data->addParam($search); + } + + $Data->setLimit('?,?'); + $Data->addParam($SearchData->getLimitStart()); + $Data->addParam($SearchData->getLimitCount()); + + DbWrapper::setFullRowCount(); + + /** @var array $queryRes */ + $queryRes = DbWrapper::getResultsArray($Data, $this->db); + + $queryRes['count'] = $Data->getQueryNumRows(); + + return $queryRes; + } +} \ No newline at end of file diff --git a/lib/SP/Services/Client/ClientService.php b/lib/SP/Services/Client/ClientService.php new file mode 100644 index 00000000..8f620172 --- /dev/null +++ b/lib/SP/Services/Client/ClientService.php @@ -0,0 +1,344 @@ +. + */ + +namespace SP\Services\Client; + + +use SP\Account\AccountUtil; +use SP\Core\Exceptions\SPException; +use SP\DataModel\ClientData; +use SP\DataModel\ItemSearchData; +use SP\Services\Service; +use SP\Services\ServiceItemInterface; +use SP\Services\ServiceItemTrait; +use SP\Storage\DbWrapper; +use SP\Storage\QueryData; + +/** + * Class ClientService + * + * @package SP\Services\Client + */ +class ClientService extends Service implements ServiceItemInterface +{ + use ServiceItemTrait; + + /** + * Creates an item + * + * @param ClientData $itemData + * @return mixed + * @throws SPException + */ + public function create($itemData) + { + if ($this->checkDuplicatedOnAdd($itemData)) { + throw new SPException(SPException::SP_WARNING, __u('Cliente duplicado')); + } + + $query = /** @lang SQL */ + 'INSERT INTO customers + SET customer_name = ?, + customer_description = ?, + customer_isGlobal = ?, + customer_hash = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getCustomerName()); + $Data->addParam($itemData->getCustomerDescription()); + $Data->addParam($itemData->getCustomerIsGlobal()); + $Data->addParam($this->makeItemHash($itemData->getCustomerName())); + $Data->setOnErrorMessage(__u('Error al crear el cliente')); + + DbWrapper::getQuery($Data, $this->db); + + return $this->db->getLastId(); + } + + /** + * Checks whether the item is duplicated on adding + * + * @param ClientData $itemData + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function checkDuplicatedOnAdd($itemData) + { + $query = /** @lang SQL */ + 'SELECT customer_id FROM customers WHERE customer_hash = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($this->makeItemHash($itemData->getCustomerName())); + + DbWrapper::getQuery($Data, $this->db); + + return $Data->getQueryNumRows() > 0; + } + + /** + * Updates an item + * + * @param ClientData $itemData + * @return mixed + * @throws SPException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function update($itemData) + { + if ($this->checkDuplicatedOnUpdate($itemData)) { + throw new SPException(SPException::SP_WARNING, __u('Cliente duplicado')); + } + + $query = /** @lang SQL */ + 'UPDATE customers + SET customer_name = ?, + customer_description = ?, + customer_isGlobal = ?, + customer_hash = ? + WHERE customer_id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getCustomerName()); + $Data->addParam($itemData->getCustomerDescription()); + $Data->addParam($itemData->getCustomerIsGlobal()); + $Data->addParam($this->makeItemHash($itemData->getCustomerName())); + $Data->addParam($itemData->getCustomerId()); + $Data->setOnErrorMessage(__u('Error al actualizar el cliente')); + + DbWrapper::getQuery($Data, $this->db); + + return $this; + } + + /** + * Checks whether the item is duplicated on updating + * + * @param ClientData $itemData + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function checkDuplicatedOnUpdate($itemData) + { + $query = /** @lang SQL */ + 'SELECT customer_id FROM customers WHERE customer_hash = ? AND customer_id <> ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($this->makeItemHash($itemData->getCustomerName())); + $Data->addParam($itemData->getCustomerId()); + + DbWrapper::getQuery($Data, $this->db); + + return $Data->getQueryNumRows() > 0; + } + + /** + * Returns the item for given id + * + * @param int $id + * @return mixed + */ + public function getById($id) + { + $query = /** @lang SQL */ + 'SELECT customer_id, customer_name, customer_description, customer_isGlobal FROM customers WHERE customer_id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setMapClassName(ClientData::class); + $Data->setQuery($query); + $Data->addParam($id); + + return DbWrapper::getResults($Data, $this->db); + } + + /** + * Returns all the items + * + * @return array + */ + public function getAll() + { + $query = /** @lang SQL */ + 'SELECT customer_id, customer_name, customer_description, customer_isGlobal FROM customers ORDER BY customer_name'; + + $Data = new QueryData(); + $Data->setMapClassName(ClientData::class); + $Data->setQuery($query); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Returns all the items for given ids + * + * @param array $ids + * @return array + */ + public function getByIdBatch(array $ids) + { + $query = /** @lang SQL */ + 'SELECT customer_id, customer_name, customer_description, customer_isGlobal FROM customers WHERE customer_id IN (' . $this->getParamsFromArray($ids) . ')'; + + $Data = new QueryData(); + $Data->setMapClassName(ClientData::class); + $Data->setQuery($query); + $Data->setParams($ids); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Deletes all the items for given ids + * + * @param array $ids + * @return void + * @throws SPException + */ + public function deleteByIdBatch(array $ids) + { + foreach ($ids as $id) { + $this->delete($id); + } + } + + /** + * Deletes an item + * + * @param $id + * @return ClientService + * @throws SPException + */ + public function delete($id) + { + if ($this->checkInUse($id)) { + throw new SPException(SPException::SP_WARNING, __u('No es posible eliminar')); + } + + $query = /** @lang SQL */ + 'DELETE FROM customers WHERE customer_id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + $Data->setOnErrorMessage(__u('Error al eliminar el cliente')); + + DbWrapper::getQuery($Data, $this->db); + + if ($Data->getQueryNumRows() === 0) { + throw new SPException(SPException::SP_INFO, __u('Cliente no encontrado')); + } + + return $this; + } + + /** + * Checks whether the item is in use or not + * + * @param $id int + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function checkInUse($id) + { + $query = /** @lang SQL */ + 'SELECT account_id FROM accounts WHERE account_customerId = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + + DbWrapper::getQuery($Data, $this->db); + + return $Data->getQueryNumRows() > 0; + } + + /** + * Searches for items by a given filter + * + * @param ItemSearchData $SearchData + * @return ClientData[] + */ + public function search(ItemSearchData $SearchData) + { + $Data = new QueryData(); + $Data->setMapClassName(ClientData::class); + $Data->setSelect('customer_id, customer_name, customer_description, customer_isGlobal'); + $Data->setFrom('customers'); + $Data->setOrder('customer_name'); + + if ($SearchData->getSeachString() !== '') { + $Data->setWhere('customer_name LIKE ? OR customer_description LIKE ?'); + + $search = '%' . $SearchData->getSeachString() . '%'; + $Data->addParam($search); + $Data->addParam($search); + } + + $Data->setLimit('?,?'); + $Data->addParam($SearchData->getLimitStart()); + $Data->addParam($SearchData->getLimitCount()); + + DbWrapper::setFullRowCount(); + + $queryRes = DbWrapper::getResultsArray($Data, $this->db); + + $queryRes['count'] = $Data->getQueryNumRows(); + + return $queryRes; + } + + /** + * Devolver los clientes visibles por el usuario + * + * @return array + */ + public function getItemsForSelectByUser() + { + $Data = new QueryData(); + + // Acotar los resultados por usuario + $queryWhere = AccountUtil::getAccountFilterUser($Data, $this->session); + + $query = /** @lang SQL */ + 'SELECT customer_id AS id, customer_name AS name + FROM accounts + RIGHT JOIN customers ON customer_id = account_customerId + WHERE account_customerId IS NULL + OR customer_isGlobal = 1 + OR (' . implode(' AND ', $queryWhere) . ') + GROUP BY customer_id + ORDER BY customer_name'; + + $Data->setQuery($query); + + return DbWrapper::getResultsArray($Data, $this->db); + } +} \ No newline at end of file diff --git a/lib/SP/Services/CustomField/CustomFieldDefService.php b/lib/SP/Services/CustomField/CustomFieldDefService.php new file mode 100644 index 00000000..73571741 --- /dev/null +++ b/lib/SP/Services/CustomField/CustomFieldDefService.php @@ -0,0 +1,311 @@ +. + */ + +namespace SP\Services\CustomField; + +use SP\Core\Acl\ActionsInterface; +use SP\Core\Exceptions\SPException; +use SP\DataModel\CustomFieldDefData; +use SP\DataModel\ItemSearchData; +use SP\Services\Service; +use SP\Services\ServiceItemInterface; +use SP\Services\ServiceItemTrait; +use SP\Storage\DbWrapper; +use SP\Storage\QueryData; + +/** + * Class CustomFieldDefService + * + * @package SP\Services\CustomField + */ +class CustomFieldDefService extends Service implements ServiceItemInterface +{ + use ServiceItemTrait; + + /** + * @param $id + * @return mixed + */ + public static function getFieldModuleById($id) + { + $modules = self::getFieldModules(); + + return isset($modules[$id]) ? $modules[$id] : $id; + } + + /** + * Devuelve los módulos disponibles para los campos personalizados + * + * @return array + */ + public static function getFieldModules() + { + $modules = [ + ActionsInterface::ACCOUNT => __('Cuentas'), + ActionsInterface::CATEGORY => __('Categorías'), + ActionsInterface::CLIENT => __('Clientes'), + ActionsInterface::USER => __('Usuarios'), + ActionsInterface::GROUP => __('Grupos') + + ]; + + return $modules; + } + + /** + * Creates an item + * + * @param CustomFieldDefData $itemData + * @return mixed + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function create($itemData) + { + $query = /** @lang SQL */ + 'INSERT INTO customFieldsDef SET name = ?, moduleId = ?, required = ?, help = ?, showInList = ?, typeId = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getName()); + $Data->addParam($itemData->getModuleId()); + $Data->addParam($itemData->getRequired()); + $Data->addParam($itemData->getHelp()); + $Data->addParam($itemData->getShowInList()); + $Data->addParam($itemData->getTypeId()); + $Data->setOnErrorMessage(__u('Error al crear el campo personalizado')); + + DbWrapper::getQuery($Data, $this->db); + + return $this->db->getLastId(); + } + + /** + * Updates an item + * + * @param CustomFieldDefData $itemData + * @return mixed + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function update($itemData) + { + $query = /** @lang SQL */ + 'UPDATE customFieldsDef + SET name = ?, moduleId = ?, required = ?, help = ?, showInList = ?, typeId = ? + WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getName()); + $Data->addParam($itemData->getModuleId()); + $Data->addParam($itemData->getRequired()); + $Data->addParam($itemData->getHelp()); + $Data->addParam($itemData->getShowInList()); + $Data->addParam($itemData->getTypeId()); + $Data->addParam($itemData->getId()); + $Data->setOnErrorMessage(__u('Error al actualizar el campo personalizado')); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Returns the item for given id + * + * @param int $id + * @return CustomFieldDefData + */ + public function getById($id) + { + $query = /** @lang SQL */ + 'SELECT id, name, moduleId, required, help, showInList, typeId + FROM customFieldsDef + WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setMapClassName(CustomFieldDefData::class); + $Data->setQuery($query); + $Data->addParam($id); + + return DbWrapper::getResults($Data, $this->db); + } + + /** + * Returns all the items + * + * @return CustomFieldDefData[] + */ + public function getAll() + { + $query = /** @lang SQL */ + 'SELECT id, name, moduleId, required, help, showInList + FROM customFieldsDef + ORDER BY moduleId'; + + $Data = new QueryData(); + $Data->setMapClassName(CustomFieldDefData::class); + $Data->setQuery($query); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Returns all the items for given ids + * + * @param array $ids + * @return array + */ + public function getByIdBatch(array $ids) + { + $query = /** @lang SQL */ + 'SELECT id, name, moduleId, required, help, showInList, typeId + FROM customFieldsDef + WHERE id IN (' . $this->getParamsFromArray($ids) . ')'; + + $Data = new QueryData(); + $Data->setMapClassName(CustomFieldDefData::class); + $Data->setQuery($query); + $Data->setParams($ids); + + return DbWrapper::getResults($Data, $this->db); + } + + /** + * Deletes all the items for given ids + * + * @param array $ids + * @return void + * @throws SPException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function deleteByIdBatch(array $ids) + { + foreach ($ids as $id) { + $this->delete($id); + } + } + + /** + * Deletes an item + * + * @param $id + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + * @throws \SP\Core\Exceptions\SPException + */ + public function delete($id) + { + if ($this->deleteItemsDataForDefinition($id) === false) { + throw new SPException(SPException::SP_ERROR, __u('Error al eliminar el campo personalizado')); + } + + $query = /** @lang SQL */ + 'DELETE FROM customFieldsDef WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + $Data->setOnErrorMessage(__u('Error al eliminar el campo personalizado')); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Eliminar los datos de los elementos de una definición + * + * @param $id + * @return bool + * @throws \SP\Core\Exceptions\SPException + */ + protected function deleteItemsDataForDefinition($id) + { + $query = /** @lang SQL */ + 'DELETE FROM customFieldsData WHERE id = ?'; + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Checks whether the item is in use or not + * + * @param $id int + */ + public function checkInUse($id) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Checks whether the item is duplicated on updating + * + * @param mixed $itemData + */ + public function checkDuplicatedOnUpdate($itemData) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Checks whether the item is duplicated on adding + * + * @param mixed $itemData + */ + public function checkDuplicatedOnAdd($itemData) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Searches for items by a given filter + * + * @param ItemSearchData $SearchData + * @return CustomFieldDefData[] + */ + public function search(ItemSearchData $SearchData) + { + $Data = new QueryData(); + $Data->setMapClassName(CustomFieldDefData::class); + $Data->setSelect('a.id, a.name, a.moduleId, a.required, a.help, a.showInList, a.typeId, b.name AS typeName'); + $Data->setFrom('customFieldsDef a INNER JOIN customFieldsType b ON b.id = a.typeId'); + $Data->setOrder('moduleId'); + + $Data->setLimit('?,?'); + $Data->addParam($SearchData->getLimitStart()); + $Data->addParam($SearchData->getLimitCount()); + + DbWrapper::setFullRowCount(); + + /** @var CustomFieldDefData[] $queryRes */ + $queryRes = DbWrapper::getResultsArray($Data, $this->db); + + $queryRes['count'] = $Data->getQueryNumRows(); + + return $queryRes; + } +} \ No newline at end of file diff --git a/lib/SP/Services/CustomField/CustomFieldService.php b/lib/SP/Services/CustomField/CustomFieldService.php index e0fee2bc..5e430acd 100644 --- a/lib/SP/Services/CustomField/CustomFieldService.php +++ b/lib/SP/Services/CustomField/CustomFieldService.php @@ -30,14 +30,11 @@ use SP\Core\Crypt\Session as CryptSession; use SP\Core\Exceptions\QueryException; use SP\Core\Exceptions\SPException; use SP\DataModel\CustomFieldData; -use SP\DataModel\CustomFieldDefData; use SP\DataModel\ItemSearchData; -use SP\Mgmt\CustomFields\CustomFieldTypes; use SP\Services\Service; use SP\Services\ServiceItemInterface; use SP\Storage\DbWrapper; use SP\Storage\QueryData; -use SP\Util\Util; /** * Class CustomFieldService @@ -47,107 +44,54 @@ use SP\Util\Util; class CustomFieldService extends Service implements ServiceItemInterface { /** - * Guardar los datos de los campos personalizados del módulo + * Returns the form Id for a given name * - * @param array $customFields - * @param int $itemId - * @param int $moduleId - * @throws \SP\Core\Exceptions\SPException + * @param $name + * @return string */ - public function addCustomFieldData($customFields, $itemId, $moduleId) + public static function getFormIdForName($name) { - if (is_array($customFields)) { - $customFieldData = new CustomFieldData(); - $customFieldData->setId($itemId); - $customFieldData->setModule($moduleId); - - try { - foreach ($customFields as $id => $value) { - $customFieldData->setDefinitionId($id); - $customFieldData->setValue($value); - - $this->create($customFieldData); - } - } catch (CryptoException $e) { - throw new SPException(SPException::SP_ERROR, __u('Error interno')); - } - } + return 'cf_' . strtolower(preg_replace('/\W*/', '', $name)); } /** - * Creates an item + * Desencriptar y formatear los datos del campo * - * @param mixed $itemData - * @return bool - * @throws CryptoException - * @throws QueryException - * @throws \SP\Core\Exceptions\ConstraintException + * @param CustomFieldData $CustomFieldData + * @return string + * @throws \Defuse\Crypto\Exception\CryptoException */ - public function create($itemData) + public static function unencryptData(CustomFieldData $CustomFieldData) { - if ($itemData->getValue() === '') { - return true; + if ($CustomFieldData->getData() !== '') { + $securedKey = Crypt::unlockSecuredKey($CustomFieldData->getKey(), CryptSession::getSessionKey()); + + return self::formatValue(Crypt::decrypt($CustomFieldData->getData(), $securedKey)); } - $sessionKey = CryptSession::getSessionKey(); - $securedKey = Crypt::makeSecuredKey($sessionKey); - - if (strlen($securedKey) > 1000) { - throw new QueryException(SPException::SP_ERROR, __u('Error interno')); - } - - $query = /** @lang SQL */ - 'INSERT INTO customFieldsData SET - customfielddata_itemId = ?, - customfielddata_moduleId = ?, - customfielddata_defId = ?, - customfielddata_data = ?, - customfielddata_key = ?'; - - $Data = new QueryData(); - $Data->setQuery($query); - $Data->addParam($itemData->getId()); - $Data->addParam($itemData->getModule()); - $Data->addParam($itemData->getDefinitionId()); - $Data->addParam(Crypt::encrypt($itemData->getValue(), $securedKey, $sessionKey)); - $Data->addParam($securedKey); - - return DbWrapper::getQuery($Data, $this->db); + return ''; } /** - * Actualizar los datos de los campos personalizados del módulo + * Formatear el valor del campo * - * @param array $customFields - * @param int $itemId - * @param int $moduleId - * @throws \SP\Core\Exceptions\SPException + * @param $value string El valor del campo + * @return string */ - public function updateCustomFieldData($customFields, $itemId, $moduleId) + public static function formatValue($value) { - if (is_array($customFields)) { - $customFieldData = new CustomFieldData(); - $customFieldData->setId($itemId); - $customFieldData->setModule($moduleId); - - try { - foreach ($customFields as $id => $value) { - $customFieldData->setDefinitionId($id); - $customFieldData->setValue($value); - - $this->update($customFieldData); - } - } catch (CryptoException $e) { - throw new SPException(SPException::SP_ERROR, __u('Error interno')); - } + if (preg_match('#https?://#', $value)) { + return '' . $value . ''; } + + return $value; } /** * Updates an item * - * @param mixed $itemData - * @return mixed + * @param CustomFieldData $itemData + * @return bool * @throws CryptoException * @throws QueryException * @throws \SP\Core\Exceptions\ConstraintException @@ -157,12 +101,12 @@ class CustomFieldService extends Service implements ServiceItemInterface $exists = $this->checkExists($itemData); // Deletes item's custom field data if value is left blank - if ($exists && $itemData->getValue() === '') { + if ($exists && $itemData->getData() === '') { return $this->delete($itemData->getId()); } // Create item's custom field data if value is set - if (!$exists && $itemData->getValue() !== '') { + if (!$exists && $itemData->getData() !== '') { return $this->create($itemData); } @@ -175,17 +119,17 @@ class CustomFieldService extends Service implements ServiceItemInterface $query = /** @lang SQL */ 'UPDATE customFieldsData SET - customfielddata_data = ?, - customfielddata_key = ? - WHERE customfielddata_moduleId = ? - AND customfielddata_itemId = ? - AND customfielddata_defId = ?'; + `data` = ?, + `key` = ? + WHERE moduleId = ? + AND itemId = ? + AND definitionId = ?'; $Data = new QueryData(); $Data->setQuery($query); - $Data->addParam(Crypt::encrypt($itemData->getValue(), $securedKey, $sessionKey)); + $Data->addParam(Crypt::encrypt($itemData->getData(), $securedKey, $sessionKey)); $Data->addParam($securedKey); - $Data->addParam($itemData->getModule()); + $Data->addParam($itemData->getModuleId()); $Data->addParam($itemData->getId()); $Data->addParam($itemData->getDefinitionId()); @@ -203,21 +147,21 @@ class CustomFieldService extends Service implements ServiceItemInterface protected function checkExists($itemData) { $query = /** @lang SQL */ - 'SELECT customfielddata_id + 'SELECT id FROM customFieldsData - WHERE customfielddata_moduleId = ? - AND customfielddata_itemId = ? - AND customfielddata_defId = ?'; + WHERE moduleId = ? + AND itemId = ? + AND definitionId = ?'; $Data = new QueryData(); $Data->setQuery($query); - $Data->addParam($itemData->getModule()); + $Data->addParam($itemData->getModuleId()); $Data->addParam($itemData->getId()); $Data->addParam($itemData->getDefinitionId()); DbWrapper::getQuery($Data, $this->db); - return ($Data->getQueryNumRows() >= 1); + return $Data->getQueryNumRows() >= 1; } /** @@ -228,7 +172,43 @@ class CustomFieldService extends Service implements ServiceItemInterface */ public function delete($id) { - // TODO: Implement delete() method. + throw new \RuntimeException('Unimplemented'); + } + + /** + * Creates an item + * + * @param CustomFieldData $itemData + * @return bool + * @throws CryptoException + * @throws QueryException + * @throws \SP\Core\Exceptions\ConstraintException + */ + public function create($itemData) + { + if ($itemData->getData() === '') { + return true; + } + + $sessionKey = CryptSession::getSessionKey(); + $securedKey = Crypt::makeSecuredKey($sessionKey); + + if (strlen($securedKey) > 1000) { + throw new QueryException(SPException::SP_ERROR, __u('Error interno')); + } + + $query = /** @lang SQL */ + 'INSERT INTO customFieldsData SET itemId = ?, moduleId = ?, definitionId = ?, `data` = ?, `key` = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getId()); + $Data->addParam($itemData->getModuleId()); + $Data->addParam($itemData->getDefinitionId()); + $Data->addParam(Crypt::encrypt($itemData->getData(), $securedKey, $sessionKey)); + $Data->addParam($securedKey); + + return DbWrapper::getQuery($Data, $this->db); } /** @@ -243,8 +223,8 @@ class CustomFieldService extends Service implements ServiceItemInterface { $query = /** @lang SQL */ 'DELETE FROM customFieldsData - WHERE customfielddata_itemId = ? - AND customfielddata_moduleId = ?'; + WHERE itemId = ? + AND moduleId = ?'; $Data = new QueryData(); $Data->setQuery($query); @@ -258,11 +238,11 @@ class CustomFieldService extends Service implements ServiceItemInterface * Returns the item for given id * * @param int $id - * @return mixed + * @return void */ public function getById($id) { - // TODO: Implement getById() method. + throw new \RuntimeException('Unimplemented'); } /** @@ -272,40 +252,40 @@ class CustomFieldService extends Service implements ServiceItemInterface */ public function getAll() { - // TODO: Implement getAll() method. + throw new \RuntimeException('Unimplemented'); } /** * Returns all the items for given ids * * @param array $ids - * @return array + * @return void */ public function getByIdBatch(array $ids) { - // TODO: Implement getByIdBatch() method. + throw new \RuntimeException('Unimplemented'); } /** * Deletes all the items for given ids * * @param array $ids - * @return $this + * @return void */ public function deleteByIdBatch(array $ids) { - // TODO: Implement deleteByIdBatch() method. + throw new \RuntimeException('Unimplemented'); } /** * Checks whether the item is in use or not * * @param $id int - * @return bool + * @return void */ public function checkInUse($id) { - // TODO: Implement checkInUse() method. + throw new \RuntimeException('Unimplemented'); } /** @@ -316,7 +296,7 @@ class CustomFieldService extends Service implements ServiceItemInterface */ public function search(ItemSearchData $SearchData) { - // TODO: Implement search() method. + throw new \RuntimeException('Unimplemented'); } /** @@ -325,100 +305,55 @@ class CustomFieldService extends Service implements ServiceItemInterface * @param $moduleId * @param $itemId * @return array - * @throws \Defuse\Crypto\Exception\CryptoException */ public function getForModuleById($moduleId, $itemId) { $query = /** @lang SQL */ - 'SELECT customfielddata_id, - customfielddef_id, - customfielddata_data, - customfielddata_key, - customfielddef_field - FROM customFieldsDef a - LEFT JOIN customFieldsData b ON b.customfielddata_defId = a.customfielddef_id - WHERE customfielddef_module = ? - AND (customfielddata_itemId = ? OR customfielddata_defId IS NULL) - ORDER BY customfielddef_id'; + 'SELECT cf_definition.name AS definitionName, + cf_definition.id AS definitionId, + cf_definition.moduleId, + cf_definition.required, + cf_definition.showInList, + cf_definition.help, + cf_data.data, + cf_data.key, + cf_type.id AS typeId, + cf_type.name AS typeName, + cf_type.text AS typeText + FROM customFieldsDef cf_definition + LEFT JOIN customFieldsData cf_data ON cf_data.definitionId = cf_definition.id + INNER JOIN customFieldsType cf_type ON cf_type.id = cf_definition.typeId + WHERE cf_definition.moduleId = ? + AND (cf_data.itemId = ? OR cf_data.definitionId IS NULL) + ORDER BY cf_definition.id'; $Data = new QueryData(); - $Data->setMapClassName(CustomFieldData::class); $Data->setQuery($query); $Data->addParam($moduleId); $Data->addParam($itemId); - /** @var CustomFieldData[] $queryRes */ - $queryRes = DbWrapper::getResultsArray($Data, $this->db); - - $customFields = []; - - foreach ($queryRes as $CustomFieldData) { - /** @var CustomFieldDefData $fieldDef */ - $fieldDef = Util::unserialize(CustomFieldDefData::class, $CustomFieldData->getCustomfielddefField()); - - $CustomFieldData->setDefinition($fieldDef); - $CustomFieldData->setDefinitionId($CustomFieldData->getCustomfielddefId()); - $CustomFieldData->setTypeName(CustomFieldTypes::getFieldsTypes($fieldDef->getType())); - $CustomFieldData->setValue($this->unencryptData($CustomFieldData)); - - $customFields[] = $CustomFieldData; - } - - return $customFields; - } - - /** - * Desencriptar y formatear los datos del campo - * - * @param CustomFieldData $CustomFieldData - * @return string - * @throws \Defuse\Crypto\Exception\CryptoException - */ - protected function unencryptData(CustomFieldData $CustomFieldData) - { - if ($CustomFieldData->getCustomfielddataData() !== '') { - $securedKey = Crypt::unlockSecuredKey($CustomFieldData->getCustomfielddataKey(), CryptSession::getSessionKey()); - - return $this->formatValue(Crypt::decrypt($CustomFieldData->getCustomfielddataData(), $securedKey)); - } - - return ''; - } - - /** - * Formatear el valor del campo - * - * @param $value string El valor del campo - * @return string - */ - protected function formatValue($value) - { - if (preg_match('#https?://#', $value)) { - return '' . $value . ''; - } - - return $value; + return DbWrapper::getResultsArray($Data, $this->db); } /** * Checks whether the item is duplicated on updating * * @param mixed $itemData - * @return bool + * @return void */ public function checkDuplicatedOnUpdate($itemData) { - // TODO: Implement checkDuplicatedOnUpdate() method. + throw new \RuntimeException('Unimplemented'); } /** * Checks whether the item is duplicated on adding * * @param mixed $itemData - * @return bool + * @return void */ public function checkDuplicatedOnAdd($itemData) { - // TODO: Implement checkDuplicatedOnAdd() method. + throw new \RuntimeException('Unimplemented'); } } \ No newline at end of file diff --git a/lib/SP/Services/CustomField/CustomFieldTypeService.php b/lib/SP/Services/CustomField/CustomFieldTypeService.php new file mode 100644 index 00000000..5ae42002 --- /dev/null +++ b/lib/SP/Services/CustomField/CustomFieldTypeService.php @@ -0,0 +1,221 @@ +. + */ + +namespace SP\Services\CustomField; + + +use SP\Core\Exceptions\SPException; +use SP\DataModel\CustomFieldTypeData; +use SP\DataModel\ItemSearchData; +use SP\Services\Service; +use SP\Services\ServiceItemInterface; +use SP\Services\ServiceItemTrait; +use SP\Storage\DbWrapper; +use SP\Storage\QueryData; + +/** + * Class CustomFieldTypeService + * + * @package SP\Services\CustomField + */ +class CustomFieldTypeService extends Service implements ServiceItemInterface +{ + use ServiceItemTrait; + + /** + * Creates an item + * + * @param CustomFieldTypeData $itemData + * @return mixed + * @throws SPException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function create($itemData) + { + $query = /** @lang SQL */ + 'INSERT INTO customFieldsType SET name = ?, text = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getName()); + $Data->addParam($itemData->getText()); + $Data->setOnErrorMessage(__u('Error al crear el tipo de campo')); + + DbWrapper::getQuery($Data, $this->db); + + return $this->db->getLastId(); + } + + /** + * Checks whether the item is duplicated on adding + * + * @param mixed $itemData + * @return void + */ + public function checkDuplicatedOnAdd($itemData) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Updates an item + * + * @param CustomFieldTypeData $itemData + * @return mixed + * @throws SPException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function update($itemData) + { + $query = /** @lang SQL */ + 'UPDATE customFieldsType SET name = ?, text = ? WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getName()); + $Data->addParam($itemData->getText()); + $Data->addParam($itemData->getId()); + $Data->setOnErrorMessage(__u('Error al actualizar el tipo de campo')); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Checks whether the item is duplicated on updating + * + * @param mixed $itemData + * @return void + */ + public function checkDuplicatedOnUpdate($itemData) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Returns the item for given id + * + * @param int $id + * @return mixed + */ + public function getById($id) + { + $query = /** @lang SQL */ + 'SELECT id, name, text FROM customFieldsType WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setMapClassName(CustomFieldTypeData::class); + $Data->setQuery($query); + $Data->addParam($id); + + return DbWrapper::getResults($Data, $this->db); + } + + /** + * Returns all the items + * + * @return array + */ + public function getAll() + { + $query = /** @lang SQL */ + 'SELECT id, name, text FROM customFieldsType'; + + $Data = new QueryData(); + $Data->setMapClassName(CustomFieldTypeData::class); + $Data->setQuery($query); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Returns all the items for given ids + * + * @param array $ids + * @return void + */ + public function getByIdBatch(array $ids) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Deletes all the items for given ids + * + * @param array $ids + * @return void + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function deleteByIdBatch(array $ids) + { + foreach ($ids as $id) { + $this->delete($id); + } + } + + /** + * Deletes an item + * + * @param $id + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function delete($id) + { + $query = /** @lang SQL */ + 'DELETE FROM customFieldsType WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + $Data->setOnErrorMessage(__u('Error al eliminar el tipo de campo')); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Checks whether the item is in use or not + * + * @param $id int + * @return void + */ + public function checkInUse($id) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Searches for items by a given filter + * + * @param ItemSearchData $SearchData + * @return mixed + */ + public function search(ItemSearchData $SearchData) + { + throw new \RuntimeException('Not implemented'); + } +} \ No newline at end of file diff --git a/lib/SP/Services/Plugin/PluginService.php b/lib/SP/Services/Plugin/PluginService.php new file mode 100644 index 00000000..9ae39b23 --- /dev/null +++ b/lib/SP/Services/Plugin/PluginService.php @@ -0,0 +1,446 @@ +. + */ + +namespace SP\Services\Plugin; + +use SP\Core\Exceptions\SPException; +use SP\DataModel\ItemSearchData; +use SP\DataModel\PluginData; +use SP\Services\Service; +use SP\Services\ServiceItemInterface; +use SP\Services\ServiceItemTrait; +use SP\Storage\DbWrapper; +use SP\Storage\QueryData; + +/** + * Class PluginService + * + * @package SP\Services\Plugin + */ +class PluginService extends Service implements ServiceItemInterface +{ + use ServiceItemTrait; + + /** + * Creates an item + * + * @param PluginData $itemData + * @return mixed + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function create($itemData) + { + $query = /** @lang SQL */ + 'INSERT INTO plugins SET name = ?, data = ?, enabled = ?, available = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getPluginName()); + $Data->addParam($itemData->getPluginData()); + $Data->addParam($itemData->getPluginEnabled()); + $Data->addParam($itemData->getPluginAvailable()); + $Data->setOnErrorMessage(__u('Error al crear el plugin')); + + DbWrapper::getQuery($Data, $this->db); + + return $this->db->getLastId(); + } + + /** + * Updates an item + * + * @param PluginData $itemData + * @return mixed + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function update($itemData) + { + $query = /** @lang SQL */ + 'UPDATE plugins + SET name = ?, + data = ?, + enabled = ?, + available = ? + WHERE name = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getPluginName()); + $Data->addParam($itemData->getPluginData()); + $Data->addParam($itemData->getPluginEnabled()); + $Data->addParam($itemData->getPluginAvailable()); + $Data->addParam($itemData->getPluginName()); + $Data->setOnErrorMessage(__u('Error al actualizar el plugin')); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Returns the item for given id + * + * @param int $id + * @return mixed + */ + public function getById($id) + { + $query = /** @lang SQL */ + 'SELECT id, + name, + data, + enabled, + available + FROM plugins + WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setMapClassName(PluginData::class); + $Data->setQuery($query); + $Data->addParam($id); + + return DbWrapper::getResults($Data, $this->db); + } + + /** + * Returns all the items + * + * @return PluginData[] + */ + public function getAll() + { + $query = /** @lang SQL */ + 'SELECT id, + name, + enabled, + available + FROM plugins + ORDER BY name'; + + $Data = new QueryData(); + $Data->setMapClassName(PluginData::class); + $Data->setQuery($query); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Returns all the items for given ids + * + * @param array $ids + * @return array + */ + public function getByIdBatch(array $ids) + { + $query = /** @lang SQL */ + 'SELECT id, + name, + enabled, + available + FROM plugins + WHERE id IN (' . $this->getParamsFromArray($ids) . ')'; + + $Data = new QueryData(); + $Data->setMapClassName(PluginData::class); + $Data->setQuery($query); + $Data->setParams($ids); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Deletes all the items for given ids + * + * @param array $ids + * @return void + * @throws SPException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function deleteByIdBatch(array $ids) + { + foreach ($ids as $id) { + $this->delete($id); + } + } + + /** + * Deletes an item + * + * @param $id + * @return PluginService + * @throws SPException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function delete($id) + { + $query = /** @lang SQL */ + 'DELETE FROM plugins WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + $Data->setOnErrorMessage(__u('Error al eliminar el plugin')); + + DbWrapper::getQuery($Data, $this->db); + + if ($Data->getQueryNumRows() === 0) { + throw new SPException(SPException::SP_INFO, __u('Plugin no encontrado')); + } + + return $this; + } + + /** + * Checks whether the item is in use or not + * + * @param $id int + * @return void + */ + public function checkInUse($id) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Checks whether the item is duplicated on updating + * + * @param mixed $itemData + * @return void + */ + public function checkDuplicatedOnUpdate($itemData) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Checks whether the item is duplicated on adding + * + * @param mixed $itemData + * @return void + */ + public function checkDuplicatedOnAdd($itemData) + { + throw new \RuntimeException('Not implemented'); + } + + /** + * Searches for items by a given filter + * + * @param ItemSearchData $SearchData + * @return mixed + */ + public function search(ItemSearchData $SearchData) + { + $Data = new QueryData(); + $Data->setSelect('id, name, enabled, available'); + $Data->setFrom('plugins'); + $Data->setOrder('name'); + + if ($SearchData->getSeachString() !== '') { + $Data->setWhere('name LIKE ?'); + + $search = '%' . $SearchData->getSeachString() . '%'; + $Data->addParam($search); + } + + $Data->setLimit('?,?'); + $Data->addParam($SearchData->getLimitStart()); + $Data->addParam($SearchData->getLimitCount()); + + DbWrapper::setFullRowCount(); + + /** @var array $queryRes */ + $queryRes = DbWrapper::getResultsArray($Data); + + $queryRes['count'] = $Data->getQueryNumRows(); + + return $queryRes; + } + + /** + * Devuelve los datos de un plugin por su nombre + * + * @param $name int + * @return mixed + */ + public function getByName($name) + { + $query = /** @lang SQL */ + 'SELECT id, + name, + data, + enabled, + available + FROM plugins + WHERE name = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setMapClassName(PluginData::class); + $Data->setQuery($query); + $Data->addParam($name); + + return DbWrapper::getResults($Data, $this->db); + } + + /** + * Cambiar el estado del plugin + * + * @param $id + * @param $enabled + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function toggleEnabled($id, $enabled) + { + $query = /** @lang SQL */ + 'UPDATE plugins + SET enabled = ? + WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($enabled); + $Data->addParam($id); + $Data->setOnErrorMessage(__u('Error al actualizar el plugin')); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Cambiar el estado del plugin + * + * @param $name + * @param $enabled + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function toggleEnabledByName($name, $enabled) + { + $query = /** @lang SQL */ + 'UPDATE plugins + SET enabled = ? + WHERE name = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($enabled); + $Data->addParam($name); + $Data->setOnErrorMessage(__u('Error al actualizar el plugin')); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Cambiar el estado del plugin + * + * @param $id + * @param $available + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function toggleAvailable($id, $available) + { + $query = /** @lang SQL */ + 'UPDATE plugins + SET available = ? + WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + $Data->addParam($available); + $Data->setOnErrorMessage(__u('Error al actualizar el plugin')); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Cambiar el estado del plugin + * + * @param $name + * @param $available + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function toggleAvailableByName($name, $available) + { + $query = /** @lang SQL */ + 'UPDATE plugins + SET available = ? + WHERE name = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($available); + $Data->addParam($name); + $Data->setOnErrorMessage(__u('Error al actualizar el plugin')); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Restablecer los datos de un plugin + * + * @param int $id Id del plugin + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function resetById($id) + { + $query = /** @lang SQL */ + 'UPDATE plugins + SET data = NULL + WHERE id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + $Data->setOnErrorMessage(__u('Error al actualizar el plugin')); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Devolver los plugins activados + * + * @return array + */ + public function getEnabled() + { + $query = /** @lang SQL */ + 'SELECT name FROM plugins WHERE enabled = 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + + return DbWrapper::getResultsArray($Data, $this->db); + } +} \ No newline at end of file diff --git a/lib/SP/Services/PublicLink/PublicLinkService.php b/lib/SP/Services/PublicLink/PublicLinkService.php index 5de7886a..e9f90798 100644 --- a/lib/SP/Services/PublicLink/PublicLinkService.php +++ b/lib/SP/Services/PublicLink/PublicLinkService.php @@ -24,7 +24,6 @@ namespace SP\Services\PublicLink; -use SP\Account\AccountUtil; use SP\Bootstrap; use SP\Config\Config; use SP\Core\Crypt\Crypt; @@ -35,9 +34,6 @@ use SP\DataModel\ItemSearchData; use SP\DataModel\PublicLinkData; use SP\DataModel\PublicLinkListData; use SP\Http\Request; -use SP\Log\Email; -use SP\Log\Log; -use SP\Mgmt\Users\UserUtil; use SP\Services\Account\AccountService; use SP\Services\Service; use SP\Services\ServiceItemInterface; @@ -45,7 +41,6 @@ use SP\Services\ServiceItemTrait; use SP\Storage\DbWrapper; use SP\Storage\QueryData; use SP\Util\Checks; -use SP\Util\DateUtil; use SP\Util\HttpUtil; use SP\Util\Util; @@ -204,11 +199,11 @@ class PublicLinkService extends Service implements ServiceItemInterface * Checks whether the item is in use or not * * @param $id int - * @return bool + * @return void */ public function checkInUse($id) { - // TODO: Implement checkInUse() method. + throw new \RuntimeException('Unimplemented'); } /** @@ -381,11 +376,11 @@ class PublicLinkService extends Service implements ServiceItemInterface * Checks whether the item is duplicated on updating * * @param mixed $itemData - * @return bool + * @return void */ public function checkDuplicatedOnUpdate($itemData) { - // TODO: Implement checkDuplicatedOnUpdate() method. + throw new \RuntimeException('Unimplemented'); } /** @@ -393,7 +388,6 @@ class PublicLinkService extends Service implements ServiceItemInterface * * @param PublicLinkData $publicLinkData * @return void - * @throws \PHPMailer\PHPMailer\Exception * @throws \SP\Core\Exceptions\ConstraintException * @throws \SP\Core\Exceptions\QueryException */ @@ -419,18 +413,18 @@ class PublicLinkService extends Service implements ServiceItemInterface DbWrapper::getQuery($Data, $this->db); // FIXME - $Log = new Log(); - $LogMessage = $Log->getLogMessage(); - $LogMessage->setAction(__u('Ver Enlace Público')); - $LogMessage->addDescription(__u('Enlace visualizado')); - $LogMessage->addDetails(__u('Tipo'), $publicLinkData->getPublicLinkTypeId()); - $LogMessage->addDetails(__u('Cuenta'), AccountUtil::getAccountNameById($publicLinkData->getPublicLinkItemId())); - $LogMessage->addDetails(__u('Usuario'), UserUtil::getUserLoginById($publicLinkData->getPublicLinkUserId())); - $Log->writeLog(); - - if ($publicLinkData->isPublicLinkNotify()) { - Email::sendEmail($LogMessage); - } +// $Log = new Log(); +// $LogMessage = $Log->getLogMessage(); +// $LogMessage->setAction(__u('Ver Enlace Público')); +// $LogMessage->addDescription(__u('Enlace visualizado')); +// $LogMessage->addDetails(__u('Tipo'), $publicLinkData->getPublicLinkTypeId()); +// $LogMessage->addDetails(__u('Cuenta'), AccountUtil::getAccountNameById($publicLinkData->getPublicLinkItemId())); +// $LogMessage->addDetails(__u('Usuario'), UserUtil::getUserLoginById($publicLinkData->getPublicLinkUserId())); +// $Log->writeLog(); +// +// if ($publicLinkData->isPublicLinkNotify()) { +// Email::sendEmail($LogMessage); +// } } /** diff --git a/lib/SP/Services/ServiceItemTrait.php b/lib/SP/Services/ServiceItemTrait.php index 52e35444..36f1c24c 100644 --- a/lib/SP/Services/ServiceItemTrait.php +++ b/lib/SP/Services/ServiceItemTrait.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link http://syspass.org + * @author nuxsmin + * @link http://syspass.org * @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -42,6 +42,17 @@ trait ServiceItemTrait */ private static $itemsSelectCache; + /** + * Returns service items for a select + * + * @return mixed + */ + public static function getServiceItems() + { + $service = new static(); + return $service->getItemsForSelect(); + } + /** * Devolver los elementos para un campo select * @@ -105,15 +116,14 @@ trait ServiceItemTrait protected function makeItemHash($name) { $charsSrc = ['.', ' ', '_', ', ', '-', ';', '\'', '"', ':', '(', ')', '|', '/']; - $newValue = strtolower(str_replace($charsSrc, '', DBUtil::escape($name))); - return md5($newValue); + return md5(strtolower(str_replace($charsSrc, '', DBUtil::escape($name)))); } /** * Devuelve una cadena con los parámetros para una consulta SQL desde un array * - * @param array $items + * @param array $items * @param string $string Cadena a utilizar para los parámetros * @return string */ @@ -121,15 +131,4 @@ trait ServiceItemTrait { return implode(',', array_fill(0, count($items), $string)); } - - /** - * Returns service items for a select - * - * @return mixed - */ - public static function getServiceItems() - { - $service = new static(); - return $service->getItemsForSelect(); - } } \ No newline at end of file diff --git a/lib/SP/Services/Tag/TagService.php b/lib/SP/Services/Tag/TagService.php new file mode 100644 index 00000000..c7929971 --- /dev/null +++ b/lib/SP/Services/Tag/TagService.php @@ -0,0 +1,295 @@ +. + */ + +namespace SP\Services\Tag; + + +use SP\Core\Exceptions\SPException; +use SP\DataModel\ItemSearchData; +use SP\DataModel\TagData; +use SP\Services\Service; +use SP\Services\ServiceItemInterface; +use SP\Services\ServiceItemTrait; +use SP\Storage\DbWrapper; +use SP\Storage\QueryData; + +/** + * Class TagService + * + * @package SP\Services\Tag + */ +class TagService extends Service implements ServiceItemInterface +{ + use ServiceItemTrait; + + /** + * Creates an item + * + * @param TagData $itemData + * @return mixed + * @throws SPException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function create($itemData) + { + if ($this->checkDuplicatedOnAdd($itemData)) { + throw new SPException(SPException::SP_INFO, __u('Etiqueta duplicada')); + } + + $query = /** @lang SQL */ + 'INSERT INTO tags SET tag_name = ?, tag_hash = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getTagName()); + $Data->addParam($itemData->getTagHash()); + $Data->setOnErrorMessage(__u('Error al crear etiqueta')); + + DbWrapper::getQuery($Data, $this->db); + + return $this->db->getLastId(); + } + + /** + * Checks whether the item is duplicated on adding + * + * @param mixed $itemData + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function checkDuplicatedOnAdd($itemData) + { + $query = /** @lang SQL */ + 'SELECT tag_id FROM tags WHERE tag_hash = ?'; + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getTagHash()); + + DbWrapper::getQuery($Data); + + return $Data->getQueryNumRows() > 0; + } + + /** + * Updates an item + * + * @param TagData $itemData + * @return mixed + * @throws SPException + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function update($itemData) + { + if ($this->checkDuplicatedOnUpdate($itemData)) { + throw new SPException(SPException::SP_INFO, __u('Etiqueta duplicada')); + } + + $query = /** @lang SQL */ + 'UPDATE tags SET tag_name = ?, tag_hash = ? WHERE tag_id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getTagName()); + $Data->addParam($itemData->getTagHash()); + $Data->addParam($itemData->getTagId()); + $Data->setOnErrorMessage(__u('Error al actualizar etiqueta')); + + return DbWrapper::getQuery($Data, $this->db); + } + + /** + * Checks whether the item is duplicated on updating + * + * @param mixed $itemData + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function checkDuplicatedOnUpdate($itemData) + { + $query = /** @lang SQL */ + 'SELECT tag_hash FROM tags WHERE tag_hash = ? AND tag_id <> ?'; + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($itemData->getTagHash()); + $Data->addParam($itemData->getTagId()); + + DbWrapper::getQuery($Data); + + return $Data->getQueryNumRows() > 0; + } + + /** + * Returns the item for given id + * + * @param int $id + * @return mixed + */ + public function getById($id) + { + $query = /** @lang SQL */ + 'SELECT tag_id, tag_name FROM tags WHERE tag_id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + $Data->setMapClassName(TagData::class); + + return DbWrapper::getResults($Data, $this->db); + } + + /** + * Returns all the items + * + * @return TagData[] + */ + public function getAll() + { + $query = /** @lang SQL */ + 'SELECT tag_id, tag_name, tag_hash FROM tags ORDER BY tag_name'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->setMapClassName(TagData::class); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Returns all the items for given ids + * + * @param array $ids + * @return TagData[] + */ + public function getByIdBatch(array $ids) + { + $query = /** @lang SQL */ + 'SELECT tag_id, tag_name FROM tags WHERE tag_id IN (' . $this->getParamsFromArray($ids) . ')'; + + $Data = new QueryData(); + $Data->setMapClassName(TagData::class); + $Data->setQuery($query); + $Data->setParams($ids); + + return DbWrapper::getResultsArray($Data, $this->db); + } + + /** + * Deletes all the items for given ids + * + * @param array $ids + * @return void + * @throws SPException + */ + public function deleteByIdBatch(array $ids) + { + foreach ($ids as $id) { + $this->delete($id); + } + } + + /** + * Deletes an item + * + * @param $id + * @return TagService + * @throws SPException + */ + public function delete($id) + { + $query = /** @lang SQL */ + 'DELETE FROM tags WHERE tag_id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + $Data->setOnErrorMessage(__u('Error al eliminar etiqueta')); + + DbWrapper::getQuery($Data, $this->db); + + if ($Data->getQueryNumRows() === 0) { + throw new SPException(SPException::SP_INFO, __u('Etiqueta no encontrada')); + } + + return $this; + } + + /** + * Checks whether the item is in use or not + * + * @param $id int + * @return bool + * @throws \SP\Core\Exceptions\ConstraintException + * @throws \SP\Core\Exceptions\QueryException + */ + public function checkInUse($id) + { + $query = /** @lang SQL */ + 'SELECT acctag_tagId FROM accTags WHERE acctag_tagId = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + + DbWrapper::getQuery($Data, $this->db); + + return $Data->getQueryNumRows() > 0; + } + + /** + * Searches for items by a given filter + * + * @param ItemSearchData $SearchData + * @return mixed + */ + public function search(ItemSearchData $SearchData) + { + $Data = new QueryData(); + $Data->setSelect('tag_id, tag_name'); + $Data->setFrom('tags'); + $Data->setOrder('tag_name'); + + if ($SearchData->getSeachString() !== '') { + $Data->setWhere('tag_name LIKE ?'); + + $search = '%' . $SearchData->getSeachString() . '%'; + $Data->addParam($search); + } + + $Data->setLimit('?,?'); + $Data->addParam($SearchData->getLimitStart()); + $Data->addParam($SearchData->getLimitCount()); + + DbWrapper::setFullRowCount(); + + $queryRes = DbWrapper::getResultsArray($Data, $this->db); + + $queryRes['count'] = $Data->getQueryNumRows(); + + return $queryRes; + } +} \ No newline at end of file diff --git a/schemas/110.sql b/schemas/110.sql index 86b91ad7..d260c732 100644 --- a/schemas/110.sql +++ b/schemas/110.sql @@ -1,6 +1,6 @@ -- To 1.1.0; ALTER TABLE `accFiles` - CHANGE COLUMN `accfile_name` `accfile_name` VARCHAR(100) NOT NULL; + CHANGE COLUMN name `accfile_name` VARCHAR(100) NOT NULL; ALTER TABLE `accounts` ADD COLUMN `account_otherGroupEdit` BIT(1) NULL DEFAULT 0 AFTER `account_dateEdit`, @@ -20,4 +20,4 @@ ALTER TABLE `accHistory` ADD COLUMN `accHistory_otherGroupEdit` VARCHAR(45) NULL AFTER `accHistory_otherUserEdit`; ALTER TABLE `accFiles` - CHANGE COLUMN `accfile_type` `accfile_type` VARCHAR(100) NOT NULL; \ No newline at end of file + CHANGE COLUMN type `accfile_type` VARCHAR(100) NOT NULL; \ No newline at end of file diff --git a/schemas/13016100601.sql b/schemas/13016100601.sql index b2d551a0..a38ff4f1 100644 --- a/schemas/13016100601.sql +++ b/schemas/13016100601.sql @@ -78,7 +78,7 @@ REFERENCES `usrData` (`user_id`) ALTER TABLE `accFiles` ADD CONSTRAINT `fk_accFiles_accounts_id` -FOREIGN KEY (`accfile_accountId`) +FOREIGN KEY (accountId) REFERENCES `accounts` (`account_id`) ON DELETE NO ACTION ON UPDATE NO ACTION; @@ -339,7 +339,7 @@ CREATE OR REPLACE ALGORITHM = UNDEFINED DEFINER = CURRENT_USER SQL SECURITY DEFI FROM `accFiles` WHERE - (`accFiles`.`accfile_accountId` = `accounts`.`account_id`)) AS `num_files` + (`accFiles`.accountId = `accounts`.`account_id`)) AS `num_files` FROM (((`accounts` LEFT JOIN `categories` ON ((`accounts`.`account_categoryId` = `categories`.`category_id`))) diff --git a/schemas/20017011701.sql b/schemas/20017011701.sql index 73453e8e..f282b6a6 100644 --- a/schemas/20017011701.sql +++ b/schemas/20017011701.sql @@ -72,7 +72,7 @@ CREATE OR REPLACE ALGORITHM = UNDEFINED DEFINER = CURRENT_USER SQL SECURITY DEFI FROM `accFiles` WHERE - (`accFiles`.`accfile_accountId` = `accounts`.`account_id`)) AS `num_files` + (`accFiles`.accountId = `accounts`.`account_id`)) AS `num_files` FROM (((`accounts` LEFT JOIN `categories` ON ((`accounts`.`account_categoryId` = `categories`.`category_id`))) diff --git a/schemas/20017012901.sql b/schemas/20017012901.sql index 98a2691a..a60f2bc1 100644 --- a/schemas/20017012901.sql +++ b/schemas/20017012901.sql @@ -32,7 +32,7 @@ CREATE OR REPLACE ALGORITHM = UNDEFINED DEFINER = CURRENT_USER SQL SECURITY DEFI FROM `accFiles` WHERE - (`accFiles`.`accfile_accountId` = `accounts`.`account_id`)) AS `num_files` + (`accFiles`.accountId = `accounts`.`account_id`)) AS `num_files` FROM (((`accounts` LEFT JOIN `categories` ON ((`accounts`.`account_categoryId` = `categories`.`category_id`))) diff --git a/schemas/22017050101.sql b/schemas/22017050101.sql index 7d7c2f5c..3bc9e255 100644 --- a/schemas/22017050101.sql +++ b/schemas/22017050101.sql @@ -1,153 +1,423 @@ -ALTER TABLE `customers` ADD `customer_isGlobal` BIT(1) DEFAULT b'0' NULL; -ALTER TABLE `usrData` ADD `user_ssoLogin` VARCHAR(100) NULL AFTER `user_login`; +ALTER TABLE `customers` + ADD `customer_isGlobal` BIT(1) DEFAULT b'0' NULL; +ALTER TABLE `usrData` + ADD `user_ssoLogin` VARCHAR(100) NULL + AFTER `user_login`; -DROP INDEX IDX_login ON `usrData`; -CREATE UNIQUE INDEX `IDX_login` ON `usrData` (`user_login`, `user_ssoLogin`); +DROP INDEX IDX_login +ON `usrData`; +CREATE UNIQUE INDEX `IDX_login` + ON `usrData` (`user_login`, `user_ssoLogin`); -ALTER TABLE plugins ADD `plugin_available` BIT(1) DEFAULT b'0' NULL; +ALTER TABLE plugins + ADD `plugin_available` BIT(1) DEFAULT b'0' NULL; CREATE TABLE `actions` ( - `action_id` SMALLINT(5) UNSIGNED NOT NULL, - `action_name` VARCHAR(50) NOT NULL, - `action_text` VARCHAR(100) NOT NULL, + `action_id` SMALLINT(5) UNSIGNED NOT NULL, + `action_name` VARCHAR(50) NOT NULL, + `action_text` VARCHAR(100) NOT NULL, `action_route` VARCHAR(100), PRIMARY KEY (`action_id`, `action_name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) + ENGINE = InnoDB + DEFAULT CHARSET = utf8; CREATE TABLE actions ( - action_id int(10) unsigned PRIMARY KEY NOT NULL, - action_name varchar(50) NOT NULL, - action_text varchar(100) NOT NULL, - action_route varchar(100) + action_id INT(10) UNSIGNED PRIMARY KEY NOT NULL, + action_name VARCHAR(50) NOT NULL, + action_text VARCHAR(100) NOT NULL, + action_route VARCHAR(100) ); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1, 'ACCOUNT_SEARCH', 'Buscar Cuentas', 'account/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (10, 'ACCOUNT', 'Cuentas', 'account/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (11, 'ACCOUNT_FILE', 'Archivos', 'account/listFile'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (12, 'ACCOUNT_REQUEST', 'Peticiones', 'account/request'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (13, 'ACCOUNT_FAVORITE', 'Favoritos', 'favorite/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1, 'ACCOUNT_SEARCH', 'Buscar Cuentas', 'account/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (10, 'ACCOUNT', 'Cuentas', 'account/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (11, 'ACCOUNT_FILE', 'Archivos', 'account/listFile'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (12, 'ACCOUNT_REQUEST', 'Peticiones', 'account/request'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (13, 'ACCOUNT_FAVORITE', 'Favoritos', 'favorite/index'); INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (20, 'WIKI', 'Wiki', 'wiki/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (60, 'ITEMS_MANAGE', 'Elementos y Personalización', 'itemManager/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (61, 'CATEGORY', 'Gestión Categorías', 'category/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (62, 'CLIENT', 'Gestión Clientes', 'client/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (63, 'APITOKEN', 'Gestión Autorizaciones API', 'apiToken/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (64, 'CUSTOMFIELD', 'Gestión Campos Personalizados', 'customField/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (65, 'PUBLICLINK', 'Enlaces Públicos', 'publicLink/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (66, 'FILE', 'Gestión de Archivos', 'file/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (67, 'ACCOUNTMGR', 'Gestión de Cuentas', 'accountManager/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (68, 'TAG', 'Gestión de Etiquetas', 'tag/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (69, 'PLUGIN', 'Gestión Plugins', 'plugin/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (70, 'ACCESS_MANAGE', 'Usuarios y Accesos', 'accessManager/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (71, 'USER', 'Gestión Usuarios', 'user/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (72, 'GROUP', 'Gestión Grupos', 'group/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (73, 'PROFILE', 'Gestión Perfiles', 'profile/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (90, 'EVENTLOG', 'Registro de Eventos', 'eventlog/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (100, 'ACCOUNT_VIEW', 'Ver Cuenta', 'account/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (101, 'ACCOUNT_CREATE', 'Nueva Cuenta', 'account/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (102, 'ACCOUNT_EDIT', 'Editar Cuenta', 'account/edit'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (103, 'ACCOUNT_DELETE', 'Eliminar Cuenta', 'account/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (104, 'ACCOUNT_VIEW_PASS', 'Ver Clave', 'account/viewPass'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (105, 'ACCOUNT_VIEW_HISTORY', 'Ver Historial', 'account/viewHistory'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (106, 'ACCOUNT_EDIT_PASS', 'Editar Clave de Cuenta', 'account/editPass'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (107, 'ACCOUNT_EDIT_RESTORE', 'Restaurar Cuenta', 'account/restore'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (108, 'ACCOUNT_COPY', 'Copiar Cuenta', 'account/copy'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (109, 'ACCOUNT_COPY_PASS', 'Copiar Clave', 'account/copyPass'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (111, 'ACCOUNT_FILE_VIEW', 'Ver Archivo', 'account/viewFile'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (112, 'ACCOUNT_FILE_UPLOAD', 'Subir Archivo', 'account/uploadFile'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (113, 'ACCOUNT_FILE_DOWNLOAD', 'Descargar Archivo', 'account/downloadFile'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (114, 'ACCOUNT_FILE_DELETE', 'Eliminar Archivo', 'account/deleteFile'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (130, 'ACCOUNT_FAVORITE_VIEW', 'Ver Favoritos', 'favorite/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (131, 'ACCOUNT_FAVORITE_ADD', 'Añadir Favorito', 'favorite/add'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (133, 'ACCOUNT_FAVORITE_DELETE', 'Eliminar Favorito', 'favorite/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (200, 'WIKI_VIEW', 'Ver Wiki', 'wiki/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (201, 'WIKI_NEW', 'Añadir Wiki', 'wiki/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (202, 'WIKI_EDIT', 'Editar Wiki', 'wiki/edit'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (203, 'WIKI_DELETE', 'Eliminar Wiki', 'wiki/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (610, 'CATEGORY_VIEW', 'Ver Categoría', 'category/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (611, 'CATEGORY_CREATE', 'Nueva Categoría', 'category/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (612, 'CATEGORY_EDIT', 'Editar Categoría', 'category/edit'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (613, 'CATEGORY_DELETE', 'Eliminar Categoría', 'category/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (615, 'CATEGORY_SEARCH', 'Buscar Categoría', 'category/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (620, 'CLIENT_VIEW', 'Ver Cliente', 'client/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (621, 'CLIENT_CREATE', 'Nuevo CLiente', 'client/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (622, 'CLIENT_EDIT', 'Editar Cliente', 'client/edit'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (623, 'CLIENT_DELETE', 'Eliminar Cliente', 'client/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (625, 'CLIENT_SEARCH', 'Buscar Cliente', 'client/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (630, 'APITOKEN_CREATE', 'Nuevo Token API', 'apiToken/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (631, 'APITOKEN_VIEW', 'Ver Token API', 'apiToken/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (632, 'APITOKEN_EDIT', 'Editar Token API', 'apiToken/edit'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (633, 'APITOKEN_DELETE', 'Eliminar Token API', 'apiToken/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (635, 'APITOKEN_SEARCH', 'Buscar Token API', 'apiToken/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (640, 'CUSTOMFIELD_CREATE', 'Nuevo Campo Personalizado', 'customField/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (641, 'CUSTOMFIELD_VIEW', 'Ver Campo Personalizado', 'customField/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (642, 'CUSTOMFIELD_EDIT', 'Editar Campo Personalizado', 'customField/edit'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (643, 'CUSTOMFIELD_DELETE', 'Eliminar Campo Personalizado', 'customField/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (645, 'CUSTOMFIELD_SEARCH', 'Buscar Campo Personalizado', 'customField/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (650, 'PUBLICLINK_CREATE', 'Crear Enlace Público', 'publicLink/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (651, 'PUBLICLINK_VIEW', 'Ver Enlace Público', 'publicLink/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (653, 'PUBLICLINK_DELETE', 'Eliminar Enlace Público', 'publicLink/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (654, 'PUBLICLINK_REFRESH', 'Actualizar Enlace Público', 'publicLink/refresh'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (655, 'PUBLICLINK_SEARCH', 'Buscar Enlace Público', 'publicLink/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (661, 'FILE_VIEW', 'Ver Archivo', 'file/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (663, 'FILE_DELETE', 'Eliminar Archivo', 'file/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (665, 'FILE_SEARCH', 'Buscar Archivo', 'file/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (671, 'ACCOUNTMGR_VIEW', 'Ver Cuenta', 'accountManager/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (673, 'ACCOUNTMGR_DELETE', 'Eliminar Cuenta', 'accountManager/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (675, 'ACCOUNTMGR_SEARCH', 'Buscar Cuenta', 'accountManager/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (680, 'TAG_CREATE', 'Nueva Etiqueta', 'tag/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (681, 'TAG_VIEW', 'Ver Etiqueta', 'tag/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (682, 'TAG_EDIT', 'Editar Etiqueta', 'tag/edit'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (683, 'TAG_DELETE', 'Eliminar Etiqueta', 'tag/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (685, 'TAG_SEARCH', 'Buscar Etiqueta', 'tag/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (690, 'PLUGIN_NEW', 'Nuevo Plugin', 'plugin/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (691, 'PLUGIN_VIEW', 'Ver Plugin', 'plugin/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (695, 'PLUGIN_SEARCH', 'Buscar Plugin', 'plugin/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (696, 'PLUGIN_ENABLE', 'Habilitar Plugin', 'plugin/enable'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (697, 'PLUGIN_DISABLE', 'Deshabilitar Plugin', 'plugin/disable'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (698, 'PLUGIN_RESET', 'Restablecer Plugin', 'plugin/reset'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (710, 'USER_VIEW', 'Ver Usuario', 'user/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (711, 'USER_CREATE', 'Nuevo Usuario', 'user/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (712, 'USER_EDIT', 'Editar Usuario', 'user/edit'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (713, 'USER_DELETE', 'Eliminar Usuario', 'user/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (714, 'USER_EDIT_PASS', 'Editar Clave Usuario', 'user/editPass'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (715, 'USER_SEARCH', 'Buscar Usuario', 'user/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (720, 'GROUP_VIEW', 'Ver Grupo', 'userGroup/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (721, 'GROUP_CREATE', 'Nuevo Grupo', 'userGroup/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (722, 'GROUP_EDIT', 'Editar Grupo', 'userGroup/edit'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (723, 'GROUP_DELETE', 'Eliminar Grupo', 'userGroup/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (725, 'GROUP_SEARCH', 'Buscar Grupo', 'userGroup/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (730, 'PROFILE_VIEW', 'Ver Perfil', 'userProfile/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (731, 'PROFILE_CREATE', 'Nuevo Perfil', 'userProfile/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (732, 'PROFILE_EDIT', 'Editar Perfil', 'userProfile/edit'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (733, 'PROFILE_DELETE', 'Eliminar Perfil', 'userProfile/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (735, 'PROFILE_SEARCH', 'Buscar Perfil', 'userProfile/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (740, 'PREFERENCE', 'Gestión Preferencias', 'userPreference/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (741, 'PREFERENCE_GENERAL', 'Preferencias General', 'userPreference/general'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (742, 'PREFERENCE_SECURITY', 'Preferencias Seguridad', 'userPreference/security'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (760, 'NOTICE', 'Notificaciones', 'notice/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (761, 'NOTICE_USER', 'Notificaciones Usuario', 'noticeUser/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1000, 'CONFIG', 'Configuración', 'config/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1001, 'CONFIG_GENERAL', 'Configuración General', 'config/general'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1010, 'ACCOUNT_CONFIG', 'Configuración Cuentas', 'account/config'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1020, 'WIKI_CONFIG', 'Configuración Wiki', 'wiki/config'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1030, 'ENCRYPTION_CONFIG', 'Configuración Encriptación', 'encryption/config'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1031, 'ENCRYPTION_REFRESH', 'Actualizar Hash', 'encryption/updateHash'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1032, 'ENCRYPTION_TEMPPASS', 'Clave Maestra Temporal', 'encryption/createTempPass'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1040, 'BACKUP_CONFIG', 'Configuración Copia de Seguridad', 'backup/config'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1050, 'IMPORT_CONFIG', 'Configuración Importación', 'import/config'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1051, 'IMPORT_CSV', 'Importar CSV', 'import/csv'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1052, 'IMPORT_XML', 'Importar XML', 'import/xml'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1070, 'MAIL_CONFIG', 'Configuración Email', 'mail/config'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1080, 'LDAP_CONFIG', 'Configuración LDAP', 'ldap/config'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (1081, 'LDAP_SYNC', 'Sincronización LDAP', 'ldap/sync'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (6701, 'ACCOUNTMGR_HISTORY', 'Gestión de Cuenta (H)', 'accountHistoryManager/index'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (6731, 'ACCOUNTMGR_DELETE_HISTORY', 'Eliminar Cuenta', 'accountHistoryManager/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (6751, 'ACCOUNTMGR_SEARCH_HISTORY', 'Buscar Cuenta', 'accountHistoryManager/search'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (6771, 'ACCOUNTMGR_RESTORE', 'Restaurar Cuenta', 'accountManager/restore'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (7610, 'NOTICE_USER_VIEW', 'Ver Notificación', 'userNotice/view'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (7611, 'NOTICE_USER_CREATE', 'Crear Notificación', 'userNotice/create'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (7612, 'NOTICE_USER_EDIT', 'Editar Notificación', 'userNotice/edit'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (7613, 'NOTICE_USER_DELETE', 'Eliminar Notificación', 'userNotice/delete'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (7614, 'NOTICE_USER_CHECK', 'Marcar Notificación', 'userNotice/check'); -INSERT INTO actions (action_id, action_name, action_text, action_route) VALUES (7615, 'NOTICE_USER_SEARCH', 'Buscar Notificación', 'userNotice/search'); \ No newline at end of file +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (60, 'ITEMS_MANAGE', 'Elementos y Personalización', 'itemManager/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (61, 'CATEGORY', 'Gestión Categorías', 'category/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (62, 'CLIENT', 'Gestión Clientes', 'client/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (63, 'APITOKEN', 'Gestión Autorizaciones API', 'apiToken/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (64, 'CUSTOMFIELD', 'Gestión Campos Personalizados', 'customField/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (65, 'PUBLICLINK', 'Enlaces Públicos', 'publicLink/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (66, 'FILE', 'Gestión de Archivos', 'file/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (67, 'ACCOUNTMGR', 'Gestión de Cuentas', 'accountManager/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (68, 'TAG', 'Gestión de Etiquetas', 'tag/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (69, 'PLUGIN', 'Gestión Plugins', 'plugin/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (70, 'ACCESS_MANAGE', 'Usuarios y Accesos', 'accessManager/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (71, 'USER', 'Gestión Usuarios', 'user/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (72, 'GROUP', 'Gestión Grupos', 'group/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (73, 'PROFILE', 'Gestión Perfiles', 'profile/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (90, 'EVENTLOG', 'Registro de Eventos', 'eventlog/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (100, 'ACCOUNT_VIEW', 'Ver Cuenta', 'account/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (101, 'ACCOUNT_CREATE', 'Nueva Cuenta', 'account/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (102, 'ACCOUNT_EDIT', 'Editar Cuenta', 'account/edit'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (103, 'ACCOUNT_DELETE', 'Eliminar Cuenta', 'account/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (104, 'ACCOUNT_VIEW_PASS', 'Ver Clave', 'account/viewPass'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (105, 'ACCOUNT_VIEW_HISTORY', 'Ver Historial', 'account/viewHistory'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (106, 'ACCOUNT_EDIT_PASS', 'Editar Clave de Cuenta', 'account/editPass'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (107, 'ACCOUNT_EDIT_RESTORE', 'Restaurar Cuenta', 'account/restore'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (108, 'ACCOUNT_COPY', 'Copiar Cuenta', 'account/copy'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (109, 'ACCOUNT_COPY_PASS', 'Copiar Clave', 'account/copyPass'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (111, 'ACCOUNT_FILE_VIEW', 'Ver Archivo', 'account/viewFile'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (112, 'ACCOUNT_FILE_UPLOAD', 'Subir Archivo', 'account/uploadFile'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (113, 'ACCOUNT_FILE_DOWNLOAD', 'Descargar Archivo', 'account/downloadFile'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (114, 'ACCOUNT_FILE_DELETE', 'Eliminar Archivo', 'account/deleteFile'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (130, 'ACCOUNT_FAVORITE_VIEW', 'Ver Favoritos', 'favorite/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (131, 'ACCOUNT_FAVORITE_ADD', 'Añadir Favorito', 'favorite/add'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (133, 'ACCOUNT_FAVORITE_DELETE', 'Eliminar Favorito', 'favorite/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (200, 'WIKI_VIEW', 'Ver Wiki', 'wiki/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (201, 'WIKI_NEW', 'Añadir Wiki', 'wiki/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (202, 'WIKI_EDIT', 'Editar Wiki', 'wiki/edit'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (203, 'WIKI_DELETE', 'Eliminar Wiki', 'wiki/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (610, 'CATEGORY_VIEW', 'Ver Categoría', 'category/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (611, 'CATEGORY_CREATE', 'Nueva Categoría', 'category/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (612, 'CATEGORY_EDIT', 'Editar Categoría', 'category/edit'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (613, 'CATEGORY_DELETE', 'Eliminar Categoría', 'category/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (615, 'CATEGORY_SEARCH', 'Buscar Categoría', 'category/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (620, 'CLIENT_VIEW', 'Ver Cliente', 'client/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (621, 'CLIENT_CREATE', 'Nuevo CLiente', 'client/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (622, 'CLIENT_EDIT', 'Editar Cliente', 'client/edit'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (623, 'CLIENT_DELETE', 'Eliminar Cliente', 'client/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (625, 'CLIENT_SEARCH', 'Buscar Cliente', 'client/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (630, 'APITOKEN_CREATE', 'Nuevo Token API', 'apiToken/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (631, 'APITOKEN_VIEW', 'Ver Token API', 'apiToken/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (632, 'APITOKEN_EDIT', 'Editar Token API', 'apiToken/edit'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (633, 'APITOKEN_DELETE', 'Eliminar Token API', 'apiToken/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (635, 'APITOKEN_SEARCH', 'Buscar Token API', 'apiToken/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (640, 'CUSTOMFIELD_CREATE', 'Nuevo Campo Personalizado', 'customField/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (641, 'CUSTOMFIELD_VIEW', 'Ver Campo Personalizado', 'customField/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (642, 'CUSTOMFIELD_EDIT', 'Editar Campo Personalizado', 'customField/edit'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (643, 'CUSTOMFIELD_DELETE', 'Eliminar Campo Personalizado', 'customField/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (645, 'CUSTOMFIELD_SEARCH', 'Buscar Campo Personalizado', 'customField/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (650, 'PUBLICLINK_CREATE', 'Crear Enlace Público', 'publicLink/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (651, 'PUBLICLINK_VIEW', 'Ver Enlace Público', 'publicLink/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (653, 'PUBLICLINK_DELETE', 'Eliminar Enlace Público', 'publicLink/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (654, 'PUBLICLINK_REFRESH', 'Actualizar Enlace Público', 'publicLink/refresh'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (655, 'PUBLICLINK_SEARCH', 'Buscar Enlace Público', 'publicLink/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (661, 'FILE_VIEW', 'Ver Archivo', 'file/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (663, 'FILE_DELETE', 'Eliminar Archivo', 'file/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (665, 'FILE_SEARCH', 'Buscar Archivo', 'file/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (671, 'ACCOUNTMGR_VIEW', 'Ver Cuenta', 'accountManager/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (673, 'ACCOUNTMGR_DELETE', 'Eliminar Cuenta', 'accountManager/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (675, 'ACCOUNTMGR_SEARCH', 'Buscar Cuenta', 'accountManager/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (680, 'TAG_CREATE', 'Nueva Etiqueta', 'tag/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (681, 'TAG_VIEW', 'Ver Etiqueta', 'tag/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (682, 'TAG_EDIT', 'Editar Etiqueta', 'tag/edit'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (683, 'TAG_DELETE', 'Eliminar Etiqueta', 'tag/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (685, 'TAG_SEARCH', 'Buscar Etiqueta', 'tag/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (690, 'PLUGIN_NEW', 'Nuevo Plugin', 'plugin/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (691, 'PLUGIN_VIEW', 'Ver Plugin', 'plugin/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (695, 'PLUGIN_SEARCH', 'Buscar Plugin', 'plugin/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (696, 'PLUGIN_ENABLE', 'Habilitar Plugin', 'plugin/enable'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (697, 'PLUGIN_DISABLE', 'Deshabilitar Plugin', 'plugin/disable'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (698, 'PLUGIN_RESET', 'Restablecer Plugin', 'plugin/reset'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (710, 'USER_VIEW', 'Ver Usuario', 'user/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (711, 'USER_CREATE', 'Nuevo Usuario', 'user/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (712, 'USER_EDIT', 'Editar Usuario', 'user/edit'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (713, 'USER_DELETE', 'Eliminar Usuario', 'user/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (714, 'USER_EDIT_PASS', 'Editar Clave Usuario', 'user/editPass'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (715, 'USER_SEARCH', 'Buscar Usuario', 'user/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (720, 'GROUP_VIEW', 'Ver Grupo', 'userGroup/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (721, 'GROUP_CREATE', 'Nuevo Grupo', 'userGroup/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (722, 'GROUP_EDIT', 'Editar Grupo', 'userGroup/edit'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (723, 'GROUP_DELETE', 'Eliminar Grupo', 'userGroup/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (725, 'GROUP_SEARCH', 'Buscar Grupo', 'userGroup/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (730, 'PROFILE_VIEW', 'Ver Perfil', 'userProfile/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (731, 'PROFILE_CREATE', 'Nuevo Perfil', 'userProfile/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (732, 'PROFILE_EDIT', 'Editar Perfil', 'userProfile/edit'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (733, 'PROFILE_DELETE', 'Eliminar Perfil', 'userProfile/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (735, 'PROFILE_SEARCH', 'Buscar Perfil', 'userProfile/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (740, 'PREFERENCE', 'Gestión Preferencias', 'userPreference/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (741, 'PREFERENCE_GENERAL', 'Preferencias General', 'userPreference/general'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (742, 'PREFERENCE_SECURITY', 'Preferencias Seguridad', 'userPreference/security'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (760, 'NOTICE', 'Notificaciones', 'notice/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (761, 'NOTICE_USER', 'Notificaciones Usuario', 'noticeUser/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1000, 'CONFIG', 'Configuración', 'config/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1001, 'CONFIG_GENERAL', 'Configuración General', 'config/general'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1010, 'ACCOUNT_CONFIG', 'Configuración Cuentas', 'account/config'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1020, 'WIKI_CONFIG', 'Configuración Wiki', 'wiki/config'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1030, 'ENCRYPTION_CONFIG', 'Configuración Encriptación', 'encryption/config'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1031, 'ENCRYPTION_REFRESH', 'Actualizar Hash', 'encryption/updateHash'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1032, 'ENCRYPTION_TEMPPASS', 'Clave Maestra Temporal', 'encryption/createTempPass'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1040, 'BACKUP_CONFIG', 'Configuración Copia de Seguridad', 'backup/config'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1050, 'IMPORT_CONFIG', 'Configuración Importación', 'import/config'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1051, 'IMPORT_CSV', 'Importar CSV', 'import/csv'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1052, 'IMPORT_XML', 'Importar XML', 'import/xml'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1070, 'MAIL_CONFIG', 'Configuración Email', 'mail/config'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1080, 'LDAP_CONFIG', 'Configuración LDAP', 'ldap/config'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (1081, 'LDAP_SYNC', 'Sincronización LDAP', 'ldap/sync'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (6701, 'ACCOUNTMGR_HISTORY', 'Gestión de Cuenta (H)', 'accountHistoryManager/index'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (6731, 'ACCOUNTMGR_DELETE_HISTORY', 'Eliminar Cuenta', 'accountHistoryManager/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (6751, 'ACCOUNTMGR_SEARCH_HISTORY', 'Buscar Cuenta', 'accountHistoryManager/search'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (6771, 'ACCOUNTMGR_RESTORE', 'Restaurar Cuenta', 'accountManager/restore'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (7610, 'NOTICE_USER_VIEW', 'Ver Notificación', 'userNotice/view'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (7611, 'NOTICE_USER_CREATE', 'Crear Notificación', 'userNotice/create'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (7612, 'NOTICE_USER_EDIT', 'Editar Notificación', 'userNotice/edit'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (7613, 'NOTICE_USER_DELETE', 'Eliminar Notificación', 'userNotice/delete'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (7614, 'NOTICE_USER_CHECK', 'Marcar Notificación', 'userNotice/check'); +INSERT INTO actions (action_id, action_name, action_text, action_route) +VALUES (7615, 'NOTICE_USER_SEARCH', 'Buscar Notificación', 'userNotice/search'); + +ALTER TABLE customFieldsDef + MODIFY field BLOB; +ALTER TABLE customFieldsDef + ADD required TINYINT(1) UNSIGNED NULL; +ALTER TABLE customFieldsDef + ADD help VARCHAR(255) NULL; +ALTER TABLE customFieldsDef + ADD showInList TINYINT(1) UNSIGNED NULL; +ALTER TABLE customFieldsDef + ADD name VARCHAR(100) NOT NULL; +ALTER TABLE customFieldsDef + MODIFY COLUMN name VARCHAR(100) NOT NULL + AFTER id; +ALTER TABLE customFieldsDef + CHANGE customfielddef_module moduleId SMALLINT(5) UNSIGNED NOT NULL; +ALTER TABLE customFieldsDef + CHANGE customfielddef_field field BLOB NOT NULL; +ALTER TABLE customFieldsData + DROP FOREIGN KEY fk_customFieldsDef_id; +ALTER TABLE customFieldsData + CHANGE customfielddata_defId defId INT(10) UNSIGNED NOT NULL; +ALTER TABLE customFieldsDef + CHANGE customfielddef_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT; +ALTER TABLE customFieldsData + ADD CONSTRAINT fk_customFieldsDef_id +FOREIGN KEY (definitionId) REFERENCES customFieldsDef (id); +ALTER TABLE customFieldsData + CHANGE customfielddata_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT; +ALTER TABLE customFieldsData + CHANGE customfielddata_moduleId moduleId SMALLINT(5) UNSIGNED NOT NULL; +ALTER TABLE customFieldsData + CHANGE customfielddata_itemId itemId INT(10) UNSIGNED NOT NULL; +ALTER TABLE customFieldsData + CHANGE customfielddata_data data LONGBLOB; +ALTER TABLE customFieldsData + CHANGE customfielddata_key `key` VARBINARY(1000); + +CREATE TABLE customFieldsType +( + id TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(50) NOT NULL, + text VARCHAR(50) NOT NULL +); + +ALTER TABLE customFieldsDef + ADD typeId TINYINT UNSIGNED NULL; +ALTER TABLE customFieldsDef + ADD CONSTRAINT fk_customFieldsType_id +FOREIGN KEY (typeId) REFERENCES customFieldsType (id) + ON UPDATE CASCADE; + +CREATE TABLE customFieldsType +( + id TINYINT(3) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT, + name VARCHAR(50) NOT NULL, + text VARCHAR(50) NOT NULL +); + +-- Extraer antes desde los datos +INSERT INTO customFieldsType (id, name, text) VALUES (1, 'text', 'Texto'); +INSERT INTO customFieldsType (id, name, text) VALUES (2, 'password', 'Clave'); +INSERT INTO customFieldsType (id, name, text) VALUES (3, 'date', 'Fecha'); +INSERT INTO customFieldsType (id, name, text) VALUES (4, 'number', 'Número'); +INSERT INTO customFieldsType (id, name, text) VALUES (5, 'email', 'Email'); +INSERT INTO customFieldsType (id, name, text) VALUES (6, 'telephone', 'Teléfono'); +INSERT INTO customFieldsType (id, name, text) VALUES (7, 'url', 'URL'); +INSERT INTO customFieldsType (id, name, text) VALUES (8, 'color', 'Color'); +INSERT INTO customFieldsType (id, name, text) VALUES (9, 'wiki', 'Wiki'); +INSERT INTO customFieldsType (id, name, text) VALUES (10, 'textarea', 'Área de texto'); + +ALTER TABLE accFiles + DROP FOREIGN KEY fk_accFiles_accounts_id; +ALTER TABLE accFiles + CHANGE accfile_accountId accountId SMALLINT(5) UNSIGNED NOT NULL; +ALTER TABLE accFiles + ADD CONSTRAINT fk_account_id +FOREIGN KEY (accountId) REFERENCES accounts (account_id); +ALTER TABLE accFiles + CHANGE accfile_id id INT(11) NOT NULL AUTO_INCREMENT; +ALTER TABLE accFiles + CHANGE accfile_name name VARCHAR(100) NOT NULL; +ALTER TABLE accFiles + CHANGE accfile_type type VARCHAR(100) NOT NULL; +ALTER TABLE accFiles + CHANGE accfile_size size INT(11) NOT NULL; +ALTER TABLE accFiles + CHANGE accfile_content content MEDIUMBLOB NOT NULL; +ALTER TABLE accFiles + CHANGE accfile_extension extension VARCHAR(10) NOT NULL; +ALTER TABLE accFiles + CHANGE accFile_thumb thumb MEDIUMBLOB; + +CREATE OR REPLACE VIEW account_search_v AS + SELECT DISTINCT + `accounts`.`account_id` AS `account_id`, + `accounts`.`account_customerId` AS `account_customerId`, + `accounts`.`account_categoryId` AS `account_categoryId`, + `accounts`.`account_name` AS `account_name`, + `accounts`.`account_login` AS `account_login`, + `accounts`.`account_url` AS `account_url`, + `accounts`.`account_notes` AS `account_notes`, + `accounts`.`account_userId` AS `account_userId`, + `accounts`.`account_userGroupId` AS `account_userGroupId`, + `accounts`.`account_otherUserEdit` AS `account_otherUserEdit`, + `accounts`.`account_otherGroupEdit` AS `account_otherGroupEdit`, + `accounts`.`account_isPrivate` AS `account_isPrivate`, + `accounts`.`account_isPrivateGroup` AS `account_isPrivateGroup`, + `accounts`.`account_passDate` AS `account_passDate`, + `accounts`.`account_passDateChange` AS `account_passDateChange`, + `accounts`.`account_parentId` AS `account_parentId`, + `accounts`.`account_countView` AS `account_countView`, + `ug`.`usergroup_name` AS `usergroup_name`, + `categories`.`category_name` AS `category_name`, + `customers`.`customer_name` AS `customer_name`, + (SELECT count(0) + FROM `accFiles` + WHERE (`accFiles`.`accountId` = `accounts`.`account_id`)) AS `num_files` + FROM (((`accounts` + LEFT JOIN `categories` + ON ((`accounts`.`account_categoryId` = `categories`.`category_id`))) LEFT JOIN + `usrGroups` `ug` ON ((`accounts`.`account_userGroupId` = `ug`.`usergroup_id`))) LEFT JOIN + `customers` ON ((`customers`.`customer_id` = `accounts`.`account_customerId`))); + +ALTER TABLE plugins + CHANGE plugin_id id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT; +ALTER TABLE plugins + CHANGE plugin_name name VARCHAR(100) NOT NULL; +ALTER TABLE plugins + CHANGE plugin_data data VARBINARY(5000); +ALTER TABLE plugins + CHANGE plugin_enabled enabled TINYINT(1) NOT NULL DEFAULT 0; +ALTER TABLE plugins + CHANGE plugin_available available TINYINT(1) DEFAULT 0; \ No newline at end of file diff --git a/schemas/dbstructure.sql b/schemas/dbstructure.sql index 9c3d386e..5eece34f 100644 --- a/schemas/dbstructure.sql +++ b/schemas/dbstructure.sql @@ -520,7 +520,7 @@ CREATE OR REPLACE ALGORITHM = UNDEFINED DEFINER = CURRENT_USER SQL SECURITY DEFI FROM `accFiles` WHERE - (`accFiles`.`accfile_accountId` = `accounts`.`account_id`)) AS `num_files` + (`accFiles`.accountId = `accounts`.`account_id`)) AS `num_files` FROM (((`accounts` LEFT JOIN `categories` ON ((`accounts`.`account_categoryId` = `categories`.`category_id`)))