00001 <?php
00002
00015
00016
00017 import('form.Form');
00018
00019 define('REGISTRATION_SUCCESSFUL', 1);
00020 define('REGISTRATION_FAILED', 2);
00021 define('REGISTRATION_NO_PAYMENT', 3);
00022 define('REGISTRATION_FREE', 4);
00023
00024 class UserRegistrationForm extends Form {
00026 var $captchaEnabled;
00027
00029 var $typeId;
00030
00035 function UserRegistrationForm($typeId) {
00036 $schedConf =& Request::getSchedConf();
00037
00038 $this->typeId = (int) $typeId;
00039
00040 parent::Form('registration/userRegistrationForm.tpl');
00041
00042 $this->addCheck(new FormValidatorCustom($this, 'registrationTypeId', 'required', 'manager.registration.form.typeIdValid', create_function('$registrationTypeId, $schedConfId, $typeId', '$registrationTypeDao =& DAORegistry::getDAO(\'RegistrationTypeDAO\'); return $registrationTypeDao->openRegistrationTypeExistsByTypeId($typeId, $schedConfId);'), array($schedConf->getId(), $typeId)));
00043
00044 import('captcha.CaptchaManager');
00045 $captchaManager = new CaptchaManager();
00046 $this->captchaEnabled = ($captchaManager->isEnabled() && Config::getVar('captcha', 'captcha_on_register'))?true:false;
00047
00048 $user =& Request::getUser();
00049 if (!$user) {
00050 $site =& Request::getSite();
00051 $this->addCheck(new FormValidator($this, 'username', 'required', 'user.profile.form.usernameRequired'));
00052 $this->addCheck(new FormValidator($this, 'password', 'required', 'user.profile.form.passwordRequired'));
00053
00054 $this->addCheck(new FormValidatorCustom($this, 'username', 'required', 'user.account.form.usernameExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByUsername'), array(), true));
00055 $this->addCheck(new FormValidatorAlphaNum($this, 'username', 'required', 'user.account.form.usernameAlphaNumeric'));
00056 $this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.account.form.passwordLengthTooShort', '>=', $site->getMinPasswordLength()));
00057 $this->addCheck(new FormValidatorCustom($this, 'password', 'required', 'user.account.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'password2\');'), array(&$this)));
00058 $this->addCheck(new FormValidator($this, 'firstName', 'required', 'user.profile.form.firstNameRequired'));
00059 $this->addCheck(new FormValidator($this, 'lastName', 'required', 'user.profile.form.lastNameRequired'));
00060 $this->addCheck(new FormValidator($this, 'country', 'required', 'user.profile.form.countryRequired'));
00061 $this->addCheck(new FormValidator($this, 'mailingAddress', 'required', 'user.profile.form.mailingAddressRequired'));
00062 $this->addCheck(new FormValidatorEmail($this, 'email', 'required', 'user.profile.form.emailRequired'));
00063 $this->addCheck(new FormValidator($this, 'affiliation', 'required', 'user.profile.form.affiliationRequired'));
00064 $this->addCheck(new FormValidatorCustom($this, 'email', 'required', 'user.account.form.emailExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByEmail'), array(), true));
00065 if ($this->captchaEnabled) {
00066 $this->addCheck(new FormValidatorCaptcha($this, 'captcha', 'captchaId', 'common.captchaField.badCaptcha'));
00067 }
00068
00069 $authDao =& DAORegistry::getDAO('AuthSourceDAO');
00070 $this->defaultAuth =& $authDao->getDefaultPlugin();
00071 if (isset($this->defaultAuth)) {
00072 $this->addCheck(new FormValidatorCustom($this, 'username', 'required', 'user.account.form.usernameExists', create_function('$username,$form,$auth', 'return (!$auth->userExists($username) || $auth->authenticate($username, $form->getData(\'password\')));'), array(&$this, $this->defaultAuth)));
00073 }
00074 }
00075
00076 $this->addCheck(new FormValidatorPost($this));
00077 }
00078
00079 function validate() {
00080 $schedConf =& Request::getSchedConf();
00081 $registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
00082 $registrationType =& $registrationTypeDao->getRegistrationType($this->getData('registrationTypeId'));
00083 if ($registrationType && $registrationType->getCode() != '') {
00084 $this->addCheck(new FormValidatorCustom($this, 'feeCode', 'required', 'manager.registration.form.feeCodeValid', create_function('$feeCode, $schedConfId, $form', '$registrationTypeDao =& DAORegistry::getDAO(\'RegistrationTypeDAO\'); return $registrationTypeDao->checkCode($form->getData(\'registrationTypeId\'), $schedConfId, $feeCode);'), array($schedConf->getId(), $this)));
00085 }
00086 return parent::validate();
00087 }
00088
00092 function display() {
00093 $templateMgr =& TemplateManager::getManager();
00094 $user =& Request::getUser();
00095 $schedConf =& Request::getSchedConf();
00096 $site =& Request::getSite();
00097
00098 $registrationOptionDao =& DAORegistry::getDAO('RegistrationOptionDAO');
00099 $registrationOptions =& $registrationOptionDao->getRegistrationOptionsBySchedConfId($schedConf->getId());
00100 $templateMgr->assign_by_ref('registrationOptions', $registrationOptions);
00101 $templateMgr->assign('registrationTypeId', $this->typeId);
00102
00103 $templateMgr->assign('userLoggedIn', $user?true:false);
00104 $templateMgr->assign('requestUri', $_SERVER['REQUEST_URI']);
00105 if ($user) {
00106 $templateMgr->assign('userFullName', $user->getFullName());
00107
00108 }
00109
00110 if ($this->captchaEnabled) {
00111 import('captcha.CaptchaManager');
00112 $captchaManager = new CaptchaManager();
00113 $captcha =& $captchaManager->createCaptcha();
00114 if ($captcha) {
00115 $templateMgr->assign('captchaEnabled', $this->captchaEnabled);
00116 $this->setData('captchaId', $captcha->getId());
00117 }
00118 }
00119
00120 $countryDao =& DAORegistry::getDAO('CountryDAO');
00121 $countries =& $countryDao->getCountries();
00122 $templateMgr->assign_by_ref('countries', $countries);
00123
00124 $registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
00125 $registrationOptionCosts = $registrationTypeDao->getRegistrationOptionCosts($this->typeId);
00126 $templateMgr->assign('registrationOptionCosts', $registrationOptionCosts);
00127
00128 $registrationType =& $registrationTypeDao->getRegistrationType($this->typeId);
00129 $templateMgr->assign_by_ref('registrationType', $registrationType);
00130
00131 $templateMgr->assign('minPasswordLength', $site->getMinPasswordLength());
00132
00133 $templateMgr->assign_by_ref('user', $user);
00134 parent::display();
00135 }
00136
00137 function getLocaleFieldNames() {
00138 $userDao =& DAORegistry::getDAO('UserDAO');
00139 return $userDao->getLocaleFieldNames();
00140 }
00141
00145 function readInputData() {
00146 $userVars = array('registrationTypeId', 'specialRequests', 'feeCode', 'registrationOptionId');
00147
00148 $user =& Request::getUser();
00149 if (!$user) {
00150 $userVars[] = 'username';
00151 $userVars[] = 'salutation';
00152 $userVars[] = 'password';
00153 $userVars[] = 'password2';
00154 $userVars[] = 'firstName';
00155 $userVars[] = 'middleName';
00156 $userVars[] = 'captcha';
00157 $userVars[] = 'lastName';
00158 $userVars[] = 'initials';
00159 $userVars[] = 'affiliation';
00160 $userVars[] = 'signature';
00161 $userVars[] = 'email';
00162 $userVars[] = 'userUrl';
00163 $userVars[] = 'phone';
00164 $userVars[] = 'fax';
00165 $userVars[] = 'mailingAddress';
00166 $userVars[] = 'country';
00167 $userVars[] = 'biography';
00168 $userVars[] = 'userLocales';
00169 }
00170
00171 if ($this->captchaEnabled) {
00172 $userVars[] = 'captchaId';
00173 $userVars[] = 'captcha';
00174 }
00175
00176 $this->readUserVars($userVars);
00177
00178
00179 $registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
00180 $needMembership = $registrationTypeDao->getRegistrationTypeMembership($this->getData('typeId'));
00181 }
00182
00186 function execute() {
00187 $schedConf =& Request::getSchedConf();
00188 $user =& Request::getUser();
00189
00190 if (!$user) {
00191
00192 $user = new User();
00193
00194 $user->setUsername($this->getData('username'));
00195 $user->setSalutation($this->getData('salutation'));
00196 $user->setFirstName($this->getData('firstName'));
00197 $user->setMiddleName($this->getData('middleName'));
00198 $user->setInitials($this->getData('initials'));
00199 $user->setLastName($this->getData('lastName'));
00200 $user->setAffiliation($this->getData('affiliation'));
00201 $user->setSignature($this->getData('signature'), null);
00202 $user->setEmail($this->getData('email'));
00203 $user->setUrl($this->getData('userUrl'));
00204 $user->setPhone($this->getData('phone'));
00205 $user->setFax($this->getData('fax'));
00206 $user->setMailingAddress($this->getData('mailingAddress'));
00207 $user->setBiography($this->getData('biography'), null);
00208 $user->setInterests($this->getData('interests'), null);
00209 $user->setDateRegistered(Core::getCurrentDate());
00210 $user->setCountry($this->getData('country'));
00211
00212 $user->setPassword(Validation::encryptCredentials($this->getData('username'), $this->getData('password')));
00213
00214 $userDao =& DAORegistry::getDAO('UserDAO');
00215 $userId = $userDao->insertUser($user);
00216 if (!$userId) {
00217 return REGISTRATION_FAILED;
00218 }
00219
00220 $conference =& Request::getConference();
00221 $roleDao =& DAORegistry::getDAO('RoleDAO');
00222 $role = new Role();
00223 $role->setRoleId(ROLE_ID_READER);
00224 $role->setSchedConfId($schedConf->getId());
00225 $role->setConferenceId($conference->getId());
00226 $role->setUserId($user->getId());
00227 $roleDao->insertRole($role);
00228
00229 $sessionManager =& SessionManager::getManager();
00230 $session =& $sessionManager->getUserSession();
00231 $session->setSessionVar('username', $user->getUsername());
00232
00233
00234 Validation::login($this->getData('username'), $this->getData('password'), $reason);
00235
00236 import('user.form.CreateAccountForm');
00237 CreateAccountForm::sendConfirmationEmail($user, $this->getData('password'), true);
00238 }
00239
00240
00241 $registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
00242 $registrationType =& $registrationTypeDao->getRegistrationType($this->getData('registrationTypeId'));
00243 if (!$registrationType || $registrationType->getSchedConfId() != $schedConf->getId()) {
00244 Request::redirect('index');
00245 }
00246
00247 import('payment.ocs.OCSPaymentManager');
00248 $paymentManager =& OCSPaymentManager::getManager();
00249
00250 if (!$paymentManager->isConfigured()) return REGISTRATION_NO_PAYMENT;
00251
00252 import('registration.Registration');
00253 $registration = new Registration();
00254
00255 $registration->setSchedConfId($schedConf->getId());
00256 $registration->setUserId($user->getId());
00257 $registration->setTypeId($this->getData('registrationTypeId'));
00258 $registration->setSpecialRequests($this->getData('specialRequests') ? $this->getData('specialRequests') : null);
00259 $registration->setDateRegistered(time());
00260
00261 $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
00262 $registrationId = $registrationDao->insertRegistration($registration);
00263
00264 $registrationOptionDao =& DAORegistry::getDAO('RegistrationOptionDAO');
00265 $registrationOptions =& $registrationOptionDao->getRegistrationOptionsBySchedConfId($schedConf->getId());
00266 $registrationOptionIds = (array) $this->getData('registrationOptionId');
00267
00268 $cost = $registrationType->getCost();
00269 $registrationOptionCosts = $registrationTypeDao->getRegistrationOptionCosts($this->getData('registrationTypeId'));
00270
00271 while ($registrationOption =& $registrationOptions->next()) {
00272 if (
00273 in_array($registrationOption->getOptionId(), $registrationOptionIds) &&
00274 strtotime($registrationOption->getOpeningDate()) < time() &&
00275 strtotime($registrationOption->getClosingDate()) > time() &&
00276 $registrationOption->getPublic()
00277 ) {
00278 $registrationOptionDao->insertRegistrationOptionAssoc($registrationId, $registrationOption->getOptionId());
00279 $cost += $registrationOptionCosts[$registrationOption->getOptionId()];
00280 }
00281 unset($registrationOption);
00282 }
00283
00284 $queuedPayment =& $paymentManager->createQueuedPayment($schedConf->getConferenceId(), $schedConf->getId(), QUEUED_PAYMENT_TYPE_REGISTRATION, $user->getId(), $registrationId, $cost, $registrationType->getCurrencyCodeAlpha());
00285 $queuedPaymentId = $paymentManager->queuePayment($queuedPayment, time() + (60 * 60 * 24 * 30));
00286
00287 if ($cost == 0) {
00288 $paymentManager->fulfillQueuedPayment($queuedPaymentId, $queuedPayment);
00289 return REGISTRATION_FREE;
00290 } else {
00291 $paymentManager->displayPaymentForm($queuedPaymentId, $queuedPayment);
00292 }
00293
00294 return REGISTRATION_SUCCESSFUL;
00295 }
00296 }
00297
00298 ?>