classes/registration/form/RegistrationForm.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00019 //$Id$
00020 
00021 import('form.Form');
00022 
00023 class RegistrationForm extends Form {
00024 
00026    var $registrationId;
00027 
00032    function RegistrationForm($registrationId = null, $userId = null) {
00033 
00034       $this->registrationId = isset($registrationId) ? (int) $registrationId : null;
00035       $this->userId = isset($userId) ? (int) $userId : null;
00036       $schedConf =& Request::getSchedConf();
00037 
00038       parent::Form('registration/registrationForm.tpl');
00039 
00040       // User is provided and valid
00041       $this->addCheck(new FormValidator($this, 'userId', 'required', 'manager.registration.form.userIdRequired'));
00042       $this->addCheck(new FormValidatorCustom($this, 'userId', 'required', 'manager.registration.form.userIdValid', create_function('$userId', '$userDao =& DAORegistry::getDAO(\'UserDAO\'); return $userDao->userExistsById($userId);')));
00043 
00044       // Ensure that user does not already have a registration for this scheduled conference
00045       if ($this->registrationId == null) {
00046          $this->addCheck(new FormValidatorCustom($this, 'userId', 'required', 'manager.registration.form.registrationExists', array(DAORegistry::getDAO('RegistrationDAO'), 'registrationExistsByUser'), array($schedConf->getId()), true));
00047       } else {
00048          $this->addCheck(new FormValidatorCustom($this, 'userId', 'required', 'manager.registration.form.registrationExists', create_function('$userId, $schedConfId, $registrationId', '$registrationDao =& DAORegistry::getDAO(\'RegistrationDAO\'); $checkId = $registrationDao->getRegistrationIdByUser($userId, $schedConfId); return ($checkId == 0 || $checkId == $registrationId) ? true : false;'), array($schedConf->getId(), $this->registrationId)));
00049       }
00050 
00051       // Registration type is provided and valid
00052       $this->addCheck(new FormValidator($this, 'typeId', 'required', 'manager.registration.form.typeIdRequired'));
00053       $this->addCheck(new FormValidatorCustom($this, 'typeId', 'required', 'manager.registration.form.typeIdValid', create_function('$typeId, $schedConfId', '$registrationTypeDao =& DAORegistry::getDAO(\'RegistrationTypeDAO\'); return $registrationTypeDao->registrationTypeExistsByTypeId($typeId, $schedConfId);'), array($schedConf->getId())));
00054 
00055       // If provided, domain is valid
00056       $this->addCheck(new FormValidatorRegExp($this, 'domain', 'optional', 'manager.registration.form.domainValid', '/^' .
00057             '[A-Z0-9]+([\-_\.][A-Z0-9]+)*' .
00058             '\.' .
00059             '[A-Z]{2,4}' .
00060          '$/i'));
00061 
00062       // If provided, IP range has IP address format; IP addresses may contain wildcards
00063       $this->addCheck(new FormValidatorRegExp($this, 'ipRange', 'optional', 'manager.registration.form.ipRangeValid','/^' .
00064             // IP4 address (with or w/o wildcards) or IP4 address range (with or w/o wildcards) or CIDR IP4 address
00065             '((([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2}|[' . REGISTRATION_IP_RANGE_WILDCARD . '])([.]([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2}|[' . REGISTRATION_IP_RANGE_WILDCARD . '])){3}((\s)*[' . REGISTRATION_IP_RANGE_RANGE . '](\s)*([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2}|[' . REGISTRATION_IP_RANGE_WILDCARD . '])([.]([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2}|[' . REGISTRATION_IP_RANGE_WILDCARD . '])){3}){0,1})|(([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2})([.]([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2})){3}([\/](([3][0-2]{0,1})|([1-2]{0,1}[0-9])))))' .
00066             // followed by 0 or more delimited IP4 addresses (with or w/o wildcards) or IP4 address ranges
00067             // (with or w/o wildcards) or CIDR IP4 addresses
00068             '((\s)*' . REGISTRATION_IP_RANGE_SEPERATOR . '(\s)*' .
00069             '((([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2}|[' . REGISTRATION_IP_RANGE_WILDCARD . '])([.]([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2}|[' . REGISTRATION_IP_RANGE_WILDCARD . '])){3}((\s)*[' . REGISTRATION_IP_RANGE_RANGE . '](\s)*([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2}|[' . REGISTRATION_IP_RANGE_WILDCARD . '])([.]([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2}|[' . REGISTRATION_IP_RANGE_WILDCARD . '])){3}){0,1})|(([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2})([.]([0-9]|[1-9][0-9]|[1][0-9]{2}|[2][0-5]{2})){3}([\/](([3][0-2]{0,1})|([1-2]{0,1}[0-9])))))' .
00070             ')*' .
00071          '$/i'));
00072 
00073       // Notify email flag is valid value
00074       $this->addCheck(new FormValidatorInSet($this, 'notifyEmail', 'optional', 'manager.registration.form.notifyEmailValid', array('1')));
00075       $this->addCheck(new FormValidatorInSet($this, 'notifyPaymentEmail', 'optional', 'manager.registration.form.notifyEmailValid', array('1')));
00076 
00077       $this->addCheck(new FormValidatorPost($this));
00078    }
00079 
00083    function display() {
00084       $templateMgr =& TemplateManager::getManager();
00085       $schedConf =& Request::getSchedConf();
00086 
00087       $templateMgr->assign('registrationId', $this->registrationId);
00088       $templateMgr->assign('yearOffsetPast', REGISTRATION_YEAR_OFFSET_PAST);
00089       $templateMgr->assign('yearOffsetFuture', REGISTRATION_YEAR_OFFSET_FUTURE);
00090 
00091       $userDao =& DAORegistry::getDAO('UserDAO');
00092       $user =& $userDao->getUser(isset($this->userId)?$this->userId:$this->getData('userId'));
00093 
00094       $templateMgr->assign_by_ref('user', $user);
00095 
00096       $registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
00097       $registrationTypes =& $registrationTypeDao->getRegistrationTypesBySchedConfId($schedConf->getId());
00098       $templateMgr->assign('registrationTypes', $registrationTypes);
00099 
00100       $registrationOptionDao =& DAORegistry::getDAO('RegistrationOptionDAO');
00101       $registrationOptions =& $registrationOptionDao->getRegistrationOptionsBySchedConfId($schedConf->getId());
00102       $registrationOptionsArray =& $registrationOptions->toArray();
00103       $templateMgr->assign('registrationOptions', $registrationOptionsArray);
00104 
00105       $templateMgr->assign('helpTopicId', 'conference.currentConferences.registration');
00106 
00107       parent::display();
00108    }
00109 
00113    function initData() {   
00114       if (isset($this->registrationId)) {
00115          $registrationOptionDao =& DAORegistry::getDAO('RegistrationOptionDAO');
00116          $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
00117          $registration =& $registrationDao->getRegistration($this->registrationId);
00118 
00119          if ($registration != null) {
00120             $this->_data = array(
00121                'userId' => $registration->getUserId(),
00122                'typeId' => $registration->getTypeId(),
00123                'membership' => $registration->getMembership(),
00124                'domain' => $registration->getDomain(),
00125                'ipRange' => $registration->getIPRange(),
00126                'specialRequests' => $registration->getSpecialRequests(),
00127                'datePaid' => $registration->getDatePaid(),
00128                'registrationOptionIds' => $registrationOptionDao->getRegistrationOptions($this->registrationId)
00129             );
00130 
00131          } else {
00132             $this->registrationId = null;
00133          }
00134       }
00135    }
00136 
00140    function readInputData() {
00141       $this->readUserVars(array('userId', 'typeId', 'membership', 'domain', 'ipRange', 'notifyEmail', 'notifyPaymentEmail', 'specialRequests', 'datePaid', 'registrationOptionIds'));
00142 
00143       $this->_data['datePaid'] = Request::getUserVar('paid')?Request::getUserDateVar('datePaid'):null;
00144 
00145       // If registration type requires it, membership is provided
00146       $registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
00147       $registrationType =& $registrationTypeDao->getRegistrationType($this->getData('typeId'));
00148       $needMembership = $registrationType->getMembership();
00149 
00150       if ($needMembership) { 
00151          $this->addCheck(new FormValidator($this, 'membership', 'required', 'manager.registration.form.membershipRequired'));
00152       }
00153 
00154       // If registration type requires it, domain and/or IP range is provided
00155       $isInstitutional = $registrationTypeDao->getRegistrationTypeInstitutional($this->getData('typeId'));
00156       $isOnline = $registrationType->getAccess() != REGISTRATION_TYPE_ACCESS_PHYSICAL ? true : false;
00157 
00158       if ($isInstitutional && $isOnline) { 
00159          $this->addCheck(new FormValidatorCustom($this, 'domain', 'required', 'manager.registration.form.domainIPRangeRequired', create_function('$domain, $ipRange', 'return $domain != \'\' || $ipRange != \'\' ? true : false;'), array($this->getData('ipRange'))));
00160       }
00161 
00162       // If notify email is requested, ensure registration contact name and email exist.
00163       if ($this->_data['notifyEmail'] == 1) {
00164          $this->addCheck(new FormValidatorCustom($this, 'notifyEmail', 'required', 'manager.registration.form.registrationContactRequired', create_function('', '$schedConf =& Request::getSchedConf(); $schedConfSettingsDao =& DAORegistry::getDAO(\'SchedConfSettingsDAO\'); $registrationName = $schedConfSettingsDao->getSetting($schedConf->getId(), \'registrationName\'); $registrationEmail = $schedConfSettingsDao->getSetting($schedConf->getId(), \'registrationEmail\'); return $registrationName != \'\' && $registrationEmail != \'\' ? true : false;'), array()));
00165       }
00166       if ($this->_data['notifyPaymentEmail'] == 1) {
00167          $this->addCheck(new FormValidatorCustom($this, 'notifyPaymentEmail', 'required', 'manager.registration.form.registrationContactRequired', create_function('', '$schedConf =& Request::getSchedConf(); $schedConfSettingsDao =& DAORegistry::getDAO(\'SchedConfSettingsDAO\'); $registrationName = $schedConfSettingsDao->getSetting($schedConf->getId(), \'registrationName\'); $registrationEmail = $schedConfSettingsDao->getSetting($schedConf->getId(), \'registrationEmail\'); return $registrationName != \'\' && $registrationEmail != \'\' ? true : false;'), array()));
00168       }
00169    }
00170 
00174    function execute() {
00175       $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
00176       $schedConf =& Request::getSchedConf();
00177 
00178       if (isset($this->registrationId)) {
00179          $registration =& $registrationDao->getRegistration($this->registrationId);
00180       }
00181 
00182       if (!isset($registration)) {
00183          $registration = new Registration();
00184          $registration->setDateRegistered(time());
00185       }
00186 
00187       $registration->setSchedConfId($schedConf->getId());
00188       $registration->setUserId($this->getData('userId'));
00189       $registration->setTypeId($this->getData('typeId'));
00190       $registration->setMembership($this->getData('membership') ? $this->getData('membership') : null);
00191       $registration->setDomain($this->getData('domain') ? $this->getData('domain') : null);
00192       $registration->setIPRange($this->getData('ipRange') ? $this->getData('ipRange') : null);
00193       $registration->setSpecialRequests($this->getData('specialRequests') ? $this->getData('specialRequests') : null);
00194 
00195       // Send an email to the registrant informing them that their payment was received
00196       if ($this->getData('notifyPaymentEmail')) {
00197          $userDao =& DAORegistry::getDAO('UserDAO');
00198 
00199          $schedConfName = $schedConf->getSchedConfTitle();
00200          $schedConfId = $schedConf->getId();
00201          $user =& $userDao->getUser($this->getData('userId'));
00202 
00203          list($registrationEmail, $registrationName, $registrationContactSignature) = $this->getRegistrationContactInformation($schedConfId);
00204 
00205          $paramArray = array(
00206             'registrantName' => $user->getFullName(),
00207             'schedConfName' => $schedConfName,
00208             'registrationContactSignature' => $registrationContactSignature 
00209          );
00210 
00211          import('mail.MailTemplate');
00212          $mail = new MailTemplate('MANUAL_PAYMENT_RECEIVED');
00213          $mail->setFrom($registrationEmail, $registrationName);
00214          $mail->assignParams($paramArray);
00215          $mail->addRecipient($user->getEmail(), $user->getFullName());
00216          $mail->send();
00217       }
00218       
00219       $registration->setDatePaid($this->getData('datePaid'));
00220 
00221       // Update or insert registration
00222       if ($registration->getId() != null) {
00223          $registrationDao->updateRegistration($registration);
00224       } else {
00225          $registrationDao->insertRegistration($registration);
00226       }
00227 
00228       $registrationOptionDao =& DAORegistry::getDAO('RegistrationOptionDAO');
00229       $registrationOptions =& $registrationOptionDao->getRegistrationOptionsBySchedConfId($schedConf->getId());
00230       $registrationOptionIds = (array) $this->getData('registrationOptionIds');
00231       $registrationOptionDao->deleteRegistrationOptionAssocByRegistrationId($this->registrationId);
00232 
00233       while ($registrationOption =& $registrationOptions->next()) {
00234          $optionId = (int) $registrationOption->getOptionId();
00235          if (in_array($optionId, $registrationOptionIds)) {
00236             $registrationOptionDao->insertRegistrationOptionAssoc($this->registrationId, $registrationOption->getOptionId());
00237          }
00238          unset($registrationOption);
00239       }
00240 
00241       if ($this->getData('notifyEmail')) {
00242          // Send user registration notification email
00243          $userDao =& DAORegistry::getDAO('UserDAO');
00244          $registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
00245 
00246          $schedConfName = $schedConf->getSchedConfTitle();
00247          $schedConfId = $schedConf->getId();
00248          $user =& $userDao->getUser($this->getData('userId'));
00249          $registrationType =& $registrationTypeDao->getRegistrationType($this->getData('typeId'));
00250 
00251          list($registrationEmail, $registrationName, $registrationContactSignature) = $this->getRegistrationContactInformation($schedConfId);
00252 
00253          $paramArray = array(
00254             'registrantName' => $user->getFullName(),
00255             'schedConfName' => $schedConfName,
00256             'registrationType' => $registrationType->getSummaryString(),
00257             'username' => $user->getUsername(),
00258             'registrationContactSignature' => $registrationContactSignature 
00259          );
00260 
00261          import('mail.MailTemplate');
00262          $mail = new MailTemplate('REGISTRATION_NOTIFY', null, null, null, null, false);
00263          $mail->setFrom($registrationEmail, $registrationName);
00264          $mail->assignParams($paramArray);
00265          $mail->addRecipient($user->getEmail(), $user->getFullName());
00266          $mail->send();
00267       }
00268    }
00269    
00275    function getRegistrationContactInformation($schedConfId) {
00276       $schedConfSettingsDao =& DAORegistry::getDAO('SchedConfSettingsDAO');
00277       
00278       $registrationName = $schedConfSettingsDao->getSetting($schedConfId, 'registrationName');
00279       $registrationEmail = $schedConfSettingsDao->getSetting($schedConfId, 'registrationEmail');
00280       $registrationPhone = $schedConfSettingsDao->getSetting($schedConfId, 'registrationPhone');
00281       $registrationFax = $schedConfSettingsDao->getSetting($schedConfId, 'registrationFax');
00282       $registrationMailingAddress = $schedConfSettingsDao->getSetting($schedConfId, 'registrationMailingAddress');
00283       $registrationContactSignature = $registrationName;
00284 
00285       if ($registrationMailingAddress != '') $registrationContactSignature .= "\n" . $registrationMailingAddress;
00286       if ($registrationPhone != '') $registrationContactSignature .= "\n" . AppLocale::Translate('user.phone') . ': ' . $registrationPhone;
00287       if ($registrationFax != '')   $registrationContactSignature .= "\n" . AppLocale::Translate('user.fax') . ': ' . $registrationFax;
00288 
00289       $registrationContactSignature .= "\n" . AppLocale::Translate('user.email') . ': ' . $registrationEmail;
00290       
00291       return array($registrationEmail, $registrationName, $registrationContactSignature);
00292    }
00293 
00294 }
00295 
00296 ?>

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