classes/trackDirector/form/CreateReviewerForm.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00020 // $Id$
00021 
00022 
00023 import('form.Form');
00024 
00025 class CreateReviewerForm extends Form {
00027    var $paperId;
00028 
00032    function CreateReviewerForm($paperId) {
00033       parent::Form('trackDirector/createReviewerForm.tpl');
00034 
00035       $site =& Request::getSite();
00036       $this->paperId = $paperId;
00037 
00038       // Validation checks for this form
00039       $this->addCheck(new FormValidator($this, 'username', 'required', 'user.profile.form.usernameRequired'));
00040       $this->addCheck(new FormValidatorCustom($this, 'username', 'required', 'user.account.form.usernameExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByUsername'), array(null, true), true));
00041       $this->addCheck(new FormValidatorAlphaNum($this, 'username', 'required', 'user.account.form.usernameAlphaNumeric'));
00042       $this->addCheck(new FormValidator($this, 'firstName', 'required', 'user.profile.form.firstNameRequired'));
00043       $this->addCheck(new FormValidator($this, 'lastName', 'required', 'user.profile.form.lastNameRequired'));
00044       $this->addCheck(new FormValidatorUrl($this, 'userUrl', 'optional', 'user.profile.form.urlInvalid'));
00045       $this->addCheck(new FormValidatorEmail($this, 'email', 'required', 'user.profile.form.emailRequired'));
00046       $this->addCheck(new FormValidatorCustom($this, 'email', 'required', 'user.account.form.emailExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByEmail'), array(null, true), true));
00047       $this->addCheck(new FormValidatorPost($this));
00048 
00049       // Provide a default for sendNotify: If we're using one-click
00050       // reviewer access, it's not necessary;
00051       // otherwise, it should default to on.
00052       $schedConf =& Request::getSchedConf();
00053       $reviewerAccessKeysEnabled = $schedConf->getSetting('reviewerAccessKeysEnabled');
00054       $this->setData('sendNotify', $reviewerAccessKeysEnabled?false:true);
00055    }
00056 
00057    function getLocaleFieldNames() {
00058       return array('biography', 'interests', 'gossip');
00059    }
00060 
00064    function display() {
00065       $templateMgr =& TemplateManager::getManager();
00066       $site =& Request::getSite();
00067       $templateMgr->assign('paperId', $this->paperId);
00068 
00069       $site =& Request::getSite();
00070       $templateMgr->assign('availableLocales', $site->getSupportedLocaleNames());
00071       $userDao =& DAORegistry::getDAO('UserDAO');
00072       $templateMgr->assign('genderOptions', $userDao->getGenderOptions());
00073 
00074       $countryDao =& DAORegistry::getDAO('CountryDAO');
00075       $countries =& $countryDao->getCountries();
00076       $templateMgr->assign_by_ref('countries', $countries);
00077 
00078       parent::display();
00079    }
00080 
00084    function readInputData() {
00085       $this->readUserVars(array(
00086          'salutation',
00087          'firstName',
00088          'middleName',
00089          'lastName',
00090          'gender',
00091          'initials',
00092          'affiliation',
00093          'email',
00094          'userUrl',
00095          'phone',
00096          'fax',
00097          'mailingAddress',
00098          'country',
00099          'biography',
00100          'interests',
00101          'gossip',
00102          'userLocales',
00103          'sendNotify',
00104          'username'
00105       ));
00106 
00107       if ($this->getData('userLocales') == null || !is_array($this->getData('userLocales'))) {
00108          $this->setData('userLocales', array());
00109       }
00110 
00111       if ($this->getData('username') != null) {
00112          // Usernames must be lowercase
00113          $this->setData('username', strtolower($this->getData('username')));
00114       }
00115    }
00116 
00121    function execute() {
00122       $userDao =& DAORegistry::getDAO('UserDAO');
00123       $user = new User();
00124 
00125       $user->setSalutation($this->getData('salutation'));
00126       $user->setFirstName($this->getData('firstName'));
00127       $user->setMiddleName($this->getData('middleName'));
00128       $user->setLastName($this->getData('lastName'));
00129       $user->setGender($this->getData('gender'));
00130       $user->setInitials($this->getData('initials'));
00131       $user->setAffiliation($this->getData('affiliation'));
00132       $user->setEmail($this->getData('email'));
00133       $user->setUrl($this->getData('userUrl'));
00134       $user->setPhone($this->getData('phone'));
00135       $user->setFax($this->getData('fax'));
00136       $user->setMailingAddress($this->getData('mailingAddress'));
00137       $user->setCountry($this->getData('country'));
00138       $user->setBiography($this->getData('biography'), null); // Localized
00139       $user->setInterests($this->getData('interests'), null); // Localized
00140       $user->setGossip($this->getData('gossip'), null); // Localized
00141       $user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
00142 
00143       $authDao =& DAORegistry::getDAO('AuthSourceDAO');
00144       $auth =& $authDao->getDefaultPlugin();
00145       $user->setAuthId($auth?$auth->getAuthId():0);
00146 
00147       $site =& Request::getSite();
00148       $availableLocales = $site->getSupportedLocales();
00149 
00150       $locales = array();
00151       foreach ($this->getData('userLocales') as $locale) {
00152          if (AppLocale::isLocaleValid($locale) && in_array($locale, $availableLocales)) {
00153             array_push($locales, $locale);
00154          }
00155       }
00156       $user->setLocales($locales);
00157 
00158       $user->setUsername($this->getData('username'));
00159       $password = Validation::generatePassword();
00160       $sendNotify = $this->getData('sendNotify');
00161 
00162       if (isset($auth)) {
00163          $user->setPassword($password);
00164          // FIXME Check result and handle failures
00165          $auth->doCreateUser($user);
00166          $user->setAuthId($auth->authId);
00167          $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only
00168       } else {
00169          $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
00170       }
00171 
00172       $user->setDateRegistered(Core::getCurrentDate());
00173       $userId = $userDao->insertUser($user);
00174 
00175       $roleDao =& DAORegistry::getDAO('RoleDAO');
00176       $schedConf =& Request::getSchedConf();
00177       $role = new Role();
00178       $role->setConferenceId($schedConf->getConferenceId());
00179       $role->setSchedConfId($schedConf->getId());
00180       $role->setUserId($userId);
00181       $role->setRoleId(ROLE_ID_REVIEWER);
00182       $roleDao->insertRole($role);
00183 
00184       if ($sendNotify) {
00185          // Send welcome email to user
00186          import('mail.MailTemplate');
00187          $mail = new MailTemplate('USER_REGISTER');
00188          $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName'));
00189          $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password));
00190          $mail->addRecipient($user->getEmail(), $user->getFullName());
00191          $mail->send();
00192       }
00193 
00194       return $userId;
00195    }
00196 }
00197 
00198 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7