diff --git a/ajax/ajax_appMgmtData.php b/ajax/ajax_appMgmtData.php index 583dbe8a..2509b431 100644 --- a/ajax/ajax_appMgmtData.php +++ b/ajax/ajax_appMgmtData.php @@ -69,6 +69,12 @@ switch ($actionId) { $Controller = new AccItemController($Tpl); $Controller->getUser(); break; + case ActionsInterface::ACTION_USR_USERS_EDITPASS: + $Tpl->assign('header', _('Cambio de Clave')); + $Tpl->assign('onCloseAction', ActionsInterface::ACTION_USR); + $Controller = new AccItemController($Tpl); + $Controller->getUserPass(); + break; case ActionsInterface::ACTION_USR_USERS_NEW: $Tpl->assign('header', _('Nuevo Usuario')); $Tpl->assign('onCloseAction', ActionsInterface::ACTION_USR); diff --git a/ajax/ajax_doLogin.php b/ajax/ajax_doLogin.php index 0887e229..9f63070d 100644 --- a/ajax/ajax_doLogin.php +++ b/ajax/ajax_doLogin.php @@ -222,8 +222,8 @@ if ($UserPass->getClearUserMPass()) { SessionUtil::loadUserSession($User->getItemData()); $Log->addDetails(_('Usuario'), $User->getItemData()->getUserLogin()); - $Log->addDetails(_('Perfil'), Profile::getItem()->getById($User->getItemData()->getUserProfileId())->getItemData()->getUserprofileName()); - $Log->addDetails(_('Grupo'), Group::getItem()->getById($User->getItemData()->getUserGroupId())->getItemData()->getUsergroupName()); + $Log->addDetails(_('Perfil'), Profile::getItem()->getById($User->getItemData()->getUserProfileId())->getUserprofileName()); + $Log->addDetails(_('Grupo'), Group::getItem()->getById($User->getItemData()->getUserGroupId())->getUsergroupName()); $Log->writeLog(); } else { $Log->setLogLevel(Log::ERROR); @@ -234,7 +234,7 @@ if ($UserPass->getClearUserMPass()) { Json::returnJson($Json); } -$UserPreferencesData = UserPreferences::getItem()->getById($User->getItemData()->getUserId())->getItemData(); +$UserPreferencesData = UserPreferences::getItem()->getById($User->getItemData()->getUserId()); Language::setLanguage(true); DiFactory::getTheme()->initTheme(true); Session::setUserPreferences($UserPreferencesData); diff --git a/ajax/ajax_filesMgmt.php b/ajax/ajax_filesMgmt.php index aa436346..259ec1fc 100644 --- a/ajax/ajax_filesMgmt.php +++ b/ajax/ajax_filesMgmt.php @@ -151,7 +151,7 @@ if ($actionId === ActionsInterface::ACTION_ACC_FILES_UPLOAD) { Response::printJson(_('No es un ID de archivo válido')); } - $FileData = File::getItem()->getById($fileId)->getItemData(); + $FileData = File::getItem()->getById($fileId); if (!$FileData) { Response::printJson(_('El archivo no existe')); diff --git a/ajax/ajax_userPrefsSave.php b/ajax/ajax_userPrefsSave.php index 9348ef1f..6b94e7dc 100644 --- a/ajax/ajax_userPrefsSave.php +++ b/ajax/ajax_userPrefsSave.php @@ -112,7 +112,7 @@ if ($actionId === ActionsInterface::ACTION_USR_PREFERENCES_GENERAL) { } try { - $UserPreferencesData = UserPreferences::getItem()->getById($itemId)->getItemData(); + $UserPreferencesData = UserPreferences::getItem()->getById($itemId); $UserPreferencesData->setUse2Fa(Util::boolval($twoFaEnabled)); UserPreferences::getItem($UserPreferencesData)->update(); diff --git a/ajax/ajax_usrpass.php b/ajax/ajax_usrpass.php deleted file mode 100644 index 816eced6..00000000 --- a/ajax/ajax_usrpass.php +++ /dev/null @@ -1,52 +0,0 @@ -. - * - */ - -use SP\Controller\AccItemController; -use SP\Core\Init; -use SP\Core\Template; -use SP\Http\Request; -use SP\Util\Util; - -define('APP_ROOT', '..'); - -require_once APP_ROOT . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'Base.php'; - -Request::checkReferer('GET'); - -if (!Init::isLoggedIn()) { - Util::logout(); -} - -$userId = Request::analyze('userId', false); - -if (!$userId) { - return; -} - -$Tpl = new Template(); -$Tpl->assign('userId', $userId); -$Controller = new AccItemController($Tpl); -$Controller->getUserPass(); -$Controller->view(); \ No newline at end of file diff --git a/inc/SP/Account/AccountSearch.class.php b/inc/SP/Account/AccountSearch.class.php index 396ba77f..db4ca3c2 100644 --- a/inc/SP/Account/AccountSearch.class.php +++ b/inc/SP/Account/AccountSearch.class.php @@ -353,6 +353,7 @@ class AccountSearch $queryLimit = ''; $Data = new QueryData(); + $Data->setMapClassName('SP\DataModel\AccountSearchData'); if ($this->txtSearch) { // Analizar la cadena de búsqueda por etiquetas especiales @@ -380,7 +381,6 @@ class AccountSearch $arrFilterCommon[] = 'account_notes LIKE ?'; $Data->addParam($txtSearch); - } } @@ -397,9 +397,6 @@ class AccountSearch if ($this->searchFavorites === true) { $arrayQueryJoin[] = 'INNER JOIN accFavorites ON (accfavorite_accountId = account_id AND accfavorite_userId = ?)'; $Data->addParam(Session::getUserId()); - -// $arrFilterSelect[] = 'accfavorite_userId = ?'; -// $Data->addParam(Session::getUserId()); } if (count($arrFilterCommon) > 0) { @@ -411,36 +408,15 @@ class AccountSearch } if (!$isAdmin && !$this->globalSearch) { - /* $subQueryGroups = '(SELECT user_groupId FROM usrData WHERE user_id = ? UNION ALL SELECT usertogroup_groupId FROM usrToGroups WHERE usertogroup_userId = ?)'; - - // Buscar el grupo principal de la cuenta en los grupos del usuario - $arrFilterUser[] = 'account_userGroupId IN ' . $subQueryGroups; - $Data->addParam(Session::getUserId()); - $Data->addParam(Session::getUserId()); - - // Buscar los grupos secundarios de la cuenta en los grupos del usuario - $arrFilterUser[] = 'accgroup_groupId IN ' . $subQueryGroups; - $Data->addParam(Session::getUserId()); - $Data->addParam(Session::getUserId()); - - // Comprobar el usuario principal de la cuenta con el usuario actual - $arrFilterUser[] = 'account_userId = ?'; - $Data->addParam(Session::getUserId()); - - // Comprobar los usuarios secundarios de la cuenta con el usuario actual - $arrFilterUser[] = 'accuser_userId = ?'; - $Data->addParam(Session::getUserId()); - - $arrQueryWhere[] = '(' . implode(' OR ', $arrFilterUser) . ')';*/ - $arrFilterUser[] = 'account_userId = ?'; $Data->addParam(Session::getUserId()); $arrFilterUser[] = 'account_userGroupId = ?'; $Data->addParam(Session::getUserGroupId()); - $arrFilterUser[] = 'account_id IN (SELECT accuser_accountId FROM accUsers WHERE accuser_userId = ?)'; + $arrFilterUser[] = 'account_id IN (SELECT accuser_accountId AS accountId FROM accUsers WHERE accuser_accountId = account_id AND accuser_userId = ? UNION ALL SELECT accgroup_accountId AS accountId FROM accGroups WHERE accgroup_accountId = account_id AND accgroup_groupId = ?)'; $Data->addParam(Session::getUserId()); - $arrFilterUser[] = 'account_userGroupId IN (SELECT usertogroup_groupId FROM usrToGroups WHERE usertogroup_userId = ?)'; $Data->addParam(Session::getUserGroupId()); + $arrFilterUser[] = 'account_userGroupId IN (SELECT usertogroup_groupId FROM usrToGroups WHERE usertogroup_groupId = account_userGroupId AND usertogroup_userId = ?)'; + $Data->addParam(Session::getUserId()); $arrQueryWhere[] = '(' . implode(' OR ', $arrFilterUser) . ')'; } @@ -452,12 +428,12 @@ class AccountSearch $Data->addParam($this->limitCount); } + $queryWhere = ''; + if (count($arrQueryWhere) === 1) { $queryWhere = implode($arrQueryWhere); } elseif (count($arrQueryWhere) > 1) { $queryWhere = implode(' AND ', $arrQueryWhere); - } else { - $queryWhere = ''; } $queryJoin = implode('', $arrayQueryJoin); @@ -468,16 +444,14 @@ class AccountSearch $Data->setOrder($this->getOrderString()); $Data->setLimit($queryLimit); -// $Data->setQuery($query); - $Data->setMapClassName('SP\DataModel\AccountSearchData'); - // Obtener el número total de cuentas visibles por el usuario DB::setFullRowCount(); // Obtener los resultados siempre en array de objetos DB::setReturnArray(); - Log::writeNewLog(__FUNCTION__, $Data->getQuery(), Log::DEBUG); +// Log::writeNewLog(__FUNCTION__, $Data->getQuery(), Log::DEBUG); +// Log::writeNewLog(__FUNCTION__, print_r($Data->getParams(), true), Log::DEBUG); // Consulta de la búsqueda de cuentas $queryRes = DB::getResults($Data); @@ -487,7 +461,7 @@ class AccountSearch } // Obtenemos el número de registros totales de la consulta sin contar el LIMIT - self::$queryNumRows = DB::$lastNumRows; + self::$queryNumRows = $Data->getQueryNumRows(); // Establecer el filtro de búsqueda en la sesión como un objeto Session::setSearchFilters($this); diff --git a/inc/SP/Account/AccountUtil.class.php b/inc/SP/Account/AccountUtil.class.php index caee9dc8..a115e8ee 100644 --- a/inc/SP/Account/AccountUtil.class.php +++ b/inc/SP/Account/AccountUtil.class.php @@ -200,7 +200,7 @@ class AccountUtil return array(); } - $queryRes['count'] = DB::$lastNumRows; + $queryRes['count'] = $Data->getQueryNumRows(); return $queryRes; } diff --git a/inc/SP/Api/ApiTokens.class.php b/inc/SP/Api/ApiTokens.class.php index 09c30c7b..ba84a495 100644 --- a/inc/SP/Api/ApiTokens.class.php +++ b/inc/SP/Api/ApiTokens.class.php @@ -140,7 +140,7 @@ class ApiTokens throw new SPException(SPException::SP_CRITICAL, _('Error interno')); } - if (DB::$lastNumRows === 1) { + if ($Data->getQueryNumRows() === 1) { throw new SPException(SPException::SP_WARNING, _('La autorización ya existe')); } } @@ -189,7 +189,7 @@ class ApiTokens throw new SPException(SPException::SP_CRITICAL, _('Error interno')); } - if (DB::$lastNumRows === 0) { + if ($Data->getQueryNumRows() === 0) { return false; } diff --git a/inc/SP/Api/ApiTokensUtil.class.php b/inc/SP/Api/ApiTokensUtil.class.php index ced9e4b3..c4637f4a 100644 --- a/inc/SP/Api/ApiTokensUtil.class.php +++ b/inc/SP/Api/ApiTokensUtil.class.php @@ -133,7 +133,7 @@ class ApiTokensUtil $token->authtoken_actionId = Acl::getActionName($token->authtoken_actionId); } - $queryRes['count'] = DB::$lastNumRows; + $queryRes['count'] = $Data->getQueryNumRows(); return $queryRes; } @@ -178,7 +178,7 @@ class ApiTokensUtil throw new SPException(SPException::SP_CRITICAL, _('Error interno')); } - if (DB::$lastNumRows === 0) { + if ($Data->getQueryNumRows() === 0) { return false; } diff --git a/inc/SP/Auth/Auth.class.php b/inc/SP/Auth/Auth.class.php index 18632814..5db3ef3c 100644 --- a/inc/SP/Auth/Auth.class.php +++ b/inc/SP/Auth/Auth.class.php @@ -255,7 +255,7 @@ class Auth DB::getQuery($Data); - return (DB::$lastNumRows === 1); + return ($Data->getQueryNumRows() === 1); } /** diff --git a/inc/SP/Controller/AccItemController.class.php b/inc/SP/Controller/AccItemController.class.php index a4770a6d..26954d10 100644 --- a/inc/SP/Controller/AccItemController.class.php +++ b/inc/SP/Controller/AccItemController.class.php @@ -87,7 +87,7 @@ class AccItemController extends ControllerBase implements ActionsInterface $this->module = self::ACTION_USR_USERS; $this->view->addTemplate('users'); - $this->view->assign('user', $this->view->itemId ? User::getItem()->getById($this->view->itemId)->getItemData() : new UserData()); + $this->view->assign('user', $this->view->itemId ? User::getItem()->getById($this->view->itemId) : new UserData()); $this->view->assign('isDisabled', ((User::getItem()->getItemData()->getUserLogin() === 'demo' && $this->view->isDemo) || $this->view->actionId === self::ACTION_USR_USERS_VIEW) ? 'disabled' : ''); $this->view->assign('groups', Group::getItem()->getItemsForSelect()); $this->view->assign('profiles', Profile::getItem()->getItemsForSelect()); @@ -111,7 +111,7 @@ class AccItemController extends ControllerBase implements ActionsInterface $this->module = self::ACTION_USR_GROUPS; $this->view->addTemplate('groups'); - $this->view->assign('group', Group::getItem()->getById($this->view->itemId)->getItemData()); + $this->view->assign('group', Group::getItem()->getById($this->view->itemId)); $this->view->assign('users', User::getItem()->getItemsForSelect()); $this->view->assign('groupUsers', GroupUsers::getItem()->getById($this->view->itemId)); @@ -126,7 +126,7 @@ class AccItemController extends ControllerBase implements ActionsInterface $this->module = self::ACTION_USR_PROFILES; $this->view->addTemplate('profiles'); - $Profile = $this->view->itemId ? Profile::getItem()->getById($this->view->itemId)->getItemData() : new ProfileData(); + $Profile = $this->view->itemId ? Profile::getItem()->getById($this->view->itemId) : new ProfileData(); $this->view->assign('profile', $Profile); $this->view->assign('isDisabled', ($this->view->actionId === self::ACTION_USR_PROFILES_VIEW) ? 'disabled' : ''); @@ -159,13 +159,12 @@ class AccItemController extends ControllerBase implements ActionsInterface $this->setAction(self::ACTION_USR_USERS_EDITPASS); // Comprobar si el usuario a modificar es distinto al de la sesión - if ($this->view->userId != Session::getUserId() && !$this->checkAccess()) { + if ($this->view->itemId !== Session::getUserId() && !$this->checkAccess()) { return; } + $this->view->assign('user', User::getItem()->getById($this->view->itemId)); $this->view->addTemplate('userspass'); - - $this->view->assign('actionId', self::ACTION_USR_USERS_EDITPASS); } /** @@ -199,6 +198,6 @@ class AccItemController extends ControllerBase implements ActionsInterface $this->module = self::ACTION_MGM_PUBLICLINKS; $this->view->addTemplate('publiclinks'); - $this->view->assign('link', PublicLink::getItem()->getById($this->view->itemId)->getItemData()); + $this->view->assign('link', PublicLink::getItem()->getById($this->view->itemId)); } } \ No newline at end of file diff --git a/inc/SP/Controller/AppItemController.class.php b/inc/SP/Controller/AppItemController.class.php index ba7f64c6..c22a7062 100644 --- a/inc/SP/Controller/AppItemController.class.php +++ b/inc/SP/Controller/AppItemController.class.php @@ -80,7 +80,7 @@ class AppItemController extends ControllerBase implements ActionsInterface $this->_module = self::ACTION_MGM_CUSTOMERS; $this->view->addTemplate('customers'); - $this->view->assign('customer', ($this->view->itemId) ? Customer::getItem()->getById($this->view->itemId)->getItemData() : new CustomerData()); + $this->view->assign('customer', ($this->view->itemId) ? Customer::getItem()->getById($this->view->itemId) : new CustomerData()); $this->getCustomFieldsForItem(); } @@ -100,7 +100,7 @@ class AppItemController extends ControllerBase implements ActionsInterface $this->_module = self::ACTION_MGM_CATEGORIES; $this->view->addTemplate('categories'); - $this->view->assign('category', ($this->view->itemId) ? Category::getItem()->getById($this->view->itemId)->getItemData() : new CategoryData()); + $this->view->assign('category', ($this->view->itemId) ? Category::getItem()->getById($this->view->itemId) : new CategoryData()); $this->getCustomFieldsForItem(); } @@ -131,7 +131,7 @@ class AppItemController extends ControllerBase implements ActionsInterface { $this->view->addTemplate('customfields'); - $customField = ($this->view->itemId) ? CustomFieldDef::getItem()->getById($this->view->itemId)->getItemData() : new CustomFieldDefData(); + $customField = ($this->view->itemId) ? CustomFieldDef::getItem()->getById($this->view->itemId) : new CustomFieldDefData(); $this->view->assign('customField', $customField); $this->view->assign('field', $customField); @@ -147,6 +147,6 @@ class AppItemController extends ControllerBase implements ActionsInterface $this->_module = self::ACTION_MGM_TAGS; $this->view->addTemplate('tags'); - $this->view->assign('tag', ($this->view->itemId) ? Tag::getItem()->getById($this->view->itemId)->getItemData() : new TagData()); + $this->view->assign('tag', ($this->view->itemId) ? Tag::getItem()->getById($this->view->itemId) : new TagData()); } } diff --git a/inc/SP/Controller/Grids.class.php b/inc/SP/Controller/Grids.class.php index 82bdbe34..20642530 100644 --- a/inc/SP/Controller/Grids.class.php +++ b/inc/SP/Controller/Grids.class.php @@ -443,7 +443,7 @@ class Grids implements ActionsInterface $GridActionEditPass->setName(_('Cambiar Clave de Usuario')); $GridActionEditPass->setTitle(_('Cambiar Clave de Usuario')); $GridActionEditPass->setIcon($this->icons->getIconEditPass()); - $GridActionEditPass->setOnClickFunction('user/password'); + $GridActionEditPass->setOnClickFunction('appMgmt/show'); $GridActionEditPass->setFilterRowSource('user_isLdap'); $GridHeaders = new DataGridHeader(); diff --git a/inc/SP/Controller/UserPreferencesController.class.php b/inc/SP/Controller/UserPreferencesController.class.php index db130056..caf51ae1 100644 --- a/inc/SP/Controller/UserPreferencesController.class.php +++ b/inc/SP/Controller/UserPreferencesController.class.php @@ -73,7 +73,7 @@ class UserPreferencesController extends ControllerBase implements ActionsInterfa $this->view->assign('tabs', array()); $this->view->assign('sk', SessionUtil::getSessionKey(true)); $this->userId = Session::getUserId(); - $this->userPrefs = UserPreferences::getItem()->getById($this->userId)->getItemData(); + $this->userPrefs = UserPreferences::getItem()->getById($this->userId); } /** diff --git a/inc/SP/Core/Init.class.php b/inc/SP/Core/Init.class.php index 9ea667f4..f2702987 100644 --- a/inc/SP/Core/Init.class.php +++ b/inc/SP/Core/Init.class.php @@ -640,7 +640,7 @@ class Init session_regenerate_id(true); Session::setSidStartTime(time()); // Recargar los permisos del perfil de usuario - Session::setUserProfile(Profile::getItem()->getById(Session::getUserProfileId())->getItemData()); + Session::setUserProfile(Profile::getItem()->getById(Session::getUserProfileId())); // Regenerar la clave maestra SessionUtil::saveSessionMPass($sessionMPass); } diff --git a/inc/SP/Core/Language.class.php b/inc/SP/Core/Language.class.php index a0a80953..b1a4a193 100644 --- a/inc/SP/Core/Language.class.php +++ b/inc/SP/Core/Language.class.php @@ -80,7 +80,7 @@ class Language */ private function getUserLang() { - return (Session::getUserId() > 0) ? UserPreferences::getItem()->getById(Session::getUserId())->getItemData()->getLang() : ''; + return (Session::getUserId() > 0) ? UserPreferences::getItem()->getById(Session::getUserId())->getLang() : ''; } /** diff --git a/inc/SP/Core/SessionUtil.class.php b/inc/SP/Core/SessionUtil.class.php index 32bbda22..a98b5975 100644 --- a/inc/SP/Core/SessionUtil.class.php +++ b/inc/SP/Core/SessionUtil.class.php @@ -57,7 +57,7 @@ class SessionUtil Session::setUserIsAdminApp($UserData->isUserIsAdminApp()); Session::setUserIsAdminAcc($UserData->isUserIsAdminAcc()); Session::setUserIsLdap($UserData->isUserIsLdap()); - Session::setUserProfile(Profile::getItem()->getById($UserData->getUserProfileId())->getItemData()); + Session::setUserProfile(Profile::getItem()->getById($UserData->getUserProfileId())); } /** diff --git a/inc/SP/Core/UI/Theme.class.php b/inc/SP/Core/UI/Theme.class.php index eac43eab..3fce803a 100644 --- a/inc/SP/Core/UI/Theme.class.php +++ b/inc/SP/Core/UI/Theme.class.php @@ -102,7 +102,7 @@ class Theme implements ThemeInterface */ protected function getUserTheme() { - return (Session::getUserId() > 0) ? UserPreferences::getItem()->getById(Session::getUserId())->getItemData()->getTheme() : ''; + return (Session::getUserId() > 0) ? UserPreferences::getItem()->getById(Session::getUserId())->getTheme() : ''; } /** diff --git a/inc/SP/Import/Migrate.class.php b/inc/SP/Import/Migrate.class.php index 987d9e4d..1cf89d93 100644 --- a/inc/SP/Import/Migrate.class.php +++ b/inc/SP/Import/Migrate.class.php @@ -262,7 +262,7 @@ class Migrate DB::getQuery($Data); - return (DB::$lastNumRows === 0); + return ($Data->getQueryNumRows() === 0); } /** diff --git a/inc/SP/Log/Log.class.php b/inc/SP/Log/Log.class.php index bb20d0aa..1031e141 100644 --- a/inc/SP/Log/Log.class.php +++ b/inc/SP/Log/Log.class.php @@ -82,7 +82,7 @@ class Log extends ActionLog return false; } - self::$numRows = DB::$lastNumRows; + self::$numRows = $Data->getQueryNumRows(); return $queryRes; } diff --git a/inc/SP/Mgmt/Categories/Category.class.php b/inc/SP/Mgmt/Categories/Category.class.php index 296fa0d3..e5bdeab1 100644 --- a/inc/SP/Mgmt/Categories/Category.class.php +++ b/inc/SP/Mgmt/Categories/Category.class.php @@ -92,7 +92,7 @@ class Category extends CategoryBase implements ItemInterface, ItemSelectInterfac $Data->setQuery($query); $Data->addParam($this->itemData->getCategoryName()); - return (DB::getQuery($Data) === false || DB::$lastNumRows >= 1); + return (DB::getQuery($Data) === false || $Data->getQueryNumRows() >= 1); } /** @@ -110,7 +110,7 @@ class Category extends CategoryBase implements ItemInterface, ItemSelectInterfac ); } - $oldCategory = $this->getById($this->itemData->getCategoryId())->getItemData(); + $oldCategory = $this->getById($this->itemData->getCategoryId()); $query = /** @lang SQL */ 'DELETE FROM categories WHERE category_id = ? LIMIT 1'; @@ -145,12 +145,12 @@ class Category extends CategoryBase implements ItemInterface, ItemSelectInterfac DB::getQuery($Data); - return DB::$lastNumRows > 0; + return $Data->getQueryNumRows() > 0; } /** * @param $id int - * @return $this + * @return CategoryData */ public function getById($id) { @@ -162,9 +162,7 @@ class Category extends CategoryBase implements ItemInterface, ItemSelectInterfac $Data->addParam($id); $Data->setMapClassName($this->getDataModel()); - $this->itemData = DB::getResults($Data); - - return $this; + return DB::getResults($Data); } /** @@ -177,7 +175,7 @@ class Category extends CategoryBase implements ItemInterface, ItemSelectInterfac throw new SPException(SPException::SP_WARNING, _('Nombre de categoría duplicado')); } - $oldCategory = $this->getById($this->itemData->getCategoryId())->getItemData(); + $oldCategory = $this->getById($this->itemData->getCategoryId()); $query = /** @lang SQL */ 'UPDATE categories @@ -218,7 +216,7 @@ class Category extends CategoryBase implements ItemInterface, ItemSelectInterfac $Data->addParam($this->itemData->getCategoryName()); $Data->addParam($this->itemData->getCategoryId()); - return (DB::getQuery($Data) === false || DB::$lastNumRows > 0); + return (DB::getQuery($Data) === false || $Data->getQueryNumRows() > 0); } /** diff --git a/inc/SP/Mgmt/Categories/CategorySearch.class.php b/inc/SP/Mgmt/Categories/CategorySearch.class.php index 0dc6da18..8cb6759a 100644 --- a/inc/SP/Mgmt/Categories/CategorySearch.class.php +++ b/inc/SP/Mgmt/Categories/CategorySearch.class.php @@ -79,7 +79,7 @@ class CategorySearch extends CategoryBase implements ItemSearchInterface return array(); } - $queryRes['count'] = DB::$lastNumRows; + $queryRes['count'] = $Data->getQueryNumRows(); return $queryRes; } diff --git a/inc/SP/Mgmt/CustomFields/CustomField.class.php b/inc/SP/Mgmt/CustomFields/CustomField.class.php index d5e9933c..59d63193 100644 --- a/inc/SP/Mgmt/CustomFields/CustomField.class.php +++ b/inc/SP/Mgmt/CustomFields/CustomField.class.php @@ -54,7 +54,7 @@ class CustomField extends CustomFieldBase implements ItemInterface parent::__construct($itemData); if (!is_null($customFieldDefId)) { - $field = CustomFieldDef::getItem()->getById($customFieldDefId)->getItemData(); + $field = CustomFieldDef::getItem()->getById($customFieldDefId); $itemData->setDefinitionId($customFieldDefId); $itemData->setModule($field->getModule()); @@ -121,7 +121,7 @@ class CustomField extends CustomFieldBase implements ItemInterface DB::getQuery($Data); - return (DB::$lastNumRows >= 1); + return ($Data->getQueryNumRows() >= 1); } /** diff --git a/inc/SP/Mgmt/CustomFields/CustomFieldDef.class.php b/inc/SP/Mgmt/CustomFields/CustomFieldDef.class.php index 58e4456f..c1f80e81 100644 --- a/inc/SP/Mgmt/CustomFields/CustomFieldDef.class.php +++ b/inc/SP/Mgmt/CustomFields/CustomFieldDef.class.php @@ -120,7 +120,7 @@ class CustomFieldDef extends CustomFieldBase implements ItemInterface */ public function update() { - $curField = $this->getById($this->itemData->getId())->getItemData(); + $curField = $this->getById($this->itemData->getId()); $query = /** @lang SQL */ 'UPDATE customFieldsDef SET @@ -147,7 +147,7 @@ class CustomFieldDef extends CustomFieldBase implements ItemInterface /** * @param $id int - * @return $this + * @return CustomFieldDefData * @throws \SP\Core\Exceptions\SPException */ public function getById($id) @@ -185,7 +185,7 @@ class CustomFieldDef extends CustomFieldBase implements ItemInterface $this->itemData = $fieldDef; - return $this; + return $fieldDef; } /** diff --git a/inc/SP/Mgmt/CustomFields/CustomFieldDefSearch.class.php b/inc/SP/Mgmt/CustomFields/CustomFieldDefSearch.class.php index 5b552b4e..b88bd61e 100644 --- a/inc/SP/Mgmt/CustomFields/CustomFieldDefSearch.class.php +++ b/inc/SP/Mgmt/CustomFields/CustomFieldDefSearch.class.php @@ -106,7 +106,7 @@ class CustomFieldDefSearch extends CustomFieldBase implements ItemSearchInterfac } } - $customFields['count'] = DB::$lastNumRows; + $customFields['count'] = $Data->getQueryNumRows(); return $customFields; } diff --git a/inc/SP/Mgmt/Customers/Customer.class.php b/inc/SP/Mgmt/Customers/Customer.class.php index aabfa4b0..4b89dad5 100644 --- a/inc/SP/Mgmt/Customers/Customer.class.php +++ b/inc/SP/Mgmt/Customers/Customer.class.php @@ -96,7 +96,7 @@ class Customer extends CustomerBase implements ItemInterface, ItemSelectInterfac $Data->setQuery($query); $Data->addParam($this->mkCustomerHash()); - return (DB::getQuery($Data) === false || DB::$lastNumRows >= 1); + return (DB::getQuery($Data) === false || $Data->getQueryNumRows() >= 1); } /** @@ -131,7 +131,7 @@ class Customer extends CustomerBase implements ItemInterface, ItemSelectInterfac ); } - $oldCustomer = $this->getById($id)->getItemData(); + $oldCustomer = $this->getById($id); $query = /** @lang SQL */ 'DELETE FROM customers WHERE customer_id = ? LIMIT 1'; @@ -168,12 +168,12 @@ class Customer extends CustomerBase implements ItemInterface, ItemSelectInterfac DB::getQuery($Data); - return DB::$lastNumRows > 0; + return $Data->getQueryNumRows() > 0; } /** * @param $id int - * @return $this + * @return CustomerData */ public function getById($id) { @@ -185,9 +185,7 @@ class Customer extends CustomerBase implements ItemInterface, ItemSelectInterfac $Data->setQuery($query); $Data->addParam($id); - $this->itemData = DB::getResults($Data); - - return $this; + return DB::getResults($Data); } /** @@ -200,7 +198,7 @@ class Customer extends CustomerBase implements ItemInterface, ItemSelectInterfac throw new SPException(SPException::SP_WARNING, _('Cliente duplicado')); } - $oldCustomer = $this->getById($this->itemData->getCustomerId())->getItemData(); + $oldCustomer = $this->getById($this->itemData->getCustomerId()); $query = /** @lang SQL */ 'UPDATE customers @@ -243,7 +241,7 @@ class Customer extends CustomerBase implements ItemInterface, ItemSelectInterfac $Data->addParam($this->mkCustomerHash()); $Data->addParam($this->itemData->getCustomerId()); - return (DB::getQuery($Data) === false || DB::$lastNumRows >= 1); + return (DB::getQuery($Data) === false || $Data->getQueryNumRows() >= 1); } /** diff --git a/inc/SP/Mgmt/Customers/CustomerSearch.class.php b/inc/SP/Mgmt/Customers/CustomerSearch.class.php index ec2779c6..47e597bc 100644 --- a/inc/SP/Mgmt/Customers/CustomerSearch.class.php +++ b/inc/SP/Mgmt/Customers/CustomerSearch.class.php @@ -80,7 +80,7 @@ class CustomerSearch extends CustomerBase implements ItemSearchInterface return array(); } - $queryRes['count'] = DB::$lastNumRows; + $queryRes['count'] = $Data->getQueryNumRows(); return $queryRes; } diff --git a/inc/SP/Mgmt/Files/File.class.php b/inc/SP/Mgmt/Files/File.class.php index d11e3600..3bde994b 100644 --- a/inc/SP/Mgmt/Files/File.class.php +++ b/inc/SP/Mgmt/Files/File.class.php @@ -178,7 +178,7 @@ class File extends FileBase implements ItemInterface, ItemSelectInterface /** * @param $id int - * @return $this + * @return FileData */ public function getById($id) { @@ -198,10 +198,7 @@ class File extends FileBase implements ItemInterface, ItemSelectInterface $Data->setQuery($query); $Data->addParam($id); - - $this->itemData = DB::getResults($Data); - - return $this; + return DB::getResults($Data); } /** diff --git a/inc/SP/Mgmt/Files/FileSearch.class.php b/inc/SP/Mgmt/Files/FileSearch.class.php index 052a15b4..ee662505 100644 --- a/inc/SP/Mgmt/Files/FileSearch.class.php +++ b/inc/SP/Mgmt/Files/FileSearch.class.php @@ -89,7 +89,7 @@ class FileSearch extends FileBase implements ItemSearchInterface return array(); } - $queryRes['count'] = DB::$lastNumRows; + $queryRes['count'] = $Data->getQueryNumRows(); return $queryRes; } diff --git a/inc/SP/Mgmt/Files/FileUtil.class.php b/inc/SP/Mgmt/Files/FileUtil.class.php index bfdf75ee..f7305381 100644 --- a/inc/SP/Mgmt/Files/FileUtil.class.php +++ b/inc/SP/Mgmt/Files/FileUtil.class.php @@ -90,7 +90,7 @@ class FileUtil DB::getQuery($Data); - return DB::$lastNumRows; + return $Data->getQueryNumRows(); } /** diff --git a/inc/SP/Mgmt/Groups/Group.class.php b/inc/SP/Mgmt/Groups/Group.class.php index 0f776a92..1c5bccdd 100644 --- a/inc/SP/Mgmt/Groups/Group.class.php +++ b/inc/SP/Mgmt/Groups/Group.class.php @@ -102,7 +102,7 @@ class Group extends GroupBase implements ItemInterface, ItemSelectInterface $Data->setQuery($query); $Data->addParam($this->itemData->getUsergroupName()); - return (DB::getQuery($Data) === false || DB::$lastNumRows >= 1); + return (DB::getQuery($Data) === false || $Data->getQueryNumRows() >= 1); } /** @@ -116,7 +116,7 @@ class Group extends GroupBase implements ItemInterface, ItemSelectInterface throw new SPException(SPException::SP_WARNING, _('Grupo en uso')); } - $GroupData = $this->getById($id)->getItemData(); + $GroupData = $this->getById($id); $query = /** @lang SQL */ 'DELETE FROM usrGroups WHERE usergroup_id = ? LIMIT 1'; @@ -173,12 +173,12 @@ class Group extends GroupBase implements ItemInterface, ItemSelectInterface DB::getQuery($Data); - return (DB::$lastNumRows > 1); + return ($Data->getQueryNumRows() > 1); } /** * @param $id int - * @return $this + * @return GroupData */ public function getById($id) { @@ -190,9 +190,7 @@ class Group extends GroupBase implements ItemInterface, ItemSelectInterface $Data->setQuery($query); $Data->addParam($id); - $this->itemData = DB::getResults($Data); - - return $this; + return DB::getResults($Data); } /** @@ -205,7 +203,7 @@ class Group extends GroupBase implements ItemInterface, ItemSelectInterface throw new SPException(SPException::SP_INFO, _('Nombre de grupo duplicado')); } - $GroupData = $this->getById($this->itemData->getUsergroupId())->getItemData(); + $GroupData = $this->getById($this->itemData->getUsergroupId()); $query = /** @lang SQL */ 'UPDATE usrGroups SET usergroup_name = ?, usergroup_description = ? WHERE usergroup_id = ? LIMIT 1'; @@ -253,7 +251,7 @@ class Group extends GroupBase implements ItemInterface, ItemSelectInterface $Data->addParam($this->itemData->getUsergroupName()); $Data->addParam($this->itemData->getUsergroupId()); - return (DB::getQuery($Data) === false || DB::$lastNumRows >= 1); + return (DB::getQuery($Data) === false || $Data->getQueryNumRows() >= 1); } /** diff --git a/inc/SP/Mgmt/Groups/GroupAccounts.class.php b/inc/SP/Mgmt/Groups/GroupAccounts.class.php index 5f267798..0dbc5ddd 100644 --- a/inc/SP/Mgmt/Groups/GroupAccounts.class.php +++ b/inc/SP/Mgmt/Groups/GroupAccounts.class.php @@ -148,7 +148,7 @@ class GroupAccounts extends GroupAccountsBase implements ItemInterface DB::getResults($Data); - return (DB::$lastNumRows > 1); + return ($Data->getQueryNumRows() > 1); } /** diff --git a/inc/SP/Mgmt/Groups/GroupSearch.class.php b/inc/SP/Mgmt/Groups/GroupSearch.class.php index 5976afa9..136f2f09 100644 --- a/inc/SP/Mgmt/Groups/GroupSearch.class.php +++ b/inc/SP/Mgmt/Groups/GroupSearch.class.php @@ -80,7 +80,7 @@ class GroupSearch extends GroupBase implements ItemSearchInterface return array(); } - $queryRes['count'] = DB::$lastNumRows; + $queryRes['count'] = $Data->getQueryNumRows(); return $queryRes; } diff --git a/inc/SP/Mgmt/Groups/GroupUsers.class.php b/inc/SP/Mgmt/Groups/GroupUsers.class.php index 755c74a8..d6af941a 100644 --- a/inc/SP/Mgmt/Groups/GroupUsers.class.php +++ b/inc/SP/Mgmt/Groups/GroupUsers.class.php @@ -152,7 +152,7 @@ class GroupUsers extends GroupUsersBase implements ItemInterface, ItemSelectInte DB::getResults($Data); - return (DB::$lastNumRows > 1); + return ($Data->getQueryNumRows() > 1); } /** diff --git a/inc/SP/Mgmt/Profiles/Profile.class.php b/inc/SP/Mgmt/Profiles/Profile.class.php index fceaf99b..f83b52c6 100644 --- a/inc/SP/Mgmt/Profiles/Profile.class.php +++ b/inc/SP/Mgmt/Profiles/Profile.class.php @@ -56,7 +56,7 @@ class Profile extends ProfileBase implements ItemInterface, ItemSelectInterface */ public function add() { - if ($this->checkDuplicatedOnAdd()){ + if ($this->checkDuplicatedOnAdd()) { throw new SPException(SPException::SP_INFO, _('Nombre de perfil duplicado')); } @@ -85,6 +85,25 @@ class Profile extends ProfileBase implements ItemInterface, ItemSelectInterface return $this; } + /** + * @return bool + */ + public function checkDuplicatedOnAdd() + { + $query = /** @lang SQL */ + 'SELECT userprofile_name + FROM usrProfiles + WHERE UPPER(userprofile_name) = ?'; + + $Data = new QueryData(); + $Data->addParam($this->itemData->getUserprofileName()); + $Data->setQuery($query); + + DB::getQuery($Data); + + return ($Data->getQueryNumRows() > 0); + } + /** * @param $id int * @return $this @@ -96,7 +115,7 @@ class Profile extends ProfileBase implements ItemInterface, ItemSelectInterface throw new SPException(SPException::SP_INFO, _('Perfil en uso')); } - $oldProfile = $this->getById($id)->getItemData(); + $oldProfile = $this->getById($id); $query = /** @lang SQL */ 'DELETE FROM usrProfiles WHERE userprofile_id = ? LIMIT 1'; @@ -118,17 +137,70 @@ class Profile extends ProfileBase implements ItemInterface, ItemSelectInterface return $this; } + /** + * @param $id int + * @return bool + */ + public function checkInUse($id) + { + $query = /** @lang SQL */ + 'SELECT user_profileId FROM usrData WHERE user_profileId = ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($id); + + DB::getQuery($Data); + + return ($Data->getQueryNumRows() > 0); + } + + /** + * @param $id int + * @return ProfileData + */ + public function getById($id) + { + $query = /** @lang SQL */ + 'SELECT userprofile_id, + userprofile_name, + userprofile_profile + FROM usrProfiles + WHERE userprofile_id = ? LIMIT 1'; + + $Data = new QueryData(); + $Data->setMapClassName($this->getDataModel()); + $Data->setQuery($query); + $Data->addParam($id); + + /** + * @var ProfileBaseData $ProfileData + * @var ProfileData $Profile + */ + $ProfileData = DB::getResults($Data); + $Profile = unserialize($ProfileData->getUserprofileProfile()); + + if (get_class($Profile) === '__PHP_Incomplete_Class') { + $Profile = Util::castToClass($this->getDataModel(), $Profile); + } + + $Profile->setUserprofileId($ProfileData->getUserprofileId()); + $Profile->setUserprofileName($ProfileData->getUserprofileName()); + + return $Profile; + } + /** * @return $this * @throws SPException */ public function update() { - if ($this->checkDuplicatedOnUpdate()){ + if ($this->checkDuplicatedOnUpdate()) { throw new SPException(SPException::SP_INFO, _('Nombre de perfil duplicado')); } - $oldProfileName = $this->getById($this->itemData->getUserprofileId())->getItemData(); + $oldProfileName = $this->getById($this->itemData->getUserprofileId()); $query = /** @lang SQL */ 'UPDATE usrProfiles SET @@ -156,40 +228,24 @@ class Profile extends ProfileBase implements ItemInterface, ItemSelectInterface } /** - * @param $id int - * @return $this + * @return bool */ - public function getById($id) + public function checkDuplicatedOnUpdate() { $query = /** @lang SQL */ - 'SELECT userprofile_id, - userprofile_name, - userprofile_profile + 'SELECT userprofile_name FROM usrProfiles - WHERE userprofile_id = ? LIMIT 1'; + WHERE UPPER(userprofile_name) = ? + AND userprofile_id <> ?'; $Data = new QueryData(); - $Data->setMapClassName($this->getDataModel()); + $Data->addParam($this->itemData->getUserprofileName()); + $Data->addParam($this->itemData->getUserprofileId()); $Data->setQuery($query); - $Data->addParam($id); - /** - * @var ProfileBaseData $ProfileData - * @var ProfileData $Profile - */ - $ProfileData = DB::getResults($Data); - $Profile = unserialize($ProfileData->getUserprofileProfile()); + DB::getQuery($Data); - if (get_class($Profile) === '__PHP_Incomplete_Class') { - $Profile = Util::castToClass($this->getDataModel(), $Profile); - } - - $Profile->setUserprofileId($ProfileData->getUserprofileId()); - $Profile->setUserprofileName($ProfileData->getUserprofileName()); - - $this->itemData = $Profile; - - return $this; + return ($Data->getQueryNumRows() > 0); } /** @@ -219,62 +275,4 @@ class Profile extends ProfileBase implements ItemInterface, ItemSelectInterface return DB::getResults($Data); } - - /** - * @param $id int - * @return bool - */ - public function checkInUse($id) - { - $query = /** @lang SQL */ - 'SELECT user_profileId FROM usrData WHERE user_profileId = ?'; - - $Data = new QueryData(); - $Data->setQuery($query); - $Data->addParam($id); - - DB::getQuery($Data); - - return (DB::$lastNumRows > 0); - } - - /** - * @return bool - */ - public function checkDuplicatedOnUpdate() - { - $query = /** @lang SQL */ - 'SELECT userprofile_name - FROM usrProfiles - WHERE UPPER(userprofile_name) = ? - AND userprofile_id <> ?'; - - $Data = new QueryData(); - $Data->addParam($this->itemData->getUserprofileName()); - $Data->addParam($this->itemData->getUserprofileId()); - $Data->setQuery($query); - - DB::getQuery($Data); - - return (DB::$lastNumRows > 0); - } - - /** - * @return bool - */ - public function checkDuplicatedOnAdd() - { - $query = /** @lang SQL */ - 'SELECT userprofile_name - FROM usrProfiles - WHERE UPPER(userprofile_name) = ?'; - - $Data = new QueryData(); - $Data->addParam($this->itemData->getUserprofileName()); - $Data->setQuery($query); - - DB::getQuery($Data); - - return (DB::$lastNumRows > 0); - } } diff --git a/inc/SP/Mgmt/Profiles/ProfileSearch.class.php b/inc/SP/Mgmt/Profiles/ProfileSearch.class.php index 4836b8e3..20793ad0 100644 --- a/inc/SP/Mgmt/Profiles/ProfileSearch.class.php +++ b/inc/SP/Mgmt/Profiles/ProfileSearch.class.php @@ -82,7 +82,7 @@ class ProfileSearch extends ProfileBase implements ItemSearchInterface return array(); } - $queryRes['count'] = DB::$lastNumRows; + $queryRes['count'] = $Data->getQueryNumRows(); return $queryRes; } diff --git a/inc/SP/Mgmt/PublicLinks/PublicLink.class.php b/inc/SP/Mgmt/PublicLinks/PublicLink.class.php index a0fc8469..cfdf60ff 100644 --- a/inc/SP/Mgmt/PublicLinks/PublicLink.class.php +++ b/inc/SP/Mgmt/PublicLinks/PublicLink.class.php @@ -163,7 +163,7 @@ class PublicLink extends PublicLinkBase implements ItemInterface DB::getResults($Data); - return (DB::$lastNumRows === 1); + return ($Data->getQueryNumRows() === 1); } /** diff --git a/inc/SP/Mgmt/PublicLinks/PublicLinkSearch.class.php b/inc/SP/Mgmt/PublicLinks/PublicLinkSearch.class.php index 6637682f..906943ae 100644 --- a/inc/SP/Mgmt/PublicLinks/PublicLinkSearch.class.php +++ b/inc/SP/Mgmt/PublicLinks/PublicLinkSearch.class.php @@ -69,7 +69,7 @@ class PublicLinkSearch extends PublicLinkBase implements ItemSearchInterface } $publicLinks = []; - $publicLinks['count'] = DB::$lastNumRows; + $publicLinks['count'] = $Data->getQueryNumRows(); foreach ($queryRes as $PublicLinkListData) { /** diff --git a/inc/SP/Mgmt/Tags/Tag.class.php b/inc/SP/Mgmt/Tags/Tag.class.php index b1a8e600..75cdfe93 100644 --- a/inc/SP/Mgmt/Tags/Tag.class.php +++ b/inc/SP/Mgmt/Tags/Tag.class.php @@ -80,7 +80,7 @@ class Tag extends TagBase implements ItemInterface, ItemSelectInterface $Data->setQuery($query); $Data->addParam($this->itemData->getTagHash()); - return (DB::getQuery($Data) === false || DB::$lastNumRows > 0 ); + return (DB::getQuery($Data) === false || $Data->getQueryNumRows() > 0 ); } /** @@ -142,12 +142,12 @@ class Tag extends TagBase implements ItemInterface, ItemSelectInterface $Data->addParam($this->itemData->getTagHash()); $Data->addParam($this->itemData->getTagId()); - return (DB::getQuery($Data) === false || DB::$lastNumRows > 0); + return (DB::getQuery($Data) === false || $Data->getQueryNumRows() > 0); } /** * @param $id int - * @return $this + * @return TagData * @throws SPException */ public function getById($id) @@ -166,9 +166,7 @@ class Tag extends TagBase implements ItemInterface, ItemSelectInterface throw new SPException(SPException::SP_ERROR, _('Error al obtener etiqueta')); } - $this->itemData = $queryRes; - - return $this; + return $queryRes; } /** diff --git a/inc/SP/Mgmt/Tags/TagSearch.class.php b/inc/SP/Mgmt/Tags/TagSearch.class.php index 2686079f..69314290 100644 --- a/inc/SP/Mgmt/Tags/TagSearch.class.php +++ b/inc/SP/Mgmt/Tags/TagSearch.class.php @@ -72,7 +72,7 @@ class TagSearch extends TagBase implements ItemSearchInterface return array(); } - $queryRes['count'] = DB::$lastNumRows; + $queryRes['count'] = $Data->getQueryNumRows(); return $queryRes; } diff --git a/inc/SP/Mgmt/Users/User.class.php b/inc/SP/Mgmt/Users/User.class.php index 1bf50032..86c04012 100644 --- a/inc/SP/Mgmt/Users/User.class.php +++ b/inc/SP/Mgmt/Users/User.class.php @@ -136,8 +136,8 @@ class User extends UserBase implements ItemInterface, ItemSelectInterface $this->itemData->setUserId(DB::$lastId); $Log = new Log(_('Eliminar Usuario')); - $Log->addDetails(Html::strongText(_('Login')), $oldUserData->getItemData()->getUserLogin()); - $Log->addDetails(Html::strongText(_('Nombre')), $oldUserData->getItemData()->getUserName()); + $Log->addDetails(Html::strongText(_('Login')), $oldUserData->getUserLogin()); + $Log->addDetails(Html::strongText(_('Nombre')), $oldUserData->getUserName()); $Log->writeLog(); Email::sendEmail($Log); @@ -147,7 +147,7 @@ class User extends UserBase implements ItemInterface, ItemSelectInterface /** * @param $id int - * @return $this + * @return UserData * @throws SPException */ public function getById($id) @@ -187,9 +187,7 @@ class User extends UserBase implements ItemInterface, ItemSelectInterface throw new SPException(SPException::SP_ERROR, _('Error al obtener los datos del usuario')); } - $this->itemData = $queryRes; - - return $this; + return $queryRes; } /** @@ -270,7 +268,7 @@ class User extends UserBase implements ItemInterface, ItemSelectInterface $Data->addParam($this->itemData->getUserEmail()); $Data->addParam($this->itemData->getUserId()); - return (DB::getQuery($Data) === false || DB::$lastNumRows > 0); + return (DB::getQuery($Data) === false || $Data->getQueryNumRows() > 0); } /** @@ -334,7 +332,7 @@ class User extends UserBase implements ItemInterface, ItemSelectInterface $Data->addParam($this->itemData->getUserLogin()); $Data->addParam($this->itemData->getUserEmail()); - return (DB::getQuery($Data) === false || DB::$lastNumRows > 0); + return (DB::getQuery($Data) === false || $Data->getQueryNumRows() > 0); } /** @@ -365,7 +363,7 @@ class User extends UserBase implements ItemInterface, ItemSelectInterface } $Log = new Log(_('Modificar Clave Usuario')); - $Log->addDetails(Html::strongText(_('Login')), $UserData->getItemData()->getUserLogin()); + $Log->addDetails(Html::strongText(_('Login')), $UserData->getUserLogin()); $Log->writeLog(); Email::sendEmail($Log); diff --git a/inc/SP/Mgmt/Users/UserLdap.class.php b/inc/SP/Mgmt/Users/UserLdap.class.php index 53fdacc7..3f5a00c1 100644 --- a/inc/SP/Mgmt/Users/UserLdap.class.php +++ b/inc/SP/Mgmt/Users/UserLdap.class.php @@ -58,7 +58,7 @@ class UserLdap extends UserBase implements ItemInterface $Data->setQuery($query); $Data->addParam($userLogin); - return (DB::getQuery($Data) === true && DB::$lastNumRows === 1); + return (DB::getQuery($Data) === true && $Data->getQueryNumRows() === 1); } /** diff --git a/inc/SP/Mgmt/Users/UserPass.class.php b/inc/SP/Mgmt/Users/UserPass.class.php index 65b607c0..35dde003 100644 --- a/inc/SP/Mgmt/Users/UserPass.class.php +++ b/inc/SP/Mgmt/Users/UserPass.class.php @@ -125,7 +125,7 @@ class UserPass extends UserBase public function updateUserPass($userId, $userPass) { $passdata = self::makeUserPassHash($userPass); - $this->setItemData(User::getItem()->getById($userId)->getItemData()); + $this->setItemData(User::getItem()->getById($userId)); $query = /** @lang SQL */ 'UPDATE usrData SET diff --git a/inc/SP/Mgmt/Users/UserPassRecover.class.php b/inc/SP/Mgmt/Users/UserPassRecover.class.php index 433dbe7a..42e9e01e 100644 --- a/inc/SP/Mgmt/Users/UserPassRecover.class.php +++ b/inc/SP/Mgmt/Users/UserPassRecover.class.php @@ -52,6 +52,29 @@ class UserPassRecover extends UserPassRecoverBase implements ItemInterface const USER_LOGIN_EXIST = 1; const USER_MAIL_EXIST = 2; + /** + * Comprobar el límite de recuperaciones de clave. + * + * @param UserData $UserData con el login del usuario + * @return bool + */ + public static function checkPassRecoverLimit(UserData $UserData) + { + $query = /** @lang SQL */ + 'SELECT userpassr_userId + FROM usrPassRecover + WHERE userpassr_userId = ? + AND userpassr_used = 0 + AND userpassr_date >= ?'; + + $Data = new QueryData(); + $Data->setQuery($query); + $Data->addParam($UserData->getUserId()); + $Data->addParam(time() - self::MAX_PASS_RECOVER_TIME); + + return (DB::getQuery($Data) === false || $Data->getQueryNumRows() >= self::MAX_PASS_RECOVER_LIMIT); + } + /** * Comprobar el hash de recuperación de clave. * @@ -80,7 +103,7 @@ class UserPassRecover extends UserPassRecoverBase implements ItemInterface if ($queryRes === false) { throw new SPException(SPException::SP_ERROR, _('Error en comprobación de hash')); - } elseif (DB::$lastNumRows === 0){ + } elseif ($Data->getQueryNumRows() === 0) { throw new SPException(SPException::SP_INFO, _('Hash inválido o expirado')); } @@ -92,26 +115,23 @@ class UserPassRecover extends UserPassRecoverBase implements ItemInterface } /** - * Comprobar el límite de recuperaciones de clave. - * - * @param UserData $UserData con el login del usuario - * @return bool + * @return $this + * @throws SPException */ - public static function checkPassRecoverLimit(UserData $UserData) + public function update() { $query = /** @lang SQL */ - 'SELECT userpassr_userId - FROM usrPassRecover - WHERE userpassr_userId = ? - AND userpassr_used = 0 - AND userpassr_date >= ?'; + 'UPDATE usrPassRecover SET userpassr_used = 1 WHERE userpassr_hash = ? LIMIT 1'; $Data = new QueryData(); $Data->setQuery($query); - $Data->addParam($UserData->getUserId()); - $Data->addParam(time() - self::MAX_PASS_RECOVER_TIME); + $Data->addParam($this->itemData->getUserpassrHash()); - return (DB::getQuery($Data) === false || DB::$lastNumRows >= self::MAX_PASS_RECOVER_LIMIT); + if (DB::getQuery($Data) === false) { + throw new SPException(SPException::SP_ERROR, _('Error interno')); + } + + return $this; } /** @@ -148,26 +168,6 @@ class UserPassRecover extends UserPassRecoverBase implements ItemInterface // TODO: Implement delete() method. } - /** - * @return $this - * @throws SPException - */ - public function update() - { - $query = /** @lang SQL */ - 'UPDATE usrPassRecover SET userpassr_used = 1 WHERE userpassr_hash = ? LIMIT 1'; - - $Data = new QueryData(); - $Data->setQuery($query); - $Data->addParam($this->itemData->getUserpassrHash()); - - if (DB::getQuery($Data) === false) { - throw new SPException(SPException::SP_ERROR, _('Error interno')); - } - - return $this; - } - /** * @param $id int * @return mixed diff --git a/inc/SP/Mgmt/Users/UserPreferences.class.php b/inc/SP/Mgmt/Users/UserPreferences.class.php index 28b98083..67b6c7ae 100644 --- a/inc/SP/Mgmt/Users/UserPreferences.class.php +++ b/inc/SP/Mgmt/Users/UserPreferences.class.php @@ -84,7 +84,7 @@ class UserPreferences extends UserPreferencesBase implements ItemInterface /** * @param $id int - * @return $this + * @return UserPreferencesData */ public function getById($id) { @@ -99,8 +99,8 @@ class UserPreferences extends UserPreferencesBase implements ItemInterface /** @var UserData $queryRes */ $queryRes = DB::getResults($Data); - if ($queryRes === false || is_null($queryRes->getUserPreferences())) { - return $this; + if ($queryRes === false || null === $queryRes->getUserPreferences()) { + return $this->getItemData(); } $UserPreferencesData = unserialize($queryRes->getUserPreferences()); @@ -109,9 +109,7 @@ class UserPreferences extends UserPreferencesBase implements ItemInterface $UserPreferencesData = Util::castToClass($this->getDataModel(), $UserPreferencesData); } - $this->itemData = $UserPreferencesData; - - return $this; + return $UserPreferencesData; } /** diff --git a/inc/SP/Mgmt/Users/UserSearch.class.php b/inc/SP/Mgmt/Users/UserSearch.class.php index 0881f4fb..0fd32b60 100644 --- a/inc/SP/Mgmt/Users/UserSearch.class.php +++ b/inc/SP/Mgmt/Users/UserSearch.class.php @@ -93,7 +93,7 @@ class UserSearch extends UserBase implements ItemSearchInterface return array(); } - $queryRes['count'] = DB::$lastNumRows; + $queryRes['count'] = $Data->getQueryNumRows(); return $queryRes; } diff --git a/inc/SP/Mgmt/Users/UserUtil.class.php b/inc/SP/Mgmt/Users/UserUtil.class.php index dbf61ec4..c4bb3d64 100644 --- a/inc/SP/Mgmt/Users/UserUtil.class.php +++ b/inc/SP/Mgmt/Users/UserUtil.class.php @@ -59,7 +59,7 @@ class UserUtil $Data->addParam($UserData->getUserLogin()); $Data->addParam($UserData->getUserEmail()); - return (DB::getQuery($Data) === true && DB::$lastNumRows === 1); + return (DB::getQuery($Data) === true && $Data->getQueryNumRows() === 1); } /** diff --git a/inc/SP/Storage/DB.class.php b/inc/SP/Storage/DB.class.php index ebc6ecf6..e28e1f3f 100644 --- a/inc/SP/Storage/DB.class.php +++ b/inc/SP/Storage/DB.class.php @@ -49,11 +49,7 @@ class DB /** * @var int */ - public static $lastNumRows = 0; - /** - * @var int - */ - public static $lastId = null; + public static $lastId; /** * @var bool Resultado como array */ @@ -77,7 +73,7 @@ class DB /** * @var array Resultados de la consulta */ - private $lastResult = null; + private $lastResult; /** * @return int @@ -111,7 +107,8 @@ class DB try { $db = new DB(); $doQuery = $db->doQuery($queryData, self::$returnRawData); - self::$lastNumRows = (self::$fullRowCount === false) ? $db->numRows : $db->getFullRowCount($queryData); + $numRows = (self::$fullRowCount === false) ? $db->numRows : $db->getFullRowCount($queryData); + $queryData->setQueryNumRows($numRows); } catch (SPException $e) { self::logDBException($queryData->getQuery(), $e->getMessage(), $e->getCode(), __FUNCTION__); return false; @@ -194,18 +191,12 @@ class DB */ private function prepareQueryData(QueryData $queryData, $isCount = false) { -// if ($isCount === true) { - // No incluimos en el array de parámetros de posición los valores - // utilizados para LIMIT -// preg_match_all('/(\?|:)/', $queryData->getQuery(), $count); - - // Indice a partir del cual no se incluyen valores -// $paramMaxIndex = (count($count[1]) > 0) ? count($count[1]) : 0; -// } - - $query = $isCount === false ? $queryData->getQuery() : $queryData->getQueryCount(); - - $paramMaxIndex = count($queryData->getParams()) - 3; + if ($isCount === true) { + $query = $queryData->getQueryCount(); + $paramMaxIndex = count($queryData->getParams()) - 3; + } else { + $query = $queryData->getQuery(); + } try { $db = DiFactory::getDBStorage()->getConnection(); @@ -221,7 +212,7 @@ class DB if ($isCount === true && $queryData->getLimit() !== '' - && $paramIndex >= $paramMaxIndex + && $paramIndex > $paramMaxIndex ) { continue; } @@ -285,9 +276,6 @@ class DB $num = (int)$queryRes->fetchColumn(); $queryRes->closeCursor(); - error_log($queryData->getQueryCount()); - error_log($num); - return $num; } catch (SPException $e) { error_log('Exception: ' . $e->getMessage()); @@ -320,7 +308,7 @@ class DB /** * Realizar una consulta y devolver el resultado sin datos * - * @param QueryData $queryData Los datos para realizar la consulta + * @param QueryData $queryData Los datos para realizar la consulta * @param $getRawData bool Si se deben de obtener los datos como PDOStatement * @return bool */ @@ -333,7 +321,7 @@ class DB try { $db = new DB(); $db->doQuery($queryData, $getRawData); - DB::$lastNumRows = $db->numRows; + $queryData->setQueryNumRows($db->numRows); } catch (SPException $e) { self::logDBException($queryData->getQuery(), $e->getMessage(), $e->getCode(), __FUNCTION__); self::$txtError = $e->getMessage(); diff --git a/inc/SP/Storage/QueryData.class.php b/inc/SP/Storage/QueryData.class.php index d5879f64..36b420e9 100644 --- a/inc/SP/Storage/QueryData.class.php +++ b/inc/SP/Storage/QueryData.class.php @@ -78,6 +78,10 @@ class QueryData * @var string */ protected $queryCount = ''; + /** + * @var int + */ + protected $queryNumRows = 0; /** * @param $value @@ -270,9 +274,25 @@ class QueryData public function getQueryCount() { if ($this->queryCount === '') { - return 'SELECT COUNT(*) ' . $this->from . ' ' . $this->where; + return 'SELECT COUNT(*) ' . $this->getFrom() . ' ' . $this->getWhere(); } return $this->queryCount; } + + /** + * @return int + */ + public function getQueryNumRows() + { + return $this->queryNumRows; + } + + /** + * @param int $queryNumRows + */ + public function setQueryNumRows($queryNumRows) + { + $this->queryNumRows = $queryNumRows; + } } \ No newline at end of file diff --git a/inc/sql/1.3.16100601.sql b/inc/sql/1.3.16100601.sql index 23493a71..b5066de0 100644 --- a/inc/sql/1.3.16100601.sql +++ b/inc/sql/1.3.16100601.sql @@ -219,4 +219,4 @@ ADD CONSTRAINT `fk_usrToGroups_groups_id` ON DELETE CASCADE ON UPDATE CASCADE; -CREATE ALGORITHM=UNDEFINED DEFINER = CURRENT_USER SQL SECURITY DEFINER VIEW `account_search_v` AS select distinct `accounts`.`account_id` AS `account_id`,`accounts`.`account_customerId` AS `account_customerId`,`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`,conv(`accounts`.`account_otherUserEdit`,10,2) AS `account_otherUserEdit`,conv(`accounts`.`account_otherGroupEdit`,10,2) AS `account_otherGroupEdit`,`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`.`accfile_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`))) left join `accUsers` on((`accUsers`.`accuser_accountId` = `accounts`.`account_id`))) left join `accGroups` on((`accGroups`.`accgroup_accountId` = `accounts`.`account_id`))) left join `accFavorites` on((`accFavorites`.`accfavorite_accountId` = `accounts`.`account_id`))) left join `accTags` on((`accTags`.`acctag_accountId` = `accounts`.`account_id`))) left join `tags` on((`tags`.`tag_id` = `accTags`.`acctag_tagId`))); +CREATE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER SQL SECURITY DEFINER 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`,conv(`accounts`.`account_otherUserEdit`,10,2) AS `account_otherUserEdit`,conv(`accounts`.`account_otherGroupEdit`,10,2) AS `account_otherGroupEdit`,`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`.`accfile_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`))); diff --git a/inc/themes/material-blue/views/accitem/userspass.inc b/inc/themes/material-blue/views/accitem/userspass.inc index 97d9e378..f67e1d44 100644 --- a/inc/themes/material-blue/views/accitem/userspass.inc +++ b/inc/themes/material-blue/views/accitem/userspass.inc @@ -1,14 +1,42 @@ -