/** * Actualiza los datos de una cuenta en la BBDD. * * @return bool */ public function updateAccount() { $Log = new Log(__FUNCTION__); // Guardamos una copia de la cuenta en el histórico if (!AccountHistory::addHistory($this->getAccountId(), false)) { $Log->addDescription(_('Error al actualizar el historial')); $Log->writeLog(); return false; } $Log->setAction(_('Actualizar Cuenta')); if (!Groups::updateGroupsForAccount($this->getAccountId(), $this->getAccountUserGroupsId())) { $Log->addDescription(_('Error al actualizar los grupos secundarios')); $Log->writeLog(); $Log->resetDescription(); } if (!UserAccounts::updateUsersForAccount($this->getAccountId(), $this->getAccountUsersId())) { $Log->addDescription(_('Error al actualizar los usuarios de la cuenta')); $Log->writeLog(); $Log->resetDescription(); } if ($this->getAccountUserGroupId()) { $query = 'UPDATE accounts SET ' . 'account_customerId = :accountCustomerId,' . 'account_categoryId = :accountCategoryId,' . 'account_name = :accountName,' . 'account_login = :accountLogin,' . 'account_url = :accountUrl,' . 'account_notes = :accountNotes,' . 'account_userEditId = :accountUserEditId,' . 'account_userGroupId = :accountUserGroupId,' . 'account_dateEdit = NOW(),' . 'account_otherUserEdit = :accountOtherUserEdit,' . 'account_otherGroupEdit = :accountOtherGroupEdit ' . 'WHERE account_id = :accountId'; $data['accountUserGroupId'] = $this->getAccountUserGroupId(); } else { $query = 'UPDATE accounts SET ' . 'account_customerId = :accountCustomerId,' . 'account_categoryId = :accountCategoryId,' . 'account_name = :accountName,' . 'account_login = :accountLogin,' . 'account_url = :accountUrl,' . 'account_notes = :accountNotes,' . 'account_userEditId = :accountUserEditId,' . 'account_dateEdit = NOW(),' . 'account_otherUserEdit = :accountOtherUserEdit,' . 'account_otherGroupEdit = :accountOtherGroupEdit ' . 'WHERE account_id = :accountId'; } $data['accountCustomerId'] = $this->getAccountCustomerId(); $data['accountCategoryId'] = $this->getAccountCategoryId(); $data['accountName'] = $this->getAccountName(); $data['accountLogin'] = $this->getAccountLogin(); $data['accountUrl'] = $this->getAccountUrl(); $data['accountNotes'] = $this->getAccountNotes(); $data['accountUserEditId'] = $this->getAccountUserEditId(); $data['accountOtherUserEdit'] = intval($this->getAccountOtherUserEdit()); $data['accountOtherGroupEdit'] = intval($this->getAccountOtherGroupEdit()); $data['accountId'] = $this->getAccountId(); if (DB::getQuery($query, __FUNCTION__, $data) === false) { return false; } $accountInfo = array('customer_name'); $this->getAccountInfoById($accountInfo); $Log->addDescription(Html::strongText(_('Cliente') . ': ') . $this->_cacheParams['customer_name']); $Log->addDescription(Html::strongText(_('Cuenta') . ': ') . $this->getAccountName() . " (" . $this->getAccountId() . ")"); $Log->writeLog(); Email::sendEmail($Log); return true; }