PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/classes/trackDirector/form/CreateReviewerForm.inc.php

https://github.com/lib-uoguelph-ca/ocs
PHP | 198 lines | 131 code | 30 blank | 37 comment | 10 complexity | 03c8e473352f06a092edc988111e294d MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @defgroup trackDirector_form
  4. */
  5. /**
  6. * @file CreateReviewerForm.inc.php
  7. *
  8. * Copyright (c) 2000-2012 John Willinsky
  9. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  10. *
  11. * @class CreateReviewerForm
  12. * @ingroup trackDirector_form
  13. *
  14. * @brief Form for track directors to create reviewers.
  15. *
  16. */
  17. // $Id$
  18. import('form.Form');
  19. class CreateReviewerForm extends Form {
  20. /** @var int The paper this form is for */
  21. var $paperId;
  22. /**
  23. * Constructor.
  24. */
  25. function CreateReviewerForm($paperId) {
  26. parent::Form('trackDirector/createReviewerForm.tpl');
  27. $site =& Request::getSite();
  28. $this->paperId = $paperId;
  29. // Validation checks for this form
  30. $this->addCheck(new FormValidator($this, 'username', 'required', 'user.profile.form.usernameRequired'));
  31. $this->addCheck(new FormValidatorCustom($this, 'username', 'required', 'user.account.form.usernameExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByUsername'), array(null, true), true));
  32. $this->addCheck(new FormValidatorAlphaNum($this, 'username', 'required', 'user.account.form.usernameAlphaNumeric'));
  33. $this->addCheck(new FormValidator($this, 'firstName', 'required', 'user.profile.form.firstNameRequired'));
  34. $this->addCheck(new FormValidator($this, 'lastName', 'required', 'user.profile.form.lastNameRequired'));
  35. $this->addCheck(new FormValidatorUrl($this, 'userUrl', 'optional', 'user.profile.form.urlInvalid'));
  36. $this->addCheck(new FormValidatorEmail($this, 'email', 'required', 'user.profile.form.emailRequired'));
  37. $this->addCheck(new FormValidatorCustom($this, 'email', 'required', 'user.account.form.emailExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByEmail'), array(null, true), true));
  38. $this->addCheck(new FormValidatorPost($this));
  39. // Provide a default for sendNotify: If we're using one-click
  40. // reviewer access, it's not necessary;
  41. // otherwise, it should default to on.
  42. $schedConf =& Request::getSchedConf();
  43. $reviewerAccessKeysEnabled = $schedConf->getSetting('reviewerAccessKeysEnabled');
  44. $this->setData('sendNotify', $reviewerAccessKeysEnabled?false:true);
  45. }
  46. function getLocaleFieldNames() {
  47. return array('biography', 'interests', 'gossip');
  48. }
  49. /**
  50. * Display the form.
  51. */
  52. function display() {
  53. $templateMgr =& TemplateManager::getManager();
  54. $site =& Request::getSite();
  55. $templateMgr->assign('paperId', $this->paperId);
  56. $site =& Request::getSite();
  57. $templateMgr->assign('availableLocales', $site->getSupportedLocaleNames());
  58. $userDao =& DAORegistry::getDAO('UserDAO');
  59. $templateMgr->assign('genderOptions', $userDao->getGenderOptions());
  60. $countryDao =& DAORegistry::getDAO('CountryDAO');
  61. $countries =& $countryDao->getCountries();
  62. $templateMgr->assign_by_ref('countries', $countries);
  63. parent::display();
  64. }
  65. /**
  66. * Assign form data to user-submitted data.
  67. */
  68. function readInputData() {
  69. $this->readUserVars(array(
  70. 'salutation',
  71. 'firstName',
  72. 'middleName',
  73. 'lastName',
  74. 'gender',
  75. 'initials',
  76. 'affiliation',
  77. 'email',
  78. 'userUrl',
  79. 'phone',
  80. 'fax',
  81. 'mailingAddress',
  82. 'country',
  83. 'biography',
  84. 'interests',
  85. 'gossip',
  86. 'userLocales',
  87. 'sendNotify',
  88. 'username'
  89. ));
  90. if ($this->getData('userLocales') == null || !is_array($this->getData('userLocales'))) {
  91. $this->setData('userLocales', array());
  92. }
  93. if ($this->getData('username') != null) {
  94. // Usernames must be lowercase
  95. $this->setData('username', strtolower($this->getData('username')));
  96. }
  97. }
  98. /**
  99. * Register a new user.
  100. * @return $userId int
  101. */
  102. function execute() {
  103. $userDao =& DAORegistry::getDAO('UserDAO');
  104. $user = new User();
  105. $user->setSalutation($this->getData('salutation'));
  106. $user->setFirstName($this->getData('firstName'));
  107. $user->setMiddleName($this->getData('middleName'));
  108. $user->setLastName($this->getData('lastName'));
  109. $user->setGender($this->getData('gender'));
  110. $user->setInitials($this->getData('initials'));
  111. $user->setAffiliation($this->getData('affiliation'));
  112. $user->setEmail($this->getData('email'));
  113. $user->setUrl($this->getData('userUrl'));
  114. $user->setPhone($this->getData('phone'));
  115. $user->setFax($this->getData('fax'));
  116. $user->setMailingAddress($this->getData('mailingAddress'));
  117. $user->setCountry($this->getData('country'));
  118. $user->setBiography($this->getData('biography'), null); // Localized
  119. $user->setInterests($this->getData('interests'), null); // Localized
  120. $user->setGossip($this->getData('gossip'), null); // Localized
  121. $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
  122. $authDao =& DAORegistry::getDAO('AuthSourceDAO');
  123. $auth =& $authDao->getDefaultPlugin();
  124. $user->setAuthId($auth?$auth->getAuthId():0);
  125. $site =& Request::getSite();
  126. $availableLocales = $site->getSupportedLocales();
  127. $locales = array();
  128. foreach ($this->getData('userLocales') as $locale) {
  129. if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
  130. array_push($locales, $locale);
  131. }
  132. }
  133. $user->setLocales($locales);
  134. $user->setUsername($this->getData('username'));
  135. $password = Validation::generatePassword();
  136. $sendNotify = $this->getData('sendNotify');
  137. if (isset($auth)) {
  138. $user->setPassword($password);
  139. // FIXME Check result and handle failures
  140. $auth->doCreateUser($user);
  141. $user->setAuthId($auth->authId);
  142. $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only
  143. } else {
  144. $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
  145. }
  146. $user->setDateRegistered(Core::getCurrentDate());
  147. $userId = $userDao->insertUser($user);
  148. $roleDao =& DAORegistry::getDAO('RoleDAO');
  149. $schedConf =& Request::getSchedConf();
  150. $role = new Role();
  151. $role->setConferenceId($schedConf->getConferenceId());
  152. $role->setSchedConfId($schedConf->getId());
  153. $role->setUserId($userId);
  154. $role->setRoleId(ROLE_ID_REVIEWER);
  155. $roleDao->insertRole($role);
  156. if ($sendNotify) {
  157. // Send welcome email to user
  158. import('mail.MailTemplate');
  159. $mail = new MailTemplate('USER_REGISTER');
  160. $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName'));
  161. $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password));
  162. $mail->addRecipient($user->getEmail(), $user->getFullName());
  163. $mail->send();
  164. }
  165. return $userId;
  166. }
  167. }
  168. ?>