00001 <?php
00002
00020
00021
00022
00023 import('form.Form');
00024
00025 class CreateReviewerForm extends Form {
00027 var $articleId;
00028
00032 function CreateReviewerForm($articleId) {
00033 parent::Form('sectionEditor/createReviewerForm.tpl');
00034 $this->addCheck(new FormValidatorPost($this));
00035
00036 $site = &Request::getSite();
00037 $this->articleId = $articleId;
00038
00039
00040 $this->addCheck(new FormValidator($this, 'username', 'required', 'user.profile.form.usernameRequired'));
00041 $this->addCheck(new FormValidatorCustom($this, 'username', 'required', 'user.register.form.usernameExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByUsername'), array(null, true), true));
00042 $this->addCheck(new FormValidatorAlphaNum($this, 'username', 'required', 'user.register.form.usernameAlphaNumeric'));
00043 $this->addCheck(new FormValidator($this, 'firstName', 'required', 'user.profile.form.firstNameRequired'));
00044 $this->addCheck(new FormValidator($this, 'lastName', 'required', 'user.profile.form.lastNameRequired'));
00045 $this->addCheck(new FormValidatorUrl($this, 'userUrl', 'optional', 'user.profile.form.urlInvalid'));
00046 $this->addCheck(new FormValidatorEmail($this, 'email', 'required', 'user.profile.form.emailRequired'));
00047 $this->addCheck(new FormValidatorCustom($this, 'email', 'required', 'user.register.form.emailExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByEmail'), array(null, true), true));
00048
00049
00050
00051
00052 $journal =& Request::getJournal();
00053 $reviewerAccessKeysEnabled = $journal->getSetting('reviewerAccessKeysEnabled');
00054 $isEmailBasedReview = $journal->getSetting('mailSubmissionsToReviewers')==1?true:false;
00055 $this->setData('sendNotify', ($reviewerAccessKeysEnabled || $isEmailBasedReview)?false:true);
00056 }
00057
00058 function getLocaleFieldNames() {
00059 return array('biography', 'interests');
00060 }
00061
00065 function display() {
00066 $templateMgr = &TemplateManager::getManager();
00067 $site = &Request::getSite();
00068 $templateMgr->assign('articleId', $this->articleId);
00069
00070 $site = &Request::getSite();
00071 $templateMgr->assign('availableLocales', $site->getSupportedLocaleNames());
00072
00073 $countryDao =& DAORegistry::getDAO('CountryDAO');
00074 $countries =& $countryDao->getCountries();
00075 $templateMgr->assign_by_ref('countries', $countries);
00076
00077 parent::display();
00078 }
00079
00083 function readInputData() {
00084 $this->readUserVars(array(
00085 'salutation',
00086 'firstName',
00087 'middleName',
00088 'lastName',
00089 'gender',
00090 'initials',
00091 'affiliation',
00092 'email',
00093 'userUrl',
00094 'phone',
00095 'fax',
00096 'mailingAddress',
00097 'country',
00098 'biography',
00099 'interests',
00100 'userLocales',
00101 'sendNotify',
00102 'username'
00103 ));
00104
00105 if ($this->getData('userLocales') == null || !is_array($this->getData('userLocales'))) {
00106 $this->setData('userLocales', array());
00107 }
00108
00109 if ($this->getData('username') != null) {
00110
00111 $this->setData('username', strtolower($this->getData('username')));
00112 }
00113 }
00114
00119 function execute() {
00120 $userDao = &DAORegistry::getDAO('UserDAO');
00121 $user = &new User();
00122
00123 $user->setSalutation($this->getData('salutation'));
00124 $user->setFirstName($this->getData('firstName'));
00125 $user->setMiddleName($this->getData('middleName'));
00126 $user->setLastName($this->getData('lastName'));
00127 $user->setGender($this->getData('gender'));
00128 $user->setInitials($this->getData('initials'));
00129 $user->setAffiliation($this->getData('affiliation'));
00130 $user->setEmail($this->getData('email'));
00131 $user->setUrl($this->getData('userUrl'));
00132 $user->setPhone($this->getData('phone'));
00133 $user->setFax($this->getData('fax'));
00134 $user->setMailingAddress($this->getData('mailingAddress'));
00135 $user->setCountry($this->getData('country'));
00136 $user->setBiography($this->getData('biography'), null);
00137 $user->setInterests($this->getData('interests'), null);
00138 $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
00139
00140 $authDao = &DAORegistry::getDAO('AuthSourceDAO');
00141 $auth =& $authDao->getDefaultPlugin();
00142 $user->setAuthId($auth?$auth->getAuthId():0);
00143
00144 $site = &Request::getSite();
00145 $availableLocales = $site->getSupportedLocales();
00146
00147 $locales = array();
00148 foreach ($this->getData('userLocales') as $locale) {
00149 if (Locale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
00150 array_push($locales, $locale);
00151 }
00152 }
00153 $user->setLocales($locales);
00154
00155 $user->setUsername($this->getData('username'));
00156 $password = Validation::generatePassword();
00157 $sendNotify = $this->getData('sendNotify');
00158
00159 if (isset($auth)) {
00160 $user->setPassword($password);
00161
00162 $auth->doCreateUser($user);
00163 $user->setAuthId($auth->authId);
00164 $user->setPassword(Validation::encryptCredentials($user->getUserId(), Validation::generatePassword()));
00165 } else {
00166 $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
00167 }
00168
00169 $user->setDateRegistered(Core::getCurrentDate());
00170 $userId = $userDao->insertUser($user);
00171
00172 $roleDao = &DAORegistry::getDAO('RoleDAO');
00173 $journal = &Request::getJournal();
00174 $role = &new Role();
00175 $role->setJournalId($journal->getJournalId());
00176 $role->setUserId($userId);
00177 $role->setRoleId(ROLE_ID_REVIEWER);
00178 $roleDao->insertRole($role);
00179
00180 if ($sendNotify) {
00181
00182 import('mail.MailTemplate');
00183 $mail = &new MailTemplate('REVIEWER_REGISTER');
00184 $mail->setFrom($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
00185 $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName()));
00186 $mail->addRecipient($user->getEmail(), $user->getFullName());
00187 $mail->send();
00188 }
00189
00190 return $userId;
00191 }
00192 }
00193
00194 ?>