00001 <?php
00002
00015 import('controllers.grid.settings.user.form.UserForm');
00016
00017 class UserDetailsForm extends UserForm {
00018
00020 var $author;
00021
00028 function UserDetailsForm($request, $userId = null, $author = null) {
00029 parent::UserForm('controllers/grid/settings/user/form/userForm.tpl', $userId);
00030
00031 if (isset($author)) {
00032 $this->author =& $author;
00033 } else {
00034 $this->author = null;
00035 }
00036
00037 $site =& $request->getSite();
00038
00039
00040 if ($userId == null) {
00041 $this->addCheck(new FormValidator($this, 'username', 'required', 'user.profile.form.usernameRequired'));
00042 $this->addCheck(new FormValidatorCustom($this, 'username', 'required', 'user.register.form.usernameExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByUsername'), array($this->userId, true), true));
00043 $this->addCheck(new FormValidatorAlphaNum($this, 'username', 'required', 'user.register.form.usernameAlphaNumeric'));
00044
00045 if (!Config::getVar('security', 'implicit_auth')) {
00046 $this->addCheck(new FormValidator($this, 'password', 'required', 'user.profile.form.passwordRequired'));
00047 $this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.register.form.passwordLengthTooShort', '>=', $site->getMinPasswordLength()));
00048 $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.register.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'password2\');'), array(&$this)));
00049 }
00050 } else {
00051 $this->addCheck(new FormValidatorLength($this, 'password', 'optional', 'user.register.form.passwordLengthTooShort', '>=', $site->getMinPasswordLength()));
00052 $this->addCheck(new FormValidatorCustom($this, 'password', 'optional', 'user.register.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'password2\');'), array(&$this)));
00053 }
00054 $this->addCheck(new FormValidator($this, 'firstName', 'required', 'user.profile.form.firstNameRequired'));
00055 $this->addCheck(new FormValidator($this, 'lastName', 'required', 'user.profile.form.lastNameRequired'));
00056 $this->addCheck(new FormValidatorUrl($this, 'userUrl', 'optional', 'user.profile.form.urlInvalid'));
00057 $this->addCheck(new FormValidatorEmail($this, 'email', 'required', 'user.profile.form.emailRequired'));
00058 $this->addCheck(new FormValidatorCustom($this, 'email', 'required', 'user.register.form.emailExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByEmail'), array($this->userId, true), true));
00059 $this->addCheck(new FormValidatorPost($this));
00060 }
00061
00067 function initData($args, &$request) {
00068
00069 $data = array();
00070
00071 if (isset($this->userId)) {
00072 $userDao =& DAORegistry::getDAO('UserDAO');
00073 $user =& $userDao->getById($this->userId);
00074
00075 import('lib.pkp.classes.user.InterestManager');
00076 $interestManager = new InterestManager();
00077
00078 $data = array(
00079 'authId' => $user->getAuthId(),
00080 'username' => $user->getUsername(),
00081 'salutation' => $user->getSalutation(),
00082 'firstName' => $user->getFirstName(),
00083 'middleName' => $user->getMiddleName(),
00084 'lastName' => $user->getLastName(),
00085 'signature' => $user->getSignature(null),
00086 'initials' => $user->getInitials(),
00087 'gender' => $user->getGender(),
00088 'affiliation' => $user->getAffiliation(null),
00089 'email' => $user->getEmail(),
00090 'userUrl' => $user->getUrl(),
00091 'phone' => $user->getPhone(),
00092 'fax' => $user->getFax(),
00093 'mailingAddress' => $user->getMailingAddress(),
00094 'country' => $user->getCountry(),
00095 'biography' => $user->getBiography(null),
00096 'interestsKeywords' => $interestManager->getInterestsForUser($user),
00097 'interestsTextOnly' => $interestManager->getInterestsString($user),
00098 'userLocales' => $user->getLocales()
00099 );
00100 } else if (isset($this->author)) {
00101 $author =& $this->author;
00102 $data = array(
00103 'salutation' => $author->getSalutation(),
00104 'firstName' => $author->getFirstName(),
00105 'middleName' => $author->getMiddleName(),
00106 'lastName' => $author->getLastName(),
00107 'affiliation' => $author->getAffiliation(null),
00108 'email' => $author->getEmail(),
00109 'userUrl' => $author->getUrl(),
00110 'country' => $author->getCountry(),
00111 'biography' => $author->getBiography(null),
00112 );
00113 }
00114 foreach($data as $key => $value) {
00115 $this->setData($key, $value);
00116 }
00117 }
00118
00124 function display($args, &$request) {
00125 $site =& $request->getSite();
00126 $templateMgr =& TemplateManager::getManager();
00127 $userDao =& DAORegistry::getDAO('UserDAO');
00128
00129 $templateMgr->assign('genderOptions', $userDao->getGenderOptions());
00130 $templateMgr->assign('minPasswordLength', $site->getMinPasswordLength());
00131 $templateMgr->assign('source', $request->getUserVar('source'));
00132 $templateMgr->assign('userId', $this->userId);
00133
00134 if (isset($this->userId)) {
00135 $user =& $userDao->getById($this->userId);
00136 $templateMgr->assign('username', $user->getUsername());
00137 $helpTopicId = 'press.users.index';
00138 } else {
00139 $helpTopicId = 'press.users.createNewUser';
00140 }
00141
00142 $templateMgr->assign('implicitAuth', Config::getVar('security', 'implicit_auth'));
00143 $templateMgr->assign('availableLocales', $site->getSupportedLocaleNames());
00144 $templateMgr->assign('helpTopicId', $helpTopicId);
00145
00146 $countryDao =& DAORegistry::getDAO('CountryDAO');
00147 $countries =& $countryDao->getCountries();
00148 $templateMgr->assign_by_ref('countries', $countries);
00149
00150 $authDao =& DAORegistry::getDAO('AuthSourceDAO');
00151 $authSources =& $authDao->getSources();
00152 $authSourceOptions = array();
00153 foreach ($authSources->toArray() as $auth) {
00154 $authSourceOptions[$auth->getAuthId()] = $auth->getTitle();
00155 }
00156 if (!empty($authSourceOptions)) {
00157 $templateMgr->assign('authSourceOptions', $authSourceOptions);
00158 }
00159
00160
00161 $userNameParams = array('firstName' => 'FIRST_NAME_DUMMY', 'lastName' => 'LAST_NAME_DUMMY');
00162 $templateMgr->assign('suggestUsernameParams', $userNameParams);
00163
00164 return $this->fetch($request);
00165 }
00166
00167
00172 function readInputData() {
00173 parent::readInputData();
00174
00175 $this->readUserVars(array(
00176 'authId',
00177 'password',
00178 'password2',
00179 'salutation',
00180 'firstName',
00181 'middleName',
00182 'lastName',
00183 'gender',
00184 'initials',
00185 'signature',
00186 'affiliation',
00187 'email',
00188 'userUrl',
00189 'phone',
00190 'fax',
00191 'mailingAddress',
00192 'country',
00193 'biography',
00194 'keywords',
00195 'interestsTextOnly',
00196 'userLocales',
00197 'generatePassword',
00198 'sendNotify',
00199 'mustChangePassword'
00200 ));
00201 if ($this->userId == null) {
00202 $this->readUserVars(array('username'));
00203 }
00204
00205 if ($this->getData('userLocales') == null || !is_array($this->getData('userLocales'))) {
00206 $this->setData('userLocales', array());
00207 }
00208
00209 if ($this->getData('username') != null) {
00210
00211 $this->setData('username', strtolower($this->getData('username')));
00212 }
00213
00214 $keywords = $this->getData('keywords');
00215 if ($keywords != null && is_array($keywords['interests'])) {
00216
00217 $this->setData('interestsKeywords', array_map('urldecode', $keywords['interests']));
00218 }
00219 }
00220
00224 function getLocaleFieldNames() {
00225 $userDao =& DAORegistry::getDAO('UserDAO');
00226 return $userDao->getLocaleFieldNames();
00227 }
00228
00234 function &execute($args, &$request) {
00235 parent::execute($request);
00236
00237 $userDao =& DAORegistry::getDAO('UserDAO');
00238 $press =& $request->getPress();
00239
00240 if (isset($this->userId)) {
00241 $userId = $this->userId;
00242 $user =& $userDao->getById($userId);
00243 }
00244
00245 if (!isset($user)) {
00246 $user = new User();
00247 $user->setInlineHelp(1);
00248 }
00249
00250 $user->setSalutation($this->getData('salutation'));
00251 $user->setFirstName($this->getData('firstName'));
00252 $user->setMiddleName($this->getData('middleName'));
00253 $user->setLastName($this->getData('lastName'));
00254 $user->setInitials($this->getData('initials'));
00255 $user->setGender($this->getData('gender'));
00256 $user->setAffiliation($this->getData('affiliation'), null);
00257 $user->setSignature($this->getData('signature'), null);
00258 $user->setEmail($this->getData('email'));
00259 $user->setUrl($this->getData('userUrl'));
00260 $user->setPhone($this->getData('phone'));
00261 $user->setFax($this->getData('fax'));
00262 $user->setMailingAddress($this->getData('mailingAddress'));
00263 $user->setCountry($this->getData('country'));
00264 $user->setBiography($this->getData('biography'), null);
00265 $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
00266 $user->setAuthId((int) $this->getData('authId'));
00267
00268 $site =& $request->getSite();
00269 $availableLocales = $site->getSupportedLocales();
00270
00271 $locales = array();
00272 foreach ($this->getData('userLocales') as $locale) {
00273 if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
00274 array_push($locales, $locale);
00275 }
00276 }
00277 $user->setLocales($locales);
00278
00279 if ($user->getAuthId()) {
00280 $authDao =& DAORegistry::getDAO('AuthSourceDAO');
00281 $auth =& $authDao->getPlugin($user->getAuthId());
00282 }
00283
00284 if ($user->getId() != null) {
00285 if ($this->getData('password') !== '') {
00286 if (isset($auth)) {
00287 $auth->doSetUserPassword($user->getUsername(), $this->getData('password'));
00288 $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
00289 } else {
00290 $user->setPassword(Validation::encryptCredentials($user->getUsername(), $this->getData('password')));
00291 }
00292 }
00293
00294 if (isset($auth)) {
00295
00296 $auth->doSetUserInfo($user);
00297 }
00298
00299 $userDao->updateObject($user);
00300
00301 } else {
00302 $user->setUsername($this->getData('username'));
00303 if ($this->getData('generatePassword')) {
00304 $password = Validation::generatePassword();
00305 $sendNotify = true;
00306 } else {
00307 $password = $this->getData('password');
00308 $sendNotify = $this->getData('sendNotify');
00309 }
00310
00311 if (isset($auth)) {
00312 $user->setPassword($password);
00313
00314 $auth->doCreateUser($user);
00315 $user->setAuthId($auth->authId);
00316 $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword()));
00317 } else {
00318 $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
00319 }
00320
00321 $user->setDateRegistered(Core::getCurrentDate());
00322 $userId = $userDao->insertUser($user);
00323
00324 if ($sendNotify) {
00325
00326 import('classes.mail.MailTemplate');
00327 $mail = new MailTemplate('USER_REGISTER');
00328 $mail->setFrom($press->getSetting('contactEmail'), $press->getSetting('contactName'));
00329 $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName()));
00330 $mail->addRecipient($user->getEmail(), $user->getFullName());
00331 $mail->send();
00332 }
00333 }
00334
00335 $interests = $this->getData('interestsKeywords') ? $this->getData('interestsKeywords') : $this->getData('interestsTextOnly');
00336 import('lib.pkp.classes.user.InterestManager');
00337 $interestManager = new InterestManager();
00338 $interestManager->setInterestsForUser($user, $interests);
00339
00340 return $user;
00341 }
00342 }
00343
00344 ?>