/** * update login name * @param string new login * @return boolean true on success; otherwise false * @access public * @throws ilUserException */ function updateLogin($a_login) { global $ilDB, $ilSetting; if (func_num_args() != 1) { return false; } if (!isset($a_login)) { return false; } $former_login = self::_lookupLogin($this->getId()); // Update not necessary if (0 == strcmp($a_login, $former_login)) { return false; } try { $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId()); } catch (ilUserException $e) { $last_history_entry = null; } // throw exception if the desired loginame is already in history and it is not allowed to reuse it if ((int) $ilSetting->get('allow_change_loginname') && (int) $ilSetting->get('reuse_of_loginnames') == 0 && self::_doesLoginnameExistInHistory($a_login)) { throw new ilUserException($this->lng->txt('loginname_already_exists')); } else { if ((int) $ilSetting->get('allow_change_loginname') && (int) $ilSetting->get('loginname_change_blocking_time') && is_array($last_history_entry) && $last_history_entry[1] + (int) $ilSetting->get('loginname_change_blocking_time') > time()) { include_once 'Services/Calendar/classes/class.ilDate.php'; throw new ilUserException(sprintf($this->lng->txt('changing_loginname_not_possible_info'), ilDatePresentation::formatDate(new ilDateTime($last_history_entry[1], IL_CAL_UNIX)), ilDatePresentation::formatDate(new ilDateTime($last_history_entry[1] + (int) $ilSetting->get('loginname_change_blocking_time'), IL_CAL_UNIX)))); } else { // log old loginname in history if ((int) $ilSetting->get('allow_change_loginname') && (int) $ilSetting->get('create_history_loginname')) { ilObjUser::_writeHistory($this->getId(), $former_login); } //update login $this->login = $a_login; $ilDB->manipulateF(' UPDATE usr_data SET login = %s WHERE usr_id = %s', array('text', 'integer'), array($this->getLogin(), $this->getId())); include_once 'Services/Contact/classes/class.ilAddressbook.php'; ilAddressbook::onLoginNameChange($former_login, $this->getLogin()); } } return true; }