protected function _preSaveEntry(array &$entry, array $data, $action)
{
$this->_iaCore->startHook('adminAddMemberValidation');
$iaAcl = $this->_iaCore->factory('acl');
$iaField = $this->_iaCore->factory('field');
$fields = iaField::getAcoFieldsList(iaCore::ADMIN, $this->_itemName);
// below is the hacky way to force the script to upload files to the appropriate user's folder
// FIXME
$activeUser = iaUsers::getIdentity(true);
$_SESSION[iaUsers::SESSION_KEY] = array('id' => $this->getEntryId(), 'username' => $data['username']);
list($entry, $error, $this->_messages, ) = $iaField->parsePost($fields, $entry);
$_SESSION[iaUsers::SESSION_KEY] = $activeUser;
//
if ($iaAcl->isAccessible($this->getName(), 'usergroup')) {
if (isset($data['usergroup_id'])) {
$entry['usergroup_id'] = array_key_exists($data['usergroup_id'], $this->_userGroups) ? $data['usergroup_id'] : iaUsers::MEMBERSHIP_REGULAR;
}
} elseif (iaCore::ACTION_ADD == $action) {
$entry['usergroup_id'] = iaUsers::MEMBERSHIP_REGULAR;
}
if ($error) {
return false;
}
$stmt = '`email` = :email';
if (iaCore::ACTION_EDIT == $action) {
if (isset($entry['status']) && $entry['status'] == $this->_iaDb->one('status', iaDb::convertIds((int) $this->getEntryId()))) {
unset($entry['status']);
}
$stmt .= ' AND `id` != ' . (int) $this->getEntryId();
}
if ($this->_iaDb->exists($stmt, $entry)) {
$this->addMessage('error_duplicate_email');
}
if ($this->_iaDb->exists('`username` = :username AND `id` != :id', array('username' => $entry['username'], 'id' => $this->getEntryId()))) {
$this->addMessage('username_already_taken');
}
if ($iaAcl->checkAccess($this->getName(), 'password') || iaCore::ACTION_ADD == $action) {
$this->_password = trim($data['_password']);
if ($this->_password || !empty($data['_password2'])) {
$entry['password'] = $this->getHelper()->encodePassword($this->_password);
iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
if (empty($entry['password'])) {
$this->addMessage('error_password_empty');
} elseif (!utf8_is_ascii($entry['password'])) {
$this->addMessage(iaLanguage::get('password') . ': ' . iaLanguage::get('ascii_required'));
} elseif ($entry['password'] != $this->getHelper()->encodePassword($data['_password2'])) {
$this->addMessage('error_password_match');
}
}
}
if (empty($data['_password']) && iaCore::ACTION_ADD == $action) {
$this->addMessage('error_password_empty');
}
return !$this->getMessages();
}